Added a new string for the new scales.php alternative. Bug 1223
[moodle.git] / course / scales.php
CommitLineData
a57319b1 1<?PHP // $Id$
2 // Allows a creator to edit custom scales, and also display help about scales
3
4 require_once("../config.php");
5 require_once("lib.php");
6
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
13
14 if (! $course = get_record("course", "id", $id)) {
15 error("Course ID was incorrect");
16 }
17
18 require_login($course->id);
19
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");
30
31
32 if (isset($_GET['list'])) { /// Just list the scales (in a helpwindow)
33
34 print_header($strscales);
35
36 if (isset($_GET['scale'])) {
37 if ($scale = get_record("scale", "id", "$scale")) {
38 $scalemenu = make_menu_from_list($scale->scale);
39
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();
47 }
48 echo "<br />";
49 close_window_button();
50 exit;
51 }
52
53 if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
54 print_heading($strcustomscales);
4909e176 55
56 if (isteacheredit($course->id)) {
57 echo "<p align=\"center\">(";
58 print_string("scalestip");
59 echo ")</p>";
60 }
61
a57319b1 62 foreach ($scales as $scale) {
63 $scalemenu = make_menu_from_list($scale->scale);
64
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 />";
73 }
4909e176 74
75 } else {
76 if (isteacheredit($course->id)) {
77 echo "<p align=\"center\">(";
78 print_string("scalestip");
79 echo ")</p>";
80 }
a57319b1 81 }
82
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);
87
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 />";
96 }
97 }
98
99 close_window_button();
100 exit;
101 }
102
103
104/// The rest is all about editing the scales
105
d99eab3c 106 if (!isteacheredit($course->id)) {
107 error("Only editing teachers can modify scales !");
a57319b1 108 }
109
110
111/// If scale data is being submitted, then save it and continue
112
113 $errors = NULL;
114
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";
120 }
121 } else { /// Update scale data
122 if (empty($form->name)) {
123 $errors[$scaleid]->name = true;
124 $focus = "form$scaleid.save";
125 }
126 if (empty($form->scale)) {
127 $errors[$scaleid]->scale = true;
128 $focus = "form$scaleid.save";
129 }
130
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();
139
140 if (empty($scaleid)) {
141 if (!insert_record("scale", $newscale)) {
142 error("Could not insert the new scale!");
143 }
144 } else {
145 $newscale->id = $scaleid;
146 if (!update_record("scale", $newscale)) {
147 error("Could not update that scale!");
148 }
149 }
150
151 $notify = "$newscale->name: $strchangessaved";
152 $focus = "form$scaleid.save";
153 }
154 }
155 }
156
157
158/// Print out the headers
159
160 print_header("$course->shortname: $strscales", "$course->fullname",
161 "<a href=\"view.php?id=$course->id\">$course->shortname</A>
162 -> $strscales", $focus);
163
a3ba1470 164 print_heading_with_help($strcustomscales, "scales");
a57319b1 165
166 if (!empty($notify)) {
905be758 167 notify($notify, "green");
a57319b1 168 }
169
170
171/// Otherwise print out all the scale forms
172
173 $customscales = get_records("scale", "courseid", "$course->id", "name ASC");
174
175 $blankscale->id = "";
176 $blankscale->name = "";
177 $blankscale->scale = "";
178 $blankscale->description = "";
179 $customscales[] = $blankscale;
180
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;
186 }
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 = "";
194 }
d4f25384 195 echo "<td align=\"right\"><p><b>$strname:</b></p></td>";
a57319b1 196 echo "<td $class><input type=\"text\" name=\"name\" size=\"50\" value=\"".s($scale->name)."\">";
a57319b1 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 = "";
204 }
d4f25384 205 echo "<td align=\"right\"><p><b>$strscale:</b></p></td>";
a57319b1 206 echo "<td $class><textarea name=\"scale\" cols=50 rows=1 wrap=virtual>".s($scale->scale)."</textarea>";
a57319b1 207 echo "</td>";
208 echo "</tr>";
209 echo "<tr valign=top>";
d4f25384 210 echo "<td align=\"right\"><p><b>$strdescription:</b></p>";
211 helpbutton("text", get_string("helptext"));
212 echo "</td>";
a57319b1 213 echo "<td><textarea name=\"description\" cols=50 rows=8 wrap=virtual>".s($scale->description)."</textarea>";
a57319b1 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\">";
223 }
224 echo "</td></tr></table>";
225 echo "</form>";
226 echo "<br />";
227 }
228
229 echo "<br /><hr noshade=\"noshade\" size=\"1\">";
230
231
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);
236
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 />";
245 }
246 }
247
248 print_footer($course);
249
250
251?>