Skip to content

Commit

Permalink
adding capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
toyomoyo committed Sep 11, 2006
1 parent 25b0fd8 commit 1c45e42
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 58 deletions.
4 changes: 2 additions & 2 deletions calendar/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,9 @@ function calendar_get_allowed_types(&$allowed) {
$allowed->user = true; // User events always allowed
$allowed->groups = false; // This may change just below
$allowed->courses = false; // This may change just below
$allowed->site = isteacher(SITEID);
$allowed->site = has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID));

if(!empty($SESSION->cal_course_referer) && $SESSION->cal_course_referer != SITEID && isteacher($SESSION->cal_course_referer, $USER->id)) {
if(!empty($SESSION->cal_course_referer) && $SESSION->cal_course_referer != SITEID && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $SESSION->cal_course_referer))) {
$course = get_record('course', 'id', $SESSION->cal_course_referer);

$allowed->courses = array($course->id => 1);
Expand Down
26 changes: 9 additions & 17 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,

global $USER, $CFG;

$isteacher = isteacher($course->id);
if ($advancedfilter) {

// Get all the possible users
$users = array();

if ($courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname')) {
foreach ($courseusers as $courseuser) {
$users[$courseuser->id] = fullname($courseuser, $isteacher);
$users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
}
}
if ($guest = get_guest()) {
Expand Down Expand Up @@ -267,9 +266,7 @@ function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limit
global $db;

/// Setup for group handling.
$isteacher = isteacher($course->id);
$isteacheredit = isteacheredit($course->id);


/// If the group mode is separate, and this user does not have editing privileges,
/// then only the user's group can be viewed.
if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
Expand Down Expand Up @@ -373,7 +370,6 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);

$strftimedatetime = get_string("strftimedatetime");
$isteacher = isteacher($course->id);

echo "<p align=\"center\">\n";
print_string("displayingrecords", "", $totalcount);
Expand Down Expand Up @@ -431,7 +427,7 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per
echo "<td class=\"r$row c2\" nowrap=\"nowrap\">\n";
link_to_popup_window("/iplookup/index.php?ip=$log->ip&amp;user=$log->userid", 'iplookup',$log->ip, 400, 700);
echo "</td>\n";
$fullname = fullname($log, $isteacher);
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
echo "<td class=\"r$row c3\" nowrap=\"nowrap\">\n";
echo " <a href=\"$CFG->wwwroot/user/view.php?id={$log->userid}&amp;course={$log->course}\">$fullname</a>\n";
echo "</td>\n";
Expand Down Expand Up @@ -473,7 +469,6 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);

$strftimedatetime = get_string("strftimedatetime");
$isteacher = isteacher($course->id);

$filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
$filename .= '.txt';
Expand Down Expand Up @@ -510,7 +505,7 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
$log->url = str_replace('&', '&amp;', $log->url); // XHTML compatibility

$firstField = $courses[$log->course];
$fullname = fullname($log, $isteacher);
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
$row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
$text = implode("\t", $row);
echo $text." \n";
Expand Down Expand Up @@ -546,7 +541,6 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname,
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);

$strftimedatetime = get_string("strftimedatetime");
$isteacher = isteacher($course->id);

$nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1));
$filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
Expand Down Expand Up @@ -612,7 +606,7 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname,
$excelTime=25569+$log->time/(3600*24);
$myxls->write($row, 1, $excelTime, $formatDate);
$myxls->write($row, 2, $log->ip, '');
$fullname = fullname($log, $isteacher);
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
$myxls->write($row, 3, $fullname, '');
$myxls->write($row, 4, $log->module.' '.$log->action, '');
$myxls->write($row, 5, $log->info, '');
Expand Down Expand Up @@ -654,7 +648,6 @@ function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname,
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
$strftimedatetime = get_string("strftimedatetime");
$isteacher = isteacher($course->id);
$filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
$filename .= '.sxw';
Expand Down Expand Up @@ -708,7 +701,7 @@ function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname,
$log->url = str_replace('&', '&amp;', $log->url); // XHTML compatibility
$firstField = $courses[$log->course];
$fullname = fullname($log, $isteacher);
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
$row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
$data[] = $row;
Expand Down Expand Up @@ -771,7 +764,7 @@ function print_recent_activity($course) {

global $CFG, $USER, $SESSION;

$isteacher = isteacher($course->id);
$isteacher = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id));

$timestart = time() - COURSE_MAX_RECENT_PERIOD;

