Annotation of loncom/html/adm/helper/newslot.helper, revision 1.18
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.1 albertel 160: <message>
1.11 albertel 161: </p><p>Secret word proctors use to checkin users:<br />
1.3 albertel 162: </message>
163: <string variable="secret" size="12">
164: <validator>
165: return undef;
166: </validator>
1.5 albertel 167: <defaultvalue>
168: return &{$helper->{DATA}{origslot}}('secret');
169: </defaultvalue>
1.3 albertel 170: </string>
171: <message>
1.11 albertel 172: </p><p>Slot is:
1.1 albertel 173: </message>
174: <choices variable="restricttosymb">
1.4 albertel 175: <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
1.1 albertel 176: <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
1.5 albertel 177: <defaultvalue>
178: my $default=&{$helper->{DATA}{origslot}}('symb');
179: if ($default) { return 'resource'; }
180: return 'any';
181: </defaultvalue>
1.1 albertel 182: </choices>
1.2 albertel 183: <message>
1.13 albertel 184: </p><p>IP restrictions:<br />
1.2 albertel 185: </message>
186: <string variable="ip" size="30">
187: <validator>
188: return undef;
189: </validator>
1.5 albertel 190: <defaultvalue>
191: return &{$helper->{DATA}{origslot}}('ip');
192: </defaultvalue>
1.2 albertel 193: </string>
1.11 albertel 194: <message> </p> </message>
1.1 albertel 195: </state>
1.13 albertel 196:
197:
1.1 albertel 198: <state name="RESOURCESELECT" title="Specify Optional Attributes">
1.13 albertel 199:
200: <nextstate>PROCTOR</nextstate>
201:
1.1 albertel 202: <resource variable="symb">
203: <filterfunc>return $res->is_problem()</filterfunc>
204: <valuefunc>return $res->symb()</valuefunc>
1.5 albertel 205: <defaultvalue>
206: return &{$helper->{DATA}{origslot}}('symb');
207: </defaultvalue>
1.1 albertel 208: </resource>
209: </state>
1.13 albertel 210:
211:
1.4 albertel 212: <state name="PROCTOR" title="Specify Proctors">
1.13 albertel 213:
214: <nextstate>FINISH</nextstate>
215:
216: <condition>
217: <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
218: <nextstate>RESTRICTUSER</nextstate>
219: </condition>
220:
1.18 ! albertel 221: <choices variable="noproctor">
! 222: <choice computer='no'>No proctor checkin required for access.</choice>
! 223: <choice computer='yes'>Require proctored access.</choice>
! 224: <defaultvalue>
! 225: my $default=&{$helper->{DATA}{origslot}}('proctor');
! 226: if ($default) { return 'yes'; }
! 227: return 'no';
! 228: </defaultvalue>
! 229: </choices>
! 230:
1.4 albertel 231: <student variable="proctor" multichoice="1" coursepersonnel="1"
1.13 albertel 232: activeonly="1" emptyallowed="1">
1.5 albertel 233: <defaultvalue>
234: my @defaults;
235: my $default=&{$helper->{DATA}{origslot}}('proctor');
236: if ($default) {
237: @defaults=(split(',',$default));
238: }
239: return @defaults;
240: </defaultvalue>
1.4 albertel 241: </student>
242: </state>
1.13 albertel 243:
244:
245: <state name="RESTRICTUSER" title="Restrict slot availability">
246: <nextstate>FINISH</nextstate>
247: <message>
248: <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>
249: </message>
250:
251: <message>
252: Select sections to limit slot availability to: <br />
253: </message>
254: <section variable="allowedsections" multichoice="1" allowempty="1">
255: <defaultvalue>
256: return join('|||',
257: split(',',&{$helper->{DATA}{origslot}}('allowedsections')));
258: </defaultvalue>
259: </section>
260: <message>
261: Select users to limit slot availability to: <br />
262: </message>
263: <student variable="allowedusers" multichoice="1" coursepersonnel="1"
264: activeonly="1" emptyallowed="1">
265: <defaultvalue>
266: return split(',',&{$helper->{DATA}{origslot}}('allowedusers'));
267: </defaultvalue>
268: </student>
269: </state>
270:
271:
1.3 albertel 272: <state name="FINISH" title="Creating/Modfying Slot">
1.11 albertel 273: <message> Created Slot </message>
1.3 albertel 274: <final>
275: <finalcode>
276: my $result;
277: if ($helper->{'STATE'} ne 'FINISH') { return; }
278: my %slot;
1.13 albertel 279:
1.3 albertel 280: foreach my $which ('type','starttime','endtime') {
281: $slot{$which} = $helper->{'VARS'}{$which};
282: }
1.13 albertel 283:
284: foreach my $which ('ip','description','maxspace','secret','symb') {
1.3 albertel 285: if ( $helper->{'VARS'}{$which} =~/\S/ ) {
286: $slot{$which} = $helper->{'VARS'}{$which};
287: }
288: }
1.13 albertel 289:
1.12 albertel 290: if ( $helper->{'VARS'}{'startreserve'} > 0) {
291: $slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
292: }
1.13 albertel 293:
1.3 albertel 294: if ( $helper->{'VARS'}{'startunique'} > 0 &&
295: $helper->{'VARS'}{'endunique'} > 0 ) {
296: $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
297: $helper->{'VARS'}{'endunique'}];
298: }
1.13 albertel 299:
1.4 albertel 300: if ( $helper->{'VARS'}{'proctor'} =~/\S/ ) {
301: my @names;
1.16 albertel 302: # just need the username/domain throw away the other data
303: # that <student> returns
1.4 albertel 304: foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
305: my ($uname,$udomain)=split(/:/,$user);
1.16 albertel 306: push(@names,"$uname:$udomain");
1.4 albertel 307: }
1.16 albertel 308: # make sure the usernmaes are unique
1.8 albertel 309: my %proctors = map { ($_,1) } @names;
310: $slot{'proctor'}=join(',',sort(keys(%proctors)));
1.4 albertel 311: }
1.13 albertel 312:
1.14 albertel 313: if ( $helper->{'VARS'}{'allowedsections'} =~/\S/ ) {
314: $slot{'allowedsections'}=
315: join(',',sort(split(/\|\|\|/,
316: $helper->{'VARS'}{'allowedsections'})));
1.13 albertel 317: }
318:
1.14 albertel 319: if ( $helper->{'VARS'}{'allowedusers'} =~/\S/ ) {
1.13 albertel 320: my @names;
1.16 albertel 321: # just need the username/domain throw away the other data
322: # that <student> returns
1.14 albertel 323: foreach my $item (split(/\|\|\|/,
324: $helper->{'VARS'}{'allowedusers'})) {
1.13 albertel 325: my ($uname,$udomain)=split(/:/,$item);
326: push(@names,"$uname:$udomain");
327: }
328:
329: # make sure the choices are unique
1.14 albertel 330: my %users = map { ($_,1) } @names;
331: $slot{'allowedusers'}=join(',',sort(keys(%users)));
1.13 albertel 332: }
333:
1.3 albertel 334: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
335: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
336:
337: my $ret = &Apache::lonnet::cput('slots',
338: {$helper->{'VARS'}{'name'} => \%slot},
339: $cdom,$cname);
1.5 albertel 340: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
1.4 albertel 341: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
342: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
1.3 albertel 343: "\n".'<li> Type: '.$slot{'type'}.'</li>';
344: my %labels =
345: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
1.13 albertel 346: foreach my $which ('ip','description','maxspace','secret','symb',
347: 'allowedsections','allowedusers') {
1.3 albertel 348: if (exists($slot{$which})) {
349: $result.="\n".'<li> '.$labels{$which}.': '.
350: &HTML::Entities::encode($slot{$which}).'</li>';
351: }
352: }
1.12 albertel 353: if (exists($slot{'startreserve'})) {
354: $result.="\n".'<li> '.$labels{'startreserve'}.': '.
355: &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
356: }
1.6 albertel 357: if (exists($slot{'proctor'})) {
358: my $proctors = $slot{'proctor'};
359: $proctors =~ s/,/, /g;
360: $result.="\n".'<li> '.$labels{'proctor'}.': '.
361: &HTML::Entities::encode($proctors).'</li>';
362: }
1.3 albertel 363: if (exists($slot{'uniqueperiod'})) {
364: $result.=
365: "\n".'<li> '.$labels{'uniqueperiod'}.': '.
366: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
367: ', '.
368: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
369: '</li>';
370: }
371: return $result;
372: </finalcode>
1.4 albertel 373: <exitpage>/adm/slotrequest?command=showslots</exitpage>
1.3 albertel 374: </final>
1.1 albertel 375: </state>
376: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>