// 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)) {
$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 />';
$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 />';
}
'<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.'&marker=0&sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
'<img src="'.$CFG->pixpath.'/i/marked.gif" height="16" width="16" border="0" alt="'.$strmarkedthistopic.'" /></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" '.
' 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.'&marker=0&sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
'<img src="'.$CFG->pixpath.'/i/marked.gif" alt="'.$strmarkedthistopic.'" /></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="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.'&hide='.$section.'&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 '<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.'&hide='.$section.'&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 />';
}
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;
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");
$path = '.';
}
- if ($mod->visible) {
- $hideshow = '<a class="editing_hide" title="'.$str->hide.'" href="'.$path.'/mod.php?hide='.$mod->id.
- '&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.
- '&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.
+ '&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.
+ '&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) {
} else {
$groupmode = "";
}
-
- if ($moveselect) {
- $move = '<a class="editing_move" title="'.$str->move.'" href="'.$path.'/mod.php?copy='.$mod->id.
- '&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.
- '&move=-1&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.
- '&move=1&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.
+ '&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.
+ '&move=-1&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.
+ '&move=1&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.
- '&indent=-1&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.
- '&indent=1&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.
+ '&indent=-1&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.
+ '&indent=1&sesskey='.$sesskey.$section.'"><img'.
+ ' src="'.$CFG->pixpath.'/t/right.gif" class="iconsmall" '.
+ ' alt="'.$str->moveright.'" /></a>'."\n";
+ }
}
return '<span class="commands">'."\n".$leftright.$move.
}
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);
}
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);
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.
}
$isediting = $page->user_is_editing();
-
foreach($pageblocks[$position] as $instance) {
// $instance may have ->rec and ->obj
} // 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);
}
}
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)));
}
/**
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?
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';