]> git.mjollnir.org Git - moodle.git/commitdiff
Merged choice/guest fixes from stable MDL-7171
authormoodler <moodler>
Mon, 23 Oct 2006 03:00:30 +0000 (03:00 +0000)
committermoodler <moodler>
Mon, 23 Oct 2006 03:00:30 +0000 (03:00 +0000)
lang/en_utf8/choice.php
mod/choice/view.php

index 5e4f3de7ad245e61d93d71fc6a214303a228c6aa..125fa8d54c9a2bc8ea123c4cdcac5b14cc741280 100644 (file)
@@ -24,8 +24,10 @@ $string['limitanswers'] = 'Limit the number of responses allowed';
 $string['modulename'] = 'Choice';
 $string['modulenameplural'] = 'Choices';
 $string['mustchooseone'] = 'You must choose an answer before saving.  Nothing was saved.';
+$string['noguestchoose'] = 'Sorry, guests are not allowed to make choices.';
 $string['notanswered'] = 'Not answered yet';
 $string['notopenyet'] = 'Sorry, this activity is not available until $a';
+$string['noresultsviewable'] = 'The results are not currently viewable.';
 $string['privacy'] = 'Privacy of results';
 $string['publish'] = 'Publish results';
 $string['publishafteranswer'] = 'Show results to a student after they answer';
index 58a2c859306ab73cbb56f4b2e3f6571a3e7fa903..0c543fb3ab2d0fb85626dfaf6ae0a1be502be665 100644 (file)
     }
 
     require_course_login($course, false, $cm);
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-    
-    require_capability('mod/choice:choose', $context);
 
     if (!$choice = choice_get_choice($cm->instance)) {
         error("Course module is incorrect");
     }
     
-    $strchoice = get_string("modulename", "choice");
-    $strchoices = get_string("modulenameplural", "choice");
-    
+    $strchoice = get_string('modulename', 'choice');
+    $strchoices = get_string('modulenameplural', 'choice');
+
+    if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
+        print_error('badcontext');
+    }
 
 
 /// Submit any new data if there is any
 
-    if ($form = data_submitted()) {
+    if ($form = data_submitted() && has_capability('mod/choice:choose', $context)) {
         $timenow = time();
         if (has_capability('mod/choice:deleteresponses', $context)) {
             if ($action == 'delete') { //some responses need to be deleted     
 
 /// Display the choice and possibly results
 
-    add_to_log($course->id, "choice", "view", "view.php?id=$cm->id", $choice->id, $cm->id);
 
     print_header_simple(format_string($choice->name), "",
                  "<a href=\"index.php?id=$course->id\">$strchoices</a> -> ".format_string($choice->name), "", "", true,
                   update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm));
+
+    add_to_log($course->id, "choice", "view", "view.php?id=$cm->id", $choice->id, $cm->id);
                                                       
     if (has_capability('mod/choice:readresponses', $context)) {
         choice_show_reportlink($choice, $course->id, $cm->id);
         exit;
     }
 
-    if ( (!$current or $choice->allowupdate) and ($choice->timeclose >= time() or $choice->timeclose == 0) ) {
+    if ( (!$current or $choice->allowupdate) and 
+         ($choice->timeclose >= time() or $choice->timeclose == 0) and 
+          has_capability('mod/choice:choose', $context) ) {
     // They haven't made their choice yet or updates allowed and choice is open
 
-        echo "<form name=\"form\" method=\"post\" action=\"view.php\">";        
+        echo '<form name="form" method="post" action="view.php">';        
 
         choice_show_form($choice, $USER, $cm);
         
-        echo "</form>";
+        echo '</form>';
 
+        $choiceformshown = true;
+    } else {
+        $choiceformshown = false;
     }
 
 
 
     // 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
-        ( $choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and $choice->timeclose <= time() ) )  {
+    if ( $choice->showresults == CHOICE_SHOWRESULTS_ALWAYS or
+        ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_ANSWER and $current ) or
+        ($choice->showresults == CHOICE_SHOWRESULTS_AFTER_CLOSE and $choice->timeclose <= time() ) )  {
 
         choice_show_results($choice, $course, $cm);
+
+    } else if (!$choiceformshown) {
+        print_simple_box(get_string('noresultsviewable', 'choice'), 'center');
+    } 
+    
+    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)) {
+                $wwwroot = str_replace('http','https', $wwwroot);
+            }
+            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">';
+            print_single_button($CFG->wwwroot.'/course/enrol.php?id='.$course->id, NULL, 
+                                get_string('enrolme', '', $course->shortname), 'post', $CFG->framename);
+            echo '</div>'."\n";
+            print_simple_box_end();
+
+        }
     }
 
     print_footer($course);