Navigation Menu

Skip to content

Commit

Permalink
Fixed issue #5188: SQL failure in printable survey when using MSSQL s…
Browse files Browse the repository at this point in the history
…erver

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@10142 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed May 28, 2011
1 parent 3b2de46 commit c02e4a9
Showing 1 changed file with 41 additions and 40 deletions.
81 changes: 41 additions & 40 deletions admin/printablesurvey.php
Expand Up @@ -138,6 +138,7 @@ function try_debug($line)
{
$surveyname = "";
}

$survey_output = array(
'SITENAME' => $sitename
,'SURVEYNAME' => $surveyname
Expand Down Expand Up @@ -434,9 +435,9 @@ function star_replace($input)
$x=0;
$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
WHERE ".db_table_name("conditions").".qid={$deqrow['qid']}
AND ".db_table_name("conditions").".scenario={$scenariorow['scenario']}
group by cqid, method, cfieldname, value
ORDER BY cqid";
$distinctresult=db_execute_assoc($distinctquery);
//Loop through each condition for a particular scenario.
Expand Down Expand Up @@ -643,7 +644,7 @@ function star_replace($input)
} // while
break;
} // switch

// Now let's complete the answer text with the answer_section
$answer_section="";
switch($conrow['type'])
Expand Down Expand Up @@ -755,20 +756,20 @@ function star_replace($input)

++$total_questions;


//TIBO map question qid to their q number
$mapquestionsNumbers[$deqrow['qid']]=$total_questions;
//END OF GETTING CONDITIONS

$qid = $deqrow['qid'];
$fieldname = "$surveyid"."X"."$gid"."X"."$qid";

if(isset($showsgqacode) && $showsgqacode == true)
{
$deqrow['question'] = $deqrow['question']."<br />".$clang->gT("ID:")." $fieldname <br />".
$clang->gT("Question code:")." ".$deqrow['title'];
$clang->gT("Question code:")." ".$deqrow['title'];
}

$question = array(
'QUESTION_NUMBER' => $total_questions // content of the question code field
,'QUESTION_CODE' => $deqrow['title']
Expand All @@ -784,7 +785,7 @@ function star_replace($input)
,'QUESTIONHELP' => '' // content of the question help field.
,'ANSWER' => '' // contains formatted HTML answer
);


if ($deqrow['mandatory'] == 'Y')
{
Expand All @@ -804,7 +805,7 @@ function star_replace($input)
{
$hh = $deqrow['help'];
$question['QUESTIONHELP'] = $hh;

if(isset($_POST['printableexport'])){$pdf->helptextintopdf($hh);}
}

Expand All @@ -814,7 +815,7 @@ function star_replace($input)
$question['QUESTION_CLASS'] .=' breakbefore ';
}


if (isset($qidattributes['maximum_chars']) && $qidattributes['maximum_chars']!='') {
$question['QUESTION_CLASS'] ="max-chars-{$qidattributes['maximum_chars']} ".$question['QUESTION_CLASS'];
}
Expand Down Expand Up @@ -1020,7 +1021,7 @@ function star_replace($input)
$question['ANSWER'] .= $wrapper['item-start'].input_type_image('checkbox',$mearow['question'])."\n\t\t".$mearow['question'].addsgqacode(" (".$fieldname.$mearow['title'].") ").$wrapper['item-end'];
if(isset($_POST['printableexport'])){$pdf->intopdf(" o ".$mearow['answer']);}
// $upto++;

