always make sure that page param is in the pageurl
[moodle.git] / question / category_class.php
CommitLineData
107e7612 1<?php // $Id$
516cf3eb 2/**
4323d029 3 * Class representing question categories
bc649d80 4 *
bc649d80 5 * @author Martin Dougiamas and many others. {@link http://moodle.org}
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
4323d029 7 * @package questionbank
bc649d80 8 */
516cf3eb 9
10// number of categories to display on page
dac786f3 11define("QUESTION_PAGE_LENGTH", 25);
12
13require_once("$CFG->libdir/listlib.php");
14
15class question_category_list extends moodle_list {
16 var $table = "question_categories";
17 var $listitemclassname = 'question_category_list_item';
18 function question_category_list($type='ul', $attributes='', $editable = false, $page = 0){
19 parent::moodle_list($type, $attributes, $editable, $page);
20 }
21 function get_records() {
22 global $COURSE, $CFG;
23 $categories = get_records($this->table, 'course', "{$COURSE->id}", $this->sortby);
24
25 $catids = array_keys($categories);
26 $select = "WHERE category IN ('".join("', '", $catids)."') AND hidden='0' AND parent='0'";
27 $questioncounts = get_records_sql_menu('SELECT category, COUNT(*) FROM '. $CFG->prefix . 'question' .' '. $select.' GROUP BY category');
28 foreach ($categories as $categoryid => $category){
29 if (isset($questioncounts[$categoryid])){
30 $categories[$categoryid]->questioncount = $questioncounts[$categoryid];
31 } else {
32 $categories[$categoryid]->questioncount = 0;
33 }
34 }
35 $this->records = $categories;
36 }
37}
38
39class question_category_list_item extends list_item {
40
41
42 function item_html($extraargs = array()){
43 global $CFG;
44 $pixpath = $CFG->pixpath;
45 $str = $extraargs['str'];
46 $category = $this->item;
47
48 $linkcss = $category->publish ? ' class="published" ' : ' class="unpublished" ';
49
50 if (!empty($parent->page)) {
51 $pagelink="&amp;page=".$parent->page;
52 } else {
53 $pagelink="";
54 }
55
56 /// Each section adds html to be displayed as part of this list item
57
58 $item = '<a ' . $linkcss . ' title="' . $str->edit. '" href="'.$this->parentlist->get_action_url().'&amp;edit=' . $this->id .'">
59 <img src="' . $pixpath . '/t/edit.gif" class="iconsmall"
60 alt="' .$str->edit. '" /> ' . $category->name . '('.$category->questioncount.')'. '</a>';
61
62 $item .= '&nbsp;'. $category->info;
63
64
65 if (!empty($category->publish)) {
66 $item .= '<a title="' . $str->hide . '" href="'.$this->parentlist->get_action_url().'&amp;hide=' . $this->id .'">
67 <img src="' . $pixpath . '/t/hide.gif" class="iconsmall" alt="' .$str->hide. '" /></a> ';
68 } else {
69 $item .= '<a title="' . $str->publish . '" href="'.$this->parentlist->get_action_url().'&amp;publish=' . $this->id .'">
70 <img src="' . $pixpath . '/t/show.gif" class="iconsmall" alt="' .$str->publish. '" /></a> ';
71 }
72
73 if ($category->id != $extraargs['defaultcategory']->id) {
74 $item .= '<a title="' . $str->delete . '"href="'.$this->parentlist->get_action_url().'&amp;delete=' . $this->id .'">
75 <img src="' . $pixpath . '/t/delete.gif" class="iconsmall" alt="' .$str->delete. '" /></a> ';
76 }
77
78 return $item;
79
80
81 }
82
83}
84
516cf3eb 85
4323d029 86/**
87 * Class representing question categories
dac786f3 88 *
4323d029 89 * @package questionbank
90 */
dc1f00de 91class question_category_object {
516cf3eb 92
93 var $str;
94 var $pixpath;
dac786f3 95 /**
96 * Nested list to display categories.
97 *
98 * @var question_category_list
99 */
100 var $editlist;
516cf3eb 101 var $newtable;
102 var $tab;
103 var $tabsize = 3;
104 var $categories;
105 var $categorystrings;
106 var $defaultcategory;
a982d582 107//------------------------------------------------------
108 var $pageurl;
109 var $pageparams = array();
516cf3eb 110
bc649d80 111 /**
112 * Constructor
113 *
114 * Gets necessary strings and sets relevant path information
115 */
dac786f3 116 function question_category_object($page) {
117 global $CFG, $COURSE;
516cf3eb 118
119 $this->tab = str_repeat('&nbsp;', $this->tabsize);
120
121 $this->str->course = get_string('course');
122 $this->str->category = get_string('category', 'quiz');
123 $this->str->categoryinfo = get_string('categoryinfo', 'quiz');
124 $this->str->questions = get_string('questions', 'quiz');
125 $this->str->add = get_string('add');
126 $this->str->delete = get_string('delete');
127 $this->str->moveup = get_string('moveup');
128 $this->str->movedown = get_string('movedown');
129 $this->str->edit = get_string('editthiscategory');
130 $this->str->hide = get_string('hide');
131 $this->str->publish = get_string('publish', 'quiz');
132 $this->str->order = get_string('order');
133 $this->str->parent = get_string('parent', 'quiz');
134 $this->str->add = get_string('add');
135 $this->str->action = get_string('action');
136 $this->str->top = get_string('top', 'quiz');
137 $this->str->addcategory = get_string('addcategory', 'quiz');
138 $this->str->editcategory = get_string('editcategory', 'quiz');
139 $this->str->cancel = get_string('cancel');
140 $this->str->editcategories = get_string('editcategories', 'quiz');
2befe778 141 $this->str->page = get_string('page');
516cf3eb 142 $this->pixpath = $CFG->pixpath;
143
dac786f3 144 $this->editlist = new question_category_list('ul', '', true, $page);
a982d582 145
71e0eda8 146 $this->add_page_params(array('courseid'=>$COURSE->id, 'page' => $this->page));
a982d582 147 $this->pageurl = strip_querystring(qualified_me());//default
148
dac786f3 149 $this->initialize();
516cf3eb 150
516cf3eb 151 }
a982d582 152
153 /**
154 * Add an array of params to the params for this page.
155 *
156 * @param unknown_type $params
157 */
158 function add_page_params($params){
159 $this->pageparams = $params + $this->pageparams;
160 $this->editlist->add_page_params($params);
161 }
162
163 /**
164 * Get url and query string for an action on this page (get_url() + sesskey)
165 *
166 * @param array $overrideparams an array of params which override $this->pageparams
167 * @return string
168 */
169 function get_action_url($overrideparams = array()){
170 global $USER;
516cf3eb 171
a982d582 172 $arr = array();
173 $paramarray = $overrideparams + $this->pageparams + array('sesskey'=>$USER->sesskey);
174 foreach ($paramarray as $key => $val){
175 $arr[] = urlencode($key)."=".urlencode($val);
176 }
177 $params = implode($arr, "&amp;");
dac786f3 178
a982d582 179 return $this->pageurl.'?'.$params;
180 }
181
182 /**
183 * Get url and query string for this page
184 *
185 * @param array $overrideparams an array of params which override $this->pageparams
186 * @return string
187 */
188 function get_url($overrideparams = array()){
189
190 $arr = array();
191 $paramarray = $overrideparams + $this->pageparams;
192 foreach ($paramarray as $key => $val){
193 $arr[] = urlencode($key)."=".urlencode($val);
194 }
195 $params = implode($arr, "&amp;");
196
197 return $this->pageurl.'?'.$params;
198 }
dac786f3 199
bc649d80 200 /**
201 * Displays the user interface
202 *
bc649d80 203 */
dac786f3 204 function display_user_interface() {
205
206 /// Interface for editing existing categories
207 print_heading_with_help($this->str->editcategories, 'categories', 'quiz');
208 $this->output_edit_list();
209
516cf3eb 210
dac786f3 211 echo '<br />';
516cf3eb 212 /// Interface for adding a new category:
213 print_heading_with_help($this->str->addcategory, 'categories_edit', 'quiz');
214 $this->output_new_table();
215 echo '<br />';
216
516cf3eb 217 }
218
219
bc649d80 220 /**
221 * Initializes this classes general category-related variables
222 */
516cf3eb 223 function initialize() {
dac786f3 224 global $COURSE, $CFG;
516cf3eb 225
226 /// Get the existing categories
dac786f3 227 if (!$this->defaultcategory = get_default_question_category($COURSE->id)) {
516cf3eb 228 error("Error: Could not find or make a category!");
229 }
230
dac786f3 231 $this->editlist->list_from_records(QUESTION_PAGE_LENGTH);
516cf3eb 232
dac786f3 233 $this->categories = $this->editlist->records;
516cf3eb 234
235 // create the array of id=>full_name strings
236 $this->categorystrings = $this->expanded_category_strings($this->categories);
237
516cf3eb 238
516cf3eb 239 }
240
dac786f3 241
bc649d80 242 /**
243 * Outputs a table to allow entry of a new category
244 */
516cf3eb 245 function output_new_table() {
dac786f3 246 global $USER, $COURSE;
516cf3eb 247 $publishoptions[0] = get_string("no");
248 $publishoptions[1] = get_string("yes");
249
250 $this->newtable->head = array ($this->str->parent, $this->str->category, $this->str->categoryinfo, $this->str->publish, $this->str->action);
dac786f3 251 $this->newtable->width = '200';
516cf3eb 252 $this->newtable->data[] = array();
253 $this->newtable->tablealign = 'center';
254
255 /// Each section below adds a data cell to the table row
256
257
258 $viableparents[0] = $this->str->top;
259 $viableparents = $viableparents + $this->categorystrings;
260 $this->newtable->align['parent'] = "left";
261 $this->newtable->wrap['parent'] = "nowrap";
262 $row['parent'] = choose_from_menu ($viableparents, "newparent", $this->str->top, "", "", "", true);
263
264 $this->newtable->align['category'] = "left";
265 $this->newtable->wrap['category'] = "nowrap";
266 $row['category'] = '<input type="text" name="newcategory" value="" size="15" />';
267
268 $this->newtable->align['info'] = "left";
269 $this->newtable->wrap['info'] = "nowrap";
270 $row['info'] = '<input type="text" name="newinfo" value="" size="50" />';
271
272 $this->newtable->align['publish'] = "left";
273 $this->newtable->wrap['publish'] = "nowrap";
274 $row['publish'] = choose_from_menu ($publishoptions, "newpublish", "", "", "", "", true);
275
276 $this->newtable->align['action'] = "left";
277 $this->newtable->wrap['action'] = "nowrap";
278 $row['action'] = '<input type="submit" value="' . $this->str->add . '" />';
279
280
281 $this->newtable->data[] = $row;
282
283 // wrap the table in a form and output it
284 echo '<form action="category.php" method="post">';
d187f660 285 echo '<fieldset class="invisiblefieldset" style="display: block">';
516cf3eb 286 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
71e0eda8 287 echo '<input type="hidden" name="courseid" value="'. $COURSE->id . '" />';
516cf3eb 288 echo '<input type="hidden" name="addcategory" value="true" />';
289 print_table($this->newtable);
09275894 290 echo '</fieldset>';
516cf3eb 291 echo '</form>';
292 }
293
dac786f3 294
bc649d80 295 /**
dac786f3 296 * Outputs a list to allow editing/rearranging of existing categories
bc649d80 297 *
298 * $this->initialize() must have already been called
299 *
bc649d80 300 * @param int $page page to display (0=do not paginate)
301 */
dac786f3 302 function output_edit_list() {
303 print_box_start('boxwidthwide boxaligncenter generalbox');
304 echo $this->editlist->to_html(0, array('str'=>$this->str,
305 'defaultcategory' => $this->defaultcategory));
306 print_box_end();
307 echo $this->editlist->display_page_numbers();
308
516cf3eb 309 }
310
dac786f3 311
312
bc649d80 313 /**
314 * gets all the courseids for the given categories
315 *
316 * @param array categories contains category objects in a tree representation
317 * @return array courseids flat array in form categoryid=>courseid
318 */
516cf3eb 319 function get_course_ids($categories) {
320 $courseids = array();
321 foreach ($categories as $key=>$cat) {
322 $courseids[$key] = $cat->course;
323 if (!empty($cat->children)) {
324 $courseids = array_merge($courseids, $this->get_course_ids($cat->children));
325 }
326 }
327 return $courseids;
328 }
329
516cf3eb 330
516cf3eb 331
dac786f3 332 function edit_single_category($categoryid, $page=1) {
516cf3eb 333 /// Interface for adding a new category
dac786f3 334 global $USER, $COURSE;
516cf3eb 335
336 /// Interface for editing existing categories
dc1f00de 337 if ($category = get_record("question_categories", "id", $categoryid)) {
516cf3eb 338 echo '<h2 align="center">';
339 echo $this->str->edit;
340 helpbutton("categories_edit", $this->str->editcategory, "quiz");
341 echo '</h2>';
342 echo '<table width="100%"><tr><td>';
dac786f3 343 $this->output_edit_single_table($category, $page);
516cf3eb 344 echo '</td></tr></table>';
345 echo '<p><div align="center"><form action="category.php" method="get">
5bff81ab 346 <div>
516cf3eb 347 <input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />
dac786f3 348 <input type="hidden" name="id" value="' . $COURSE->id . '" />
09275894 349 <input type="submit" value="' . $this->str->cancel . '" />
5bff81ab 350 </div>
09275894 351 </form>
352 </div></p>';
dac786f3 353 print_footer($COURSE);
516cf3eb 354 exit;
355 } else {
dac786f3 356 error("Category $categoryid not found", "category.php?id={$COURSE->id}");
516cf3eb 357 }
358 }
359
bc649d80 360 /**
361 * Outputs a table to allow editing of an existing category
362 *
363 * @param object category
364 * @param int page current page
365 */
516cf3eb 366 function output_edit_single_table($category, $page=1) {
dac786f3 367 global $USER, $COURSE;
516cf3eb 368 $publishoptions[0] = get_string("no");
369 $publishoptions[1] = get_string("yes");
370 $strupdate = get_string('update');
371
4abc23b2 372 $edittable = new stdClass;
516cf3eb 373
374 $edittable->head = array ($this->str->parent, $this->str->category, $this->str->categoryinfo, $this->str->publish, $this->str->action);
375 $edittable->width = 200;
376 $edittable->data[] = array();
377 $edittable->tablealign = 'center';
378
379 /// Each section below adds a data cell to the table row
380
381 $viableparents = $this->categorystrings;
382 $this->set_viable_parents($viableparents, $category);
383 $viableparents = array(0=>$this->str->top) + $viableparents;
384 $edittable->align['parent'] = "left";
385 $edittable->wrap['parent'] = "nowrap";
386 $row['parent'] = choose_from_menu ($viableparents, "updateparent", "{$category->parent}", "", "", "", true);
387
388 $edittable->align['category'] = "left";
389 $edittable->wrap['category'] = "nowrap";
6ba65fa0 390 $row['category'] = '<input type="text" name="updatename" value="' . format_string($category->name) . '" size="15" />';
516cf3eb 391
392 $edittable->align['info'] = "left";
393 $edittable->wrap['info'] = "nowrap";
394 $row['info'] = '<input type="text" name="updateinfo" value="' . $category->info . '" size="50" />';
395
396 $edittable->align['publish'] = "left";
397 $edittable->wrap['publish'] = "nowrap";
398 $selected = (boolean)$category->publish ? 1 : 0;
399 $row['publish'] = choose_from_menu ($publishoptions, "updatepublish", $selected, "", "", "", true);
400
401 $edittable->align['action'] = "left";
402 $edittable->wrap['action'] = "nowrap";
403 $row['action'] = '<input type="submit" value="' . $strupdate . '" />';
404
405 $edittable->data[] = $row;
406
407 // wrap the table in a form and output it
408 echo '<p><form action="category.php" method="post">';
09275894 409 echo '<fieldset class="invisiblefieldset">';
516cf3eb 410 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
dac786f3 411 echo '<input type="hidden" name="id" value="'. $COURSE->id . '" />';
516cf3eb 412 echo '<input type="hidden" name="updateid" value="' . $category->id . '" />';
413 echo "<input type=\"hidden\" name=\"page\" value=\"$page\" />";
414 print_table($edittable);
09275894 415 echo '</fieldset>';
516cf3eb 416 echo '</form></p>';
417 }
418
bc649d80 419 /**
420 * Creates an array of "full-path" category strings
421 * Structure:
422 * key => string
423 * where key is the category id, and string contains the name of all ancestors as well as the particular category name
424 * E.g. '123'=>'Language / English / Grammar / Modal Verbs"
425 *
426 * @param array $categories an array containing categories arranged in a tree structure
427 */
516cf3eb 428 function expanded_category_strings($categories, $parent=null) {
429 $prefix = is_null($parent) ? '' : "$parent / ";
430 $categorystrings = array();
431 foreach ($categories as $key => $category) {
432 $expandedname = "$prefix$category->name";
433 $categorystrings[$key] = $expandedname;
434 if (isset($category->children)) {
435 $categorystrings = $categorystrings + $this->expanded_category_strings($category->children, $expandedname);
436 }
437 }
438 return $categorystrings;
439 }
440
516cf3eb 441
bc649d80 442 /**
443 * Sets the viable parents
444 *
445 * Viable parents are any except for the category itself, or any of it's descendants
446 * The parentstrings parameter is passed by reference and changed by this function.
447 *
448 * @param array parentstrings a list of parentstrings
449 * @param object category
450 */
516cf3eb 451 function set_viable_parents(&$parentstrings, $category) {
452
453 unset($parentstrings[$category->id]);
454 if (isset($category->children)) {
455 foreach ($category->children as $child) {
456 $this->set_viable_parents($parentstrings, $child);
457 }
458 }
459 }
460
bc649d80 461 /**
462 * Gets question categories
463 *
464 * @param int parent - if given, restrict records to those with this parent id.
465 * @param string sort - [[sortfield [,sortfield]] {ASC|DESC}]
466 * @return array categories
467 */
dc1f00de 468 function get_question_categories($parent=null, $sort="sortorder ASC") {
dac786f3 469 global $COURSE;
516cf3eb 470 if (is_null($parent)) {
dac786f3 471 $categories = get_records('question_categories', 'course', "{$COURSE->id}", $sort);
516cf3eb 472 } else {
dac786f3 473 $select = "parent = '$parent' AND course = '{$COURSE->id}'";
dc1f00de 474 $categories = get_records_select('question_categories', $select, $sort);
516cf3eb 475 }
476 return $categories;
477 }
478
bc649d80 479 /**
480 * Deletes an existing question category
481 *
482 * @param int deletecat id of category to delete
483 * @param int destcategoryid id of category which will inherit the orphans of deletecat
484 */
516cf3eb 485 function delete_category($deletecat, $destcategoryid = null) {
dac786f3 486 global $USER, $COURSE;
516cf3eb 487
dc1f00de 488 if (!$category = get_record("question_categories", "id", $deletecat)) { // security
dac786f3 489 error("No such category $deletecat!", "category.php?id={$COURSE->id}");
516cf3eb 490 }
491
492 if (!is_null($destcategoryid)) { // Need to move some questions before deleting the category
dc1f00de 493 if (!$category2 = get_record("question_categories", "id", $destcategoryid)) { // security
dac786f3 494 error("No such category $destcategoryid!", "category.php?id={$COURSE->id}");
516cf3eb 495 }
4abc23b2 496 if (! set_field('question', 'category', $destcategoryid, 'category', $deletecat)) {
dac786f3 497 error("Error while moving questions from category '" . format_string($category->name) . "' to '$category2->name'", "category.php?id={$COURSE->id}");
516cf3eb 498 }
499
500 } else {
501 // todo: delete any hidden questions that are not actually in use any more
4f48fb42 502 if ($count = count_records("question", "category", $category->id)) {
4abc23b2 503 $vars = new stdClass;
516cf3eb 504 $vars->name = $category->name;
505 $vars->count = $count;
506 print_simple_box(get_string("categorymove", "quiz", $vars), "center");
507 $this->initialize();
508 $categorystrings = $this->categorystrings;
509 unset ($categorystrings[$category->id]);
510 echo "<p><div align=\"center\"><form action=\"category.php\" method=\"get\">";
09275894 511 echo '<fieldset class="invisiblefieldset">';
516cf3eb 512 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
dac786f3 513 echo "<input type=\"hidden\" name=\"id\" value=\"{$COURSE->id}\" />";
516cf3eb 514 echo "<input type=\"hidden\" name=\"delete\" value=\"$category->id\" />";
515 choose_from_menu($categorystrings, "confirm", "", "");
516 echo "<input type=\"submit\" value=\"". get_string("categorymoveto", "quiz") . "\" />";
517 echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->str->cancel}\" />";
09275894 518 echo '</fieldset>';
516cf3eb 519 echo "</form></div></p>";
dac786f3 520 print_footer($COURSE);
516cf3eb 521 exit;
522 }
523 }
516cf3eb 524
525 /// Send the children categories to live with their grandparent
dc1f00de 526 if ($childcats = get_records("question_categories", "parent", $category->id)) {
516cf3eb 527 foreach ($childcats as $childcat) {
dc1f00de 528 if (! set_field("question_categories", "parent", $category->parent, "id", $childcat->id)) {
dac786f3 529 error("Could not update a child category!", "category.php?id={$COURSE->id}");
516cf3eb 530 }
531 }
532 }
533
534 /// Finally delete the category itself
dc1f00de 535 if (delete_records("question_categories", "id", $category->id)) {
6ba65fa0 536 notify(get_string("categorydeleted", "quiz", format_string($category->name)), 'notifysuccess');
a982d582 537 redirect($this->get_url());//always redirect after successful action
516cf3eb 538 }
539 }
540
516cf3eb 541
516cf3eb 542
bc649d80 543 /**
544 * Changes the published status of a category
545 *
546 * @param boolean publish
547 * @param int categoryid
548 */
516cf3eb 549 function publish_category($publish, $categoryid) {
550 /// Hide or publish a category
551
552 $publish = ($publish == false) ? 0 : 1;
dc1f00de 553 $tempcat = get_record("question_categories", "id", $categoryid);
516cf3eb 554 if ($tempcat) {
dc1f00de 555 if (! set_field("question_categories", "publish", $publish, "id", $tempcat->id)) {
516cf3eb 556 notify("Could not update that category!");
a982d582 557 } else {
558 redirect($this->get_url());//always redirect after successful action
516cf3eb 559 }
a982d582 560
516cf3eb 561 }
562 }
563
bc649d80 564 /**
565 * Creates a new category with given params
566 *
567 * @param int $newparent id of the parent category
568 * @param string $newcategory the name for the new category
569 * @param string $newinfo the info field for the new category
570 * @param int $newpublish whether to publish the category
571 * @param int $newcourse the id of the associated course
572 */
516cf3eb 573 function add_category($newparent, $newcategory, $newinfo, $newpublish, $newcourse) {
bc649d80 574 if (empty($newcategory)) {
575 notify(get_string('categorynamecantbeblank', 'quiz'), 'notifyproblem');
576 return false;
577 }
516cf3eb 578
579 if ($newparent) {
580 // first check that the parent category is in the correct course
dc1f00de 581 if(!(get_field('question_categories', 'course', 'id', $newparent) == $newcourse)) {
516cf3eb 582 return false;
583 }
584 }
585
586 $cat = NULL;
587 $cat->parent = $newparent;
588 $cat->name = $newcategory;
589 $cat->info = $newinfo;
590 $cat->publish = $newpublish;
591 $cat->course = $newcourse;
592 $cat->sortorder = 999;
593 $cat->stamp = make_unique_id_code();
dc1f00de 594 if (!insert_record("question_categories", $cat)) {
f5565b69 595 error("Could not insert the new question category '$newcategory'", "category.php?id={$newcourse}");
516cf3eb 596 } else {
bc649d80 597 notify(get_string("categoryadded", "quiz", $newcategory), 'notifysuccess');
a982d582 598 redirect($this->get_url());//always redirect after successful action
516cf3eb 599 }
516cf3eb 600 }
601
bc649d80 602 /**
603 * Updates an existing category with given params
604 *
605 * @param int updateid
606 * @param int updateparent
607 * @param string updatename
608 * @param string updateinfo
609 * @param int updatepublish
610 * @param int courseid the id of the associated course
611 */
516cf3eb 612 function update_category($updateid, $updateparent, $updatename, $updateinfo, $updatepublish, $courseid) {
bc649d80 613 if (empty($updatename)) {
614 notify(get_string('categorynamecantbeblank', 'quiz'), 'notifyproblem');
615 return false;
616 }
516cf3eb 617
618 $cat = NULL;
619 $cat->id = $updateid;
620 $cat->parent = $updateparent;
621 $cat->name = $updatename;
622 $cat->info = $updateinfo;
623 $cat->publish = $updatepublish;
dc1f00de 624 if (!update_record("question_categories", $cat)) {
516cf3eb 625 error("Could not update the category '$updatename'", "category.php?id={$courseid}");
626 } else {
bc649d80 627 notify(get_string("categoryupdated", 'quiz'), 'notifysuccess');
a982d582 628 redirect($this->get_url());
516cf3eb 629 }
630 }
516cf3eb 631}
632
633?>