Changes to use new database stuff
authormoodler <moodler>
Mon, 23 Dec 2002 05:57:05 +0000 (05:57 +0000)
committermoodler <moodler>
Mon, 23 Dec 2002 05:57:05 +0000 (05:57 +0000)
mod/survey/details.php
mod/survey/download.php
mod/survey/graph.php
mod/survey/lib.php
mod/survey/mod.html
mod/survey/report.php
mod/survey/save.php
mod/survey/view.php

index cd220661486d375c4e87453c18618b586328d7db..5a0625400adbdba4319e77854d704d588433693a 100644 (file)
         <TR VALIGN=top>
             <TD ALIGN=right NOWRAP>
                 <P><B><? print_string("introtext", "survey") ?>:</B></P><BR>
-                <? helpbutton("text", get_string("helptext")) ?>
+                <font SIZE="1">
+                <? helpbutton("writing", get_string("helpwriting"), "moodle", true, true) ?><br \>
+                <? helpbutton("text", get_string("helptext"), "moodle", true, true) ?><br \>
+                </font>
             </TD>
             <TD>
                 <TEXTAREA NAME="intro" ROWS=20 COLS=50 WRAP="virtual"><? 
index 8c90bdf21fcfc3ab1409dbc763f77ece57935b60..f7044c8325a88b228194522a23893314d1c4a670 100644 (file)
@@ -30,7 +30,7 @@
 
 // Get all the questions and their proper order
 
-    $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
+    $questions = get_records_list("survey_questions", "id", $survey->questions);
     $order = explode(",", $survey->questions);
 
     foreach ($order as $key => $qid) {  // Do we have virtual scales?
@@ -63,7 +63,7 @@
         }
     }
 
