]> git.mjollnir.org Git - moodle.git/commitdiff
made some changes so that if a user has any roles assigned in context_module or conte...
authortoyomoyo <toyomoyo>
Fri, 16 Feb 2007 07:57:19 +0000 (07:57 +0000)
committertoyomoyo <toyomoyo>
Fri, 16 Feb 2007 07:57:19 +0000 (07:57 +0000)
13 files changed:
blocks/moodleblock.class.php
course/format/lams/format.php
course/format/topics/format.php
course/format/weeks/format.php
course/format/weekscss/format.php
course/lib.php
course/mod.php
course/modedit.php
course/view.php
lib/blocklib.php
lib/moodlelib.php
lib/pagelib.php
lib/weblib.php

index f0550b66228faed534603b1c83d41bb1aaef59a0..9cfa7ae0060b6c0988cd1a6722af20c545584d9a 100644 (file)
@@ -305,7 +305,7 @@ class block_base {
         // context for site or course, i.e. participant list etc
         // check to see if user can edit site or course blocks.
         // blocks can appear on other pages such as mod and blog pages...
-        
+
         switch ($this->instance->pagetype) {
             case 'course-view':
                 if (!has_capability('moodle/site:manageblocks', $blockcontext)) {
index 2741bbea3e2ab22529b685d843dc611713e167f4..3fb6f646e95ca29867fd0ea0f626405aa1d82574 100644 (file)
@@ -108,7 +108,7 @@ if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
     $summaryformatoptions->noclean = true;
     echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
 
-    if (isediting($course->id)) {
+    if (isediting($course->id) && has_capability('moodle/course:update', $course->id)) {
         echo '<a title="'.$streditsummary.'" '.
             ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
             ' class="iconsmall" alt="'.$streditsummary.'" /></a><br /><br />';
@@ -263,7 +263,7 @@ while ($section <= $course->numsections) {
             $summaryformatoptions->noclean = true;
             echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
 
-            if (isediting($course->id)) {
+            if (isediting($course->id) && has_capability('moodle/course:update', $course->id)) {
                 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
                     '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'.$streditsummary.'" /></a><br /><br />';
             }
@@ -287,7 +287,7 @@ while ($section <= $course->numsections) {
                 '<img src="'.$CFG->pixpath.'/i/one.gif" height="16" width="16" border="0" alt="'.$strshowonlytopic.'" /></a><br />';
         }
 
-        if (isediting($course->id)) {
+            if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
             if ($course->marker == $section) {  // Show the "light globe" on/off
                 echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
                     '<img src="'.$CFG->pixpath.'/i/marked.gif" height="16" width="16" border="0" alt="'.$strmarkedthistopic.'" /></a><br />';
index 91e1681ff8d7ba18aa095549a780079dcc4b8483..0dd18f0cb6555bf14d0117938f9aee64fb5a83d3 100644 (file)
         $summaryformatoptions->noclean = true;
         echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
 
-        if (isediting($course->id)) {
+        if (isediting($course->id) && has_capability('moodle/course:update', $course->id)) {
             echo '<a title="'.$streditsummary.'" '.
                  ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
                  ' alt="'.$streditsummary.'" /></a><br /><br />';
                 $summaryformatoptions->noclean = true;
                 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
 
-                if (isediting($course->id)) {
+                if (isediting($course->id) && has_capability('moodle/course:update', $course->id)) {
                     echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
                          '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$streditsummary.'" /></a><br /><br />';
                 }
                      '<img src="'.$CFG->pixpath.'/i/one.gif" alt="'.$strshowonlytopic.'" /></a><br />';
             }
 
-            if (isediting($course->id)) {
+            if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 if ($course->marker == $section) {  // Show the "light globe" on/off
                     echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
                          '<img src="'.$CFG->pixpath.'/i/marked.gif" alt="'.$strmarkedthistopic.'" /></a><br />';
index 42dc88b393311aaf9019884753f047c648719e43..76598b64b5583906391e0008c42370744c4393d2 100644 (file)
         $summaryformatoptions->noclean = true;
         echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
 
-        if (isediting($course->id)) {
+        if (isediting($course->id) && has_capability('moodle/course:update', $course->id)) {
             echo '<a title="'.$streditsummary.'" '.
                  ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
                  'class="iconsmall edit" alt="'.$streditsummary.'" /></a><br /><br />';
                 $summaryformatoptions->noclean = true;
                 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
 
-                if (isediting($course->id)) {
+                if (isediting($course->id) && has_capability('moodle/course:update', $course->id)) {
                     echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
                          '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall edit" alt="'.$streditsummary.'" /></a><br /><br />';
                 }
                      '<img src="'.$CFG->pixpath.'/i/one.gif" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
             }
 
-            if (isediting($course->id)) {
+            if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 if ($thissection->visible) {        // Show the hide/show eye
                     echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strweekhide.'">'.
                          '<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
index d4fe8548a9570b151618aacfafde862e805cd48c..70e8efd7ff9b8074ff25075656f1ccc693a9c7c8 100644 (file)
         $summaryformatoptions->noclean = true;
         echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
 
-        if (isediting($course->id)) {
+        if (isediting($course->id) && has_capability('moodle/course:update', $course->id)) {
             echo '<p><a title="'.$streditsummary.'" '.
                  ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
                  ' class="icon edit" alt="'.$streditsummary.'" /></a></p>';
                      '<img src="'.$CFG->pixpath.'/i/one.gif" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
             }
 
-            if (isediting($course->id)) {
+            if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 if ($thissection->visible) {        // Show the hide/show eye
                     echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strweekhide.'">'.
                          '<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
                 $summaryformatoptions->noclean = true;
                 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
 
-                if (isediting($course->id)) {
+                if (isediting($course->id) && has_capability('moodle/course:update', $course->id)) {
                     echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
                          '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
                 }
index d4144d76ddeb460498fee4ebd5be04f1b1b5dec9..2f0b63731777141f9b1053bee2fceb30f9683b01 100644 (file)
@@ -1452,6 +1452,11 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
 function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false) {
     global $CFG;
 
+    // check to see if user can add menus
+    if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
+        return false;  
+    }
+
     static $resources = false;
     static $activities = false;
 
@@ -2200,6 +2205,12 @@ function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-
     static $str;
     static $sesskey;
 
+    $modcontext = get_context_instance(CONTEXT_MODULE, $mod->id);
+    // no permission to edit
+    if (!has_capability('moodle/course:manageactivities', $modcontext)) {
+        return false;  
+    }
+
     if (!isset($str)) {
         $str->delete         = get_string("delete");
         $str->move           = get_string("move");
@@ -2231,16 +2242,18 @@ function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-
         $path = '.';
     }
 
-    if ($mod->visible) {
-        $hideshow = '<a class="editing_hide" title="'.$str->hide.'" href="'.$path.'/mod.php?hide='.$mod->id.
-                    '&amp;sesskey='.$sesskey.$section.'"><img'.
-                    ' src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" '.
-                    ' alt="'.$str->hide.'" /></a>'."\n";
-    } else {
-        $hideshow = '<a class="editing_show" title="'.$str->show.'" href="'.$path.'/mod.php?show='.$mod->id.
-                    '&amp;sesskey='.$sesskey.$section.'"><img'.
-                    ' src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" '.
-                    ' alt="'.$str->show.'" /></a>'."\n";
+    if (has_capability('moodle/course:activityvisibility', $modcontext)) {
+        if ($mod->visible) {
+            $hideshow = '<a class="editing_hide" title="'.$str->hide.'" href="'.$path.'/mod.php?hide='.$mod->id.
+                        '&amp;sesskey='.$sesskey.$section.'"><img'.
+                        ' src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" '.
+                        ' alt="'.$str->hide.'" /></a>'."\n";
+        } else {
+            $hideshow = '<a class="editing_show" title="'.$str->show.'" href="'.$path.'/mod.php?show='.$mod->id.
+                        '&amp;sesskey='.$sesskey.$section.'"><img'.
+                        ' src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" '.
+                        ' alt="'.$str->show.'" /></a>'."\n";
+        }
     }
     if ($mod->groupmode !== false) {
         if ($mod->groupmode == SEPARATEGROUPS) {
@@ -2271,35 +2284,39 @@ function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-
     } else {
         $groupmode = "";
     }
-
-    if ($moveselect) {
-        $move =     '<a class="editing_move" title="'.$str->move.'" href="'.$path.'/mod.php?copy='.$mod->id.
-                    '&amp;sesskey='.$sesskey.$section.'"><img'.
-                    ' src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" '.
-                    ' alt="'.$str->move.'" /></a>'."\n";
-    } else {
-        $move =     '<a class="editing_moveup" title="'.$str->moveup.'" href="'.$path.'/mod.php?id='.$mod->id.
-                    '&amp;move=-1&amp;sesskey='.$sesskey.$section.'"><img'.
-                    ' src="'.$CFG->pixpath.'/t/up.gif" class="iconsmall" '.
-                    ' alt="'.$str->moveup.'" /></a>'."\n".
-                    '<a class="editing_movedown" title="'.$str->movedown.'" href="'.$path.'/mod.php?id='.$mod->id.
-                    '&amp;move=1&amp;sesskey='.$sesskey.$section.'"><img'.
-                    ' src="'.$CFG->pixpath.'/t/down.gif" class="iconsmall" '.
-                    ' alt="'.$str->movedown.'" /></a>'."\n";
+    
+    if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $mod->course))) {
+        if ($moveselect) {
+            $move =     '<a class="editing_move" title="'.$str->move.'" href="'.$path.'/mod.php?copy='.$mod->id.
+                        '&amp;sesskey='.$sesskey.$section.'"><img'.
+                        ' src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" '.
+                        ' alt="'.$str->move.'" /></a>'."\n";
+        } else {
+            $move =     '<a class="editing_moveup" title="'.$str->moveup.'" href="'.$path.'/mod.php?id='.$mod->id.
+                        '&amp;move=-1&amp;sesskey='.$sesskey.$section.'"><img'.
+                        ' src="'.$CFG->pixpath.'/t/up.gif" class="iconsmall" '.
+                        ' alt="'.$str->moveup.'" /></a>'."\n".
+                        '<a class="editing_movedown" title="'.$str->movedown.'" href="'.$path.'/mod.php?id='.$mod->id.
+                        '&amp;move=1&amp;sesskey='.$sesskey.$section.'"><img'.
+                        ' src="'.$CFG->pixpath.'/t/down.gif" class="iconsmall" '.
+                        ' alt="'.$str->movedown.'" /></a>'."\n";
+        }
     }
 
     $leftright = "";
-    if ($indent > 0) {
-        $leftright .= '<a class="editing_moveleft" title="'.$str->moveleft.'" href="'.$path.'/mod.php?id='.$mod->id.
-                      '&amp;indent=-1&amp;sesskey='.$sesskey.$section.'"><img'.
-                      ' src="'.$CFG->pixpath.'/t/left.gif" class="iconsmall" '.
-                      ' alt="'.$str->moveleft.'" /></a>'."\n";
-    }
-    if ($indent >= 0) {
-        $leftright .= '<a class="editing_moveright" title="'.$str->moveright.'" href="'.$path.'/mod.php?id='.$mod->id.
-                      '&amp;indent=1&amp;sesskey='.$sesskey.$section.'"><img'.
-                      ' src="'.$CFG->pixpath.'/t/right.gif" class="iconsmall" '.
-                      ' alt="'.$str->moveright.'" /></a>'."\n";
+    if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $mod->course))) {
+        if ($indent > 0) {
+            $leftright .= '<a class="editing_moveleft" title="'.$str->moveleft.'" href="'.$path.'/mod.php?id='.$mod->id.
+                        '&amp;indent=-1&amp;sesskey='.$sesskey.$section.'"><img'.
+                        ' src="'.$CFG->pixpath.'/t/left.gif" class="iconsmall" '.
+                        ' alt="'.$str->moveleft.'" /></a>'."\n";
+        }
+        if ($indent >= 0) {
+            $leftright .= '<a class="editing_moveright" title="'.$str->moveright.'" href="'.$path.'/mod.php?id='.$mod->id.
+                        '&amp;indent=1&amp;sesskey='.$sesskey.$section.'"><img'.
+                        ' src="'.$CFG->pixpath.'/t/right.gif" class="iconsmall" '.
+                        ' alt="'.$str->moveright.'" /></a>'."\n";
+        }
     }
 
     return '<span class="commands">'."\n".$leftright.$move.
index 07363f8e90a05ffb858a3e84e5834ba4639ad1a4..be25298f18610f3aa5fca57225aad46292b974b8 100644 (file)
         }
 
         require_login($cm->course); // needed to setup proper $COURSE
-        $context = get_context_instance(CONTEXT_COURSE, $cm->course);
+        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
         require_capability('moodle/course:activityvisibility', $context);
 
         set_coursemodule_visible($cm->id, 0);
         }
 
         require_login($cm->course); // needed to setup proper $COURSE
-        $context = get_context_instance(CONTEXT_COURSE, $cm->course);
+        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
         require_capability('moodle/course:manageactivities', $context);
 
         set_coursemodule_groupmode($cm->id, $groupmode);
index 493c43803115c25c43f7071c90535b10d1e79d57..7c7c07bc15be9615c87bb3956bfc929efcc7e004 100644 (file)
@@ -75,7 +75,7 @@
         }
 
         require_login($course->id); // needed to setup proper $COURSE
-        $context = get_context_instance(CONTEXT_COURSE, $course->id);
+        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
         require_capability('moodle/course:manageactivities', $context);
 
         if (! $module = get_record("modules", "id", $cm->module)) {
         }
 
         require_login($course->id); // needed to setup proper $COURSE
-        $context = get_context_instance(CONTEXT_COURSE, $course->id);
+        
+        if (!empty($fromform->coursemodule)) {
+            $context = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
+        } else {
+            $context = get_context_instance(CONTEXT_COURSE, $course->id);
+        }
         require_capability('moodle/course:manageactivities', $context);
 
         $fromform->course = $course->id;
         exit;
 
     } else {
-        $context = get_context_instance(CONTEXT_COURSE, $course->id);
+        if (!empty($cm->id)) {
+            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+        } else {
+            $context = get_context_instance(CONTEXT_COURSE, $course->id);
+        }
         require_capability('moodle/course:manageactivities', $context);
-
+        
         $streditinga = get_string("editinga", "moodle", $fullmodulename);
         $strmodulenameplural = get_string("modulenameplural", $module->name);
 
index f342fb3345a818eedc5c04027e48fb588c637b38..a59e2643482caa60185def8d9d163c6d3635952d 100644 (file)
 
         if ($USER->editing && !empty($USER->ajax) && !empty($CFG->enableajax) && $CFG->ajaxcapable) {
 
-            if (ajaxenabled()) {
+            if (ajaxenabled() && has_capability('moodle/course:manageactivities', $context)) {
                 
                 require_js(array('yui_yahoo',
                                  'yui_dom',
 
 
     // Use AJAX?
-    if ($CFG->useajax) {
+    if ($CFG->useajax && has_capability('moodle/course:manageactivities', $context)) {
         // At the bottom because we want to process sections and activities
         // after the relevant html has been generated. We're forced to do this
         // because of the way in which lib/ajax/ajaxcourse.js is written.
index 729a86fb9d0ccde442765f4488981c2e527c19d2..0cca837c3e32cbc9d486610965eac3b12b9c423c 100644 (file)
@@ -269,7 +269,6 @@ function blocks_print_group(&$page, &$pageblocks, $position) {
     }
 
     $isediting = $page->user_is_editing();
-
     foreach($pageblocks[$position] as $instance) {
         
         // $instance may have ->rec and ->obj
@@ -337,7 +336,7 @@ function blocks_print_group(&$page, &$pageblocks, $position) {
     } // End foreach
 
 
-    if ($page->blocks_default_position() == $position && $page->user_is_editing()) {
+    if ($page->blocks_default_position() == $position && $page->user_is_editing() && has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_COURSE, $COURSE->id))) {
         blocks_print_adminblock($page, $pageblocks);
     }
 }
index 345b476a907f50471f0c95d91cb7cf86dd5c7248..8d977e20c2067b448c97ded32c087207e26929e4 100644 (file)
@@ -2202,7 +2202,29 @@ function isediting($courseid, $user=NULL) {
     if (empty($user->editing)) {
         return false;
     }
-    return ($user->editing and has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid)));
+    
+    $capcheck = false;
+    $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
+    
+    if (has_capability('moodle/course:manageactivities', $coursecontext) ||
+        has_capability('moodle/site:manageblocks', $coursecontext)) {
+        $capcheck = true;      
+    } else {
+        // loop through all child context, see if user has moodle/course:manageactivities or moodle/site:manageblocks  
+        if ($children = get_child_contexts($coursecontext)) {
+            foreach ($children as $child) {
+                $childcontext = get_record('context', 'id', $child);
+                if (has_capability('moodle/course:manageactivities', $childcontext) ||
+                    has_capability('moodle/site:manageblocks', $childcontext)) {
+                    $capcheck = true;
+                    break;
+                }             
+            }          
+        }
+    }
+      
+    return ($user->editing && $capcheck);
+    //return ($user->editing and has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid)));
 }
 
 /**
index 69cdccfe2ed8a05b6e7007494364e99232c3de83..671c7579acd0231d6c5113b854268a235fd22b17 100644 (file)
@@ -350,7 +350,27 @@ class page_course extends page_base {
         if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
         }
-        return has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $this->id));
+        
+        $coursecontext = get_context_instance(CONTEXT_COURSE, $this->id);
+        $capcheck = false;   
+        if (has_capability('moodle/course:manageactivities', $coursecontext) ||
+            has_capability('moodle/site:manageblocks', $coursecontext)) {
+            $capcheck = true;      
+        } else {
+            // loop through all child context, see if user has moodle/course:manageactivities or moodle/site:manageblocks  
+            if ($children = get_child_contexts($coursecontext)) {
+                foreach ($children as $child) {
+                    $childcontext = get_record('context', 'id', $child);
+                    if (has_capability('moodle/course:manageactivities', $childcontext) ||
+                        has_capability('moodle/site:manageblocks', $childcontext)) {
+                        $capcheck = true;
+                        break;
+                    }             
+                }          
+            }
+        }
+        
+    return $capcheck;
     }
 
     // Is the user actually editing this course page or "sticky page" right now?
index 9f288fb539d5cd6d4f4fac09a654dc7516d708eb..d5d330084ce28aee1abebde1dce73fd1695bb72c 100644 (file)
@@ -3767,7 +3767,27 @@ function update_course_icon($courseid) {
 
     global $CFG, $USER;
 
-    if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
+    $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
+    
+    if (has_capability('moodle/course:manageactivities', $coursecontext) ||
+        has_capability('moodle/site:manageblocks', $coursecontext)) {
+        $capcheck = true;      
+    } else {
+        // loop through all child context, see if user has moodle/course:manageactivities or moodle/site:manageblocks  
+        if ($children = get_child_contexts($coursecontext)) {
+            foreach ($children as $child) {
+                $childcontext = get_record('context', 'id', $child);
+                if (has_capability('moodle/course:manageactivities', $childcontext) ||
+                    has_capability('moodle/site:manageblocks', $childcontext)) {
+                    $capcheck = true;
+                    break;
+                }             
+            }          
+        }
+    }
+    
+    
+    if ($capcheck) {
         if (!empty($USER->editing)) {
             $string = get_string('turneditingoff');
             $edit = '0';