Expand Down Expand Up @@ -809,7 +802,7 @@ function print_recent_activity($course) {
echo "<ol class=\"list\">\n";
foreach ($users as $user) {

$fullname = fullname($user, $isteacher);
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
echo '<li class="name"><a href="'.$CFG->wwwroot."/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
}
echo "</ol>\n</div>\n";
Expand Down Expand Up @@ -1068,7 +1061,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
if (!isset($isteacher)) {
$groupbuttons = ($course->groupmode or (!$course->groupmodeforce));
$groupbuttonslink = (!$course->groupmodeforce);
$isteacher = isteacher($course->id);
$isediting = isediting($course->id);
$ismoving = $isediting && ismoving($course->id);
if ($ismoving) {
Expand Down Expand Up @@ -1540,7 +1532,7 @@ function print_course($course, $width="100%") {
if (!$teacher->role) {
$teacher->role = $course->teacher;
}
$fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course
$fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); // is the USER a teacher of that course
echo $teacher->role.': <a href="'.$CFG->wwwroot.'/user/view.php?id='.$teacher->id.
'&amp;course='.SITEID.'">'.$fullname.'</a><br />';
}
Expand Down
4 changes: 2 additions & 2 deletions grade/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

require_login($course->id);

if (isteacher($course->id)) {
if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
$group = get_and_set_current_group($course, $course->groupmode, $group);
} else {
$group = get_current_group($course->id);
Expand Down Expand Up @@ -50,7 +50,7 @@

grade_set_uncategorized();

if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $course->id))) {
switch ($action) {
case "cats":
grade_set_categories();
Expand Down
45 changes: 24 additions & 21 deletions grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ function grade_get_grades() {
if ($mods) {
foreach ($mods as $mod) {
// hidden is a gradebook setting for an assignment and visible is a course_module setting
if (($mod->hidden != 1 && $mod->visible==1) or (isteacher($course->id) && $preferences->show_hidden==1)) {
if (($mod->hidden != 1 && $mod->visible==1) or (has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id)) && $preferences->show_hidden==1)) {
$libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
if (file_exists($libfile)) {
require_once($libfile);
Expand Down Expand Up @@ -1195,9 +1195,7 @@ function grade_download($download, $id) {
error("Course ID was incorrect");
}

if (!isteacher($course->id)) {
error("Only teachers can use this page!");
}
require_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $id));

$strgrades = get_string("grades");
$strgrade = get_string("grade");
Expand Down Expand Up @@ -1681,7 +1679,10 @@ function grade_view_category_grades($view_by_student) {
global $USER;
global $preferences;
global $group;
if (!isteacher($course->id)) {

$context = get_context_instance(CONTEXT_COURSE, $course->id);

if (!has_capability('moodle/course:viewcoursegrades', $context)) {
$view_by_student = $USER->id;
}

Expand Down Expand Up @@ -1714,7 +1715,7 @@ function grade_view_category_grades($view_by_student) {
//$maxpoints = 0;
$maxpercent = 0;
$reprint = 0;
if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
$student_heading_link = get_string('student','grades');
//only set sorting links if more than one student displayed.
if ($view_by_student == -1) {
Expand All @@ -1726,7 +1727,7 @@ function grade_view_category_grades($view_by_student) {
}
}
echo '<table align="center" class="grades">';
if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
$header = '<tr class="header"><th rowspan="2">'.$student_heading_link.'</th>';
}
else {
Expand Down Expand Up @@ -1778,7 +1779,7 @@ function grade_view_category_grades($view_by_student) {


// set the links to student information based on multiview or individual... if individual go to student info... if many go to individual grades view.
if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
if ($view_by_student != -1) {
$student_link = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$student.'&amp;course='.$course->id.'">';
}
Expand Down Expand Up @@ -1867,7 +1868,7 @@ function grade_view_category_grades($view_by_student) {
}

if ($first == 0) {
if (isteacher($course->id) && $view_by_student == -1) {
if (has_capability('moodle/course:viewcoursegrades', $context) && $view_by_student == -1) {
$total_sort_link = '<a href="?id='.$course->id.'&amp;group='.$group.'&amp;action=vcats&amp;cview='.$cview.'&amp;sort=highgrade_category"><img src="'.$CFG->wwwroot.'/pix/t/down.gif" alt="'.get_string('highgradedescending','grades').'" /></a>';
$total_sort_link .= '<a href="?id='.$course->id.'&amp;group='.$group.'&amp;action=vcats&amp;cview='.$cview.'&amp;sort=highgrade_category_asc"><img src="'.$CFG->wwwroot.'/pix/t/up.gif" alt="'.get_string('highgradeascending','grades').'" /></a>';
}
Expand Down Expand Up @@ -1899,7 +1900,7 @@ function grade_view_category_grades($view_by_student) {
$header1 .= '<th class="'.$class.'">'.$all_categories[$cview]['stats']['weight'].get_string('pctoftotalgrade','grades').'</th>';
}

if (isteacher($course->id) ) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
$header .= '<th rowspan="2">'.$student_heading_link.'</th></tr>';
}
else {
Expand All @@ -1917,7 +1918,7 @@ function grade_view_category_grades($view_by_student) {
echo get_string('grades','grades');
}

if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
helpbutton('teacher', get_string('gradehelp','grades'), 'grade');
}
else {
Expand Down Expand Up @@ -1951,7 +1952,7 @@ function grade_view_category_grades($view_by_student) {
$row .= '<td class="'.$class.'">'.$grades_by_student[$student][$cview]['stats']['weighted'].'%</td>';
}

if (isteacher($course->id) ) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
$row .= '<td class="fullname">'.$student_link.'</td>';
}
$row .= '</tr>';
Expand All @@ -1977,7 +1978,9 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a
global $group; // yu: fix for 5814
global $preferences;

if (!isteacher($course->id)) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);

if (!has_capability('moodle/course:viewcoursegrades', $context)) {
$view_by_student = $USER->id;
}

Expand Down Expand Up @@ -2005,7 +2008,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a
$reprint=0;

echo '<table align="center" class="grades">';
if (isteacher($course->id) ) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
$student_heading_link = get_string('student','grades');
if ($view_by_student == -1) {
$student_heading_link .='<a href="?id='.$course->id.'&amp;action=grades&amp;sort=lastname&amp;group='.$group.'"><br /><font size="-2">'.get_string('sortbylastname','grades').'</font></a>';
Expand Down Expand Up @@ -2040,7 +2043,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a
$oddrow = !$oddrow;

// set the links to student information based on multiview or individual... if individual go to student info... if many go to individual grades view.
if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
if ($view_by_student != -1) {
$studentviewlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$student.'&amp;course='.$course->id.'">'.$grades_by_student[$student]['student_data']['lastname'].', '.$grades_by_student[$student]['student_data']['firstname'].'</a>';
}
Expand Down Expand Up @@ -2113,7 +2116,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a
$total_columns = $grade_columns;
}

if (isteacher($course->id) && $view_by_student == -1) {
if (has_capability('moodle/course:viewcoursegrades', $context) && $view_by_student == -1) {
$grade_sort_link = '<a href="?id='.$course->id.'&amp;action=grades&amp;sort=highgrade&amp;group='.$group.'"><img src="'.$CFG->wwwroot.'/pix/t/down.gif" alt="'.get_string('highgradedescending','grades').'" /></a>';
$grade_sort_link .= '<a href="?id='.$course->id.'&amp;action=grades&amp;sort=highgrade_asc&amp;group='.$group.'"><img src="'.$CFG->wwwroot.'/pix/t/up.gif" alt="'.get_string('highgradeascending','grades').'" /></a>';
$points_sort_link = '<a href="?id='.$course->id.'&amp;action=grades&amp;sort=points&amp;group='.$group.'"><img src="'.$CFG->wwwroot.'/pix/t/down.gif" alt="'.get_string('pointsdescending','grades').'" /></a>';
Expand All @@ -2125,7 +2128,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a
}
$stats_link = '<a href="javascript:void(0)"onclick="window.open(\'?id='.$course->id.'&amp;action=stats&amp;category=all\',\''.get_string('statslink','grades').'\',\'height=200,width=300,scrollbars=no\')"><font size=-2>'.get_string('statslink','grades').'</font></a>';
$header .= '<th colspan="'.$total_columns.'">'.get_string('total','grades').'&nbsp;'.$stats_link.'</th>';
if (isteacher($course->id) && $view_by_student == -1) {
if (has_capability('moodle/course:viewcoursegrades', $context) && $view_by_student == -1) {
if ($preferences->show_points) {
$header1 .= '<th>'.get_string('points','grades').'('.$all_categories['stats']['totalpoints'].')';
if ($category != 'student_data' && $all_categories[$category]['stats']['bonus_points'] != 0) {
Expand Down Expand Up @@ -2164,14 +2167,14 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a
}
$header1 .= '</tr>';
}
if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
$header .= '<th rowspan="2">'.$student_heading_link.'</th></tr>';
}
// adjust colcount to reflect actual number of columns output
$colcount = $colcount * $grade_columns + $total_columns + 2;

echo '<tr><th colspan="'.$colcount.'"><font size="+1">'.get_string('allgrades','grades').'</font>';
if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
helpbutton('teacher', get_string('gradehelp','grades'), 'grade');
}
else {
Expand Down Expand Up @@ -2214,7 +2217,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a
}
}
}
if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', $context)) {
$row .= '<td>'. $studentviewlink .'</td></tr>';
}
else {
Expand Down Expand Up @@ -2887,7 +2890,7 @@ function grade_download_form($type='both') {
$type = 'both';
}

if (isteacher($course->id)) {
if (has_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo '<table align="center"><tr>';
$options['id'] = $course->id;
$options['sesskey'] = $USER->sesskey;
Expand Down
Loading

0 comments on commit 1c45e42

Please sign in to comment.