From: martin Date: Thu, 1 Aug 2002 05:18:07 +0000 (+0000) Subject: More cleanups to survey - renamed/moved functions, modernised mod.php X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0e30c987e5a91e68f55cdfdc0de945330e6df7e6;p=moodle.git More cleanups to survey - renamed/moved functions, modernised mod.php --- diff --git a/mod/survey/graph.php b/mod/survey/graph.php index d8e34b1adb..368cae985e 100644 --- a/mod/survey/graph.php +++ b/mod/survey/graph.php @@ -102,7 +102,7 @@ $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)"); foreach ($questionorder as $i => $val) { - $names[$i] = shorten_name($qqq["$val"]->text, 4); + $names[$i] = survey_shorten_name($qqq["$val"]->text, 4); $buckets1[$i] = 0; $buckets2[$i] = 0; $count1[$i] = 0; @@ -496,7 +496,7 @@ $qqq = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)"); foreach ($questionorder as $i => $val) { - $names[$i] = shorten_name($qqq["$val"]->text, 4); + $names[$i] = survey_shorten_name($qqq["$val"]->text, 4); $buckets1[$i] = 0; $buckets2[$i] = 0; $count1[$i] = 0; @@ -635,12 +635,5 @@ exit; -function shorten_name ($name, $numwords) { - $words = explode(" ", $name); - for ($i=0; $i < $numwords; $i++) { - $output .= $words[$i]." "; - } - return $output; -} ?> diff --git a/mod/survey/lib.php b/mod/survey/lib.php index 0811b50f19..c4f0856eb1 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -103,6 +103,13 @@ function survey_add_analysis($survey, $user, $notes) { return $db->Execute("INSERT INTO survey_analysis SET notes='$notes', survey='$survey', user='$user'"); } +function survey_shorten_name ($name, $numwords) { + $words = explode(" ", $name); + for ($i=0; $i < $numwords; $i++) { + $output .= $words[$i]." "; + } + return $output; +} function survey_user_summary($course, $user, $mod, $survey) { global $CFG; @@ -132,4 +139,125 @@ function survey_user_complete($course, $user, $mod, $survey) { } } + +function survey_print_multi($question) { + GLOBAL $db, $qnum, $checklist, $THEME; + + + echo "

 

\n"; + echo "

$question->text

"; + + echo ""; + + $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 ""; + } else { + echo ""; + } + + while (list ($key, $val) = each ($options)) { + echo "\n"; + } + 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 ""; + if ($oneanswer) { + echo ""; + echo ""; + for ($i=1;$i<=$numoptions;$i++) { + echo ""; + } + echo ""; + $checklist["q$P$q->id"] = $numoptions; + + } else { + echo ""; + echo ""; + echo ""; + for ($i=1;$i<=$numoptions;$i++) { + echo ""; + } + echo ""; + echo ""; + + echo ""; + echo ""; + for ($i=1;$i<=$numoptions;$i++) { + echo ""; + } + echo ""; + $checklist["qP$q->id"] = $numoptions; + $checklist["q$q->id"] = $numoptions; + } + echo "\n"; + } + echo "

$question->intro

$question->intro

$val

body\"> 

$qnum

$q->text

id VALUE=$i>id VALUE=0 checked>

$qnum

I prefer that 

$q->text

id VALUE=$i>body\">id VALUE=0 checked>

I found that 

id VALUE=$i>body\">id VALUE=0 checked>
"; +} + + + +function survey_print_single($question) { + GLOBAL $db, $qnum; + + $bgcolor = survey_question_color(0); + + $qnum++; + + echo "

 

\n"; + echo "\n"; + echo ""; + echo ""; + echo "\n"; + echo "
$qnum

$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

"; + } + + 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(' 

\n"; - echo "

$question->text

"; - - echo ""; - - $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 ""; - } else { - echo ""; - } - - while (list ($key, $val) = each ($options)) { - echo "\n"; - } - echo "\n"; - - $subquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi) "); - - foreach ($subquestions as $q) { - $qnum++; - $bgcolor = question_color($qnum); - - echo ""; - if ($oneanswer) { - echo ""; - echo ""; - for ($i=1;$i<=$numoptions;$i++) { - echo ""; - } - echo ""; - $checklist["q$P$q->id"] = $numoptions; - - } else { - echo ""; - echo ""; - echo ""; - for ($i=1;$i<=$numoptions;$i++) { - echo ""; - } - echo ""; - echo ""; - - echo ""; - echo ""; - for ($i=1;$i<=$numoptions;$i++) { - echo ""; - } - echo ""; - $checklist["qP$q->id"] = $numoptions; - $checklist["q$q->id"] = $numoptions; - } - echo "\n"; - } - echo "

$question->intro

$question->intro

$val

body\"> 

$qnum

$q->text

id VALUE=$i>id VALUE=0 checked>

$qnum

I prefer that 

$q->text

id VALUE=$i>body\">id VALUE=0 checked>

I found that 

id VALUE=$i>body\">id VALUE=0 checked>
"; -} - - - -function print_single($question) { - GLOBAL $db, $qnum; - - $bgcolor = question_color(0); - - $qnum++; - - echo "

 

\n"; - echo "\n"; - echo ""; - echo ""; - echo "\n"; - echo "
$qnum

$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

"; - } - - echo "
"; - -} - -function question_color($qnum) { - global $THEME; - - if ($qnum) { - return $qnum % 2 ? $THEME->cellcontent : $THEME->cellcontent2; - //return $qnum % 2 ? "#CCFFCC" : "#CCFFFF"; - } else { - return $THEME->cellcontent; - } -} - ?>