Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/glossary/editcategories.php
Go to the documentation of this file.
00001 <?php
00002 
00004 
00005 require_once("../../config.php");
00006 require_once("lib.php");
00007 
00008 $id = required_param('id', PARAM_INT);                       // Course Module ID, or
00009 $usedynalink = optional_param('usedynalink', 0, PARAM_INT);  // category ID
00010 $confirm     = optional_param('confirm', 0, PARAM_INT);      // confirm the action
00011 $name        = optional_param('name', '', PARAM_CLEAN);  // confirm the name
00012 
00013 $action = optional_param('action', '', PARAM_ALPHA ); // what to do
00014 $hook   = optional_param('hook', '', PARAM_ALPHANUM); // category ID
00015 $mode   = optional_param('mode', '', PARAM_ALPHA);   // cat
00016 
00017 $action = strtolower($action);
00018 
00019 $url = new moodle_url('/mod/glossary/editcategories.php', array('id'=>$id));
00020 if ($usedynalink !== 0) {
00021     $url->param('usedynalink', $usedynalink);
00022 }
00023 if ($confirm !== 0) {
00024     $url->param('confirm', $confirm);
00025 }
00026 if ($name !== 'name') {
00027     $url->param('name', $name);
00028 }
00029 if ($action !== 'action') {
00030     $url->param('action', $action);
00031 }
00032 if ($hook !== 'hook') {
00033     $url->param('hook', $hook);
00034 }
00035 if ($mode !== 'mode') {
00036     $url->param('mode', $mode);
00037 }
00038 
00039 $PAGE->set_url($url);
00040 
00041 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
00042     print_error('invalidcoursemodule');
00043 }
00044 
00045 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00046     print_error('coursemisconf');
00047 }
00048 
00049 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
00050     print_error('invalidcoursemodule');
00051 }
00052 
00053 if ($hook > 0) {
00054     if ($category = $DB->get_record("glossary_categories", array("id"=>$hook))) {
00055         //Check it belongs to the same glossary
00056         if ($category->glossaryid != $glossary->id) {
00057             print_error('invalidid', 'glossary');
00058         }
00059     } else {
00060         print_error('invalidcategoryid');
00061     }
00062 }
00063 
00064 require_login($course->id, false, $cm);
00065 
00066 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
00067 require_capability('mod/glossary:managecategories', $context);
00068 
00069 $strglossaries   = get_string("modulenameplural", "glossary");
00070 $strglossary     = get_string("modulename", "glossary");
00071 
00072 $PAGE->navbar->add($strglossaries, new moodle_url('/mod/glossary/index.php', array('id'=>$course->id)));
00073 $PAGE->navbar->add(get_string("categories","glossary"));
00074 if (!empty($action)) {
00075     $navaction = get_string($action). " " . moodle_strtolower(get_string("category","glossary"));
00076     $PAGE->navbar->add($navaction);
00077 }
00078 $PAGE->set_title(format_string($glossary->name));
00079 $PAGE->set_heading($course->fullname);
00080 echo $OUTPUT->header();
00081 
00082 // Prepare format_string/text options
00083 $fmtoptions = array(
00084     'context' => $context);
00085 
00086 if (right_to_left()) { // RTL table alignment support
00087     $rightalignment = 'left';
00088     $leftalignment = 'right';
00089 } else {
00090     $rightalignment = 'right';
00091     $leftalignment = 'left';
00092 
00093 }
00094 
00095 if ( $hook >0 ) {
00096 
00097     if ( $action == "edit" ) {
00098         if ( $confirm ) {
00099             $action = "";
00100             $cat = new stdClass();
00101             $cat->id = $hook;
00102             $cat->name = $name;
00103             $cat->usedynalink = $usedynalink;
00104 
00105             $DB->update_record("glossary_categories", $cat);
00106             add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id);
00107 
00108         } else {
00109             echo "<h3 class=\"main\">" . get_string("edit"). " " . get_string("category","glossary") . "</h3>";
00110 
00111             $name = $category->name;
00112             $usedynalink = $category->usedynalink;
00113             require "editcategories.html";
00114             echo $OUTPUT->footer();
00115             die;
00116         }
00117 
00118     } elseif ( $action == "delete" ) {
00119         if ( $confirm ) {
00120             $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
00121             $DB->delete_records("glossary_categories", array("id"=>$hook));
00122 
00123             echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
00124             echo "<div>" . get_string("categorydeleted","glossary") ."</div>";
00125             echo $OUTPUT->box_end();
00126 
00127             add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id);
00128 
00129             redirect("editcategories.php?id=$cm->id");
00130         } else {
00131             echo "<p>" . get_string("delete"). " " . get_string("category","glossary"). "</p>";
00132 
00133             echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
00134             echo "<div class=\"boxaligncenter deletecatconfirm\">".format_string($category->name, true, $fmtoptions)."<br/>";
00135 
00136             $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
00137             if ( $num_entries ) {
00138                 print_string("deletingnoneemptycategory","glossary");
00139             }
00140             echo "<p>";
00141             print_string("areyousuredelete","glossary");
00142             echo "</p>";
00143 ?>
00144 
00145                 <table border="0" width="100" class="confirmbuttons">
00146                     <tr>
00147                         <td align="$rightalignment" style="width:50%">
00148                         <form id="form" method="post" action="editcategories.php">
00149                         <div>
00150                         <input type="hidden" name="id"          value="<?php p($cm->id) ?>" />
00151                         <input type="hidden" name="action"      value="delete" />
00152                         <input type="hidden" name="confirm"     value="1" />
00153                         <input type="hidden" name="mode"         value="<?php echo $mode ?>" />
00154                         <input type="hidden" name="hook"         value="<?php echo $hook ?>" />
00155                         <input type="submit" value=" <?php print_string("yes")?> " />
00156                         </div>
00157                         </form>
00158                         </td>
00159                         <td align="$leftalignment" style="width:50%">
00160 
00161 <?php
00162             unset($options);
00163             $options = array ("id" => $id);
00164             echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("no"));
00165             echo "</td></tr></table>";
00166             echo "</div>";
00167             echo $OUTPUT->box_end();
00168         }
00169     }
00170 
00171 } elseif ( $action == "add" ) {
00172     if ( $confirm ) {
00173         $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE ".$DB->sql_like('name','?', false)." AND glossaryid=?", array($name, $glossary->id));
00174         if ( $dupcategory ) {
00175         echo "<h3 class=\"main\">" . get_string("add"). " " . get_string("category","glossary"). "</h3>";
00176 
00177             echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
00178             echo "<div>" . get_string("duplicatecategory","glossary") ."</div>";
00179             echo $OUTPUT->box_end();
00180 
00181             redirect("editcategories.php?id=$cm->id&amp;action=add&amp;name=$name");
00182 
00183         } else {
00184             $action = "";
00185             $cat = new stdClass();
00186             $cat->name = $name;
00187             $cat->usedynalink = $usedynalink;
00188             $cat->glossaryid = $glossary->id;
00189 
00190             $cat->id = $DB->insert_record("glossary_categories", $cat);
00191             add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id,$cm->id);
00192         }
00193     } else {
00194         echo "<h3 class=\"main\">" . get_string("add"). " " . get_string("category","glossary"). "</h3>";
00195         $name="";
00196         require "editcategories.html";
00197     }
00198 }
00199 
00200 if ( $action ) {
00201     echo $OUTPUT->footer();
00202     die;
00203 }
00204 
00205 ?>
00206 
00207 <form method="post" action="editcategories.php">
00208 <table width="40%" class="boxaligncenter generalbox" cellpadding="5">
00209         <tr>
00210           <th style="width:90%" align="center">
00211           <?php p(get_string("categories","glossary")) ?></th>
00212           <th style="width:10%" align="center">
00213           <?php p(get_string("action")) ?></th>
00214         </tr>
00215         <tr><td style="width:100%" colspan="2">
00216 
00217 
00218 
00219 <?php
00220     $categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary->id), "name ASC");
00221 
00222     if ( $categories ) {
00223         echo '<table width="100%">';
00224         foreach ($categories as $category) {
00225             $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
00226 ?>
00227 
00228              <tr>
00229                <td style="width:80%" align="$leftalignment">
00230                <?php
00231                     echo "<span class=\"bold\">".format_string($category->name, true, $fmtoptions)."</span> <span>($num_entries " . get_string("entries","glossary") . ")</span>";
00232                ?>
00233                </td>
00234                <td style="width:19%" align="center" class="action">
00235                <?php
00236                 echo "<a href=\"editcategories.php?id=$cm->id&amp;action=delete&amp;mode=cat&amp;hook=$category->id\"><img  alt=\"" . get_string("delete") . "\"src=\"" . $OUTPUT->pix_url('t/delete') . "\" class=\"iconsmall\" /></a> ";
00237                 echo "<a href=\"editcategories.php?id=$cm->id&amp;action=edit&amp;mode=cat&amp;hook=$category->id\"><img  alt=\"" . get_string("edit") . "\" src=\"" . $OUTPUT->pix_url('t/edit') . "\" class=\"iconsmall\" /></a>";
00238                ?>
00239                </td>
00240              </tr>
00241 
00242              <?php
00243 
00244           }
00245         echo '</table>';
00246      }
00247 ?>
00248 
00249         </td></tr>
00250         <tr>
00251         <td style="width:100%" colspan="2"  align="center">
00252             <?php
00253 
00254              $options['id'] = $cm->id;
00255              $options['action'] = "add";
00256 
00257              echo "<table class=\"editbuttons\" border=\"0\"><tr><td align=\"$rightalignment\">";
00258              echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("add") . " " . get_string("category","glossary"));
00259              echo "</td><td align=\"$leftalignment\">";
00260              unset($options['action']);
00261              $options['mode'] = 'cat';
00262              $options['hook'] = $hook;
00263              echo $OUTPUT->single_button(new moodle_url("view.php", $options), get_string("back","glossary"));
00264              echo "</td></tr>";
00265              echo "</table>";
00266 
00267             ?>
00268         </td>
00269         </tr>
00270         </table>
00271 
00272 
00273 </form>
00274 
00275 <?php
00276 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations