From: martin Date: Thu, 1 Aug 2002 04:49:26 +0000 (+0000) Subject: Big clean up of survey functions and removal of deadwood (more to go still though) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=551b0b9806ccfeb88d0bc43d5839820f5f886c7c;p=moodle.git Big clean up of survey functions and removal of deadwood (more to go still though) --- diff --git a/mod/survey/edit.php b/mod/survey/edit.php deleted file mode 100644 index d7350e14c1..0000000000 --- a/mod/survey/edit.php +++ /dev/null @@ -1,284 +0,0 @@ -name\" was updated."); - unset($edit); - } - } else { - notify("Error: This page was called wrongly."); - } - } - - if ($edit == "delete") { - if ($id) { - - if (get_responses_for_survey($id) > 0) { - notify("Could not delete survey as it has responses"); - - } else if ($ss = $db->Execute("DELETE FROM surveys WHERE owner = $USER->id AND id = $id")) { - notify("The survey was deleted."); - - } else { - notify("Serious error: could not find any templates."); - } - - } else { - notify("Serious error: could not find any templates."); - } - unset($edit); - } - - - if ($edit == "add") { - if ($template) { - if ($tt = $db->Execute("SELECT * FROM surveys WHERE id = $template")) { - $survey = (object)$tt->fields; - $survey->owner = $USER->id; - $survey->name = ""; - $survey->template = $template; - add_survey($survey); - } else { - notify("Serious error: could not find template $template"); - } - } else { - unset($edit); - } - } - - if ($edit == "edit") { - if ($id) { - $survey = get_survey($id); - } else { - notify("Error: script called badly."); - die; - } - } - - if ($edit) { - $survey->status = get_survey_status($survey); - include("edit_form.phtml"); - - } else { - clean_up_surveys(); - print_list_of_my_surveys(); - print_additional_commands(); - } - print_footer($course); - - - - -/// FUNCTIONS ////////////////// - -function print_additional_commands() { - echo "

Add a new survey

