Annotation of loncom/interface/lonparmset.pm, revision 1.11
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
4: # (Handler to resolve ambiguous file locations
5: #
6: # (TeX Content Handler
7: #
8: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
9: #
10: # 10/11,10/12,10/16 Gerd Kortemeyer)
11: #
1.9 www 12: # 11/20,11/21,11/22,11/23,11/24,11/25 Gerd Kortemeyer
1.1 www 13:
14: package Apache::lonparmset;
15:
16: use strict;
17: use Apache::lonnet;
18: use Apache::Constants qw(:common :http REDIRECT);
19: use GDBM_File;
1.4 www 20: use Apache::lonmeta;
21:
1.1 www 22:
1.2 www 23: my %courseopt;
24: my %useropt;
25: my %bighash;
26: my %parmhash;
27:
1.8 www 28: my @outpar;
29:
1.3 www 30: my @ids;
31: my %symbp;
1.10 www 32: my %mapp;
1.3 www 33: my %typep;
1.2 www 34:
35: my $uname;
36: my $udom;
37: my $uhome;
38:
39: my $csec;
40:
1.3 www 41: my $fcat;
42:
1.2 www 43: # -------------------------------------------- Figure out a cascading parameter
44:
45: sub parmval {
1.11 ! www 46: my ($what,$id,$def)=@_;
1.8 www 47: my $result='';
1.11 ! www 48: @outpar=();
1.2 www 49: # ----------------------------------------------------- Cascading lookup scheme
1.10 www 50:
1.3 www 51: my $symbparm=$symbp{$id}.'.'.$what;
1.10 www 52: my $mapparm=$mapp{$id}.'___(all).'.$what;
53:
1.2 www 54: my $seclevel=
1.10 www 55: $ENV{'request.course.id'}.'.['.
56: $ENV{'request.course.sec'}.'].'.$what;
57: my $seclevelr=
58: $ENV{'request.course.id'}.'.['.
59: $ENV{'request.course.sec'}.'].'.$symbparm;
60: my $seclevelm=
61: $ENV{'request.course.id'}.'.['.
62: $ENV{'request.course.sec'}.'].'.$mapparm;
63:
1.2 www 64: my $courselevel=
65: $ENV{'request.course.id'}.'.'.$what;
1.10 www 66: my $courselevelr=
67: $ENV{'request.course.id'}.'.'.$symbparm;
68: my $courselevelm=
69: $ENV{'request.course.id'}.'.'.$mapparm;
1.2 www 70:
1.11 ! www 71: # -------------------------------------------------------- first, check default
! 72:
! 73: if ($def) { $outpar[11]=$def;
! 74: $result=11; }
! 75:
! 76: # ----------------------------------------------------- second, check map parms
! 77:
! 78: my $thisparm=$parmhash{$symbparm};
! 79: if ($thisparm) { $outpar[10]=$thisparm;
! 80: $result=10; }
! 81:
! 82: # --------------------------------------------------------- third, check course
! 83:
! 84: if ($courseopt{$courselevel}) { $outpar[9]=$courseopt{$courselevel};
! 85: $result=9; }
! 86:
! 87: if ($courseopt{$courselevelm}) { $outpar[8]=$courseopt{$courselevelm};
! 88: $result=8; }
! 89:
! 90: if ($courseopt{$courselevelr}) { $outpar[7]=$courseopt{$courselevelr};
! 91: $result=7; }
! 92:
! 93: if ($csec) {
! 94:
! 95: if ($courseopt{$seclevel}) { $outpar[6]=$courseopt{$seclevel};
! 96: $result=6; }
! 97:
! 98: if ($courseopt{$seclevelm}) { $outpar[5]=$courseopt{$seclevelm};
! 99: $result=5; }
! 100:
! 101: if ($courseopt{$seclevelr}) { $outpar[4]=$courseopt{$seclevelr};
! 102: $result=4; }
! 103:
! 104: }
! 105:
! 106: # ---------------------------------------------------------- fourth, check user
1.8 www 107:
108: if ($uname) {
1.11 ! www 109:
1.10 www 110: if ($useropt{$courselevel}) { $outpar[3]=$useropt{$courselevel};
111: $result=3; }
112:
1.11 ! www 113: if ($useropt{$courselevelm}) { $outpar[2]=$useropt{$courselevelm};
! 114: $result=2; }
1.2 www 115:
1.11 ! www 116: if ($useropt{$courselevelr}) { $outpar[1]=$useropt{$courselevelr};
! 117: $result=1; }
1.10 www 118:
1.11 ! www 119: }
1.2 www 120:
1.8 www 121: return $result;
1.2 www 122: }
123:
1.3 www 124: # ---------------------------------------------------------------- Sort routine
125:
126: sub bycat {
127: if ($fcat eq '') {
128: $a<=>$b;
129: } else {
130: &parmval('0.'.$fcat,$a)<=>&parmval('0.'.$fcat,$b);
131: }
132: }
133:
1.9 www 134: # ------------------------------------------------------------ Output for value
135:
136: sub valout {
137: my ($value,$type)=@_;
138: return
139: ($value?(($type=~/^date/)?localtime($value):$value):' ');
140: }
141:
1.5 www 142: # -------------------------------------------------------- Produces link anchor
143:
144: sub plink {
145: my ($type,$dis,$value,$marker,$return,$call)=@_;
146: return '<a href="javascript:pjump('."'".$type."','".$dis."','".$value."','"
1.8 www 147: .$marker."','".$return."','".$call."'".');">'.
1.9 www 148: &valout($value,$type).'</a>';
1.5 www 149: }
150:
1.1 www 151: # ================================================================ Main Handler
152:
153: sub handler {
154: my $r=shift;
155:
156: if ($r->header_only) {
157: $r->content_type('text/html');
158: $r->send_http_header;
159: return OK;
160: }
161:
162: # ----------------------------------------------------- Needs to be in a course
163:
164: if (($ENV{'request.course.fn'}) &&
165: (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
1.2 www 166: # -------------------------------------------------------- Variable declaration
167:
168: %courseopt=();
169: %useropt=();
170: %bighash=();
171:
1.3 www 172: @ids=();
173: %symbp=();
174: %typep=();
1.2 www 175:
176: $uname=$ENV{'form.uname'};
177: $udom=$ENV{'form.udom'};
178: unless ($udom) { $uname=''; }
179: $uhome='';
1.3 www 180: my $message='';
1.2 www 181: if ($uname) {
182: $uhome=&Apache::lonnet::homeserver($uname,$udom);
183: }
1.3 www 184: if ($uhome eq 'no_host') {
185: $message=
1.8 www 186: "<h3><font color=red>Unknown user '$uname' at domain '$udom'</font></h3>";
1.3 www 187: $uname='';
188: }
1.2 www 189:
190: $csec=$ENV{'form.csec'};
1.3 www 191: unless ($csec) { $csec=''; }
192: $fcat=$ENV{'form.fcat'};
193: unless ($fcat) { $fcat=''; }
1.2 www 194:
195: # ------------------------------------------------------------------- Tie hashs
196: if ((tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
197: &GDBM_READER,0640)) &&
198: (tie(%parmhash,'GDBM_File',
199: $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640))) {
200:
201: # -------------------------------------------------------------- Get coursedata
202: my $reply=&Apache::lonnet::reply('dump:'.
203: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
204: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata',
205: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
206: if ($reply!~/^error\:/) {
207: map {
208: my ($name,$value)=split(/\=/,$_);
209: $courseopt{unescape($name)}=unescape($value);
210: } split(/\&/,$reply);
211: }
212: # --------------------------------------------------- Get userdata (if present)
213: if ($uname) {
214: my $reply=
215: &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
216: if ($reply!~/^error\:/) {
217: map {
218: my ($name,$value)=split(/\=/,$_);
219: $useropt{unescape($name)}=unescape($value);
220: } split(/\&/,$reply);
221: }
222: }
223: # --------------------------------------------------------- Get all assessments
224: map {
225: if ($_=~/^src\_(\d+)\.(\d+)$/) {
226: my $mapid=$1;
227: my $resid=$2;
1.3 www 228: my $id=$mapid.'.'.$resid;
1.2 www 229: if ($bighash{$_}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.3 www 230: $ids[$#ids+1]=$id;
231: $typep{$id}=$1;
1.10 www 232: $mapp{$id}=
233: &Apache::lonnet::declutter($bighash{'map_id_'.$mapid});
234: $symbp{$id}=$mapp{$id}.
1.3 www 235: '___'.$resid.'___'.
236: &Apache::lonnet::declutter($bighash{$_});
1.2 www 237: }
238: }
239: } keys %bighash;
240: # ------------------------------------------------------------------- Sort this
1.3 www 241: @ids=sort bycat @ids;
1.2 www 242: # ------------------------------------------------------------------ Start page
1.1 www 243: $r->content_type('text/html');
244: $r->send_http_header;
1.5 www 245: $r->print(<<ENDHEAD);
246: <html>
247: <head>
248: <title>LON-CAPA Assessment Parameters</title>
249: <script>
250: function pclose() {
251: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
252: "height=350,width=350,scrollbars=no,menubar=no");
253: parmwin.close();
254: }
255:
256: function pjump(type,dis,value,marker,ret,call) {
1.6 www 257: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
258: +"&value="+escape(value)+"&marker="+escape(marker)
259: +"&return="+escape(ret)
260: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
1.5 www 261: "height=350,width=350,scrollbars=no,menubar=no");
262:
263: }
264: </script>
265: </head>
266: <body bgcolor="#FFFFFF" onUnload="pclose()">
267: <h1>Set Assessment Parameters</h1>
1.8 www 268: <form method="post" action="/adm/parmset" name="parmform">
269: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
270: <b>
271: Section/Group:
272: <input type="text" value="$csec" size="6" name="csec"
273: onBlur="this.form.submit();">
274: <br>
275: For User
276: <input type="text" value="$uname" size="12" name="uname"
277: onBlur="if (this.form.udom.value) { this.form.submit(); }">
278: at Domain
279: <input type="text" value="$udom" size="6" name="udom"
280: onBlur="if (this.form.uname.value) { this.form.submit(); }">
281: </b>
1.5 www 282: ENDHEAD
1.8 www 283:
1.3 www 284: if ($uhome eq 'no_host') {
285: $r->print($message);
286: }
1.8 www 287: $r->print('<p>Sort list by ');
288: $r->print('<select name="fcat" onChange="this.form.submit();">');
289: my $k;
290: my @sopt=('map','Map','name','Problem Name','deadline','Deadline');
291: for ($k=0;$k<$#sopt;$k=$k+2) {
292: $r->print('<option value="'.$sopt[$k].'"');
293: if ($fcat eq $sopt[$k]) { $r->print(' selected'); }
294: $r->print('>'.$sopt[$k+1].'</option>');
295: }
296: $r->print('</select>');
1.10 www 297: # ----------------------------------------------------------------- Start Table
298: my $coursespan=$csec?8:5;
1.9 www 299: $r->print(<<ENDTABLEHEAD);
300: <p><table border=2>
1.11 ! www 301: <tr><td colspan=5></td>
1.10 www 302: <th colspan=$coursespan>Any User</th>
1.9 www 303: ENDTABLEHEAD
1.10 www 304: if ($uname) {
305: $r->print("<th colspan=3 rowspan=2>User $uname at Domain $udom</th>");
306: }
307: $r->print(<<ENDTABLETWO);
1.11 ! www 308: <th rowspan=3>Parameter in Effect</th></tr><tr><td colspan=5></td>
1.10 www 309: <th colspan=2>Resource Level</th>
310: <th colspan=3>in Course</th>
311: ENDTABLETWO
1.9 www 312: if ($csec) {
1.10 www 313: $r->print("<th colspan=3>in Section/Group $csec</th>");
1.9 www 314: }
1.10 www 315: $r->print(<<ENDTABLEHEADFOUR);
1.11 ! www 316: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1.10 www 317: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
1.11 ! www 318: <th>default</th><th>from Enclosing Map</th>
1.10 www 319: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
320: ENDTABLEHEADFOUR
321: if ($csec) {
322: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
323: }
324: if ($uname) {
325: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
326: }
327: $r->print('</tr><tr>');
1.3 www 328: map {
1.4 www 329: # ------------------------------------------------------ Entry for one resource
1.8 www 330: @outpar=();
1.5 www 331: my $rid=$_;
332: my $thistitle='';
1.11 ! www 333: my %name= ('0_deadline' => 'deadline');
! 334: my %part= ('0_deadline' => '0');
! 335: my %display=('0_deadline' => 'Deadline');
! 336: my %type= ('0_deadline' => 'date_end');
! 337: my %default=('0_deadline' => time);
1.4 www 338: my %metadata=&Apache::lonmeta::unpackagemeta(
1.5 www 339: &Apache::lonnet::getfile('/home/httpd/html/'.$bighash{'src_'.$rid}.'.meta'),1);
1.4 www 340: map {
1.5 www 341: if ($_=~/^parameter\_(\d+)\_(\w+)$/) {
1.11 ! www 342: my $hashid=$1.'_'.$2;
! 343: $part{$hashid}=$1;
! 344: $name{$hashid}=$2;
! 345: my $tdef;
! 346: ($tdef,$display{$hashid})=
1.5 www 347: split(/\_\_dis\_\_/,$metadata{$_});
1.11 ! www 348: ($type{$hashid},$default{$hashid})=split(/\:/,$tdef);
! 349: unless ($display{$hashid}) {
! 350: $display{$hashid}=$name{$hashid};
1.5 www 351: }
352: }
353: if ($_ eq 'title') {
354: $thistitle=$metadata{$_};
1.4 www 355: }
356: } keys %metadata;
1.11 ! www 357: my $totalparms=scalar keys %name;
1.5 www 358: $r->print('<td rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 359: join(' / ',split(/\//,&Apache::lonnet::declutter($bighash{'src_'.$rid}))).
360: '</font></tt><p><b>'.
1.5 www 361: $bighash{'title_'.$rid});
362: if ($thistitle) {
363: $r->print(' ('.$thistitle.')');
364: }
1.11 ! www 365: $r->print('</b></td>');
! 366: $r->print('<td rowspan='.$totalparms.'>'.$typep{$rid}.'</td>');
! 367: $r->print('<td rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 368: join(' / ',split(/\//,$mapp{$rid})).'</font></tt></td>');
1.11 ! www 369: map {
! 370:
! 371: my $result=&parmval($part{$_}.'.'.$name{$_},$rid,$default{$_});
! 372:
! 373: $r->print("<td>$part{$_}</td><td>$display{$_}</td>");
! 374:
! 375: $r->print('<td>'.&valout($outpar[11],$type{$_}).'</td>');
! 376: $r->print('<td>'.&valout($outpar[10],$type{$_}).'</td>');
1.9 www 377: $r->print('<td>'.
1.11 ! www 378: &plink($type{$_},$display{$_},$outpar[9]).'</td>');
! 379: $r->print('<td>'.
! 380: &plink($type{$_},$display{$_},$outpar[8]).'</td>');
! 381: $r->print('<td>'.
! 382: &plink($type{$_},$display{$_},$outpar[7]).'</td>');
1.9 www 383: if ($csec) {
1.11 ! www 384: $r->print('<td>'.
! 385: &plink($type{$_},$display{$_},$outpar[6]).'</td>');
! 386: $r->print('<td>'.
! 387: &plink($type{$_},$display{$_},$outpar[5]).'</td>');
! 388: $r->print('<td>'.
! 389: &plink($type{$_},$display{$_},$outpar[4]).'</td>');
1.9 www 390: }
391: if ($uname) {
1.11 ! www 392: $r->print('<td>'.
! 393: &plink($type{$_},$display{$_},$outpar[3]).'</td>');
! 394: $r->print('<td>'.
! 395: &plink($type{$_},$display{$_},$outpar[2]).'</td>');
! 396: $r->print('<td>'.
! 397: &plink($type{$_},$display{$_},$outpar[1]).'</td>');
1.9 www 398: }
1.11 ! www 399: $r->print('<td>'.&valout($outpar[$result],$type{$_}).'</td>');
1.5 www 400: $r->print("</tr>\n<tr>");
1.11 ! www 401: } sort keys %name;
1.4 www 402: # -------------------------------------------------- End entry for one resource
1.3 www 403: } @ids;
1.8 www 404: $r->print('</table></form></body></html>');
1.1 www 405: untie(%bighash);
1.2 www 406: untie(%parmhash);
1.1 www 407: }
408: } else {
409: # ----------------------------- Not in a course, or not allowed to modify parms
410: $ENV{'user.error.msg'}=
1.7 www 411: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
1.1 www 412: return HTTP_NOT_ACCEPTABLE;
413: }
414: return OK;
415: }
416:
417: 1;
418: __END__
419:
420:
421:
422:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>