From: moodler Date: Fri, 15 Aug 2003 14:03:25 +0000 (+0000) Subject: New scales editing page X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a57319b1f330aaff31f3190cd5bb439655f0ccac;p=moodle.git New scales editing page --- diff --git a/course/scales.php b/course/scales.php new file mode 100644 index 0000000000..6fb8f5fd54 --- /dev/null +++ b/course/scales.php @@ -0,0 +1,238 @@ +id); + + $strscale = get_string("scale"); + $strscales = get_string("scales"); + $strcustomscales = get_string("scalescustom"); + $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"); + + + if (isset($_GET['list'])) { /// Just list the scales (in a helpwindow) + + print_header($strscales); + + if (isset($_GET['scale'])) { + if ($scale = get_record("scale", "id", "$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; + } + + if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) { + print_heading($strcustomscales); + 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 "
"; + } + } + + 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 + + if (!iscreator() and isteacher($course->id)) { + error("Only course creators can modify scales !"); + } + + +/// If scale data is being submitted, then save it and continue + + $errors = NULL; + + if ($form = data_submitted()) { + if (!empty($form->delete)) { /// Delete a scale + $scale = get_record("scale", "id", $scaleid); + if (delete_records("scale", "id", $scaleid)) { + $notify = "$scale->name: $strdeleted"; + } + } else { /// Update scale data + if (empty($form->name)) { + $errors[$scaleid]->name = true; + $focus = "form$scaleid.save"; + } + if (empty($form->scale)) { + $errors[$scaleid]->scale = true; + $focus = "form$scaleid.save"; + } + + if (!$errors) { + $newscale=NULL; + $newscale->name = $form->name; + $newscale->scale = $form->scale; + $newscale->description = $form->description; + $newscale->courseid = $course->id; + $newscale->userid = $USER->id; + $newscale->timemodified = time(); + + if (empty($scaleid)) { + 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!"); + } + } + + $notify = "$newscale->name: $strchangessaved"; + $focus = "form$scaleid.save"; + } + } + } + + +/// Print out the headers + + print_header("$course->shortname: $strscales", "$course->fullname", + "id\">$course->shortname + -> $strscales", $focus); + + print_heading($strcustomscales); + + if (!empty($notify)) { + notify($notify); + } + + +/// Otherwise print out all the scale forms + + $customscales = get_records("scale", "courseid", "$course->id", "name ASC"); + + $blankscale->id = ""; + $blankscale->name = ""; + $blankscale->scale = ""; + $blankscale->description = ""; + $customscales[] = $blankscale; + + foreach ($customscales as $scale) { + if (!empty($errors) and ($form->scaleid == $scale->id)) { + $scale->name = $form->name; + $scale->scale = $form->scale; + $scale->description = $form->description; + } + echo "
id\">"; + echo ""; + echo ""; + if (!empty($errors[$scale->id]->name)) { + $class = "class=\"highlight\""; + } else { + $class = ""; + } + echo ""; + echo ""; + echo ""; + echo ""; + if (!empty($errors[$scale->id]->scale)) { + $class = "class=\"highlight\""; + } else { + $class = ""; + } + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "

$strname:

name)."\">"; + helpbutton("scalename", $strname); + echo "

$strscale:

"; + helpbutton("scale", $strscale); + echo "

$strdescription:

"; + helpbutton("scaledescription", get_string("scaledescription")); + echo "
"; + echo "id\">"; + echo "id\">"; + echo ""; + if ($scale->id) { + echo ""; + } + echo "
"; + echo "
"; + echo "
"; + } + + 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 "
"; + } + } + + print_footer($course); + + +?>