View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
05013Bug reportsPrint Viewpublic2011-04-11 11:30
Reporteruser179Assigned Tolemeur  
PrioritylowSeveritytext 
Status closedResolutionfixed 
Product Version1.90+ 
Fixed in Version1.91RC6 
Summary05013: GSOC - Filter settings based on token information not properly displayed in printable version
Description

Sorry if this has been reported or solved already (didn't find anything):

When conditions are based on token information (or more precisely, on additional token fields), these information is not correctly displayed in the printable survey view.

Instead of displaying any useful information (e.g., only answer if 'man = yes'), the following text is presented:

"Only answer this question if the following conditions are met:
° Answer was at question ' []' ()"

Seems wrong because (1) these conditions aren't based on questions and (2) no information about actual filter (source, value) is given.

Steps To Reproduce
  1. Create a survey, activate tokens, add additional field (e.g., gender) and type information in there (e.g., male or female)
  2. Filter according to this information (e.g., only display question if gender = male)
  3. Open the printable view of survey and look how the filtering is presented there
TagsNo tags attached.
Attached Files
05013-stable c.patch (8,106 bytes)   
Index: printablesurvey.php
===================================================================
--- printablesurvey.php	(revision 9914)
+++ printablesurvey.php	(working copy)
@@ -400,6 +400,7 @@
             $group['ODD_EVEN'] = ' g-row-even';
         }
 
