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 asssignable.</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>Maximum number of students allowed in this slot:<br />
116: </message>
117: <string variable="maxspace" size="4">
118: <validator>
119: if ($val ne '' && $val=~/\D/) { return 'Must be numeric.'; }
120: return undef;
121: </validator>
122: <defaultvalue>
123: return &{$helper->{DATA}{origslot}}('maxspace');
124: </defaultvalue>
125: </string>
126: <message>
127: </p><p>Period of time in which this slot is can only be uniquely chosen:<br /> Start:
128: </message>
129: <date variable="startunique" hoursminutes="1" anytime="1">
130: <defaultvalue>
131: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
132: if ($default eq 'anytime') { return 'anytime' };
133: if (ref($default)) { return $default->[0]; }
134: return 'anytime';
135: </defaultvalue>
136: </date>
137: <message><br /> End: </message>
138: <date variable="endunique" hoursminutes="1" anytime="1">
139: <defaultvalue>
140: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
141: if ($default eq 'anytime') { return 'anytime' };
142: if (ref($default)) { return $default->[1]; }
143: return 'anytime';
144: </defaultvalue>
145: <validator>
146: if (defined($val) && $val < $helper->{'VARS'}{'startunique'}) {
147: return 'End time must be later than the start time.';
148: }
149: return undef;
150: </validator>
151: </date>
152: </condition>
153: <condition>
154: <clause>$helper->{'VARS'}{'type'} eq 'preassigned'</clause>
155: <exec>
156: delete($helper->{'VARS'}{'startreserve'});
157: delete($helper->{'VARS'}{'maxspace'});
158: delete($helper->{'VARS'}{'startunique'});
159: delete($helper->{'VARS'}{'endunique'});
160: </exec>
161: </condition>
162:
163: <message>
164: </p><p>Proctored access:
165: </message>
166: <choices variable="useproctor">
167: <choice computer='no'>No proctor checkin required for access.</choice>
168: <choice computer='yes'>Require proctored checkin for access.</choice>
169: <defaultvalue>
170: my $default=&{$helper->{DATA}{origslot}}('proctor');
171: if ($default) { return 'yes'; }
172: return 'no';
173: </defaultvalue>
174: </choices>
175:
176: <message>
177: </p><p>Secret word proctors use to checkin users:<br />
178: </message>
179: <string variable="secret" size="12">
180: <validator>
181: return undef;
182: </validator>
183: <defaultvalue>
184: return &{$helper->{DATA}{origslot}}('secret');
185: </defaultvalue>
186: </string>
187: <message>
188: </p><p>Slot is:
189: </message>
190: <helpicon file="Slot_ChoosingResources" />
191:
192: <choices variable="restricttosymb">
193: <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
194: <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
195: <defaultvalue>
196: my $default=&{$helper->{DATA}{origslot}}('symb');
197: if ($default) { return 'resource'; }
198: return 'any';
199: </defaultvalue>
200: </choices>
201:
202: <message>
203: </p><p>IP restrictions:<br />
204: </message>
205: <string variable="ip" size="30">
206: <validator>
207: return undef;
208: </validator>
209: <defaultvalue>
210: return &{$helper->{DATA}{origslot}}('ip');
211: </defaultvalue>
212: </string>
213: <message> </p> </message>
214: </state>
215:
216:
217: <state name="RESOURCESELECT" title="Specify Optional Attributes">
218:
219: <nextstate>PROCTOR</nextstate>
220:
221: <resource variable="symb">
222: <filterfunc>return $res->is_problem()</filterfunc>
223: <valuefunc>return $res->symb()</valuefunc>
224: <defaultvalue>
225: return &{$helper->{DATA}{origslot}}('symb');
226: </defaultvalue>
227: </resource>
228: </state>
229:
230:
231: <state name="PROCTOR" title="Specify Proctors"
232: help="Slot_SpecifyProctors">
233:
234: <skip>
235: <clause>$helper->{'VARS'}{'useproctor'} eq 'no'</clause>
236: <nextstate>RESTRICTUSER</nextstate>
237: </skip>
238:
239: <nextstate>RESTRICTUSER</nextstate>
240:
241: <student variable="proctor" multichoice="1" coursepersonnel="1"
242: activeonly="1" emptyallowed="0">
243: <defaultvalue>
244: my @defaults;
245: my $default=&{$helper->{DATA}{origslot}}('proctor');
246: if ($default) {
247: @defaults=(split(',',$default));
248: }
249: return @defaults;
250: </defaultvalue>
251: </student>
252: </state>
253:
254:
255: <state name="RESTRICTUSER" title="Restrict slot availability"
256: help="Slot_RestrictAvailibility">
257: <skip>
258: <clause>$helper->{'VARS'}{'type'} ne 'schedulable_student'</clause>
259: <nextstate>FINISH</nextstate>
260: </skip>
261:
262: <nextstate>FINISH</nextstate>
263: <message>
264: <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>
265: </message>
266:
267: <message>
268: Select sections to limit slot availability to: <br />
269: </message>
270: <section variable="allowedsections" multichoice="1" allowempty="1">
271: <defaultvalue>
272: return join('|||',
273: split(',',&{$helper->{DATA}{origslot}}('allowedsections')));
274: </defaultvalue>
275: </section>
276: <message>
277: Select users to limit slot availability to: <br />
278: </message>
279: <student variable="allowedusers" multichoice="1" coursepersonnel="1"
280: activeonly="1" emptyallowed="1">
281: <defaultvalue>
282: return split(',',&{$helper->{DATA}{origslot}}('allowedusers'));
283: </defaultvalue>
284: </student>
285: </state>
286:
287:
288: <state name="FINISH" title="Creating/Modfying Slot">
289: <message> Created Slot </message>
290: <final>
291: <finalcode>
292: my $result;
293: if ($helper->{'STATE'} ne 'FINISH') { return; }
294: my %slot;
295:
296: foreach my $which ('type','starttime','endtime') {
297: $slot{$which} = $helper->{'VARS'}{$which};
298: }
299:
300: foreach my $which ('ip','description','maxspace','secret','symb') {
301: if ( $helper->{'VARS'}{$which} =~/\S/ ) {
302: $slot{$which} = $helper->{'VARS'}{$which};
303: }
304: }
305:
306: if ( $helper->{'VARS'}{'startreserve'} > 0) {
307: $slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
308: }
309:
310: if ( $helper->{'VARS'}{'startunique'} > 0 &&
311: $helper->{'VARS'}{'endunique'} > 0 ) {
312: $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
313: $helper->{'VARS'}{'endunique'}];
314: }
315:
316: if ( $helper->{'VARS'}{'useproctor'} eq 'yes'
317: && $helper->{'VARS'}{'proctor'} =~/\S/ ) {
318: my @names;
319: # just need the username/domain throw away the other data
320: # that <student> returns
321: foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
322: my ($uname,$udomain)=split(/:/,$user);
323: push(@names,"$uname:$udomain");
324: }
325: # make sure the usernmaes are unique
326: my %proctors = map { ($_,1) } @names;
327: $slot{'proctor'}=join(',',sort(keys(%proctors)));
328: }
329:
330: if ( $helper->{'VARS'}{'allowedsections'} =~/\S/ ) {
331: $slot{'allowedsections'}=
332: join(',',sort(split(/\|\|\|/,
333: $helper->{'VARS'}{'allowedsections'})));
334: }
335:
336: if ( $helper->{'VARS'}{'allowedusers'} =~/\S/ ) {
337: my @names;
338: # just need the username/domain throw away the other data
339: # that <student> returns
340: foreach my $item (split(/\|\|\|/,
341: $helper->{'VARS'}{'allowedusers'})) {
342: my ($uname,$udomain)=split(/:/,$item);
343: push(@names,"$uname:$udomain");
344: }
345:
346: # make sure the choices are unique
347: my %users = map { ($_,1) } @names;
348: $slot{'allowedusers'}=join(',',sort(keys(%users)));
349: }
350:
351: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
352: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
353:
354: my $ret = &Apache::lonnet::cput('slots',
355: {$helper->{'VARS'}{'name'} => \%slot},
356: $cdom,$cname);
357: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
358: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
359: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
360: "\n".'<li> Type: '.$slot{'type'}.'</li>';
361: my %labels =
362: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
363: foreach my $which ('ip','description','maxspace','secret','symb',
364: 'allowedsections','allowedusers') {
365: if (exists($slot{$which})) {
366: $result.="\n".'<li> '.$labels{$which}.': '.
367: &HTML::Entities::encode($slot{$which}).'</li>';
368: }
369: }
370: if (exists($slot{'startreserve'})) {
371: $result.="\n".'<li> '.$labels{'startreserve'}.': '.
372: &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
373: }
374: if (exists($slot{'proctor'})) {
375: my $proctors = $slot{'proctor'};
376: $proctors =~ s/,/, /g;
377: $result.="\n".'<li> '.$labels{'proctor'}.': '.
378: &HTML::Entities::encode($proctors).'</li>';
379: }
380: if (exists($slot{'uniqueperiod'})) {
381: $result.=
382: "\n".'<li> '.$labels{'uniqueperiod'}.': '.
383: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
384: ', '.
385: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
386: '</li>';
387: }
388: return $result;
389: </finalcode>
390: <exitpage>/adm/slotrequest?command=showslots</exitpage>
391: </final>
392: </state>
393: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>