New help translation
[moodle.git] / course / scales.php
blob6f41f39d33065434d7dff33d176e940ba5e82e11
1 <?PHP // $Id$
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($name); // scale name
10 optional_variable($description); // scale description
11 optional_variable($scale); // scale scale
12 optional_variable($delete); // scale id
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 $strcustomscales = get_string("scalescustom");
23 $strstandardscales = get_string("scalesstandard");
24 $strname = get_string("name");
25 $strdescription = get_string("description");
26 $strsavechanges = get_string("savechanges");
27 $strchangessaved = get_string("changessaved");
28 $strdeleted = get_string("deleted");
29 $strdelete = get_string("delete");
32 if (isset($_GET['list'])) { /// Just list the scales (in a helpwindow)
34 print_header($strscales);
36 if (isset($_GET['scale'])) {
37 if ($scale = get_record("scale", "id", "$scale")) {
38 $scalemenu = make_menu_from_list($scale->scale);
40 print_simple_box_start("center");
41 print_heading($scale->name);
42 echo "<center>";
43 choose_from_menu($scalemenu, "", "", "");
44 echo "</center>";
45 echo text_to_html($scale->description);
46 print_simple_box_end();
48 echo "<br />";
49 close_window_button();
50 exit;
53 if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
54 print_heading($strcustomscales);
56 if (isteacheredit($course->id)) {
57 echo "<p align=\"center\">(";
58 print_string("scalestip");
59 echo ")</p>";
62 foreach ($scales as $scale) {
63 $scalemenu = make_menu_from_list($scale->scale);
65 print_simple_box_start("center");
66 print_heading($scale->name);
67 echo "<center>";
68 choose_from_menu($scalemenu, "", "", "");
69 echo "</center>";
70 echo text_to_html($scale->description);
71 print_simple_box_end();
72 echo "<hr />";
75 } else {
76 if (isteacheredit($course->id)) {
77 echo "<p align=\"center\">(";
78 print_string("scalestip");
79 echo ")</p>";
83 if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
84 print_heading($strstandardscales);
85 foreach ($scales as $scale) {
86 $scalemenu = make_menu_from_list($scale->scale);
88 print_simple_box_start("center");
89 print_heading($scale->name);
90 echo "<center>";
91 choose_from_menu($scalemenu, "", "", "");
92 echo "</center>";
93 echo text_to_html($scale->description);
94 print_simple_box_end();
95 echo "<hr />";
99 close_window_button();
100 exit;
104 /// The rest is all about editing the scales
106 if (!isteacheredit($course->id)) {
107 error("Only editing teachers can modify scales !");
111 /// If scale data is being submitted, then save it and continue
113 $errors = NULL;
115 if ($form = data_submitted()) {
116 if (!empty($form->delete)) { /// Delete a scale
117 $scale = get_record("scale", "id", $scaleid);
118 if (delete_records("scale", "id", $scaleid)) {
119 $notify = "$scale->name: $strdeleted";
121 } else { /// Update scale data
122 if (empty($form->name)) {
123 $errors[$scaleid]->name = true;
124 $focus = "form$scaleid.save";
126 if (empty($form->scale)) {
127 $errors[$scaleid]->scale = true;
128 $focus = "form$scaleid.save";
131 if (!$errors) {
132 $newscale=NULL;
133 $newscale->name = $form->name;
134 $newscale->scale = $form->scale;
135 $newscale->description = $form->description;
136 $newscale->courseid = $course->id;
137 $newscale->userid = $USER->id;
138 $newscale->timemodified = time();
140 if (empty($scaleid)) {
141 if (!insert_record("scale", $newscale)) {
142 error("Could not insert the new scale!");
144 } else {
145 $newscale->id = $scaleid;
146 if (!update_record("scale", $newscale)) {
147 error("Could not update that scale!");
151 $notify = "$newscale->name: $strchangessaved";
152 $focus = "form$scaleid.save";
158 /// Print out the headers
160 print_header("$course->shortname: $strscales", "$course->fullname",
161 "<a href=\"view.php?id=$course->id\">$course->shortname</A>
162 -> $strscales", $focus);
164 print_heading_with_help($strcustomscales, "scales");
166 if (!empty($notify)) {
167 notify($notify, "green");
171 /// Otherwise print out all the scale forms
173 $customscales = get_records("scale", "courseid", "$course->id", "name ASC");
175 $blankscale->id = "";
176 $blankscale->name = "";
177 $blankscale->scale = "";
178 $blankscale->description = "";
179 $customscales[] = $blankscale;
181 foreach ($customscales as $scale) {
182 if (!empty($errors) and ($form->scaleid == $scale->id)) {
183 $scale->name = $form->name;
184 $scale->scale = $form->scale;
185 $scale->description = $form->description;
187 echo "<form method=\"post\" action=\"scales.php\" name=\"form$scale->id\">";
188 echo "<table cellpadding=9 cellspacing=0 align=center class=generalbox>";
189 echo "<tr valign=top>";
190 if (!empty($errors[$scale->id]->name)) {
191 $class = "class=\"highlight\"";
192 } else {
193 $class = "";
195 echo "<td align=\"right\"><p><b>$strname:</b></p></td>";
196 echo "<td $class><input type=\"text\" name=\"name\" size=\"50\" value=\"".s($scale->name)."\">";
197 echo "</td>";
198 echo "</tr>";
199 echo "<tr valign=top>";
200 if (!empty($errors[$scale->id]->scale)) {
201 $class = "class=\"highlight\"";
202 } else {
203 $class = "";
205 echo "<td align=\"right\"><p><b>$strscale:</b></p></td>";
206 echo "<td $class><textarea name=\"scale\" cols=50 rows=1 wrap=virtual>".s($scale->scale)."</textarea>";
207 echo "</td>";
208 echo "</tr>";
209 echo "<tr valign=top>";
210 echo "<td align=\"right\"><p><b>$strdescription:</b></p>";
211 helpbutton("text", get_string("helptext"));
212 echo "</td>";
213 echo "<td><textarea name=\"description\" cols=50 rows=8 wrap=virtual>".s($scale->description)."</textarea>";
214 echo "</td>";
215 echo "</tr>";
216 echo "<tr>";
217 echo "<td colspan=2 align=\"center\">";
218 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\">";
219 echo "<input type=\"hidden\" name=\"scaleid\" value=\"$scale->id\">";
220 echo "<input type=\"submit\" name=\"save\" value=\"$strsavechanges\">";
221 if ($scale->id) {
222 echo "<input type=\"submit\" name=\"delete\" value=\"$strdelete\">";
224 echo "</td></tr></table>";
225 echo "</form>";
226 echo "<br />";
229 echo "<br /><hr noshade=\"noshade\" size=\"1\">";
232 if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
233 print_heading($strstandardscales);
234 foreach ($scales as $scale) {
235 $scalemenu = make_menu_from_list($scale->scale);
237 print_simple_box_start("center");
238 print_heading($scale->name);
239 echo "<center>";
240 choose_from_menu($scalemenu, "", "", "");
241 echo "</center>";
242 echo text_to_html($scale->description);
243 print_simple_box_end();
244 echo "<hr />";
248 print_footer($course);