"; -} - -function validate_form(&$survey, &$err) { - - if (empty($survey->id)) { - notify("A serious error occurred."); - die; - } - - if (empty($survey->name)) - $err["name"] = "Missing name"; - - if (empty($survey->password)) - $err["password"] = "Missing password"; - - else if ($survey->password == "changeme") - $err["password"] = "You should change this password"; - - settype($survey->days, "integer"); - - if ($survey->days < 0 || $survey->days > 365) - $err["days"] = "Must be a number between 0 and 365"; - - -} - -function add_survey(&$survey) { - - global $db, $USER; - - $timenow = time(); - - $survey->intro = addslashes($survey->intro); // to make sure - - $rs = $db->Execute("INSERT INTO surveys SET - timecreated = $timenow, - timemodified = $timenow, - template = '$survey->template', - course = '$survey->course', - owner = '$survey->owner', - name = '$survey->name', - password = '$survey->password', - intro = '$survey->intro', - url = '$survey->url', - questions = '$survey->questions' "); - - if (!$rs) { - notify("Could not insert a record"); - die; - } - -// Now get it out again (most compatible way to get the id) - - $rs = $db->Execute("SELECT * FROM surveys WHERE owner = $survey->owner AND timecreated = $timenow"); - if ($rs) { - $survey = (object) $rs->fields; - $survey->intro = stripslashes($survey->intro); - } else { - notify("Error: Could not find the record I just inserted!"); - die; - } -} - -function release_survey($id) { - - global $db; - - if ($ss = $db->Execute("SELECT * FROM surveys WHERE id = $id")) { - $survey = (object)$ss->fields; - } else { - notify("Serious error: could not find survey $id"); - die; - } - - $timenow = time(); - $timeend = $timenow + ($survey->days * 86400); - - if ($ss = $db->Execute("UPDATE surveys SET locked=1, timeopen = $timenow, timeclose = $timeend - WHERE id = $survey->id")) { - notify("The survey \"$survey->name\" was released and can no longer be edited."); - } else { - notify("An error occurred while releasing \"$survey->name\""); - } -} - - -function update_survey($survey) { - - global $db, $USER; - - $timenow = time(); - - $rs = $db->Execute("UPDATE surveys SET - timemodified = $timenow, - name = '$survey->name', - password = '$survey->password', - intro = '$survey->intro', - url = '$survey->url', - days = $survey->days - WHERE - id = $survey->id AND - owner = $USER->id "); - - if ($rs) { - return true; - } else { - notify("Could not update the survey!"); - die; - } -} - -function get_survey($id) { - global $db, $USER; - - if ($ss = $db->Execute("SELECT * FROM surveys WHERE id = $id AND owner = $USER->id")) { - $survey = (object)$ss->fields; - $survey->intro = stripslashes($survey->intro); - $survey->name = stripslashes($survey->name); - $survey->password = stripslashes($survey->password); - return $survey; - } else { - notify("Serious error: could not find specified survey."); - die; - } -} - - -function make_survey_menu($chosenid) { - global $db; - - $chosenname = get_template_name($chosenid); - if ($ss = $db->Execute("SELECT name,id FROM surveys WHERE owner = 0 ORDER BY id")) { - print $ss->GetMenu("template", $chosenname, true); - } else { - notify("Serious error: could not find any templates."); - } -} - -function clean_up_surveys() { - global $db, $USER; - - if (!$rs = $db->Execute("DELETE FROM surveys WHERE owner = $USER->id AND name = ''")) { - notify("Error: could not clean up surveys"); - } -} - - -function print_list_of_my_surveys() { - global $db, $USER; - - if ($rs = $db->Execute("SELECT * FROM surveys WHERE owner = $USER->id ORDER BY id")) { - if ($rs->RowCount()) { - echo "

Existing surveys

"; - echo ""; - echo ""; - while (!$rs->EOF) { - $survey = (object)$rs->fields; - - $numresponses = get_responses_for_survey($survey->id); - $templatename = get_template_name($survey->template); - $status = get_survey_status($survey); - - echo ""; - echo ""; - $rs->MoveNext(); - } - echo "

Survey name

Survey type

Details

Status

id\">$survey->name"; - echo "

$templatename"; - if ($status == "editing") { - echo "

id\">Edit"; - echo "

$status"; - echo "

id\">Release to students"; - } else { - echo "

id\">View"; - echo "

$status"; - echo "

id\">$numresponses responses"; - } - echo "

"; - } else { - echo "

You don't have any surveys yet

"; - } - } else { - notify("Error: could not list surveys"); - } - -} - -?> diff --git a/mod/survey/edit_form.html b/mod/survey/edit_form.html deleted file mode 100644 index df51f89cd7..0000000000 --- a/mod/survey/edit_form.html +++ /dev/null @@ -1,66 +0,0 @@ -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -

:

template) ?> - -

:

- -

:

- -

:

- -

:

- -

:

-
-
- - - status == "editing") { ?> - - - - - id) == 0) { ?> -
- - - -
- -
-
- -
-
-
- -
- diff --git a/mod/survey/edit_form.phtml b/mod/survey/edit_form.phtml deleted file mode 100644 index 50ed637360..0000000000 --- a/mod/survey/edit_form.phtml +++ /dev/null @@ -1,70 +0,0 @@ -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

(Click on the links below
for help on each field)

 

Survey type:

template) ?> - -

:

- -

:

- -

:

- -

:

- -

:

