|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die; 00028 00029 require_once($CFG->dirroot.'/course/moodleform_mod.php'); 00030 require_once($CFG->dirroot.'/mod/page/locallib.php'); 00031 require_once($CFG->libdir.'/filelib.php'); 00032 00033 class mod_page_mod_form extends moodleform_mod { 00034 function definition() { 00035 global $CFG, $DB; 00036 00037 $mform = $this->_form; 00038 00039 $config = get_config('page'); 00040 00041 //------------------------------------------------------- 00042 $mform->addElement('header', 'general', get_string('general', 'form')); 00043 $mform->addElement('text', 'name', get_string('name'), array('size'=>'48')); 00044 if (!empty($CFG->formatstringstriptags)) { 00045 $mform->setType('name', PARAM_TEXT); 00046 } else { 00047 $mform->setType('name', PARAM_CLEANHTML); 00048 } 00049 $mform->addRule('name', null, 'required', null, 'client'); 00050 $this->add_intro_editor($config->requiremodintro); 00051 00052 //------------------------------------------------------- 00053 $mform->addElement('header', 'contentsection', get_string('contentheader', 'page')); 00054 $mform->addElement('editor', 'page', get_string('content', 'page'), null, page_get_editor_options($this->context)); 00055 $mform->addRule('page', get_string('required'), 'required', null, 'client'); 00056 00057 //------------------------------------------------------- 00058 $mform->addElement('header', 'optionssection', get_string('optionsheader', 'page')); 00059 00060 if ($this->current->instance) { 00061 $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display); 00062 } else { 00063 $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions)); 00064 } 00065 if (count($options) == 1) { 00066 $mform->addElement('hidden', 'display'); 00067 $mform->setType('display', PARAM_INT); 00068 reset($options); 00069 $mform->setDefault('display', key($options)); 00070 } else { 00071 $mform->addElement('select', 'display', get_string('displayselect', 'page'), $options); 00072 $mform->setDefault('display', $config->display); 00073 $mform->setAdvanced('display', $config->display_adv); 00074 } 00075 00076 if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) { 00077 $mform->addElement('text', 'popupwidth', get_string('popupwidth', 'page'), array('size'=>3)); 00078 if (count($options) > 1) { 00079 $mform->disabledIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP); 00080 } 00081 $mform->setType('popupwidth', PARAM_INT); 00082 $mform->setDefault('popupwidth', $config->popupwidth); 00083 $mform->setAdvanced('popupwidth', $config->popupwidth_adv); 00084 00085 $mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3)); 00086 if (count($options) > 1) { 00087 $mform->disabledIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP); 00088 } 00089 $mform->setType('popupheight', PARAM_INT); 00090 $mform->setDefault('popupheight', $config->popupheight); 00091 $mform->setAdvanced('popupheight', $config->popupheight_adv); 00092 } 00093 00094 $mform->addElement('advcheckbox', 'printheading', get_string('printheading', 'page')); 00095 $mform->setDefault('printheading', $config->printheading); 00096 $mform->setAdvanced('printintro', $config->printheading_adv); 00097 $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page')); 00098 $mform->setDefault('printintro', $config->printintro); 00099 $mform->setAdvanced('printintro', $config->printintro_adv); 00100 00101 // add legacy files flag only if used 00102 if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) { 00103 $options = array(RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'page'), 00104 RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page')); 00105 $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options); 00106 $mform->setAdvanced('legacyfiles', 1); 00107 } 00108 00109 //------------------------------------------------------- 00110 $this->standard_coursemodule_elements(); 00111 00112 //------------------------------------------------------- 00113 $this->add_action_buttons(); 00114 00115 //------------------------------------------------------- 00116 $mform->addElement('hidden', 'revision'); 00117 $mform->setType('revision', PARAM_INT); 00118 $mform->setDefault('revision', 1); 00119 } 00120 00121 function data_preprocessing(&$default_values) { 00122 if ($this->current->instance) { 00123 $draftitemid = file_get_submitted_draft_itemid('page'); 00124 $default_values['page']['format'] = $default_values['contentformat']; 00125 $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']); 00126 $default_values['page']['itemid'] = $draftitemid; 00127 } 00128 if (!empty($default_values['displayoptions'])) { 00129 $displayoptions = unserialize($default_values['displayoptions']); 00130 if (isset($displayoptions['printintro'])) { 00131 $default_values['printintro'] = $displayoptions['printintro']; 00132 } 00133 if (isset($displayoptions['printheading'])) { 00134 $default_values['printheading'] = $displayoptions['printheading']; 00135 } 00136 if (!empty($displayoptions['popupwidth'])) { 00137 $default_values['popupwidth'] = $displayoptions['popupwidth']; 00138 } 00139 if (!empty($displayoptions['popupheight'])) { 00140 $default_values['popupheight'] = $displayoptions['popupheight']; 00141 } 00142 } 00143 } 00144 } 00145