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