File:
[LON-CAPA] /
loncom /
html /
adm /
helper /
newslot.helper
Revision
1.20:
download - view:
text,
annotated -
select for diffs
Sun Jun 25 21:57:56 2006 UTC (18 years, 1 month ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_2_X,
version_2_2_99_0,
version_2_2_2,
version_2_2_1,
version_2_2_0,
version_2_1_99_3,
version_2_1_99_2,
version_2_1_99_1,
version_2_1_99_0,
HEAD
- making use of the new <skip> mechanism
1: <helper title="Slot Creation" requiredpriv="mgq">
2: <state name="START" title="Specify Required Attributes">
3:
4: <nextstate>OPTIONAL</nextstate>
5:
6: <exec>
7: if (!exists($helper->{'VARS'}{'name'}) ||
8: $helper->{'VARS'}{'name'} !~ /\S/) {
9: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
10: if (exists($env{'form.name'}) ||
11: $env{'form.name'} =~ /\S/) {
12: $helper->{'VARS'}{'name'}=$env{'form.name'};
13: $helper->{VARS}{'origname'}=$env{'form.name'};
14: $helper->{DATA}{copy} = 1;
15: }
16: }
17: $helper->{DATA}{origslot} = sub {
18: my ($which,$default)=@_;
19: if (!exists($helper->{'VARS'}{'name'}) ||
20: $helper->{'VARS'}{'name'} !~ /\S/) {
21: return $default;
22: }
23: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
24: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
25: my $name=$helper->{VARS}{'origname'};
26: my %slot=&Apache::lonnet::get('slots', [$name], $cdom, $cnum);
27: if (!ref($slot{$name})) { return $default; }
28: if (!exists($slot{$name}{$which})) { return $default; }
29: return $slot{$name}{$which};
30: }
31: </exec>
32: <message>
33: Name: <br />
34: </message>
35: <string variable="name" size="30">
36: <validator>
37: if ($val=~/^\s*$/) { return 'Must specify a name'; }
38: if ($val=~/\s/) { return 'Must not contain spaces'; }
39: if ($val=~/\W/) { return 'Must contain only letters, numbers and _'; }
40: return undef;
41: </validator>
42: <defaultvalue>
43: return $helper->{'VARS'}{'name'};
44: </defaultvalue>
45: </string>
46: <condition>
47: <clause>$helper->{DATA}{copy}</clause>
48: <message>
49: <p>Changing the Name will create a new slot with the new name, and not rename the existing slot.</p>
50: </message>
51: </condition>
52: <message>
53: <br />Start time:<br />
54: </message>
55: <date variable="starttime" hoursminutes="1">
56: <defaultvalue>
57: return &{$helper->{DATA}{origslot}}('starttime');
58: </defaultvalue>
59: </date>
60: <message>
61: <br />End time:<br />
62: </message>
63: <date variable="endtime" hoursminutes="1">
64: <defaultvalue>
65: return &{$helper->{DATA}{origslot}}('endtime');
66: </defaultvalue>
67: <validator>
68: if ($val < $helper->{'VARS'}{'starttime'}) {
69: return 'End time must be later than the start time.';
70: }
71: return undef;
72: </validator>
73: </date>
74: <message>
75: <br />Type:
76: </message>
77: <choices variable="type">
78: <choice computer='preassigned'>Instructor asssignable.</choice>
79: <choice computer='schedulable_student'>Student selectable.</choice>
80: <defaultvalue>
81: return &{$helper->{DATA}{origslot}}('type','preassigned');
82: </defaultvalue>
83: </choices>
84: </state>
85:
86:
87: <state name="OPTIONAL" title="Specify Optional Attributes">
88: <message>
89: <p>Description:<br />
90: </message>
91: <string variable="description" size="60">
92: <defaultvalue>
93: return &{$helper->{DATA}{origslot}}('description');
94: </defaultvalue>
95: </string>
96: <condition>
97: <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
98: <message>
99: </p><p>Time students can start reserving:<br />
100: </message>
101: <date variable="startreserve" hoursminutes="1" anytime="1">
102: <defaultvalue>
103: return &{$helper->{DATA}{origslot}}('startreserve','anytime');
104: </defaultvalue>
105: <validator>
106: if (defined($val) && $val > $helper->{'VARS'}{'starttime'}) {
107: return 'Reservation time must come before the slot has started.';
108: }
109: return undef;
110: </validator>
111: </date>
112: <message>
113: </p><p>Maxium number of students allowed in this slot:<br />
114: </message>
115: <string variable="maxspace" size="4">
116: <validator>
117: if ($val ne '' && $val=~/\D/) { return 'Must be numeric.'; }
118: return undef;
119: </validator>
120: <defaultvalue>
121: return &{$helper->{DATA}{origslot}}('maxspace');
122: </defaultvalue>
123: </string>
124: <message>
125: </p><p>Period of time in which this slot is can only be uniquely chosen:<br /> Start:
126: </message>
127: <date variable="startunique" hoursminutes="1" anytime="1">
128: <defaultvalue>
129: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
130: if ($default eq 'anytime') { return 'anytime' };
131: if (ref($default)) { return $default->[0]; }
132: return 'anytime';
133: </defaultvalue>
134: </date>
135: <message><br /> End: </message>
136: <date variable="endunique" hoursminutes="1" anytime="1">
137: <defaultvalue>
138: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
139: if ($default eq 'anytime') { return 'anytime' };
140: if (ref($default)) { return $default->[1]; }
141: return 'anytime';
142: </defaultvalue>
143: <validator>
144: if (defined($val) && $val < $helper->{'VARS'}{'startunique'}) {
145: return 'End time must be later than the start time.';
146: }
147: return undef;
148: </validator>
149: </date>
150: </condition>
151: <condition>
152: <clause>$helper->{'VARS'}{'type'} eq 'preassigned'</clause>
153: <exec>
154: delete($helper->{'VARS'}{'startreserve'});
155: delete($helper->{'VARS'}{'maxspace'});
156: delete($helper->{'VARS'}{'startunique'});
157: delete($helper->{'VARS'}{'endunique'});
158: </exec>
159: </condition>
160:
161: <message>
162: </p><p>Proctored access:
163: </message>
164: <choices variable="useproctor">
165: <choice computer='no'>No proctor checkin required for access.</choice>
166: <choice computer='yes'>Require proctored checkin for access.</choice>
167: <defaultvalue>
168: my $default=&{$helper->{DATA}{origslot}}('proctor');
169: if ($default) { return 'yes'; }
170: return 'no';
171: </defaultvalue>
172: </choices>
173:
174: <message>
175: </p><p>Secret word proctors use to checkin users:<br />
176: </message>
177: <string variable="secret" size="12">
178: <validator>
179: return undef;
180: </validator>
181: <defaultvalue>
182: return &{$helper->{DATA}{origslot}}('secret');
183: </defaultvalue>
184: </string>
185: <message>
186: </p><p>Slot is:
187: </message>
188: <choices variable="restricttosymb">
189: <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
190: <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
191: <defaultvalue>
192: my $default=&{$helper->{DATA}{origslot}}('symb');
193: if ($default) { return 'resource'; }
194: return 'any';
195: </defaultvalue>
196: </choices>
197: <message>
198: </p><p>IP restrictions:<br />
199: </message>
200: <string variable="ip" size="30">
201: <validator>
202: return undef;
203: </validator>
204: <defaultvalue>
205: return &{$helper->{DATA}{origslot}}('ip');
206: </defaultvalue>
207: </string>
208: <message> </p> </message>
209: </state>
210:
211:
212: <state name="RESOURCESELECT" title="Specify Optional Attributes">
213:
214: <nextstate>PROCTOR</nextstate>
215:
216: <resource variable="symb">
217: <filterfunc>return $res->is_problem()</filterfunc>
218: <valuefunc>return $res->symb()</valuefunc>
219: <defaultvalue>
220: return &{$helper->{DATA}{origslot}}('symb');
221: </defaultvalue>
222: </resource>
223: </state>
224:
225:
226: <state name="PROCTOR" title="Specify Proctors">
227:
228: <skip>
229: <clause>$helper->{'VARS'}{'useproctor'} eq 'no'</clause>
230: <nextstate>RESTRICTUSER</nextstate>
231: </skip>
232:
233: <nextstate>RESTRICTUSER</nextstate>
234:
235: <student variable="proctor" multichoice="1" coursepersonnel="1"
236: activeonly="1" emptyallowed="1">
237: <defaultvalue>
238: my @defaults;
239: my $default=&{$helper->{DATA}{origslot}}('proctor');
240: if ($default) {
241: @defaults=(split(',',$default));
242: }
243: return @defaults;
244: </defaultvalue>
245: </student>
246: </state>
247:
248:
249: <state name="RESTRICTUSER" title="Restrict slot availability">
250: <skip>
251: <clause>$helper->{'VARS'}{'type'} ne 'schedulable_student'</clause>
252: <nextstate>FINISH</nextstate>
253: </skip>
254:
255: <nextstate>FINISH</nextstate>
256: <message>
257: <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>
258: </message>
259:
260: <message>
261: Select sections to limit slot availability to: <br />
262: </message>
263: <section variable="allowedsections" multichoice="1" allowempty="1">
264: <defaultvalue>
265: return join('|||',
266: split(',',&{$helper->{DATA}{origslot}}('allowedsections')));
267: </defaultvalue>
268: </section>
269: <message>
270: Select users to limit slot availability to: <br />
271: </message>
272: <student variable="allowedusers" multichoice="1" coursepersonnel="1"
273: activeonly="1" emptyallowed="1">
274: <defaultvalue>
275: return split(',',&{$helper->{DATA}{origslot}}('allowedusers'));
276: </defaultvalue>
277: </student>
278: </state>
279:
280:
281: <state name="FINISH" title="Creating/Modfying Slot">
282: <message> Created Slot </message>
283: <final>
284: <finalcode>
285: my $result;
286: if ($helper->{'STATE'} ne 'FINISH') { return; }
287: my %slot;
288:
289: foreach my $which ('type','starttime','endtime') {
290: $slot{$which} = $helper->{'VARS'}{$which};
291: }
292:
293: foreach my $which ('ip','description','maxspace','secret','symb') {
294: if ( $helper->{'VARS'}{$which} =~/\S/ ) {
295: $slot{$which} = $helper->{'VARS'}{$which};
296: }
297: }
298:
299: if ( $helper->{'VARS'}{'startreserve'} > 0) {
300: $slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
301: }
302:
303: if ( $helper->{'VARS'}{'startunique'} > 0 &&
304: $helper->{'VARS'}{'endunique'} > 0 ) {
305: $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
306: $helper->{'VARS'}{'endunique'}];
307: }
308:
309: if ( $helper->{'VARS'}{'useproctor'} eq 'yes'
310: && $helper->{'VARS'}{'proctor'} =~/\S/ ) {
311: my @names;
312: # just need the username/domain throw away the other data
313: # that <student> returns
314: foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
315: my ($uname,$udomain)=split(/:/,$user);
316: push(@names,"$uname:$udomain");
317: }
318: # make sure the usernmaes are unique
319: my %proctors = map { ($_,1) } @names;
320: $slot{'proctor'}=join(',',sort(keys(%proctors)));
321: }
322:
323: if ( $helper->{'VARS'}{'allowedsections'} =~/\S/ ) {
324: $slot{'allowedsections'}=
325: join(',',sort(split(/\|\|\|/,
326: $helper->{'VARS'}{'allowedsections'})));
327: }
328:
329: if ( $helper->{'VARS'}{'allowedusers'} =~/\S/ ) {
330: my @names;
331: # just need the username/domain throw away the other data
332: # that <student> returns
333: foreach my $item (split(/\|\|\|/,
334: $helper->{'VARS'}{'allowedusers'})) {
335: my ($uname,$udomain)=split(/:/,$item);
336: push(@names,"$uname:$udomain");
337: }
338:
339: # make sure the choices are unique
340: my %users = map { ($_,1) } @names;
341: $slot{'allowedusers'}=join(',',sort(keys(%users)));
342: }
343:
344: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
345: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
346:
347: my $ret = &Apache::lonnet::cput('slots',
348: {$helper->{'VARS'}{'name'} => \%slot},
349: $cdom,$cname);
350: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
351: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
352: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
353: "\n".'<li> Type: '.$slot{'type'}.'</li>';
354: my %labels =
355: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
356: foreach my $which ('ip','description','maxspace','secret','symb',
357: 'allowedsections','allowedusers') {
358: if (exists($slot{$which})) {
359: $result.="\n".'<li> '.$labels{$which}.': '.
360: &HTML::Entities::encode($slot{$which}).'</li>';
361: }
362: }
363: if (exists($slot{'startreserve'})) {
364: $result.="\n".'<li> '.$labels{'startreserve'}.': '.
365: &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
366: }
367: if (exists($slot{'proctor'})) {
368: my $proctors = $slot{'proctor'};
369: $proctors =~ s/,/, /g;
370: $result.="\n".'<li> '.$labels{'proctor'}.': '.
371: &HTML::Entities::encode($proctors).'</li>';
372: }
373: if (exists($slot{'uniqueperiod'})) {
374: $result.=
375: "\n".'<li> '.$labels{'uniqueperiod'}.': '.
376: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
377: ', '.
378: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
379: '</li>';
380: }
381: return $result;
382: </finalcode>
383: <exitpage>/adm/slotrequest?command=showslots</exitpage>
384: </final>
385: </state>
386: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>