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 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
20 error("Course Module ID was incorrect");
23 if (! $course = get_record("course", "id", $cm->course
)) {
24 error("Course is misconfigured");
27 if (! $glossary = get_record("glossary", "id", $cm->instance
)) {
28 error("Course module is incorrect");
32 if ($category = get_record("glossary_categories","id",$hook)) {
33 //Check it belongs to the same glossary
34 if ($category->glossaryid
!= $glossary->id
) {
35 error("Glossary is incorrect");
38 error("Category is incorrect");
42 require_login($course->id
, false, $cm);
44 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
45 require_capability('mod/glossary:managecategories', $context);
47 $strglossaries = get_string("modulenameplural", "glossary");
48 $strglossary = get_string("modulename", "glossary");
51 $navlinks[] = array('name' => $strglossaries, 'link' => "index.php?id=$course->id", 'type' => 'activity');
52 $navlinks[] = array('name' => format_string($glossary->name
), 'link' => "view.php?id=$cm->id&tab=GLOSSARY_CATEGORY_VIEW", 'type' => 'activityinstance');
53 $navlinks[] = array('name' => get_string("categories","glossary"), 'link' => '', 'type' => 'title');
55 $navigation = build_navigation($navlinks);
57 print_header_simple(format_string($glossary->name
), "", $navigation,
58 "", "", true, update_module_button($cm->id
, $course->id
, $strglossary),
59 navmenu($course, $cm));
63 if ( $action == "edit" ) {
68 $cat->usedynalink
= $usedynalink;
70 if ( !update_record("glossary_categories", $cat) ) {
71 error("Weird error. The category was not updated.");
72 redirect("editcategories.php?id=$cm->id");
74 add_to_log($course->id
, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id
);
77 echo "<p style=\"text-align:center\">" . get_string("edit"). " " . get_string("category","glossary") . "<span style=\"font-size:1.5em\">";
79 $name = $category->name
;
80 $usedynalink = $category->usedynalink
;
81 require "editcategories.html";
86 } elseif ( $action == "delete" ) {
88 delete_records("glossary_entries_categories","categoryid", $hook);
89 delete_records("glossary_categories","id", $hook);
91 print_simple_box_start("center","40%", "#FFBBBB");
92 echo "<div style=\"text-align:center\">" . get_string("categorydeleted","glossary") ."</div>";
94 print_simple_box_end();
95 print_footer($course);
97 add_to_log($course->id
, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id
);
99 redirect("editcategories.php?id=$cm->id");
101 echo "<p style=\"text-align:center\">" . get_string("delete"). " " . get_string("category","glossary"). "</p>";
103 print_simple_box_start("center","40%", "#FFBBBB");
104 echo "<div class=\"boxaligncenter\"><b>".format_text($category->name
, FORMAT_PLAIN
)."</b><br/>";
106 $num_entries = count_records("glossary_entries_categories","categoryid",$category->id
);
107 if ( $num_entries ) {
108 print_string("deletingnoneemptycategory","glossary");
111 print_string("areyousuredelete","glossary");
115 <table border
="0" width
="100">
117 <td align
="right" style
="width:50%">
118 <form id
="form" method
="post" action
="editcategories.php">
120 <input type
="hidden" name
="id" value
="<?php p($cm->id) ?>" />
121 <input type
="hidden" name
="action" value
="delete" />
122 <input type
="hidden" name
="confirm" value
="1" />
123 <input type
="hidden" name
="mode" value
="<?php echo $mode ?>" />
124 <input type
="hidden" name
="hook" value
="<?php echo $hook ?>" />
125 <input type
="submit" value
=" <?php print_string("yes
")?> " />
129 <td align
="left" style
="width:50%">
133 $options = array ("id" => $id);
134 print_single_button("editcategories.php", $options, get_string("no") );
135 echo "</td></tr></table>";
137 print_simple_box_end();
141 } elseif ( $action == "add" ) {
143 $ILIKE = sql_ilike();
144 $dupcategory = get_records_sql("SELECT * FROM {$CFG->prefix}glossary_categories WHERE name $ILIKE '$name' AND glossaryid=$glossary->id");
145 if ( $dupcategory ) {
146 echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary");
148 print_simple_box_start("center","40%", "#FFBBBB");
149 echo "<div style=\"text-align:center\">" . get_string("duplicatedcategory","glossary") ."</div>";
150 print_simple_box_end();
152 redirect("editcategories.php?id=$cm->id&action=add&&name=$name");
157 $cat->usedynalink
= $usedynalink;
158 $cat->glossaryid
= $glossary->id
;
160 if ( ! $cat->id
= insert_record("glossary_categories", $cat) ) {
161 error("Weird error. The category was not inserted.");
163 redirect("editcategories.php?id=$cm->id");
165 add_to_log($course->id
, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id
,$cm->id
);
169 echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary"). "</p>";
171 require "editcategories.html";
182 <form method
="post" action
="editcategories.php">
183 <table width
="40%" class="boxaligncenter generalbox" cellpadding
="5">
185 <td style
="width:90%" align
="center"><b
>
186 <?php
p(get_string("categories","glossary")) ?
></b
></td
>
187 <td style
="width:10%" align
="center"><b
>
188 <?php
p(get_string("action")) ?
></b
></td
>
190 <tr
><td style
="width:100%" colspan
="2">
195 $categories = get_records("glossary_categories","glossaryid",$glossary->id
,"name ASC");
198 echo '<table width="100%">';
199 foreach ($categories as $category) {
200 $num_entries = count_records("glossary_entries_categories","categoryid",$category->id
);
204 <td style
="width:90%" align
="left">
206 echo "<b>".format_text($category->name
, FORMAT_PLAIN
)."</b> <span style=\"font-size:0.75em\">($num_entries " . get_string("entries","glossary") . ")</span>";
209 <td style
="width:10%" align
="center"><b
>
211 echo "<a href=\"editcategories.php?id=$cm->id&action=delete&mode=cat&hook=$category->id\"><img alt=\"" . get_string("delete") . "\"src=\"../../pix/t/delete.gif\" class=\"iconsmall\" /></a> ";
212 echo "<a href=\"editcategories.php?id=$cm->id&action=edit&mode=cat&hook=$category->id\"><img alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" class=\"iconsmall\" /></a>";
226 <td style
="width:100%" colspan
="2" align
="center">
229 $options['id'] = $cm->id
;
230 $options['action'] = "add";
232 echo "<table border=\"0\"><tr><td align=\"right\">";
233 echo print_single_button("editcategories.php", $options, get_string("add") . " " . get_string("category","glossary"), "get");
234 echo "</td><td align=\"left\">";
235 unset($options['action']);
236 $options['mode'] = 'cat';
237 $options['hook'] = $hook;
238 echo print_single_button("view.php", $options, get_string("back","glossary") );
250 <?php
print_footer() ?
>