1: <helper title="Slot Creation" requiredpriv="mgq">
2: <state name="START" title="Specify Required Attributes">
3: <exec>
4: if (!exists($helper->{'VARS'}{'name'}) ||
5: $helper->{'VARS'}{'name'} !~ /\S/) {
6: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
7: if (exists($env{'form.name'}) ||
8: $env{'form.name'} =~ /\S/) {
9: $helper->{'VARS'}{'name'}=$env{'form.name'};
10: $helper->{VARS}{'origname'}=$env{'form.name'};
11: $helper->{DATA}{copy} = 1;
12: }
13: }
14: $helper->{DATA}{origslot} = sub {
15: my ($which,$default)=@_;
16: if (!exists($helper->{'VARS'}{'name'}) ||
17: $helper->{'VARS'}{'name'} !~ /\S/) {
18: return $default;
19: }
20: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
21: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
22: my $name=$helper->{VARS}{'origname'};
23: my %slot=&Apache::lonnet::get('slots', [$name], $cdom, $cnum);
24: if (!ref($slot{$name})) { return $default; }
25: if (!exists($slot{$name}{$which})) { return $default; }
26: return $slot{$name}{$which};
27: }
28: </exec>
29: <message nextstate="OPTIONAL">
30: Name: <br />
31: </message>
32: <string variable="name" size="30">
33: <validator>
34: if ($val=~/^\s*$/) { return 'Must specify a name'; }
35: if ($val=~/\s/) { return 'Must not contain spaces'; }
36: if ($val=~/\W/) { return 'Must contain only letters, numbers and _'; }
37: return undef;
38: </validator>
39: <defaultvalue>
40: return $helper->{'VARS'}{'name'};
41: </defaultvalue>
42: </string>
43: <condition>
44: <clause>$helper->{DATA}{copy}</clause>
45: <message nextstate="OPTIONAL">
46: <p>Changing the Name will create a new slot with the new name, and not rename the existing slot.</p>
47: </message>
48: </condition>
49: <message>
50: <br />Start time:<br />
51: </message>
52: <date variable="starttime" hoursminutes="1">
53: <defaultvalue>
54: return &{$helper->{DATA}{origslot}}('starttime');
55: </defaultvalue>
56: </date>
57: <message>
58: <br />End time:<br />
59: </message>
60: <date variable="endtime" hoursminutes="1">
61: <defaultvalue>
62: return &{$helper->{DATA}{origslot}}('endtime');
63: </defaultvalue>
64: </date>
65: <message>
66: <br />Type:
67: </message>
68: <choices variable="type">
69: <choice computer='preassigned'>Instructor asssignable.</choice>
70: <choice computer='schedulable_student'>Student selectable.</choice>
71: <defaultvalue>
72: return &{$helper->{DATA}{origslot}}('type','preassigned');
73: </defaultvalue>
74: </choices>
75: </state>
76:
77: <state name="OPTIONAL" title="Specify Optional Attributes">
78: <message>
79: <p>Description:<br />
80: </message>
81: <string variable="description" size="60">
82: <defaultvalue>
83: return &{$helper->{DATA}{origslot}}('description');
84: </defaultvalue>
85: </string>
86: <condition>
87: <clause>$helper->{'VARS'}{'type'} eq 'schedulable_student'</clause>
88: <message>
89: </p><p>Time students can start reserving:<br />
90: </message>
91: <date variable="startreserve" hoursminutes="1" anytime="1">
92: <defaultvalue>
93: return &{$helper->{DATA}{origslot}}('startreserve','anytime');
94: </defaultvalue>
95: </date>
96: <message>
97: </p><p>Maxium number of students allowed in this slot:<br />
98: </message>
99: <string variable="maxspace" size="4">
100: <validator>
101: if ($val ne '' && $val=~/\D/) { return 'Must be numeric.'; }
102: return undef;
103: </validator>
104: <defaultvalue>
105: return &{$helper->{DATA}{origslot}}('maxspace');
106: </defaultvalue>
107: </string>
108: <message>
109: </p><p>Period of time in which this slot is can only be uniquely chosen:<br /> Start:
110: </message>
111: <date variable="startunique" hoursminutes="1" anytime="1">
112: <defaultvalue>
113: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
114: if ($default eq 'anytime') { return 'anytime' };
115: if (ref($default)) { return $default->[0]; }
116: return 'anytime';
117: </defaultvalue>
118: </date>
119: <message><br /> End: </message>
120: <date variable="endunique" hoursminutes="1" anytime="1">
121: <defaultvalue>
122: my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
123: if ($default eq 'anytime') { return 'anytime' };
124: if (ref($default)) { return $default->[1]; }
125: return 'anytime';
126: </defaultvalue>
127: </date>
128: </condition>
129: <condition>
130: <clause>$helper->{'VARS'}{'type'} eq 'preassigned'</clause>
131: <exec>
132: delete($helper->{'VARS'}{'startreserve'});
133: delete($helper->{'VARS'}{'maxspace'});
134: delete($helper->{'VARS'}{'startunique'});
135: delete($helper->{'VARS'}{'endunique'});
136: </exec>
137: </condition>
138: <message>
139: </p><p>Secret word proctors use to checkin users:<br />
140: </message>
141: <string variable="secret" size="12">
142: <validator>
143: return undef;
144: </validator>
145: <defaultvalue>
146: return &{$helper->{DATA}{origslot}}('secret');
147: </defaultvalue>
148: </string>
149: <message>
150: </p><p>Slot is:
151: </message>
152: <choices variable="restricttosymb">
153: <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
154: <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
155: <defaultvalue>
156: my $default=&{$helper->{DATA}{origslot}}('symb');
157: if ($default) { return 'resource'; }
158: return 'any';
159: </defaultvalue>
160: </choices>
161: <message>
162:
163: </p><p>IP restrictions:<br />
164:
165: </message>
166: <string variable="ip" size="30">
167: <validator>
168: return undef;
169: </validator>
170: <defaultvalue>
171: return &{$helper->{DATA}{origslot}}('ip');
172: </defaultvalue>
173: </string>
174: <message> </p> </message>
175: </state>
176: <state name="RESOURCESELECT" title="Specify Optional Attributes">
177: <resource variable="symb">
178: <filterfunc>return $res->is_problem()</filterfunc>
179: <valuefunc>return $res->symb()</valuefunc>
180: <nextstate>PROCTOR</nextstate>
181: <defaultvalue>
182: return &{$helper->{DATA}{origslot}}('symb');
183: </defaultvalue>
184: </resource>
185: </state>
186: <state name="PROCTOR" title="Specify Proctors">
187: <student variable="proctor" multichoice="1" coursepersonnel="1"
188: nextstate="FINISH" activeonly="1" emptyallowed="1">
189: <defaultvalue>
190: my @defaults;
191: my $default=&{$helper->{DATA}{origslot}}('proctor');
192: if ($default) {
193: $default=~ tr/@/:/;
194: @defaults=(split(',',$default));
195: }
196: return @defaults;
197: </defaultvalue>
198: </student>
199: </state>
200: <state name="FINISH" title="Creating/Modfying Slot">
201: <message> Created Slot </message>
202: <final>
203: <finalcode>
204: my $result;
205: if ($helper->{'STATE'} ne 'FINISH') { return; }
206: my %slot;
207: foreach my $which ('type','starttime','endtime') {
208: $slot{$which} = $helper->{'VARS'}{$which};
209: }
210: foreach my $which ('ip','description','maxspace',
211: 'secret','symb') {
212: if ( $helper->{'VARS'}{$which} =~/\S/ ) {
213: $slot{$which} = $helper->{'VARS'}{$which};
214: }
215: }
216: if ( $helper->{'VARS'}{'startunique'} > 0 &&
217: $helper->{'VARS'}{'endunique'} > 0 ) {
218: $slot{'uniqueperiod'} = [$helper->{'VARS'}{'startunique'},
219: $helper->{'VARS'}{'endunique'}];
220: }
221: if ( $helper->{'VARS'}{'proctor'} =~/\S/ ) {
222: my @names;
223: foreach my $user (split(/\|\|\|/, $helper->{'VARS'}{'proctor'})) {
224: my ($uname,$udomain)=split(/:/,$user);
225: push(@names,"$uname\@$udomain");
226: }
227: # make sure the usenrmaes are unique
228: my %proctors = map { ($_,1) } @names;
229: $slot{'proctor'}=join(',',sort(keys(%proctors)));
230: }
231: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
232: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
233:
234: my $ret = &Apache::lonnet::cput('slots',
235: {$helper->{'VARS'}{'name'} => \%slot},
236: $cdom,$cname);
237: $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
238: "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
239: "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
240: "\n".'<li> Type: '.$slot{'type'}.'</li>';
241: my %labels =
242: map {($_->[0],$_->[1])} &Apache::slotrequest::csvupload_fields();
243: foreach my $which ('ip','description','maxspace','secret','symb') {
244: if (exists($slot{$which})) {
245: $result.="\n".'<li> '.$labels{$which}.': '.
246: &HTML::Entities::encode($slot{$which}).'</li>';
247: }
248: }
249: if (exists($slot{'proctor'})) {
250: my $proctors = $slot{'proctor'};
251: $proctors =~ s/,/, /g;
252: $result.="\n".'<li> '.$labels{'proctor'}.': '.
253: &HTML::Entities::encode($proctors).'</li>';
254: }
255: if (exists($slot{'uniqueperiod'})) {
256: $result.=
257: "\n".'<li> '.$labels{'uniqueperiod'}.': '.
258: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[0]).
259: ', '.
260: &Apache::lonlocal::locallocaltime($slot{'uniqueperiod'}[1]).
261: '</li>';
262: }
263: return $result;
264: </finalcode>
265: <exitpage>/adm/slotrequest?command=showslots</exitpage>
266: </final>
267: </state>
268: </helper>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>