"Virtual Actual and Preferred", "-2" => "Virtual Preferred", "-1" => "Virtual Actual", "0" => "Text", "1" => "Actual", "2" => "Preferred", "3" => "Actual and Preferred", ); // STANDARD FUNCTIONS //////////////////////////////////////////////////////// function survey_add_instance($survey) { // Given an object containing all the necessary data, // (defined by the form in mod.html) this function // will create a new instance and return the id number // of the new instance. if (!$template = get_record("survey", "id", $survey->template)) { return 0; } $survey->questions = $template->questions; $survey->timecreated = time(); $survey->timemodified = $survey->timecreated; return insert_record("survey", $survey); } function survey_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. if (!$template = get_record("survey", "id", $survey->template)) { return 0; } $survey->id = $survey->instance; $survey->questions = $template->questions; $survey->timemodified = time(); return update_record("survey", $survey); } function survey_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. if (! $survey = get_record("survey", "id", "$id")) { return false; } $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; } function survey_user_outline($course, $user, $mod, $survey) { if ($answers = get_records_select("survey_answers", "survey='$survey->id' AND userid='$user->id'")) { $lastanswer = array_pop($answers); $result->info = get_string("done", "survey"); $result->time = $lastanswer->time; return $result; } return NULL; } function survey_user_complete($course, $user, $mod, $survey) { global $CFG; if (survey_already_done($survey->id, $user->id)) { survey_print_graph("id=$mod->id&sid=$user->id&type=student.png"); } else { print_string("notdone", "survey"); } } function survey_print_recent_activity(&$logs, $isteacher=false) { global $CFG; $content = false; $surveys = NULL; foreach ($logs as $key => $log) { if ($log->module == "survey") { if ($log->action == "submit") { //Create a temp valid module structure (course,id) $tempmod->course = $log->course; $tempmod->id = $log->info; //Obtain the visible property from the instance $modvisible = instance_is_visible($log->module,$tempmod); //Only if the mod is visible if ($modvisible) { $surveys[$log->id] = survey_log_info($log); $surveys[$log->id]->time = $log->time; $surveys[$log->id]->url = $log->url; } } unset($logs[$key]); // No longer need this record } } if ($surveys) { $content = true; $strftimerecent = get_string("strftimerecent"); print_headline(get_string("newsurveyresponses", "survey").":"); foreach ($surveys as $survey) { $date = userdate($survey->time, $strftimerecent); echo "

$date - $survey->firstname $survey->lastname
"; echo "\"wwwroot/mod/survey/$survey->url\">"; echo "$survey->name"; echo "\"

"; } } return $content; } // SQL FUNCTIONS //////////////////////////////////////////////////////// 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->userid'"); } function survey_get_responses($survey) { global $CFG; return get_records_sql("SELECT MAX(a.time) as time, count(*) as numanswers, u.id, u.firstname, u.lastname 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.userid = u.id GROUP BY u.id, u.firstname, u.lastname ORDER BY time ASC"); } function survey_get_analysis($survey, $user) { global $CFG; return get_record_sql("SELECT notes FROM {$CFG->prefix}survey_analysis WHERE survey='$survey' AND userid='$user'"); } function survey_update_analysis($survey, $user, $notes) { global $CFG; return execute_sql("UPDATE {$CFG->prefix}survey_analysis SET notes='$notes' WHERE survey='$survey' AND userid='$user'"); } function survey_get_user_answers($surveyid, $questionid) { global $CFG; return get_records_sql("SELECT sa.*,u.firstname,u.lastname,u.picture FROM {$CFG->prefix}survey_answers sa, {$CFG->prefix}user u WHERE sa.survey = '$surveyid' AND sa.question = $questionid AND u.id = sa.userid ORDER BY sa.answer1,sa.answer2 ASC"); } // MODULE FUNCTIONS //////////////////////////////////////////////////////// function survey_add_analysis($survey, $user, $notes) { global $CFG; $record->survey = $survey; $record->userid = $user; $record->notes = $notes; return insert_record("survey_analysis", $record, false); } function survey_already_done($survey, $user) { return record_exists("survey_answers", "survey", $survey, "userid", $user); } function survey_count_responses($survey) { if ($responses = survey_get_responses($survey)) { return count($responses); } else { return 0; } } function survey_print_all_responses($survey, $results) { global $THEME; $dateformat = get_string("strftimedatetime"); echo ""; echo ""; foreach ($results as $a) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
NameTimeAnswered
id&id=$survey\">$a->firstname $a->lastname".userdate($a->time, $dateformat)."$a->numanswers
"; } function survey_get_template_name($templateid) { global $db; if ($templateid) { if ($ss = get_record("surveys", "id", $templateid)) { return $ss->name; } } else { return ""; } } function survey_shorten_name ($name, $numwords) { $words = explode(" ", $name); for ($i=0; $i < $numwords; $i++) { $output .= $words[$i]." "; } return $output; } function survey_print_multi($question) { GLOBAL $db, $qnum, $checklist, $THEME; $stripreferthat = get_string("ipreferthat", "survey"); $strifoundthat = get_string("ifoundthat", "survey"); 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_list("survey_questions", "id", $question->multi); foreach ($subquestions as $q) { $qnum++; $bgcolor = survey_question_color($qnum); if ($q->text) { $q->text = get_string($q->text, "survey"); } 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

$stripreferthat 

$q->text

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

$strifoundthat 

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 $strchoose = get_string("choose"); echo ""; } else if ($question->type < 0) { // Choose several of a number $options = explode( ",", $question->options); notify("This question type 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; } } function survey_print_graph($url) { global $CFG, $SURVEY_GHEIGHT, $SURVEY_GWIDTH; if (empty($CFG->gdversion)) { echo "(".get_string("gdneed").")"; } else { echo "wwwroot/mod/survey/graph.php?$url\">"; } } ?>