-    $fullquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($fullorderlist)");
+    $fullquestions = get_records_list("survey_questions", "id", $fullorderlist);
 
 //  Question type of multi-questions overrides the type of single questions
     foreach ($order as $key => $qid) {
             if (! $u = get_record("user", "id", $user)) {
                 error("Error finding student # $user");
             }
-            if ($n = get_record_sql("SELECT * FROM survey_analysis WHERE survey='$survey->id' AND user='$user'")) {
+            if ($n = get_record("survey_analysis", "survey", $survey->id, "user", $user)) {
                 $notes = $n->notes;
             } else {
                 $notes = "No notes made";
 // Print all the lines of data.
 
     foreach ($results as $user => $rest) {
-        if (! $u = get_record_sql("SELECT firstname,lastname,email,idnumber FROM user WHERE id = '$user'")) {
+        if (! $u = get_record("user", "id", $user)) {
             error("Error finding student # $user");
         }
         echo $survey->id."\t";
index d12d3eadf96a68264d75e55b2cf00a0b395b4626..8c9ee557cc23f0d670edc3111732576b563c8ad0 100644 (file)
            $buckets2[$key] = 0;
        }
 
-       $aa = $db->Execute("SELECT * FROM survey_answers WHERE survey = $cm->instance AND question = $qid");
-
-       while (!$aa->EOF) {
-           if ($a1 = $aa->fields["answer1"]) {
-               $buckets1[$a1 - 1]++;
-           }
-           if ($a2 = $aa->fields["answer2"]) {
-               $buckets2[$a2 - 1]++;
+       if ($aaa = get_records_select("survey_answers", "survey = '$cm->instance' AND question = '$qid'")) {
+           foreach ($aaa as $aa) {
+               if ($a1 = $aa->answer1) {
+                   $buckets1[$a1 - 1]++;
+               }
+               if ($a2 = $aa->answer2) {
+                   $buckets2[$a2 - 1]++;
+               }
            }
-           $aa->MoveNext();
        }
 
        
        $options = explode(",",$question->options);
        $questionorder = explode( ",", $question->multi);
 
-       $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
+       $qqq = get_records_list("survey_questions", "id", $question->multi);
 
        foreach ($questionorder as $i => $val) {
            $names[$i] = get_string($qqq["$val"]->shorttext, "survey");
            $indexof[$val] = $i;
        }
 
-       $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($question->multi)))");
+       $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($question->multi)))");
 
-       foreach ($aaa as $a) {
-           $index = $indexof[$a->question];
-           if ($a->answer1) {
-               $buckets1[$index] += $a->answer1;
-               $count1[$index]++;
-           }
-           if ($a->answer2) {
-               $buckets2[$index] += $a->answer2;
-               $count2[$index]++;
+       if ($aaa) {
+           foreach ($aaa as $a) {
+               $index = $indexof[$a->question];
+               if ($a->answer1) {
+                   $buckets1[$index] += $a->answer1;
+                   $count1[$index]++;
+               }
+               if ($a->answer2) {
+                   $buckets2[$index] += $a->answer2;
+                   $count2[$index]++;
+               }
            }
        }
 
            }
        }
 
-       foreach ($aaa as $a) {
-           $index = $indexof[$a->question];
-           if ($a->answer1) {
-               $difference = (float) ($a->answer1 - $buckets1[$index]);
-               $stdev1[$index] += ($difference * $difference);
-           }
-           if ($a->answer2) {
-               $difference = (float) ($a->answer2 - $buckets2[$index]);
-               $stdev2[$index] += ($difference * $difference);
+       if ($aaa) {
+           foreach ($aaa as $a) {
+               $index = $indexof[$a->question];
+               if ($a->answer1) {
+                   $difference = (float) ($a->answer1 - $buckets1[$index]);
+                   $stdev1[$index] += ($difference * $difference);
+               }
+               if ($a->answer2) {
+                   $difference = (float) ($a->answer2 - $buckets2[$index]);
+                   $stdev2[$index] += ($difference * $difference);
+               }
            }
        }
 
     
      case "overall.png":
 
-       $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions) AND multi <> ''");
+       $qqq = get_records_list("survey_questions", "id", $survey->questions);
 
        foreach ($qqq as $key => $qq) {
-           $qqq[$key]->text = get_string($qq->text, "survey");
-           $qqq[$key]->options = get_string($qq->options, "survey");
-           if ($qq->type < 0) {
-               $virtualscales = true;
+           if ($qq->multi) {
+               $qqq[$key]->text = get_string($qq->text, "survey");
+               $qqq[$key]->options = get_string($qq->options, "survey");
+               if ($qq->type < 0) {
+                   $virtualscales = true;
+               }
            }
        }
        foreach ($qqq as $qq) {         // if any virtual, then use JUST virtual, else use JUST nonvirtual
-           if ($virtualscales && $qq->type < 0) {
-               $question[] = $qq;
-           } else if (!$virtualscales && $qq->type > 0) {
-               $question[] = $qq;
+           if ($qq->multi) {
+               if ($virtualscales && $qq->type < 0) {
+                   $question[] = $qq;
+               } else if (!$virtualscales && $qq->type > 0) {
+                   $question[] = $qq;
+               }
            }
        }
        $numquestions = count($question);
            $count1[$i] = 0;
            $count2[$i] = 0;
            $subquestions = $question[$i]->multi;   // otherwise next line doesn't work
-           $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($subquestions)))");
+           $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($subquestions)))");
 
-           foreach ($aaa as $a) {
-               if ($a->answer1) {
-                   $buckets1[$i] += $a->answer1;
-                   $count1[$i]++;
-               }
-               if ($a->answer2) {
-                   $buckets2[$i] += $a->answer2;
-                   $count2[$i]++;
+           if ($aaa) {
+               foreach ($aaa as $a) {
+                   if ($a->answer1) {
+                       $buckets1[$i] += $a->answer1;
+                       $count1[$i]++;
+                   }
+                   if ($a->answer2) {
+                       $buckets2[$i] += $a->answer2;
+                       $count2[$i]++;
+                   }
                }
            }
 
            }
 
            // Calculate the standard devaiations
-           foreach ($aaa as $a) {
-               if ($a->answer1) {
-                   $difference = (float) ($a->answer1 - $buckets1[$i]);
-                   $stdev1[$i] += ($difference * $difference);
-               }
-               if ($a->answer2) {
-                   $difference = (float) ($a->answer2 - $buckets2[$i]);
-                   $stdev2[$i] += ($difference * $difference);
+           if ($aaa) {
+               foreach ($aaa as $a) {
+                   if ($a->answer1) {
+                       $difference = (float) ($a->answer1 - $buckets1[$i]);
+                       $stdev1[$i] += ($difference * $difference);
+                   }
+                   if ($a->answer2) {
+                       $difference = (float) ($a->answer2 - $buckets2[$i]);
+                       $stdev2[$i] += ($difference * $difference);
+                   }
                }
            }
 
 
      case "student.png":
 
-       $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions) AND multi <> ''");
+       $qqq = get_records_list("survey_questions", "id", $survey->questions);
 
        foreach ($qqq as $key => $qq) {
-           $qqq[$key]->text = get_string($qq->text, "survey");
-           $qqq[$key]->options = get_string($qq->options, "survey");
-           if ($qq->type < 0) {
-               $virtualscales = true;
+           if ($qq->multi) {
+               $qqq[$key]->text = get_string($qq->text, "survey");
+               $qqq[$key]->options = get_string($qq->options, "survey");
+               if ($qq->type < 0) {
+                   $virtualscales = true;
+               }
            }
        }
        foreach ($qqq as $qq) {         // if any virtual, then use JUST virtual, else use JUST nonvirtual
-           if ($virtualscales && $qq->type < 0) {
-               $question[] = $qq;
-           } else if (!$virtualscales && $qq->type > 0) {
-               $question[] = $qq;
+           if ($qq->multi) {
+               if ($virtualscales && $qq->type < 0) {
+                   $question[] = $qq;
+               } else if (!$virtualscales && $qq->type > 0) {
+                   $question[] = $qq;
+               }
            }
        }
        $numquestions= count($question);
            $studbuckets2[$i] = 0.0;
            $studcount1[$i] = 0;
            $studcount2[$i] = 0;
-           $subquestions = $question[$i]->multi;   // otherwise next line doesn't work
-           $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($subquestions)))");
 
-           foreach ($aaa as $a) {
-               if ($a->user == $sid) {
+           $subquestions = $question[$i]->multi;   // otherwise next line doesn't work
+           $aaa = get_records_select("survey_answers","((survey = $cm->instance) AND (question in ($subquestions)))");
+
+           if ($aaa) {
+               foreach ($aaa as $a) {
+                   if ($a->user == $sid) {
+                       if ($a->answer1) {
+                           $studbuckets1[$i] += $a->answer1;
+                           $studcount1[$i]++;
+                       }
+                       if ($a->answer2) {
+                           $studbuckets2[$i] += $a->answer2;
+                           $studcount2[$i]++;
+                       }
+                   }
                    if ($a->answer1) {
-                       $studbuckets1[$i] += $a->answer1;
-                       $studcount1[$i]++;
+                       $buckets1[$i] += $a->answer1;
+                       $count1[$i]++;
                    }
                    if ($a->answer2) {
-                       $studbuckets2[$i] += $a->answer2;
-                       $studcount2[$i]++;
+                       $buckets2[$i] += $a->answer2;
+                       $count2[$i]++;
                    }
                }
-               if ($a->answer1) {
-                   $buckets1[$i] += $a->answer1;
-                   $count1[$i]++;
-               }
-               if ($a->answer2) {
-                   $buckets2[$i] += $a->answer2;
-                   $count2[$i]++;
-               }
            }
 
            if ($count1[$i]) {
        $options = explode(",",$question->options);
        $questionorder = explode( ",", $question->multi);
 
-       $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
+       $qqq = get_records_list("survey_questions", "id", $question->multi);
 
        foreach ($questionorder as $i => $val) {
            $names[$i] = get_string($qqq[$val]->shorttext, "survey");
            $studcount2[$i] = 0;
        }
 
-       $aaa = get_records_sql("SELECT * FROM survey_answers WHERE ((survey = $cm->instance) AND (question in ($question->multi)))");
+       $aaa = get_records_select("survey_answers", "((survey = $cm->instance) AND (question in ($question->multi)))");
 
-       foreach ($aaa as $a) {
-           $index = $indexof[$a->question];
-               if ($a->user == $sid) {
-                   if ($a->answer1) {
-                       $studbuckets1[$index] += $a->answer1;
-                       $studcount1[$index]++;
-                   }
-                   if ($a->answer2) {
-                       $studbuckets2[$index] += $a->answer2;
-                       $studcount2[$index]++;
+       if ($aaa) {
+           foreach ($aaa as $a) {
+               $index = $indexof[$a->question];
+                   if ($a->user == $sid) {
+                       if ($a->answer1) {
+                           $studbuckets1[$index] += $a->answer1;
+                           $studcount1[$index]++;
+                       }
+                       if ($a->answer2) {
+                           $studbuckets2[$index] += $a->answer2;
+                           $studcount2[$index]++;
+                       }
                    }
+               if ($a->answer1) {
+                   $buckets1[$index] += $a->answer1;
+                   $count1[$index]++;
+               }
+               if ($a->answer2) {
+                   $buckets2[$index] += $a->answer2;
+                   $count2[$index]++;
                }
-           if ($a->answer1) {
-               $buckets1[$index] += $a->answer1;
-               $count1[$index]++;
-           }
-           if ($a->answer2) {
-               $buckets2[$index] += $a->answer2;
-               $count2[$index]++;
            }
        }
 
index 9cbcd74c615f70b5a83e1789888b3b314745d366..931e99355f1a59e39105fd02bb15540ec1b368cd 100644 (file)
@@ -78,7 +78,7 @@ function survey_delete_instance($id) {
 }
 
 function survey_user_outline($course, $user, $mod, $survey) {
-    if ($answers = get_records_sql("SELECT * FROM survey_answers WHERE survey='$survey->id' AND user='$user->id'")) {
+    if ($answers = get_records_select("survey_answers", "survey='$survey->id' AND user='$user->id'")) {
 
         $lastanswer = array_pop($answers);
 
@@ -108,9 +108,7 @@ function survey_print_recent_activity(&$logs, $isteacher=false) {
 
     foreach ($logs as $log) {
         if ($log->module == "survey" and $log->action == "submit") {
-            $surveys[$log->id] = get_record_sql("SELECT s.name, u.firstname, u.lastname
-                                                 FROM survey s, user u
-                                                 WHERE s.id = '$log->info' AND u.id = '$log->user'");
+            $surveys[$log->id] = survey_log_info($log);
             $surveys[$log->id]->time = $log->time;
             $surveys[$log->id]->url = $log->url;
         }
@@ -132,20 +130,74 @@ function survey_print_recent_activity(&$logs, $isteacher=false) {
 }
 
 
-// MODULE FUNCTIONS ////////////////////////////////////////////////////////
+// SQL FUNCTIONS ////////////////////////////////////////////////////////
 
-function survey_already_done($survey, $user) {
-   return record_exists_sql("SELECT * FROM survey_answers WHERE survey='$survey' AND user='$user'");
-}
 
+function survey_log_info($log) {
+    global $CFG;
+    return get_record_sql("SELECT s.name, u.firstname, u.lastname
+                             FROM {$CFG->prefix}survey s, 
+                                  {$CFG->prefix}user u
+                            WHERE s.id = '$log->info' 
+                              AND u.id = '$log->user'");
+}
 
 function survey_get_responses($survey) {
+    global $CFG;
     return get_records_sql("SELECT a.time as time, count(*) as numanswers, u.*
-                            FROM survey_answers AS a, user AS u
-                            WHERE a.answer1 <> '0' AND a.answer2 <> '0'
-                                  AND a.survey = $survey 
-                                  AND a.user = u.id
-                            GROUP BY a.user ORDER BY a.time ASC");
+                              FROM {$CFG->prefix}survey_answers AS a, 
+                                   {$CFG->prefix}user AS u
+                             WHERE a.answer1 <> '0' AND a.answer2 <> '0'
+                                   AND a.survey = $survey 
+                                   AND a.user = u.id
+                          GROUP BY a.user 
+                          ORDER BY a.time ASC");
+}
+
+function survey_get_analysis($survey, $user) {
+    global $db, $CFG;
+
+    return get_record_sql("SELECT notes 
+                             FROM {$CFG->prefix}survey_analysis 
+                            WHERE survey='$survey' 
+                              AND user='$user'");
+}
+
+function survey_update_analysis($survey, $user, $notes) {
+    global $db, $CFG;
+
+    return $db->Execute("UPDATE {$CFG->prefix}survey_analysis 
+                            SET notes='$notes' 
+                          WHERE survey='$survey' 
+                            AND user='$user'");
+}
+
+
+function survey_add_analysis($survey, $user, $notes) {
+    global $db, $CFG;
+
+    return $db->Execute("INSERT INTO {$CFG->prefix}survey_analysis 
+                                 SET notes='$notes', 
+                                     survey='$survey', 
+                                     user='$user'");
+}
+
+function survey_get_user_answers($surveyid, $questionid) {
+    global $CFG;
+
+    return get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture 
+                              FROM survey_answers sa, 
+                                   user u 
+                             WHERE sa.survey = '$surveyid' 
+                               AND sa.question = $questionid 
+                               AND u.id = sa.user 
+                          ORDER BY sa.answer1,sa.answer2 ASC");
+}
+
+// MODULE FUNCTIONS ////////////////////////////////////////////////////////
+
+function survey_already_done($survey, $user) {
+   return record_exists("survey_answers", "survey", $survey, "user", $user);
 }
 
 function survey_count_responses($survey) {
@@ -179,8 +231,8 @@ function survey_get_template_name($templateid) {
     global $db;
 
     if ($templateid) {
-        if ($ss = $db->Execute("SELECT name FROM surveys WHERE id = $templateid")) {
-            return $ss->fields["name"];
+        if ($ss = get_record("surveys", "id", $templateid)) {
+            return $ss->name;
         }
     } else {
         return "";
@@ -188,24 +240,6 @@ function survey_get_template_name($templateid) {
 }
 
 
-function survey_get_analysis($survey, $user) {
-    global $db;
-
-    return get_record_sql("SELECT notes from survey_analysis WHERE survey='$survey' and user='$user'");
-}
-
-function survey_update_analysis($survey, $user, $notes) {
-    global $db;
-
-    return $db->Execute("UPDATE survey_analysis SET notes='$notes' WHERE survey='$survey' and user='$user'");
-}
-
-
-function survey_add_analysis($survey, $user, $notes) {
-    global $db;
-
-    return $db->Execute("INSERT INTO survey_analysis SET notes='$notes', survey='$survey', user='$user'");
-}
 
 function survey_shorten_name ($name, $numwords) {
     $words = explode(" ", $name);
@@ -249,7 +283,7 @@ function survey_print_multi($question) {
     }
     echo "<TD ALIGN=CENTER BGCOLOR=\"$THEME->body\">&nbsp</TD></TR>\n";
 
-    $subquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi) ");
+    $subquestions = get_records_list("survey_questions", "id", $question->multi);
 
     foreach ($subquestions as $q) {
         $qnum++;
index f61014fc8cfcf3302ffba0b0a0610a65b3e88a6e..e45cd6b160de3bbe914f394b8bc97dbebb17d4b5 100644 (file)
@@ -10,7 +10,7 @@
     <td align=right><P><B><? print_string("surveytype", "survey") ?>:</B></P></TD>
     <td>
     <?
-        if ($options = get_records_sql_menu("SELECT id, name FROM survey WHERE template='0'")) {
+        if ($options = get_records_menu("survey", "template", 0, "name", "id, name")) {
             foreach ($options as $id => $name) {
                 $options[$id] = get_string($name, "survey");
             }
index 57f1e87f4ca5861a0ac6d1bcef3cf19be0586bbd..a15e057fa11488401180566829882aae47a15da1 100644 (file)
       case "scales":
         print_header("$survey->name: $strscales", "$strallscales");
 
-        $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
+        $questions = get_records_list("survey_questions", "id", $survey->questions);
         $questionorder = explode(",", $survey->questions);
 
         foreach ($questionorder as $key => $val) {
       case "questions":
 
         if ($qid) {     // just get one multi-question
-            $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($qid)");
+            $questions = get_records_list("survey_questions", "id", $qid);
             $questionorder = explode(",", $qid);
 
             if ($scale = get_records("survey_questions", "multi", "$qid")) {
             }
 
         } else {        // get all top-level questions
-            $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
+            $questions = get_records_list("survey_questions", "id", $survey->questions);
             $questionorder = explode(",", $survey->questions);
 
             print_header("$survey->name: $strquestions", "$strallquestions");
             if ($question->multi) {
                 echo "<H3>$question->text :</H3>";
 
-                $subquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)");
+                $subquestions = get_records_list("survey_questions", "id", $question->multi);
                 $subquestionorder = explode(",", $question->multi);
                 foreach ($subquestionorder as $key => $val) {
                     $subquestion = $subquestions[$val];
                            BORDER=1 SRC=\"graph.php?id=$id&qid=$question->id&type=question.png\"></A></P>";
             } else {
                 echo "<H3>$question->text</H3>";
-                if ($aaa = get_records_sql("SELECT sa.*, u.firstname,u.lastname FROM survey_answers sa, user u WHERE survey = '$survey->id' AND question = $question->id and sa.user = u.id")) {
+                if ($aaa = survey_get_user_answers($survey->id, $question->id)) {
                     echo "<UL>";
                     foreach ($aaa as $a) {
                         echo "<LI>$a->firstname $a->lastname: $a->answer1";
 
         print_header("$survey->name: $strquestion", "$strquestion: $question->text");
 
-        $aaa = get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture FROM survey_answers sa, user u WHERE sa.survey = '$survey->id' AND sa.question = $question->id AND u.id = sa.user ORDER by sa.answer1,sa.answer2 ASC");
 
         $strname = get_string("name", "survey");
         $strtime = get_string("time", "survey");
         $strpreferred = get_string("preferred", "survey");
 
         echo "<TABLE ALIGN=center CELLPADDING=0 CELLSPACING=10><TR><TD>&nbsp;<TH align=left>$strname<TH align=left>$strtime<TH align=left>$stractual<TH align=left>$strpreferred</TR>";
-        foreach ($aaa as $a) {
-            echo "<TR>";
-            echo "<TD WIDTH=35>";
-            print_user_picture($a->user, $course->id, $a->picture, false);
-            echo "</TD>";
-            echo "<TD><P><A HREF=\"report.php?id=$id&action=student&student=$a->user\">$a->firstname $a->lastname</A></TD>";
-            echo "<TD><P>".userdate($a->time, "%d %B %Y, %I:%M %p")."</TD>";
-            echo "<TD BGCOLOR=\"$THEME->cellcontent\"><P>";
-            if ($a->answer1) {
-                echo "$a->answer1 - ".$answers[$a->answer1 - 1];
-            } else {
-                echo "&nbsp;";
-            }
-            echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\"><P>";
-            if ($a->answer2) {
-                echo "$a->answer2 - ".$answers[$a->answer2 - 1];
-            } else {
-                echo "&nbsp;";
-            }
-            echo "</TD></TR>";
 
+        if ($aaa = survey_get_user_answers($survey->id, $question->id)) {
+            foreach ($aaa as $a) {
+                echo "<TR>";
+                echo "<TD WIDTH=35>";
+                print_user_picture($a->user, $course->id, $a->picture, false);
+                echo "</TD>";
+                echo "<TD><P><A HREF=\"report.php?id=$id&action=student&student=$a->user\">$a->firstname $a->lastname</A></TD>";
+                echo "<TD><P>".userdate($a->time, "%d %B %Y, %I:%M %p")."</TD>";
+                echo "<TD BGCOLOR=\"$THEME->cellcontent\"><P>";
+                if ($a->answer1) {
+                    echo "$a->answer1 - ".$answers[$a->answer1 - 1];
+                } else {
+                    echo "&nbsp;";
+                }
+                echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\"><P>";
+                if ($a->answer2) {
+                    echo "$a->answer2 - ".$answers[$a->answer2 - 1];
+                } else {
+                    echo "&nbsp;";
+                }
+                echo "</TD></TR>";
+    
+            }
         }
-        echo "</TABLE>";
 
+        echo "</TABLE>";
 
         print_footer($course);
         break;
          echo "<P ALIGN=CENTER><IMG HEIGHT=$SURVEY_GHEIGHT WIDTH=$SURVEY_GWIDTH ALIGN=CENTER SRC=\"graph.php?id=$id&sid=$student&type=student.png\"></P>";
          
          // Print scales
-         $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)");
+         $questions = get_records_list("survey_questions", "id", $survey->questions);
          $questionorder = explode(",", $survey->questions);
  
          foreach ($questionorder as $key => $val) {
index 5af81ef9c1c7fed1de97d21ccc7818b1c47697cf..5e56aef4e4399631819edcb1e7afe2dbd79a1e80 100644 (file)
 
     $timenow = time();
     foreach ($answers as $key => $val) {
-        $val1 = $val[0]; $val2 = $val[1];
-        if (! $result = $db->Execute("INSERT INTO survey_answers 
-                         (time, user, survey, question, answer1, answer2) 
-                         VALUES ('$timenow', '$USER->id', '$survey->id', '$key', '$val1', '$val2')") ) {
+
+        $newdata->time = $timenow;
+        $newdata->user = $USER->id;
+        $newdata->survey = $survey->id;
+        $newdata->question = $key;
+        $newdata->answer1 = $val[0];
+        $newdata->answer2 = $val[1];
+
+        if (! insert_record("survey_answers", $newdata)) {
             error("Encountered a problem trying to store your results. Sorry.");
         }
     }
index c243466187663419b8aa2f2416dced8a09c35b19..df13ce0263385ba7eeff1521584bfa36215141b3 100644 (file)
@@ -45,7 +45,7 @@
         $numusers = survey_count_responses($survey->id);
         print_heading(get_string("peoplecompleted", "survey", $numusers));
         echo "<CENTER>";
-        echo "<IMG SRC=\"$CFG->wwwroot/mod/survey/graph.php?id=$cm->id&sid=$USER->id&type=student.png\">";
+        echo "<IMG HEIGHT=\"$SURVEY_GHEIGHT\" WIDTH=\"$SURVEY_GWIDTH\" SRC=\"$CFG->wwwroot/mod/survey/graph.php?id=$cm->id&sid=$USER->id&type=student.png\">";
         echo "</CENTER>";
         print_footer($course);
         exit;
@@ -60,7 +60,7 @@
     print_simple_box(text_to_html($survey->intro), "center", "80%");
 
 // Get all the major questions and their proper order
-    if (! $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)")) {
+    if (! $questions = get_records_list("survey_questions", "id", $survey->questions)) {
         error("Couldn't find any questions in this survey!!");
     }
     $questionorder = explode( ",", $survey->questions);