1: <helper title="Slot Creation" requiredpriv="mgq">
2: <state name="START" title="Specify Required Attributes"
3: help="Slot_RequiredAttributes">
4:
5: <nextstate>OPTIONAL</nextstate>
6:
7: <exec>
8: if (!exists($helper->{'VARS'}{'name'}) ||
9: $helper->{'VARS'}{'name'} !~ /\S/) {
10: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
11: if (exists($env{'form.name'}) ||
12: $env{'form.name'} =~ /\S/) {
13: $helper->{'VARS'}{'name'}=$env{'form.name'};
14: $helper->{VARS}{'origname'}=$env{'form.name'};
15: $helper->{DATA}{copy} = 1;
16: }
17: }
18: $helper->{DATA}{origslot} = sub {
19: my ($which,$default)=@_;
20: if (!exists($helper->{'VARS'}{'name'}) ||
21: $helper->{'VARS'}{'name'} !~ /\S/) {
22: return $default;
23: }
24: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
25: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
26: my $name=$helper->{VARS}{'origname'};
27: my %slot=&Apache::lonnet::get('slots', [$name], $cdom, $cnum);
28: if (!ref($slot{$name})) { return $default; }
29: if (!exists($slot{$name}{$which})) { return $default; }
30: return $slot{$name}{$which};
31: }
32: </exec>
33: <message>
34: <br />Name: <br />
35: </message>
36: <string variable="name" size="30">
37: <validator>
38: if ($val=~/^\s*$/) { return 'Must specify a name'; }
39: if ($val=~/\s/) { return 'Must not contain spaces'; }
40: if ($val=~/\W/) { return 'Must contain only letters, numbers and _'; }
41: return undef;
42: </validator>
43: <defaultvalue>
44: return $helper->{'VARS'}{'name'};
45: </defaultvalue>
46: </string>
47: <condition>
48: <clause>$helper->{DATA}{copy}</clause>
49: <message>
50: <p>Changing the Name will create a new slot with the new name, and not rename the existing slot.</p>
51: </message>
52: </condition>
53: <message>
54: <br />Start time:<br />
55: </message>
56: <date variable="starttime" hoursminutes="1">
57: <defaultvalue>
58: return &{$helper->{DATA}{origslot}}('starttime');
59: </defaultvalue>
60: </date>
61: <message>
62: <br />End time:<br />
63: </message>
64: <date variable="endtime" hoursminutes="1">
65: <defaultvalue>
66: return &{$helper->{DATA}{origslot}}('endtime');
67: </defaultvalue>
68: <validator>
69: if ($val < $helper->{'VARS'}{'starttime'}) {
70: return 'End time must be later than the start time.';
71: }
72: return undef;
73: </validator>
74: </date>
75: <message>
76: <br />Type:
77: </message>
78: <choices variable="type">
79: <choice computer='preassigned'>Instructor assignable.</choice>
80: <choice computer='schedulable_student'>Student selectable.</choice>
81: <defaultvalue>
82: return &{$helper->{DATA}{origslot}}('type','preassigned');
83: </defaultvalue>
84: </choices>
85: </state>
86:
87:
88: <state name="OPTIONAL" title="Specify Optional Attributes"
89: help="Slot_OptionalAttributes">
90: <message>
91: <p>Description:<br />
92: </message>
93: <string variable="description" size="60">
94: <defaultvalue>
95: return &{$helper->{DATA}{origslot}}('description');
96: </defaultvalue>
97: </string>
98: <condition>
99: <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
100: <message>
101: </p><p>Time students can start reserving:<br />
102: </message>
103: <date variable="startreserve" hoursminutes="1" anytime="1">
104: <defaultvalue>
105: return &{$helper->{DATA}{origslot}}('startreserve','anytime');
106: </defaultvalue>
107: <validator>
108: if (defined($val) && $val > $helper->{'VARS'}{'starttime'}) {
109: return 'Reservation time must come before the slot has started.';
110: }
111: return undef;
112: </validator>
113: </date>
114: <message>
115: </p><p>Time students can no longer reserve:<br />
116: </message>
117: <date variable="endreserve" hoursminutes="1" anytime="1">
118: <defaultvalue>
119: return &{$helper->{DATA}{origslot}}('endreserve','anytime');
120: </defaultvalue>
121: <validator>
122: if (defined($val) && $val > $helper->{'VARS'}{'starttime'}) {
123: return 'Reservation end time must come before the slot has started.';
124: }
125: return undef;
126: </validator>
127: </date>
128: <message>
129: </p><p>Maximum number of students allowed in this slot:<br />
130: </message>
131: <string variable="maxspace" size="4">
132: <validator>
133: if ($val ne '' && $val=~/\D/) { return 'Must be numeric.'; }
134: return undef;
135: </validator>
136: <defaultvalue>
137: return &{$helper->{DATA}{origslot}}('maxspace');
138: </defaultvalue>
139: </string>
140: <message>
141: </p><p>Period of time when this slot can only be uniquely chosen:<br /> Start:
142: </message>
143: <date variable="startunique" hoursminutes="1" anytime="1">
144: <defaultvalue>
145: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
146: if ($default eq 'anytime') { return 'anytime' };
147: if (ref($default)) { return $default->[0]; }
148: return 'anytime';
149: </defaultvalue>
150: </date>
151: <message><br /> End: </message>
152: <date variable="endunique" hoursminutes="1" anytime="1">
153: <defaultvalue>
154: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
155: if ($default eq 'anytime') { return 'anytime' };
156: if (ref($default)) { return $default->[1]; }
157: return 'anytime';
158: </defaultvalue>
159: <validator>
160: if (defined($val) && $val < $helper->{'VARS'}{'startunique'}) {
161: return 'End time must be later than the start time.';
162: }
163: return undef;
164: </validator>
165: </date>
166: <message>
167: </p><p>Message(s) triggered by reservation change by student
168: </message>
169: <choices variable="reservationmsg">
170: <choice computer='only_student'>Sent to student</choice>
171: <choice computer='student_and_user_notes_screen'>Sent to student and added to user notes</choice>
172: <choice computer='none'>None sent and no record in user notes</choice>
173: <defaultvalue>
174: my $default=&{$helper->{DATA}{origslot}}('reservationmsg');
175: if ($default eq 'only_student') { return $default; }
176: if ($default eq 'student_and_user_notes_screen') { return $default; }
177: return 'none';
178: </defaultvalue>
179: </choices>
180: </condition>
181: <condition>
182: <clause>$helper->{'VARS'}{'type'} eq 'preassigned'</clause>
183: <exec>
184: delete($helper->{'VARS'}{'startreserve'});
185: delete($helper->{'VARS'}{'endreserve'});
186: delete($helper->{'VARS'}{'maxspace'});
187: </exec>
188: <message>
189: </p><p>Period of time when this slot can only be uniquely assigned:<br /> Start:
190: </message>
191: <date variable="startunique" hoursminutes="1" anytime="1">
192: <defaultvalue>
193: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
194: if ($default eq 'anytime') { return 'anytime' };
195: if (ref($default)) { return $default->[0]; }
196: return 'anytime';
197: </defaultvalue>
198: </date>
199: <message><br /> End: </message>
200: <date variable="endunique" hoursminutes="1" anytime="1">
201: <defaultvalue>
202: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
203: if ($default eq 'anytime') { return 'anytime' };
204: if (ref($default)) { return $default->[1]; }
205: return 'anytime';
206: </defaultvalue>
207: <validator>
208: if (defined($val) && $val < $helper->{'VARS'}{'startunique'}) {
209: return 'End time must be later than the start time.';
210: }
211: return undef;
212: </validator>
213: </date>
214: </condition>
215: <message>
216: </p><p>Proctored access:
217: </message>
218: <choices variable="useproctor">
219: <choice computer='no'>No proctor checkin required for access.</choice>
220: <choice computer='yes'>Require proctored checkin for access.</choice>
221: <defaultvalue>
222: my $default=&{$helper->{DATA}{origslot}}('proctor');
223: if ($default) { return 'yes'; }
224: return 'no';
225: </defaultvalue>
226: </choices>
227:
228: <message>
229: </p><p>Secret word proctors use to checkin users:<br />
230: </message>
231: <string variable="secret" size="12">
232: <validator>
233: return undef;
234: </validator>
235: <defaultvalue>
236: return &{$helper->{DATA}{origslot}}('secret');
237: </defaultvalue>
238: </string>
239: <message>
240: </p><p>Slot is:
241: </message>
242: <helpicon file="Slot_ChoosingResources" />
243:
244: <choices variable="restricttosymb">
245: <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
246: <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
247: <defaultvalue>
248: my $default=&{$helper->{DATA}{origslot}}('symb');
249: if ($default) { return 'resource'; }
250: return 'any';
251: </defaultvalue>
252: </choices>
253:
254: <message>
255: </p><p>IP restrictions:<br />
256: </message>
257: <string variable="ip" size="30">
258: <validator>
259: return undef;
260: </validator>
261: <defaultvalue>
262: return &{$helper->{DATA}{origslot}}('ip');
263: </defaultvalue>
264: </string>
265: <message> </p> </message>
266: </state>
267:
268:
269: <state name="RESOURCESELECT" title="Specify Optional Attributes">
270:
271: <nextstate>PROCTOR</nextstate>
272:
273: <resource variable="symb">
274: <filterfunc>return $res->is_problem()</filterfunc>
275: <valuefunc>return $res->symb()</valuefunc>
276: <defaultvalue>
277: return &{$helper->{DATA}{origslot}}('symb');
278: </defaultvalue>
279: </resource>
280: </state>
281:
282:
283: <state name="PROCTOR" title="Specify Proctors"
284: help="Slot_SpecifyProctors">
285:
286: <skip>
287: <clause>$helper->{'VARS'}{'useproctor'} eq 'no'</clause>
288: <nextstate>RESTRICTUSER</nextstate>
289: </skip>
290:
291: <nextstate>RESTRICTUSER</nextstate>
292:
293: <student variable="proctor" multichoice="1" coursepersonnel="1"
294: activeonly="1" emptyallowed="0">
295: <defaultvalue>
296: my @defaults;
297: my $default=&{$helper->{DATA}{origslot}}('proctor');
298: if ($default) {
299: @defaults=(split(',',$default));
300: }
301: return @defaults;
302: </defaultvalue>
303: </student>
304: </state>
305:
306:
307: <state name="RESTRICTUSER" title="Restrict slot availability"
308: help="Slot_RestrictAvailibility">
309: <skip>
310: <clause>$helper->{'VARS'}{'type'} ne 'schedulable_student'</clause>
311: <nextstate>FINISH</nextstate>
312: </skip>
313:
314: <nextstate>FINISH</nextstate>
315: <message>
316: <p>Slots are by default available to all users in a course, if you would like this slot to be restricted to a subset of users you can specify restrictions.</p>
317: </message>
318:
319: <message>
320: Select sections to limit slot availability to: <br />
321: </message>
322: <section variable="allowedsections" multichoice="1" allowempty="1">
323: <defaultvalue>
324: return join('|||',
325: split(',',&{$helper->{DATA}{origslot}}('allowedsections')));
326: </defaultvalue>
327: </section>
328: <message>
329: Select users to limit slot availability to: <br />
330: </message>
331: <student variable="allowedusers" multichoice="1" coursepersonnel="1"
332: activeonly="1" emptyallowed="1">
333: <defaultvalue>
334: return split(',',&{$helper->{DATA}{origslot}}('allowedusers'));
335: </defaultvalue>
336: </student>
337: </state>
338:
339:
340: <state name="FINISH" title="Creating/Modifying Slot">
341: <message> Created Slot </message>
342: <final>
343: <finalcode>
344: my $result;
345: if ($helper->{'STATE'} ne 'FINISH') { return; }
346: my %slot;
347:
348: foreach my $which ('type','starttime','endtime') {
349: $slot{$which} = $helper->{'VARS'}{$which};
350: }
351:
352: foreach my $which ('ip','description','maxspace','secret','symb') {
353: if ( $helper->{'VARS'}{$which} =~/\S/ ) {
354: $slot{$which} = $helper->{'VARS'}{$which};
355: }
356: }
357:
358: if ($helper->{'VARS'}{'type'} eq 'schedulable_student') {
359: if (($helper->{'VARS'}{'reservationmsg'} eq 'only_student') ||
360: ($helper->{'VARS'}{'reservationmsg'} eq 'student_and_user_notes_screen')) {
361: $slot{'reservationmsg'} = $helper->{'VARS'}{'reservationmsg'};
362: } else {
363: $slot{'reservationmsg'} = 'none';
364: }
365: }
366:
367: if ( $helper->{'VARS'}{'startreserve'} > 0) {
368: $slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
369: }
370:
371: if ( $helper->{'VARS'}{'endreserve'} > 0) {
372: $slot{'endreserve'} = $helper->{'VARS'}{'endreserve'};
373: }
374:
375: if ( $helper->{'VARS'}{'startunique'} > 0 &&
376: $helper->{'VARS'}{'endunique'} > 0 ) {
377: $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
378: $helper->{'VARS'}{'endunique'}];
379: }
380:
381: if ( $helper->{'VARS'}{'useproctor'} eq 'yes'
382: && $helper->{'VARS'}{'proctor'} =~/\S/ ) {
383: my @names;
384: # just need the username/domain throw away the other data
385: # that <student> returns
386: foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
387: my ($uname,$udomain)=split(/:/,$user);
388: push(@names,"$uname:$udomain");
389: }
390: # make sure the usernmaes are unique
391: my %proctors = map { ($_,1) } @names;
392: $slot{'proctor'}=join(',',sort(keys(%proctors)));
393: }
394:
395: if ( $helper->{'VARS'}{'allowedsections'} =~/\S/ ) {
396: $slot{'allowedsections'}=
397: join(',',sort(split(/\|\|\|/,
398: $helper->{'VARS'}{'allowedsections'})));
399: }
400:
401: if ( $helper->{'VARS'}{'allowedusers'} =~/\S/ ) {
402: my @names;
403: # just need the username/domain throw away the other data
404: # that <student> returns
405: foreach my $item (split(/\|\|\|/,
406: $helper->{'VARS'}{'allowedusers'})) {
407: my ($uname,$udomain)=split(/:/,$item);
408: push(@names,"$uname:$udomain");
409: }
410:
411: # make sure the choices are unique
412: my %users = map { ($_,1) } @names;
413: $slot{'allowedusers'}=join(',',sort(keys(%users)));
414: }
415:
416: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
417: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
418:
419: my $ret = &Apache::lonnet::cput('slots',
420: {$helper->{'VARS'}{'name'} => \%slot},
421: $cdom,$cname);
422: if ($ret eq 'ok') {
423: &Apache::lonnet::devalidate_slots_cache($cname,$cdom);
424: }
425: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
426: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
427: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
428: "\n".'<li> Type: '.$slot{'type'}.'</li>';
429: my %labels =
430: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
431: foreach my $which ('ip','description','maxspace','secret','symb',
432: 'allowedsections','allowedusers') {
433: if (exists($slot{$which})) {
434: $result.="\n".'<li> '.$labels{$which}.': '.
435: &HTML::Entities::encode($slot{$which}).'</li>';
436: }
437: }
438: if (exists($slot{'startreserve'})) {
439: $result.="\n".'<li> '.$labels{'startreserve'}.': '.
440: &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
441: }
442:
443: if (exists($slot{'endreserve'})) {
444: $result.="\n".'<li> '.$labels{'endreserve'}.': '.
445: &Apache::lonlocal::locallocaltime($slot{'endreserve'}).'</li>';
446: }
447:
448: if (exists($slot{'reservationmsg'})) {
449: my %options = &Apache::slotrequest::slot_reservationmsg_options();
450: $result.="\n".'<li> '.$labels{'reservationmsg'}.': '.
451: $options{$slot{'reservationmsg'}}.'</li>';
452: }
453:
454: if (exists($slot{'proctor'})) {
455: my $proctors = $slot{'proctor'};
456: $proctors =~ s/,/, /g;
457: $result.="\n".'<li> '.$labels{'proctor'}.': '.
458: &HTML::Entities::encode($proctors).'</li>';
459: }
460: if (exists($slot{'uniqueperiod'})) {
461: $result.=
462: "\n".'<li> '.$labels{'uniqueperiod'}.': '.
463: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
464: ', '.
465: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
466: '</li>';
467: }
468: return $result;
469: </finalcode>
470: <exitpage>/adm/slotrequest?command=showslots</exitpage>
471: </final>
472: </state>
473: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>