From cca69d695671dbd66ac4e6a2e73dc7e238c1751c Mon Sep 17 00:00:00 2001 From: Jason Cleeland Date: Mon, 1 Mar 2004 12:35:44 +0000 Subject: [PATCH] Updated with language constants. Added "boilerplate" type question handling. Added check to ensure that values exist before calling jpgraph. git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@942 b72ed6b6-b9f8-46b5-92b4-906544132732 --- admin/statistics.php | 173 +++++++++++++++++++++++++++---------------- 1 file changed, 111 insertions(+), 62 deletions(-) diff --git a/admin/statistics.php b/admin/statistics.php index 0f6ff9e250e..41123bb1a81 100644 --- a/admin/statistics.php +++ b/admin/statistics.php @@ -83,7 +83,11 @@ require($langfilename); // 1: Get list of questions from survey -$query = "SELECT qid, {$dbprefix}questions.gid, type, title, group_name, question, lid FROM {$dbprefix}questions, {$dbprefix}groups WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid AND {$dbprefix}questions.sid='$sid' ORDER BY group_name, title"; +$query = "SELECT qid, {$dbprefix}questions.gid, type, title, group_name, question, lid " + ."FROM {$dbprefix}questions, {$dbprefix}groups " + ."WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid " + ."AND {$dbprefix}questions.sid='$sid' " + ."ORDER BY group_name, title"; $result = mysql_query($query) or die("Couldn't do it!
$query
".mysql_error()); while ($row=mysql_fetch_row($result)) { @@ -101,7 +105,7 @@ echo "\n\t\t\t\t\n\t\t\t\n"; } echo "\t\t\n" - ."\t\t$flt[4] (Group $flt[1])\n\t\t" + ."\t\t$flt[4] ("._GROUP." $flt[1])\n\t\t" ."\n" ."\t\t\t\n"; $counter=0; @@ -113,14 +117,15 @@ $niceqtext = str_replace("\r", "", $niceqtext); $niceqtext = str_replace("\n", "", $niceqtext); //headings - if ($flt[2] != "A" && $flt[2] != "B" && $flt[2] != "C" && $flt[2] != "E" && $flt[2] != "F" && $flt[2] != "T" && $flt[2] != "S" && $flt[2] != "D" && $flt[2] != "R" && $flt[2] != "Q") //Have to make an exception for these types! + if ($flt[2] != "A" && $flt[2] != "B" && $flt[2] != "C" && $flt[2] != "E" && $flt[2] != "F" && $flt[2] != "T" && $flt[2] != "S" && $flt[2] != "D" && $flt[2] != "R" && $flt[2] != "Q" && $flt[2] != "X") //Have to make an exception for these types! { echo "\t\t\t\t\n\t\t\t\t\n"; $counter2=0;} echo "\t\t\t\t\n\t\t\t\t\n"; $counter=0; break; + case "X": //This is a boilerplate question and it has no business in this script + break; default: $query = "SELECT code, answer FROM {$dbprefix}answers WHERE qid='$flt[0]' ORDER BY sortorder, answer"; $result = mysql_query($query) or die("Couldn't get answers!
$query
".mysql_error()); @@ -455,12 +486,11 @@ ."\t\t\n" ."\t\t\n" - ."\t\t\t\t\n" + ."\t\t\t\t\n" ."\t\t\n" ."\t\n" ."\t\n" @@ -555,19 +585,22 @@ while ($row=mysql_fetch_row($result)) {$results=$row[0];} // 3: Present results including option to view those rows - echo "
\n
" ."$setfont$flt[3] "; //Heading (Question No) if ($flt[2] == "M" || $flt[2] == "P" || $flt[2] == "R") {$myfield = "M$myfield";} if ($flt[2] == "N") {$myfield = "N$myfield";} echo " " ."\"".str_replace("\""," ."
\n"; @@ -138,9 +143,12 @@ case "T": // Long free text $myfield2="T$myfield"; echo "\t\t\t\t
$setfont$flt[3]" - ." \"".str_replace("\""," + ." \""" ."
\n" - ."\t\t\t\t\tResponses containing:
\n" + ."\t\t\t\t\t"._ST_RESPONECONT.":
\n" ."\t\t\t\t\t"; @@ -149,9 +157,12 @@ case "S": // Short free text $myfield2="T$myfield"; echo "\t\t\t\t
$setfont$flt[3]" - ." \"".str_replace("\""," + ." \""" ."
\n" - ."\t\t\t\t\tResponses containing:
\n" + ."\t\t\t\t\t"._ST_RESPONECONT.":
\n" ."\t\t\t\t\t"; @@ -160,11 +171,11 @@ case "N": // Numerical $myfield2="{$myfield}G"; $myfield3="{$myfield}L"; - echo "\t\t\t\t\tNumber greater than:
\n" + echo "\t\t\t\t\t"._ST_NOGREATERTHAN.":
\n" ."\t\t\t\t\t
\n" - ."\t\t\t\t\tNumber less than:
\n" + ."\t\t\t\t\t"._ST_NOLESSTHAN.":
\n" ."\t\t\t\t\t
\n"; @@ -174,25 +185,30 @@ $myfield3="$myfield2="; $myfield4="$myfield2<"; $myfield5="$myfield2>"; echo "\t\t\t\t
$setfont$flt[3]" - ." \"".str_replace("\""," + ." \""" ."
\n" - ."\t\t\t\t\tDate (YYYY-MM-DD) equals:
\n" + ."\t\t\t\t\t"._ST_DATEEQUALS.":
\n" ."\t\t\t\t\t
\n" - ."\t\t\t\t\t  OR between:
\n" + ."\t\t\t\t\t  "._ST_ORBETWEEN.":
\n" ."\t\t\t\t\t & "._AND." \n"; + echo "' type='text' ".substr($slstyle2, 0, -13) + ."; width:65'>\n"; break; case "5": // 5 point choice for ($i=1; $i<=5; $i++) { echo "\t\t\t\t\t\n"; } break; @@ -230,7 +246,9 @@ ." " - ."\"".str_replace("\""," + ."\""" ."
\n" ."\t\t\t\t " - ."\"".str_replace("\""," ."
\n" ."\t\t\t\t
$setfont$flt[3] ($row[0])" ." " - ."\"".str_replace("\""," + ."\""" ."
\n" ."\t\t\t\t\n" ."\t\t\t\t\t
\n" ."\t\t 
$setfont
$setfont
\n\t\t\t
\n" - ."\t\t\t\n" - ."\t\t\t\n" + ."\t\t\t\n" + ."\t\t\t\n" ."\t\t
 \n\t\t
\n" - ."\t\n" - ."\t
$setfontResults
$setfont" - ."Your query returns $results record(s)!
\n\t\t" - ."There are $total records in your survey."; + echo "
\n\n" + ."\t\n" + ."\t\n"; if (isset ($selects) && $selects) {$sql=implode(" AND ", $selects);} if (!isset($sql) || !$sql) {$sql="NULL";} @@ -603,7 +636,8 @@ $nresult = mysql_query($nquery) or die ("Couldn't get question
$nquery
".mysql_error()); while ($nrow=mysql_fetch_row($nresult)) { - $qtitle=$nrow[0]; $qtype=$nrow[1]; + $qtitle=$nrow[0]; + $qtype=$nrow[1]; $qquestion=strip_tags($nrow[2]); $qlid=$nrow[3]; $qother=$nrow[4]; @@ -643,8 +677,12 @@ $nquery = "SELECT title, type, question FROM {$dbprefix}questions WHERE qid='$qqid'"; $nresult = mysql_query($nquery) or die ("Couldn't get question
$nquery
".mysql_error()); - while ($nrow=mysql_fetch_row($nresult)) {$qtitle=$nrow[0]. " [".substr($rt, strchr($rt, "-")-($lengthofnumeral+1), $lengthofnumeral)."]"; $qtype=$nrow[1]; $qquestion=strip_tags($nrow[2]). "[Rank ".substr($rt, strchr($rt, "-")-($lengthofnumeral+1), $lengthofnumeral)."]";} - + while ($nrow=mysql_fetch_row($nresult)) + { + $qtitle=$nrow[0]. " [".substr($rt, strchr($rt, "-")-($lengthofnumeral+1), $lengthofnumeral)."]"; + $qtype=$nrow[1]; + $qquestion=strip_tags($nrow[2]). "["._RANK." ".substr($rt, strchr($rt, "-")-($lengthofnumeral+1), $lengthofnumeral)."]"; + } $query="SELECT code, answer FROM {$dbprefix}answers WHERE qid='$qqid' ORDER BY sortorder, answer"; $result=mysql_query($query) or die("Couldn't get list of answers for multitype
$query
".mysql_error()); while ($row=mysql_fetch_row($result)) @@ -660,11 +698,13 @@ $nresult = mysql_query($nquery) or die ("Couldn't get question
$nquery
".mysql_error()); while ($nrow=mysql_fetch_row($nresult)) {$qtitle=$nrow[0]; $qtype=$nrow[1]; $qquestion=strip_tags($nrow[2]); $qiqid=$nrow[3]; $qlid=$nrow[4];} echo "
\n
$setfont" + ._ST_RESULTS."
" + ."$setfont" + .""._ST_RECORDSRETURNED.": $results
\n\t\t" + ._ST_TOTALRECORDS.": $total
\n"; if ($total) { $percent=sprintf("%01.2f", ($results/$total)*100); - echo " This query represents " - ."$percent% of your total results
"; + echo _ST_PERCENTAGE + .": $percent%
"; } echo "\n\t\t
\n" - ."\t\tSQL: $query\n" + ."\t\t"._SQL.": $query\n" ."\t
\n" - ."\t\n" ."\t\n" - ."\t\n\t\t\n" - ."\t\t\n" + ."\t\n\t\t\n" + ."\t\t\n" ."\t\t\n" ."\t\n"; $fieldname=substr($rt, 1, strlen($rt)); @@ -678,10 +718,10 @@ $result=mysql_query($query) or die("Couldn't do maths testing
$query
".mysql_error()); while ($row=mysql_fetch_array($result)) { - $showem[]=array("Sum", $row['sum']); - $showem[]=array("Standard Deviation", $row['stdev']); - $showem[]=array("Average", $row['average']); - $showem[]=array("Minimum", $row['minimum']); + $showem[]=array(_ST_SUM, $row['sum']); + $showem[]=array(_ST_STDEV, $row['stdev']); + $showem[]=array(_ST_AVERAGE, $row['average']); + $showem[]=array(_ST_MIN, $row['minimum']); $maximum=$row['maximum']; //we're going to put this after the quartiles for neatness $minimum=$row['minimum']; } @@ -713,7 +753,7 @@ } $q1total=$lastnumber-(1-($total*$q1diff)); if ($q1total < $minimum) {$q1total=$minimum;} - $showem[]=array("1st Quartile (Q1)", $q1total); + $showem[]=array(_ST_Q1, $q1total); } else { @@ -734,7 +774,7 @@ $query = $querystarter . " ORDER BY `$fieldname`*1 LIMIT $medianc, 2"; $result=mysql_query($query) or die("What a complete mess
".mysql_error()); while ($row=mysql_fetch_array($result)) {$total=$total+$row[$fieldname];} - $showem[]=array("2nd Quartile (Median)", $total/2); + $showem[]=array(_ST_Q2, $total/2); } else { @@ -762,7 +802,7 @@ } $q3total=$lastnumber+($total*$q3diff); if ($q3total < $maximum) {$q1total=$maximum;} - $showem[]=array("3rd Quartile (Q3)", $q3total); + $showem[]=array(_ST_Q3, $q3total); } else { @@ -771,7 +811,7 @@ while ($row=mysql_fetch_array($result)) {$showem[]=array("3rd Quartile (Q3)", $row[$fieldname]);} } $total=0; - $showem[]=array("Maximum", $maximum); + $showem[]=array(_ST_MAX, $maximum); foreach ($showem as $shw) { echo "\t\n" @@ -782,8 +822,8 @@ } echo "\t\n" ."\t\t\n" ."\t\n"; @@ -928,12 +968,17 @@ if (isset($alist) && $alist) //JUST IN CASE SOMETHING GOES WRONG { echo "
\n
$setfontField Summary for $qtitle:" + ."\t
$setfont"._ST_FIELDSUMMARY." $qtitle:" ."
$setfont$qquestion
$setfontCalculation$setfontResult
$setfont" + ._ST_CALCULATION."$setfont" + ._ST_RESULT."$setfont
\n" - ."\t\t\t$setfont*Null values are ignored in calculations
\n" - ."\t\t\t*Q1 and Q3 calculated using minitab method" + ."\t\t\t$setfont"._ST_NULLIGNORED."
\n" + ."\t\t\t"._ST_QUARTMETHOD ."
\n" ."\t\t
\n" - ."\t\n" - ."\t\n" - ."\t\n\t\t\n" - ."\t\t\n" - ."\t\t\n" + ."\t\n" + ."\t\n\t\t\n" + ."\t\t\n" + ."\t\t\n" ."\t\n"; foreach ($alist as $al) { @@ -988,9 +1033,12 @@ $lbl[] = $fname; } } - //$usejpgraph=1; - if ($usejpgraph == 1) //JPGRAPH CODING SUBMITTED BY Pieterjan Heyse + + if ($usejpgraph == 1 && array_sum($gdata)>0) //JPGRAPH CODING SUBMITTED BY Pieterjan Heyse { + //$gdata and $lbl are arrays built at the end of the last section + //that contain the values, and labels for the data we are about + //to send to jpgraph. $graph = new PieGraph(640,320,'png'); $graph->img->SetAntiAliasing(); @@ -1019,9 +1067,10 @@ echo ""; ////// PIE ALL DONE + } unset($gdata); unset($lbl); - } + } echo "
$setfontField Summary for $qtitle:" + ."\t
$setfont" + ._ST_FIELDSUMMARY." $qtitle:" ."
$setfont$qquestion
$setfontAnswer$setfontCount$setfontPercentage
$setfont" + ."$qquestion
$setfont" + .""._AL_ANSWER."$setfont" + .""._COUNT."$setfont" + .""._PERCENTAGE."
\n"; unset ($alist);