Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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   * Instance add/edit form
  19   *
  20   * @package    mod_book
  21   * @copyright  2004-2011 Petr Skoda {@link http://skodak.org}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die;
  26  
  27  require_once (__DIR__.'/locallib.php');
  28  require_once($CFG->dirroot.'/course/moodleform_mod.php');
  29  
  30  class mod_book_mod_form extends moodleform_mod {
  31  
  32      function definition() {
  33          global $CFG;
  34  
  35          $mform = $this->_form;
  36  
  37          $config = get_config('book');
  38  
  39          $mform->addElement('header', 'general', get_string('general', 'form'));
  40  
  41          $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
  42          if (!empty($CFG->formatstringstriptags)) {
  43              $mform->setType('name', PARAM_TEXT);
  44          } else {
  45              $mform->setType('name', PARAM_CLEANHTML);
  46          }
  47          $mform->addRule('name', null, 'required', null, 'client');
  48          $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  49          $this->standard_intro_elements(get_string('moduleintro'));
  50  
  51          // Appearance.
  52          $mform->addElement('header', 'appearancehdr', get_string('appearance'));
  53  
  54          $alloptions = book_get_numbering_types();
  55          $allowed = explode(',', $config->numberingoptions);
  56          $options = array();
  57          foreach ($allowed as $type) {
  58              if (isset($alloptions[$type])) {
  59                  $options[$type] = $alloptions[$type];
  60              }
  61          }
  62          if ($this->current->instance) {
  63              if (!isset($options[$this->current->numbering])) {
  64                  if (isset($alloptions[$this->current->numbering])) {
  65                      $options[$this->current->numbering] = $alloptions[$this->current->numbering];
  66                  }
  67              }
  68          }
  69          $mform->addElement('select', 'numbering', get_string('numbering', 'book'), $options);
  70          $mform->addHelpButton('numbering', 'numbering', 'mod_book');
  71          $mform->setDefault('numbering', $config->numbering);
  72  
  73          $alloptions = book_get_nav_types();
  74          $allowed = explode(',', $config->navoptions);
  75          $options = array();
  76          foreach ($allowed as $type) {
  77              if (isset($alloptions[$type])) {
  78                  $options[$type] = $alloptions[$type];
  79              }
  80          }
  81          if ($this->current->instance) {
  82              if (!isset($options[$this->current->navstyle])) {
  83                  if (isset($alloptions[$this->current->navstyle])) {
  84                      $options[$this->current->navstyle] = $alloptions[$this->current->navstyle];
  85                  }
  86              }
  87          }
  88          $mform->addElement('select', 'navstyle', get_string('navstyle', 'book'), $options);
  89          $mform->addHelpButton('navstyle', 'navstyle', 'mod_book');
  90          $mform->setDefault('navstyle', $config->navstyle);
  91  
  92          $mform->addElement('checkbox', 'customtitles', get_string('customtitles', 'book'));
  93          $mform->addHelpButton('customtitles', 'customtitles', 'mod_book');
  94          $mform->setDefault('customtitles', 0);
  95  
  96          $this->standard_coursemodule_elements();
  97  
  98          $this->add_action_buttons();
  99      }
 100  }