Annotation of loncom/html/adm/helper/newslot.helper, revision 1.16
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.4 albertel 221: <student variable="proctor" multichoice="1" coursepersonnel="1"
1.13 albertel 222: activeonly="1" emptyallowed="1">
1.5 albertel 223: <defaultvalue>
224: my @defaults;
225: my $default=&{$helper->{DATA}{origslot}}('proctor');
226: if ($default) {
227: $default=~ tr/@/:/;
228: @defaults=(split(',',$default));
229: }
230: return @defaults;
231: </defaultvalue>
1.4 albertel 232: </student>
233: </state>
1.13 albertel 234:
235:
236: <state name="RESTRICTUSER" title="Restrict slot availability">
237: <nextstate>FINISH</nextstate>
238: <message>
239: <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>
240: </message>
241:
242: <message>
243: Select sections to limit slot availability to: <br />
244: </message>
245: <section variable="allowedsections" multichoice="1" allowempty="1">
246: <defaultvalue>
247: return join('|||',
248: split(',',&{$helper->{DATA}{origslot}}('allowedsections')));
249: </defaultvalue>
250: </section>
251: <message>
252: Select users to limit slot availability to: <br />
253: </message>
254: <student variable="allowedusers" multichoice="1" coursepersonnel="1"
255: activeonly="1" emptyallowed="1">
256: <defaultvalue>
257: return split(',',&{$helper->{DATA}{origslot}}('allowedusers'));
258: </defaultvalue>
259: </student>
260: </state>
261:
262:
1.3 albertel 263: <state name="FINISH" title="Creating/Modfying Slot">
1.11 albertel 264: <message> Created Slot </message>
1.3 albertel 265: <final>
266: <finalcode>
267: my $result;
268: if ($helper->{'STATE'} ne 'FINISH') { return; }
269: my %slot;
1.13 albertel 270:
1.3 albertel 271: foreach my $which ('type','starttime','endtime') {
272: $slot{$which} = $helper->{'VARS'}{$which};
273: }
1.13 albertel 274:
275: foreach my $which ('ip','description','maxspace','secret','symb') {
1.3 albertel 276: if ( $helper->{'VARS'}{$which} =~/\S/ ) {
277: $slot{$which} = $helper->{'VARS'}{$which};
278: }
279: }
1.13 albertel 280:
1.12 albertel 281: if ( $helper->{'VARS'}{'startreserve'} > 0) {
282: $slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
283: }
1.13 albertel 284:
1.3 albertel 285: if ( $helper->{'VARS'}{'startunique'} > 0 &&
286: $helper->{'VARS'}{'endunique'} > 0 ) {
287: $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
288: $helper->{'VARS'}{'endunique'}];
289: }
1.13 albertel 290:
1.4 albertel 291: if ( $helper->{'VARS'}{'proctor'} =~/\S/ ) {
292: my @names;
1.16 ! albertel 293: # just need the username/domain throw away the other data
! 294: # that <student> returns
1.4 albertel 295: foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
296: my ($uname,$udomain)=split(/:/,$user);
1.16 ! albertel 297: push(@names,"$uname:$udomain");
1.4 albertel 298: }
1.16 ! albertel 299: # make sure the usernmaes are unique
1.8 albertel 300: my %proctors = map { ($_,1) } @names;
301: $slot{'proctor'}=join(',',sort(keys(%proctors)));
1.4 albertel 302: }
1.13 albertel 303:
1.14 albertel 304: if ( $helper->{'VARS'}{'allowedsections'} =~/\S/ ) {
305: $slot{'allowedsections'}=
306: join(',',sort(split(/\|\|\|/,
307: $helper->{'VARS'}{'allowedsections'})));
1.13 albertel 308: }
309:
1.14 albertel 310: if ( $helper->{'VARS'}{'allowedusers'} =~/\S/ ) {
1.13 albertel 311: my @names;
1.16 ! albertel 312: # just need the username/domain throw away the other data
! 313: # that <student> returns
1.14 albertel 314: foreach my $item (split(/\|\|\|/,
315: $helper->{'VARS'}{'allowedusers'})) {
1.13 albertel 316: my ($uname,$udomain)=split(/:/,$item);
317: push(@names,"$uname:$udomain");
318: }
319:
320: # make sure the choices are unique
1.14 albertel 321: my %users = map { ($_,1) } @names;
322: $slot{'allowedusers'}=join(',',sort(keys(%users)));
1.13 albertel 323: }
324:
1.3 albertel 325: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
326: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
327:
328: my $ret = &Apache::lonnet::cput('slots',
329: {$helper->{'VARS'}{'name'} => \%slot},
330: $cdom,$cname);
1.5 albertel 331: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
1.4 albertel 332: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
333: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
1.3 albertel 334: "\n".'<li> Type: '.$slot{'type'}.'</li>';
335: my %labels =
336: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
1.13 albertel 337: foreach my $which ('ip','description','maxspace','secret','symb',
338: 'allowedsections','allowedusers') {
1.3 albertel 339: if (exists($slot{$which})) {
340: $result.="\n".'<li> '.$labels{$which}.': '.
341: &HTML::Entities::encode($slot{$which}).'</li>';
342: }
343: }
1.12 albertel 344: if (exists($slot{'startreserve'})) {
345: $result.="\n".'<li> '.$labels{'startreserve'}.': '.
346: &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
347: }
1.6 albertel 348: if (exists($slot{'proctor'})) {
349: my $proctors = $slot{'proctor'};
350: $proctors =~ s/,/, /g;
351: $result.="\n".'<li> '.$labels{'proctor'}.': '.
352: &HTML::Entities::encode($proctors).'</li>';
353: }
1.3 albertel 354: if (exists($slot{'uniqueperiod'})) {
355: $result.=
356: "\n".'<li> '.$labels{'uniqueperiod'}.': '.
357: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
358: ', '.
359: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
360: '</li>';
361: }
362: return $result;
363: </finalcode>
1.4 albertel 364: <exitpage>/adm/slotrequest?command=showslots</exitpage>
1.3 albertel 365: </final>
1.1 albertel 366: </state>
367: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>