$eid = optional_param('eid', 0, PARAM_ALPHANUM);
$category = optional_param('category', null, PARAM_INT);
$aggregationtype = optional_param('aggregationtype', null, PARAM_INT);
+$showadvanced = optional_param('showadvanced', false, PARAM_BOOL);
/// Make sure they can even access this course
// note: total must be first for moving to work correctly, if you want it last moving code must be rewritten!
$gtree = new grade_tree($courseid, false, false);
+if (empty($eid)) {
+ $element = null;
+ $object = null;
+
+} else {
+ if (!$element = $gtree->locate_element($eid)) {
+ print_error('invalidelementid', '', $returnurl);
+ }
+ $object = $element['object'];
+}
+
$switch = grade_get_setting($course->id, 'aggregationposition', $CFG->grade_aggregationposition);
$strgrades = get_string('grades');
$navigation = grade_build_nav(__FILE__, $strcategoriesanditems, array('courseid' => $courseid));
$moving = false;
+switch ($action) {
+ case 'delete':
+ if ($eid) {
+ if (!element_deletable($element)) {
+ // no deleting of external activities - they would be recreated anyway!
+ // exception is activity without grading or misconfigured activities
+ break;
+ }
+ $confirm = optional_param('confirm', 0, PARAM_BOOL);
+
+ if ($confirm and confirm_sesskey()) {
+ $object->delete('grade/report/grader/category');
+ redirect($returnurl);
+
+ } else {
+ print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
+ $strdeletecheckfull = get_string('deletecheck', '', $object->get_name());
+ $optionsyes = array('eid'=>$eid, 'confirm'=>1, 'sesskey'=>sesskey(), 'id'=>$course->id, 'action'=>'delete');
+ $optionsno = array('id'=>$course->id);
+ notice_yesno($strdeletecheckfull, 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
+ print_footer($course);
+ die;
+ }
+ }
+ break;
+
+ case 'autosort':
+ //TODO: implement autosorting based on order of mods on course page, categories first, manual items last
+ break;
+
+ case 'synclegacy':
+ grade_grab_legacy_grades($course->id);
+ redirect($returnurl);
+
+ case 'move':
+ if ($eid and confirm_sesskey()) {
+ $moveafter = required_param('moveafter', PARAM_ALPHANUM);
+ if(!$after_el = $gtree->locate_element($moveafter)) {
+ print_error('invalidelementid', '', $returnurl);
+ }
+ $after = $after_el['object'];
+ $parent = $after->get_parent_category();
+ $sortorder = $after->get_sortorder();
+
+ $object->set_parent($parent->id);
+ $object->move_after_sortorder($sortorder);
+
+ redirect($returnurl);
+ }
+ break;
+
+ case 'moveselect':
+ if ($eid and confirm_sesskey()) {
+ $moving = $eid;
+ }
+ break;
+
+ default:
+ break;
+}
+
+// Hide advanced columns if moving
+if ($moving) {
+ $showadvanced = false;
+}
+
$CFG->stylesheets[] = $CFG->wwwroot.'/grade/edit/weights/tree.css';
print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcategoriesedit, $navigation, '', '', true, '', navmenu($course));
if ($form_key && $data = data_submitted()) {
foreach ($data as $key => $value) {
- if (preg_match('/aggregation_type_([0-9]*)/', $key, $matches)) {
- $aggtype = required_param($matches[0], PARAM_INT);
- $a->id = $matches[1];
+ // Grade category text inputs
+ if (preg_match('/(aggregation|droplow|keephigh)_([0-9]*)/', $key, $matches)) {
+ $value = required_param($matches[0], PARAM_INT);
+ $param = $matches[1];
+ $a->id = $matches[2];
- if (!$DB->update_record('grade_categories', array('id' => $matches[1], 'aggregation' => $aggtype))) {
+ if (!$DB->update_record('grade_categories', array('id' => $matches[2], $param => $value))) {
print_error('errorupdatinggradecategoryaggregation', 'grades', $a);
}
- } elseif (preg_match('/weight_([0-9]*)/', $key, $matches)) {
- $weight = required_param($matches[0], PARAM_NUMBER);
- $a->id = $matches[1];
+ // Grade item text inputs
+ } elseif (preg_match('/(aggregationcoef|multfactor|plusfactor)_([0-9]*)/', $key, $matches)) {
+ $value = required_param($matches[0], PARAM_NUMBER);
+ $param = $matches[1];
+ $a->id = $matches[2];
- if (!$DB->update_record('grade_items', array('id' => $matches[1], 'aggregationcoef' => $weight))) {
+ if (!$DB->update_record('grade_items', array('id' => $matches[2], $param => $value))) {
print_error('errorupdatinggradeitemaggregationcoef', 'grades', $a);
}
+ // Grade item checkbox inputs
} elseif (preg_match('/extracredit_original_([0-9]*)/', $key, $matches)) { // Sum extra credit checkbox
$extracredit = optional_param("extracredit_{$matches[1]}", null, PARAM_BOOL);
$original_value = required_param($matches[0], PARAM_BOOL);
print_error('errorupdatinggradeitemaggregationcoef', 'grades', $a);
}
+ // Grade category checkbox inputs
} elseif (preg_match('/aggregate(onlygraded|subcats|outcomes)_original_([0-9]*)/', $key, $matches)) {
$setting = optional_param('aggregate'.$matches[1].'_'.$matches[2], null, PARAM_BOOL);
$original_value = required_param($matches[0], PARAM_BOOL);
// echo '<div id="expandcontractdiv"> <a id="expand" href="#">Expand all</a> <a id="collapse" href="#">Collapse all</a> </div> ';
-echo '<button type="button" onclick="toggle_advanced_columns()">Show/Hide advanced columns</button>';
+print_box_start('gradetreebox generalbox');
+
echo '<form method="post" action="'.$returnurl.'">';
-echo '<div id="gradetree">';
+echo '<div>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
-echo build_html_tree(get_tree_json($gtree, $gtree->top_element, 0, $gpr), null, $returnurl);
+echo build_html_tree(get_tree_json($gtree, $gtree->top_element, 0, $gpr), null, $returnurl, $moving, $eid);
-// print_grade_tree($gtree, $gtree->top_element, $gpr, $switch);
-//
-echo '</div><div>';
+if ($showadvanced && !$moving) {
+ echo '<input class="advanced" type="submit" value="Update weights" />';
+}
-echo '<input type="submit" value="Update weights" />';
-echo '</div></form>
+echo '</div>
+</form>';
+
+print_box_end();
+
+echo '<div class="buttons">';
+if ($moving) {
+ print_single_button('index.php', array('id'=>$course->id), get_string('cancel'), 'get');
+} else {
+ $strshowhideadvanced = get_string('showadvancedcolumns', 'grades');
+
+ if ($showadvanced) {
+ $strshowhideadvanced = get_string('hideadvancedcolumns', 'grades');
+ }
+
+ print_single_button('index.php', array('id'=>$course->id, 'showadvanced' => !$showadvanced), $strshowhideadvanced, 'get');
+ print_single_button('category.php', array('courseid'=>$course->id), get_string('addcategory', 'grades'), 'get');
+ print_single_button('item.php', array('courseid'=>$course->id), get_string('additem', 'grades'), 'get');
+
+ if (!empty($CFG->enableoutcomes)) {
+ print_single_button('outcomeitem.php', array('courseid'=>$course->id), get_string('addoutcomeitem', 'grades'), 'get');
+ }
+
+ //print_single_button('index.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get');
+ print_single_button('index.php', array('id'=>$course->id, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get');
+}
+echo '</div>';
+echo '
<script type="text/javascript">
function toggle_advanced_columns() {
YAHOO.util.Dom.replaceClass(shownAdvEls[i], "advancedshown", "advanced");
}
}
-</script>
-<noscript>
-<!-- Print a button for hiding/showing the advanced columns -->
-</noscript>';
+</script>';
print_footer($course);
die;
$return_array['item']->actions .= $gtree->get_hiding_icon($element, $gpr);
$return_array['item']->actions .= $gtree->get_locking_icon($element, $gpr);
+ $return_array['item']->eid = $element['eid'];
+ $return_array['item']->type = $element['type'];
if ($element['type'] == 'category') {
foreach($element['children'] as $child_el) {
return $return_array;
}
-function build_html_tree($tree, $element=null, $level=0) {
- global $CFG;
+function build_html_tree($tree, $element=null, $level=0, $moving=false, $eid) {
+ global $CFG, $COURSE;
+
+ $showadvanced = optional_param('showadvanced', false, PARAM_BOOL);
+ $advclass = ($showadvanced) ? 'shown' : 'hidden';
$options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'),
GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'),
if (is_null($element)) {
$html .= '<table cellpadding="5" class="generaltable">
<tr>
- <th class="header name">'.get_string('name').'</th>
- <th class="header advanced">'.get_string('aggregation', 'grades').'</th>
- <th class="header advanced">'.get_string('weightorextracredit', 'grades').'</th>
- <th class="header advanced">'.get_string('range', 'grades').'</th>
- <th class="header advanced" style="width: 40px">'.get_string('aggregateonlygraded', 'grades').'</th>
- <th class="header advanced" style="width: 40px">'.get_string('aggregatesubcats', 'grades').'</th>
- <th class="header advanced" style="width: 40px">'.get_string('aggregateoutcomes', 'grades').'</th>
- <th class="header advanced">'.get_string('droplow', 'grades').'</th>
- <th class="header advanced">'.get_string('keephigh', 'grades').'</th>
- <th class="header advanced">'.get_string('multfactor', 'grades').'</th>
- <th class="header advanced">'.get_string('plusfactor', 'grades').'</th>
+ <th class="header name">'.get_string('name').'</th>';
+ if (!$moving) {
+ $html .= '
+ <th class="header '.$advclass.'">'.get_string('aggregation', 'grades').'</th>
+ <th class="header '.$advclass.'">'.get_string('weightorextracredit', 'grades').'</th>
+ <th class="header '.$advclass.'">'.get_string('range', 'grades').'</th>
+ <th class="header '.$advclass.'" style="width: 40px">'.get_string('aggregateonlygraded', 'grades').'</th>
+ <th class="header '.$advclass.'" style="width: 40px">'.get_string('aggregatesubcats', 'grades').'</th>
+ <th class="header '.$advclass.'" style="width: 40px">'.get_string('aggregateoutcomes', 'grades').'</th>
+ <th class="header '.$advclass.'">'.get_string('droplow', 'grades').'</th>
+ <th class="header '.$advclass.'">'.get_string('keephigh', 'grades').'</th>
+ <th class="header '.$advclass.'">'.get_string('multfactor', 'grades').'</th>
+ <th class="header '.$advclass.'">'.get_string('plusfactor', 'grades').'</th>
<th class="header actions">'.get_string('actions').'</th>
- </tr>';
+ ';
+ }
+
+ $html .= '</tr>';
$element = $tree;
$root = true;
}
$id = required_param('id', PARAM_INT);
+ /// prepare move target if needed
+ $last = '';
+ $moveto = '';
+
+ if ($moving) {
+ $strmove = get_string('move');
+ $strmovehere = get_string('movehere');
+ $element['item']->actions = ''; // no action icons when moving
+ $moveto = '<tr><td colspan="12"><a href="index.php?id='.$COURSE->id.'&action=move&eid='.$moving.'&moveafter='
+ . $element['item']->eid.'&sesskey='.sesskey().'"><img class="movetarget" src="'.$CFG->wwwroot.'/pix/movehere.gif" alt="'
+ . $strmovehere.'" title="'.$strmovehere.'" /></a></td></tr>';
+ }
+
+ /// print the list items now
+ if ($moving == $element['item']->eid) {
+
+ // do not diplay children
+ return '<tr><td colspan="12" class="'.$element['item']->type.' moving">'.$element['item']->name.' ('.get_string('move').')</td></tr>';
+
+ }
+
if (!empty($element['children'])) { // Grade category
$category = grade_category::fetch(array('id' => $element['item']->id));
$item = $category->get_grade_item();
$script = "window.location='index.php?id=$id&category={$category->id}&aggregationtype='+this.value";
- $aggregation_type = choose_from_menu($options, 'aggregation_type_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true);
+ $aggregation = choose_from_menu($options, 'aggregation_'.$category->id, $category->aggregation, get_string('choose'), $script, 0, true);
$onlygradedcheck = ($category->aggregateonlygraded == 1) ? 'checked="checked"' : '';
$subcatscheck = ($category->aggregatesubcats == 1) ? 'checked="checked"' : '';
// Add aggregation coef input if not a course item and if parent category has correct aggregation type
$aggcoef_input = get_weight_input($item);
+ $dimmed = ($item->hidden) ? " dimmed " : "";
$html .= '
- <tr class="category">
+ <tr class="category '.$dimmed.'">
<td class="cell name" style="padding-left:' . ($level * 20)
- . 'px; background: #DDDDDD url(img/ln.gif) no-repeat scroll ' . (($level - 1) * 20) . 'px 8px">' . $element['item']->name . $hidden . '</td>
- <td class="cell advanced">' . $aggregation_type . '</td>
- <td class="cell advanced">' . $aggcoef_input . '</td>
- <td class="cell advanced">' . $item->get_formatted_range() . '</td>
- <td class="cell advanced">' . $aggregateonlygraded . '</td>
- <td class="cell advanced">' . $aggregatesubcats . '</td>
- <td class="cell advanced">' . $aggregateoutcomes . '</td>
- <td class="cell advanced">' . $droplow . '</td>
- <td class="cell advanced">' . $keephigh . '</td>
- <td class="cell advanced"> - </td>
- <td class="cell advanced"> - </td>
- <td class="cell actions">' . $element['item']->actions . '</td>
+ . 'px; background: #DDDDDD url(img/ln.gif) no-repeat scroll ' . (($level - 1) * 20) . 'px 8px">' . $element['item']->name . $hidden . '</td>';
+
+ if (!$moving) {
+ $html .= '
+ <td class="cell '.$advclass.'">' . $aggregation . '</td>
+ <td class="cell '.$advclass.'">' . $aggcoef_input . '</td>
+ <td class="cell '.$advclass.'">' . $item->get_formatted_range() . '</td>
+ <td class="cell '.$advclass.'">' . $aggregateonlygraded . '</td>
+ <td class="cell '.$advclass.'">' . $aggregatesubcats . '</td>
+ <td class="cell '.$advclass.'">' . $aggregateoutcomes . '</td>
+ <td class="cell '.$advclass.'">' . $droplow . '</td>
+ <td class="cell '.$advclass.'">' . $keephigh . '</td>
+ <td class="cell '.$advclass.'"> - </td>
+ <td class="cell '.$advclass.'"> - </td>
+ <td class="cell actions">' . $element['item']->actions . '</td>';
+ }
+
+ $html .= '
</tr>
- ';
+ '.$moveto;
foreach ($element['children'] as $child) {
- $html .= build_html_tree($tree, $child, $level+1);
+ $html .= build_html_tree($tree, $child, $level+1, $moving, $eid);
}
} else { // Dealing with a grade item
$multfactor = '<input type="text" size="3" id="multfactor'.$item->id.'" name="multfactor'.$item->id.'" value="'.$item->multfactor.'" />';
$plusfactor = '<input type="text" size="3" id="plusfactor_'.$item->id.'" name="plusfactor_'.$item->id.'" value="'.$item->plusfactor.'" />';
+ $dimmed = ($item->hidden) ? " dimmed_text " : "";
$html .= '
- <tr class="item">
+ <tr class="item'.$dimmed.'">
<td class="cell name" style="padding-left:' . ($level * 20)
- . 'px; background: #FFFFFF url(img/ln.gif) no-repeat scroll ' . (($level - 1) * 20) . 'px 8px">' . $element['item']->name . '</td>
- <td class="cell advanced"> - </td>
- <td class="cell advanced">' . $aggcoef_input . '</td>
- <td class="cell advanced">' . $item->get_formatted_range() . '</td>
- <td class="cell advanced"> - </td>
- <td class="cell advanced"> - </td>
- <td class="cell advanced"> - </td>
- <td class="cell advanced"> - </td>
- <td class="cell advanced"> - </td>
- <td class="cell advanced">'.$multfactor.'</td>
- <td class="cell advanced">'.$plusfactor.'</td>
- <td class="cell actions">' . $element['item']->actions . '</td>
+ . 'px; background: #FFFFFF url(img/ln.gif) no-repeat scroll ' . (($level - 1) * 20) . 'px 8px">' . $element['item']->name . '</td>';
+
+ if (!$moving) {
+ $html .= '
+ <td class="cell '.$advclass.'"> - </td>
+ <td class="cell '.$advclass.'">' . $aggcoef_input . '</td>
+ <td class="cell '.$advclass.'">' . $item->get_formatted_range() . '</td>
+ <td class="cell '.$advclass.'"> - </td>
+ <td class="cell '.$advclass.'"> - </td>
+ <td class="cell '.$advclass.'"> - </td>
+ <td class="cell '.$advclass.'"> - </td>
+ <td class="cell '.$advclass.'"> - </td>
+ <td class="cell '.$advclass.'">'.$multfactor.'</td>
+ <td class="cell '.$advclass.'">'.$plusfactor.'</td>
+ <td class="cell actions">' . $element['item']->actions . '</td>';
+ }
+
+ $html .= '
</tr>
- ';
+ '.$moveto;
}
}
if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoefextra') {
- return '<input type="text" size="6" id="weight_'.$item->id.'" name="weight_'.$item->id.'" value="'.$item->aggregationcoef.'" />';
+ return '<input type="text" size="6" id="aggregationcoef_'.$item->id.'" name="aggregationcoef_'.$item->id.'" value="'.$item->aggregationcoef.'" />';
} elseif ($aggcoef == 'aggregationcoefextrasum' ) {
$checked = ($item->aggregationcoef > 0) ? 'checked="checked"' : '';
$extracredit = ($item->aggregationcoef > 0) ? 1 : 0;
-#gradetree tr.category td {
+.gradetreebox tr.category td {
background-color: #DDDDDD;
}
-#gradetree .category td.name {
+.gradetreebox .category td.name {
font-weight: bold;
}
-#gradetree td.name {
+.gradetreebox td.name {
}
-#gradetree th.actions {
+.gradetreebox th.actions {
width: 80px;
}
background-image: url(img/ln.gif);
}
-.advanced {
+.hidden {
display: none;
}
+.shown {
+}
+
+img.iconsmall {
+ margin-left: 4px;
+}
+
+img.icon {
+ margin-right: 5px;
+}
+
+.gradetreebox {
+ margin-left: auto;
+ margin-right: auto;
+ margin-top: 10px;
+ padding-bottom: 15px;
+}
+
+.gradetreebox table {
+ margin-left: auto;
+ margin-right: auto;
+}
+
+.buttons {
+ margin: 20px;
+ text-align: center;
+ width: 100%;
+}
+
+.buttons .singlebutton {
+ display: inline;
+ padding: 5px;
+}