campusconnect /local/campusconnect/fakecms_form.php

Language PHP Lines 207
MD5 Hash ba5e48a80e55c6d1848bba58692cf1eb Estimated Cost $3,531 (why?)
Repository https://bitbucket.org/synergylearning/campusconnect.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Supports the creation of resources via fakecms.php
 *
 * @package   local_campusconnect
 * @copyright 2012 Davo Smith, Synergy Learning
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->libdir.'/formslib.php');


/** Form for entering CMS data */
class fakecms_form extends moodleform {

    public function definition() {
        $mform = $this->_form;

        $participants = $this->_customdata['participants'];
        $cmsparticipant = $this->_customdata['cmsparticipant'];
        $thisparticipant = $this->_customdata['thisparticipant'];
        $dirresources = $this->_customdata['dirresources'];
        if (!empty($dirresources)) {
            $dirresources = array_combine($dirresources, $dirresources);
        }
        $crsresources = $this->_customdata['crsresources'];
        if (!empty($crsresources)) {
            $crsresources = array_combine($crsresources, $crsresources);
        }
        $mbrresources = $this->_customdata['mbrresources'];
        if (!empty($mbrresources)) {
            $mbrresources = array_combine($mbrresources, $mbrresources);
        }

        $actions = array(
            'create' => 'create',
            'retrieve' => 'retrieve',
            'update' => 'update',
            'delete' => 'delete',
        );

        // General settings
        $mform->addElement('header', 'general', 'General');
        $mform->addElement('select', 'srcpart', 'Send from', $participants);
        $mform->setDefault('srcpart', $cmsparticipant);
        $mform->addElement('select', 'dstpart', 'Send to', $participants);
        $mform->setDefault('dstpart', $thisparticipant);

        // Directory trees
        $mform->addElement('header', 'dirtree', 'Directory tree');
        $mform->addElement('select', 'diraction', 'Action', $actions);
        $mform->addElement('select', 'dirresourceid', 'Existing resource', $dirresources);
        $mform->disabledIf('dirresourceid', 'diraction', 'eq', 'create');

        $mform->addElement('text', 'dirtreetitle', 'Directory tree name');
        $mform->setType('dirtreetitle', PARAM_TEXT);
        $mform->setDefault('dirtreetitle', 'Directory tree');
        $mform->addElement('text', 'dirrootid', 'Root directory id', array('size' => 10));
        $mform->setType('dirrootid', PARAM_TEXT);
        $mform->addElement('text', 'dirid', 'Directory id', array('size' => 10));
        $mform->setType('dirid', PARAM_TEXT);
        $mform->addElement('text', 'dirtitle', 'Directory title');
        $mform->setType('dirtitle', PARAM_TEXT);
        $mform->addElement('text', 'dirparentid', 'Parent directory id', array('size' => 10));
        $mform->setType('dirparentid', PARAM_TEXT);
        $mform->addElement('text', 'dirorder', 'Directory order (within parent)', array('size' => 10));
        $mform->setType('dirorder', PARAM_TEXT);

        $mform->addElement('submit', 'dirsubmit', 'Send directory request');
        
        // Courses
        $mform->addElement('header', 'course', 'Course');
        $mform->addElement('select', 'crsaction', 'Action', $actions);
        $mform->addElement('select', 'crsresourceid', 'Existing resource', $crsresources);
        $mform->disabledIf('crsresourceid', 'crsaction', 'eq', 'create');

        $mform->addElement('text', 'crsorganisation', 'Course organisation');
        $mform->setType('crsorganisation', PARAM_TEXT);
        $mform->addElement('text', 'crsid', 'Course id', array('size' => 10));
        $mform->setType('crsid', PARAM_TEXT);
        $mform->addElement('text', 'crsterm', 'Term', array('size' => 10));
        $mform->setType('crsterm', PARAM_TEXT);
        $mform->addElement('text', 'crstitle', 'Title');
        $mform->setType('crstitle', PARAM_TEXT);
        $mform->addElement('text', 'crstype', 'Course type');
        $mform->setType('crstype', PARAM_TEXT);
        $mform->addElement('text', 'crsmaxpart', 'Max participants', array('size' => 10));
        $mform->setType('crsmaxpart', PARAM_TEXT);

        /*
        for ($i=1; $i<=2; $i++) {
            $grp = array(
                $mform->createElement('text', "crslecturerfirst[$i]", ''),
                $mform->createElement('text', "crslecturerlast[$i]", ''),
            );
            $mform->setType("crslecturerfirst[$i]", PARAM_TEXT);
            $mform->setType("crslecturerlast[$i]", PARAM_TEXT);
            $mform->addGroup($grp, "crslecturer[$i]", "Lecturer $i (first, last)", ' ', false);
        }
        */

        for ($i=1; $i<=3; $i++) {
            $grp = array(
                $mform->createElement('text', "crsallparent[$i]", '', array('size' => 10)),
                $mform->createElement('text', "crsallorder[$i]", '', array('size' => 10)),
            );
            $mform->setType("crsallparent[$i]", PARAM_TEXT);
            $mform->setType("crsallorder[$i]", PARAM_TEXT);
            $mform->addGroup($grp, "crsallocation[$i]", "Allocation $i (parentdir, order)", ' ', false);
        }

        $mform->addElement('static', 'crsp', '', 'Parallel groups');
        $mform->setAdvanced('crsp');
        $mform->addElement('select', 'crsparallel', 'Parallel group scenario', array(-1 => 'none', 1 => 'One course', 2 => 'Separate groups', 3 => 'Separate courses', 4 => 'Separate lecturers'));
        $mform->setAdvanced("crsparallel");
        for ($i=1; $i<=3; $i++) {
            $mform->addElement('text', "crsptitle[$i]", "PGroup$i title");
            $mform->setAdvanced("crsptitle[$i]");
            $mform->setType("crsptitle[$i]", PARAM_TEXT);
            $mform->addElement('text', "crspid[$i]", "PGroup$i id", array('size' => 10));
            $mform->setType("crspid[$i]", PARAM_TEXT);
            $mform->setAdvanced("crspid[$i]");
            $mform->addElement('text', "crspcomment[$i]", "PGroup$i comment", array('size' => 40));
            $mform->setType("crspcomment[$i]", PARAM_TEXT);
            $mform->setAdvanced("crspcomment[$i]");
            for ($j=1; $j<=3; $j++) {
                $grp = array(
                    $mform->createElement('text', "crsplecturerfirst[$i][$j]", ''),
                    $mform->createElement('text', "crsplecturerlast[$i][$j]", ''),
                );
                $mform->setType("crsplecturerfirst[$i][$j]", PARAM_TEXT);
                $mform->setType("crsplecturerlast[$i][$j]", PARAM_TEXT);
                $mform->addGroup($grp, "crsplecturer[$i][$j]", "Lecturer $j (first, last)", ' ', false);
                $mform->setAdvanced("crsplecturer[$i][$j]");
            }
            $mform->addElement('static', "crsp$i", '', '');
            $mform->setAdvanced("crsp$i");
        }

        $mform->addElement('submit', 'crssubmit', 'Send course request');

        // Membership
        $mform->addElement('header', 'membership', 'Course membership');
        $mform->addElement('select', 'mbraction', 'Action', $actions);
        $mform->addElement('select', 'mbrresourceid', 'Existing resource', $mbrresources);
        $mform->disabledIf('mbrresourceid', 'mbraction', 'eq', 'create');
        $mform->addElement('text', 'mbrcourseid', 'Course id', array('size' => 10));
        $mform->setType('mbrcourseid', PARAM_TEXT);
        for ($i=1; $i<=5; $i++) {
            $mform->addElement('static', "mbr$i", '', '');
            $mform->addElement('text', "mbrid[$i]", "Person ID $i (username)");
            $mform->setType("mbrid[$i]", PARAM_TEXT);
            $mform->addElement('text', "mbrrole[$i]", "Role $i");
            $mform->setType("mbrrole[$i]", PARAM_TEXT);
            for ($j=1; $j<=3; $j++) {
                $mform->addElement('text', "mbrpgid[$i][$j]", "PGroup $i.$j ID", array('size' => 10));
                $mform->setType("mbrpgid[$i][$j]", PARAM_TEXT);
                $mform->setAdvanced("mbrpgid[$i][$j]");
                $mform->addElement('text', "mbrpgrole[$i][$j]", "PGroup $i.$j role");
                $mform->setType("mbrpgrole[$i][$j]", PARAM_TEXT);
                $mform->setAdvanced("mbrpgrole[$i][$j]");
            }
        }

        $mform->addElement('submit', 'mbrsubmit', 'Send membership request');

        $js = <<<END
<script type="text/javascript">
var elnames = ['dir', 'crs', 'mbr'], i, prefix, sel, fnchange;

fnchange = function (e) {
        var name = e.currentTarget.id;
        var prefix = name.substr(3, 3);
        var action = document.getElementById('id_' + prefix + 'action');
        action.options[1].selected = true;
};

for (i = 0; i < elnames.length; i += 1) {
    prefix = elnames[i];
    sel = document.getElementById('id_' + prefix + 'resourceid');
    sel.onchange = fnchange;
}
</script>
END;

        $mform->addElement('static', 'javascript', '', $js);
    }
}
Back to Top