PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/page/mod_form.php

http://github.com/moodle/moodle
PHP | 152 lines | 98 code | 20 blank | 34 comment | 20 complexity | 740597f74ac23809fae5e34d69f7ae64 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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. * Page configuration form
  18. *
  19. * @package mod_page
  20. * @copyright 2009 Petr Skoda (http://skodak.org)
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die;
  24. require_once($CFG->dirroot.'/course/moodleform_mod.php');
  25. require_once($CFG->dirroot.'/mod/page/locallib.php');
  26. require_once($CFG->libdir.'/filelib.php');
  27. class mod_page_mod_form extends moodleform_mod {
  28. function definition() {
  29. global $CFG, $DB;
  30. $mform = $this->_form;
  31. $config = get_config('page');
  32. //-------------------------------------------------------
  33. $mform->addElement('header', 'general', get_string('general', 'form'));
  34. $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
  35. if (!empty($CFG->formatstringstriptags)) {
  36. $mform->setType('name', PARAM_TEXT);
  37. } else {
  38. $mform->setType('name', PARAM_CLEANHTML);
  39. }
  40. $mform->addRule('name', null, 'required', null, 'client');
  41. $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  42. $this->standard_intro_elements();
  43. //-------------------------------------------------------
  44. $mform->addElement('header', 'contentsection', get_string('contentheader', 'page'));
  45. $mform->addElement('editor', 'page', get_string('content', 'page'), null, page_get_editor_options($this->context));
  46. $mform->addRule('page', get_string('required'), 'required', null, 'client');
  47. //-------------------------------------------------------
  48. $mform->addElement('header', 'appearancehdr', get_string('appearance'));
  49. if ($this->current->instance) {
  50. $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
  51. } else {
  52. $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
  53. }
  54. if (count($options) == 1) {
  55. $mform->addElement('hidden', 'display');
  56. $mform->setType('display', PARAM_INT);
  57. reset($options);
  58. $mform->setDefault('display', key($options));
  59. } else {
  60. $mform->addElement('select', 'display', get_string('displayselect', 'page'), $options);
  61. $mform->setDefault('display', $config->display);
  62. }
  63. if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
  64. $mform->addElement('text', 'popupwidth', get_string('popupwidth', 'page'), array('size'=>3));
  65. if (count($options) > 1) {
  66. $mform->hideIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
  67. }
  68. $mform->setType('popupwidth', PARAM_INT);
  69. $mform->setDefault('popupwidth', $config->popupwidth);
  70. $mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3));
  71. if (count($options) > 1) {
  72. $mform->hideIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
  73. }
  74. $mform->setType('popupheight', PARAM_INT);
  75. $mform->setDefault('popupheight', $config->popupheight);
  76. }
  77. $mform->addElement('advcheckbox', 'printheading', get_string('printheading', 'page'));
  78. $mform->setDefault('printheading', $config->printheading);
  79. $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page'));
  80. $mform->setDefault('printintro', $config->printintro);
  81. $mform->addElement('advcheckbox', 'printlastmodified', get_string('printlastmodified', 'page'));
  82. $mform->setDefault('printlastmodified', $config->printlastmodified);
  83. // add legacy files flag only if used
  84. if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
  85. $options = array(RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'page'),
  86. RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
  87. $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
  88. $mform->setAdvanced('legacyfiles', 1);
  89. }
  90. //-------------------------------------------------------
  91. $this->standard_coursemodule_elements();
  92. //-------------------------------------------------------
  93. $this->add_action_buttons();
  94. //-------------------------------------------------------
  95. $mform->addElement('hidden', 'revision');
  96. $mform->setType('revision', PARAM_INT);
  97. $mform->setDefault('revision', 1);
  98. }
  99. /**
  100. * Enforce defaults here.
  101. *
  102. * @param array $defaultvalues Form defaults
  103. * @return void
  104. **/
  105. public function data_preprocessing(&$defaultvalues) {
  106. if ($this->current->instance) {
  107. $draftitemid = file_get_submitted_draft_itemid('page');
  108. $defaultvalues['page']['format'] = $defaultvalues['contentformat'];
  109. $defaultvalues['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page',
  110. 'content', 0, page_get_editor_options($this->context), $defaultvalues['content']);
  111. $defaultvalues['page']['itemid'] = $draftitemid;
  112. }
  113. if (!empty($defaultvalues['displayoptions'])) {
  114. $displayoptions = unserialize($defaultvalues['displayoptions']);
  115. if (isset($displayoptions['printintro'])) {
  116. $defaultvalues['printintro'] = $displayoptions['printintro'];
  117. }
  118. if (isset($displayoptions['printheading'])) {
  119. $defaultvalues['printheading'] = $displayoptions['printheading'];
  120. }
  121. if (isset($displayoptions['printlastmodified'])) {
  122. $defaultvalues['printlastmodified'] = $displayoptions['printlastmodified'];
  123. }
  124. if (!empty($displayoptions['popupwidth'])) {
  125. $defaultvalues['popupwidth'] = $displayoptions['popupwidth'];
  126. }
  127. if (!empty($displayoptions['popupheight'])) {
  128. $defaultvalues['popupheight'] = $displayoptions['popupheight'];
  129. }
  130. }
  131. }
  132. }