course)) { error("Course is misconfigured"); } require_login($course->id); if (!isteacher($course->id)) { error("Sorry, only teachers can see this."); } if (! $survey = get_record("survey", "id", $cm->instance)) { error("Survey ID was incorrect"); } $ME = qualified_me()."?id=$id"; $strreport = get_string("report", "survey"); $strsurveys = get_string("modulenameplural", "survey"); $strsummary = get_string("summary", "survey"); $strscales = get_string("scales", "survey"); $strquestion = get_string("question", "survey"); $strquestions = get_string("questions", "survey"); $strdownload = get_string("download", "survey"); $strallscales = get_string("allscales", "survey"); $strallquestions = get_string("allquestions", "survey"); $strselectedquestions = get_string("selectedquestions", "survey"); $strseemoredetail = get_string("seemoredetail", "survey"); $strnotes = get_string("notes", "survey"); if (!$action) { $display = "summary"; } if ($display) { // Display the frame containing something. add_to_log($course->id, "survey", "view report", "report.php?id=$cm->id", "$survey->id"); echo "$course->shortname: $strreport: $survey->name\n"; echo " "; echo " \n"; echo " "; echo " \n"; echo " \n"; echo " \n"; echo "\n"; exit; } switch ($action) { case "top": if ($course->category) { $navigation = "id\">$course->shortname -> id\">$strsurveys -> id\">$survey->name -> "; } else { $navigation = "id\">$strsurveys -> id\">$survey->name -> "; } print_header("$course->shortname: $survey->name", "$course->fullname", "$navigation $strreport"); break; case "menu": print_header(); //echo ""; //echo "

Survey Report

"; echo "

$strsummary

"; echo "

$strscales

"; echo "

$strquestions

"; echo "

$course->student:

"; if ($users = survey_get_responses($survey->id)) { foreach ($users as $user) { echo "
  • "; echo "id&id=$id\">"; echo "$user->firstname $user->lastname"; echo "
  • "; } } echo "

    $strdownload

    "; break; case "summary": print_header("$survey->name: $strsummary", "$strsummary"); print_heading($strallscales); if (survey_count_responses($survey->id)) { echo "

    "; } else { echo "

    ".get_string("nobodyyet","survey")."

    "; } print_footer($course); break; case "scales": print_header("$survey->name: $strscales", "$strscales"); print_heading($strallscales); $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)"); $questionorder = explode(",", $survey->questions); foreach ($questionorder as $key => $val) { $question = $questions[$val]; if ($question->type < 0) { // We have some virtual scales. Just show them. $virtualscales = true; break; } } foreach ($questionorder as $key => $val) { $question = $questions[$val]; if ($question->multi) { if ($virtualscales && $question->type > 0) { // Don't show non-virtual scales if virtual continue; } echo "

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


    "; } } print_footer($course); break; case "questions": print_header("$survey->name: $strquestions", "$strquestions"); if ($qid) { // just get one multi-question $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($qid)"); $questionorder = explode(",", $qid); print_heading($strselectedquestions); } else { // get all top-level questions $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)"); $questionorder = explode(",", $survey->questions); print_heading($strallquestions); } foreach ($questionorder as $key => $val) { $question = $questions[$val]; if ($question->type < 0) { // We have some virtual scales. DON'T show them. $virtualscales = true; break; } } foreach ($questionorder as $key => $val) { $question = $questions[$val]; if ($question->type < 0) { // We have some virtual scales. DON'T show them. continue; } if ($question->multi) { echo "

    $question->text :

    "; $subquestions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($question->multi)"); $subquestionorder = explode(",", $question->multi); foreach ($subquestionorder as $key => $val) { $subquestion = $subquestions[$val]; if ($subquestion->type > 0) { echo "

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

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

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

    "; } else { echo "

    $question->text

    "; 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")) { echo ""; } } } print_footer($course); break; case "question": if (!$question = get_record("survey_questions", "id", $qid)) { error("Question doesn't exist"); } $answers = explode(",", $question->options); print_header("$survey->name: $strquestion", "$strquestion"); print_heading("$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"); $stractual = get_string("actual", "survey"); $strpreferred = get_string("preferred", "survey"); echo ""; foreach ($aaa as $a) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
     $strname$strtime$stractual$strpreferred
    "; print_user_picture($a->user, $course->id, $a->picture, false); echo "

    user\">$a->firstname $a->lastname

    ".userdate($a->time, "%e %B %Y, %I:%M %p")."

    cellcontent\">

    "; if ($a->answer1) { echo "$a->answer1 - ".$answers[$a->answer1 - 1]; } else { echo " "; } echo "

    cellcontent\">

    "; if ($a->answer2) { echo "$a->answer2 - ".$answers[$a->answer2 - 1]; } else { echo " "; } echo "

    "; print_footer($course); break; case "students": print_header("$survey->name: $course->student", get_string("analysisof", "survey", "$course->student")); if (! $results = survey_get_responses($survey->id) ) { notify(get_string("nobodyyet","survey")); } else { survey_print_all_responses($cm->id, $results); } print_footer($course); break; case "student": if (!$user = get_record("user", "id", $student)) { error("Student doesn't exist"); } print_header("$survey->name: $$user->firstname $user->lastname", get_string("analysisof", "survey", "$user->firstname $user->lastname")); if (isset($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 { notify(get_string("savednotes", "survey")); } } else { if (! survey_add_analysis($survey->id, $user->id, $notes)) { notify("An error occurred while saving your notes. Sorry."); } else { notify(get_string("savednotes", "survey")); } } } print_heading("$user->firstname $user->lastname"); echo "

    "; print_user_picture($user->id, $course->id, $user->picture, true); echo "

    "; // Print overall summary echo "

    "; // Print scales $questions = get_records_sql("SELECT * FROM survey_questions WHERE id in ($survey->questions)"); $questionorder = explode(",", $survey->questions); foreach ($questionorder as $key => $val) { $question = $questions[$val]; if ($question->type < 0) { // We have some virtual scales. Just show them. $virtualscales = true; break; } } foreach ($questionorder as $key => $val) { $question = $questions[$val]; if ($question->multi) { if ($virtualscales && $question->type > 0) { // Don't show non-virtual scales if virtual continue; } echo "

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


    "; } } if ($rs = survey_get_analysis($survey->id, $user->id)) { $notes = $rs->notes; } else { $notes = ""; } echo "
    "; echo "
    "; echo "
    "; echo "

    $strnotes:

    "; echo "
    "; echo "
    "; echo ""; echo ""; echo "id>"; echo ""; echo "
    "; echo "
    "; echo "
    "; print_footer($course); break; case "download": print_header("$survey->name: $strdownload", "$strdownload"); $strdownloadinfo = get_string("downloadinfo", "survey"); $strdownloadexcel = get_string("downloadexcel", "survey"); $strdownloadtext = get_string("downloadtext", "survey"); echo "

    $strdownloadinfo

    "; echo "

    $strdownloadexcel

    "; echo "

    $strdownloadtext

    "; print_footer($course); break; } ?>