]> git.mjollnir.org Git - moodle.git/commitdiff
adding capabilitiies
authortoyomoyo <toyomoyo>
Wed, 13 Sep 2006 09:08:14 +0000 (09:08 +0000)
committertoyomoyo <toyomoyo>
Wed, 13 Sep 2006 09:08:14 +0000 (09:08 +0000)
24 files changed:
backup/backup_execute.html
backup/restore_check.html
blocks/news_items/block_news_items.php
course/category.php
course/reset.php
course/scales.php
course/student.php
files/index.php
lib/accesslib.php
lib/editor/htmlarea/coursefiles.php
lib/pagelib.php
mod/quiz/editlib.php
mod/quiz/index.php
mod/resource/type/directory/resource.class.php
mod/resource/type/ims/deploy.php
mod/resource/type/ims/resource.class.php
question/category.php
question/edit.php
question/editlib.php
question/import.php
question/showbank.php
question/type/datasetdependent/categorydatasetdefinitions.php
question/type/description/questiontype.php
user/index.php

index 4276c885be3a70e39e65cbd4ec237702dea3cfc9..dabed9e04dfe9ee950c827410206aee4e1f536e1 100644 (file)
@@ -9,7 +9,7 @@
             if (empty($to)) {
                 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
             } else {
-                if (!isteacheredit($to)) {
+                if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
                     error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
                 }
             }
index e97182335fa65c8e295aa9f8373930e02d661085..fb1dba3637b2506ebe95dd631a64d1fceaabd349 100644 (file)
             print_heading(get_string("choosecourse"));
             print_simple_box_start("center");
             foreach ($courses as $course) {
-                if (!isteacheredit($course->id)) {
+                if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $course->id))) {
                     continue;
                 }
                 if (empty($course->visible)) {
         //Final access control check
         if ($restore->course_id == 0 and !has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be a creator or admin to restore into new course!");
-        } else if ($restore->course_id != 0 and !isteacheredit($restore->course_id)) {
+        } else if ($restore->course_id != 0 and !has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $restore->course_id))) {
             error("You need to be an edit teacher or admin to restore into selected course!");
         }
         $show_continue_button = true;
index ac8cdb0e5e669a0ebe6953a5d86680be34f8476c..f23d30d0bc8aa919f68205ff21a66fa616241581 100644 (file)
@@ -35,7 +35,7 @@ class block_news_items extends block_base {
 
         /// First work out whether we can post to this group and if so, include a link
 
-            if (isteacheredit($COURSE->id)) {     /// Teachers can always post
+            if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {     /// Teachers can always post
                 $visiblegroups = -1; 
 
                 $text .= '<div align="center" class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
index dee217456dd93b64f2bb7ffbc935626c5a87bcde..f25e5e05623cb57fc4e9d123d4aaa0e2c6e21d19 100644 (file)
                     echo '<input type="checkbox" name="c'.$acourse->id.'" />';
                     $abletomovecourses = true;
 
-                } else if (isteacheredit($acourse->id)) {
+                } else if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $acourse->id))) {
                     echo '<td>';
                     echo '<a title="'.$strsettings.'" href="'.$CFG->wwwroot.'/course/edit.php?id='.$acourse->id.'">'.
                          '<img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" alt="'.$strsettings.'" /></a> ';
index 7b010eeff63db2cd864567bd9233a42f371a6f80..a9f0675348967be2a73258bbc1436533ab776c13 100755 (executable)
@@ -15,9 +15,7 @@ The feature will also reset the start date of the course if necessary.
         error("Course is misconfigured");
     }
 
-    if (!isteacheredit($course->id)) {
-        error('Only editing teachers can use this script');
-    }
+    require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
 
     $strreset = get_string('reset');
     $strresetcourse = get_string('resetcourse');
index b23729e787807b1de9a355516bdda0e30d077898..985db4385e9b823b4da830a8d0bd4ea5eee5821c 100644 (file)
         if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
             print_heading($strcustomscales);
 
