Annotation of loncom/html/adm/helper/newslot.helper, revision 1.14
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>
67: </date>
1.1 albertel 68: <message>
1.11 albertel 69: <br />Type:
1.1 albertel 70: </message>
71: <choices variable="type">
72: <choice computer='preassigned'>Instructor asssignable.</choice>
1.5 albertel 73: <choice computer='schedulable_student'>Student selectable.</choice>
1.1 albertel 74: <defaultvalue>
1.5 albertel 75: return &{$helper->{DATA}{origslot}}('type','preassigned');
1.1 albertel 76: </defaultvalue>
77: </choices>
78: </state>
79:
1.13 albertel 80:
1.1 albertel 81: <state name="OPTIONAL" title="Specify Optional Attributes">
82: <message>
1.11 albertel 83: <p>Description:<br />
1.1 albertel 84: </message>
1.5 albertel 85: <string variable="description" size="60">
86: <defaultvalue>
87: return &{$helper->{DATA}{origslot}}('description');
88: </defaultvalue>
89: </string>
1.7 albertel 90: <condition>
91: <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
92: <message>
1.11 albertel 93: </p><p>Time students can start reserving:<br />
1.7 albertel 94: </message>
95: <date variable="startreserve" hoursminutes="1" anytime="1">
96: <defaultvalue>
97: return &{$helper->{DATA}{origslot}}('startreserve','anytime');
98: </defaultvalue>
99: </date>
100: <message>
1.11 albertel 101: </p><p>Maxium number of students allowed in this slot:<br />
1.7 albertel 102: </message>
103: <string variable="maxspace" size="4">
104: <validator>
105: if ($val ne '' && $val=~/\D/) { return 'Must be numeric.'; }
106: return undef;
107: </validator>
108: <defaultvalue>
109: return &{$helper->{DATA}{origslot}}('maxspace');
110: </defaultvalue>
111: </string>
112: <message>
1.11 albertel 113: </p><p>Period of time in which this slot is can only be uniquely chosen:<br /> Start:
1.7 albertel 114: </message>
115: <date variable="startunique" hoursminutes="1" anytime="1">
116: <defaultvalue>
117: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
118: if ($default eq 'anytime') { return 'anytime' };
119: if (ref($default)) { return $default->[0]; }
120: return 'anytime';
121: </defaultvalue>
122: </date>
1.11 albertel 123: <message><br /> End: </message>
1.7 albertel 124: <date variable="endunique" hoursminutes="1" anytime="1">
125: <defaultvalue>
126: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
127: if ($default eq 'anytime') { return 'anytime' };
128: if (ref($default)) { return $default->[1]; }
129: return 'anytime';
130: </defaultvalue>
131: </date>
132: </condition>
133: <condition>
134: <clause>$helper->{'VARS'}{'type'} eq 'preassigned'</clause>
135: <exec>
136: delete($helper->{'VARS'}{'startreserve'});
137: delete($helper->{'VARS'}{'maxspace'});
138: delete($helper->{'VARS'}{'startunique'});
139: delete($helper->{'VARS'}{'endunique'});
140: </exec>
141: </condition>
1.1 albertel 142: <message>
1.11 albertel 143: </p><p>Secret word proctors use to checkin users:<br />
1.3 albertel 144: </message>
145: <string variable="secret" size="12">
146: <validator>
147: return undef;
148: </validator>
1.5 albertel 149: <defaultvalue>
150: return &{$helper->{DATA}{origslot}}('secret');
151: </defaultvalue>
1.3 albertel 152: </string>
153: <message>
1.11 albertel 154: </p><p>Slot is:
1.1 albertel 155: </message>
156: <choices variable="restricttosymb">
1.4 albertel 157: <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
1.1 albertel 158: <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
1.5 albertel 159: <defaultvalue>
160: my $default=&{$helper->{DATA}{origslot}}('symb');
161: if ($default) { return 'resource'; }
162: return 'any';
163: </defaultvalue>
1.1 albertel 164: </choices>
1.2 albertel 165: <message>
1.13 albertel 166: </p><p>IP restrictions:<br />
1.2 albertel 167: </message>
168: <string variable="ip" size="30">
169: <validator>
170: return undef;
171: </validator>
1.5 albertel 172: <defaultvalue>
173: return &{$helper->{DATA}{origslot}}('ip');
174: </defaultvalue>
1.2 albertel 175: </string>
1.11 albertel 176: <message> </p> </message>
1.1 albertel 177: </state>
1.13 albertel 178:
179:
1.1 albertel 180: <state name="RESOURCESELECT" title="Specify Optional Attributes">
1.13 albertel 181:
182: <nextstate>PROCTOR</nextstate>
183:
1.1 albertel 184: <resource variable="symb">
185: <filterfunc>return $res->is_problem()</filterfunc>
186: <valuefunc>return $res->symb()</valuefunc>
1.5 albertel 187: <defaultvalue>
188: return &{$helper->{DATA}{origslot}}('symb');
189: </defaultvalue>
1.1 albertel 190: </resource>
191: </state>
1.13 albertel 192:
193:
1.4 albertel 194: <state name="PROCTOR" title="Specify Proctors">
1.13 albertel 195:
196: <nextstate>FINISH</nextstate>
197:
198: <condition>
199: <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
200: <nextstate>RESTRICTUSER</nextstate>
201: </condition>
202:
1.4 albertel 203: <student variable="proctor" multichoice="1" coursepersonnel="1"
1.13 albertel 204: activeonly="1" emptyallowed="1">
1.5 albertel 205: <defaultvalue>
206: my @defaults;
207: my $default=&{$helper->{DATA}{origslot}}('proctor');
208: if ($default) {
209: $default=~ tr/@/:/;
210: @defaults=(split(',',$default));
211: }
212: return @defaults;
213: </defaultvalue>
1.4 albertel 214: </student>
215: </state>
1.13 albertel 216:
217:
218: <state name="RESTRICTUSER" title="Restrict slot availability">
219: <nextstate>FINISH</nextstate>
220: <message>
221: <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>
222: </message>
223:
224: <message>
225: Select sections to limit slot availability to: <br />
226: </message>
227: <section variable="allowedsections" multichoice="1" allowempty="1">
228: <defaultvalue>
229: return join('|||',
230: split(',',&{$helper->{DATA}{origslot}}('allowedsections')));
231: </defaultvalue>
232: </section>
233: <message>
234: Select users to limit slot availability to: <br />
235: </message>
236: <student variable="allowedusers" multichoice="1" coursepersonnel="1"
237: activeonly="1" emptyallowed="1">
238: <defaultvalue>
239: return split(',',&{$helper->{DATA}{origslot}}('allowedusers'));
240: </defaultvalue>
241: </student>
242: </state>
243:
244:
1.3 albertel 245: <state name="FINISH" title="Creating/Modfying Slot">
1.11 albertel 246: <message> Created Slot </message>
1.3 albertel 247: <final>
248: <finalcode>
249: my $result;
250: if ($helper->{'STATE'} ne 'FINISH') { return; }
251: my %slot;
1.13 albertel 252:
1.3 albertel 253: foreach my $which ('type','starttime','endtime') {
254: $slot{$which} = $helper->{'VARS'}{$which};
255: }
1.13 albertel 256:
257: foreach my $which ('ip','description','maxspace','secret','symb') {
1.3 albertel 258: if ( $helper->{'VARS'}{$which} =~/\S/ ) {
259: $slot{$which} = $helper->{'VARS'}{$which};
260: }
261: }
1.13 albertel 262:
1.12 albertel 263: if ( $helper->{'VARS'}{'startreserve'} > 0) {
264: $slot{'startreserve'} = $helper->{'VARS'}{'startreserve'};
265: }
1.13 albertel 266:
1.3 albertel 267: if ( $helper->{'VARS'}{'startunique'} > 0 &&
268: $helper->{'VARS'}{'endunique'} > 0 ) {
269: $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
270: $helper->{'VARS'}{'endunique'}];
271: }
1.13 albertel 272:
1.4 albertel 273: if ( $helper->{'VARS'}{'proctor'} =~/\S/ ) {
274: my @names;
275: foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
276: my ($uname,$udomain)=split(/:/,$user);
277: push(@names,"$uname\@$udomain");
278: }
1.8 albertel 279: # make sure the usenrmaes are unique
280: my %proctors = map { ($_,1) } @names;
281: $slot{'proctor'}=join(',',sort(keys(%proctors)));
1.4 albertel 282: }
1.13 albertel 283:
1.14 ! albertel 284: if ( $helper->{'VARS'}{'allowedsections'} =~/\S/ ) {
! 285: $slot{'allowedsections'}=
! 286: join(',',sort(split(/\|\|\|/,
! 287: $helper->{'VARS'}{'allowedsections'})));
1.13 albertel 288: }
289:
1.14 ! albertel 290: if ( $helper->{'VARS'}{'allowedusers'} =~/\S/ ) {
1.13 albertel 291:
292: my @names;
1.14 ! albertel 293: foreach my $item (split(/\|\|\|/,
! 294: $helper->{'VARS'}{'allowedusers'})) {
1.13 albertel 295: my ($uname,$udomain)=split(/:/,$item);
296: push(@names,"$uname:$udomain");
297: }
298:
299: # make sure the choices are unique
1.14 ! albertel 300: my %users = map { ($_,1) } @names;
! 301: $slot{'allowedusers'}=join(',',sort(keys(%users)));
1.13 albertel 302: }
303:
1.3 albertel 304: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
305: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
306:
307: my $ret = &Apache::lonnet::cput('slots',
308: {$helper->{'VARS'}{'name'} => \%slot},
309: $cdom,$cname);
1.5 albertel 310: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
1.4 albertel 311: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
312: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
1.3 albertel 313: "\n".'<li> Type: '.$slot{'type'}.'</li>';
314: my %labels =
315: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
1.13 albertel 316: foreach my $which ('ip','description','maxspace','secret','symb',
317: 'allowedsections','allowedusers') {
1.3 albertel 318: if (exists($slot{$which})) {
319: $result.="\n".'<li> '.$labels{$which}.': '.
320: &HTML::Entities::encode($slot{$which}).'</li>';
321: }
322: }
1.12 albertel 323: if (exists($slot{'startreserve'})) {
324: $result.="\n".'<li> '.$labels{'startreserve'}.': '.
325: &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
326: }
1.6 albertel 327: if (exists($slot{'proctor'})) {
328: my $proctors = $slot{'proctor'};
329: $proctors =~ s/,/, /g;
330: $result.="\n".'<li> '.$labels{'proctor'}.': '.
331: &HTML::Entities::encode($proctors).'</li>';
332: }
1.3 albertel 333: if (exists($slot{'uniqueperiod'})) {
334: $result.=
335: "\n".'<li> '.$labels{'uniqueperiod'}.': '.
336: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
337: ', '.
338: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
339: '</li>';
340: }
341: return $result;
342: </finalcode>
1.4 albertel 343: <exitpage>/adm/slotrequest?command=showslots</exitpage>
1.3 albertel 344: </final>
1.1 albertel 345: </state>
346: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>