[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/question/ -> category.php (source)

   1  <?php // $Id: category.php,v 1.24.2.3 2008/04/22 14:06:57 tjhunt Exp $
   2  /**
   3   * Allows a teacher to create, edit and delete categories
   4   *
   5   * @author Martin Dougiamas and many others.
   6   *         {@link http://moodle.org}
   7   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
   8   * @package questionbank
   9   */
  10  
  11      require_once("../config.php");
  12      require_once($CFG->dirroot."/question/editlib.php");
  13      require_once($CFG->dirroot."/question/category_class.php");
  14  
  15  
  16  
  17      list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('categories');
  18  
  19      // get values from form for actions on this page
  20      $param = new stdClass();
  21  
  22  
  23      $param->moveup = optional_param('moveup', 0, PARAM_INT);
  24      $param->movedown = optional_param('movedown', 0, PARAM_INT);
  25      $param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
  26      $param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
  27      $param->tocontext = optional_param('tocontext', 0, PARAM_INT);
  28      $param->left = optional_param('left', 0, PARAM_INT);
  29      $param->right = optional_param('right', 0, PARAM_INT);
  30      $param->delete = optional_param('delete', 0, PARAM_INT);
  31      $param->confirm = optional_param('confirm', 0, PARAM_INT);
  32      $param->cancel = optional_param('cancel', '', PARAM_ALPHA);
  33      $param->move = optional_param('move', 0, PARAM_INT);
  34      $param->moveto = optional_param('moveto', 0, PARAM_INT);
  35      $param->edit = optional_param('edit', 0, PARAM_INT);
  36  
  37      $qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $param->edit, $pagevars['cat'], $param->delete,
  38                                  $contexts->having_cap('moodle/question:add'));
  39  
  40      $streditingcategories = get_string('editcategories', 'quiz');
  41      if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){
  42          confirm_sesskey();
  43          foreach ($qcobject->editlists as $list){
  44              //processing of these actions is handled in the method where appropriate and page redirects.
  45              $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown,
  46                                      $param->moveupcontext, $param->movedowncontext, $param->tocontext);
  47          }
  48      }
  49      if ($param->delete && ($questionstomove = count_records("question", "category", $param->delete))){
  50          if (!$category = get_record("question_categories", "id", $param->delete)) {  // security
  51              error("No such category {$param->delete}!", $thispageurl->out());
  52          }
  53          $categorycontext = get_context_instance_by_id($category->contextid);
  54          $qcobject->moveform = new question_move_form($thispageurl,
  55                      array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete));
  56          if ($qcobject->moveform->is_cancelled()){
  57              redirect($thispageurl->out());
  58          }  elseif ($formdata = $qcobject->moveform->get_data()) {
  59              /// 'confirm' is the category to move existing questions to
  60              list($tocategoryid, $tocontextid) = explode(',', $formdata->category);
  61              $qcobject->move_questions_and_delete_category($formdata->delete, $tocategoryid);
  62              $thispageurl->remove_params('cat');
  63              $thispageurl->remove_params('category'); // TODO check in fix for bug 5353 
  64              redirect($thispageurl->out());
  65          }
  66      } else {
  67          $questionstomove = 0;
  68      }
  69      if ($qcobject->catform->is_cancelled()){
  70          redirect($thispageurl->out());
  71      }elseif ($catformdata = $qcobject->catform->get_data()) {
  72          if (!$catformdata->id) {//new category
  73              $qcobject->add_category($catformdata->parent, $catformdata->name, $catformdata->info);
  74          } else {
  75              $qcobject->update_category($catformdata->id, $catformdata->parent, $catformdata->name, $catformdata->info);
  76          }
  77          redirect($thispageurl->out());
  78      } elseif ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey()))  {
  79          $qcobject->delete_category($param->delete);//delete the category now no questions to move
  80      }
  81      $navlinks = array();
  82      if ($cm!==null) {
  83          // Page header
  84          $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
  85              ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname))
  86              : "";
  87          $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname),
  88                              'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id",
  89                              'type' => 'activity');
  90          $navlinks[] = array('name' => format_string($module->name),
  91                              'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}",
  92                              'type' => 'title');
  93      } else {
  94          // Print basic page layout.
  95          $strupdatemodule = '';
  96      }
  97  
  98      if (!$param->edit){
  99          $navlinks[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
 100      } else {
 101          $navlinks[] = array('name' => $streditingcategories, 'link' => $thispageurl->out(), 'type' => 'title');
 102          $navlinks[] = array('name' => get_string('editingcategory', 'question'), 'link' => '', 'type' => 'title');
 103      }
 104  
 105      $navigation = build_navigation($navlinks);
 106      print_header_simple($streditingcategories, '', $navigation, "", "", true, $strupdatemodule);
 107  
 108      // print tabs
 109      if ($cm!==null) {
 110          $currenttab = 'edit';
 111          $mode = 'categories';
 112          ${$cm->modname} = $module;
 113          include($CFG->dirroot."/mod/{$cm->modname}/tabs.php");
 114      } else {
 115          $currenttab = 'categories';
 116          $context = $contexts->lowest();
 117          include ('tabs.php');
 118      }
 119  
 120      // display UI
 121      if (!empty($param->edit)) {
 122          $qcobject->edit_single_category($param->edit);
 123      } else if ($questionstomove){
 124          $qcobject->display_move_form($questionstomove, $category);
 125      } else {
 126          // display the user interface
 127          $qcobject->display_user_interface();
 128      }
 129      print_footer($COURSE);
 130  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7