Annotation of loncom/html/adm/helper/newslot.helper, revision 1.20
1.1 albertel 1: <helper title="Slot Creation" requiredpriv="mgq">
2: <state name="START" title="Specify Required Attributes">
1.13 albertel 3:
4: <nextstate>OPTIONAL</nextstate>
5:
1.5 albertel 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'};
1.10 albertel 13: $helper->{VARS}{'origname'}=$env{'form.name'};
14: $helper->{DATA}{copy} = 1;
1.5 albertel 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'};
1.10 albertel 25: my $name=$helper->{VARS}{'origname'};
1.5 albertel 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>
1.13 albertel 32: <message>
1.11 albertel 33: Name: <br />
1.1 albertel 34: </message>
1.3 albertel 35: <string variable="name" size="30">
1.1 albertel 36: <validator>
37: if ($val=~/^\s*$/) { return 'Must specify a name'; }
1.9 albertel 38: if ($val=~/\s/) { return 'Must not contain spaces'; }
39: if ($val=~/\W/) { return 'Must contain only letters, numbers and _'; }
1.1 albertel 40: return undef;
41: </validator>
1.5 albertel 42: <defaultvalue>
43: return $helper->{'VARS'}{'name'};
44: </defaultvalue>
1.1 albertel 45: </string>
1.10 albertel 46: <condition>
47: <clause>$helper->{DATA}{copy}</clause>
1.13 albertel 48: <message>
1.10 albertel 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>
1.1 albertel 52: <message>
1.11 albertel 53: <br />Start time:<br />
1.1 albertel 54: </message>
1.5 albertel 55: <date variable="starttime" hoursminutes="1">
56: <defaultvalue>
57: return &{$helper->{DATA}{origslot}}('starttime');
58: </defaultvalue>
59: </date>
1.1 albertel 60: <message>
1.11 albertel 61: <br />End time:<br />
1.1 albertel 62: </message>
1.5 albertel 63: <date variable="endtime" hoursminutes="1">
64: <defaultvalue>
65: return &{$helper->{DATA}{origslot}}('endtime');
66: </defaultvalue>
1.15 albertel 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>
1.5 albertel 73: </date>
1.1 albertel 74: <message>
1.11 albertel 75: <br />Type:
1.1 albertel 76: </message>
77: <choices variable="type">
78: <choice computer='preassigned'>Instructor asssignable.</choice>
1.5 albertel 79: <choice computer='schedulable_student'>Student selectable.</choice>
1.1 albertel 80: <defaultvalue>
1.5 albertel 81: return &{$helper->{DATA}{origslot}}('type','preassigned');
1.1 albertel 82: </defaultvalue>
83: </choices>
84: </state>
85:
1.13 albertel 86:
1.1 albertel 87: <state name="OPTIONAL" title="Specify Optional Attributes">
88: <message>
1.11 albertel 89: <p>Description:<br />
1.1 albertel 90: </message>
1.5 albertel 91: <string variable="description" size="60">
92: <defaultvalue>
93: return &{$helper->{DATA}{origslot}}('description');
94: </defaultvalue>
95: </string>
1.7 albertel 96: <condition>
97: <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
98: <message>
1.11 albertel 99: </p><p>Time students can start reserving:<br />
1.7 albertel 100: </message>
101: <date variable="startreserve" hoursminutes="1" anytime="1">
102: <defaultvalue>
103: return &{$helper->{DATA}{origslot}}('startreserve','anytime');
104: </defaultvalue>
1.15 albertel 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>
1.7 albertel 111: </date>
112: <message>
1.11 albertel 113: </p><p>Maxium number of students allowed in this slot:<br />
1.7 albertel 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>
1.11 albertel 125: </p><p>Period of time in which this slot is can only be uniquely chosen:<br /> Start:
1.7 albertel 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>
1.11 albertel 135: <message><br /> End: </message>
1.7 albertel 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>
1.15 albertel 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>
1.7 albertel 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>
1.20 ! albertel 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:
1.1 albertel 174: <message>
1.11 albertel 175: </p><p>Secret word proctors use to checkin users:<br />
1.3 albertel 176: </message>
177: <string variable="secret" size="12">
178: <validator>
179: return undef;
180: </validator>
1.5 albertel 181: <defaultvalue>
182: return &{$helper->{DATA}{origslot}}('secret');
183: </defaultvalue>
1.3 albertel 184: </string>
185: <message>
1.11 albertel 186: </p><p>Slot is:
1.1 albertel 187: </message>
188: <choices variable="restricttosymb">
1.4 albertel 189: <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
1.1 albertel 190: <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
1.5 albertel 191: <defaultvalue>
192: my $default=&{$helper->{DATA}{origslot}}('symb');
193: if ($default) { return 'resource'; }
194: return 'any';
195: </defaultvalue>
1.1 albertel 196: </choices>
1.2 albertel 197: <message>
1.13 albertel 198: </p><p>IP restrictions:<br />
1.2 albertel 199: </message>
200: <string variable="ip" size="30">
201: <validator>
202: return undef;
203: </validator>
1.5 albertel 204: <defaultvalue>
205: return &{$helper->{DATA}{origslot}}('ip');
206: </defaultvalue>
1.2 albertel 207: </string>
1.11 albertel 208: <message> </p> </message>
1.1 albertel 209: </state>
1.13 albertel 210:
211:
1.1 albertel 212: <state name="RESOURCESELECT" title="Specify Optional Attributes">
1.13 albertel 213:
214: <nextstate>PROCTOR</nextstate>
215:
1.1 albertel 216: <resource variable="symb">
217: <filterfunc>return $res->is_problem()</filterfunc>
218: <valuefunc>return $res->symb()</valuefunc>
1.5 albertel 219: <defaultvalue>
220: return &{$helper->{DATA}{origslot}}('symb');
221: </defaultvalue>
1.1 albertel 222: </resource>
223: </state>
1.13 albertel 224:
225:
1.4 albertel 226: <state name="PROCTOR" title="Specify Proctors">
1.13 albertel 227:
1.20 ! albertel 228: <skip>
! 229: <clause>$helper->{'VARS'}{'useproctor'} eq 'no'</clause>
! 230: <nextstate>RESTRICTUSER</nextstate>
! 231: </skip>
1.13 albertel 232:
1.20 ! albertel 233: <nextstate>RESTRICTUSER</nextstate>
1.18 albertel 234:
1.4 albertel 235: <student variable="proctor" multichoice="1" coursepersonnel="1"
1.13 albertel 236: activeonly="1" emptyallowed="1">
1.5 albertel 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>
1.4 albertel 245: </student>
246: </state>
1.13 albertel 247:
248:
249: <state name="RESTRICTUSER" title="Restrict slot availability">
1.20 ! albertel 250: <skip>
! 251: <clause>$helper->{'VARS'}{'type'} ne 'schedulable_student'</clause>
! 252: <nextstate>FINISH</nextstate>
! 253: </skip>
! 254:
1.13 albertel 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:
1.3 albertel 281: <state name="FINISH" title="Creating/Modfying Slot">
1.11 albertel 282: <message> Created Slot </message>
1.3 albertel 283: <final>
284: <finalcode>
285: my $result;
286: if ($helper->{'STATE'} ne 'FINISH') { return; }
287: my %slot;
1.13 albertel 288:
1.3 albertel 289: foreach my $which ('type','starttime','endtime') {
290: $slot{$which} = $helper->{'VARS'}{$which};
291: }
1.13 albertel 292:
293: foreach my $which ('ip','description','maxspace','secret','symb') {
1.3 albertel 294: if ( $helper->{'VARS'}{$which} =~/\S/ ) {
295: $slot{$which} = $helper->{'VARS'}{$which};
296: }
297: }
1.13 albertel 298:
1.12 albertel 299: if ( $helper->{'VARS'}{'startreserve'} > 0) {
300: $slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
301: }
1.13 albertel 302:
1.3 albertel 303: if ( $helper->{'VARS'}{'startunique'} > 0 &&
304: $helper->{'VARS'}{'endunique'} > 0 ) {
305: $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
306: $helper->{'VARS'}{'endunique'}];
307: }
1.13 albertel 308:
1.19 albertel 309: if ( $helper->{'VARS'}{'useproctor'} eq 'yes'
310: && $helper->{'VARS'}{'proctor'} =~/\S/ ) {
1.4 albertel 311: my @names;
1.16 albertel 312: # just need the username/domain throw away the other data
313: # that <student> returns
1.4 albertel 314: foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
315: my ($uname,$udomain)=split(/:/,$user);
1.16 albertel 316: push(@names,"$uname:$udomain");
1.4 albertel 317: }
1.16 albertel 318: # make sure the usernmaes are unique
1.8 albertel 319: my %proctors = map { ($_,1) } @names;
320: $slot{'proctor'}=join(',',sort(keys(%proctors)));
1.4 albertel 321: }
1.13 albertel 322:
1.14 albertel 323: if ( $helper->{'VARS'}{'allowedsections'} =~/\S/ ) {
324: $slot{'allowedsections'}=
325: join(',',sort(split(/\|\|\|/,
326: $helper->{'VARS'}{'allowedsections'})));
1.13 albertel 327: }
328:
1.14 albertel 329: if ( $helper->{'VARS'}{'allowedusers'} =~/\S/ ) {
1.13 albertel 330: my @names;
1.16 albertel 331: # just need the username/domain throw away the other data
332: # that <student> returns
1.14 albertel 333: foreach my $item (split(/\|\|\|/,
334: $helper->{'VARS'}{'allowedusers'})) {
1.13 albertel 335: my ($uname,$udomain)=split(/:/,$item);
336: push(@names,"$uname:$udomain");
337: }
338:
339: # make sure the choices are unique
1.14 albertel 340: my %users = map { ($_,1) } @names;
341: $slot{'allowedusers'}=join(',',sort(keys(%users)));
1.13 albertel 342: }
343:
1.3 albertel 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);
1.5 albertel 350: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
1.4 albertel 351: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
352: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
1.3 albertel 353: "\n".'<li> Type: '.$slot{'type'}.'</li>';
354: my %labels =
355: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
1.13 albertel 356: foreach my $which ('ip','description','maxspace','secret','symb',
357: 'allowedsections','allowedusers') {
1.3 albertel 358: if (exists($slot{$which})) {
359: $result.="\n".'<li> '.$labels{$which}.': '.
360: &HTML::Entities::encode($slot{$which}).'</li>';
361: }
362: }
1.12 albertel 363: if (exists($slot{'startreserve'})) {
364: $result.="\n".'<li> '.$labels{'startreserve'}.': '.
365: &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
366: }
1.6 albertel 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: }
1.3 albertel 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>
1.4 albertel 383: <exitpage>/adm/slotrequest?command=showslots</exitpage>
1.3 albertel 384: </final>
1.1 albertel 385: </state>
386: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>