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);
if (isteacheredit($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 (isteacheredit($course->id)) {
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
if (!isteacheredit($course->id)) {
error("Only editing teachers 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_with_help($strcustomscales, "scales");
if (!empty($notify)) {
notify($notify, "green");
}
/// 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 "";
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);
?>