Automatic installer.php lang files by installer_builder (20070313)
[moodle.git] / mod / glossary / editcategories.php
blobcd6d933dedadd8bd687fa1e0c43d98238257188a
1 <?php // $Id$
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");
31 if ($hook > 0) {
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");
37 } else {
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&amp;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));
56 if ( $hook >0 ) {
58 if ( $action == "edit" ) {
59 if ( $confirm ) {
60 $action = "";
61 $cat->id = $hook;
62 $cat->name = $name;
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");
68 } else {
69 add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id);
71 } else {
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";
77 print_footer();
78 die;
81 } elseif ( $action == "delete" ) {
82 if ( $confirm ) {
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>";
88 echo "</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");
95 } else {
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");
105 echo "<p>";
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")?> " />
117 </form>
118 </td><td align="left" width="50%">
120 <?php
121 unset($options);
122 $options = array ("id" => $id);
123 print_single_button("editcategories.php", $options, get_string("no") );
124 echo "</td></tr></table>";
125 echo "</center>";
126 print_simple_box_end();
130 } elseif ( $action == "add" ) {
131 if ( $confirm ) {
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>";
139 echo "</center>";
140 print_simple_box_end();
142 print_footer($course);
144 redirect("editcategories.php?id=$cm->id&amp;action=add&&amp;name=$name");
146 } else {
147 $action = "";
148 $cat->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");
156 } else {
157 add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id,$cm->id);
160 } else {
161 echo "<p align=\"center\">" . get_string("add"). " " . get_string("category","glossary") . "<font size=\"3\">";
162 $name="";
163 require "editcategories.html";
167 if ( $action ) {
168 print_footer();
169 die;
175 <div align="center">
177 <form name="theform" method="post" action="editcategories.php">
178 <table width="40%" class="generalbox" cellpadding="5">
179 <tr>
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>
184 </tr>
185 <tr><td width="100%" colspan="2">
187 <table width="100%">
189 <?php
190 $categories = get_records("glossary_categories","glossaryid",$glossary->id,"name ASC");
192 if ( $categories ) {
193 foreach ($categories as $category) {
194 $num_entries = count_records("glossary_entries_categories","categoryid",$category->id);
197 <tr>
198 <td width="90%" align="left">
199 <?php
200 echo "<b>".format_text($category->name)."</b> <font size=-1>($num_entries " . get_string("entries","glossary") . ")</font>";
202 </td>
203 <td width="10%" align="center"><b>
204 <?php
205 echo "<a href=\"editcategories.php?id=$cm->id&amp;action=delete&amp;mode=cat&amp;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&amp;action=edit&amp;mode=cat&amp;hook=$category->id\"><img alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=\"11\" width=\"11\" border=\"0\" /></a>";
208 </b></td>
209 </tr>
211 <?php
215 </table>
217 </td>
218 <tr>
219 <td width="100%" colspan="2" align="center">
220 <?php
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") );
232 echo "</td></tr>";
233 echo "</tablee>";
236 </td>
237 </tr>
238 </table>
240 </table>
241 </p>
244 </form>
246 <?php print_footer() ?>