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);
44 if ( !isteacher($course->id
) ) {
45 error("You must be a teacher to use this page.");
48 $strglossaries = get_string("modulenameplural", "glossary");
49 $strglossary = get_string("modulename", "glossary");
51 print_header_simple(format_string($glossary->name
), "",
52 "<a href=\"index.php?id=$course->id\">$strglossaries</a> -> <a href=\"view.php?id=$cm->id&tab=GLOSSARY_CATEGORY_VIEW\">".format_string($glossary->name
,true)."</a> -> " . get_string("categories","glossary"),
53 "", "", true, update_module_button($cm->id
, $course->id
, $strglossary),
54 navmenu($course, $cm));
58 if ( $action == "edit" ) {
63 $cat->usedynalink
= $usedynalink;
65 if ( !update_record("glossary_categories", $cat) ) {
66 error("Weird error. The category was not updated.");
67 redirect("editcategories.php?id=$cm->id");
69 add_to_log($course->id
, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id
);
72 echo "<p align=\"center\">" . get_string("edit"). " " . get_string("category","glossary") . "<font size=\"3\">";
74 $name = $category->name
;
75 $usedynalink = $category->usedynalink
;
76 require "editcategories.html";
81 } elseif ( $action == "delete" ) {
83 delete_records("glossary_entries_categories","categoryid", $hook);
84 delete_records("glossary_categories","id", $hook);
86 print_simple_box_start("center","40%", "#FFBBBB");
87 echo "<center>" . get_string("categorydeleted","glossary") ."</center>";
89 print_simple_box_end();
90 print_footer($course);
92 add_to_log($course->id
, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id
);
94 redirect("editcategories.php?id=$cm->id");
96 echo "<p align=\"center\">" . get_string("delete"). " " . get_string("category","glossary") . "<font size=\"3\">";
98 print_simple_box_start("center","40%", "#FFBBBB");
99 echo "<center><b>".format_text($category->name
)."</b><br>";
101 $num_entries = count_records("glossary_entries_categories","categoryid",$category->id
);
102 if ( $num_entries ) {
103 print_string("deletingnoneemptycategory","glossary");
106 print_string("areyousuredelete","glossary");
108 <form name
="form" method
="post" action
="editcategories.php">
110 <input type
="hidden" name
="id" value
="<?php p($cm->id) ?>" />
111 <input type
="hidden" name
="action" value
="delete" />
112 <input type
="hidden" name
="confirm" value
="1" />
113 <input type
="hidden" name
="mode" value
="<?php echo $mode ?>" />
114 <input type
="hidden" name
="hook" value
="<?php echo $hook ?>" />
115 <table border
="0" width
="100"><tr
><td align
="right" width
="50%" />
116 <input type
="submit" value
=" <?php print_string("yes
")?> " />
118 </td
><td align
="left" width
="50%">
122 $options = array ("id" => $id);
123 print_single_button("editcategories.php", $options, get_string("no") );
124 echo "</td></tr></table>";
126 print_simple_box_end();
130 } elseif ( $action == "add" ) {
132 $lcase = db_lowercase();
133 $dupcategory = get_record("glossary_categories","$lcase(name)",strtolower($name),"glossaryid",$glossary->id
);
134 if ( $dupcategory ) {
135 echo "<p align=\"center\">" . get_string("add"). " " . get_string("category","glossary") . "<font size=\"3\">";
137 print_simple_box_start("center","40%", "#FFBBBB");
138 echo "<center>" . get_string("duplicatedcategory","glossary") ."</center>";
140 print_simple_box_end();
142 print_footer($course);
144 redirect("editcategories.php?id=$cm->id&action=add&&name=$name");
149 $cat->usedynalink
= $usedynalink;
150 $cat->glossaryid
= $glossary->id
;
152 if ( ! $cat->id
= insert_record("glossary_categories", $cat) ) {
153 error("Weird error. The category was not inserted.");
155 redirect("editcategories.php?id=$cm->id");
157 add_to_log($course->id
, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id
,$cm->id
);
161 echo "<p align=\"center\">" . get_string("add"). " " . get_string("category","glossary") . "<font size=\"3\">";
163 require "editcategories.html";
177 <form name
="theform" method
="post" action
="editcategories.php">
178 <table width
="40%" class="generalbox" cellpadding
="5">
180 <td width
="90%" align
="center"><b
>
181 <?php
p(get_string("categories","glossary")) ?
></b
></td
>
182 <td width
="10%" align
="center"><b
>
183 <?php
p(get_string("action")) ?
></b
></td
>
185 <tr
><td width
="100%" colspan
="2">
190 $categories = get_records("glossary_categories","glossaryid",$glossary->id
,"name ASC");
193 foreach ($categories as $category) {
194 $num_entries = count_records("glossary_entries_categories","categoryid",$category->id
);
198 <td width
="90%" align
="left">
200 echo "<b>".format_text($category->name
)."</b> <font size=-1>($num_entries " . get_string("entries","glossary") . ")</font>";
203 <td width
="10%" align
="center"><b
>
205 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\" height=\"11\" width=\"11\" border=\"0\" /></a> ";
206 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\" height=\"11\" width=\"11\" border=\"0\" /></a>";
219 <td width
="100%" colspan
="2" align
="center">
222 $options['id'] = $cm->id
;
223 $options['action'] = "add";
225 echo "<table border=\"0\"><tr><td align=\"right\">";
226 echo print_single_button("editcategories.php", $options, get_string("add") . " " . get_string("category","glossary"), "get");
227 echo "</td><td align=\"left\">";
228 unset($options['action']);
229 $options['mode'] = 'cat';
230 $options['hook'] = $hook;
231 echo print_single_button("view.php", $options, get_string("back","glossary") );
246 <?php
print_footer() ?
>