course)) { error("Course is misconfigured"); } if (! $glossary = get_record("glossary", "id", $cm->instance)) { error("Course module is incorrect"); } if ($hook > 0) { if ($category = get_record("glossary_categories","id",$hook)) { //Check it belongs to the same glossary if ($category->glossaryid != $glossary->id) { error("Glossary is incorrect"); } } else { error("Category is incorrect"); } } require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('mod/glossary:managecategories', $context); $strglossaries = get_string("modulenameplural", "glossary"); $strglossary = get_string("modulename", "glossary"); $navlinks = array(); $navlinks[] = array('name' => $strglossaries, 'link' => "index.php?id=$course->id", 'type' => 'activity'); $navlinks[] = array('name' => format_string($glossary->name), 'link' => "view.php?id=$cm->id&tab=GLOSSARY_CATEGORY_VIEW", 'type' => 'activityinstance'); $navlinks[] = array('name' => get_string("categories","glossary"), 'link' => '', 'type' => 'title'); $navigation = build_navigation($navlinks); print_header_simple(format_string($glossary->name), "", $navigation, "", "", true, update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm)); if ( $hook >0 ) { if ( $action == "edit" ) { if ( $confirm ) { $action = ""; $cat->id = $hook; $cat->name = $name; $cat->usedynalink = $usedynalink; if ( !update_record("glossary_categories", $cat) ) { error("Weird error. The category was not updated."); redirect("editcategories.php?id=$cm->id"); } else { add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id); } } else { echo "

" . get_string("edit"). " " . get_string("category","glossary") . ""; $name = $category->name; $usedynalink = $category->usedynalink; require "editcategories.html"; print_footer(); die; } } elseif ( $action == "delete" ) { if ( $confirm ) { delete_records("glossary_entries_categories","categoryid", $hook); delete_records("glossary_categories","id", $hook); print_simple_box_start("center","40%", "#FFBBBB"); echo "

" . get_string("categorydeleted","glossary") ."
"; echo ""; print_simple_box_end(); print_footer($course); add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id); redirect("editcategories.php?id=$cm->id"); } else { echo "

" . get_string("delete"). " " . get_string("category","glossary"). "

"; print_simple_box_start("center","40%", "#FFBBBB"); echo "
".format_text($category->name, FORMAT_PLAIN)."
"; $num_entries = count_records("glossary_entries_categories","categoryid",$category->id); if ( $num_entries ) { print_string("deletingnoneemptycategory","glossary"); } echo "

"; print_string("areyousuredelete","glossary"); echo "

"; ?>
" />
$id); print_single_button("editcategories.php", $options, get_string("no") ); echo "
"; echo "
"; print_simple_box_end(); } } } elseif ( $action == "add" ) { if ( $confirm ) { $ILIKE = sql_ilike(); $dupcategory = get_records_sql("SELECT * FROM {$CFG->prefix}glossary_categories WHERE name $ILIKE '$name' AND glossaryid=$glossary->id"); if ( $dupcategory ) { echo "

" . get_string("add"). " " . get_string("category","glossary"); print_simple_box_start("center","40%", "#FFBBBB"); echo "

" . get_string("duplicatedcategory","glossary") ."
"; print_simple_box_end(); redirect("editcategories.php?id=$cm->id&action=add&&name=$name"); } else { $action = ""; $cat->name = $name; $cat->usedynalink = $usedynalink; $cat->glossaryid = $glossary->id; if ( ! $cat->id = insert_record("glossary_categories", $cat) ) { error("Weird error. The category was not inserted."); redirect("editcategories.php?id=$cm->id"); } else { add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id,$cm->id); } } } else { echo "

" . get_string("add"). " " . get_string("category","glossary"). "

"; $name=""; require "editcategories.html"; } } if ( $action ) { print_footer(); die; } ?>
id,"name ASC"); if ( $categories ) { echo ''; foreach ($categories as $category) { $num_entries = count_records("glossary_entries_categories","categoryid",$category->id); ?> '; } ?>
".format_text($category->name, FORMAT_PLAIN)." ($num_entries " . get_string("entries","glossary") . ")"; ?> id&action=delete&mode=cat&hook=$category->id\">\""pixpath}/t/delete.gif\" class=\"iconsmall\" /> "; echo "id&action=edit&mode=cat&hook=$category->id\">\""pixpath}/t/edit.gif\" class=\"iconsmall\" />"; ?>
id; $options['action'] = "add"; echo ""; echo "
"; echo print_single_button("editcategories.php", $options, get_string("add") . " " . get_string("category","glossary"), "get"); echo ""; unset($options['action']); $options['mode'] = 'cat'; $options['hook'] = $hook; echo print_single_button("view.php", $options, get_string("back","glossary") ); echo "
"; ?>