[ Index ]

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

title

Body

[close]

/course/ -> delete_category_form.php (source)

   1  <?php  //$Id: delete_category_form.php,v 1.1.2.1 2008/05/13 21:51:46 skodak Exp $
   2  
   3  require_once($CFG->libdir.'/formslib.php');
   4  
   5  class delete_category_form extends moodleform {
   6  
   7      var $_category;
   8  
   9      function definition() {
  10          global $CFG;
  11  
  12          $mform    =& $this->_form;
  13          $category = $this->_customdata;
  14          $this->_category = $category;
  15  
  16          $mform->addElement('header','general', get_string('categorycurrentcontents', '', format_string($category->name)));
  17  
  18          $displaylist = array();
  19          $parentlist = array();
  20          $children = array();
  21          make_categories_list($displaylist, $parentlist);
  22          unset($displaylist[$category->id]);
  23          foreach ($displaylist as $catid=>$unused) {
  24              // remove all children of $category
  25              if (isset($parentlist[$catid]) and in_array($category->id, $parentlist[$catid])) {
  26                  $children[] = $catid;
  27                  unset($displaylist[$catid]);
  28                  continue;
  29              }
  30              if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $catid))) {
  31                  unset($displaylist[$catid]);
  32              }
  33          }
  34  
  35          $candeletecontent = true;
  36          foreach ($children as $catid) {
  37              $context = get_context_instance(CONTEXT_COURSECAT, $catid);
  38              if (!has_capability('moodle/category:delete', $context)) {
  39                  $candeletecontent = false;
  40                  break;
  41              }
  42          }
  43  
  44          $options = array();
  45  
  46          if ($displaylist) {
  47              $options[0] = get_string('move');
  48          }
  49  
  50          if ($candeletecontent) {
  51              $options[1] =get_string('delete');
  52          }
  53  
  54          if (empty($options)) {
  55              print_error('nocategorydelete', 'error', 'index.php', format_string($category->name));
  56          }
  57  
  58          $mform->addElement('select', 'fulldelete', get_string('categorycontents'), $options);
  59          $mform->disabledIf('newparent', 'fulldelete', 'eq', '1');
  60          $mform->setDefault('newparent', 0);
  61  
  62          if ($displaylist) {
  63              $mform->addElement('select', 'newparent', get_string('movecategorycontentto'), $displaylist);
  64              if (in_array($category->parent, $displaylist)) {
  65                  $mform->setDefault('newparent', $category->parent);
  66              }
  67          }
  68  
  69          $mform->addElement('hidden', 'delete');
  70          $mform->addElement('hidden', 'sure');
  71          $mform->setDefault('sure', md5(serialize($category)));
  72  
  73  //--------------------------------------------------------------------------------
  74          $this->add_action_buttons(true, get_string('delete'));
  75  
  76      }
  77  
  78  /// perform some extra moodle validation
  79      function validation($data, $files) {
  80          $errors = parent::validation($data, $files);
  81  
  82          if (!empty($data['fulldelete'])) {
  83              // already verified
  84          } else {
  85              if (empty($data['newparent'])) {
  86                  $errors['newparent'] = get_string('required');
  87              }
  88          }
  89  
  90          if ($data['sure'] != md5(serialize($this->_category))) {
  91              $errors['categorylabel'] = get_string('categorymodifiedcancel');
  92          }
  93  
  94          return $errors;
  95      }
  96  }
  97  ?>


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