|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 require_once("../../config.php"); 00027 require_once("lib.php"); 00028 00029 // Check that all the parameters have been provided. 00030 00031 $id = required_param('id', PARAM_INT); // Course Module ID 00032 $action = optional_param('action', '', PARAM_ALPHA); // What to look at 00033 $qid = optional_param('qid', 0, PARAM_RAW); // Question IDs comma-separated list 00034 $student = optional_param('student', 0, PARAM_INT); // Student ID 00035 $notes = optional_param('notes', '', PARAM_RAW); // Save teachers notes 00036 00037 $qids = explode(',', $qid); 00038 $qids = clean_param_array($qids, PARAM_INT); 00039 $qid = implode (',', $qids); 00040 00041 if (! $cm = get_coursemodule_from_id('survey', $id)) { 00042 print_error('invalidcoursemodule'); 00043 } 00044 00045 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { 00046 print_error('coursemisconf'); 00047 } 00048 00049 $url = new moodle_url('/mod/survey/report.php', array('id'=>$id)); 00050 if ($action !== '') { 00051 $url->param('action', $action); 00052 } 00053 if ($qid !== 0) { 00054 $url->param('qid', $qid); 00055 } 00056 if ($student !== 0) { 00057 $url->param('student', $student); 00058 } 00059 if ($notes !== '') { 00060 $url->param('notes', $notes); 00061 } 00062 $PAGE->set_url($url); 00063 00064 require_login($course->id, false, $cm); 00065 00066 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00067 00068 require_capability('mod/survey:readresponses', $context); 00069 00070 if (! $survey = $DB->get_record("survey", array("id"=>$cm->instance))) { 00071 print_error('invalidsurveyid', 'survey'); 00072 } 00073 00074 if (! $template = $DB->get_record("survey", array("id"=>$survey->template))) { 00075 print_error('invalidtmptid', 'survey'); 00076 } 00077 00078 $showscales = ($template->name != 'ciqname'); 00079 00080 00081 $strreport = get_string("report", "survey"); 00082 $strsurvey = get_string("modulename", "survey"); 00083 $strsurveys = get_string("modulenameplural", "survey"); 00084 $strsummary = get_string("summary", "survey"); 00085 $strscales = get_string("scales", "survey"); 00086 $strquestion = get_string("question", "survey"); 00087 $strquestions = get_string("questions", "survey"); 00088 $strdownload = get_string("download", "survey"); 00089 $strallscales = get_string("allscales", "survey"); 00090 $strallquestions = get_string("allquestions", "survey"); 00091 $strselectedquestions = get_string("selectedquestions", "survey"); 00092 $strseemoredetail = get_string("seemoredetail", "survey"); 00093 $strnotes = get_string("notes", "survey"); 00094 00095 add_to_log($course->id, "survey", "view report", "report.php?id=$cm->id", "$survey->id", $cm->id); 00096 00097 switch ($action) { 00098 case 'download': 00099 $PAGE->navbar->add(get_string('downloadresults', 'survey')); 00100 break; 00101 case 'summary': 00102 case 'scales': 00103 case 'questions': 00104 $PAGE->navbar->add($strreport); 00105 $PAGE->navbar->add(${'str'.$action}); 00106 break; 00107 case 'students': 00108 $PAGE->navbar->add($strreport); 00109 $PAGE->navbar->add(get_string('participants')); 00110 break; 00111 case '': 00112 $PAGE->navbar->add($strreport); 00113 $PAGE->navbar->add($strsummary); 00114 break; 00115 default: 00116 $PAGE->navbar->add($strreport); 00117 break; 00118 } 00119 00120 $PAGE->set_title("$course->shortname: ".format_string($survey->name)); 00121 $PAGE->set_heading($course->fullname); 00122 echo $OUTPUT->header(); 00123 00125 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used 00126 $menuaction = $action == "student" ? "students" : $action; 00127 $currentgroup = groups_get_activity_group($cm, true); 00128 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/survey/report.php?id=$cm->id&action=$menuaction&qid=$qid"); 00129 } else { 00130 $currentgroup = 0; 00131 } 00132 00133 if ($currentgroup) { 00134 $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $currentgroup, null, false); 00135 } else if (!empty($cm->groupingid)) { 00136 $groups = groups_get_all_groups($courseid, 0, $cm->groupingid); 00137 $groups = array_keys($groups); 00138 $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $groups, null, false); 00139 } else { 00140 $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', '', null, false); 00141 $group = false; 00142 } 00143 00144 $groupingid = $cm->groupingid; 00145 00146 echo $OUTPUT->box_start("generalbox boxaligncenter"); 00147 if ($showscales) { 00148 echo "<a href=\"report.php?action=summary&id=$id\">$strsummary</a>"; 00149 echo " <a href=\"report.php?action=scales&id=$id\">$strscales</a>"; 00150 echo " <a href=\"report.php?action=questions&id=$id\">$strquestions</a>"; 00151 echo " <a href=\"report.php?action=students&id=$id\">".get_string('participants')."</a>"; 00152 if (has_capability('mod/survey:download', $context)) { 00153 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>"; 00154 } 00155 if (empty($action)) { 00156 $action = "summary"; 00157 } 00158 } else { 00159 echo "<a href=\"report.php?action=questions&id=$id\">$strquestions</a>"; 00160 echo " <a href=\"report.php?action=students&id=$id\">".get_string('participants')."</a>"; 00161 if (has_capability('mod/survey:download', $context)) { 00162 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>"; 00163 } 00164 if (empty($action)) { 00165 $action = "questions"; 00166 } 00167 } 00168 echo $OUTPUT->box_end(); 00169 00170 echo $OUTPUT->spacer(array('height'=>30, 'width'=>30, 'br'=>true)); // should be done with CSS instead 00171 00172 00174 00175 $virtualscales = false; 00176 00177 switch ($action) { 00178 00179 case "summary": 00180 echo $OUTPUT->heading($strsummary); 00181 00182 if (survey_count_responses($survey->id, $currentgroup, $groupingid)) { 00183 echo "<div class='reportsummary'><a href=\"report.php?action=scales&id=$id\">"; 00184 survey_print_graph("id=$id&group=$currentgroup&type=overall.png"); 00185 echo "</a></div>"; 00186 } else { 00187 echo $OUTPUT->notification(get_string("nobodyyet","survey")); 00188 } 00189 break; 00190 00191 case "scales": 00192 echo $OUTPUT->heading($strscales); 00193 00194 if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) { 00195 echo $OUTPUT->notification(get_string("nobodyyet","survey")); 00196 00197 } else { 00198 00199 $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions)); 00200 $questionorder = explode(",", $survey->questions); 00201 00202 foreach ($questionorder as $key => $val) { 00203 $question = $questions[$val]; 00204 if ($question->type < 0) { // We have some virtual scales. Just show them. 00205 $virtualscales = true; 00206 break; 00207 } 00208 } 00209 00210 foreach ($questionorder as $key => $val) { 00211 $question = $questions[$val]; 00212 if ($question->multi) { 00213 if (!empty($virtualscales) && $question->type > 0) { // Don't show non-virtual scales if virtual 00214 continue; 00215 } 00216 echo "<p class=\"centerpara\"><a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">"; 00217 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png"); 00218 echo "</a></p><br />"; 00219 } 00220 } 00221 } 00222 00223 break; 00224 00225 case "questions": 00226 00227 if ($qid) { // just get one multi-question 00228 $questions = $DB->get_records_select("survey_questions", "id in ($qid)"); 00229 $questionorder = explode(",", $qid); 00230 00231 if ($scale = $DB->get_records("survey_questions", array("multi"=>$qid))) { 00232 $scale = array_pop($scale); 00233 echo $OUTPUT->heading("$scale->text - $strselectedquestions"); 00234 } else { 00235 echo $OUTPUT->heading($strselectedquestions); 00236 } 00237 00238 } else { // get all top-level questions 00239 $questions = $DB->get_records_list("survey_questions", "id", explode(',',$survey->questions)); 00240 $questionorder = explode(",", $survey->questions); 00241 00242 echo $OUTPUT->heading($strallquestions); 00243 } 00244 00245 if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) { 00246 echo $OUTPUT->notification(get_string("nobodyyet","survey")); 00247 00248 } else { 00249 00250 foreach ($questionorder as $key => $val) { 00251 $question = $questions[$val]; 00252 if ($question->type < 0) { // We have some virtual scales. DON'T show them. 00253 $virtualscales = true; 00254 break; 00255 } 00256 } 00257 00258 foreach ($questionorder as $key => $val) { 00259 $question = $questions[$val]; 00260 00261 if ($question->type < 0) { // We have some virtual scales. DON'T show them. 00262 continue; 00263 } 00264 $question->text = get_string($question->text, "survey"); 00265 00266 if ($question->multi) { 00267 echo "<h3>$question->text:</h3>"; 00268 00269 $subquestions = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi)); 00270 $subquestionorder = explode(",", $question->multi); 00271 foreach ($subquestionorder as $key => $val) { 00272 $subquestion = $subquestions[$val]; 00273 if ($subquestion->type > 0) { 00274 echo "<p class=\"centerpara\">"; 00275 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$subquestion->id\">"; 00276 survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png"); 00277 echo "</a></p>"; 00278 } 00279 } 00280 } else if ($question->type > 0 ) { 00281 echo "<p class=\"centerpara\">"; 00282 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$question->id\">"; 00283 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png"); 00284 echo "</a></p>"; 00285 00286 } else { 00287 $table = new html_table(); 00288 $table->head = array($question->text); 00289 $table->align = array ("left"); 00290 00291 $contents = '<table cellpadding="15" width="100%">'; 00292 00293 if ($aaa = survey_get_user_answers($survey->id, $question->id, $currentgroup, "sa.time ASC")) { 00294 foreach ($aaa as $a) { 00295 $contents .= "<tr>"; 00296 $contents .= '<td class="fullnamecell">'.fullname($a).'</td>'; 00297 $contents .= '<td valign="top">'.$a->answer1.'</td>'; 00298 $contents .= "</tr>"; 00299 } 00300 } 00301 $contents .= "</table>"; 00302 00303 $table->data[] = array($contents); 00304 00305 echo html_writer::table($table); 00306 00307 echo $OUTPUT->spacer(array('height'=>30)); // should be done with CSS instead 00308 } 00309 } 00310 } 00311 00312 break; 00313 00314 case "question": 00315 if (!$question = $DB->get_record("survey_questions", array("id"=>$qid))) { 00316 print_error('cannotfindquestion', 'survey'); 00317 } 00318 $question->text = get_string($question->text, "survey"); 00319 00320 $answers = explode(",", get_string($question->options, "survey")); 00321 00322 echo $OUTPUT->heading("$strquestion: $question->text"); 00323 00324 00325 $strname = get_string("name", "survey"); 00326 $strtime = get_string("time", "survey"); 00327 $stractual = get_string("actual", "survey"); 00328 $strpreferred = get_string("preferred", "survey"); 00329 $strdateformat = get_string("strftimedatetime"); 00330 00331 $table = new html_table(); 00332 $table->head = array("", $strname, $strtime, $stractual, $strpreferred); 00333 $table->align = array ("left", "left", "left", "left", "right"); 00334 $table->size = array (35, "", "", "", ""); 00335 00336 if ($aaa = survey_get_user_answers($survey->id, $question->id, $currentgroup)) { 00337 foreach ($aaa as $a) { 00338 if ($a->answer1) { 00339 $answer1 = "$a->answer1 - ".$answers[$a->answer1 - 1]; 00340 } else { 00341 $answer1 = " "; 00342 } 00343 if ($a->answer2) { 00344 $answer2 = "$a->answer2 - ".$answers[$a->answer2 - 1]; 00345 } else { 00346 $answer2 = " "; 00347 } 00348 $table->data[] = array( 00349 $OUTPUT->user_picture($a, array('courseid'=>$course->id)), 00350 "<a href=\"report.php?id=$id&action=student&student=$a->userid\">".fullname($a)."</a>", 00351 userdate($a->time), 00352 $answer1, $answer2); 00353 00354 } 00355 } 00356 00357 echo html_writer::table($table); 00358 00359 break; 00360 00361 case "students": 00362 00363 echo $OUTPUT->heading(get_string("analysisof", "survey", get_string('participants'))); 00364 00365 if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) { 00366 echo $OUTPUT->notification(get_string("nobodyyet","survey")); 00367 } else { 00368 survey_print_all_responses($cm->id, $results, $course->id); 00369 } 00370 00371 break; 00372 00373 case "student": 00374 if (!$user = $DB->get_record("user", array("id"=>$student))) { 00375 print_error('invaliduserid'); 00376 } 00377 00378 echo $OUTPUT->heading(get_string("analysisof", "survey", fullname($user))); 00379 00380 if ($notes != '' and confirm_sesskey()) { 00381 if (survey_get_analysis($survey->id, $user->id)) { 00382 if (! survey_update_analysis($survey->id, $user->id, $notes)) { 00383 echo $OUTPUT->notification("An error occurred while saving your notes. Sorry."); 00384 } else { 00385 echo $OUTPUT->notification(get_string("savednotes", "survey")); 00386 } 00387 } else { 00388 if (! survey_add_analysis($survey->id, $user->id, $notes)) { 00389 echo $OUTPUT->notification("An error occurred while saving your notes. Sorry."); 00390 } else { 00391 echo $OUTPUT->notification(get_string("savednotes", "survey")); 00392 } 00393 } 00394 } 00395 00396 echo "<p <p class=\"centerpara\">"; 00397 echo $OUTPUT->user_picture($user, array('courseid'=>$course->id)); 00398 echo "</p>"; 00399 00400 $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions)); 00401 $questionorder = explode(",", $survey->questions); 00402 00403 if ($showscales) { 00404 // Print overall summary 00405 echo "<p <p class=\"centerpara\">>"; 00406 survey_print_graph("id=$id&sid=$student&type=student.png"); 00407 echo "</p>"; 00408 00409 // Print scales 00410 00411 foreach ($questionorder as $key => $val) { 00412 $question = $questions[$val]; 00413 if ($question->type < 0) { // We have some virtual scales. Just show them. 00414 $virtualscales = true; 00415 break; 00416 } 00417 } 00418 00419 foreach ($questionorder as $key => $val) { 00420 $question = $questions[$val]; 00421 if ($question->multi) { 00422 if ($virtualscales && $question->type > 0) { // Don't show non-virtual scales if virtual 00423 continue; 00424 } 00425 echo "<p class=\"centerpara\">"; 00426 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">"; 00427 survey_print_graph("id=$id&qid=$question->id&sid=$student&type=studentmultiquestion.png"); 00428 echo "</a></p><br />"; 00429 } 00430 } 00431 } 00432 00433 // Print non-scale questions 00434 00435 foreach ($questionorder as $key => $val) { 00436 $question = $questions[$val]; 00437 if ($question->type == 0 or $question->type == 1) { 00438 if ($answer = survey_get_user_answer($survey->id, $question->id, $user->id)) { 00439 $table = new html_table(); 00440 $table->head = array(get_string($question->text, "survey")); 00441 $table->align = array ("left"); 00442 $table->data[] = array(s($answer->answer1)); // no html here, just plain text 00443 echo html_writer::table($table); 00444 echo $OUTPUT->spacer(array('height'=>30)); 00445 } 00446 } 00447 } 00448 00449 if ($rs = survey_get_analysis($survey->id, $user->id)) { 00450 $notes = $rs->notes; 00451 } else { 00452 $notes = ""; 00453 } 00454 echo "<hr noshade=\"noshade\" size=\"1\" />"; 00455 echo "<div class='studentreport'>"; 00456 echo "<form action=\"report.php\" method=\"post\">"; 00457 echo "<h3>$strnotes:</h3>"; 00458 echo "<blockquote>"; 00459 echo "<textarea name=\"notes\" rows=\"10\" cols=\"60\">"; 00460 p($notes); 00461 echo "</textarea><br />"; 00462 echo "<input type=\"hidden\" name=\"action\" value=\"student\" />"; 00463 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />"; 00464 echo "<input type=\"hidden\" name=\"student\" value=\"$student\" />"; 00465 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />"; 00466 echo "<input type=\"submit\" value=\"".get_string("savechanges")."\" />"; 00467 echo "</blockquote>"; 00468 echo "</form>"; 00469 echo "</div>"; 00470 00471 00472 break; 00473 00474 case "download": 00475 echo $OUTPUT->heading($strdownload); 00476 00477 require_capability('mod/survey:download', $context); 00478 00479 echo '<p class="centerpara">'.get_string("downloadinfo", "survey").'</p>'; 00480 00481 echo $OUTPUT->container_start('reportbuttons'); 00482 $options = array(); 00483 $options["id"] = "$cm->id"; 00484 $options["group"] = $currentgroup; 00485 00486 $options["type"] = "ods"; 00487 echo $OUTPUT->single_button(new moodle_url("download.php", $options), get_string("downloadods")); 00488 00489 $options["type"] = "xls"; 00490 echo $OUTPUT->single_button(new moodle_url("download.php", $options), get_string("downloadexcel")); 00491 00492 $options["type"] = "txt"; 00493 echo $OUTPUT->single_button(new moodle_url("download.php", $options), get_string("downloadtext")); 00494 echo $OUTPUT->container_end(); 00495 00496 break; 00497 00498 } 00499 echo $OUTPUT->footer(); 00500