| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: view.php,v 1.102.2.8 2008/08/15 01:49:26 danmarsden Exp $ 2 3 require_once("../../config.php"); 4 require_once ("lib.php"); 5 6 $id = required_param('id', PARAM_INT); // Course Module ID 7 $action = optional_param('action', '', PARAM_ALPHA); 8 $attemptids = optional_param('attemptid', array(), PARAM_INT); // array of attempt ids for delete action 9 10 if (! $cm = get_coursemodule_from_id('choice', $id)) { 11 error("Course Module ID was incorrect"); 12 } 13 14 if (! $course = get_record("course", "id", $cm->course)) { 15 error("Course is misconfigured"); 16 } 17 18 require_course_login($course, false, $cm); 19 20 if (!$choice = choice_get_choice($cm->instance)) { 21 error("Course module is incorrect"); 22 } 23 24 $strchoice = get_string('modulename', 'choice'); 25 $strchoices = get_string('modulenameplural', 'choice'); 26 27 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { 28 print_error('badcontext'); 29 } 30 31 if ($action == 'delchoice') { 32 if ($answer = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $USER->id)) { 33 //print_object($answer); 34 delete_records('choice_answers', 'id', $answer->id); 35 } 36 } 37 38 /// Submit any new data if there is any 39 40 if ($form = data_submitted() && has_capability('mod/choice:choose', $context)) { 41 $timenow = time(); 42 if (has_capability('mod/choice:deleteresponses', $context)) { 43 if ($action == 'delete') { //some responses need to be deleted 44 choice_delete_responses($attemptids, $choice->id); //delete responses. 45 redirect("view.php?id=$cm->id"); 46 } 47 } 48 $answer = optional_param('answer', '', PARAM_INT); 49 50 if (empty($answer)) { 51 redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice')); 52 } else { 53 choice_user_submit_response($answer, $choice, $USER->id, $course->id, $cm); 54 } 55 redirect("view.php?id=$cm->id"); 56 exit; 57 } 58 59 60 /// Display the choice and possibly results 61 $navigation = build_navigation('', $cm); 62 print_header_simple(format_string($choice->name), "", $navigation, "", "", true, 63 update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm)); 64 65 add_to_log($course->id, "choice", "view", "view.php?id=$cm->id", $choice->id, $cm->id); 66 67 /// Check to see if groups are being used in this choice 68 $groupmode = groups_get_activity_groupmode($cm); 69 70 if ($groupmode) { 71 groups_get_activity_group($cm, true); 72 groups_print_activity_menu($cm, 'view.php?id='.$id); 73 } 74 $allresponses = choice_get_response_data($choice, $cm, $groupmode); // Big function, approx 6 SQL calls per user 75 76 77 if (has_capability('mod/choice:readresponses', $context)) { 78 choice_show_reportlink($allresponses, $cm); 79 } 80 81 echo '<div class="clearer"></div>'; 82 83 if ($choice->text) { 84 print_box(format_text($choice->text, $choice->format), 'generalbox', 'intro'); 85 } 86 87 $current = false; // Initialise for later 88 //if user has already made a selection, and they are not allowed to update it, show their selected answer. 89 if (!empty($USER->id) && ($current = get_record('choice_answers', 'choiceid', $choice->id, 'userid', $USER->id)) && 90 empty($choice->allowupdate) ) { 91 print_simple_box(get_string("yourselection", "choice", userdate($choice->timeopen)).": ".format_string(choice_get_option_text($choice, $current->optionid)), "center"); 92 } 93 94 /// Print the form 95 $choiceopen = true; 96 $timenow = time(); 97 if ($choice->timeclose !=0) { 98 if ($choice->timeopen > $timenow ) { 99 print_simple_box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "center"); 100 print_footer($course); 101 exit; 102 } else if ($timenow > $choice->timeclose) { 103 print_simple_box(get_string("expired", "choice", userdate($choice->timeclose)), "center"); 104 $choiceopen = false; 105 } 106 } 107 108 if ( (!$current or $choice->allowupdate) and $choiceopen and 109 has_capability('mod/choice:choose', $context) ) { 110 // They haven't made their choice yet or updates allowed and choice is open 111 112 echo '<form id="form" method="post" action="view.php">'; 113 114 choice_show_form($choice, $USER, $cm, $allresponses); 115 116 echo '</form>'; 117 118 $choiceformshown = true; 119 } else { 120 $choiceformshown = false; 121 } 122 123 124 125 if (!$choiceformshown) { 126 127 $sitecontext = get_context_instance(CONTEXT_SYSTEM); 128 129 if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) { // Guest on whole site 130 $wwwroot = $CFG->wwwroot.'/login/index.php'; 131 if (!empty($CFG->loginhttps)) { 132 $wwwroot = str_replace('http:','https:', $wwwroot); 133 } 134 notice_yesno(get_string('noguestchoose', 'choice').'<br /><br />'.get_string('liketologin'), 135 $wwwroot, $_SERVER['HTTP_REFERER']); 136 137 } else if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Guest in this course only 138 $SESSION->wantsurl = $FULLME; 139 $SESSION->enrolcancel = $_SERVER['HTTP_REFERER']; 140 141 print_simple_box_start('center', '60%', '', 5, 'generalbox', 'notice'); 142 echo '<p align="center">'. get_string('noguestchoose', 'choice') .'</p>'; 143 echo '<div class="continuebutton">'; 144 print_single_button($CFG->wwwroot.'/course/enrol.php?id='.$course->id, NULL, 145 get_string('enrolme', '', format_string($course->shortname)), 'post', $CFG->framename); 146 echo '</div>'."\n"; 147 print_simple_box_end(); 148 149 } 150 } 151 152 // print the results at the bottom of the screen 153 154 if ( $choice->showresults == CHOICE_SHOWRESULTS_ALWAYS or 155 ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_ANSWER and $current ) or 156 ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and !$choiceopen ) ) { 157 158 choice_show_results($choice, $course, $cm, $allresponses); //show table with students responses. 159 160 } else if (!$choiceformshown) { 161 print_simple_box(get_string('noresultsviewable', 'choice'), 'center'); 162 } 163 164 165 print_footer($course); 166 167 168 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |