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  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Page configuration form
  20   *
  21   * @package mod_page
  22   * @copyright  2009 Petr Skoda (http://skodak.org)
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die;
  27  
  28  require_once($CFG->dirroot.'/course/moodleform_mod.php');
  29  require_once($CFG->dirroot.'/mod/page/locallib.php');
  30  require_once($CFG->libdir.'/filelib.php');
  31  
  32  class mod_page_mod_form extends moodleform_mod {
  33      function definition() {
  34          global $CFG, $DB;
  35  
  36          $mform = $this->_form;
  37  
  38          $config = get_config('page');
  39  
  40          //-------------------------------------------------------
  41          $mform->addElement('header', 'general', get_string('general', 'form'));
  42          $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
  43          if (!empty($CFG->formatstringstriptags)) {
  44              $mform->setType('name', PARAM_TEXT);
  45          } else {
  46              $mform->setType('name', PARAM_CLEANHTML);
  47          }
  48          $mform->addRule('name', null, 'required', null, 'client');
  49          $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  50          $this->standard_intro_elements();
  51  
  52          //-------------------------------------------------------
  53          $mform->addElement('header', 'contentsection', get_string('contentheader', 'page'));
  54          $mform->addElement('editor', 'page', get_string('content', 'page'), null, page_get_editor_options($this->context));
  55          $mform->addRule('page', get_string('required'), 'required', null, 'client');
  56  
  57          //-------------------------------------------------------
  58          $mform->addElement('header', 'appearancehdr', get_string('appearance'));
  59  
  60          if ($this->current->instance) {
  61              $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
  62          } else {
  63              $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
  64          }
  65          if (count($options) == 1) {
  66              $mform->addElement('hidden', 'display');
  67              $mform->setType('display', PARAM_INT);
  68              reset($options);
  69              $mform->setDefault('display', key($options));
  70          } else {
  71              $mform->addElement('select', 'display', get_string('displayselect', 'page'), $options);
  72              $mform->setDefault('display', $config->display);
  73          }
  74  
  75          if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
  76              $mform->addElement('text', 'popupwidth', get_string('popupwidth', 'page'), array('size'=>3));
  77              if (count($options) > 1) {
  78                  $mform->hideIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
  79              }
  80              $mform->setType('popupwidth', PARAM_INT);
  81              $mform->setDefault('popupwidth', $config->popupwidth);
  82  
  83              $mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3));
  84              if (count($options) > 1) {
  85                  $mform->hideIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
  86              }
  87              $mform->setType('popupheight', PARAM_INT);
  88              $mform->setDefault('popupheight', $config->popupheight);
  89          }
  90  
  91          $mform->addElement('advcheckbox', 'printheading', get_string('printheading', 'page'));
  92          $mform->setDefault('printheading', $config->printheading);
  93          $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page'));
  94          $mform->setDefault('printintro', $config->printintro);
  95          $mform->addElement('advcheckbox', 'printlastmodified', get_string('printlastmodified', 'page'));
  96          $mform->setDefault('printlastmodified', $config->printlastmodified);
  97  
  98          // add legacy files flag only if used
  99          if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
 100              $options = array(RESOURCELIB_LEGACYFILES_DONE   => get_string('legacyfilesdone', 'page'),
 101                               RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
 102              $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
 103              $mform->setAdvanced('legacyfiles', 1);
 104          }
 105  
 106          //-------------------------------------------------------
 107          $this->standard_coursemodule_elements();
 108  
 109          //-------------------------------------------------------
 110          $this->add_action_buttons();
 111  
 112          //-------------------------------------------------------
 113          $mform->addElement('hidden', 'revision');
 114          $mform->setType('revision', PARAM_INT);
 115          $mform->setDefault('revision', 1);
 116      }
 117  
 118      /**
 119       * Enforce defaults here.
 120       *
 121       * @param array $defaultvalues Form defaults
 122       * @return void
 123       **/
 124      public function data_preprocessing(&$defaultvalues) {
 125          if ($this->current->instance) {
 126              $draftitemid = file_get_submitted_draft_itemid('page');
 127              $defaultvalues['page']['format'] = $defaultvalues['contentformat'];
 128              $defaultvalues['page']['text']   = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page',
 129                      'content', 0, page_get_editor_options($this->context), $defaultvalues['content']);
 130              $defaultvalues['page']['itemid'] = $draftitemid;
 131          }
 132          if (!empty($defaultvalues['displayoptions'])) {
 133              $displayoptions = (array) unserialize_array($defaultvalues['displayoptions']);
 134              if (isset($displayoptions['printintro'])) {
 135                  $defaultvalues['printintro'] = $displayoptions['printintro'];
 136              }
 137              if (isset($displayoptions['printheading'])) {
 138                  $defaultvalues['printheading'] = $displayoptions['printheading'];
 139              }
 140              if (isset($displayoptions['printlastmodified'])) {
 141                  $defaultvalues['printlastmodified'] = $displayoptions['printlastmodified'];
 142              }
 143              if (!empty($displayoptions['popupwidth'])) {
 144                  $defaultvalues['popupwidth'] = $displayoptions['popupwidth'];
 145              }
 146              if (!empty($displayoptions['popupheight'])) {
 147                  $defaultvalues['popupheight'] = $displayoptions['popupheight'];
 148              }
 149          }
 150      }
 151  }
 152