From 2cc773f5fac7cdb7f765a7ab894103973fb333b1 Mon Sep 17 00:00:00 2001 From: skodak <skodak> Date: Tue, 24 Jul 2007 21:20:29 +0000 Subject: [PATCH] MDL-10579 implemented capability checks in grader report, minor refactoring, whitespace cleanup --- grade/lib.php | 78 ++++++++-- grade/report/grader/index.php | 50 ++++--- grade/report/grader/lib.php | 231 ++++++++---------------------- grade/report/lib.php | 47 +----- grade/report/outcomes/course.html | 18 +-- grade/report/outcomes/course.php | 16 +-- grade/report/outcomes/site.php | 16 +-- grade/report/outcomes/tabs.php | 2 +- lib/gradelib.php | 4 - 9 files changed, 181 insertions(+), 281 deletions(-) diff --git a/grade/lib.php b/grade/lib.php index 76d2a48cbb..ca85582f94 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -335,6 +335,11 @@ class grade_tree { */ var $levels; + /** + * Course context + */ + var $context; + /** * Constructor, retrieves and stores a hierarchical array of all grade_category and grade_item * objects for the given courseid. Full objects are instantiated. @@ -351,6 +356,7 @@ class grade_tree { $this->courseid = $courseid; $this->commonvars = "&sesskey=$USER->sesskey&id=$this->courseid"; $this->levels = array(); + $this->context = get_context_instance(CONTEXT_COURSE, $courseid); // get course grade tree $this->top_element = grade_category::fetch_course_tree($courseid, true); @@ -528,12 +534,17 @@ class grade_tree { function get_edit_icon($element, $gpr) { global $CFG; - $context = get_context_instance(CONTEXT_COURSE, $this->courseid); - if (!has_capability('moodle/grade:manage', $context)) { + if (!has_capability('moodle/grade:manage', $this->context)) { return ''; } + static $stredit = null; + if (is_null($stredit)) { + $stredit = get_string('edit'); + } + $object = $element['object']; + $overlib = ''; switch ($element['type']) { case 'item': @@ -552,6 +563,11 @@ class grade_tree { //TODO: improve dealing with new grades $url = $CFG->wwwroot.'/grade/edit/grade.php?courseid='.$this->courseid.'&id='.$object->id; $url = $gpr->add_url_params($url); + if (!empty($object->feedback)) { + $feedback = format_text($object->feedback, $object->feedbackformat); + $function = "return overlib('".s(ltrim($object->feedback)."', FULLHTML);"); + $overlib = 'onmouseover="'.$function.'" onmouseout="return nd();"'; + } break; default: @@ -559,8 +575,7 @@ class grade_tree { } if ($url) { - $stredit = get_string('edit'); - return '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'.$stredit.'" title="'.$stredit.'"/></a>'; + return '<a href="'.$url.'"><img '.$overlib.' src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="'.$stredit.'" title="'.$stredit.'"/></a>'; } else { return ''; @@ -575,19 +590,23 @@ class grade_tree { function get_hiding_icon($element, $gpr) { global $CFG; - $context = get_context_instance(CONTEXT_COURSE, $this->courseid); - if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:hide', $context)) { + if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:hide', $this->context)) { return ''; } - if ($element['object']->is_hidden()) { + static $strshow = null; + static $strhide = null; + if (is_null($strshow)) { $strshow = get_string('show'); + $strhide = get_string('hide'); + } + + if ($element['object']->is_hidden()) { $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&action=show&sesskey='.sesskey().'&eid='.$element['eid']; $url = $gpr->add_url_params($url); $action = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.$strshow.'" title="'.$strshow.'"/></a>'; } else { - $strhide = get_string('hide'); $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&action=hide&sesskey='.sesskey().'&eid='.$element['eid']; $url = $gpr->add_url_params($url); $action = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.$strhide.'" title="'.$strhide.'"/></a>'; @@ -603,22 +622,25 @@ class grade_tree { function get_locking_icon($element, $gpr) { global $CFG; - $context = get_context_instance(CONTEXT_COURSE, $this->courseid); + static $strunlock = null; + static $strlock = null; + if (is_null($strunlock)) { + $strunlock = get_string('unlock', 'grades'); + $strlock = get_string('lock', 'grades'); + } if ($element['object']->is_locked()) { - if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:unlock', $context)) { + if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:unlock', $this->context)) { return ''; } - $strunlock = get_string('unlock', 'grades'); $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&action=unlock&sesskey='.sesskey().'&eid='.$element['eid']; $url = $gpr->add_url_params($url); $action = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/unlock.gif" class="iconsmall" alt="'.$strunlock.'" title="'.$strunlock.'"/></a>'; } else { - if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:lock', $context)) { + if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:lock', $this->context)) { return ''; } - $strlock = get_string('lock', 'grades'); $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&action=lock&sesskey='.sesskey().'&eid='.$element['eid']; $url = $gpr->add_url_params($url); $action = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/lock.gif" class="iconsmall" alt="'.$strlock.'" title="'.$strlock.'"/></a>'; @@ -626,6 +648,36 @@ class grade_tree { return $action; } + /** + * Return calculation icon for given element + * @param object $element + * @return string + */ + function get_calculation_icon($element, $gpr) { + global $CFG; + if (!has_capability('moodle/grade:manage', $this->context)) { + return ''; + } + + $calculation_icon = ''; + + $type = $element['type']; + $object = $element['object']; + + if ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') { + $streditcalculation = get_string('editcalculation', 'grades'); + + // show calculation icon only when calculation possible + if (!$object->is_normal_item() and ($object->gradetype == GRADE_TYPE_SCALE or $object->gradetype == GRADE_TYPE_VALUE)) { + $url = $CFG->wwwroot.'/grade/edit/calculation.php?courseid='.$this->courseid.'&id='.$object->id; + $url = $gpr->add_url_params($url); + $calculation_icon = '<a href="'. $url.'"><img src="'.$CFG->pixpath.'/t/calc.gif" class="iconsmall" alt="' + . $streditcalculation.'" title="'.$streditcalculation.'" /></a>'. "\n"; + } + } + + return $calculation_icon; + } } ?> diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index 3c385bf20b..1d95ee499a 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -47,7 +47,9 @@ if (!$course = get_record('course', 'id', $courseid)) { } require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); + require_capability('gradereport/grader:view', $context); +require_capability('moodle/grade:viewall', $context); /// return tracking object $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'grader', 'courseid'=>$courseid, 'page'=>$page)); @@ -71,29 +73,39 @@ $navigation = build_navigation($navlinks); /// Build editing on/off buttons if (!isset($USER->gradeediting)) { - $USER->gradeediting = 0; + $USER->gradeediting = array(); } -if (($edit == 1) and confirm_sesskey()) { - $USER->gradeediting = 1; -} else if (($edit == 0) and confirm_sesskey()) { - $USER->gradeediting = 0; -} +if (has_capability('moodle/grade:override', $context)) { + if (!isset($USER->gradeediting[$course->id])) { + $USER->gradeediting[$course->id] = 0; + } + + if (($edit == 1) and confirm_sesskey()) { + $USER->gradeediting[$course->id] = 1; + } else if (($edit == 0) and confirm_sesskey()) { + $USER->gradeediting[$course->id] = 0; + } -// page params for the turn editting on -$options = $gpr->get_options(); -$options['sesskey'] = sesskey(); + // page params for the turn editting on + $options = $gpr->get_options(); + $options['sesskey'] = sesskey(); + + if ($USER->gradeediting[$course->id]) { + $options['edit'] = 0; + $string = get_string('turneditingoff'); + } else { + $options['edit'] = 1; + $string = get_string('turneditingon'); + } + + $buttons = print_single_button('index.php', $options, $string, 'get', '_self', true); -if ($USER->gradeediting) { - $options['edit'] = 0; - $string = get_string('turneditingoff'); } else { - $options['edit'] = 1; - $string = get_string('turneditingon'); + $USER->gradeediting[$course->id] = 0; + $buttons = ''; } -$buttons = print_single_button('index.php', $options, $string, 'get', '_self', true); - $gradeserror = array(); // Handle toggle change request @@ -117,7 +129,7 @@ if ($perpageurl) { $report->user_prefs['studentsperpage'] = $perpageurl; } -// Perform actions on categories, items and grades +// Perform actions if (!empty($target) && !empty($action) && confirm_sesskey()) { $report->process_action($target, $action); } @@ -153,7 +165,7 @@ $reporthtml .= $report->get_avghtml(); $reporthtml .= "</table>"; // print submit button -if ($USER->gradeediting) { +if ($USER->gradeediting[$course->id]) { echo '<form action="index.php" method="post">'; echo '<div>'; echo '<input type="hidden" value="'.$courseid.'" name="id" />'; @@ -164,7 +176,7 @@ if ($USER->gradeediting) { echo $reporthtml; // print submit button -if ($USER->gradeediting && ($report->get_pref('quickfeedback') || $report->get_pref('quickgrading'))) { +if ($USER->gradeediting[$course->id] && ($report->get_pref('quickfeedback') || $report->get_pref('quickgrading'))) { echo '<div class="submit"><input type="submit" value="'.get_string('update').'" /></div>'; echo '</div></form>'; } diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index aff58e5ff0..bd09921df0 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -85,6 +85,11 @@ class grade_report_grader extends grade_report { * @return bool Success or Failure (array of errors). */ function process_data($data) { + + if (!has_capability('moodle/grade:override', $this->context)) { + return false; + } + // always initialize all arrays $queue = array(); foreach ($data as $varname => $postedvalue) { @@ -283,10 +288,18 @@ class grade_report_grader extends grade_report { function get_toggles_html() { global $USER; $html = '<div id="grade-report-toggles">'; - if ($USER->gradeediting) { - $html .= $this->print_toggle('eyecons', true); - $html .= $this->print_toggle('locks', true); - $html .= $this->print_toggle('calculations', true); + if ($USER->gradeediting[$this->courseid]) { + if (has_capability('moodle/grade:manage', $this->context) or has_capability('moodle/grade:hide', $this->context)) { + $html .= $this->print_toggle('eyecons', true); + } + if (has_capability('moodle/grade:manage', $this->context) + or has_capability('moodle/grade:lock', $this->context) + or has_capability('moodle/grade:unlock', $this->context)) { + $html .= $this->print_toggle('locks', true); + } + if (has_capability('moodle/grade:manage', $this->context)) { + $html .= $this->print_toggle('calculations', true); + } } $html .= $this->print_toggle('averages', true); @@ -453,7 +466,7 @@ class grade_report_grader extends grade_report { $headerhtml .= '<th class="category'.$catlevel.'" '.$colspan.'>'.$element['object']->get_name(); // Print icons - if ($USER->gradeediting) { + if ($USER->gradeediting[$this->courseid]) { $headerhtml .= $this->get_icons($element); } @@ -542,7 +555,7 @@ class grade_report_grader extends grade_report { $studentshtml .= '<tr><th class="user">' . $user_pic . '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '">' . fullname($user) . '</a></th>'; - foreach ($this->items as $item) { + foreach ($this->items as $itemid=>$item) { // Get the decimal points preference for this item $decimalpoints = $this->get_pref('decimalpoints', $item->id); @@ -555,10 +568,16 @@ class grade_report_grader extends grade_report { } else { $gradeval = null; - $grade = new grade_grade(array('userid' => $userid, 'itemid' => $item->id), false); + $grade = new grade_grade(array('userid'=>$userid, 'itemid'=>$item->id), false); $grade->feedback = ''; } + $grade->courseid = $this->courseid; + $grade->grade_item =& $this->items[$itemid]; // this speedsup is_hidden() and other grade_grade methods + + // emulate grade element + $element = array('eid'=>'g'.$grade->id, 'object'=>$grade, 'type'=>'grade'); + if ($grade->is_overridden()) { $studentshtml .= '<td class="overridden">'; } else { @@ -569,18 +588,10 @@ class grade_report_grader extends grade_report { $studentshtml .= get_string('excluded', 'grades'); // TODO: improve visual representation of excluded grades } - // emulate grade element - $grade->courseid = $this->courseid; - $grade->grade_item = $item; // this may speedup is_hidden() and other grade_grade methods - $element = array ('eid'=>'g'.$grade->id, 'object'=>$grade, 'type'=>'grade'); - // Do not show any icons if no grade (no record in DB to match) // TODO: change edit/hide/etc. links to use itemid and userid to allow creating of new grade objects - if (!$item->needsupdate and !empty($grade->id) and $USER->gradeediting) { - $states = array('is_hidden' => $item->hidden, - 'is_locked' => $item->locked, - 'is_editable' => $item->gradetype != GRADE_TYPE_NONE && !$grade->locked && !$item->locked); - $studentshtml .= $this->get_icons($element, null, true, $states); + if (!$item->needsupdate and !empty($grade->id) and $USER->gradeediting[$this->courseid]) { + $studentshtml .= $this->get_icons($element); } // if in editting mode, we need to print either a text box @@ -589,7 +600,7 @@ class grade_report_grader extends grade_report { if ($item->needsupdate) { $studentshtml .= '<span class="gradingerror">'.get_string('error').'</span>'; - } else if ($USER->gradeediting) { + } else if ($USER->gradeediting[$this->courseid]) { // We need to retrieve each grade_grade object from DB in order to // know if they are hidden/locked @@ -776,7 +787,7 @@ class grade_report_grader extends grade_report { $decimalpoints = $this->get_pref('decimalpoints', $item->id); // Determine which display type to use for this average $gradedisplaytype = $this->get_pref('gradedisplaytype', $item->id); - if ($USER->gradeediting) { + if ($USER->gradeediting[$this->courseid]) { $displaytype = GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL; } elseif ($averagesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // Inherit specific column or general preference $displaytype = $gradedisplaytype; @@ -846,7 +857,7 @@ class grade_report_grader extends grade_report { // Determine which display type to use for this range $gradedisplaytype = $this->get_pref('gradedisplaytype', $item->id); - if ($USER->gradeediting) { + if ($USER->gradeediting[$this->courseid]) { $displaytype = GRADE_REPORT_GRADE_DISPLAY_TYPE_REAL; } elseif ($rangesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // Inherit specific column or general preference $displaytype = $gradedisplaytype; @@ -883,177 +894,51 @@ class grade_report_grader extends grade_report { * with the icons needed for the grader report. * * @param object $object - * @param array $icons An array of icon names that this function is explicitly requested to print, regardless of settings - * @param bool $limit If true, use the $icons array as the only icons that will be printed. If false, use it to exclude these icons. - * @param object $states An optional array of states (hidden, locked, editable), shortcuts to increase performance. * @return string HTML */ - function get_icons($element, $icons=null, $limit=true, $states=array()) { - global $CFG; - global $USER; - - // Load language strings - $stredit = $this->get_lang_string("edit"); - $streditcalculation= $this->get_lang_string("editcalculation", 'grades'); - $strfeedback = $this->get_lang_string("feedback"); - $strmove = $this->get_lang_string("move"); - $strmoveup = $this->get_lang_string("moveup"); - $strmovedown = $this->get_lang_string("movedown"); - $strmovehere = $this->get_lang_string("movehere"); - $strcancel = $this->get_lang_string("cancel"); - $stredit = $this->get_lang_string("edit"); - $strdelete = $this->get_lang_string("delete"); - $strhide = $this->get_lang_string("hide"); - $strshow = $this->get_lang_string("show"); - $strlock = $this->get_lang_string("lock", 'grades'); - $strswitch_minus = $this->get_lang_string("contract", 'grades'); - $strswitch_plus = $this->get_lang_string("expand", 'grades'); - $strunlock = $this->get_lang_string("unlock", 'grades'); - - // Prepare container div - $html = '<div class="grade_icons">'; - - // Prepare reference variables - $eid = $element['eid']; - $object = $element['object']; - $type = $element['type']; - - if (empty($states)) { - $states['is_hidden'] = $object->is_hidden(); - $states['is_locked'] = $object->is_locked(); - $states['is_editable'] = $object->is_editable(); - } - - // Add mock attributes in case the object is not of the right type - if ($type != 'grade') { - $object->feedback = ''; - } - - $overlib = ''; - if (!empty($object->feedback)) { - if (empty($object->feedbackformat) || $object->feedbackformat != 1) { - $function = "return overlib('" . strip_tags($object->feedback) . "', CAPTION, '$strfeedback');"; - } else { - $function = "return overlib('" . s(ltrim($object->feedback) . "', FULLHTML);"); - } - $overlib = 'onmouseover="' . $function . '" onmouseout="return nd();"'; - } + function get_icons($element) { + global $CFG, $USER; - // Prepare image strings - $edit_icon = ''; - if ($states['is_editable']) { - if ($type == 'category') { - $url = GRADE_EDIT_URL . '/category.php?courseid='.$object->courseid.'&id='.$object->id; - $url = $this->gpr->add_url_params($url); - $edit_icon = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="' - . $stredit.'" title="'.$stredit.'" /></a>'. "\n"; - } else if ($type == 'item' or $type == 'categoryitem' or $type == 'courseitem'){ - $url = GRADE_EDIT_URL . '/item.php?courseid='.$object->courseid.'&id='.$object->id; - $url = $this->gpr->add_url_params($url); - $edit_icon = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall" alt="' - . $stredit.'" title="'.$stredit.'" /></a>'. "\n"; - } else if ($type == 'grade' and ($states['is_editable'] or empty($object->id))) { - // TODO: change link to use itemid and userid to allow creating of new grade objects - $url = GRADE_EDIT_URL . '/grade.php?courseid='.$object->courseid.'&id='.$object->id; - $url = $this->gpr->add_url_params($url); - $edit_icon = '<a href="'.$url.'"><img ' . $overlib . ' src="'.$CFG->pixpath.'/t/edit.gif"' - . 'class="iconsmall" alt="' . $stredit.'" title="'.$stredit.'" /></a>'. "\n"; - } + if (!$USER->gradeediting[$this->courseid]) { + return '<div class="grade_icons" />'; } + // Init all icons + $edit_icon = $this->gtree->get_edit_icon($element, $this->gpr); $edit_calculation_icon = ''; - if ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') { - // show calculation icon only when calculation possible - if (!$object->is_normal_item() and ($object->gradetype == GRADE_TYPE_SCALE or $object->gradetype == GRADE_TYPE_VALUE)) { - $url = GRADE_EDIT_URL . '/calculation.php?courseid='.$object->courseid.'&id='.$object->id; - $url = $this->gpr->add_url_params($url); - $edit_calculation_icon = '<a href="'. $url.'"><img src="'.$CFG->pixpath.'/t/calc.gif" class="iconsmall" alt="' - . $streditcalculation.'" title="'.$streditcalculation.'" /></a>'. "\n"; - } - } + $show_hide_icon = ''; + $contract_expand_icon = ''; + $lock_unlock_icon = ''; - // Prepare Hide/Show icon state - $hide_show = 'hide'; - if ($states['is_hidden']) { - $hide_show = 'show'; + if ($this->get_pref('showcalculations')) { + $edit_calculation_icon = $this->gtree->get_calculation_icon($element, $this->gpr); } - $show_hide_icon = '<a href="index.php?target='.$eid - . "&action=$hide_show" . $this->gtree->commonvars . "\">\n" - . '<img src="'.$CFG->pixpath.'/t/'.$hide_show.'.gif" class="iconsmall" alt="' - . ${'str' . $hide_show}.'" title="'.${'str' . $hide_show}.'" /></a>'. "\n"; - - // Prepare lock/unlock string - $lock_unlock = 'lock'; - if ($states['is_locked']) { - $lock_unlock = 'unlock'; + if ($this->get_pref('showeyecons')) { + $show_hide_icon = $this->gtree->get_hiding_icon($element, $this->gpr); } - // Print lock/unlock icon - - $lock_unlock_icon = '<a href="index.php?target='.$eid - . "&action=$lock_unlock" . $this->gtree->commonvars . "\">\n" - . '<img src="'.$CFG->pixpath.'/t/'.$lock_unlock.'.gif" class="iconsmall" alt="' - . ${'str' . $lock_unlock}.'" title="'.${'str' . $lock_unlock}.'" /></a>'. "\n"; - - // Prepare expand/contract string - $expand_contract = 'switch_minus'; // Default: expanded - $state = get_user_preferences('grade_category_' . $object->id, GRADE_CATEGORY_EXPANDED); - if ($state == GRADE_CATEGORY_CONTRACTED) { - $expand_contract = 'switch_plus'; + if ($this->get_pref('showlocks')) { + $lock_unlock_icon = $this->gtree->get_locking_icon($element, $this->gpr); } - $contract_expand_icon = '<a href="index.php?target=' . $eid + // If object is a category, display expand/contract icon + if ($element['type'] == 'category' && $this->get_pref('aggregationview') == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) { + // Load language strings + $strswitch_minus = $this->get_lang_string('contract', 'grades'); + $strswitch_plus = $this->get_lang_string('expand', 'grades'); + $expand_contract = 'switch_minus'; // Default: expanded + $state = get_user_preferences('grade_category_'.$element['object']->id, GRADE_CATEGORY_EXPANDED); + if ($state == GRADE_CATEGORY_CONTRACTED) { + $expand_contract = 'switch_plus'; + } + $contract_expand_icon = '<a href="index.php?target=' . $element['eid'] . "&action=$expand_contract" . $this->gtree->commonvars . "\">\n" . '<img src="'.$CFG->pixpath.'/t/'.$expand_contract.'.gif" class="iconsmall" alt="' . ${'str' . $expand_contract}.'" title="'.${'str' . $expand_contract}.'" /></a>'. "\n"; - - // If an array of icon names is given, return only these in the order they are given - if (!empty($icons) && is_array($icons)) { - $new_html = ''; - - foreach ($icons as $icon_name) { - if ($limit) { - $new_html .= ${$icon_name . '_icon'}; - } else { - ${'show_' . $icon_name} = false; - } - } - if ($limit) { - return $new_html; - } else { - $html .= $new_html; - } - } - - // Icons shown when edit mode is on - if ($USER->gradeediting) { - // Edit icon (except for grade_grade) - if ($edit_icon) { - $html .= $edit_icon; - } - - // Calculation icon for items and categories - if ($this->get_pref('showcalculations')) { - $html .= $edit_calculation_icon; - } - - if ($this->get_pref('showeyecons')) { - $html .= $show_hide_icon; - } - - if ($this->get_pref('showlocks')) { - $html .= $lock_unlock_icon; - } - - // If object is a category, display expand/contract icon - if (get_class($object) == 'grade_category' && $this->get_pref('aggregationview') == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) { - $html .= $contract_expand_icon; - } - } else { // Editing mode is off } - return $html . '</div>'; + return '<div class="grade_icons">'.$edit_icon.$edit_calculation_icon.$show_hide_icon.$lock_unlock_icon.$contract_expand_icon.'</div>'; } } ?> diff --git a/grade/report/lib.php b/grade/report/lib.php index f540c9aa64..da008d5b0a 100755 --- a/grade/report/lib.php +++ b/grade/report/lib.php @@ -197,54 +197,9 @@ class grade_report { * @param string $target Sortorder * @param string $action Which action to take (edit, delete etc...) * @return - * TODO Update this, it's quite old and needs a major makeover */ function process_action($target, $action) { - $element = $this->gtree->locate_element($target); - - switch ($action) { - case 'edit': - break; - case 'delete': - if ($confirm == 1) { // Perform the deletion - //TODO: add proper delete support for grade items and categories - //$element['object']->delete(); - // Print result message - - } else { // Print confirmation dialog - $eid = $element['eid']; - $strdeletecheckfull = $this->get_lang_string('deletecheck', '', $element['object']->get_name()); - $linkyes = GRADE_EDIT_URL . "/tree.php?target=$eid&action=delete&confirm=1$this->gtree->commonvars"; - $linkno = GRADE_EDIT_URL . "/tree.php?$this->gtree->commonvars"; - notice_yesno($strdeletecheckfull, $linkyes, $linkno); - } - break; - - case 'hide': - // TODO Implement calendar for selection of a date to hide element until - $element['object']->set_hidden(1); - $this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition')); - break; - case 'show': - $element['object']->set_hidden(0); - $this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition')); - break; - case 'lock': - // TODO Implement calendar for selection of a date to lock element after - if (!$element['object']->set_locked(1)) { - debugging("Could not update the element's locked state!"); - } - $this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition')); - break; - case 'unlock': - if (!$element['object']->set_locked(0)) { - debugging("Could not update the element's locked state!"); - } - $this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition')); - break; - default: - break; - } + //implement if needed } /** diff --git a/grade/report/outcomes/course.html b/grade/report/outcomes/course.html index 25bdc4e1f6..59232aaf54 100755 --- a/grade/report/outcomes/course.html +++ b/grade/report/outcomes/course.html @@ -2,29 +2,29 @@ <tr> <td> <select id="addoutcomes" size="20" name="addoutcomes[]" multiple="multiple"> - - <?php + + <?php foreach ($outcomes as $outcome) { - echo '<option value="'.$outcome->id.'">'.$outcome->shortname.'</option>'; + echo '<option value="'.$outcome->id.'">'.$outcome->shortname.'</option>'; } ?> - </select> - </td> + </select> + </td> <td> <p class="arrow_button"> <input name="add" id="add" type="submit" value="<?php echo ' '.$THEME->larrow.' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" /> <br /> <input name="remove" id="remove" type="submit" value="<?php echo ' '.$THEME->rarrow.' '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" /> </p> - </td> + </td> <td> <select id="removeoutcomes" size="20" name="removeoutcomes[]" multiple="multiple"> - <?php + <?php foreach ($courseoutcomes as $courseoutcome) { - echo '<option value="'.$courseoutcome->id.'">'.$courseoutcome->shortname.'</option>'; + echo '<option value="'.$courseoutcome->id.'">'.$courseoutcome->shortname.'</option>'; } ?> - </select> + </select> </td> </tr> </table> \ No newline at end of file diff --git a/grade/report/outcomes/course.php b/grade/report/outcomes/course.php index b1cb29311b..21795e505f 100755 --- a/grade/report/outcomes/course.php +++ b/grade/report/outcomes/course.php @@ -8,18 +8,18 @@ $courseid = required_param('id', SITEID, PARAM_INT); // course id /// form processing print_header(); - + // Add tabs $currenttab = 'outcomesettings'; - include('tabs.php'); - - /// listing of all site outcomes + this course specific outcomes - $outcomes = get_records_sql('SELECT * FROM '.$CFG->prefix.'grade_outcomes - WHERE ISNULL(courseid)'); + include('tabs.php'); + + /// listing of all site outcomes + this course specific outcomes + $outcomes = get_records_sql('SELECT * FROM '.$CFG->prefix.'grade_outcomes + WHERE ISNULL(courseid)'); get_records('grade_outcomes', 'courseid', $courseid); - + check_theme_arrows(); include_once('course.html'); - + print_footer(); ?> \ No newline at end of file diff --git a/grade/report/outcomes/site.php b/grade/report/outcomes/site.php index 3318c32247..6537653939 100755 --- a/grade/report/outcomes/site.php +++ b/grade/report/outcomes/site.php @@ -17,7 +17,7 @@ $search = optional_param('search', 0, PARAM_TEXT); $deleteid = optional_param('deleteid', 0, PARAM_INT); // which outcome to delete $confirm = optional_param('confirm', 0, PARAM_INT); $perpage = 30; - + // form processing if ($deleteid && confirm_sesskey()) { if ($confirm) { @@ -41,7 +41,7 @@ $perpage = 30; exit; } } - + /// display information admin_externalpage_setup('gradereportoutcomes'); admin_externalpage_print_header(); @@ -76,22 +76,22 @@ $perpage = 30; foreach ($outcomes as $outcome) { $data = array(); - + // full name of the outcome $data[] = $outcome['fullname']; - + // full name of the scale used by this outcomes $scale= get_record('scale', 'id', $outcome['scaleid']); $data[] = $scale->name; - + // get course if ($outcome['courseid']) { $course = get_record('course', 'id', $outcome['courseid']); $data[] = $course->shortname; } else { - $data[] = get_string('site'); - } - + $data[] = get_string('site'); + } + // add operations $data[] = '<a href="editoutcomes.php?id='.$outcome['id'].'&sesskey='.sesskey().'"><img alt="Update" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a> <a href="settings.php?deleteid='.$outcome['id'].'&sesskey='.sesskey().'"><img alt="Delete" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/></a>'; // icons and links diff --git a/grade/report/outcomes/tabs.php b/grade/report/outcomes/tabs.php index 8f88907e81..30a2a03061 100644 --- a/grade/report/outcomes/tabs.php +++ b/grade/report/outcomes/tabs.php @@ -11,7 +11,7 @@ } else { $row[] = new tabobject('outcomesettings', $CFG->wwwroot.'/grade/report/outcomes/site.php?id='.$courseid, - get_string('settings')); + get_string('settings')); } $row[] = new tabobject('editoutcomes', diff --git a/lib/gradelib.php b/lib/gradelib.php index 210415f9df..68599109f8 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -81,10 +81,6 @@ define('GRADE_REPORT_PREFERENCE_DEFAULT', 'default'); define('GRADE_REPORT_PREFERENCE_INHERIT', 'inherit'); define('GRADE_REPORT_PREFERENCE_UNUSED', -1); -// Common directories -define('GRADE_EDIT_DIR', $CFG->dirroot . '/grade/edit'); -define('GRADE_EDIT_URL', $CFG->wwwroot . '/grade/edit'); - require_once($CFG->libdir . '/grade/grade_category.php'); require_once($CFG->libdir . '/grade/grade_item.php'); require_once($CFG->libdir . '/grade/grade_grade.php'); -- 2.39.5