$id)); if ($usedynalink !== 0) { $url->param('usedynalink', $usedynalink); } if ($confirm !== 0) { $url->param('confirm', $confirm); } if ($name !== 'name') { $url->param('name', $name); } if ($action !== 'action') { $url->param('action', $action); } if ($hook !== 'hook') { $url->param('hook', $hook); } if ($mode !== 'mode') { $url->param('mode', $mode); } $PAGE->set_url($url); if (! $cm = get_coursemodule_from_id('glossary', $id)) { print_error('invalidcoursemodule'); } if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { print_error('coursemisconf'); } if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { print_error('invalidcoursemodule'); } if ($hook > 0) { if ($category = $DB->get_record("glossary_categories", array("id"=>$hook))) { //Check it belongs to the same glossary if ($category->glossaryid != $glossary->id) { print_error('invalidid', 'glossary'); } } else { print_error('invalidcategoryid'); } } require_login($course, false, $cm); $context = context_module::instance($cm->id); require_capability('mod/glossary:managecategories', $context); $strglossaries = get_string("modulenameplural", "glossary"); $strglossary = get_string("modulename", "glossary"); $PAGE->navbar->add(get_string("categories","glossary"), new moodle_url('/mod/glossary/editcategories.php', array('id' => $cm->id,'mode' => 'cat'))); if (!empty($action)) { $navaction = get_string(core_text::strtolower($action."category"), 'glossary'); $PAGE->navbar->add($navaction); } $PAGE->set_title($glossary->name); $PAGE->set_heading($course->fullname); // Prepare format_string/text options $fmtoptions = array( 'context' => $context); if (right_to_left()) { // RTL table alignment support $rightalignment = 'left'; $leftalignment = 'right'; } else { $rightalignment = 'right'; $leftalignment = 'left'; } if ( $hook >0 ) { if ( $action == "edit" ) { if ( $confirm ) { require_sesskey(); $action = ""; $cat = new stdClass(); $cat->id = $hook; $cat->name = $name; $cat->usedynalink = $usedynalink; $DB->update_record("glossary_categories", $cat); $event = \mod_glossary\event\category_updated::create(array( 'context' => $context, 'objectid' => $hook )); $cat->glossaryid = $glossary->id; $event->add_record_snapshot('glossary_categories', $cat); $event->add_record_snapshot('glossary', $glossary); $event->trigger(); // Reset caches. \mod_glossary\local\concept_cache::reset_glossary($glossary); } else { echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($glossary->name), 2); echo $OUTPUT->heading(format_string(get_string("editcategory", "glossary")), 3); $name = $category->name; $usedynalink = $category->usedynalink; require "editcategories.html"; echo $OUTPUT->footer(); die; } } elseif ( $action == "delete" ) { if ( $confirm ) { require_sesskey(); $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook)); $DB->delete_records("glossary_categories", array("id"=>$hook)); $event = \mod_glossary\event\category_deleted::create(array( 'context' => $context, 'objectid' => $hook )); $event->add_record_snapshot('glossary_categories', $category); $event->add_record_snapshot('glossary', $glossary); $event->trigger(); // Reset caches. \mod_glossary\local\concept_cache::reset_glossary($glossary); redirect("editcategories.php?id=$cm->id", get_string("categorydeleted", "glossary"), 2); } else { echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($glossary->name), 2); echo $OUTPUT->heading(format_string(get_string("deletecategory", "glossary")), 3); echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow'); echo "
".format_string($category->name, true, $fmtoptions)."
"; $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id)); if ( $num_entries ) { print_string("deletingnoneemptycategory","glossary"); } echo "

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

"; ?>
" />
$id); echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("no")); echo "
"; echo "
"; echo $OUTPUT->box_end(); } } } elseif ( $action == "add" ) { if ( $confirm ) { require_sesskey(); $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE ".$DB->sql_like('name','?', false)." AND glossaryid=?", array($name, $glossary->id)); if ( $dupcategory ) { redirect("editcategories.php?id=$cm->id&action=add&name=$name", get_string("duplicatecategory", "glossary"), 2); } else { $action = ""; $cat = new stdClass(); $cat->name = $name; $cat->usedynalink = $usedynalink; $cat->glossaryid = $glossary->id; $cat->id = $DB->insert_record("glossary_categories", $cat); $event = \mod_glossary\event\category_created::create(array( 'context' => $context, 'objectid' => $cat->id )); $event->add_record_snapshot('glossary_categories', $cat); $event->add_record_snapshot('glossary', $glossary); $event->trigger(); // Reset caches. \mod_glossary\local\concept_cache::reset_glossary($glossary); } } else { echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($glossary->name), 2); echo "

" . get_string("addcategory", "glossary"). "

"; $name=""; require "editcategories.html"; } } if ( $action ) { echo $OUTPUT->footer(); die; } echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($glossary->name), 2); ?>
get_records("glossary_categories", array("glossaryid"=>$glossary->id), "name ASC"); if ( $categories ) { echo ''; foreach ($categories as $category) { $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id)); ?> '; } ?>
".format_string($category->name, true, $fmtoptions)." ($num_entries " . get_string("entries","glossary") . ")"; ?> id&action=delete&mode=cat&hook=$category->id\">" . $OUTPUT->pix_icon('t/delete', get_string('delete')). " "; echo "id&action=edit&mode=cat&hook=$category->id\">" . $OUTPUT->pix_icon('t/edit', get_string('edit')). " "; ?>
id; $options['action'] = "add"; echo ""; echo "
"; echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("addcategory", "glossary")); echo ""; unset($options['action']); $options['mode'] = 'cat'; $options['hook'] = $hook; echo $OUTPUT->single_button(new moodle_url("view.php", $options), get_string("back","glossary")); echo "
"; ?>
footer();