+        //Loop through questions
         foreach ($deqrows as $deqrow)
         {
             // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -418,6 +419,7 @@
             $scenarioquery="SELECT DISTINCT ".db_table_name("conditions").".scenario FROM ".db_table_name("conditions")." WHERE ".db_table_name("conditions").".qid={$deqrow['qid']} ORDER BY scenario";
             $scenarioresult=db_execute_assoc($scenarioquery);
 
+            //Loop through distinct scenarios, thus grouping them together.
             while ($scenariorow=$scenarioresult->FetchRow())
             {
                 if($s == 0 && $scenarioresult->RecordCount() > 1)
@@ -430,13 +432,14 @@
                 }
 
                 $x=0;
-                $distinctquery="SELECT cqid, method
+                $distinctquery="SELECT cqid, method, cfieldname, value
                             FROM ".db_table_name("conditions")."
                             WHERE  ".db_table_name("conditions").".qid={$deqrow['qid']} 
                                 AND ".db_table_name("conditions").".scenario={$scenariorow['scenario']} 
                             group by cqid, method
                             ORDER BY cqid";
                 $distinctresult=db_execute_assoc($distinctquery);
+                //Loop through each condition for a particular scenario.
                 while ($distinctrow=$distinctresult->FetchRow())
                 {
                     $subquery='select title, question from '.db_table_name("questions")." where qid={$distinctrow['cqid']} AND parent_qid=0 AND language='{$surveyprintlang}'";
@@ -451,38 +454,78 @@
                         $distinctrow['method']='==';
                     }
 
-                    if($distinctrow['method']=='==')
-                    {
-                        $explanation .= $clang->gT("Answer was")." ";
+                    if($distinctrow['cqid']){
+                        if($distinctrow['method']=='==')
+                        {
+                            $explanation .= $clang->gT("Answer was")." ";
+                        }
+                        elseif($distinctrow['method']=='!=')
+                        {
+                            $explanation .= $clang->gT("Answer was NOT")." ";
+                        }
+                        elseif($distinctrow['method']=='<')
+                        {
+                            $explanation .= $clang->gT("Answer was less than")." ";
+                        }
+                        elseif($distinctrow['method']=='<=')
+                        {
+                            $explanation .= $clang->gT("Answer was less than or equal to")." ";
+                        }
+                        elseif($distinctrow['method']=='>=')
+                        {
+                            $explanation .= $clang->gT("Answer was greater than or equal to")." ";
+                        }
+                        elseif($distinctrow['method']=='>')
+                        {
+                            $explanation .= $clang->gT("Answer was greater than")." ";
+                        }
+                        elseif($distinctrow['method']=='RX')
+                        {
+                            $explanation .= $clang->gT("Answer matched (regexp)")." ";
+                        }
+                        else
+                        {
+                            $explanation .= $clang->gT("Answer was")." ";
+                        }
                     }
-                    elseif($distinctrow['method']=='!=')
-                    {
-                        $explanation .= $clang->gT("Answer was NOT")." ";
+                    if(!$distinctrow['cqid']){
+                        $tokenData = GetTokenFieldsAndNames($surveyid);
+                        preg_match('/^{TOKEN:([^}]*)}$/',$distinctrow['cfieldname'],$extractedTokenAttr);
+                        $explanation .= "Your ".$tokenData[strtolower($extractedTokenAttr[1])]." ";
+                        if($distinctrow['method']=='==')
+                        {
+                            $explanation .= $clang->gT("is")." ";
+                        }
+                        elseif($distinctrow['method']=='!=')
+                        {
+                            $explanation .= $clang->gT("is NOT")." ";
+                        }
+                        elseif($distinctrow['method']=='<')
+                        {
+                            $explanation .= $clang->gT("is less than")." ";
+                        }
+                        elseif($distinctrow['method']=='<=')
+                        {
+                            $explanation .= $clang->gT("is less than or equal to")." ";
+                        }
+                        elseif($distinctrow['method']=='>=')
+                        {
+                            $explanation .= $clang->gT("is greater than or equal to")." ";
+                        }
+                        elseif($distinctrow['method']=='>')
+                        {
+                            $explanation .= $clang->gT("is greater than")." ";
+                        }
+                        elseif($distinctrow['method']=='RX')
+                        {
+                            $explanation .= $clang->gT("is matched (regexp)")." ";
+                        }
+                        else
+                        {
+                            $explanation .= $clang->gT("is")." ";
+                        }
+                        $answer_section = $distinctrow['value'];
                     }
-                    elseif($distinctrow['method']=='<')
-                    {
-                        $explanation .= $clang->gT("Answer was less than")." ";
-                    }
-                    elseif($distinctrow['method']=='<=')
-                    {
-                        $explanation .= $clang->gT("Answer was less than or equal to")." ";
-                    }
-                    elseif($distinctrow['method']=='>=')
-                    {
-                        $explanation .= $clang->gT("Answer was greater than or equal to")." ";
-                    }
-                    elseif($distinctrow['method']=='>')
-                    {
-                        $explanation .= $clang->gT("Answer was greater than")." ";
-                    }
-                    elseif($distinctrow['method']=='RX')
-                    {
-                        $explanation .= $clang->gT("Answer matched (regexp)")." ";
-                    }
-                    else
-                    {
-                        $explanation .= $clang->gT("Answer was")." ";
-                    }
 
                     $conquery="SELECT cid, cqid, q.title,\n"
                     ."q.question, value, q.type, cfieldname\n"
@@ -689,7 +732,12 @@
                     unset($conditions);
                     // Following line commented out because answer_section  was lost, but is required for some question types
                     //$explanation .= " ".$clang->gT("to question")." '".$mapquestionsNumbers[$distinctrow['cqid']]."' $answer_section ";
-                    $explanation .= " ".$clang->gT("at question")." '".$mapquestionsNumbers[$distinctrow['cqid']]." [".$subresult['title']."]' (".strip_tags($subresult['question'])."$answer_section)" ;
+                    if($distinctrow['cqid']){
+                        $explanation .= " ".$clang->gT("at question")." '".$mapquestionsNumbers[$distinctrow['cqid']]." [".$subresult['title']."]' (".strip_tags($subresult['question'])."$answer_section)" ;
+                    }
+                    else{
+                        $explanation .= " ".$distinctrow['value'] ;
+                    }
                     //$distinctrow
                     $x++;
                 }
05013-stable c.patch (8,106 bytes)   
05013.png (8,725 bytes)   
05013.png (8,725 bytes)   
05013 pre patch.png (12,906 bytes)   
05013 pre patch.png (12,906 bytes)   
Bug heat8
Complete LimeSurvey version number (& build)9642
I will donate to the project if issue is resolvedNo
BrowserFirefox 3
Database type & versionMySQL
Server OS (if known)don't know
Webserver software & version (if known)don't know
PHP Versiondon't know

Users monitoring this issue

pasmaill

Activities

lemeur

lemeur

2011-03-20 07:46

developer   ~14469

If a GSoC applicant wants do give it a try, the fix is to be applied to admin/printablesurvey.php below line 391.

Conditions based on token information use the {TOKEN:XXX} placeholder as then condition value.

See my comment in ticket 05031

pasmaill

pasmaill

2011-03-28 02:37

reporter   ~14583

Last edited: 2011-03-28 02:44

Hi Lemeur,

Please see my attempt at a patch above. The survey I attached was what I used to test and the resulting printout. In case you have difficulties with the survey I have added a after (05013.png) and before (05013 pre patch.png) screenshot. Not too sure if it is an appropriate fix, especially with regards to translations. Would love some feedback:)

Regards,
Peter

lemeur

lemeur

2011-03-29 22:01

developer   ~14609

@pasmaill,

Sorry for the delay,
will have a look soon

lemeur

lemeur

2011-03-29 22:28

developer   ~14610

Last edited: 2011-03-29 22:28

@pasmaill,

Good work.
I've applied the fix in rev 9933 and 9934.
Keep track of this ticket that you fixed and if you're applying to GSOC don't hesitate to add a reference to this ticket.

Thx,
Thibault

PS: if you want a more challenging ticket, have a look at "05031: GSOC - update answercodes does not update conditions"

c_schmitz

c_schmitz

2011-04-11 11:30

administrator   ~14754

1.91RC6 released.

Issue History

Date Modified Username Field Change
2011-03-09 19:27 user179 New Issue
2011-03-10 12:27 c_schmitz Assigned To => lemeur
2011-03-10 12:27 c_schmitz Status new => assigned
2011-03-20 07:44 lemeur Summary Filter settings based on token information not properly displayed in printable version => GSOC - Filter settings based on token information not properly displayed in printable version
2011-03-20 07:46 lemeur Note Added: 14469
2011-03-28 02:08 pasmaill File Added: 05013-stable c.patch
2011-03-28 02:08 pasmaill File Added: limesurvey_survey_85474b.lss
2011-03-28 02:37 pasmaill Note Added: 14583
2011-03-28 02:39 pasmaill File Added: 05013.png
2011-03-28 02:42 pasmaill File Added: 05013 pre patch.png
2011-03-28 02:44 pasmaill Note Edited: 14583
2011-03-29 00:45 pasmaill Issue Monitored: pasmaill
2011-03-29 18:39 user13064 Issue Monitored: user13064
2011-03-29 22:01 lemeur Note Added: 14609
2011-03-29 22:28 lemeur Note Added: 14610
2011-03-29 22:28 lemeur Note Edited: 14610
2011-03-29 22:29 lemeur Status assigned => resolved
2011-03-29 22:29 lemeur Fixed in Version => 1.91RC6
2011-03-29 22:29 lemeur Resolution open => fixed
2011-03-29 23:57 user13064 Issue End Monitor: user13064
2011-04-11 11:30 c_schmitz Note Added: 14754
2011-04-11 11:30 c_schmitz Status resolved => closed
2021-08-02 16:48 guest Bug heat 6 => 8