PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/page/mod_form.php

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