diff --git a/blocks/admin/block_admin.php b/blocks/admin/block_admin.php
index 66d3787def5..60e4b5c4a91 100644
--- a/blocks/admin/block_admin.php
+++ b/blocks/admin/block_admin.php
@@ -131,7 +131,7 @@ class block_admin extends block_list {
/// Manage scales
if (has_capability('moodle/course:managescales', $context) && ($course->id!==SITEID)) {
- $this->content->items[]=''.get_string('scales').'';
+ $this->content->items[]=''.get_string('scales').'';
$this->content->icons[]='
';
}
diff --git a/course/scales.php b/course/scales.php
index efbe8cf763c..3759a1f45e4 100644
--- a/course/scales.php
+++ b/course/scales.php
@@ -4,19 +4,15 @@
require_once("../config.php");
require_once("lib.php");
- $id = required_param('id', PARAM_INT); // course id
- $scaleid = optional_param('scaleid', 0, PARAM_INT); // scale id
- $action = optional_param('action', 'undefined', PARAM_ALPHA); // action to execute
- $name = optional_param('name', '', PARAM_CLEAN); // scale name
- $description = optional_param('description', '', PARAM_CLEAN);// scale description
- $list = optional_param('list', 0, PARAM_BOOL); // show listing in help window
+ $id = required_param('id', PARAM_INT); // course id
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect");
}
- require_login($course->id);
+ require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
+ require_capability('moodle/course:viewscales', $context);
$strscale = get_string("scale");
$strscales = get_string("scales");
@@ -26,447 +22,59 @@
$strstandardscales = get_string("scalesstandard");
$strname = get_string("name");
$strdescription = get_string("description");
- $strsavechanges = get_string("savechanges");
- $strchangessaved = get_string("changessaved");
- $strdeleted = get_string("deleted");
- $strdelete = get_string("delete");
- $stredit = get_string("edit");
- $strdown = get_string("movedown");
- $strup = get_string("moveup");
- $strmoved = get_string("changessaved");
- $srtcreatenewscale = get_string("scalescustomcreate");
$strhelptext = get_string("helptext");
$stractivities = get_string("activities");
- $stroptions = get_string("action");
- $strtype = get_string("group");
- /// init this here so we can pass it by reference to every call to site_scale_used to avoid getting the courses out of the db over and over again
- $courses = array();
- /// If scale data is being submitted, then save it and continue
- $focus = "";
- $errors = NULL;
+ print_header($strscales);
- if ($action == 'sendform' and confirm_sesskey()) {
- if ($form = data_submitted()) {
- if (empty($form->name)) {
- $errors[$scaleid]->name = true;
- $focus = "form$scaleid.save";
- }
- if (empty($form->scalescale)) {
- $errors[$scaleid]->scalescale = true;
- $focus = "form$scaleid.save";
- }
+ if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
+ print_heading($strcustomscales);
- if (!$errors) {
- $newscale=NULL;
- $newscale->name = $form->name;
- $newscale->scale = $form->scalescale;
- $newscale->description = $form->description;
- $newscale->courseid = $form->courseid;
- $newscale->userid = $USER->id;
- $newscale->timemodified = time();
+ if (has_capability('moodle/course:managescales', $context)) {
+ echo "
(";
+ print_string("scalestip");
+ echo ")
";
+ }
- if (empty($scaleid)) {
- $newscale->courseid = $course->id;
- if (!insert_record("scale", $newscale)) {
- error("Could not insert the new scale!");
- }
- } else {
- $newscale->id = $scaleid;
- if (!update_record("scale", $newscale)) {
- error("Could not update that scale!");
- }
- }
+ foreach ($scales as $scale) {
+ $scalemenu = make_menu_from_list($scale->scale);
- $notify = "$newscale->name: $strchangessaved";
- $focus = "form$scaleid.save";
- } else {
- if (!empty($scaleid)) {
- $action = "edit";
- } else {
- $action = "new";
- }
- }
+ print_simple_box_start("center");
+ print_heading($scale->name);
+ echo "";
+ choose_from_menu($scalemenu, "", "", "");
+ echo "";
+ echo text_to_html($scale->description);
+ print_simple_box_end();
+ echo "
";
+ }
+
+ } else {
+ if (has_capability('moodle/course:managescales', $context)) {
+ echo "(";
+ print_string("scalestip");
+ echo ")
";
}
}
- //If action is details, show the popup info
- if ($action == "details") {
- //Check for teacher edit
- require_capability('moodle/course:managescales', $context);
-
- //Check for scale
- if (! $scale = get_record("scale", "id", $scaleid)) {
- error("Scale ID was incorrect");
- }
+ if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
+ print_heading($strstandardscales);
+ foreach ($scales as $scale) {
+ $scalemenu = make_menu_from_list($scale->scale);
- // $scales_course_uses = course_scale_used($course->id,$scale->id);
- // $scales_site_uses = site_scale_used($scale->id,$courses);
- $scalemenu = make_menu_from_list($scale->scale);
-
- print_header("$course->shortname: $strscales", $course->fullname,
- "$course->shortname -> $strscales -> $scale->name", "", "", true, " ", " ");
-
- close_window_button();
-
- echo "";
- print_simple_box_start("center");
- print_heading($scale->name);
- echo "";
- choose_from_menu($scalemenu, "", "", "");
- echo "";
- echo text_to_html($scale->description);
- print_simple_box_end();
- echo "";
-
- close_window_button();
- print_footer();
- exit;
- }
-
- //If action is edit or new, show the form
- if ($action == "edit" || $action == "new") {
-
- $sesskey = !empty($USER->id) ? $USER->sesskey : '';
-
- require_capability('moodle/course:managescales', $context);
-
- //Check for scale if action = edit
- if ($action == "edit") {
- if (! $scale = get_record("scale", "id", $scaleid)) {
- error("Scale ID was incorrect");
- }
- } else {
- $scale = new object();
- $scale->id = 0;
- $scale->courseid = $course->id;
- $scale->name = "";
- $scale->scale = "";
- $scale->description = "";
- }
-
- //Calculate the uses
- if ($scale->courseid == 0) {
- $scale_uses = site_scale_used($scale->id,$courses);
- } else {
- $scale_uses = course_scale_used($course->id,$scale->id);
- }
-
- //Check for scale_uses
- if (!empty($scale_uses)) {
- error("Scale is in use and cannot be modified",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
- }
-
- //Check for standard scales
- if ($scale->courseid == 0 and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
- error("Only administrators can edit this scale",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
- }
-
- //Print out the headers
- print_header("$course->shortname: $strscales", $course->fullname,
- "id\">$course->shortname".
- " -> id\">$strscales".
- " -> ".get_string("editinga","",$strscale), $focus);
-
- //Title
- print_heading_with_help($strscales, "scales");
-
- if (!empty($errors) and ($form->scaleid == $scale->id)) {
- $scale->name = $form->name;
- $scale->scale = $form->scalescale;
- $scale->description = $form->description;
- }
- echo "";
- echo "
";
-
- print_footer($course);
-
- exit;
- }
-
- //If action is delete, do it
- if ($action == "delete" and confirm_sesskey()) {
- //Check for teacher edit
- require_capability('moodle/course:managescales', $context);
- //Check for scale if action = edit
- if (! $scale = get_record("scale", "id", $scaleid)) {
- error("Scale ID was incorrect");
- }
-
- //Calculate the uses
- if ($scale->courseid == 0) {
- $scale_uses = site_scale_used($scale->id,$courses);
- } else {
- $scale_uses = course_scale_used($course->id,$scale->id);
- }
-
- //Check for scale_uses
- if (!empty($scale_uses)) {
- error("Scale is in use and cannot be deleted",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
- }
-
- //Check for standard scales
- if ($scale->courseid == 0 and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
- error("Only administrators can delete this scale",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
- }
-
- if (delete_records("scale", "id", $scaleid)) {
- $notify = "$scale->name: $strdeleted";
+ print_simple_box_start("center");
+ print_heading($scale->name);
+ echo "";
+ choose_from_menu($scalemenu, "", "", "");
+ echo "";
+ echo text_to_html($scale->description);
+ print_simple_box_end();
+ echo "
";
}
}
- //If action is down or up, do it
- if (($action == "down" || $action == "up") and confirm_sesskey()) {
- //Check for teacher edit
- require_capability('moodle/course:managescales', $context);
- //Check for scale if action = edit
- if (! $scale = get_record("scale", "id", $scaleid)) {
- error("Scale ID was incorrect");
- }
-
- //Calculate the uses
- if ($scale->courseid == 0) {
- $scale_uses = site_scale_used($scale->id,$courses);
- } else {
- $scale_uses = course_scale_used($course->id,$scale->id);
- }
-
- //Check for scale_uses
- if (!empty($scale_uses)) {
- error("Scale is in use and cannot be moved",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
- }
-
- if ($action == "down") {
- $scale->courseid = 0;
- } else {
- $scale->courseid = $course->id;
- }
-
- if (set_field("scale", "courseid", $scale->courseid, "id", $scale->id)) {
- $notify = "$scale->name: $strmoved";
- }
- }
-
- if ($list) { /// Just list the scales (in a helpwindow)
- require_capability('moodle/course:viewscales', $context);
- print_header($strscales);
-
- if (!empty($scaleid)) {
- if ($scale = get_record("scale", "id", "$scaleid")) {
- $scalemenu = make_menu_from_list($scale->scale);
-
- print_simple_box_start("center");
- print_heading($scale->name);
- echo "";
- choose_from_menu($scalemenu, "", "", "");
- echo "";
- echo text_to_html($scale->description);
- print_simple_box_end();
- }
- echo "
";
- close_window_button();
- exit;
- }
-
- if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
- print_heading($strcustomscales);
-
- if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_COURSE, $course->id))) {
- echo "(";
- print_string("scalestip");
- echo ")
";
- }
-
- foreach ($scales as $scale) {
- $scalemenu = make_menu_from_list($scale->scale);
-
- print_simple_box_start("center");
- print_heading($scale->name);
- echo "";
- choose_from_menu($scalemenu, "", "", "");
- echo "";
- echo text_to_html($scale->description);
- print_simple_box_end();
- echo "
";
- }
-
- } else {
- if (has_capability('moodle/course:managescales', $context)) {
- echo "(";
- print_string("scalestip");
- echo ")
";
- }
- }
-
- if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
- print_heading($strstandardscales);
- foreach ($scales as $scale) {
- $scalemenu = make_menu_from_list($scale->scale);
-
- print_simple_box_start("center");
- print_heading($scale->name);
- echo "";
- choose_from_menu($scalemenu, "", "", "");
- echo "";
- echo text_to_html($scale->description);
- print_simple_box_end();
- echo "
";
- }
- }
-
- close_window_button();
- exit;
- }
-
-
-/// The rest is all about editing the scales
-
- require_capability('moodle/course:managescales', $context);
-
-/// Print out the main page
-
- print_header("$course->shortname: $strscales", $course->fullname,
- "id\">$course->shortname
- -> $strscales");
-
- print_heading_with_help($strscales, "scales");
-
- $options = array();
- $options['id'] = $course->id;
- $options['scaleid'] = 0;
- $options['action'] = 'new';
-
- print_simple_box_start('center');
- print_single_button($CFG->wwwroot.'/course/scales.php',$options,$srtcreatenewscale,'POST');
- print_simple_box_end();
- echo "";
-
- if (!empty($notify)) {
- notify($notify, "green");
- }
-
- $scales = array();
- $customscales = get_records("scale", "courseid", "$course->id", "name ASC");
- $standardscales = get_records("scale", "courseid", "0", "name ASC");
-
- if ($customscales) {
- foreach($customscales as $scale) {
- $scales[] = $scale;
- }
- }
-
- if ($standardscales) {
- foreach($standardscales as $scale) {
- $scales[] = $scale;
- }
- }
-
- if ($scales) {
- //Calculate the base path
- $path = "$CFG->wwwroot/course";
-
- $data = array();
- $incustom = true;
- foreach($scales as $scale) {
- //Check the separator
- if (empty($scale->courseid) && $incustom) {
- $incustom = false;
- $line = "hr";
- $data[] = $line;
- }
- $line = array();
- $line[] = "name\" href=\"$CFG->wwwroot/course/scales.php?id=$course->id&scaleid=$scale->id&action=details\" "."onclick=\"return openpopup('/course/scales.php?id=$course->id\&scaleid=$scale->id&action=details', 'scale', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">".$scale->name."
".str_replace(",",", ",$scale->scale)."";
- if (!empty($scale->courseid)) {
- $scales_uses = course_scale_used($course->id,$scale->id);
- } else {
- $scales_uses = site_scale_used($scale->id,$courses);
- }
- $line[] = $scales_uses;
- if ($incustom) {
- $line[] = $strcustomscale;
- } else {
- $line[] = $strstandardscale;
- }
- $buttons = "";
- if (empty($scales_uses) && ($incustom || has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID)))) {
- $buttons .= "id&scaleid=$scale->id&action=edit\">
pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /> ";
- if ($incustom && has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
- $buttons .= "id&scaleid=$scale->id&action=down&sesskey=$USER->sesskey\">
pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strdown\" /> ";
- }
- if (!$incustom && has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
- $buttons .= "id&scaleid=$scale->id&action=up&sesskey=$USER->sesskey\">
pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strup\" /> ";
- }
- $buttons .= "id&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\">
pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /> ";
- }
- $line[] = $buttons;
-
- $data[] = $line;
- }
- $head = $strscale.",".$stractivities.",".$strtype.",".$stroptions;
- $table->head = explode(",",$head);
- $size = "50%,20%,20%,10%";
- $table->size = explode(",",$size);
- $align = "left,center,center,center";
- $table->align = explode(",",$align);
- $wrap = ",nowrap,nowrap,nowrap";
- $table->wrap = explode(",",$wrap);
- $table->width = "90%";
- $table->data = $data;
- print_table ($table);
- }
-
- print_footer($course);
-
+ close_window_button();
+ exit;
?>
diff --git a/grade/edit/outcome/index.php b/grade/edit/outcome/index.php
new file mode 100644
index 00000000000..30404ce4c54
--- /dev/null
+++ b/grade/edit/outcome/index.php
@@ -0,0 +1 @@
+TODO
\ No newline at end of file
diff --git a/grade/edit/scale/edit.php b/grade/edit/scale/edit.php
new file mode 100644
index 00000000000..38b08bcd9fd
--- /dev/null
+++ b/grade/edit/scale/edit.php
@@ -0,0 +1,84 @@
+dirroot.'/grade/lib.php';
+require_once $CFG->dirroot.'/grade/report/lib.php';
+require_once 'edit_form.php';
+
+$courseid = required_param('courseid', PARAM_INT);
+$id = optional_param('id', 0, PARAM_INT);
+
+if (!$course = get_record('course', 'id', $courseid)) {
+ print_error('nocourseid');
+}
+
+require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+require_capability('moodle/course:managescales', $context);
+
+// default return url
+$gpr = new grade_plugin_return();
+$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
+
+$mform = new edit_scale_form(null, array('gpr'=>$gpr));
+if ($scale = get_record('scale', 'id', $id)) {
+ $scale->custom = (int)(!empty($scale->courseid));
+ if (!empty($scale->courseid)) {
+ require_capability('moodle/course:managescales', $systemcontext);
+ }
+ $scale->courseid = $courseid;
+ $options = new object();
+ $options->smiley = false;
+ $options->filter = false;
+ $options->noclean = false;
+ $scale->description = format_text($scale->description, FORMAT_MOODLE, $options);
+ $mform->set_data($scale);
+
+} else {
+ $mform->set_data(array('courseid'=>$courseid, 'custom'=>1));
+}
+
+if ($mform->is_cancelled()) {
+ redirect($returnurl);
+
+} else if ($data = $mform->get_data(false)) {
+ $scale = new grade_scale(array('id'=>$id));
+ $data->userid = $USER->id;
+ grade_scale::set_properties($scale, $data);
+
+ if (empty($scale->id)) {
+ $scale->courseid = $courseid;
+ if (empty($data->custom) and has_capability('moodle/course:managescales', $systemcontext)) {
+ $scale->courseid = 0;
+ }
+ $scale->insert();
+
+ } else {
+ if (isset($data->custom)) {
+ $scale->courseid = $data->custom ? $courseid : 0;
+ } else {
+ unset($scale->couseid);
+ }
+ $scale->update();
+ }
+
+ redirect($returnurl, 'temp debug delay', 3);
+}
+
+$strgrades = get_string('grades');
+$strgraderreport = get_string('graderreport', 'grades');
+$strscaleedit = get_string('scale');
+
+$nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
+ array('name'=>$strscaleedit, 'link'=>'', 'type'=>'misc'));
+
+$navigation = build_navigation($nav);
+
+
+print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strscaleedit, $navigation, '', '', true, '', navmenu($course));
+
+$mform->display();
+
+print_footer($course);
+die;
diff --git a/grade/edit/scale/edit_form.php b/grade/edit/scale/edit_form.php
new file mode 100644
index 00000000000..93b78dc8da5
--- /dev/null
+++ b/grade/edit/scale/edit_form.php
@@ -0,0 +1,89 @@
+libdir.'/formslib.php';
+
+class edit_scale_form extends moodleform {
+ function definition() {
+ global $CFG;
+ $mform =& $this->_form;
+
+ // visible elements
+ $mform->addElement('header', 'general', get_string('scale'));
+
+ $mform->addElement('text', 'name', get_string('name'));
+ $mform->addRule('name', get_string('required'), 'required', null, 'client');
+ $mform->setType('name', PARAM_TEXT);
+
+ $mform->addElement('advcheckbox', 'custom', get_string('coursescale', 'grades'));
+
+ $mform->addElement('static', 'activities', get_string('activities'));
+
+ $mform->addElement('textarea', 'scale', get_string('scale'), array('cols'=>50, 'rows'=>2));
+ $mform->addRule('scale', get_string('required'), 'required', null, 'client');
+ $mform->setType('scale', PARAM_TEXT);
+
+ $mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20));
+
+
+ // hidden params
+ $mform->addElement('hidden', 'id', 0);
+ $mform->setType('id', PARAM_INT);
+
+ $mform->addElement('hidden', 'courseid', 0);
+ $mform->setType('courseid', PARAM_INT);
+
+/// add return tracking info
+ $gpr = $this->_customdata['gpr'];
+ $gpr->add_mform_elements($mform);
+
+//-------------------------------------------------------------------------------
+ // buttons
+ $this->add_action_buttons();
+ }
+
+
+/// tweak the form - depending on existing data
+ function definition_after_data() {
+ global $CFG;
+
+ $mform =& $this->_form;
+
+ if ($id = $mform->getElementValue('id')) {
+ $scale = grade_scale::fetch(array('id'=>$id));
+ if ($count = $scale->get_uses_count()) {
+ if (empty($scale->courseid)) {
+ $mform->hardFreeze('custom');
+ }
+ $mform->hardFreeze('scale');
+ }
+ $activities_el =& $mform->getElement('activities');
+ $activities_el->setValue(get_string('usedinnplaces', '', $count));
+
+ } else {
+ $mform->removeElement('activities');
+ if (!has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
+ $mform->hardFreeze('custom');
+ }
+ }
+ }
+
+/// perform extra validation before submission
+ function validation($data){
+ $errors= array();
+
+ $options = explode(',', $data['scale']);
+ if (count($options) < 2) {
+ $errors['scale'] = get_string('error');
+ }
+
+ if (0 == count($errors)){
+ return true;
+ } else {
+ return $errors;
+ }
+ }
+
+
+}
+
+?>
diff --git a/grade/edit/scale/index.php b/grade/edit/scale/index.php
new file mode 100644
index 00000000000..bf2e4553a76
--- /dev/null
+++ b/grade/edit/scale/index.php
@@ -0,0 +1,136 @@
+dirroot.'/grade/lib.php';
+require_once $CFG->libdir.'/gradelib.php';
+
+$courseid = required_param('id', PARAM_INT);
+$action = optional_param('action', '', PARAM_ALPHA);
+
+/// Make sure they can even access this course
+if (!$course = get_record('course', 'id', $courseid)) {
+ print_error('nocourseid');
+}
+require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+require_capability('moodle/course:managescales', $context);
+
+/// return tracking object
+$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
+
+
+$strgrades = get_string('grades');
+$pagename = get_string('scales');
+
+$navlinks = array(array('name'=>$strgrades, 'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
+ array('name'=>$pagename, 'link'=>'', 'type'=>'misc'));
+$navigation = build_navigation($navlinks);
+
+$strscale = get_string('scale');
+$strstandardscale = get_string('scalesstandard');
+$strcustomscales = get_string('coursescales', 'grades');
+$strname = get_string('name');
+$strdelete = get_string('delete');
+$stredit = get_string('edit');
+$srtcreatenewscale = get_string('scalescustomcreate');
+$stractivities = get_string('activities');
+$stroptions = get_string('action');
+
+switch ($action) {
+ case 'delete':
+ if (!confirm_sesskey()) {
+ break;
+ }
+ $scaleid = required_param('scaleid', PARAM_INT);
+ if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) {
+ break;
+ }
+
+ if (empty($scale->courseid)) {
+ require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM));
+ }
+
+ if (!$scale->can_delete()) {
+ break;
+ }
+
+ //TODO: add confirmation
+ $scale->delete();
+ break;
+}
+
+/// Print header
+print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation,
+ '', '', true, '', navmenu($course));
+
+/// Print the plugin selector at the top
+print_grade_plugin_selector($courseid, 'edit', 'scale');
+
+
+print_heading($strstandardscale);
+if ($scales = grade_scale::fetch_all(array('courseid'=>0))) {
+ $data = array();
+ foreach($scales as $scale) {
+ $line = array();
+ $line[] = format_string($scale->name).''.str_replace(",",", ",$scale->scale).'
';
+
+ $scales_uses = $scale->get_uses_count();
+ $line[] = $scales_uses;
+
+ $buttons = "";
+ if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
+ $buttons .= "id&id=$scale->id\">
pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /> ";
+ }
+ if (empty($scales_uses) and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
+ $buttons .= "id&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\">
pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /> ";
+ }
+ $line[] = $buttons;
+ $data[] = $line;
+ }
+ $table->head = array($strscale, $stractivities, $stroptions);
+ $table->size = array('70%', '20%', '10%');
+ $table->align = array('left', 'center', 'center');
+ $table->width = '90%';
+ $table->data = $data;
+ print_table($table);
+}
+
+print_heading($strcustomscales);
+if ($scales = grade_scale::fetch_all(array('courseid'=>$courseid))) {
+ $data = array();
+ foreach($scales as $scale) {
+ $line = array();
+ $line[] = format_string($scale->name).''.str_replace(",",", ",$scale->scale).'
';
+
+ $scales_uses = $scale->get_uses_count();
+ $line[] = $scales_uses;
+
+ $buttons = "";
+ $buttons .= "id&id=$scale->id\">
pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /> ";
+ if (empty($scales_uses)) {
+ $buttons .= "id&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\">
pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /> ";
+ }
+ $line[] = $buttons;
+ $data[] = $line;
+ }
+ $table->head = array($strscale, $stractivities, $stroptions);
+ $table->size = array('70%', '20%', '10%');
+ $table->align = array('left', 'center', 'center');
+ $table->width = '90%';
+ $table->data = $data;
+ print_table($table);
+}
+
+echo '';
+print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
+echo '
';
+
+print_footer($course);
+
+
+?>
diff --git a/grade/edit/action.php b/grade/edit/tree/action.php
similarity index 96%
rename from grade/edit/action.php
rename to grade/edit/tree/action.php
index f6b4eb2ec46..90a870004ec 100644
--- a/grade/edit/action.php
+++ b/grade/edit/tree/action.php
@@ -1,6 +1,6 @@
dirroot.'/grade/lib.php';
$courseid = required_param('id', PARAM_INT);
@@ -16,7 +16,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id);
// default return url
$gpr = new grade_plugin_return();
-$returnurl = $gpr->get_return_url($CFG->wwwroot.'/grade/edit/tree.php?id='.$course->id);
+$returnurl = $gpr->get_return_url($CFG->wwwroot.'/grade/edit/tree/index.php?id='.$course->id);
// get the grading tree object
$gtree = new grade_tree($courseid, false, false);
diff --git a/grade/edit/calculation.php b/grade/edit/tree/calculation.php
similarity index 98%
rename from grade/edit/calculation.php
rename to grade/edit/tree/calculation.php
index 727cc8e121c..ccc66660f59 100644
--- a/grade/edit/calculation.php
+++ b/grade/edit/tree/calculation.php
@@ -1,6 +1,6 @@
dirroot.'/grade/lib.php';
require_once 'calculation_form.php';
diff --git a/grade/edit/calculation_form.php b/grade/edit/tree/calculation_form.php
similarity index 100%
rename from grade/edit/calculation_form.php
rename to grade/edit/tree/calculation_form.php
diff --git a/grade/edit/category.php b/grade/edit/tree/category.php
similarity index 95%
rename from grade/edit/category.php
rename to grade/edit/tree/category.php
index 1a576da802a..f110f859062 100644
--- a/grade/edit/category.php
+++ b/grade/edit/tree/category.php
@@ -1,6 +1,6 @@
dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/lib.php';
require_once 'category_form.php';
@@ -18,7 +18,7 @@ require_capability('moodle/grade:manage', $context);
// default return url
$gpr = new grade_plugin_return();
-$returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
+$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
$mform = new edit_category_form(null, array('gpr'=>$gpr));
diff --git a/grade/edit/category_form.php b/grade/edit/tree/category_form.php
similarity index 100%
rename from grade/edit/category_form.php
rename to grade/edit/tree/category_form.php
diff --git a/grade/edit/grade.php b/grade/edit/tree/grade.php
similarity index 99%
rename from grade/edit/grade.php
rename to grade/edit/tree/grade.php
index a176e9fda86..f1e1cfe3dcb 100644
--- a/grade/edit/grade.php
+++ b/grade/edit/tree/grade.php
@@ -1,6 +1,6 @@
dirroot.'/grade/lib.php';
require_once 'grade_form.php';
diff --git a/grade/edit/grade_form.php b/grade/edit/tree/grade_form.php
similarity index 100%
rename from grade/edit/grade_form.php
rename to grade/edit/tree/grade_form.php
diff --git a/grade/edit/tree.php b/grade/edit/tree/index.php
similarity index 98%
rename from grade/edit/tree.php
rename to grade/edit/tree/index.php
index 68eaaae89a9..9f07fe4f1d6 100644
--- a/grade/edit/tree.php
+++ b/grade/edit/tree/index.php
@@ -23,7 +23,7 @@
// //
///////////////////////////////////////////////////////////////////////////
-require_once '../../config.php';
+require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
$courseid = required_param('id', PARAM_INT);
@@ -42,7 +42,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/grade:manage', $context);
/// return tracking object
-$gpr = new grade_plugin_return(array('type'=>'edit', 'courseid'=>$courseid));
+$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'tree', 'courseid'=>$courseid));
$returnurl = $gpr->get_return_url(null);
//first make sure we have proper final grades - we need it for locking changes
diff --git a/grade/edit/item.php b/grade/edit/tree/item.php
similarity index 92%
rename from grade/edit/item.php
rename to grade/edit/tree/item.php
index 4865d230776..0b74fbafb9f 100644
--- a/grade/edit/item.php
+++ b/grade/edit/tree/item.php
@@ -1,6 +1,6 @@
dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/lib.php';
require_once 'item_form.php';
@@ -18,7 +18,7 @@ require_capability('moodle/grade:manage', $context);
// default return url
$gpr = new grade_plugin_return();
-$returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
+$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
$mform = new edit_item_form(null, array('gpr'=>$gpr));
@@ -29,7 +29,7 @@ if ($mform->is_cancelled()) {
if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
// redirect if outcomeid present
if (!empty($item->outcomeid)) {
- $url = $CFG->wwwroot.'/grade/edit/outcome.php?id='.$id.'&courseid='.$courseid;
+ $url = $CFG->wwwroot.'/grade/edit/tree/outcome.php?id='.$id.'&courseid='.$courseid;
redirect($gpr->add_url_params($url));
}
@@ -49,6 +49,8 @@ if ($data = $mform->get_data()) {
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
grade_item::set_properties($grade_item, $data);
+ $grade_item->outcomeid = null;
+
if (empty($grade_item->id)) {
$grade_item->itemtype = 'manual'; // all new items to be manual only
$grade_item->insert();
diff --git a/grade/edit/item_form.php b/grade/edit/tree/item_form.php
similarity index 100%
rename from grade/edit/item_form.php
rename to grade/edit/tree/item_form.php
diff --git a/grade/edit/outcomeitem.php b/grade/edit/tree/outcomeitem.php
similarity index 95%
rename from grade/edit/outcomeitem.php
rename to grade/edit/tree/outcomeitem.php
index c5109d3f83d..4cc5b7e0fd0 100644
--- a/grade/edit/outcomeitem.php
+++ b/grade/edit/tree/outcomeitem.php
@@ -1,6 +1,6 @@
dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/lib.php';
require_once 'outcomeitem_form.php';
@@ -18,7 +18,7 @@ require_capability('moodle/grade:manage', $context);
// default return url
$gpr = new grade_plugin_return();
-$returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
+$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
$mform = new edit_outcomeitem_form(null, array('gpr'=>$gpr));
@@ -29,7 +29,7 @@ if ($mform->is_cancelled()) {
if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
// redirect if outcomeid present
if (empty($item->outcomeid)) {
- $url = $CFG->wwwroot.'/grade/edit/outcome.php?id='.$id.'&courseid='.$courseid;
+ $url = $CFG->wwwroot.'/grade/edit/tree/outcome.php?id='.$id.'&courseid='.$courseid;
redirect($gpr->add_url_params($url));
}
diff --git a/grade/edit/outcomeitem_form.php b/grade/edit/tree/outcomeitem_form.php
similarity index 100%
rename from grade/edit/outcomeitem_form.php
rename to grade/edit/tree/outcomeitem_form.php
diff --git a/grade/lib.php b/grade/lib.php
index 7e4f66f11f6..5ca2cfb583d 100644
--- a/grade/lib.php
+++ b/grade/lib.php
@@ -93,13 +93,33 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
}
/// editing scripts - not real plugins
- if (has_capability('moodle/grade:manage', $context)) {
+ if (has_capability('moodle/grade:manage', $context)
+ or has_capability('moodle/course:managescales', $context)) {
$menu['edit']='--'.get_string('edit');
- $url = 'edit/tree.php?id='.$courseid;
- if ($active_type == 'edit' and $active_plugin == 'tree' ) {
- $active = $url;
+
+ if (has_capability('moodle/grade:manage', $context)) {
+ $url = 'edit/tree/index.php?id='.$courseid;
+ if ($active_type == 'edit' and $active_plugin == 'tree' ) {
+ $active = $url;
+ }
+ $menu[$url] = get_string('edittree', 'grades');
+ }
+
+ if (has_capability('moodle/course:managescales', $context)) {
+ $url = 'edit/scale/index.php?id='.$courseid;
+ if ($active_type == 'edit' and $active_plugin == 'scale' ) {
+ $active = $url;
+ }
+ $menu[$url] = get_string('scales');
+ }
+
+ if (has_capability('moodle/grade:manage', $context)) { // TODO: add outcome cap
+ $url = 'edit/outcome/index.php?id='.$courseid;
+ if ($active_type == 'edit' and $active_plugin == 'outcome' ) {
+ $active = $url;
+ }
+ $menu[$url] = get_string('outcomes', 'grades');
}
- $menu[$url] = get_string('edittree', 'grades');
}
/// finally print/return the popup form
@@ -175,10 +195,6 @@ class grade_plugin_return {
function get_return_url($default, $extras=null) {
global $CFG;
- if ($this->type == 'edit') {
- return $CFG->wwwroot.'/grade/edit/tree.php?id='.$this->courseid;
- }
-
if (empty($this->type) or empty($this->plugin)) {
return $default;
}
@@ -581,21 +597,21 @@ class grade_tree {
case 'categoryitem':
case 'courseitem':
if (empty($object->outcomeid)) {
- $url = $CFG->wwwroot.'/grade/edit/item.php?courseid='.$this->courseid.'&id='.$object->id;
+ $url = $CFG->wwwroot.'/grade/edit/tree/item.php?courseid='.$this->courseid.'&id='.$object->id;
} else {
- $url = $CFG->wwwroot.'/grade/edit/outcomeitem.php?courseid='.$this->courseid.'&id='.$object->id;
+ $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?courseid='.$this->courseid.'&id='.$object->id;
}
$url = $gpr->add_url_params($url);
break;
case 'category':
- $url = $CFG->wwwroot.'/grade/edit/category.php?courseid='.$this->courseid.'&id='.$object->id;
+ $url = $CFG->wwwroot.'/grade/edit/tree/category.php?courseid='.$this->courseid.'&id='.$object->id;
$url = $gpr->add_url_params($url);
break;
case 'grade':
//TODO: improve dealing with new grades
- $url = $CFG->wwwroot.'/grade/edit/grade.php?courseid='.$this->courseid.'&id='.$object->id;
+ $url = $CFG->wwwroot.'/grade/edit/tree/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);
@@ -636,12 +652,12 @@ class grade_tree {
}
if ($element['object']->is_hidden()) {
- $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&action=show&sesskey='.sesskey().'&eid='.$element['eid'];
+ $url = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&action=show&sesskey='.sesskey().'&eid='.$element['eid'];
$url = $gpr->add_url_params($url);
$action = '
';
} else {
- $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&action=hide&sesskey='.sesskey().'&eid='.$element['eid'];
+ $url = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&action=hide&sesskey='.sesskey().'&eid='.$element['eid'];
$url = $gpr->add_url_params($url);
$action = '
';
}
@@ -667,7 +683,7 @@ class grade_tree {
if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:unlock', $this->context)) {
return '';
}
- $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&action=unlock&sesskey='.sesskey().'&eid='.$element['eid'];
+ $url = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&action=unlock&sesskey='.sesskey().'&eid='.$element['eid'];
$url = $gpr->add_url_params($url);
$action = '
';
@@ -675,7 +691,7 @@ class grade_tree {
if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:lock', $this->context)) {
return '';
}
- $url = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&action=lock&sesskey='.sesskey().'&eid='.$element['eid'];
+ $url = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&action=lock&sesskey='.sesskey().'&eid='.$element['eid'];
$url = $gpr->add_url_params($url);
$action = '
';
}
@@ -703,7 +719,7 @@ class grade_tree {
// 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 = $CFG->wwwroot.'/grade/edit/tree/calculation.php?courseid='.$this->courseid.'&id='.$object->id;
$url = $gpr->add_url_params($url);
$calculation_icon = '
'. "\n";
diff --git a/lang/en_utf8/gradereport_outcomes.php b/lang/en_utf8/gradereport_outcomes.php
index a755444e228..2df4002f6c5 100644
--- a/lang/en_utf8/gradereport_outcomes.php
+++ b/lang/en_utf8/gradereport_outcomes.php
@@ -3,6 +3,6 @@
$string['addoutcome'] = 'Add an outcome';
$string['courseoutcomes'] = 'Course outcomes';
$string['coursespecoutcome'] = 'Course outcomes';
-$string['modulename'] = 'Outcomes';
+$string['modulename'] = 'Outcomes report';
$string['usedgradeitem'] = 'Number of grade items';
?>
diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php
index d4c19ce46b5..a0bc9a7601d 100644
--- a/lang/en_utf8/grades.php
+++ b/lang/en_utf8/grades.php
@@ -91,7 +91,7 @@ $string['editcalculation'] = 'Edit Calculation';
$string['editfeedback'] = 'Edit Feedback';
$string['editgrade'] = 'Edit Grade';
$string['editoutcomes'] = 'Edit outcomes';
-$string['edittree'] = 'Categories';
+$string['edittree'] = 'Categories and items';
$string['enableajax'] = 'Enable AJAX';
$string['enableoutcomes'] = 'Enable outcomes';
$string['encoding'] = 'Encoding';
diff --git a/lib/grade/grade_scale.php b/lib/grade/grade_scale.php
index 51ee8ca760a..3141fa5d592 100644
--- a/lib/grade/grade_scale.php
+++ b/lib/grade/grade_scale.php
@@ -169,5 +169,48 @@ class grade_scale extends grade_object {
return $scales[$grade-1];
}
+
+ /**
+ * Determines if scale can be deleted.
+ * @return boolean
+ */
+ function can_delete() {
+ $count = $this->get_uses_count();
+ return empty($count);
+ }
+
+ /**
+ * Returns the number of places where scale is used - activities, grade items, outcomes, etc.
+ * @return int
+ */
+ function get_uses_count() {
+ global $CFG;
+
+ $count = 0;
+ if (!empty($this->courseid)) {
+ if ($scales_uses = course_scale_used($this->courseid,$this->id)) {
+ $count += count($scales_uses);
+ }
+ } else {
+ $courses = array();
+ if ($scales_uses = site_scale_used($this->id,$courses)) {
+ $count += count($scales_uses);
+ }
+ }
+
+ // count grade items
+ $sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_items WHERE scaleid = {$this->id} AND outcomeid IS NULL";
+ if ($scales_uses = count_records_sql($sql)) {
+ $count += $scales_uses;
+ }
+
+ // count outcomes
+ $sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_outcomes WHERE scaleid = {$this->id}";
+ if ($scales_uses = count_records_sql($sql)) {
+ $count += $scales_uses;
+ }
+
+ return $count;
+ }
}
?>
diff --git a/theme/standard/styles_fonts.css b/theme/standard/styles_fonts.css
index f38f58e64b8..8904b69b47a 100644
--- a/theme/standard/styles_fonts.css
+++ b/theme/standard/styles_fonts.css
@@ -481,6 +481,10 @@ body#grade-index .grades .header {
font-size: 0.7em;
}
+.grade-edit-scale .scale_options {
+ font-size: 0.7em;
+}
+
/***
*** Login
diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css
index 1f2c3022ebe..6e26731f522 100644
--- a/theme/standard/styles_layout.css
+++ b/theme/standard/styles_layout.css
@@ -2145,9 +2145,22 @@ body#doc-contents ul {
display: inline;
margin-right: 10px;
}
+
+/* scales edit */
+
+.grade-edit-scale .buttons {
+ margin: 20px;
+ text-align:center;
+}
+
+.grade-edit-scale .buttons .singlebutton {
+ display: inline;
+ padding: 5px;
+}
+
/* gradebook edit tree */
-#grade-edit-edit_tree .gradetreebox {
+.grade-edit-tree .gradetreebox {
width:70%;
margin-left:auto;
margin-right:auto;
@@ -2155,40 +2168,39 @@ body#doc-contents ul {
padding-bottom:15px;
}
-#grade-edit-tree .buttons {
+.grade-edit-tree .buttons {
margin: 20px;
text-align:center;
}
-#grade-edit-tree .buttons .singlebutton {
+.grade-edit-tree .buttons .singlebutton {
display: inline;
padding: 5px;
}
-
-#grade-edit-tree .movetarget {
+.grade-edit-tree .movetarget {
position: relative;
width: 80px;
height: 16px;
}
-#grade-edit-tree ul#grade_tree {
+.grade-edit-tree ul#grade_tree {
width: auto;
}
-#grade-edit-tree ul#grade_tree li {
+.grade-edit-tree ul#grade_tree li {
list-style: none;
}
-#grade-edit-tree ul#grade_tree li.category {
+.grade-edit-tree ul#grade_tree li.category {
margin-bottom: 6px;
}
-#grade-edit-tree .moving {
+.grade-edit-tree .moving {
background-color: #E8EEF7;
}
-#grade-edit-tree .iconsmall {
+.grade-edit-tree .iconsmall {
margin-left: 4px;
}