Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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', 'printintro', get_string('printintro', 'page'));
92
        $mform->setDefault('printintro', $config->printintro);
93
        $mform->addElement('advcheckbox', 'printlastmodified', get_string('printlastmodified', 'page'));
94
        $mform->setDefault('printlastmodified', $config->printlastmodified);
95
 
96
        // add legacy files flag only if used
97
        if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
98
            $options = array(RESOURCELIB_LEGACYFILES_DONE   => get_string('legacyfilesdone', 'page'),
99
                             RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
100
            $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
101
            $mform->setAdvanced('legacyfiles', 1);
102
        }
103
 
104
        //-------------------------------------------------------
105
        $this->standard_coursemodule_elements();
106
 
107
        //-------------------------------------------------------
108
        $this->add_action_buttons();
109
 
110
        //-------------------------------------------------------
111
        $mform->addElement('hidden', 'revision');
112
        $mform->setType('revision', PARAM_INT);
113
        $mform->setDefault('revision', 1);
114
    }
115
 
116
    /**
117
     * Enforce defaults here.
118
     *
119
     * @param array $defaultvalues Form defaults
120
     * @return void
121
     **/
122
    public function data_preprocessing(&$defaultvalues) {
123
        if ($this->current->instance) {
124
            $draftitemid = file_get_submitted_draft_itemid('page');
125
            $defaultvalues['page']['format'] = $defaultvalues['contentformat'];
126
            $defaultvalues['page']['text']   = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page',
127
                    'content', 0, page_get_editor_options($this->context), $defaultvalues['content']);
128
            $defaultvalues['page']['itemid'] = $draftitemid;
129
        }
130
        if (!empty($defaultvalues['displayoptions'])) {
131
            $displayoptions = (array) unserialize_array($defaultvalues['displayoptions']);
132
            if (isset($displayoptions['printintro'])) {
133
                $defaultvalues['printintro'] = $displayoptions['printintro'];
134
            }
135
            if (isset($displayoptions['printlastmodified'])) {
136
                $defaultvalues['printlastmodified'] = $displayoptions['printlastmodified'];
137
            }
138
            if (!empty($displayoptions['popupwidth'])) {
139
                $defaultvalues['popupwidth'] = $displayoptions['popupwidth'];
140
            }
141
            if (!empty($displayoptions['popupheight'])) {
142
                $defaultvalues['popupheight'] = $displayoptions['popupheight'];
143
            }
144
        }
145
    }
146
}
147