Updating to 1.7 Beta
[moodle.git] / course / edit_form.php
CommitLineData
01963b95 1<?php
01963b95 2
01963b95 3 $mform->addElement('header','general', get_string("general"));
4 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $default->category))) {
5 $displaylist = array();
6 $parentlist = array();
7 make_categories_list($displaylist, $parentlist);
8 $mform->addElement('select', "category", get_string("category"), $displaylist );
9 }
10
11 $mform->addElement('text','fullname', get_string("fullname"),'maxlength="254" size="50"');
12 $mform->addElement('text','shortname', get_string("shortname"),'maxlength="15" size="10"');
13 $mform->addElement('text','idnumber', get_string("idnumbercourse"),'maxlength="100" size="10"');
5ae70385 14 $mform->addElement('htmleditor','summary', get_string("summary"), array('rows'=>'10', 'cols'=>'65'));
01963b95 15
16 $courseformats = get_list_of_plugins("course/format");
17 $formcourseformats = array();
18
19 foreach ($courseformats as $courseformat) {
20 $formcourseformats["$courseformat"] = get_string("format$courseformat");
21 }
22
23 $mform->addElement('select', 'format', get_string("format"), $formcourseformats );
24
25 for ($i=1; $i<=52; $i++) {
26 $sectionmenu[$i] = "$i";
27 }
28 $mform->addElement('select', 'numsections', get_string("numberweeks"), $sectionmenu);
29 $mform->addElement('date_selector', 'startdate', get_string('startdate'));
30
31 unset($choices);
32 $choices["0"] = get_string("hiddensectionscollapsed");
33 $choices["1"] = get_string("hiddensectionsinvisible");
34 $mform->addElement('select', 'hiddensections', get_string("hiddensections"), $choices);
35
36 $newsitem = get_string("newsitem");
37 $newsitems = get_string("newsitems");
38 $options = array("0" => "0 $newsitems",
39 "1" => "1 $newsitem",
40 "2" => "2 $newsitems",
41 "3" => "3 $newsitems",
42 "4" => "4 $newsitems",
43 "5" => "5 $newsitems",
44 "6" => "6 $newsitems",
45 "7" => "7 $newsitems",
46 "8" => "8 $newsitems",
47 "9" => "9 $newsitems",
48 "10" => "10 $newsitems");
49 $mform->addElement('select', 'newsitems', get_string("newsitemsnumber"), $options);
50
51 unset($choices);
52 $choices["0"] = get_string("no");
53 $choices["1"] = get_string("yes");
54 $mform->addElement('select', 'showgrades', get_string("showgrades"), $choices);
55 unset($choices);
56 $choices["0"] = get_string("no");
57 $choices["1"] = get_string("yes");
58 $mform->addElement('select', 'showreports', get_string("showreports"), $choices);
59 $choices = get_max_upload_sizes($CFG->maxbytes);
60 $mform->addElement('select', 'maxbytes', get_string("maximumupload"), $choices);
61 if (!empty($CFG->allowcoursethemes)) {
62 $themes=array();
63 $themes[''] = get_string("forceno");
64 $themes += get_list_of_themes();
65 $mform->addElement('select', 'theme', get_string("forcetheme"), $themes);
66 }
67 unset($choices);
68 if (empty($disable_meta)) {
69 $meta=array();
70 $meta[0] = get_string('no');
71 $meta[1] = get_string('yes');
72 $mform->addElement('select', 'metacourse', get_string("managemeta"), $meta);
73 }else{
74 $mform->addElement('static', 'metacourse', get_string("managemeta"),
75 ((empty($default->metacourse)) ? get_string("no") : get_string("yes"))
76 . " - $disable_meta ");
77
78 }
79
80 $roles = get_assignable_roles($context);
81 asort($roles);
82 $choices = array();
83
84 if ($sitedefaultrole = get_record('role', 'id', $CFG->defaultcourseroleid)) {
85 $choices[0] = get_string('sitedefault').' ('.$sitedefaultrole->name.')';
86 } else {
87 $choices[0] = get_string('sitedefault');
88 }
89
90 $choices = $choices + $roles;
91 $defaultroleelement=$mform->addElement('select', 'defaultrole', get_string('defaultrole'), $choices );
92 if ($mform->exportValue('defaultrole') && !isset($roles[$mform->exportValue('defaultrole')])) { // Existing setting is one we can't choose
93 if ($coursedefaultrole = get_record('role', 'id', $mform->exportValue('defaultrole'))) {
94
95 $defaultroleelement->addOption(get_string('currentrole', 'role').' ('.$coursedefaultrole->name.')',-1);
96 } else {
97 $defaultroleelement->addOption(get_string('currentrole', 'role'),-1);
98 }
99 }
100
101
102 $mform->addElement('header','enrolhdr', get_string("enrolment"));
103
104 $modules = explode(',', $CFG->enrol_plugins_enabled);
105 foreach ($modules as $module) {
106 $name = get_string("enrolname", "enrol_$module");
107 $plugin = enrolment_factory::factory($module);
108 if (method_exists($plugin, 'print_entry')) {
109 $choices[$name] = $module;
110 }
111 }
112 asort($choices);
113 $choices = array_flip($choices);
114 $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string("enrolname", "enrol_$CFG->enrol").')'), $choices);
115 $mform->addElement('select', 'enrol', get_string("enrolmentplugins"), $choices );
116
117 $radio = array();
118 $radio[] = &moodleform::createElement('radio', 'enrollable', null, get_string("no"), 0);
119 $radio[] = &moodleform::createElement('radio', 'enrollable', null, get_string("yes"), 1);
120 $radio[] = &moodleform::createElement('radio', 'enrollable', null, get_string("enroldate"), 2);
121 $mform->addGroup($radio, 'enrollable', get_string("enrollable"), ' ', false);
122
123 $enroldatestartgrp = array();
124 $enroldatestartgrp[] = &moodleform::createElement('date_selector', 'enrolstartdate');
125 $enroldatestartgrp[] = &moodleform::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
126 $mform->addGroup($enroldatestartgrp, '', get_string('enrolstartdate'), ' ', false);
127
128 $enroldateendgrp = array();
129 $enroldateendgrp[] = &moodleform::createElement('date_selector', 'enrolenddate');
130 $enroldateendgrp[] = &moodleform::createElement('checkbox', 'enrolenddisabled', null, get_string('disable'));
131 $mform->addGroup($enroldateendgrp, 'enroldateendgrp', get_string('enrolenddate'), ' ', false);
132
133 $periodmenu=array();
134 $periodmenu[0] = get_string('unlimited');
135 for ($i=1; $i<=365; $i++) {
136 $seconds = $i * 86400;
137 $periodmenu[$seconds] = get_string('numdays', '', $i);
138 }
139 $mform->addElement('select', 'enrolperiod', get_string("enrolperiod"), $periodmenu);
140
141
142 $mform->addElement('header','expirynotifyhdr', get_string("expirynotify"));
143
144 unset($choices);
145 $choices["0"] = get_string("no");
146 $choices["1"] = get_string("yes");
147 $mform->addElement('select', 'expirynotify', get_string("expirynotify"), $choices);
148 $mform->addElement('select', 'notifystudents', get_string("expirynotifystudents"), $choices);
149 $thresholdmenu=array();
150 for ($i=1; $i<=30; $i++) {
151 $seconds = $i * 86400;
152 $thresholdmenu[$seconds] = get_string('numdays', '', $i);
153 }
154 $mform->addElement('select', 'expirythreshold', get_string("expirythreshold"), $thresholdmenu);
155
156
157 $mform->addElement('header','', get_string("groupmode"));
158 unset($choices);
159 $choices[NOGROUPS] = get_string("groupsnone");
160 $choices[SEPARATEGROUPS] = get_string("groupsseparate");
161 $choices[VISIBLEGROUPS] = get_string("groupsvisible");
162 $mform->addElement('select', 'groupmode', get_string("groupmode"), $choices);
163 unset($choices);
164 $choices["0"] = get_string("no");
165 $choices["1"] = get_string("yes");
166 $mform->addElement('select', 'groupmodeforce', get_string("force"), $choices);
167 $mform->addElement('header','', get_string("availability"));
168 unset($choices);
169 $choices["0"] = get_string("courseavailablenot");
170 $choices["1"] = get_string("courseavailable");
171 $mform->addElement('select', 'visible', get_string("availability"), $choices);
172 $mform->addElement('text', 'password', get_string("enrolmentkey"), 'size="25"');
173 unset($choices);
174 $choices["0"] = get_string("guestsno");
175 $choices["1"] = get_string("guestsyes");
176 $choices["2"] = get_string("guestskey");
177 $mform->addElement('select', 'guest', get_string("opentoguests"), $choices);
178 if (isset($course) && method_exists(enrolment_factory::factory($course->enrol), 'print_entry') && $course->enrol != 'manual') {
179 $costgroup=array();
180 $currencies = get_list_of_currencies();
181 $costgroup[]= &moodleform::createElement('text','cost', '', 'maxlength="6" size="6"');
182 $costgroup[]= &moodleform::createElement('select', 'currency', '', $currencies);
183 $mform->addGroup($costgroup, 'costgrp', get_string("cost"), '&nbsp;', false);
184 }
185
186 $mform->addElement('header','', get_string("language"));
187 $languages=array();
188 $languages[''] = get_string("forceno");
189 $languages += get_list_of_languages();
190 $mform->addElement('select', 'lang', get_string("forcelanguage"), $languages);
5f2256f3 191
01963b95 192 if(!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $default->category))) {
5f2256f3 193 $mform->addElement('hidden', 'category', null);
01963b95 194 }
5f2256f3 195 $mform->addElement('hidden', 'id', null);
01963b95 196
197 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) && ((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) {
198 unset($options);
199 $options[0] = get_string("no");
200 $options[1] = get_string("yes");
201 $mform->addElement('header', '', get_string("restrictmodules"));
202 $mform->addElement('select', 'restrictmodules', get_string("restrictmodules"), $options,
49c53687 203 array('onChange'=>"document.getElementById('id_allowedmods').disabled=".
01963b95 204 "((this.selectedIndex==0)?true:false);"));
205 $mods = array(0=>get_string('allownone'));
206 $mods += get_records_menu("modules", '','','','id, name');
0d26ea7a 207 $disabled=($mform->exportValue('restrictmodules')==1) ? array() :array('disabled' => 'disabled') ;
208
209
01963b95 210 $mform->addElement('select', 'allowedmods', get_string("to"),$mods,
230a910a 211 array('multiple'=>"multiple", 'size'=>"10", 'id'=>"allowedmods")
212 +$disabled);
01963b95 213 }else {
214 $mform->addElement('hidden', 'restrictmodules', $default->restrictmodules);
215 }
5f2256f3 216 $mform->setHelpButtons(array('category'=>array("coursecategory", get_string("category")),
01963b95 217 'fullname'=>array("coursefullname", get_string("fullname")),
218 'shortname'=>array("courseshortname", get_string("shortname")),
219 'idnumber'=>array("courseidnumber", get_string("idnumbercourse")),
220 'summary'=>array("text", get_string("helptext")),
221 'format'=>array("courseformats", get_string("courseformats")),
222 'summary'=>array("coursestartdate", get_string("startdate")),
223 'enrol'=>array("courseenrolmentplugins", get_string("enrolmentplugins")),
224 'enrollable'=>array("courseenrollable", get_string("enrollable")),
225 'expirynotify'=>array("expirynotify", get_string("expirynotify")),
226 'notifystudents'=>array("expirynotifystudents", get_string("expirynotifystudents")),
227 'expirythreshold'=>array("expirythreshold", get_string("expirythreshold")),
228 'groupmode'=>array("groupmode", get_string("groupmode")),
229 'groupmodeforce'=>array("groupmodeforce", get_string("groupmodeforce")),
230 'visible'=>array("courseavailability", get_string("availability")),
231 'password'=>array("enrolmentkey", get_string("enrolmentkey")),
232 'guest'=>array("guestaccess", get_string("opentoguests")),
233 'costgrp'=>array("cost", get_string("cost")),
234 'hiddensections'=>array("coursehiddensections", get_string("hiddensections")),
235 'newsitems'=>array("coursenewsitems", get_string("newsitemsnumber")),
236 'showgrades'=>array("coursegrades", get_string("grades")),
237 'showreports'=>array("coursereports", get_string("activityreport")),
238 'maxbytes'=>array("courseuploadsize", get_string("maximumupload")),
239 'metacourse'=>array("metacourse", get_string("metacourse")),
240 'defaultrole'=>array("coursedefaultrole", get_string("defaultrole"))),
241 true);
242 $mform->addElement('submit', 'submit', get_string("savechanges"));
243
244 $mform->addRule('fullname', get_string("missingfullname"), 'required', null, 'client');
245 $mform->addRule('shortname', get_string("missingshortname"), 'required', null, 'client');
246 $mform->addRule('summary', get_string("missingsummary"), 'required', null, 'client');
247 $mform->addRule('category', get_string("missingcategory"), 'required', null, 'client');
248
249 /**
250 * a Form rule check - if we need to create rules which involve the contents of more than one
251 * field this is the way to do it. We can do it all at once in one function or create several
252 * form rules.
253 *
254 * @param array $fields values from form without slashes
255 * @return mixed array of errors or true if passed check
256 */
257 function form_check($fields){
258 global $course;
259 $errors= array();
260 if ($foundcourses = get_records("course", "shortname", addslashes($fields['shortname']))) {
261 if (!empty($course->id)) {
262 unset($foundcourses[$course->id]);
263 }
264 if (!empty($foundcourses)) {
265 foreach ($foundcourses as $foundcourse) {
266 $foundcoursenames[] = $foundcourse->fullname;
267 }
268 $foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
269
270 $errors['shortname']= get_string("shortnametaken", "", $foundcoursenamestring);
271
272 }
273
274
275 }
276 if (empty($fields['enrolenddisabled'])){
277 $enrolenddate=make_timestamp($fields['enrolenddate']['year'],
278 $fields['enrolenddate']['month'],
279 $fields['enrolenddate']['day']);
280 $enrolstartdate=make_timestamp($fields['enrolstartdate']['year'],
281 $fields['enrolstartdate']['month'],
282 $fields['enrolstartdate']['day']);
283 if ($enrolenddate <= $enrolstartdate){
284 $errors['enroldateendgrp']=get_string("enrolenddaterror");
285 }
286 }
287 if (0==count($errors)){
288 return true;
289 }else {
290 return $errors;
291 }
292 }
293 $mform->addFormRule('form_check');
294
2462a50a 295 $renderer =& $mform->defaultRenderer();
01963b95 296 $renderer->addStopFieldsetElements('submit');
01963b95 297?>