}
// get the params
-$courseid = required_param('id', PARAM_INT);
-$context = get_context_instance(CONTEXT_COURSE, $courseid);
-$page = optional_param('page', 0, PARAM_INT);
-$sortitemid = optional_param('sortitemid', 0, PARAM_ALPHANUM); // sort by which grade item
-$report = optional_param('report', 0, PARAM_ALPHANUM);
-$perpage = optional_param('perpage', 3, PARAM_INT); // number of users on a page
+$courseid = required_param('id', PARAM_INT);
+$context = get_context_instance(CONTEXT_COURSE, $courseid);
+$page = optional_param('page', 0, PARAM_INT);
+$sortitemid = optional_param('sortitemid', 0, PARAM_ALPHANUM); // sort by which grade item
+$report = optional_param('report', 0, PARAM_ALPHANUM);
+$perpage = optional_param('perpage', 3, PARAM_INT); // number of users on a page
+$action = optional_param('action', 0, PARAM_ALPHA);
+$move = optional_param('move', 0, PARAM_INT);
+$type = optional_param('type', 0, PARAM_ALPHA);
+$target = optional_param('target', 0, PARAM_INT);
+
+// Grab the grade_tree for this course
+$gtree = new grade_tree($courseid, false);
// setting the sort order, this depends on last state
// all this should be in the new table class that we might need to use
/// end of setting sort order code
+// Perform actions on categories, items and grades
+if (!empty($target) && !empty($action) && confirm_sesskey()) {
+ $element = $gtree->locate_element($target);
+ switch ($action) {
+ case 'edit':
+ break;
+ case 'delete':
+ if ($confirm == 1) { // Perform the deletion
+ $gtree->remove_element($target);
+ $gtree->renumber();
+ $gtree->update_db();
+ // Print result message
+
+ } else { // Print confirmation dialog
+ $strdeletecheckfull = get_string('deletecheck', '', $element->element['object']->get_name());
+ $linkyes = "category.php?target=$target&action=delete&confirm=1$gtree->commonvars";
+ $linkno = "category.php?$gtree->commonvars";
+ notice_yesno($strdeletecheckfull, $linkyes, $linkno);
+ }
+ break;
+
+ case 'hide':
+ // TODO Implement calendar for selection of a date to hide element until
+ if (!$element->element['object']->set_hidden(1)) {
+ debugging("Could not update the element's hidden state!");
+ } else {
+ $gtree = new grade_tree($courseid);
+ }
+ break;
+ case 'show':
+ if (!$element->element['object']->set_hidden(0)) {
+ debugging("Could not update the element's hidden state!");
+ } else {
+ $gtree = new grade_tree($courseid);
+ }
+ break;
+ case 'lock':
+ // TODO Implement calendar for selection of a date to lock element after
+ if (!$element->element['object']->set_locked(1)) {
+ debugging("Could not update the element's locked state!");
+ } else {
+ $gtree = new grade_tree($courseid);
+ }
+ break;
+ case 'unlock':
+ if (!$element->element['object']->set_locked(0)) {
+ debugging("Could not update the element's locked state!");
+ } else {
+ $gtree = new grade_tree($courseid);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
// first make sure we have all final grades
// TODO: check that no grade_item has needsupdate set
print_paging_bar($numusers, $page, $perpage, $pbarurl);
/// With the users in an sorted array and grades fetched, we can not print the main html table
-if ($gtree = new grade_tree($courseid, false)) {
- // 1. Fetch all top-level categories for this course, with all children preloaded, sorted by sortorder
- $tree = $gtree->tree_filled;
+// 1. Fetch all top-level categories for this course, with all children preloaded, sorted by sortorder
+$tree = $gtree->tree_filled;
- if (empty($gtree->tree_filled)) {
- debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly.");
- }
-
- // Fetch array of students enroled in this course
- if (!$context = get_context_instance(CONTEXT_COURSE, $gtree->courseid)) {
- return false;
- }
- //$users = get_role_users(@implode(',', $CFG->gradebookroles), $context);
-
- $topcathtml = '<tr><td class="filler"> </td>';
- $cathtml = '<tr><td class="filler"> </td>';
-
- if ($sortitemid === 'lastname') {
- if ($sortorder == 'ASC') {
- $lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
- } else {
- $lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
- }
+if (empty($gtree->tree_filled)) {
+ debugging("The tree_filled array wasn't initialised, grade_tree could not display the grades correctly.");
+}
+
+ // Fetch array of students enroled in this course
+if (!$context = get_context_instance(CONTEXT_COURSE, $gtree->courseid)) {
+ return false;
+}
+//$users = get_role_users(@implode(',', $CFG->gradebookroles), $context);
+
+$topcathtml = '<tr><td class="filler"> </td>';
+$cathtml = '<tr><td class="filler"> </td>';
+
+if ($sortitemid === 'lastname') {
+ if ($sortorder == 'ASC') {
+ $lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
} else {
- $lastarrow = '';
+ $lastarrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
}
-
- if ($sortitemid === 'firstname') {
- if ($sortorder == 'ASC') {
- $firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
- } else {
- $firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
- }
+} else {
+ $lastarrow = '';
+}
+
+if ($sortitemid === 'firstname') {
+ if ($sortorder == 'ASC') {
+ $firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
} else {
- $firstarrow = '';
+ $firstarrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
}
-
- // first name/last name column
- $itemhtml = '<tr><th class="filler"><a href="'.$baseurl.'&sortitemid=firstname">Firstname</a> '. $firstarrow. '/ <a href="'.$baseurl.'&sortitemid=lastname">Lastname </a>'. $lastarrow .'</th>';
-
- $items = array();
+} else {
+ $firstarrow = '';
+}
- foreach ($tree as $topcat) {
- $itemcount = 0;
-
- foreach ($topcat['children'] as $catkey => $cat) {
- $catitemcount = 0;
+// first name/last name column
+$itemhtml = '<tr><th class="filler"><a href="'.$baseurl.'&sortitemid=firstname">Firstname</a> '. $firstarrow. '/ <a href="'.$baseurl.'&sortitemid=lastname">Lastname </a>'. $lastarrow .'</th>';
- foreach ($cat['children'] as $item) {
- $itemcount++;
- $catitemcount++;
-
- if ($item['object']->id == $sortitemid) {
- if ($sortorder == 'ASC') {
- $arrow = ' <img src="http://yu.moodle.com/dev/pix/t/up.gif"/> ';
- } else {
- $arrow = ' <img src="http://yu.moodle.com/dev/pix/t/down.gif"/> ';
- }
+$items = array();
+
+foreach ($tree as $topcat) {
+ $itemcount = 0;
+
+ foreach ($topcat['children'] as $catkey => $cat) {
+ $catitemcount = 0;
+
+ foreach ($cat['children'] as $item) {
+ $itemcount++;
+ $catitemcount++;
+
+ if ($item['object']->id == $sortitemid) {
+ if ($sortorder == 'ASC') {
+ $arrow = ' <img src="pix/t/up.gif"/> ';
} else {
- $arrow = '';
- }
- $itemhtml .= '<th><a href="'.$baseurl.'&sortitemid='. $item['object']->id .'">'. $item['object']->itemname . '</a>' . $arrow. '</th>';
- $items[] = $item;
- }
-
- if ($cat['object'] == 'filler') {
- $cathtml .= '<td class="subfiller"> </td>';
+ $arrow = ' <img src="pix/t/down.gif"/> ';
+ }
} else {
- $cat['object']->load_grade_item();
- $cathtml .= '<td colspan="' . $catitemcount . '">' . $cat['object']->fullname . '</td>';
- }
+ $arrow = '';
+ }
+ $itemhtml .= '<th><a href="'.$baseurl.'&sortitemid='
+ . $item['object']->id .'">'. $item['object']->itemname
+ . '</a>' . $arrow;
+
+ // Print icons
+ $itemhtml .= grade_get_icons($item['object'], $gtree) . '</th>';
+ $items[] = $item;
}
-
- if ($topcat['object'] == 'filler') {
- $colspan = null;
- if (!empty($topcat['colspan'])) {
- $colspan = 'colspan="' . $topcat['colspan'] . '" ';
- }
- $topcathtml .= '<td ' . $colspan . 'class="topfiller"> </td>';
+
+ if ($cat['object'] == 'filler') {
+ $cathtml .= '<td class="subfiller"> </td>';
} else {
- $topcathtml .= '<th colspan="' . $itemcount . '">' . $topcat['object']->fullname . '</th>';
+ $cat['object']->load_grade_item();
+ $cathtml .= '<td colspan="' . $catitemcount . '">' . $cat['object']->fullname;
+ // Print icons
+ $cathtml .= grade_get_icons($cat['object'], $gtree) . '</td>';
}
}
-
- $studentshtml = '';
- foreach ($users as $userid => $user) {
- $studentshtml .= '<tr><th>' . $user->firstname . ' ' . $user->lastname . '</th>';
- foreach ($items as $item) {
-
-
- $studentshtml .= '<td>';
-
- if (isset($finalgrades[$userid][$item['object']->id])) {
- $gradeval = $finalgrades[$userid][$item['object']->id];
- } else {
- $gradeval = '-';
- }
-
- // if in editting mode, we need to print either a text box
- // or a drop down (for scales)
- if ($USER->gradeediting) {
- if ($item['object']->scaleid) {
- if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
- $scales = explode(",", $scale->scale);
- // reindex because scale is off 1
- $i = 0;
- foreach ($scales as $scaleoption) {
- $i++;
- $scaleopt[$i] = $scaleoption;
- }
- $studentshtml .= choose_from_menu ($scaleopt, 'grade_'.$userid.'_'.$item['object']->id, $gradeval, get_string('nograde'), '', -1, true);
+ if ($topcat['object'] == 'filler') {
+ $colspan = null;
+ if (!empty($topcat['colspan'])) {
+ $colspan = 'colspan="' . $topcat['colspan'] . '" ';
+ }
+ $topcathtml .= '<td ' . $colspan . 'class="topfiller"> </td>';
+ } else {
+ $topcathtml .= '<th colspan="' . $itemcount . '">' . $topcat['object']->fullname;
+ // Print icons
+ $topcathtml .= grade_get_icons($topcat['object'], $gtree) . '</th>';
+ }
+}
+
+$studentshtml = '';
+
+foreach ($users as $userid => $user) {
+ $studentshtml .= '<tr><th>' . $user->firstname . ' ' . $user->lastname . '</th>';
+ foreach ($items as $item) {
+
+
+ $studentshtml .= '<td>';
+
+ if (isset($finalgrades[$userid][$item['object']->id])) {
+ $gradeval = $finalgrades[$userid][$item['object']->id];
+ } else {
+ $gradeval = '-';
+ }
+
+ // if in editting mode, we need to print either a text box
+ // or a drop down (for scales)
+ if ($USER->gradeediting) {
+ if ($item['object']->scaleid) {
+ if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
+ $scales = explode(",", $scale->scale);
+ // reindex because scale is off 1
+ $i = 0;
+ foreach ($scales as $scaleoption) {
+ $i++;
+ $scaleopt[$i] = $scaleoption;
}
- } else {
- $studentshtml .= '<input type="text" name="grade_'.$userid.'_'.$item['object']->id.'" value="'.$gradeval.'"/>';
+ $studentshtml .= choose_from_menu ($scaleopt, 'grade_'.$userid.'_'.$item['object']->id, $gradeval, get_string('nograde'), '', -1, true);
}
} else {
- // finalgrades[$userid][$itemid] could be null because of the outer join
- // in this case it's different than a 0
- if ($item['object']->scaleid) {
- if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
- $scales = explode(",", $scale->scale);
-
- // invalid grade if gradeval < 1
- if ((int) $gradeval < 1) {
- $studentshtml .= '-';
- } else {
- $studentshtml .= $scales[$gradeval-1];
- }
+ $studentshtml .= '<input type="text" name="grade_'.$userid.'_'.$item['object']->id.'" value="'.$gradeval.'"/>';
+ }
+ } else {
+ // finalgrades[$userid][$itemid] could be null because of the outer join
+ // in this case it's different than a 0
+ if ($item['object']->scaleid) {
+ if ($scale = get_record('scale', 'id', $item['object']->scaleid)) {
+ $scales = explode(",", $scale->scale);
+
+ // invalid grade if gradeval < 1
+ if ((int) $gradeval < 1) {
+ $studentshtml .= '-';
} else {
- // no such scale, throw error?
- }
+ $studentshtml .= $scales[$gradeval-1];
+ }
} else {
- $studentshtml .= $gradeval;
- }
+ // no such scale, throw error?
+ }
+ } else {
+ $studentshtml .= $gradeval;
}
-
- $studentshtml .= '</td>' . "\n";
}
- $studentshtml .= '</tr>';
- }
- $itemhtml .= '</tr>';
- $cathtml .= '</tr>';
- $topcathtml .= '</tr>';
-
- $reporthtml = "<table style=\"text-align: center\" border=\"1\">$topcathtml$cathtml$itemhtml";
- $reporthtml .= $studentshtml;
- $reporthtml .= "</table>";
-
- // print submit button
- if ($USER->gradeediting) {
- echo '<form action="report.php" method="POST">';
- echo '<div>';
- echo '<input type="hidden" value="'.$courseid.'" name="id" />';
- echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
- echo '<input type="hidden" value="grader" name="report"/>';
- }
-
- echo $reporthtml;
-
- // print submit button
- if ($USER->gradeediting) {
- echo '<input type="submit" value="'.get_string('update').'" />';
- echo '</div></form>';
+ $studentshtml .= '</td>' . "\n";
}
+ $studentshtml .= '</tr>';
+}
+$itemhtml .= '</tr>';
+$cathtml .= '</tr>';
+$topcathtml .= '</tr>';
+
+$reporthtml = "<table style=\"text-align: center\" border=\"1\">$topcathtml$cathtml$itemhtml";
+$reporthtml .= $studentshtml;
+$reporthtml .= "</table>";
+
+// print submit button
+if ($USER->gradeediting) {
+ echo '<form action="report.php" method="POST">';
+ echo '<div>';
+ echo '<input type="hidden" value="'.$courseid.'" name="id" />';
+ echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
+ echo '<input type="hidden" value="grader" name="report"/>';
+}
+
+echo $reporthtml;
+
+// print submit button
+if ($USER->gradeediting) {
+ echo '<input type="submit" value="'.get_string('update').'" />';
+ echo '</div></form>';
}
-
?>