Annotation of loncom/html/adm/helper/newslot.helper, revision 1.13
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:
! 284: if ( $helper->{'VARS'}{'allowedsections'} !~/\S/ );
! 285:
! 286: my @names;
! 287: foreach my $item (split(/\|\|\|/, $helper->{'VARS'}{'allowedsections'})) {
! 288: my ($uname,$udomain)=split(/:/,$item);
! 289: push(@names,"$uname:$udomain");
! 290: }
! 291:
! 292: # make sure the choices are unique
! 293: my %proctors = map { ($_,1) } @names;
! 294: $slot{'allowedsections'}=join(',',sort(keys(%proctors)));
! 295: }
! 296:
! 297: if ( $helper->{'VARS'}{$which} !~/\S/ );
! 298:
! 299: my @names;
! 300: foreach my $item (split(/\|\|\|/, $helper->{'VARS'}{$which})) {
! 301: my ($uname,$udomain)=split(/:/,$item);
! 302: push(@names,"$uname:$udomain");
! 303: }
! 304:
! 305: # make sure the choices are unique
! 306: my %proctors = map { ($_,1) } @names;
! 307: $slot{$which}=join(',',sort(keys(%proctors)));
! 308: }
! 309:
1.3 albertel 310: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
311: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
312:
313: my $ret = &Apache::lonnet::cput('slots',
314: {$helper->{'VARS'}{'name'} => \%slot},
315: $cdom,$cname);
1.5 albertel 316: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
1.4 albertel 317: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
318: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
1.3 albertel 319: "\n".'<li> Type: '.$slot{'type'}.'</li>';
320: my %labels =
321: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
1.13 ! albertel 322: foreach my $which ('ip','description','maxspace','secret','symb',
! 323: 'allowedsections','allowedusers') {
1.3 albertel 324: if (exists($slot{$which})) {
325: $result.="\n".'<li> '.$labels{$which}.': '.
326: &HTML::Entities::encode($slot{$which}).'</li>';
327: }
328: }
1.12 albertel 329: if (exists($slot{'startreserve'})) {
330: $result.="\n".'<li> '.$labels{'startreserve'}.': '.
331: &Apache::lonlocal::locallocaltime($slot{'startreserve'}).'</li>';
332: }
1.6 albertel 333: if (exists($slot{'proctor'})) {
334: my $proctors = $slot{'proctor'};
335: $proctors =~ s/,/, /g;
336: $result.="\n".'<li> '.$labels{'proctor'}.': '.
337: &HTML::Entities::encode($proctors).'</li>';
338: }
1.3 albertel 339: if (exists($slot{'uniqueperiod'})) {
340: $result.=
341: "\n".'<li> '.$labels{'uniqueperiod'}.': '.
342: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
343: ', '.
344: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
345: '</li>';
346: }
347: return $result;
348: </finalcode>
1.4 albertel 349: <exitpage>/adm/slotrequest?command=showslots</exitpage>
1.3 albertel 350: </final>
1.1 albertel 351: </state>
352: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>