The question core code was restricting question types unnecessarily. This is a tempor...
[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;
516cf3eb 107
bc649d80 108 /**
109 * Constructor
110 *
111 * Gets necessary strings and sets relevant path information
112 */
dac786f3 113 function question_category_object($page) {
114 global $CFG, $COURSE;
516cf3eb 115
116 $this->tab = str_repeat('&nbsp;', $this->tabsize);
117
118 $this->str->course = get_string('course');
119 $this->str->category = get_string('category', 'quiz');
120 $this->str->categoryinfo = get_string('categoryinfo', 'quiz');
121 $this->str->questions = get_string('questions', 'quiz');
122 $this->str->add = get_string('add');
123 $this->str->delete = get_string('delete');
124 $this->str->moveup = get_string('moveup');
125 $this->str->movedown = get_string('movedown');
126 $this->str->edit = get_string('editthiscategory');
127 $this->str->hide = get_string('hide');
128 $this->str->publish = get_string('publish', 'quiz');
129 $this->str->order = get_string('order');
130 $this->str->parent = get_string('parent', 'quiz');
131 $this->str->add = get_string('add');
132 $this->str->action = get_string('action');
133 $this->str->top = get_string('top', 'quiz');
134 $this->str->addcategory = get_string('addcategory', 'quiz');
135 $this->str->editcategory = get_string('editcategory', 'quiz');
136 $this->str->cancel = get_string('cancel');
137 $this->str->editcategories = get_string('editcategories', 'quiz');
2befe778 138 $this->str->page = get_string('page');
516cf3eb 139 $this->pixpath = $CFG->pixpath;
140
dac786f3 141 $this->editlist = new question_category_list('ul', '', true, $page);
142 $this->editlist->add_page_params(array('id'=>$COURSE->id));
143 $this->initialize();
516cf3eb 144
516cf3eb 145 }
146
dac786f3 147
148
bc649d80 149 /**
150 * Displays the user interface
151 *
bc649d80 152 */
dac786f3 153 function display_user_interface() {
154
155 /// Interface for editing existing categories
156 print_heading_with_help($this->str->editcategories, 'categories', 'quiz');
157 $this->output_edit_list();
158
516cf3eb 159
dac786f3 160 echo '<br />';
516cf3eb 161 /// Interface for adding a new category:
162 print_heading_with_help($this->str->addcategory, 'categories_edit', 'quiz');
163 $this->output_new_table();
164 echo '<br />';
165
516cf3eb 166 }
167
168
bc649d80 169 /**
170 * Initializes this classes general category-related variables
171 */
516cf3eb 172 function initialize() {
dac786f3 173 global $COURSE, $CFG;
516cf3eb 174
175 /// Get the existing categories
dac786f3 176 if (!$this->defaultcategory = get_default_question_category($COURSE->id)) {
516cf3eb 177 error("Error: Could not find or make a category!");
178 }
179
dac786f3 180 $this->editlist->list_from_records(QUESTION_PAGE_LENGTH);
516cf3eb 181
dac786f3 182 $this->categories = $this->editlist->records;
516cf3eb 183
184 // create the array of id=>full_name strings
185 $this->categorystrings = $this->expanded_category_strings($this->categories);
186
516cf3eb 187
516cf3eb 188 }
189
dac786f3 190
bc649d80 191 /**
192 * Outputs a table to allow entry of a new category
193 */
516cf3eb 194 function output_new_table() {
dac786f3 195 global $USER, $COURSE;
516cf3eb 196 $publishoptions[0] = get_string("no");
197 $publishoptions[1] = get_string("yes");
198
199 $this->newtable->head = array ($this->str->parent, $this->str->category, $this->str->categoryinfo, $this->str->publish, $this->str->action);
dac786f3 200 $this->newtable->width = '200';
516cf3eb 201 $this->newtable->data[] = array();
202 $this->newtable->tablealign = 'center';
203
204 /// Each section below adds a data cell to the table row
205
206
207 $viableparents[0] = $this->str->top;
208 $viableparents = $viableparents + $this->categorystrings;
209 $this->newtable->align['parent'] = "left";
210 $this->newtable->wrap['parent'] = "nowrap";
211 $row['parent'] = choose_from_menu ($viableparents, "newparent", $this->str->top, "", "", "", true);
212
213 $this->newtable->align['category'] = "left";
214 $this->newtable->wrap['category'] = "nowrap";
215 $row['category'] = '<input type="text" name="newcategory" value="" size="15" />';
216
217 $this->newtable->align['info'] = "left";
218 $this->newtable->wrap['info'] = "nowrap";
219 $row['info'] = '<input type="text" name="newinfo" value="" size="50" />';
220
221 $this->newtable->align['publish'] = "left";
222 $this->newtable->wrap['publish'] = "nowrap";
223 $row['publish'] = choose_from_menu ($publishoptions, "newpublish", "", "", "", "", true);
224
225 $this->newtable->align['action'] = "left";
226 $this->newtable->wrap['action'] = "nowrap";
227 $row['action'] = '<input type="submit" value="' . $this->str->add . '" />';
228
229
230 $this->newtable->data[] = $row;
231
232 // wrap the table in a form and output it
233 echo '<form action="category.php" method="post">';
d187f660 234 echo '<fieldset class="invisiblefieldset" style="display: block">';
516cf3eb 235 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
dac786f3 236 echo '<input type="hidden" name="id" value="'. $COURSE->id . '" />';
516cf3eb 237 echo '<input type="hidden" name="addcategory" value="true" />';
238 print_table($this->newtable);
09275894 239 echo '</fieldset>';
516cf3eb 240 echo '</form>';
241 }
242
dac786f3 243
bc649d80 244 /**
dac786f3 245 * Outputs a list to allow editing/rearranging of existing categories
bc649d80 246 *
247 * $this->initialize() must have already been called
248 *
bc649d80 249 * @param int $page page to display (0=do not paginate)
250 */
dac786f3 251 function output_edit_list() {
252 print_box_start('boxwidthwide boxaligncenter generalbox');
253 echo $this->editlist->to_html(0, array('str'=>$this->str,
254 'defaultcategory' => $this->defaultcategory));
255 print_box_end();
256 echo $this->editlist->display_page_numbers();
257
516cf3eb 258 }
259
dac786f3 260
261
bc649d80 262 /**
263 * gets all the courseids for the given categories
264 *
265 * @param array categories contains category objects in a tree representation
266 * @return array courseids flat array in form categoryid=>courseid
267 */
516cf3eb 268 function get_course_ids($categories) {
269 $courseids = array();
270 foreach ($categories as $key=>$cat) {
271 $courseids[$key] = $cat->course;
272 if (!empty($cat->children)) {
273 $courseids = array_merge($courseids, $this->get_course_ids($cat->children));
274 }
275 }
276 return $courseids;
277 }
278
516cf3eb 279
516cf3eb 280
dac786f3 281 function edit_single_category($categoryid, $page=1) {
516cf3eb 282 /// Interface for adding a new category
dac786f3 283 global $USER, $COURSE;
516cf3eb 284
285 /// Interface for editing existing categories
dc1f00de 286 if ($category = get_record("question_categories", "id", $categoryid)) {
516cf3eb 287 echo '<h2 align="center">';
288 echo $this->str->edit;
289 helpbutton("categories_edit", $this->str->editcategory, "quiz");
290 echo '</h2>';
291 echo '<table width="100%"><tr><td>';
dac786f3 292 $this->output_edit_single_table($category, $page);
516cf3eb 293 echo '</td></tr></table>';
294 echo '<p><div align="center"><form action="category.php" method="get">
5bff81ab 295 <div>
516cf3eb 296 <input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />
dac786f3 297 <input type="hidden" name="id" value="' . $COURSE->id . '" />
09275894 298 <input type="submit" value="' . $this->str->cancel . '" />
5bff81ab 299 </div>
09275894 300 </form>
301 </div></p>';
dac786f3 302 print_footer($COURSE);
516cf3eb 303 exit;
304 } else {
dac786f3 305 error("Category $categoryid not found", "category.php?id={$COURSE->id}");
516cf3eb 306 }
307 }
308
bc649d80 309 /**
310 * Outputs a table to allow editing of an existing category
311 *
312 * @param object category
313 * @param int page current page
314 */
516cf3eb 315 function output_edit_single_table($category, $page=1) {
dac786f3 316 global $USER, $COURSE;
516cf3eb 317 $publishoptions[0] = get_string("no");
318 $publishoptions[1] = get_string("yes");
319 $strupdate = get_string('update');
320
4abc23b2 321 $edittable = new stdClass;
516cf3eb 322
323 $edittable->head = array ($this->str->parent, $this->str->category, $this->str->categoryinfo, $this->str->publish, $this->str->action);
324 $edittable->width = 200;
325 $edittable->data[] = array();
326 $edittable->tablealign = 'center';
327
328 /// Each section below adds a data cell to the table row
329
330 $viableparents = $this->categorystrings;
331 $this->set_viable_parents($viableparents, $category);
332 $viableparents = array(0=>$this->str->top) + $viableparents;
333 $edittable->align['parent'] = "left";
334 $edittable->wrap['parent'] = "nowrap";
335 $row['parent'] = choose_from_menu ($viableparents, "updateparent", "{$category->parent}", "", "", "", true);
336
337 $edittable->align['category'] = "left";
338 $edittable->wrap['category'] = "nowrap";
6ba65fa0 339 $row['category'] = '<input type="text" name="updatename" value="' . format_string($category->name) . '" size="15" />';
516cf3eb 340
341 $edittable->align['info'] = "left";
342 $edittable->wrap['info'] = "nowrap";
343 $row['info'] = '<input type="text" name="updateinfo" value="' . $category->info . '" size="50" />';
344
345 $edittable->align['publish'] = "left";
346 $edittable->wrap['publish'] = "nowrap";
347 $selected = (boolean)$category->publish ? 1 : 0;
348 $row['publish'] = choose_from_menu ($publishoptions, "updatepublish", $selected, "", "", "", true);
349
350 $edittable->align['action'] = "left";
351 $edittable->wrap['action'] = "nowrap";
352 $row['action'] = '<input type="submit" value="' . $strupdate . '" />';
353
354 $edittable->data[] = $row;
355
356 // wrap the table in a form and output it
357 echo '<p><form action="category.php" method="post">';
09275894 358 echo '<fieldset class="invisiblefieldset">';
516cf3eb 359 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
dac786f3 360 echo '<input type="hidden" name="id" value="'. $COURSE->id . '" />';
516cf3eb 361 echo '<input type="hidden" name="updateid" value="' . $category->id . '" />';
362 echo "<input type=\"hidden\" name=\"page\" value=\"$page\" />";
363 print_table($edittable);
09275894 364 echo '</fieldset>';
516cf3eb 365 echo '</form></p>';
366 }
367
bc649d80 368 /**
369 * Creates an array of "full-path" category strings
370 * Structure:
371 * key => string
372 * where key is the category id, and string contains the name of all ancestors as well as the particular category name
373 * E.g. '123'=>'Language / English / Grammar / Modal Verbs"
374 *
375 * @param array $categories an array containing categories arranged in a tree structure
376 */
516cf3eb 377 function expanded_category_strings($categories, $parent=null) {
378 $prefix = is_null($parent) ? '' : "$parent / ";
379 $categorystrings = array();
380 foreach ($categories as $key => $category) {
381 $expandedname = "$prefix$category->name";
382 $categorystrings[$key] = $expandedname;
383 if (isset($category->children)) {
384 $categorystrings = $categorystrings + $this->expanded_category_strings($category->children, $expandedname);
385 }
386 }
387 return $categorystrings;
388 }
389
516cf3eb 390
bc649d80 391 /**
392 * Sets the viable parents
393 *
394 * Viable parents are any except for the category itself, or any of it's descendants
395 * The parentstrings parameter is passed by reference and changed by this function.
396 *
397 * @param array parentstrings a list of parentstrings
398 * @param object category
399 */
516cf3eb 400 function set_viable_parents(&$parentstrings, $category) {
401
402 unset($parentstrings[$category->id]);
403 if (isset($category->children)) {
404 foreach ($category->children as $child) {
405 $this->set_viable_parents($parentstrings, $child);
406 }
407 }
408 }
409
bc649d80 410 /**
411 * Gets question categories
412 *
413 * @param int parent - if given, restrict records to those with this parent id.
414 * @param string sort - [[sortfield [,sortfield]] {ASC|DESC}]
415 * @return array categories
416 */
dc1f00de 417 function get_question_categories($parent=null, $sort="sortorder ASC") {
dac786f3 418 global $COURSE;
516cf3eb 419 if (is_null($parent)) {
dac786f3 420 $categories = get_records('question_categories', 'course', "{$COURSE->id}", $sort);
516cf3eb 421 } else {
dac786f3 422 $select = "parent = '$parent' AND course = '{$COURSE->id}'";
dc1f00de 423 $categories = get_records_select('question_categories', $select, $sort);
516cf3eb 424 }
425 return $categories;
426 }
427
bc649d80 428 /**
429 * Deletes an existing question category
430 *
431 * @param int deletecat id of category to delete
432 * @param int destcategoryid id of category which will inherit the orphans of deletecat
433 */
516cf3eb 434 function delete_category($deletecat, $destcategoryid = null) {
dac786f3 435 global $USER, $COURSE;
516cf3eb 436
dc1f00de 437 if (!$category = get_record("question_categories", "id", $deletecat)) { // security
dac786f3 438 error("No such category $deletecat!", "category.php?id={$COURSE->id}");
516cf3eb 439 }
440
441 if (!is_null($destcategoryid)) { // Need to move some questions before deleting the category
dc1f00de 442 if (!$category2 = get_record("question_categories", "id", $destcategoryid)) { // security
dac786f3 443 error("No such category $destcategoryid!", "category.php?id={$COURSE->id}");
516cf3eb 444 }
4abc23b2 445 if (! set_field('question', 'category', $destcategoryid, 'category', $deletecat)) {
dac786f3 446 error("Error while moving questions from category '" . format_string($category->name) . "' to '$category2->name'", "category.php?id={$COURSE->id}");
516cf3eb 447 }
448
449 } else {
450 // todo: delete any hidden questions that are not actually in use any more
4f48fb42 451 if ($count = count_records("question", "category", $category->id)) {
4abc23b2 452 $vars = new stdClass;
516cf3eb 453 $vars->name = $category->name;
454 $vars->count = $count;
455 print_simple_box(get_string("categorymove", "quiz", $vars), "center");
456 $this->initialize();
457 $categorystrings = $this->categorystrings;
458 unset ($categorystrings[$category->id]);
459 echo "<p><div align=\"center\"><form action=\"category.php\" method=\"get\">";
09275894 460 echo '<fieldset class="invisiblefieldset">';
516cf3eb 461 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
dac786f3 462 echo "<input type=\"hidden\" name=\"id\" value=\"{$COURSE->id}\" />";
516cf3eb 463 echo "<input type=\"hidden\" name=\"delete\" value=\"$category->id\" />";
464 choose_from_menu($categorystrings, "confirm", "", "");
465 echo "<input type=\"submit\" value=\"". get_string("categorymoveto", "quiz") . "\" />";
466 echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->str->cancel}\" />";
09275894 467 echo '</fieldset>';
516cf3eb 468 echo "</form></div></p>";
dac786f3 469 print_footer($COURSE);
516cf3eb 470 exit;
471 }
472 }
516cf3eb 473
474 /// Send the children categories to live with their grandparent
dc1f00de 475 if ($childcats = get_records("question_categories", "parent", $category->id)) {
516cf3eb 476 foreach ($childcats as $childcat) {
dc1f00de 477 if (! set_field("question_categories", "parent", $category->parent, "id", $childcat->id)) {
dac786f3 478 error("Could not update a child category!", "category.php?id={$COURSE->id}");
516cf3eb 479 }
480 }
481 }
482
483 /// Finally delete the category itself
dc1f00de 484 if (delete_records("question_categories", "id", $category->id)) {
6ba65fa0 485 notify(get_string("categorydeleted", "quiz", format_string($category->name)), 'notifysuccess');
516cf3eb 486 }
487 }
488
bc649d80 489 /**
490 * Moves a category up or down in the display order
491 *
492 * @param string direction up|down
493 * @param int categoryid id of category to move
494 */
516cf3eb 495 function move_category_up_down ($direction, $categoryid) {
496 /// Move a category up or down
497 $swapcategory = NULL;
498 $movecategory = NULL;
499
500 if ($direction == 'up') {
dc1f00de 501 if ($movecategory = get_record("question_categories", "id", $categoryid)) {
502 $categories = $this->get_question_categories("$movecategory->parent", 'parent, sortorder, name');
516cf3eb 503
504 foreach ($categories as $category) {
505 if ($category->id == $movecategory->id) {
506 break;
507 }
508 $swapcategory = $category;
509 }
510 }
511 }
512 if ($direction == 'down') {
dc1f00de 513 if ($movecategory = get_record("question_categories", "id", $categoryid)) {
514 $categories = $this->get_question_categories("$movecategory->parent", 'parent, sortorder, name');
516cf3eb 515 $choosenext = false;
516 foreach ($categories as $category) {
517 if ($choosenext) {
518 $swapcategory = $category;
519 break;
520 }
521 if ($category->id == $movecategory->id) {
522 $choosenext = true;
523 }
524 }
525 }
526 }
527 if ($swapcategory and $movecategory) { // Renumber everything for robustness
528 $count=0;
529 foreach ($categories as $category) {
530 $count++;
531 if ($category->id == $swapcategory->id) {
532 $category = $movecategory;
533 } else if ($category->id == $movecategory->id) {
534 $category = $swapcategory;
535 }
dc1f00de 536 if (! set_field("question_categories", "sortorder", $count, "id", $category->id)) {
516cf3eb 537 notify("Could not update that category!");
538 }
539 }
540 }
541 }
542
bc649d80 543 /**
544 * Changes the parent of a category
545 *
546 * @param int categoryid
547 * @param int parentid
548 */
516cf3eb 549 function move_category($categoryid, $parentid) {
550 /// Move a category to a new parent
551
dc1f00de 552 if ($tempcat = get_record("question_categories", "id", $categoryid)) {
516cf3eb 553 if ($tempcat->parent != $parentid) {
dc1f00de 554 if (! set_field("question_categories", "parent", $parentid, "id", $tempcat->id)) {
516cf3eb 555 notify("Could not update that category!");
556 }
557 }
558 }
559 }
560
bc649d80 561 /**
562 * Changes the published status of a category
563 *
564 * @param boolean publish
565 * @param int categoryid
566 */
516cf3eb 567 function publish_category($publish, $categoryid) {
568 /// Hide or publish a category
569
570 $publish = ($publish == false) ? 0 : 1;
dc1f00de 571 $tempcat = get_record("question_categories", "id", $categoryid);
516cf3eb 572 if ($tempcat) {
dc1f00de 573 if (! set_field("question_categories", "publish", $publish, "id", $tempcat->id)) {
516cf3eb 574 notify("Could not update that category!");
575 }
576 }
577 }
578
bc649d80 579 /**
580 * Creates a new category with given params
581 *
582 * @param int $newparent id of the parent category
583 * @param string $newcategory the name for the new category
584 * @param string $newinfo the info field for the new category
585 * @param int $newpublish whether to publish the category
586 * @param int $newcourse the id of the associated course
587 */
516cf3eb 588 function add_category($newparent, $newcategory, $newinfo, $newpublish, $newcourse) {
bc649d80 589 if (empty($newcategory)) {
590 notify(get_string('categorynamecantbeblank', 'quiz'), 'notifyproblem');
591 return false;
592 }
516cf3eb 593
594 if ($newparent) {
595 // first check that the parent category is in the correct course
dc1f00de 596 if(!(get_field('question_categories', 'course', 'id', $newparent) == $newcourse)) {
516cf3eb 597 return false;
598 }
599 }
600
601 $cat = NULL;
602 $cat->parent = $newparent;
603 $cat->name = $newcategory;
604 $cat->info = $newinfo;
605 $cat->publish = $newpublish;
606 $cat->course = $newcourse;
607 $cat->sortorder = 999;
608 $cat->stamp = make_unique_id_code();
dc1f00de 609 if (!insert_record("question_categories", $cat)) {
f5565b69 610 error("Could not insert the new question category '$newcategory'", "category.php?id={$newcourse}");
516cf3eb 611 } else {
bc649d80 612 notify(get_string("categoryadded", "quiz", $newcategory), 'notifysuccess');
516cf3eb 613 }
516cf3eb 614 }
615
bc649d80 616 /**
617 * Updates an existing category with given params
618 *
619 * @param int updateid
620 * @param int updateparent
621 * @param string updatename
622 * @param string updateinfo
623 * @param int updatepublish
624 * @param int courseid the id of the associated course
625 */
516cf3eb 626 function update_category($updateid, $updateparent, $updatename, $updateinfo, $updatepublish, $courseid) {
bc649d80 627 if (empty($updatename)) {
628 notify(get_string('categorynamecantbeblank', 'quiz'), 'notifyproblem');
629 return false;
630 }
516cf3eb 631
632 $cat = NULL;
633 $cat->id = $updateid;
634 $cat->parent = $updateparent;
635 $cat->name = $updatename;
636 $cat->info = $updateinfo;
637 $cat->publish = $updatepublish;
dc1f00de 638 if (!update_record("question_categories", $cat)) {
516cf3eb 639 error("Could not update the category '$updatename'", "category.php?id={$courseid}");
640 } else {
bc649d80 641 notify(get_string("categoryupdated", 'quiz'), 'notifysuccess');
516cf3eb 642 }
643 }
516cf3eb 644}
645
646?>