]> git.mjollnir.org Git - moodle.git/commitdiff
Reverting toyomoyo's conversion of mod/quiz/view.php to roles because his changes...
authortjhunt <tjhunt>
Tue, 22 Aug 2006 13:53:39 +0000 (13:53 +0000)
committertjhunt <tjhunt>
Tue, 22 Aug 2006 13:53:39 +0000 (13:53 +0000)
Admittedly, this file is pretty incomprehensible and it is not clear at first what it is trying to do. (Even though it is more comprehensible now than it was a week ago.) I'll to a proper conversion of this file to RnP once I have checked in my other changes there - assuming I can actually get Moodle to work so I can test my changes.

mod/quiz/view.php

index 36f6b37d1c3420221945e629d8d81d0190366ea2..2219f4c4af2db582e3141c1dcf2bd2fb3feaa4c1 100644 (file)
             error("The course module for the quiz with id $q is missing");
         }
     }
-    
+
     require_login($course->id, false, $cm);
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     $isteacher = isteacher($course->id);
 
     // if no questions have been set up yet redirect to edit.php
-    if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
+    if (!$quiz->questions and isteacheredit($course->id)) {
         redirect('edit.php?quizid='.$quiz->id);
     }
 
 // Print the main part of the page
 
     // Print heading and tabs for teacher
-
-    $currenttab = 'info';
-    include('tabs.php');
-
+    if ($isteacher) {
+        $currenttab = 'info';
+        include('tabs.php');
+    }
     print_heading(format_string($quiz->name));
 
     if (trim(strip_tags($quiz->intro))) {
 
 
     // This is all the teacher will get
-    if (has_capability('mod/quiz:manage', $context)) {
+    if ($isteacher) {
         if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
             $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
             $a->studentstring  = $course->students;
         exit;
     }
 
+    if (isguest()) {
+
+        $wwwroot = $CFG->wwwroot.'/login/index.php';
+        if (!empty($CFG->loginhttps)) {
+            $wwwroot = str_replace('http:','https:', $wwwroot);
+        }
+
+        notice_yesno(get_string('guestsno', 'quiz').'<br /><br />'.get_string('liketologin'),
+                     $wwwroot, $_SERVER['HTTP_REFERER']);
+        print_footer($course);
+        echo '</td></tr></table>';
+        exit;
+    }
+
     if ($attempts = quiz_get_user_attempts($quiz->id, $USER->id)) {
         $numattempts = count($attempts);
     } else {
             if ($attempt->timefinish > 0) { // attempt has finished
                 $timetaken = format_time($attempt->timefinish - $attempt->timestart);
                 $datecompleted = userdate($attempt->timefinish);
-            } else if ($available && has_capability('mod/quiz:attempt', $context)) { // The student can continue this attempt, so put appropriate link
+            } else if ($available) { // The student can continue this attempt, so put appropriate link
                 $timetaken = format_time(time() - $attempt->timestart);
                 $datecompleted  = "\n".'<script language="javascript" type="text/javascript">';
                 $datecompleted .= "\n<!--\n"; // -->
                          $lastattempt = $lastattempt_obj->timefinish;
                      }
                      if($numattempts == 1 && $quiz->delay1) {
-                         if (($timenow - $quiz->delay1 > $lastattempt) && has_capability('mod/quiz:attempt', $context)) {
-                             print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
+                         if ($timenow - $quiz->delay1 > $lastattempt) {
+                              print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
                          } else {
                              $notify_msg = get_string('temporaryblocked', 'quiz') . '<b>'. userdate($lastattempt + $quiz->delay1). '<b>';
                              print_simple_box($notify_msg, "center");
                          }
                      } else if($numattempts > 1 && $quiz->delay2) {
-                         if (($timenow - $quiz->delay2 > $lastattempt) && has_capability('mod/quiz:attempt', $context)) {
+                         if ($timenow - $quiz->delay2 > $lastattempt) {
                               print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
                          } else {
                               $notify_msg = get_string('temporaryblocked', 'quiz') . '<b>'. userdate($lastattempt + $quiz->delay2). '<b>';
                               print_simple_box($notify_msg, "center");
                          }
-                     } elseif (has_capability('mod/quiz:attempt', $context)) {
+                     } else {
                          print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
                      }
-                } elseif (has_capability('mod/quiz:attempt', $context)) {
+                } else {
                      print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
                 }     
                 echo "</div>\n";