id); if (!isteacher($course->id)) { error("Only teachers can use this page!"); } /// Print headings $strcategory = get_string("category", "quiz"); $strcategoryinfo = get_string("categoryinfo", "quiz"); $strquestions = get_string("questions", "quiz"); $strpublish = get_string("publish", "quiz"); $strdelete = get_string("delete"); $straction = get_string("action"); $stradd = get_string("add"); $strcancel = get_string("cancel"); $strsavechanges = get_string("savechanges"); $strbacktoquiz = get_string("backtoquiz", "quiz"); $streditingquiz = get_string(isset($modform->instance) ? "editingquiz" : "editquestions", "quiz"); $streditcategories = get_string("editcategories", "quiz"); print_header("$course->shortname: $streditcategories", "$course->shortname: $streditcategories", "wwwroot/course/view.php?id=$course->id\">$course->shortname -> $streditingquiz -> $streditcategories"); /// Delete category if the user wants to delete it if (isset($delete) and !isset($cancel)) { if (!$category = get_record("quiz_categories", "id", $delete)) { // security error("No such category $delete!"); } if (isset($confirm)) { // Need to move some questions before deleting the category if (!$category2 = get_record("quiz_categories", "id", $confirm)) { // security error("No such category $confirm!"); } if (! quiz_move_questions($category->id, $category2->id)) { error("Error while moving questions from category '$category->name' to '$category2->name'"); } } else { if ($count = count_records("quiz_questions", "category", $category->id)) { $vars->name = $category->name; $vars->count = $count; print_simple_box(get_string("categorymove", "quiz", $vars), "CENTER"); $categories = quiz_get_category_menu($course->id); unset($categories[$category->id]); echo "
"; echo $streditcategories; helpbutton("categories", $streditcategories, "quiz"); echo "
"; /// If data submitted, then process and store. if ($form = data_submitted()) { $form = (array)$form; // Peel out all the data from variable names. foreach ($form as $key => $val) { $cat = NULL; if ($key == "new" and $val != "") { $cat->name = $val; $cat->info = $form['newinfo']; $cat->publish = $form['newpublish']; $cat->course = $course->id; $cat->stamp = make_unique_id_code(); if (!insert_record("quiz_categories", $cat)) { error("Could not insert the new quiz category '$val'"); } else { notify(get_string("categoryadded", "", $val)); } } else if (substr($key,0,1) == "c") { $cat->id = substr($key,1); $cat->name = $val; $cat->info = $form["i$cat->id"]; $cat->publish = $form["p$cat->id"]; $cat->course = $course->id; if (!update_record("quiz_categories", $cat)) { error("Could not update the quiz category '$val'"); } } } } /// Get the existing categories if (!$categories = get_records("quiz_categories", "course", $course->id, "id ASC")) { unset($categories); if (!$categories[] = quiz_get_default_category($course->id)) { error("Error: Could not find or make a category!"); } } /// Find lowest ID category - this is the default category $default = 99999; foreach ($categories as $category) { if ($category->id < $default) { $default = $category->id; } } $publishoptions[0] = get_string("no"); $publishoptions[1] = get_string("yes"); /// Print the table of all categories $table->head = array ($strcategory, $strcategoryinfo, $strpublish, $strquestions, $straction); $table->align = array ("LEFT", "LEFT", "CENTER", "CENTER", "CENTER"); $table->size = array ("80", "80", "40", "40", "50"); $table->width = 200; $table->nowrap = true; echo ""; print_footer(); ?>