[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/question/ -> category.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This script allows a teacher to create, edit and delete question categories.
  19   *
  20   * @package    moodlecore
  21   * @subpackage questionbank
  22   * @copyright  1999 onwards Martin Dougiamas {@link http://moodle.com}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  require_once("../config.php");
  28  require_once($CFG->dirroot."/question/editlib.php");
  29  require_once($CFG->dirroot."/question/category_class.php");
  30  
  31  list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) =
  32          question_edit_setup('categories', '/question/category.php');
  33  
  34  // Get values from form for actions on this page.
  35  $param = new stdClass();
  36  $param->moveup = optional_param('moveup', 0, PARAM_INT);
  37  $param->movedown = optional_param('movedown', 0, PARAM_INT);
  38  $param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
  39  $param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
  40  $param->tocontext = optional_param('tocontext', 0, PARAM_INT);
  41  $param->left = optional_param('left', 0, PARAM_INT);
  42  $param->right = optional_param('right', 0, PARAM_INT);
  43  $param->delete = optional_param('delete', 0, PARAM_INT);
  44  $param->confirm = optional_param('confirm', 0, PARAM_INT);
  45  $param->cancel = optional_param('cancel', '', PARAM_ALPHA);
  46  $param->move = optional_param('move', 0, PARAM_INT);
  47  $param->moveto = optional_param('moveto', 0, PARAM_INT);
  48  $param->edit = optional_param('edit', 0, PARAM_INT);
  49  
  50  $url = new moodle_url($thispageurl);
  51  foreach ((array)$param as $key=>$value) {
  52      if (($key !== 'cancel' && $value !== 0) || ($key === 'cancel' && $value !== '')) {
  53          $url->param($key, $value);
  54      }
  55  }
  56  $PAGE->set_url($url);
  57  
  58  $qcobject = new question_category_object($pagevars['cpage'], $thispageurl,
  59          $contexts->having_one_edit_tab_cap('categories'), $param->edit,
  60          $pagevars['cat'], $param->delete, $contexts->having_cap('moodle/question:add'));
  61  
  62  if ($param->left || $param->right || $param->moveup || $param->movedown) {
  63      require_sesskey();
  64  
  65      foreach ($qcobject->editlists as $list) {
  66          // Processing of these actions is handled in the method where appropriate and page redirects.
  67          $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown);
  68      }
  69  }
  70  
  71  if ($param->moveupcontext || $param->movedowncontext) {
  72      require_sesskey();
  73  
  74      if ($param->moveupcontext) {
  75          $catid = $param->moveupcontext;
  76      } else {
  77          $catid = $param->movedowncontext;
  78      }
  79      $oldcat = $DB->get_record('question_categories', array('id' => $catid), '*', MUST_EXIST);
  80      $qcobject->update_category($catid, '0,'.$param->tocontext, $oldcat->name, $oldcat->info);
  81      // The previous line does a redirect().
  82  }
  83  
  84  if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))) {
  85      if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) {  // security
  86          print_error('nocate', 'question', $thispageurl->out(), $param->delete);
  87      }
  88      $categorycontext = context::instance_by_id($category->contextid);
  89      $qcobject->moveform = new question_move_form($thispageurl,
  90                  array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete));
  91      if ($qcobject->moveform->is_cancelled()){
  92          redirect($thispageurl);
  93      }  elseif ($formdata = $qcobject->moveform->get_data()) {
  94          /// 'confirm' is the category to move existing questions to
  95          list($tocategoryid, $tocontextid) = explode(',', $formdata->category);
  96          $qcobject->move_questions_and_delete_category($formdata->delete, $tocategoryid);
  97          $thispageurl->remove_params('cat', 'category');
  98          redirect($thispageurl);
  99      }
 100  } else {
 101      $questionstomove = 0;
 102  }
 103  
 104  if ($qcobject->catform->is_cancelled()) {
 105      redirect($thispageurl);
 106  } else if ($catformdata = $qcobject->catform->get_data()) {
 107      $catformdata->infoformat = $catformdata->info['format'];
 108      $catformdata->info       = $catformdata->info['text'];
 109      if (!$catformdata->id) {//new category
 110          $qcobject->add_category($catformdata->parent, $catformdata->name,
 111                  $catformdata->info, false, $catformdata->infoformat);
 112      } else {
 113          $qcobject->update_category($catformdata->id, $catformdata->parent,
 114                  $catformdata->name, $catformdata->info, $catformdata->infoformat);
 115      }
 116      redirect($thispageurl);
 117  } else if ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey())) {
 118      $qcobject->delete_category($param->delete);//delete the category now no questions to move
 119      $thispageurl->remove_params('cat', 'category');
 120      redirect($thispageurl);
 121  }
 122  
 123  if ($param->edit) {
 124      $PAGE->navbar->add(get_string('editingcategory', 'question'));
 125  }
 126  
 127  $PAGE->set_title(get_string('editcategories', 'question'));
 128  $PAGE->set_heading($COURSE->fullname);
 129  echo $OUTPUT->header();
 130  
 131  // Display the UI.
 132  if (!empty($param->edit)) {
 133      $qcobject->edit_single_category($param->edit);
 134  } else if ($questionstomove){
 135      $qcobject->display_move_form($questionstomove, $category);
 136  } else {
 137      // Display the user interface.
 138      $qcobject->display_user_interface();
 139  }
 140  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1