2004-09-12 15:06:29 +00:00
|
|
|
<?php // $Id$
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-04-23 21:07:44 +00:00
|
|
|
$id = required_param('id', PARAM_INT); // Course Module ID
|
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
|
$attemptids = optional_param('attemptid', array(), PARAM_INT); // array of attempt ids for delete action
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2006-08-08 22:09:55 +00:00
|
|
|
if (! $cm = get_coursemodule_from_id('choice', $id)) {
|
2008-05-23 07:03:17 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-06-04 06:42:54 +00:00
|
|
|
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
|
2008-05-23 07:03:17 +00:00
|
|
|
print_error('coursemisconf');
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
require_course_login($course, false, $cm);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-09-08 09:42:07 +00:00
|
|
|
if (!$choice = choice_get_choice($cm->instance)) {
|
2008-05-23 07:03:17 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2006-10-23 03:00:30 +00:00
|
|
|
$strchoice = get_string('modulename', 'choice');
|
|
|
|
$strchoices = get_string('modulenameplural', 'choice');
|
|
|
|
|
|
|
|
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
|
|
|
|
print_error('badcontext');
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2008-02-15 02:43:38 +00:00
|
|
|
if ($action == 'delchoice') {
|
2008-06-04 06:42:54 +00:00
|
|
|
if ($answer = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) {
|
2008-02-15 02:43:38 +00:00
|
|
|
//print_object($answer);
|
2008-06-04 06:42:54 +00:00
|
|
|
$DB->delete_records('choice_answers', array('id' => $answer->id));
|
2008-02-15 02:43:38 +00:00
|
|
|
}
|
2007-05-03 00:04:53 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2005-03-30 17:32:23 +00:00
|
|
|
/// Submit any new data if there is any
|
|
|
|
|
2006-10-23 03:00:30 +00:00
|
|
|
if ($form = data_submitted() && has_capability('mod/choice:choose', $context)) {
|
2002-08-12 08:56:36 +00:00
|
|
|
$timenow = time();
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('mod/choice:deleteresponses', $context)) {
|
2008-08-15 01:48:29 +00:00
|
|
|
if ($action == 'delete') { //some responses need to be deleted
|
|
|
|
choice_delete_responses($attemptids, $choice->id); //delete responses.
|
2006-02-23 01:20:24 +00:00
|
|
|
redirect("view.php?id=$cm->id");
|
|
|
|
}
|
2006-10-23 07:01:18 +00:00
|
|
|
}
|
|
|
|
$answer = optional_param('answer', '', PARAM_INT);
|
|
|
|
|
|
|
|
if (empty($answer)) {
|
2004-02-04 13:40:20 +00:00
|
|
|
redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice'));
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2006-10-23 07:01:18 +00:00
|
|
|
choice_user_submit_response($answer, $choice, $USER->id, $course->id, $cm);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2004-07-01 12:52:15 +00:00
|
|
|
redirect("view.php?id=$cm->id");
|
2001-11-22 06:23:56 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2005-03-30 17:32:23 +00:00
|
|
|
|
|
|
|
/// Display the choice and possibly results
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation('', $cm);
|
2007-04-16 21:02:24 +00:00
|
|
|
print_header_simple(format_string($choice->name), "", $navigation, "", "", true,
|
2002-11-10 07:37:15 +00:00
|
|
|
update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm));
|
2006-10-23 03:00:30 +00:00
|
|
|
|
|
|
|
add_to_log($course->id, "choice", "view", "view.php?id=$cm->id", $choice->id, $cm->id);
|
2007-07-05 04:40:48 +00:00
|
|
|
|
|
|
|
/// Check to see if groups are being used in this choice
|
2007-08-27 21:52:35 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2008-03-03 04:42:01 +00:00
|
|
|
if ($groupmode) {
|
|
|
|
groups_get_activity_group($cm, true);
|
|
|
|
groups_print_activity_menu($cm, 'view.php?id='.$id);
|
|
|
|
}
|
|
|
|
$allresponses = choice_get_response_data($choice, $cm, $groupmode); // Big function, approx 6 SQL calls per user
|
|
|
|
|
2008-06-04 06:42:54 +00:00
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('mod/choice:readresponses', $context)) {
|
2008-03-03 04:42:01 +00:00
|
|
|
choice_show_reportlink($allresponses, $cm);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 04:40:48 +00:00
|
|
|
echo '<div class="clearer"></div>';
|
|
|
|
|
2005-03-13 16:17:55 +00:00
|
|
|
if ($choice->text) {
|
2007-01-11 08:06:15 +00:00
|
|
|
print_box(format_text($choice->text, $choice->format), 'generalbox', 'intro');
|
2005-03-13 16:17:55 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2008-01-25 06:31:15 +00:00
|
|
|
$current = false; // Initialise for later
|
2005-04-15 01:40:22 +00:00
|
|
|
//if user has already made a selection, and they are not allowed to update it, show their selected answer.
|
2008-06-04 06:42:54 +00:00
|
|
|
if (!empty($USER->id) && ($current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id))) &&
|
2006-10-23 07:01:18 +00:00
|
|
|
empty($choice->allowupdate) ) {
|
2005-04-15 01:40:22 +00:00
|
|
|
print_simple_box(get_string("yourselection", "choice", userdate($choice->timeopen)).": ".format_string(choice_get_option_text($choice, $current->optionid)), "center");
|
|
|
|
}
|
2004-07-01 12:52:15 +00:00
|
|
|
|
2005-03-30 17:32:23 +00:00
|
|
|
/// Print the form
|
2008-08-11 04:19:34 +00:00
|
|
|
$choiceopen = true;
|
2007-10-22 21:25:06 +00:00
|
|
|
$timenow = time();
|
|
|
|
if ($choice->timeclose !=0) {
|
|
|
|
if ($choice->timeopen > $timenow ) {
|
|
|
|
print_simple_box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "center");
|
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
} else if ($timenow > $choice->timeclose) {
|
|
|
|
print_simple_box(get_string("expired", "choice", userdate($choice->timeclose)), "center");
|
2008-08-11 04:19:34 +00:00
|
|
|
$choiceopen = false;
|
2007-10-22 21:25:06 +00:00
|
|
|
}
|
2004-07-01 12:52:15 +00:00
|
|
|
}
|
|
|
|
|
2008-08-11 04:19:34 +00:00
|
|
|
if ( (!$current or $choice->allowupdate) and $choiceopen and
|
2006-10-23 03:00:30 +00:00
|
|
|
has_capability('mod/choice:choose', $context) ) {
|
2004-07-01 12:52:15 +00:00
|
|
|
// They haven't made their choice yet or updates allowed and choice is open
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2008-06-04 06:42:54 +00:00
|
|
|
echo '<form id="form" method="post" action="view.php">';
|
2005-03-30 17:32:23 +00:00
|
|
|
|
2008-03-03 04:42:01 +00:00
|
|
|
choice_show_form($choice, $USER, $cm, $allresponses);
|
|
|
|
|
2006-10-23 03:00:30 +00:00
|
|
|
echo '</form>';
|
2002-09-08 09:42:07 +00:00
|
|
|
|
2006-10-23 03:00:30 +00:00
|
|
|
$choiceformshown = true;
|
|
|
|
} else {
|
|
|
|
$choiceformshown = false;
|
2004-07-01 12:52:15 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-01-01 06:34:13 +00:00
|
|
|
|
2006-10-23 03:00:30 +00:00
|
|
|
if (!$choiceformshown) {
|
|
|
|
|
|
|
|
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
|
|
|
|
|
|
|
if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) { // Guest on whole site
|
|
|
|
$wwwroot = $CFG->wwwroot.'/login/index.php';
|
|
|
|
if (!empty($CFG->loginhttps)) {
|
2007-08-22 19:36:24 +00:00
|
|
|
$wwwroot = str_replace('http:','https:', $wwwroot);
|
2006-10-23 03:00:30 +00:00
|
|
|
}
|
|
|
|
notice_yesno(get_string('noguestchoose', 'choice').'<br /><br />'.get_string('liketologin'),
|
|
|
|
$wwwroot, $_SERVER['HTTP_REFERER']);
|
|
|
|
|
|
|
|
} else if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Guest in this course only
|
|
|
|
$SESSION->wantsurl = $FULLME;
|
|
|
|
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
|
|
|
|
|
|
|
|
print_simple_box_start('center', '60%', '', 5, 'generalbox', 'notice');
|
|
|
|
echo '<p align="center">'. get_string('noguestchoose', 'choice') .'</p>';
|
|
|
|
echo '<div class="continuebutton">';
|
2008-06-04 06:42:54 +00:00
|
|
|
print_single_button($CFG->wwwroot.'/course/enrol.php?id='.$course->id, NULL,
|
2007-02-28 06:25:22 +00:00
|
|
|
get_string('enrolme', '', format_string($course->shortname)), 'post', $CFG->framename);
|
2006-10-23 03:00:30 +00:00
|
|
|
echo '</div>'."\n";
|
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
}
|
2003-01-01 06:34:13 +00:00
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2006-10-31 19:00:55 +00:00
|
|
|
// print the results at the bottom of the screen
|
|
|
|
|
|
|
|
if ( $choice->showresults == CHOICE_SHOWRESULTS_ALWAYS or
|
|
|
|
($choice->showresults == CHOICE_SHOWRESULTS_AFTER_ANSWER and $current ) or
|
2008-08-11 04:19:34 +00:00
|
|
|
($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and !$choiceopen ) ) {
|
2006-10-31 19:00:55 +00:00
|
|
|
|
2008-03-03 04:42:01 +00:00
|
|
|
choice_show_results($choice, $course, $cm, $allresponses); //show table with students responses.
|
2006-10-31 19:00:55 +00:00
|
|
|
|
|
|
|
} else if (!$choiceformshown) {
|
|
|
|
print_simple_box(get_string('noresultsviewable', 'choice'), 'center');
|
2008-06-04 06:42:54 +00:00
|
|
|
}
|
2006-10-31 19:00:55 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
print_footer($course);
|
|
|
|
|
2008-07-29 17:22:47 +00:00
|
|
|
/// Mark as viewed
|
|
|
|
$completion=new completion_info($course);
|
|
|
|
$completion->set_module_viewed($cm);
|
2008-08-11 04:19:34 +00:00
|
|
|
?>
|