-            if (isteacheredit($course->id)) {
+            if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 echo "<p align=\"center\">(";
                 print_string("scalestip");
                 echo ")</p>";
index 773b0e1bdbb7c348db2f18e9c21d748011af87bd..094a6b68d156c118eb7e5e640205d27f009a2516 100644 (file)
@@ -1,6 +1,6 @@
 <?php // $Id$
       // Script to assign students to courses
-
+    //deprecated, should use admin/roles/assign.php now
     require_once("../config.php");
 
     define("MAX_USERS_PER_PAGE", 5000);
index ef3071069644c1f5af6cae393845704a80ff8c83..dc570cc0d365c60e2b0e0f328cd6366e30936194 100644 (file)
@@ -35,9 +35,7 @@
 
     require_login($course->id);
 
-    if (! isteacheredit($course->id) ) {
-        error("You need to be a teacher with editing privileges");
-    }
+    require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
 
     function html_footer() {
         global $course, $choose;
@@ -798,7 +796,7 @@ function displaydir ($wdir) {
             } else if ($icon == "zip.gif") {
                 $edittext .= "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=unzip&amp;sesskey=$USER->sesskey&amp;choose=$choose\">$strunzip</a>&nbsp;";
                 $edittext .= "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=listzip&amp;sesskey=$USER->sesskey&amp;choose=$choose\">$strlist</a> ";
-                if (!empty($CFG->backup_version) and isteacheredit($id)) {
+                if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
                     $edittext .= "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$filesafe&amp;action=restore&amp;sesskey=$USER->sesskey&amp;choose=$choose\">$strrestore</a> ";
                 }
             }
index fe015e2550423aac3f0e0453221947c13ebe1688..c1c7abb1c53a2c246a647292895edf4f28a7fdc2 100755 (executable)
@@ -850,6 +850,13 @@ function moodle_install_roles() {
     if (in_array($CFG->prefix.'user_teachers', $dbtables)) {
         if ($userteachers = get_records('user_teachers')) {
             foreach ($userteachers as $teacher) {
+                // populate the user_lastaccess table
+                unset($access);
+                $access->timeaccess = $teacher->timeaccess;
+                $access->userid = $teacher->userid;
+                $access->courseid = $teacher->course;
+                insert_record('user_lastaccess', $access);
+                // assign the default student role
                 $coursecontext = get_context_instance(CONTEXT_COURSE, $teacher->course); // needs cache
                 if ($teacher->editall) { // editting teacher
                     role_assign($editteacherrole, $teacher->userid, 0, $coursecontext->id);
@@ -866,7 +873,14 @@ function moodle_install_roles() {
      */
     if (in_array($CFG->prefix.'user_students', $dbtables)) {
         if ($userstudents = get_records('user_students')) {
-            foreach ($userstudents as $student) {
+            foreach ($userstudents as $student) {  
+                // populate the user_lastaccess table
+                unset($access);
+                $access->timeaccess = $student->timeaccess;
+                $access->userid = $student->userid;
+                $access->courseid = $student->course;
+                insert_record('user_lastaccess', $access);
+                // assign the default student role
                 $coursecontext = get_context_instance(CONTEXT_COURSE, $student->course);
                 role_assign($studentrole, $student->userid, 0, $coursecontext->id);
             }
index 9d3d73f88a7ed276c9ad0812d5f1e565a03460e5..0755aa8d882f408fec61ab4634790073a5f7e61d 100644 (file)
@@ -32,9 +32,7 @@
 
     require_login($course->id);
 
-    if (! isteacheredit($course->id) ) {
-        error("Only teachers can edit files");
-    }
+    require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id));
 
     function html_footer() {
         echo "\n\n</body>\n</html>";
index e96ce866a1598e6ed76b55cbe7ada0dba1af9e5a..3d55e96cf961753772d73b792499a7735a951f99 100644 (file)
@@ -355,7 +355,7 @@ class page_course extends page_base {
         if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
         }
-        return isteacheredit($this->id);
+        return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_COURSE, $this->id));
     }
 
     // Is the user actually editing this page right now? This would have something
@@ -580,7 +580,7 @@ class page_generic_activity extends page_base {
 
     function user_allowed_editing() {
         $this->init_full();
-        return isteacheredit($this->modulerecord->course);
+        return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_COURSE, $this->modulerecord->course));
     }
 
     function user_is_editing() {
index 8c5c428e51d84268f3ad7b47c5b291f71cc44756..092f65c18037e35f19302e532ceba11e4398d396 100644 (file)
@@ -229,7 +229,7 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
             continue;
         }
         $question = $questions[$qnum];
-        $canedit = isteacheredit($question->course);
+        $canedit = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $question->course));
 
         echo "<td>";
         if ($count != 0) {
index 3494c9b26079d5776000d3748aa2a78b85a482ae..176a0ee070832f21e448b6eb3d1bb85999a5872b 100644 (file)
@@ -25,7 +25,7 @@
 // Print the header
 
     $strquizzes = get_string("modulenameplural", "quiz");
-    $streditquestions = isteacheredit($course->id)
+    $streditquestions = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $course->id))
                         ? "<form target=\"_parent\" method=\"get\" "
                            ." action=\"$CFG->wwwroot/question/edit.php\">"
                            ."<input type=\"hidden\" name=\"courseid\" "
index 4648b478213aec4b6a4dca044821e0661bdbdccd..1d50a7c81fbf33a00a1258119f750f2b05fbce41 100644 (file)
@@ -65,7 +65,7 @@ function display() {
             "", "", true, update_module_button($cm->id, $course->id, $this->strresource),
             navmenu($course, $cm));
 
-    if (isteacheredit($course->id)) {
+    if (has_capabilities('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id))) {
         echo "<div align=\"right\"><img src=\"$CFG->pixpath/i/files.gif\" height=\"16\" width=\"16\" alt=\"\" />&nbsp".
             "<a href=\"$CFG->wwwroot/files/index.php?id={$course->id}&amp;wdir=/{$resource->reference}$subdir\">".
             get_string("editfiles")."...</a></div>";
index 1beb7172cf9720930565508671bcb59edf246ba4..5c85f0559f9e12770bf4ccdad32e5f9959e94eca 100644 (file)
@@ -78,7 +78,7 @@
 /// Security Constraints (sesskey and isteacheredit)
     if (!confirm_sesskey()) {
         error(get_string('confirmsesskeybad', 'error'));
-    } else if (!isteacheredit($courseid)) {
+    } else if (!has_capabilities('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
         error(get_string('onlyeditingteachers', 'error'));
     }
 
index f6a8fe1926ae803ba71d27b420b6bf7db1f78eaa..1f0caa9ce8e4b7b9f5f7501f017571b1eaa07379 100644 (file)
@@ -334,7 +334,7 @@ class resource_ims extends resource_base {
 
     /// If there are any error, show it instead of the resource page
         if ($errorcode) {
-            if (!isteacheredit($course->id)) {
+            if (!has_capabilities('moodle/course:activityvisibility', get_context_instance(CONTEXT_COURSE, $course->id))) {
             /// Resource not available page
                 $errortext = get_string('resourcenotavailable','resource');
             } else {
index a3f3dc57fc31cff1b27104cd3dfa593ff01e00b3..150aea09d32ef3ad94a0adf8cc6dffe5b3526049 100644 (file)
@@ -48,7 +48,7 @@
 
     // TODO: generalise this to any activity
     if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
-        $strupdatemodule = isteacheredit($course->id)
+        $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
             ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
             : "";
         print_header_simple(get_string('editcategories', 'quiz'), '',
index 6d1fb00c7315ec3789c820785c944db0d70715ef..e70ec9436517e87fa6e7fbe97128b9377a4aaf96 100644 (file)
@@ -40,7 +40,7 @@
     $strquizzes = get_string('modulenameplural', 'quiz');
     $streditingquestions = get_string('editquestions', "quiz");
     if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
-        $strupdatemodule = isteacheredit($course->id)
+        $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
             ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
             : "";
         print_header_simple($streditingquestions, '',
index 1b2b26162ea16294c1f8985c6e7ebd3cc939c17e..f8d90632106c6b8b101f45e71b77bfa194b7a854 100644 (file)
@@ -263,7 +263,7 @@ function question_list($course, $categoryid, $quizid=0,
     echo '<table><tr>';
 
     // check if editing of this category is allowed
-    if (isteacheredit($category->course)) {
+    if (has_capability('moodle/question:managecateory', $context)) {
         echo "<td valign=\"top\"><b>$strcreatenewquestion:</b></td>";
         echo '<td valign="top" align="right">';
         popup_form ("$CFG->wwwroot/question/question.php?category=$category->id&amp;qtype=", $qtypemenu, "addquestion",
@@ -323,7 +323,7 @@ function question_list($course, $categoryid, $quizid=0,
     print_paging_bar($totalnumber, $page, $perpage,
                 "edit.php?courseid={$course->id}&amp;perpage=$perpage&amp;");
 
-    $canedit = isteacheredit($category->course);
+    $canedit = has_capability('moodle/question:manage', $context);
 
     echo '<form method="post" action="edit.php?courseid='.$course->id.'">';
     echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
index 32b18bcc1f7cf433a74d970660bb956f7a87a025..d8f21e85f9093ef8c83ba782583275c49915e429 100644 (file)
@@ -79,9 +79,7 @@
 
     require_login($course->id, false);
 
-    if (!isteacheredit($course->id)) {
-        error( $txt->onlyteachersimport );
-    }
+    require_capability('moodle/question:import', get_context_instance(CONTEXT_COURSE, $course->id));
 
     // ensure the files area exists for this course
     make_upload_directory( "$course->id" );
@@ -92,7 +90,7 @@
     //==========
 
     if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
-        $strupdatemodule = isteacheredit($course->id)
+        $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
             ? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename)
             : "";
         print_header_simple($txt->importquestions, '',
index 7f23eb8a6b28e1013e112dcfc73b336385bbc868..af11deb7148fd7c2a9b704ecb346c5757fdfee9e 100644 (file)
@@ -55,7 +55,7 @@
         if (!$tocategory = get_record('question_categories', 'id', $tocategoryid)) {
             error('Invalid category');
         }
-        if (!isteacheredit($tocategory->course)) {
+        if (!has_capability('moodle/question:managecateory', get_context_instance(CONTEXT_COURSE, $tocategory->course))){
             error(get_string('categorynoedit', 'quiz', $tocategory->name), 'edit.php?courseid=$course->id');
         }
         foreach ($_POST as $key => $value) {    // Parse input for question ids
index bf9dda3d8e9702c4102c541737bd316a5d107402..65f51cf772d5aa0022ff899697b972745d043e46 100644 (file)
     }
 
     require_login($course->id, false);
-
-    if (!isteacheredit($course->id)) {
-        error("Only the teacher can import quiz questions!");
-    }
+    require_capability('moodle/question:import', get_context_instance(CONTEXT_COURSE, $course->id));
 
     $DATASET_TYPES = array('1' => get_string('literal', 'quiz'),
                            '2' => get_string('file', 'quiz'),
index b084e1335ca6c494e2197b35cf74d607f86e5fd8..d215f4e18c72ec75bcbb257849651aa7da01bc7a 100644 (file)
@@ -36,7 +36,7 @@ class description_qtype extends default_questiontype {
 
         // For editing teachers print a link to an editing popup window
         $editlink = '';
-        if (isteacheredit($cmoptions->course)) {
+        if (has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $cmoptions->course))) {
             $stredit = get_string('edit');
             $linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" border="0" alt="'.$stredit.'" />';
             $editlink = link_to_popup_window('/question/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true);
index 54e6ae7d97253e9a0233e1f66401926431cdcba0..2c26ace1c8c3688800bf57283ee4790a6ecc877e 100644 (file)
 
     if (!empty($isteacher)) {
         // get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
-        $minlastaccess = get_field_sql('SELECT min(timeaccess) FROM '.$CFG->prefix.'user_lastaccess WHERE courseid = '.$course->id.' AND timeaccess != 0');
-        
+        // this might not work anymore because you always going to get yourself as the most recent entry? added $USER!=$user ch
+        $minlastaccess = get_field_sql('SELECT min(timeaccess) FROM '.$CFG->prefix.'user_lastaccess WHERE courseid = '.$course->id.' AND timeaccess != 0 AND userid!='.$USER->id);
         $lastaccess0exists = record_exists('user_lastaccess','courseid',$course->id,'timeaccess',0);
         $now = usergetmidnight(time());
         $timeaccess = array();