-
-
- - - status == "editing") { ?> - - - - - id) == 0) { ?> -
- - - -
- -
-
- -
-
-
- -
- diff --git a/mod/survey/edit_new.html b/mod/survey/edit_new.html deleted file mode 100644 index ff37e05bc0..0000000000 --- a/mod/survey/edit_new.html +++ /dev/null @@ -1,14 +0,0 @@ -
-

Choose a template for your new survey

- -

- -
- - - - -

- -

-
diff --git a/mod/survey/edit_new.phtml b/mod/survey/edit_new.phtml deleted file mode 100644 index 9d86be8a7b..0000000000 --- a/mod/survey/edit_new.phtml +++ /dev/null @@ -1,14 +0,0 @@ -
-

Choose a template for your new survey

- -

- -
- - - - -

- -

-
diff --git a/mod/survey/graph.php b/mod/survey/graph.php index a9f78cf2e3..d8e34b1adb 100644 --- a/mod/survey/graph.php +++ b/mod/survey/graph.php @@ -58,7 +58,7 @@ $maxbuckets2 = max($buckets2); $maxbuckets = ($maxbuckets1 > $maxbuckets2) ? $maxbuckets1 : $maxbuckets2; - $graph = new graph($GWIDTH,$GHEIGHT); + $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT); $graph->parameter['title'] = "$question->text"; $graph->x_data = $options; @@ -162,7 +162,7 @@ $maxbuckets2 = max($buckets2); - $graph = new graph($GWIDTH,$GHEIGHT); + $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT); $graph->parameter['title'] = "$question->text"; $graph->x_data = $names; @@ -287,7 +287,7 @@ $maxbuckets2 = max($buckets2); - $graph = new graph($GWIDTH,$GHEIGHT); + $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT); $graph->parameter['title'] = "$survey->name"; $graph->x_data = $names; @@ -433,7 +433,7 @@ $maxbuckets2 = max($buckets2); - $graph = new graph($GWIDTH,$GHEIGHT); + $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT); $graph->parameter['title'] = "$survey->name"; $graph->x_data = $names; @@ -578,7 +578,7 @@ $maxbuckets2 = max($buckets2); - $graph = new graph($GWIDTH,$GHEIGHT); + $graph = new graph($SURVEY_GWIDTH,$SURVEY_GHEIGHT); $graph->parameter['title'] = "$question->text"; $graph->x_data = $names; diff --git a/mod/survey/lib.php b/mod/survey/lib.php index fce203cade..63fab365a2 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -1,10 +1,10 @@ "Virtual Actual and Preferred", "-2" => "Virtual Preferred", "-1" => "Virtual Actual", @@ -18,7 +18,7 @@ function survey_already_done($survey, $user) { return record_exists_sql("SELECT * FROM survey_answers WHERE survey='$survey' AND user='$user'"); } -function get_survey_status($survey) { +function survey_get_status($survey) { $timenow = time(); if ($survey->locked) { @@ -35,22 +35,25 @@ function get_survey_status($survey) { } -function get_responses_for_survey($surveyid) { - global $db; +function survey_get_responses($survey) { + 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"); +} - if ($aa = $db->Execute("SELECT user FROM survey_answers WHERE survey = $surveyid GROUP BY user")) { - if ($aa) { - return $aa->RowCount(); - } else { - return -1; - } - } else { - return -1; - } +function survey_count_reponses($survey) { + if ($responses = survey_get_responses($survey)) { + return count($responses); + } else { + return 0; + } } -function print_all_responses($survey, $results) { +function survey_print_all_responses($survey, $results) { global $THEME; echo ""; @@ -67,26 +70,8 @@ function print_all_responses($survey, $results) { echo "
"; } - -function get_survey_responses($survey) { - 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"); -} -function count_completed_surveys($survey) { - if ($responses = get_survey_responses($survey)) { - return count($responses); - } else { - return 0; - } -} - - -function get_template_name($templateid) { +function survey_get_template_name($templateid) { global $db; if ($templateid) { @@ -99,14 +84,20 @@ function get_template_name($templateid) { } -function update_survey_analysis($survey, $user, $notes) { +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 add_survey_analysis($survey, $user, $notes) { +function survey_add_analysis($survey, $user, $notes) { global $db; return $db->Execute("INSERT INTO survey_analysis SET notes='$notes', survey='$survey', user='$user'"); diff --git a/mod/survey/login_form.html b/mod/survey/login_form.html deleted file mode 100644 index a2d5341346..0000000000 --- a/mod/survey/login_form.html +++ /dev/null @@ -1,65 +0,0 @@ -
-

You need to log in before you can fill out this survey

- - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - -

Survey Password:
(from your teacher)

- " > - -

Your first name:

- "> - -

Your last name:

- "> - -

Your email address:

- "> - -

Student ID Number:
(optional)

- "> - -
  -
- - -
- -
-
-
-
- -
-
- -

Home

- - diff --git a/mod/survey/report.php b/mod/survey/report.php index 30226e3a1d..a6f0648e12 100644 --- a/mod/survey/report.php +++ b/mod/survey/report.php @@ -53,7 +53,7 @@ echo "

Scales

"; echo "

Questions

"; echo "

Students

"; - if ($users = get_survey_responses($survey->id)) { + if ($users = survey_get_responses($survey->id)) { foreach ($users as $user) { echo "
  • "; echo "id&id=$id\">"; @@ -71,8 +71,8 @@ print_heading("All scales, all students"); - if (count_completed_surveys($survey->id)) { - echo "

    \"Click"; + if (survey_count_responses($survey->id)) { + echo "

    \"Click"; } else { echo "

    Nobody has yet completed this survey

    "; } @@ -102,7 +102,7 @@ continue; } echo "

    multi>"; - echo "\"Clickid&type=multiquestion.png\">"; echo "


    "; } @@ -151,13 +151,13 @@ $subquestion = $subquestions[$val]; if ($subquestion->type > 0) { echo "

    id\"> - \"Clickid&type=question.png\">

    "; } } } else if ($question->type > 0 ) { echo "

    id\"> - \"Clickid&type=question.png\">

    "; } else { echo "

    $question->text

    "; @@ -220,10 +220,10 @@ print_header("Analysis by Student", "$survey->name: Students", "", ""); - if (! $results = get_survey_responses($survey->id) ) { + if (! $results = survey_get_responses($survey->id) ) { notify("There are no responses for this survey."); } else { - print_all_responses($cm->id, $results); + survey_print_all_responses($cm->id, $results); } print_footer($course); @@ -237,12 +237,12 @@ print_header("Analysis of $user->firstname $user->lastname", "$survey->name: Analysis of a student", "", ""); if (isset($notes)) { - if (record_exists_sql("SELECT * FROM survey_analysis WHERE survey='$survey->id' and user='$user->id'")) { - if (! update_survey_analysis($survey->id, $user->id, $notes)) { + if (survey_get_analysis($survey->id, $user->id)) { + if (! survey_update_analysis($survey->id, $user->id, $notes)) { notify("An error occurred while saving your notes. Sorry."); } } else { - if (!add_survey_analysis($survey->id, $user->id, $notes)) { + if (! survey_add_analysis($survey->id, $user->id, $notes)) { notify("An error occurred while saving your notes. Sorry."); } } @@ -255,7 +255,7 @@ echo "

    "; // Print overall summary - echo "

    "; + echo "

    "; // Print scales $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)"); @@ -276,13 +276,13 @@ continue; } echo "

    multi>"; - echo "\"Clickid&sid=$student&type=studentmultiquestion.png\">"; echo "


    "; } } - if ($rs = get_record_sql("SELECT notes from survey_analysis WHERE survey='$survey->id' and user='$user->id'")) { + if ($rs = survey_get_analysis($survey->id, $user->id)) { $notes = $rs->notes; } else { $notes = ""; diff --git a/mod/survey/test.php b/mod/survey/test.php deleted file mode 100644 index 025a8ae450..0000000000 --- a/mod/survey/test.php +++ /dev/null @@ -1,10 +0,0 @@ -totalcol = 2; -for ($i=0; $i<10; $i++) { - $myxls->WriteText_pos($i, $i, "$i stuff"); -} -$myxls->SendFile(); -?> diff --git a/mod/survey/view.php b/mod/survey/view.php index 691d3e5f9f..5d010f9340 100644 --- a/mod/survey/view.php +++ b/mod/survey/view.php @@ -35,7 +35,7 @@ if (survey_already_done($survey->id, $USER->id)) { add_to_log($course->id, "survey", "view graph", "view.php?id=$cm->id", "$survey->id"); print_heading("You've completed this survey. The graph below shows a summary of your results compared to the class averages."); - $numusers = count_completed_surveys($survey->id); + $numusers = survey_count_responses($survey->id); print_heading("$numusers people have completed the survey so far"); echo "
    "; echo "wwwroot/mod/survey/graph.php?id=$cm->id&sid=$USER->id&type=student.png\">";