3 /// This page allows to edit entries categories for a particular instance of glossary
5 require_once("../../config.php");
6 require_once("lib.php");
8 $id = required_param('id', PARAM_INT
); // Course Module ID, or
9 $usedynalink = optional_param('usedynalink', 0, PARAM_INT
); // category ID
10 $confirm = optional_param('confirm', 0, PARAM_INT
); // confirm the action
11 $name = optional_param('name', '', PARAM_CLEAN
); // confirm the name
13 $action = optional_param('action', '', PARAM_ALPHA
); // what to do
14 $hook = optional_param('hook', '', PARAM_ALPHANUM
); // category ID
15 $mode = optional_param('mode', '', PARAM_ALPHA
); // cat
17 $action = strtolower($action);
19 $url = new moodle_url('/mod/glossary/editcategories.php', array('id'=>$id));
20 if ($usedynalink !== 0) {
21 $url->param('usedynalink', $usedynalink);
24 $url->param('confirm', $confirm);
26 if ($name !== 'name') {
27 $url->param('name', $name);
29 if ($action !== 'action') {
30 $url->param('action', $action);
32 if ($hook !== 'hook') {
33 $url->param('hook', $hook);
35 if ($mode !== 'mode') {
36 $url->param('mode', $mode);
41 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
42 print_error('invalidcoursemodule');
45 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
46 print_error('coursemisconf');
49 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance
))) {
50 print_error('invalidcoursemodule');
54 if ($category = $DB->get_record("glossary_categories", array("id"=>$hook))) {
55 //Check it belongs to the same glossary
56 if ($category->glossaryid
!= $glossary->id
) {
57 print_error('invalidid', 'glossary');
60 print_error('invalidcategoryid');
64 require_login($course, false, $cm);
66 $context = context_module
::instance($cm->id
);
67 require_capability('mod/glossary:managecategories', $context);
69 $strglossaries = get_string("modulenameplural", "glossary");
70 $strglossary = get_string("modulename", "glossary");
72 $PAGE->navbar
->add(get_string("categories","glossary"),
73 new moodle_url('/mod/glossary/editcategories.php', array('id' => $cm->id
,'mode' => 'cat')));
74 if (!empty($action)) {
75 $navaction = get_string(core_text
::strtolower($action."category"), 'glossary');
76 $PAGE->navbar
->add($navaction);
78 $PAGE->set_title($glossary->name
);
79 $PAGE->set_heading($course->fullname
);
81 // Prepare format_string/text options
83 'context' => $context);
85 if (right_to_left()) { // RTL table alignment support
86 $rightalignment = 'left';
87 $leftalignment = 'right';
89 $rightalignment = 'right';
90 $leftalignment = 'left';
96 if ( $action == "edit" ) {
100 $cat = new stdClass();
103 $cat->usedynalink
= $usedynalink;
105 $DB->update_record("glossary_categories", $cat);
106 $event = \mod_glossary\event\category_updated
::create(array(
107 'context' => $context,
110 $cat->glossaryid
= $glossary->id
;
111 $event->add_record_snapshot('glossary_categories', $cat);
112 $event->add_record_snapshot('glossary', $glossary);
116 \mod_glossary\local\concept_cache
::reset_glossary($glossary);
119 echo $OUTPUT->header();
120 echo $OUTPUT->heading(format_string($glossary->name
), 2);
121 echo $OUTPUT->heading(format_string(get_string("editcategory", "glossary")), 3);
123 $name = $category->name
;
124 $usedynalink = $category->usedynalink
;
125 require "editcategories.html";
126 echo $OUTPUT->footer();
130 } elseif ( $action == "delete" ) {
133 $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
134 $DB->delete_records("glossary_categories", array("id"=>$hook));
136 $event = \mod_glossary\event\category_deleted
::create(array(
137 'context' => $context,
140 $event->add_record_snapshot('glossary_categories', $category);
141 $event->add_record_snapshot('glossary', $glossary);
145 \mod_glossary\local\concept_cache
::reset_glossary($glossary);
147 redirect("editcategories.php?id=$cm->id", get_string("categorydeleted", "glossary"), 2);
149 echo $OUTPUT->header();
150 echo $OUTPUT->heading(format_string($glossary->name
), 2);
151 echo $OUTPUT->heading(format_string(get_string("deletecategory", "glossary")), 3);
153 echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
154 echo "<div class=\"boxaligncenter deletecatconfirm\">".format_string($category->name
, true, $fmtoptions)."<br/>";
156 $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id
));
157 if ( $num_entries ) {
158 print_string("deletingnoneemptycategory","glossary");
161 print_string("areyousuredelete","glossary");
165 <table border
="0" width
="100" class="confirmbuttons">
167 <td align
="$rightalignment" style
="width:50%">
168 <form id
="form" method
="post" action
="editcategories.php">
170 <input type
="hidden" name
="sesskey" value
="<?php echo sesskey(); ?>" />
171 <input type
="hidden" name
="id" value
="<?php p($cm->id) ?>" />
172 <input type
="hidden" name
="action" value
="delete" />
173 <input type
="hidden" name
="confirm" value
="1" />
174 <input type
="hidden" name
="mode" value
="<?php echo $mode ?>" />
175 <input type
="hidden" name
="hook" value
="<?php echo $hook ?>" />
176 <input type
="submit" class="btn btn-primary" value
=" <?php print_string("yes
")?> " />
180 <td align
="$leftalignment" style
="width:50%">
184 $options = array ("id" => $id);
185 echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("no"));
186 echo "</td></tr></table>";
188 echo $OUTPUT->box_end();
192 } elseif ( $action == "add" ) {
195 $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE ".$DB->sql_like('name','?', false)." AND glossaryid=?", array($name, $glossary->id
));
196 if ( $dupcategory ) {
197 redirect("editcategories.php?id=$cm->id&action=add&name=$name", get_string("duplicatecategory", "glossary"), 2);
201 $cat = new stdClass();
203 $cat->usedynalink
= $usedynalink;
204 $cat->glossaryid
= $glossary->id
;
206 $cat->id
= $DB->insert_record("glossary_categories", $cat);
207 $event = \mod_glossary\event\category_created
::create(array(
208 'context' => $context,
209 'objectid' => $cat->id
211 $event->add_record_snapshot('glossary_categories', $cat);
212 $event->add_record_snapshot('glossary', $glossary);
216 \mod_glossary\local\concept_cache
::reset_glossary($glossary);
219 echo $OUTPUT->header();
220 echo $OUTPUT->heading(format_string($glossary->name
), 2);
221 echo "<h3 class=\"main\">" . get_string("addcategory", "glossary"). "</h3>";
223 require "editcategories.html";
228 echo $OUTPUT->footer();
232 echo $OUTPUT->header();
233 echo $OUTPUT->heading(format_string($glossary->name
), 2);
237 <form method
="post" action
="editcategories.php">
238 <table width
="40%" class="boxaligncenter generalbox" cellpadding
="5">
240 <th style
="width:90%" align
="center">
241 <?php
p(get_string("categories","glossary")) ?
></th
>
242 <th style
="width:10%" align
="center">
243 <?php
p(get_string("action")) ?
></th
>
245 <tr
><td style
="width:100%" colspan
="2">
250 $categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary->id
), "name ASC");
253 echo '<table width="100%">';
254 foreach ($categories as $category) {
255 $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id
));
259 <td style
="width:80%" align
="$leftalignment">
261 echo "<span class=\"bold\">".format_string($category->name
, true, $fmtoptions)."</span> <span>($num_entries " . get_string("entries","glossary") . ")</span>";
264 <td style
="width:19%" align
="center" class="action">
266 echo "<a href=\"editcategories.php?id=$cm->id&action=delete&mode=cat&hook=$category->id\">" .
267 $OUTPUT->pix_icon('t/delete', get_string('delete')). "</a> ";
268 echo "<a href=\"editcategories.php?id=$cm->id&action=edit&mode=cat&hook=$category->id\">" .
269 $OUTPUT->pix_icon('t/edit', get_string('edit')). "</a> ";
283 <td style
="width:100%" colspan
="2" align
="center">
286 $options['id'] = $cm->id
;
287 $options['action'] = "add";
289 echo "<table class=\"editbuttons\" border=\"0\"><tr><td align=\"$rightalignment\">";
290 echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("addcategory", "glossary"));
291 echo "</td><td align=\"$leftalignment\">";
292 unset($options['action']);
293 $options['mode'] = 'cat';
294 $options['hook'] = $hook;
295 echo $OUTPUT->single_button(new moodle_url("view.php", $options), get_string("back","glossary"));
308 echo $OUTPUT->footer();