2 // Allows a creator to edit custom scales, and also display help about scales
4 require_once("../config.php");
5 require_once("lib.php");
7 require_variable($id); // course id
8 optional_variable($scaleid); // scale id
9 optional_variable($action,"undefined"); // action to execute
10 optional_variable($name); // scale name
11 optional_variable($description); // scale description
12 optional_variable($scalescale); // scale scale
14 if (! $course = get_record("course", "id", $id)) {
15 error("Course ID was incorrect");
18 require_login($course->id
);
20 $strscale = get_string("scale");
21 $strscales = get_string("scales");
22 $strcustomscale = get_string("scalescustom");
23 $strstandardscale = get_string("scalesstandard");
24 $strcustomscales = get_string("scalescustom");
25 $strstandardscales = get_string("scalesstandard");
26 $strname = get_string("name");
27 $strdescription = get_string("description");
28 $strsavechanges = get_string("savechanges");
29 $strchangessaved = get_string("changessaved");
30 $strdeleted = get_string("deleted");
31 $strdelete = get_string("delete");
32 $stredit = get_string("edit");
33 $strdown = get_string("movedown");
34 $strup = get_string("moveup");
35 $strmoved = get_string("changessaved");
36 $srtcreatenewscale = get_string("scalescustomcreate");
37 $strhelptext = get_string("helptext");
38 $stractivities = get_string("activities");
39 $stroptions = get_string("action");
40 $strtype = get_string("group");
42 /// 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
45 /// If scale data is being submitted, then save it and continue
49 if ($action == 'sendform' and confirm_sesskey()) {
50 if ($form = data_submitted()) {
51 if (empty($form->name
)) {
52 $errors[$scaleid]->name
= true;
53 $focus = "form$scaleid.save";
55 if (empty($form->scalescale
)) {
56 $errors[$scaleid]->scalescale
= true;
57 $focus = "form$scaleid.save";
62 $newscale->name
= $form->name
;
63 $newscale->scale
= $form->scalescale
;
64 $newscale->description
= $form->description
;
65 $newscale->courseid
= $form->courseid
;
66 $newscale->userid
= $USER->id
;
67 $newscale->timemodified
= time();
69 if (empty($scaleid)) {
70 $newscale->courseid
= $course->id
;
71 if (!insert_record("scale", $newscale)) {
72 error("Could not insert the new scale!");
75 $newscale->id
= $scaleid;
76 if (!update_record("scale", $newscale)) {
77 error("Could not update that scale!");
81 $notify = "$newscale->name: $strchangessaved";
82 $focus = "form$scaleid.save";
84 if (!empty($scaleid)) {
93 //If action is details, show the popup info
94 if ($action == "details") {
95 //Check for teacher edit
96 if (! isteacheredit($course->id
)) {
97 error("Only editing teachers can view scales !");
100 if (! $scale = get_record("scale", "id", $scaleid)) {
101 error("Scale ID was incorrect");
104 // $scales_course_uses = course_scale_used($course->id,$scale->id);
105 // $scales_site_uses = site_scale_used($scale->id,$courses);
106 $scalemenu = make_menu_from_list($scale->scale
);
108 print_header("$course->shortname: $strscales", "$course->fullname",
109 "$course->shortname -> $strscales -> $scale->name", "", "", true, " ", " ");
111 close_window_button();
114 print_simple_box_start("center");
115 print_heading($scale->name
);
117 choose_from_menu($scalemenu, "", "", "");
119 echo text_to_html($scale->description
);
120 print_simple_box_end();
123 close_window_button();
128 //If action is edit or new, show the form
129 if ($action == "edit" ||
$action == "new") {
131 $sesskey = !empty($USER->id
) ?
$USER->sesskey
: '';
133 //Check for teacher edit
134 if (! isteacheredit($course->id
)) {
135 error("Only editing teachers can modify scales !");
137 //Check for scale if action = edit
138 if ($action == "edit") {
139 if (! $scale = get_record("scale", "id", $scaleid)) {
140 error("Scale ID was incorrect");
144 $scale->courseid
= $course->id
;
147 $scale->description
= "";
151 if ($scale->courseid
== 0) {
152 $scale_uses = site_scale_used($scale->id
,$courses);
154 $scale_uses = course_scale_used($course->id
,$scale->id
);
157 //Check for scale_uses
158 if (!empty($scale_uses)) {
159 error("Scale is in use and cannot be modified",$CFG->wwwroot
.'/course/scales.php?id='.$course->id
);
162 //Check for standard scales
163 if ($scale->courseid
== 0 and !isadmin()) {
164 error("Only administrators can edit this scale",$CFG->wwwroot
.'/course/scales.php?id='.$course->id
);
167 //Print out the headers
168 if (!isset($focus)) {
171 print_header("$course->shortname: $strscales", "$course->fullname",
172 "<a href=\"view.php?id=$course->id\">$course->shortname</a>".
173 " -> <a href=\"scales.php?id=$course->id\">$strscales</a>".
174 " -> ".get_string("editinga","",$strscale), $focus);
177 print_heading_with_help($strscales, "scales");
179 if (!empty($errors) and ($form->scaleid
== $scale->id
)) {
180 $scale->name
= $form->name
;
181 $scale->scale
= $form->scalescale
;
182 $scale->description
= $form->description
;
184 echo "<form method=\"post\" action=\"scales.php\" name=\"form$scale->id\">";
185 echo "<table cellpadding=\"9\" cellspacing=\"0\" align=\"center\" class=\"generalbox\">";
186 echo "<tr valign=\"top\">";
187 if (!empty($errors[$scale->id
]->name
)) {
188 $class = "class=\"highlight\"";
192 echo "<td align=\"right\"><b>$strname:</b></td>";
193 echo "<td $class><input type=\"text\" name=\"name\" size=\"50\" value=\"".s($scale->name
)."\" />";
196 echo "<tr valign=\"top\">";
197 if (!empty($errors[$scale->id
]->scalescale
)) {
198 $class = "class=\"highlight\"";
202 echo "<td align=\"right\"><b>$strscale:</b></td>";
203 echo "<td $class><textarea name=\"scalescale\" cols=\"50\" rows=\"2\" wrap=\"virtual\">".s($scale->scale
)."</textarea>";
206 echo "<tr valign=\"top\">";
207 echo "<td align=\"right\"><b>$strdescription:</b>";
208 helpbutton("text", $strhelptext);
210 echo "<td><textarea name=\"description\" cols=\"50\" rows=\"8\" wrap=\"virtual\">".s($scale->description
)."</textarea>";
215 echo "<tr valign=\"top\">";
216 echo "<td align=\"right\">";
218 echo "<td>".get_string("usedinnplaces","",$scale_uses);
223 echo "<td colspan=\"2\" align=\"center\">";
224 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
225 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$sesskey\" />";
226 echo "<input type=\"hidden\" name=\"courseid\" value=\"$scale->courseid\" />";
227 echo "<input type=\"hidden\" name=\"scaleid\" value=\"$scale->id\" />";
228 echo "<input type=\"hidden\" name=\"action\" value=\"sendform\" />";
229 echo "<input type=\"submit\" name=\"save\" value=\"$strsavechanges\" />";
230 echo "</td></tr></table>";
234 print_footer($course);
239 //If action is delete, do it
240 if ($action == "delete" and confirm_sesskey()) {
241 //Check for teacher edit
242 if (! isteacheredit($course->id
)) {
243 error("Only editing teachers can delete scales !");
245 //Check for scale if action = edit
246 if (! $scale = get_record("scale", "id", $scaleid)) {
247 error("Scale ID was incorrect");
251 if ($scale->courseid
== 0) {
252 $scale_uses = site_scale_used($scale->id
,$courses);
254 $scale_uses = course_scale_used($course->id
,$scale->id
);
257 //Check for scale_uses
258 if (!empty($scale_uses)) {
259 error("Scale is in use and cannot be deleted",$CFG->wwwroot
.'/course/scales.php?id='.$course->id
);
262 //Check for standard scales
263 if ($scale->courseid
== 0 and !isadmin()) {
264 error("Only administrators can delete this scale",$CFG->wwwroot
.'/course/scales.php?id='.$course->id
);
267 if (delete_records("scale", "id", $scaleid)) {
268 $notify = "$scale->name: $strdeleted";
272 //If action is down or up, do it
273 if (($action == "down" ||
$action == "up") and confirm_sesskey()) {
274 //Check for teacher edit
276 error("Only administrators can move scales",$CFG->wwwroot
.'/course/scales.php?id='.$course->id
);
278 //Check for scale if action = edit
279 if (! $scale = get_record("scale", "id", $scaleid)) {
280 error("Scale ID was incorrect");
284 if ($scale->courseid
== 0) {
285 $scale_uses = site_scale_used($scale->id
,$courses);
287 $scale_uses = course_scale_used($course->id
,$scale->id
);
290 //Check for scale_uses
291 if (!empty($scale_uses)) {
292 error("Scale is in use and cannot be moved",$CFG->wwwroot
.'/course/scales.php?id='.$course->id
);
295 if ($action == "down") {
296 $scale->courseid
= 0;
298 $scale->courseid
= $course->id
;
301 if (set_field("scale", "courseid", $scale->courseid
, "id", $scale->id
)) {
302 $notify = "$scale->name: $strmoved";
306 if (isset($_GET['list'])) { /// Just list the scales (in a helpwindow)
308 print_header($strscales);
310 if (isset($_GET['scale'])) {
311 if ($scale = get_record("scale", "id", "$scale")) {
312 $scalemenu = make_menu_from_list($scale->scale
);
314 print_simple_box_start("center");
315 print_heading($scale->name
);
317 choose_from_menu($scalemenu, "", "", "");
319 echo text_to_html($scale->description
);
320 print_simple_box_end();
323 close_window_button();
327 if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
328 print_heading($strcustomscales);
330 if (isteacheredit($course->id
)) {
331 echo "<p align=\"center\">(";
332 print_string("scalestip");
336 foreach ($scales as $scale) {
337 $scalemenu = make_menu_from_list($scale->scale
);
339 print_simple_box_start("center");
340 print_heading($scale->name
);
342 choose_from_menu($scalemenu, "", "", "");
344 echo text_to_html($scale->description
);
345 print_simple_box_end();
350 if (isteacheredit($course->id
)) {
351 echo "<p align=\"center\">(";
352 print_string("scalestip");
357 if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
358 print_heading($strstandardscales);
359 foreach ($scales as $scale) {
360 $scalemenu = make_menu_from_list($scale->scale
);
362 print_simple_box_start("center");
363 print_heading($scale->name
);
365 choose_from_menu($scalemenu, "", "", "");
367 echo text_to_html($scale->description
);
368 print_simple_box_end();
373 close_window_button();
378 /// The rest is all about editing the scales
380 if (!isteacheredit($course->id
)) {
381 error("Only editing teachers can modify scales !");
384 /// Print out the main page
386 print_header("$course->shortname: $strscales", "$course->fullname",
387 "<a href=\"view.php?id=$course->id\">$course->shortname</a>
390 print_heading_with_help($strscales, "scales");
393 $options['id'] = $course->id
;
394 $options['scaleid'] = 0;
395 $options['action'] = 'new';
397 print_simple_box_start('center');
398 print_single_button($CFG->wwwroot
.'/course/scales.php',$options,$srtcreatenewscale,'POST');
399 print_simple_box_end();
402 if (!empty($notify)) {
403 notify($notify, "green");
407 $customscales = get_records("scale", "courseid", "$course->id", "name ASC");
408 $standardscales = get_records("scale", "courseid", "0", "name ASC");
411 foreach($customscales as $scale) {
416 if ($standardscales) {
417 foreach($standardscales as $scale) {
423 //Calculate the base path
424 $path = "$CFG->wwwroot/course";
428 foreach($scales as $scale) {
429 //Check the separator
430 if (empty($scale->courseid
) && $incustom) {
436 $line[] = "<a target=\"scale\" title=\"$scale->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
."</a><br /><font size=\"-1\">".str_replace(",",", ",$scale->scale
)."</font>";
437 if (!empty($scale->courseid
)) {
438 $scales_uses = course_scale_used($course->id
,$scale->id
);
440 $scales_uses = site_scale_used($scale->id
,$courses);
442 $line[] = $scales_uses;
444 $line[] = $strcustomscale;
446 $line[] = $strstandardscale;
449 if (empty($scales_uses) && ($incustom ||
isadmin())) {
450 $buttons .= "<a title=\"$stredit\" href=\"$path/scales.php?id=$course->id&scaleid=$scale->id&action=edit\"><img".
451 " src=\"$CFG->pixpath/t/edit.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"\" /></a> ";
452 if ($incustom && isadmin()) {
453 $buttons .= "<a title=\"$strdown\" href=\"$path/scales.php?id=$course->id&scaleid=$scale->id&action=down&sesskey=$USER->sesskey\"><img".
454 " src=\"$CFG->pixpath/t/down.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"\" /></a> ";
456 if (!$incustom && isadmin()) {
457 $buttons .= "<a title=\"$strup\" href=\"$path/scales.php?id=$course->id&scaleid=$scale->id&action=up&sesskey=$USER->sesskey\"><img".
458 " src=\"$CFG->pixpath/t/up.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"\" /></a> ";
460 $buttons .= "<a title=\"$strdelete\" href=\"$path/scales.php?id=$course->id&scaleid=$scale->id&action=delete&sesskey=$USER->sesskey\"><img".
461 " src=\"$CFG->pixpath/t/delete.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"\" /></a> ";
467 $head = $strscale.",".$stractivities.",".$strtype.",".$stroptions;
468 $table->head
= explode(",",$head);
469 $size = "50%,20%,20%,10%";
470 $table->size
= explode(",",$size);
471 $align = "left,center,center,center";
472 $table->align
= explode(",",$align);
473 $wrap = ",nowrap,nowrap,nowrap";
474 $table->wrap
= explode(",",$wrap);
475 $table->width
= "90%";
476 $table->data
= $data;
477 print_table ($table);
480 print_footer($course);