[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * This file is responsible for displaying the survey 20 * 21 * @package mod_survey 22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 require_once("../../config.php"); 27 require_once ("lib.php"); 28 29 $id = required_param('id', PARAM_INT); // Course Module ID 30 31 if (! $cm = get_coursemodule_from_id('survey', $id)) { 32 print_error('invalidcoursemodule'); 33 } 34 35 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { 36 print_error('coursemisconf'); 37 } 38 39 $PAGE->set_url('/mod/survey/view.php', array('id'=>$id)); 40 require_login($course, false, $cm); 41 $context = context_module::instance($cm->id); 42 43 require_capability('mod/survey:participate', $context); 44 45 if (! $survey = $DB->get_record("survey", array("id"=>$cm->instance))) { 46 print_error('invalidsurveyid', 'survey'); 47 } 48 $trimmedintro = trim($survey->intro); 49 if (empty($trimmedintro)) { 50 $tempo = $DB->get_field("survey", "intro", array("id"=>$survey->template)); 51 $survey->intro = get_string($tempo, "survey"); 52 } 53 54 if (! $template = $DB->get_record("survey", array("id"=>$survey->template))) { 55 print_error('invalidtmptid', 'survey'); 56 } 57 58 // Update 'viewed' state if required by completion system 59 require_once($CFG->libdir . '/completionlib.php'); 60 $completion = new completion_info($course); 61 $completion->set_module_viewed($cm); 62 63 $showscales = ($template->name != 'ciqname'); 64 65 $strsurvey = get_string("modulename", "survey"); 66 $PAGE->set_title($survey->name); 67 $PAGE->set_heading($course->fullname); 68 echo $OUTPUT->header(); 69 echo $OUTPUT->heading($survey->name); 70 71 /// Check to see if groups are being used in this survey 72 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used 73 $currentgroup = groups_get_activity_group($cm); 74 } else { 75 $currentgroup = 0; 76 } 77 $groupingid = $cm->groupingid; 78 79 if (has_capability('mod/survey:readresponses', $context) or ($groupmode == VISIBLEGROUPS)) { 80 $currentgroup = 0; 81 } 82 83 if (has_capability('mod/survey:readresponses', $context)) { 84 $numusers = survey_count_responses($survey->id, $currentgroup, $groupingid); 85 echo "<div class=\"reportlink\"><a href=\"report.php?id=$cm->id\">". 86 get_string("viewsurveyresponses", "survey", $numusers)."</a></div>"; 87 } else if (!$cm->visible) { 88 notice(get_string("activityiscurrentlyhidden")); 89 } 90 91 if (!is_enrolled($context)) { 92 echo $OUTPUT->notification(get_string("guestsnotallowed", "survey")); 93 } 94 95 96 // Check the survey hasn't already been filled out. 97 98 if (survey_already_done($survey->id, $USER->id)) { 99 $params = array( 100 'objectid' => $survey->id, 101 'context' => $context, 102 'courseid' => $course->id, 103 'other' => array('viewed' => 'graph') 104 ); 105 $event = \mod_survey\event\course_module_viewed::create($params); 106 $event->trigger(); 107 $numusers = survey_count_responses($survey->id, $currentgroup, $groupingid); 108 109 if ($showscales) { 110 echo $OUTPUT->box(get_string("surveycompleted", "survey")); 111 echo $OUTPUT->box(get_string("peoplecompleted", "survey", $numusers)); 112 echo '<div class="resultgraph">'; 113 survey_print_graph("id=$cm->id&sid=$USER->id&group=$currentgroup&type=student.png"); 114 echo '</div>'; 115 116 } else { 117 118 echo $OUTPUT->box(format_module_intro('survey', $survey, $cm->id), 'generalbox', 'intro'); 119 echo $OUTPUT->spacer(array('height'=>30, 'width'=>1), true); // should be done with CSS instead 120 121 $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions)); 122 $questionorder = explode(",", $survey->questions); 123 foreach ($questionorder as $key => $val) { 124 $question = $questions[$val]; 125 if ($question->type == 0 or $question->type == 1) { 126 if ($answer = survey_get_user_answer($survey->id, $question->id, $USER->id)) { 127 $table = new html_table(); 128 $table->head = array(get_string($question->text, "survey")); 129 $table->align = array ("left"); 130 $table->data[] = array(s($answer->answer1));//no html here, just plain text 131 echo html_writer::table($table); 132 echo $OUTPUT->spacer(array('height'=>30, 'width'=>1), true); 133 } 134 } 135 } 136 } 137 138 echo $OUTPUT->footer(); 139 exit; 140 } 141 142 // Start the survey form 143 $params = array( 144 'objectid' => $survey->id, 145 'context' => $context, 146 'courseid' => $course->id, 147 'other' => array('viewed' => 'form') 148 ); 149 $event = \mod_survey\event\course_module_viewed::create($params); 150 $event->trigger(); 151 152 echo "<form method=\"post\" action=\"save.php\" id=\"surveyform\">"; 153 echo '<div>'; 154 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />"; 155 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />"; 156 157 echo $OUTPUT->box(format_module_intro('survey', $survey, $cm->id), 'generalbox boxaligncenter bowidthnormal', 'intro'); 158 echo '<div>'. get_string('allquestionrequireanswer', 'survey'). '</div>'; 159 160 // Get all the major questions and their proper order 161 if (! $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions))) { 162 print_error('cannotfindquestion', 'survey'); 163 } 164 $questionorder = explode( ",", $survey->questions); 165 166 // Cycle through all the questions in order and print them 167 168 global $qnum; //TODO: ugly globals hack for survey_print_*() 169 global $checklist; //TODO: ugly globals hack for survey_print_*() 170 $qnum = 0; 171 $checklist = array(); 172 foreach ($questionorder as $key => $val) { 173 $question = $questions["$val"]; 174 $question->id = $val; 175 176 if ($question->type >= 0) { 177 178 if ($question->text) { 179 $question->text = get_string($question->text, "survey"); 180 } 181 182 if ($question->shorttext) { 183 $question->shorttext = get_string($question->shorttext, "survey"); 184 } 185 186 if ($question->intro) { 187 $question->intro = get_string($question->intro, "survey"); 188 } 189 190 if ($question->options) { 191 $question->options = get_string($question->options, "survey"); 192 } 193 194 if ($question->multi) { 195 survey_print_multi($question); 196 } else { 197 survey_print_single($question); 198 } 199 } 200 } 201 202 if (!is_enrolled($context)) { 203 echo '</div>'; 204 echo "</form>"; 205 echo $OUTPUT->footer(); 206 exit; 207 } 208 209 $checkarray = Array('questions'=>Array()); 210 if (!empty($checklist)) { 211 foreach ($checklist as $question => $default) { 212 $checkarray['questions'][] = Array('question'=>$question, 'default'=>$default); 213 } 214 } 215 $PAGE->requires->data_for_js('surveycheck', $checkarray); 216 $module = array( 217 'name' => 'mod_survey', 218 'fullpath' => '/mod/survey/survey.js', 219 'requires' => array('yui2-event'), 220 ); 221 $PAGE->requires->string_for_js('questionsnotanswered', 'survey'); 222 $PAGE->requires->js_init_call('M.mod_survey.init', $checkarray, true, $module); 223 224 echo '<br />'; 225 echo '<input type="submit" value="'.get_string("clicktocontinue", "survey").'" />'; 226 echo '</div>'; 227 echo "</form>"; 228 229 echo $OUTPUT->footer(); 230 231
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |