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++; }