PageRenderTime 62ms CodeModel.GetById 52ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/local/campusconnect/fakecms_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 206 lines | 145 code | 24 blank | 37 comment | 10 complexity | ba5e48a80e55c6d1848bba58692cf1eb MD5 | raw file
  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/**
 18 * Supports the creation of resources via fakecms.php
 19 *
 20 * @package   local_campusconnect
 21 * @copyright 2012 Davo Smith, Synergy Learning
 22 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 23 */
 24
 25defined('MOODLE_INTERNAL') || die();
 26
 27global $CFG;
 28require_once($CFG->libdir.'/formslib.php');
 29
 30
 31/** Form for entering CMS data */
 32class fakecms_form extends moodleform {
 33
 34    public function definition() {
 35        $mform = $this->_form;
 36
 37        $participants = $this->_customdata['participants'];
 38        $cmsparticipant = $this->_customdata['cmsparticipant'];
 39        $thisparticipant = $this->_customdata['thisparticipant'];
 40        $dirresources = $this->_customdata['dirresources'];
 41        if (!empty($dirresources)) {
 42            $dirresources = array_combine($dirresources, $dirresources);
 43        }
 44        $crsresources = $this->_customdata['crsresources'];
 45        if (!empty($crsresources)) {
 46            $crsresources = array_combine($crsresources, $crsresources);
 47        }
 48        $mbrresources = $this->_customdata['mbrresources'];
 49        if (!empty($mbrresources)) {
 50            $mbrresources = array_combine($mbrresources, $mbrresources);
 51        }
 52
 53        $actions = array(
 54            'create' => 'create',
 55            'retrieve' => 'retrieve',
 56            'update' => 'update',
 57            'delete' => 'delete',
 58        );
 59
 60        // General settings
 61        $mform->addElement('header', 'general', 'General');
 62        $mform->addElement('select', 'srcpart', 'Send from', $participants);
 63        $mform->setDefault('srcpart', $cmsparticipant);
 64        $mform->addElement('select', 'dstpart', 'Send to', $participants);
 65        $mform->setDefault('dstpart', $thisparticipant);
 66
 67        // Directory trees
 68        $mform->addElement('header', 'dirtree', 'Directory tree');
 69        $mform->addElement('select', 'diraction', 'Action', $actions);
 70        $mform->addElement('select', 'dirresourceid', 'Existing resource', $dirresources);
 71        $mform->disabledIf('dirresourceid', 'diraction', 'eq', 'create');
 72
 73        $mform->addElement('text', 'dirtreetitle', 'Directory tree name');
 74        $mform->setType('dirtreetitle', PARAM_TEXT);
 75        $mform->setDefault('dirtreetitle', 'Directory tree');
 76        $mform->addElement('text', 'dirrootid', 'Root directory id', array('size' => 10));
 77        $mform->setType('dirrootid', PARAM_TEXT);
 78        $mform->addElement('text', 'dirid', 'Directory id', array('size' => 10));
 79        $mform->setType('dirid', PARAM_TEXT);
 80        $mform->addElement('text', 'dirtitle', 'Directory title');
 81        $mform->setType('dirtitle', PARAM_TEXT);
 82        $mform->addElement('text', 'dirparentid', 'Parent directory id', array('size' => 10));
 83        $mform->setType('dirparentid', PARAM_TEXT);
 84        $mform->addElement('text', 'dirorder', 'Directory order (within parent)', array('size' => 10));
 85        $mform->setType('dirorder', PARAM_TEXT);
 86
 87        $mform->addElement('submit', 'dirsubmit', 'Send directory request');
 88        
 89        // Courses
 90        $mform->addElement('header', 'course', 'Course');
 91        $mform->addElement('select', 'crsaction', 'Action', $actions);
 92        $mform->addElement('select', 'crsresourceid', 'Existing resource', $crsresources);
 93        $mform->disabledIf('crsresourceid', 'crsaction', 'eq', 'create');
 94
 95        $mform->addElement('text', 'crsorganisation', 'Course organisation');
 96        $mform->setType('crsorganisation', PARAM_TEXT);
 97        $mform->addElement('text', 'crsid', 'Course id', array('size' => 10));
 98        $mform->setType('crsid', PARAM_TEXT);
 99        $mform->addElement('text', 'crsterm', 'Term', array('size' => 10));
100        $mform->setType('crsterm', PARAM_TEXT);
101        $mform->addElement('text', 'crstitle', 'Title');
102        $mform->setType('crstitle', PARAM_TEXT);
103        $mform->addElement('text', 'crstype', 'Course type');
104        $mform->setType('crstype', PARAM_TEXT);
105        $mform->addElement('text', 'crsmaxpart', 'Max participants', array('size' => 10));
106        $mform->setType('crsmaxpart', PARAM_TEXT);
107
108        /*
109        for ($i=1; $i<=2; $i++) {
110            $grp = array(
111                $mform->createElement('text', "crslecturerfirst[$i]", ''),
112                $mform->createElement('text', "crslecturerlast[$i]", ''),
113            );
114            $mform->setType("crslecturerfirst[$i]", PARAM_TEXT);
115            $mform->setType("crslecturerlast[$i]", PARAM_TEXT);
116            $mform->addGroup($grp, "crslecturer[$i]", "Lecturer $i (first, last)", ' ', false);
117        }
118        */
119
120        for ($i=1; $i<=3; $i++) {
121            $grp = array(
122                $mform->createElement('text', "crsallparent[$i]", '', array('size' => 10)),
123                $mform->createElement('text', "crsallorder[$i]", '', array('size' => 10)),
124            );
125            $mform->setType("crsallparent[$i]", PARAM_TEXT);
126            $mform->setType("crsallorder[$i]", PARAM_TEXT);
127            $mform->addGroup($grp, "crsallocation[$i]", "Allocation $i (parentdir, order)", ' ', false);
128        }
129
130        $mform->addElement('static', 'crsp', '', 'Parallel groups');
131        $mform->setAdvanced('crsp');
132        $mform->addElement('select', 'crsparallel', 'Parallel group scenario', array(-1 => 'none', 1 => 'One course', 2 => 'Separate groups', 3 => 'Separate courses', 4 => 'Separate lecturers'));
133        $mform->setAdvanced("crsparallel");
134        for ($i=1; $i<=3; $i++) {
135            $mform->addElement('text', "crsptitle[$i]", "PGroup$i title");
136            $mform->setAdvanced("crsptitle[$i]");
137            $mform->setType("crsptitle[$i]", PARAM_TEXT);
138            $mform->addElement('text', "crspid[$i]", "PGroup$i id", array('size' => 10));
139            $mform->setType("crspid[$i]", PARAM_TEXT);
140            $mform->setAdvanced("crspid[$i]");
141            $mform->addElement('text', "crspcomment[$i]", "PGroup$i comment", array('size' => 40));
142            $mform->setType("crspcomment[$i]", PARAM_TEXT);
143            $mform->setAdvanced("crspcomment[$i]");
144            for ($j=1; $j<=3; $j++) {
145                $grp = array(
146                    $mform->createElement('text', "crsplecturerfirst[$i][$j]", ''),
147                    $mform->createElement('text', "crsplecturerlast[$i][$j]", ''),
148                );
149                $mform->setType("crsplecturerfirst[$i][$j]", PARAM_TEXT);
150                $mform->setType("crsplecturerlast[$i][$j]", PARAM_TEXT);
151                $mform->addGroup($grp, "crsplecturer[$i][$j]", "Lecturer $j (first, last)", ' ', false);
152                $mform->setAdvanced("crsplecturer[$i][$j]");
153            }
154            $mform->addElement('static', "crsp$i", '', '');
155            $mform->setAdvanced("crsp$i");
156        }
157
158        $mform->addElement('submit', 'crssubmit', 'Send course request');
159
160        // Membership
161        $mform->addElement('header', 'membership', 'Course membership');
162        $mform->addElement('select', 'mbraction', 'Action', $actions);
163        $mform->addElement('select', 'mbrresourceid', 'Existing resource', $mbrresources);
164        $mform->disabledIf('mbrresourceid', 'mbraction', 'eq', 'create');
165        $mform->addElement('text', 'mbrcourseid', 'Course id', array('size' => 10));
166        $mform->setType('mbrcourseid', PARAM_TEXT);
167        for ($i=1; $i<=5; $i++) {
168            $mform->addElement('static', "mbr$i", '', '');
169            $mform->addElement('text', "mbrid[$i]", "Person ID $i (username)");
170            $mform->setType("mbrid[$i]", PARAM_TEXT);
171            $mform->addElement('text', "mbrrole[$i]", "Role $i");
172            $mform->setType("mbrrole[$i]", PARAM_TEXT);
173            for ($j=1; $j<=3; $j++) {
174                $mform->addElement('text', "mbrpgid[$i][$j]", "PGroup $i.$j ID", array('size' => 10));
175                $mform->setType("mbrpgid[$i][$j]", PARAM_TEXT);
176                $mform->setAdvanced("mbrpgid[$i][$j]");
177                $mform->addElement('text', "mbrpgrole[$i][$j]", "PGroup $i.$j role");
178                $mform->setType("mbrpgrole[$i][$j]", PARAM_TEXT);
179                $mform->setAdvanced("mbrpgrole[$i][$j]");
180            }
181        }
182
183        $mform->addElement('submit', 'mbrsubmit', 'Send membership request');
184
185        $js = <<<END
186<script type="text/javascript">
187var elnames = ['dir', 'crs', 'mbr'], i, prefix, sel, fnchange;
188
189fnchange = function (e) {
190        var name = e.currentTarget.id;
191        var prefix = name.substr(3, 3);
192        var action = document.getElementById('id_' + prefix + 'action');
193        action.options[1].selected = true;
194};
195
196for (i = 0; i < elnames.length; i += 1) {
197    prefix = elnames[i];
198    sel = document.getElementById('id_' + prefix + 'resourceid');
199    sel.onchange = fnchange;
200}
201</script>
202END;
203
204        $mform->addElement('static', 'javascript', '', $js);
205    }
206}