Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / survey / view.php
blobb163d4267bf4a6cb4757701eaf376fc290c75830
1 <?php // $Id$
3 require_once("../../config.php");
4 require_once("lib.php");
6 $id = required_param('id', PARAM_INT); // Course Module ID
8 if (! $cm = get_coursemodule_from_id('survey', $id)) {
9 error("Course Module ID was incorrect");
12 if (! $course = get_record("course", "id", $cm->course)) {
13 error("Course is misconfigured");
16 require_login($course->id, false, $cm);
18 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
20 require_capability('mod/survey:participate', $context);
22 if (! $survey = get_record("survey", "id", $cm->instance)) {
23 error("Survey ID was incorrect");
25 $trimmedintro = trim($survey->intro);
26 if (empty($trimmedintro)) {
27 $tempo = get_field("survey", "intro", "id", $survey->template);
28 $survey->intro = get_string($tempo, "survey");
31 if (! $template = get_record("survey", "id", $survey->template)) {
32 error("Template ID was incorrect");
35 $showscales = ($template->name != 'ciqname');
37 $strsurveys = get_string("modulenameplural", "survey");
38 $strsurvey = get_string("modulename", "survey");
40 $navlinks = array();
41 $navlinks[] = array('name' => $strsurveys, 'link' => "index.php?id=$course->id", 'type' => 'activity');;
42 $navlinks[] = array('name' => format_string($survey->name), 'link' => '', 'type' => 'activityinistance');
43 $navigation = build_navigation($navlinks);
45 print_header_simple(format_string($survey->name), "", $navigation, "", "", true,
46 update_module_button($cm->id, $course->id, $strsurvey), navmenu($course, $cm));
48 /// Check to see if groups are being used in this survey
49 if ($groupmode = groupmode($course, $cm)) { // Groups are being used
50 $currentgroup = get_current_group($course->id);
51 } else {
52 $currentgroup = 0;
55 if (has_capability('mod/survey:readresponses', $context) or ($groupmode == VISIBLEGROUPS)) {
56 $currentgroup = 0;
59 if (has_capability('mod/survey:readresponses', $context)) {
60 $numusers = survey_count_responses($survey->id, $currentgroup);
61 echo "<div class=\"reportlink\"><a href=\"report.php?id=$cm->id\">".
62 get_string("viewsurveyresponses", "survey", $numusers)."</a></div>";
63 } else if (!$cm->visible) {
64 notice(get_string("activityiscurrentlyhidden"));
67 if (isguest()) {
68 notify(get_string("guestsnotallowed", "survey"));
72 // Check the survey hasn't already been filled out.
74 if (survey_already_done($survey->id, $USER->id)) {
76 add_to_log($course->id, "survey", "view graph", "view.php?id=$cm->id", $survey->id, $cm->id);
77 $numusers = survey_count_responses($survey->id, $currentgroup);
79 if ($showscales) {
80 print_heading(get_string("surveycompleted", "survey"));
81 print_heading(get_string("peoplecompleted", "survey", $numusers));
82 echo '<div class="resultgraph">';
83 survey_print_graph("id=$cm->id&amp;sid=$USER->id&amp;group=$currentgroup&amp;type=student.png");
84 echo '</div>';
86 } else {
88 print_box(format_text($survey->intro), 'generalbox', 'intro');
89 print_spacer(30);
91 $questions = get_records_list("survey_questions", "id", $survey->questions);
92 $questionorder = explode(",", $survey->questions);
93 foreach ($questionorder as $key => $val) {
94 $question = $questions[$val];
95 if ($question->type == 0 or $question->type == 1) {
96 if ($answer = survey_get_user_answer($survey->id, $question->id, $USER->id)) {
97 $table = NULL;
98 $table->head = array(get_string($question->text, "survey"));
99 $table->align = array ("left");
100 $table->data[] = array(s($answer->answer1));//no html here, just plain text
101 print_table($table);
102 print_spacer(30);
108 print_footer($course);
109 exit;
112 // Start the survey form
113 add_to_log($course->id, "survey", "view form", "view.php?id=$cm->id", $survey->id, $cm->id);
115 echo "<form method=\"post\" action=\"save.php\" id=\"surveyform\">";
116 echo '<div>';
117 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
119 print_simple_box(format_text($survey->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
121 // Get all the major questions and their proper order
122 if (! $questions = get_records_list("survey_questions", "id", $survey->questions)) {
123 error("Couldn't find any questions in this survey!!");
125 $questionorder = explode( ",", $survey->questions);
127 // Cycle through all the questions in order and print them
129 $qnum = 0;
130 foreach ($questionorder as $key => $val) {
131 $question = $questions["$val"];
132 $question->id = $val;
134 if ($question->type >= 0) {
136 if ($question->text) {
137 $question->text = get_string($question->text, "survey");
140 if ($question->shorttext) {
141 $question->shorttext = get_string($question->shorttext, "survey");
144 if ($question->intro) {
145 $question->intro = get_string($question->intro, "survey");
148 if ($question->options) {
149 $question->options = get_string($question->options, "survey");
152 if ($question->multi) {
153 survey_print_multi($question);
154 } else {
155 survey_print_single($question);
160 if (isguest()) {
161 echo '</div>';
162 echo "</form>";
163 print_footer($course);
164 exit;
169 <br />
170 <script type="text/javascript">
171 <!--
172 function checkform() {
174 var error=false;
176 with (document.getElementById('surveyform')) {
177 <?php
178 if (!empty($checklist)) {
179 foreach ($checklist as $question => $default) {
180 echo " if (".$question."[".$default."].checked) error=true;\n";
186 if (error) {
187 alert("<?php print_string("questionsnotanswered", "survey") ?>");
188 } else {
189 document.getElementById('surveyform').submit();
193 <?php echo "document.write('<input type=\"button\" value=\"".get_string("clicktocontinuecheck", "survey")."\" onClick=\"checkform()\" />');"; ?>
195 // END -->
196 </script>
198 <noscript>
199 <!-- Without Javascript, no checking is done -->
200 <div>
201 <input type="submit" value="<?php get_string("clicktocontinue", "survey") ?>" />
202 </div>
203 </noscript>
205 <?php
206 echo '</div>';
207 echo "</form>";
209 print_footer($course);