++$rowcounter;
if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
{
Expand Down Expand Up @@ -1127,7 +1128,7 @@ function star_replace($input)
if (isset($qidattributes['slider_layout']) && $qidattributes['slider_layout']==1)
{
$mearow['question']=explode(':',$mearow['question']);
$mearow['question']=$mearow['question'][0];
$mearow['question']=$mearow['question'][0];
}
$question['ANSWER'] .= "\t<li>\n\t\t<span>".$mearow['question']."</span>\n\t\t".input_type_image('text',$mearow['question'],$width).addsgqacode(" (".$fieldname.$mearow['title'].") ")."\n\t</li>\n";
if(isset($_POST['printableexport'])){$pdf->intopdf($mearow['question'].": ____________________");}
Expand Down Expand Up @@ -1223,9 +1224,9 @@ function star_replace($input)
{
$question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
$rowclass = alternation($rowclass,'row');

//semantic differential question type?
if (strpos($mearow['question'],'|'))
if (strpos($mearow['question'],'|'))
{
$answertext = substr($mearow['question'],0, strpos($mearow['question'],'|')).addsgqacode(" (".$fieldname.$mearow['title'].")")." ";
}
Expand All @@ -1243,7 +1244,7 @@ function star_replace($input)
}

$answertext .= $mearow['question'];

//semantic differential question type?
if (strpos($mearow['question'],'|'))
{
Expand Down Expand Up @@ -1327,7 +1328,7 @@ function star_replace($input)
$question['ANSWER'] .= "\t\t\t<td>".input_type_image('radio',$clang->gT("Uncertain"))."</td>\n";
$question['ANSWER'] .= "\t\t\t<td>".input_type_image('radio',$clang->gT("No"))."</td>\n";
$question['ANSWER'] .= "\t\t</tr>\n";

$pdfoutput[$j]=array($mearow['question']," o ".$clang->gT("Yes")," o ".$clang->gT("Uncertain")," o ".$clang->gT("No"));
$j++;
$rowclass = alternation($rowclass,'row');
Expand Down Expand Up @@ -1411,7 +1412,7 @@ function star_replace($input)
}
$meaquery = "SELECT * FROM ".db_table_name("questions")." WHERE parent_qid={$deqrow['qid']} AND scale_id=0 AND language='{$surveyprintlang}' ORDER BY question_order";
$mearesult = db_execute_assoc($meaquery);

if ($checkboxlayout === false)
{
if ($stepvalue > 1)
Expand All @@ -1433,24 +1434,24 @@ function star_replace($input)

$question['ANSWER'] .= "\n<table>\n\t<thead>\n\t\t<tr>\n\t\t\t<td>&nbsp;</td>\n";
$fquery = "SELECT * FROM ".db_table_name("questions")." WHERE parent_qid={$deqrow['qid']} AND scale_id=1 AND language='{$surveyprintlang}' ORDER BY question_order";
$fresult = db_execute_assoc($fquery);
$fresult = db_execute_assoc($fquery);

$fcount = $fresult->RecordCount();
$fwidth = "120";
$i=0;
$pdfoutput = array();
$pdfoutput[0][0]=' ';

//array to temporary store X axis question codes
$xaxisarray = array();
while ($frow = $fresult->FetchRow())
{
$question['ANSWER'] .= "\t\t\t<th>{$frow['question']}</th>\n";
$i++;
$pdfoutput[0][$i]=$frow['question'];

//add current question code
$xaxisarray[$i] = $frow['title'];
$xaxisarray[$i] = $frow['title'];
}
$question['ANSWER'] .= "\t\t</tr>\n\t</thead>\n\n\t<tbody>\n";
$a=1; //Counter for pdfoutput
Expand Down Expand Up @@ -1512,15 +1513,15 @@ function star_replace($input)
$i=0;
$pdfoutput=array();
$pdfoutput[0][0]='';

//array to temporary store X axis question codes
$xaxisarray = array();
$xaxisarray = array();
while ($frow = $fresult->FetchRow())
{
$question['ANSWER'] .= "\t\t\t<th>{$frow['question']}</th>\n";
$i++;
$pdfoutput[0][$i]=$frow['question'];

//add current question code
$xaxisarray[$i] = $frow['title'];
}
Expand Down Expand Up @@ -1613,17 +1614,17 @@ function star_replace($input)
$question['ANSWER'] .= "\t\t<tr class=\"$rowclass\">\n";
$rowclass = alternation($rowclass,'row');
if (trim($answertext)=='') $answertext='&nbsp;';

//semantic differential question type?
if (strpos($mearow['question'],'|'))
if (strpos($mearow['question'],'|'))
{
$answertext = substr($mearow['question'],0, strpos($mearow['question'],'|')).addsgqacode(" (".$fieldname.$mearow['title'].")")." ";
}
else
{
$answertext=$mearow['question'].addsgqacode(" (".$fieldname.$mearow['title'].")");
}
}

if (trim($qidattributes['answer_width'])!='')
{
$sInsertStyle=' style="width:'.$qidattributes['answer_width'].'%" ';
Expand All @@ -1633,7 +1634,7 @@ function star_replace($input)
$sInsertStyle='';
}
$question['ANSWER'] .= "\t\t\t<th $sInsertStyle class=\"answertext\">$answertext</th>\n";

$pdfoutput[$counter][0]=$answertext;
for ($i=1; $i<=$fcount; $i++)
{
Expand All @@ -1644,7 +1645,7 @@ function star_replace($input)
$counter++;

$answertext=$mearow['question'];

//semantic differential question type?
if (strpos($mearow['question'],'|'))
{
Expand Down Expand Up @@ -1696,18 +1697,18 @@ function star_replace($input)
$fcount1 = $fresult1->RecordCount();
$fwidth = "120";
$l2=0;

//array to temporary store second scale question codes
$scale2array = array();
$scale2array = array();
while ($frow1 = $fresult1->FetchRow())
{
$printablesurveyoutput2 .="\t\t\t<th>{$frow1['answer']}</th>\n";
$pdfoutput[1][$l2]=$frow['answer'];

//add current question code
$scale2array[$l2] = $frow1['code'];
$l2++;

$l2++;
}
// build header if needed
if ($leftheader != '' || $rightheader !='')
Expand Down Expand Up @@ -1760,7 +1761,7 @@ function star_replace($input)
$question['ANSWER'] .= "\t\t\t<th class=\"answertextright\">$answertext</th>\n";
}
$question['ANSWER'] .= "\t\t</tr>\n";

//increase subquestion counter
$sqcounter++;
}
Expand Down Expand Up @@ -1946,10 +1947,10 @@ function array_filter_help($qidattributes, $surveyprintlang, $surveyid) {

/*
* $code: Text string containing the reference (column heading) for the current (sub-) question
*
*
* Checks if the $showsgqacode setting is enabled at config and adds references to the column headings
* to the output so it can be used as a code book for customized SQL queries when analysing data.
*
*
* return: adds the text string to the overview
*/
function addsgqacode($code)
Expand Down

0 comments on commit c02e4a9

Please sign in to comment.