From: martin   $question->text $question->intro $question->intro $val $qnum $q->text $qnum I prefer that $q->text I found that   $question->text \n";
+
+
+ if ($question->type == 0) { // Plain text field
+ echo "";
+
+ } else if ($question->type > 0) { // Choose one of a number
+ echo "";
+
+ } else if ($question->type < 0) { // Choose several of a number
+ $options = explode( ",", $question->options);
+ echo " THIS TYPE OF QUESTION NOT SUPPORTED YET";
+
+ $options = explode( ",", $question->options);
+ $numoptions = count($options);
+
+ $oneanswer = ($question->type == 1 || $question->type == 2) ? true : false;
+ if ($question->type == 2) {
+ $P = "P";
+ } else {
+ $P = "";
+ }
+
+ if ($oneanswer) {
+ echo "
";
+}
+
+
+
+function survey_print_single($question) {
+ GLOBAL $db, $qnum;
+
+ $bgcolor = survey_question_color(0);
+
+ $qnum++;
+
+ echo " ";
+ } else {
+ echo " \n";
+
+ $subquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi) ");
+
+ foreach ($subquestions as $q) {
+ $qnum++;
+ $bgcolor = survey_question_color($qnum);
+
+ echo " ";
+ }
+
+ while (list ($key, $val) = each ($options)) {
+ echo " \n";
+ }
+ echo "body\">  ";
+ if ($oneanswer) {
+ echo " ";
+
+ echo " ";
+ echo " ";
+ for ($i=1;$i<=$numoptions;$i++) {
+ echo "id VALUE=$i> ";
+ }
+ echo "id VALUE=0 checked> ";
+ $checklist["q$P$q->id"] = $numoptions;
+
+ } else {
+ echo " ";
+ echo " ";
+ echo " ";
+ for ($i=1;$i<=$numoptions;$i++) {
+ echo "id VALUE=$i> ";
+ }
+ echo "body\">id VALUE=0 checked> ";
+ echo "";
+ echo " \n";
+ }
+ echo " ";
+ for ($i=1;$i<=$numoptions;$i++) {
+ echo "id VALUE=$i> ";
+ }
+ echo "body\">id VALUE=0 checked> ";
+ $checklist["qP$q->id"] = $numoptions;
+ $checklist["q$q->id"] = $numoptions;
+ }
+ echo "\n";
+ echo "
";
+
+}
+
+function survey_question_color($qnum) {
+ global $THEME;
+
+ if ($qnum) {
+ return $qnum % 2 ? $THEME->cellcontent : $THEME->cellcontent2;
+ //return $qnum % 2 ? "#CCFFCC" : "#CCFFFF";
+ } else {
+ return $THEME->cellcontent;
+ }
+}
+
?>
diff --git a/mod/survey/mod.php b/mod/survey/mod.php
index 973bff3771..9534d546c5 100644
--- a/mod/survey/mod.php
+++ b/mod/survey/mod.php
@@ -14,34 +14,17 @@ function add_instance($survey) {
// (defined by the form in mod.html) this function
// will create a new instance and return the id number
// of the new instance.
-//
- GLOBAL $db;
-
- $timenow = time();
if (!$template = get_record("survey", "id", $survey->template)) {
return 0;
}
- if (!$rs = $db->Execute("INSERT into survey
- SET course = '$survey->course',
- name = '$survey->name',
- days = '$survey->days',
- intro = '$survey->intro',
- template = '$template->id',
- questions = '$template->questions',
- timecreated = '$timenow',
- timemodified = '$timenow' ")) {
- return 0;
- }
-
- // Get it out again - this is the most compatible way to determine the ID
- if ($rs = $db->Execute("SELECT id FROM survey
- WHERE course = $survey->course AND timemodified = '$timenow'")) {
- return $rs->fields[0];
- } else {
- return 0;
- }
+ $survey->questions = $template->questions;
+ $survey->timecreated = time();
+ $survey->timemodified = $survey->timecreated;
+
+ return insert_record("survey", $survey);
+
}
@@ -49,42 +32,42 @@ function update_instance($survey) {
// Given an object containing all the necessary data,
// (defined by the form in mod.html) this function
// will update an existing instance with new data.
-//
- GLOBAL $db;
-
- $timenow = time();
if (!$template = get_record("survey", "id", $survey->template)) {
return 0;
}
- if (!$rs = $db->Execute("UPDATE survey
- SET name = '$survey->name',
- days = '$survey->days',
- intro = '$survey->intro',
- template = '$template->id',
- questions = '$template->questions',
- timemodified = '$timenow'
- WHERE id = '$survey->instance' ")) {
- return false;
- }
- return true;
-}
+ $survey->id = $survey->instance;
+ $survey->questions = $template->questions;
+ $survey->timemodified = time();
+ return update_record("survey", $survey);
+}
function delete_instance($id) {
// Given an ID of an instance of this module,
// this function will permanently delete the instance
// and any data that depends on it.
-//
- GLOBAL $db;
- if (!$rs = $db->Execute("DELETE from survey WHERE id = '$id' ")) {
+ if (! $survey = get_record("survey", "id", "$id")) {
return false;
}
- return true;
-
+ $result = true;
+
+ if (! delete_records("survey_analysis", "survey", "$survey->id")) {
+ $result = false;
+ }
+
+ if (! delete_records("survey_answers", "survey", "$survey->id")) {
+ $result = false;
+ }
+
+ if (! delete_records("survey", "id", "$survey->id")) {
+ $result = false;
+ }
+
+ return $result;
}
diff --git a/mod/survey/view.php b/mod/survey/view.php
index 5d010f9340..53a75ebf09 100644
--- a/mod/survey/view.php
+++ b/mod/survey/view.php
@@ -19,7 +19,6 @@
error("Survey ID was incorrect");
}
-
print_header("$course->shortname: $survey->name", "$course->fullname",
"id>$course->shortname ->
id>Surveys -> $survey->name", "", "", true,
@@ -67,9 +66,9 @@
if ($question->type > 0) {
if ($question->multi) {
- print_multi($question);
+ survey_print_multi($question);
} else {
- print_single($question);
+ survey_print_single($question);
}
}
}
@@ -119,130 +118,4 @@ document.write(' ";
+ echo " $qnum ";
+ echo " \n";
+ echo "
$question->text
"; - - echo "$question->intro | ";
- } else {
- echo "||||||||
$question->intro | ";
- }
-
- while (list ($key, $val) = each ($options)) {
- echo "$val | \n";
- }
- echo "body\">  | ||||||
$qnum | ";
- echo "$q->text | ";
- for ($i=1;$i<=$numoptions;$i++) {
- echo "id VALUE=$i> | "; - } - echo "id VALUE=0 checked> | "; - $checklist["q$P$q->id"] = $numoptions; - - } else { - echo "$qnum | ";
- echo "I prefer that | ";
- echo "$q->text | ";
- for ($i=1;$i<=$numoptions;$i++) {
- echo "id VALUE=$i> | "; - } - echo "body\">id VALUE=0 checked> | "; - echo "
I found that | ";
- for ($i=1;$i<=$numoptions;$i++) {
- echo "id VALUE=$i> | "; - } - echo "body\">id VALUE=0 checked> | "; - $checklist["qP$q->id"] = $numoptions; - $checklist["q$q->id"] = $numoptions; - } - echo "
 
\n"; - echo "$qnum | "; - echo "$question->text | \n";
- echo "\n";
-
-
- if ($question->type == 0) { // Plain text field
- echo "";
-
- } else if ($question->type > 0) { // Choose one of a number
- echo "";
-
- } else if ($question->type < 0) { // Choose several of a number
- $options = explode( ",", $question->options);
- echo " THIS TYPE OF QUESTION NOT SUPPORTED YET |