diff --git a/course/search.php b/course/search.php index 4f2b5ae54af..4c087753e6f 100644 --- a/course/search.php +++ b/course/search.php @@ -163,14 +163,25 @@ echo "$strcategory"; echo "$strselect"; echo "$stredit"; - foreach ($courses as $course) { + foreach ($courses as $course) { + + $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + $course->fullname = highlight("$search", $course->fullname); $linkcss = $course->visible ? "" : " class=\"dimmed\" "; echo ""; echo "id\">$course->fullname"; echo "".$displaylist[$course->category].""; echo ""; - echo "id\">"; + + // this is ok since this will get inherited from course category context + // if it is set + if (has_capability('moodle/category:update', $coursecontext)) { + echo "id\">"; + } else { + echo "id\" disabled=\"disabled\">"; + } + echo ""; echo ""; if (empty($THEME->custompix)) { @@ -179,30 +190,47 @@ $pixpath = "$CFG->themedir/$CFG->theme/pix"; } - echo "wwwroot/course/edit.php?id=$course->id\"> "; - - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); + // checks whether user can update course settings + if (has_capability('moodle/course:update', $coursecontext)) { + echo "wwwroot/course/edit.php?id=$course->id\"> "; + } + + // checks whether user can do role assignment if (has_capability('moodle/role:assign', $coursecontext)) { echo''; echo ''.get_string('assignroles', 'role').''; } - - echo "id\"> "; - if (!empty($course->visible)) { - echo "id&sesskey=$USER->sesskey\"> "; - } else { - echo "id&sesskey=$USER->sesskey\"> "; + + // checks whether user can delete course + if (has_capability('moodle/course:delete', $coursecontext)) { + echo "id\"> "; + } + + // checks whether user can change visibility + if (has_capability('moodle/course:visibility', $coursecontext)) { + if (!empty($course->visible)) { + echo "id&sesskey=$USER->sesskey\"> "; + } else { + echo "id&sesskey=$USER->sesskey\"> "; + } + } + + // checks whether user can do site backup + if (has_capability('moodle/site:backup', $coursecontext)) { + echo "id\"> "; } - echo "id\"> "; - - echo "id&wdir=/backupdata\"> "; + // checks whether user can do restore + if (has_capability('moodle/site:restore', $coursecontext)) { + echo "id&wdir=/backupdata\"> "; + } + echo ""; } echo "";