Annotation of loncom/interface/lonparmset.pm, revision 1.14
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.13 www 12: # 11/20,11/21,11/22,11/23,11/24,11/25,11/27 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'}.'.['.
1.14 ! www 56: $csec.'].'.$what;
1.10 www 57: my $seclevelr=
58: $ENV{'request.course.id'}.'.['.
1.14 ! www 59: $csec.'].'.$symbparm;
1.10 www 60: my $seclevelm=
61: $ENV{'request.course.id'}.'.['.
1.14 ! www 62: $csec.'].'.$mapparm;
1.10 www 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:
1.12 www 176: my $message='';
177:
178: $csec=$ENV{'form.csec'};
1.2 www 179: $udom=$ENV{'form.udom'};
1.12 www 180: my $id=$ENV{'form.id'};
181: if (($id) && ($udom)) {
182: $uname=(&Apache::lonnet::idget($udom,$id))[1];
183: if ($uname) {
184: $id='';
185: } else {
186: $message=
187: "<h3><font color=red>Unknown ID '$id' at domain '$udom'</font></h3>";
188: }
189: } else {
190: $uname=$ENV{'form.uname'};
191: }
1.2 www 192: unless ($udom) { $uname=''; }
193: $uhome='';
194: if ($uname) {
195: $uhome=&Apache::lonnet::homeserver($uname,$udom);
1.12 www 196:
197: if ($uhome eq 'no_host') {
1.3 www 198: $message=
1.8 www 199: "<h3><font color=red>Unknown user '$uname' at domain '$udom'</font></h3>";
1.3 www 200: $uname='';
1.12 www 201: } else {
202: $csec=&Apache::lonnet::usection(
203: $udom,$uname,$ENV{'request.course.id'});
204: if ($csec eq '-1') {
205: $message="<h3><font color=red>".
206: "User '$uname' at domain '$udom' not in this course</font></h3>";
207: $uname='';
208: $csec=$ENV{'form.csec'};
209: } else {
210: my %name=&Apache::lonnet::userenvironment($udom,$uname,
211: ('firstname','middlename','lastname','generation','id'));
212: $message="\n<p>\nFull Name: ".
213: $name{'firstname'}.' '.$name{'middlename'}
214: .$name{'lastname'}.' '.$name{'generation'}.
215: "<br>\nID: ".$name{'id'}.'<p>';
216: }
217: }
1.3 www 218: }
1.2 www 219:
1.3 www 220: unless ($csec) { $csec=''; }
1.12 www 221:
1.3 www 222: $fcat=$ENV{'form.fcat'};
223: unless ($fcat) { $fcat=''; }
1.2 www 224:
225: # ------------------------------------------------------------------- Tie hashs
226: if ((tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
227: &GDBM_READER,0640)) &&
228: (tie(%parmhash,'GDBM_File',
229: $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640))) {
230:
1.14 ! www 231: # --------------------------------------------------------- Get all assessments
! 232: map {
! 233: if ($_=~/^src\_(\d+)\.(\d+)$/) {
! 234: my $mapid=$1;
! 235: my $resid=$2;
! 236: my $id=$mapid.'.'.$resid;
! 237: if ($bighash{$_}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
! 238: $ids[$#ids+1]=$id;
! 239: $typep{$id}=$1;
! 240: $mapp{$id}=
! 241: &Apache::lonnet::declutter($bighash{'map_id_'.$mapid});
! 242: $symbp{$id}=$mapp{$id}.
! 243: '___'.$resid.'___'.
! 244: &Apache::lonnet::declutter($bighash{$_});
! 245: }
! 246: }
! 247: } keys %bighash;
! 248: # ---------------------------------------------------------- Anything to store?
! 249: if ($ENV{'form.pres_marker'}) {
! 250: my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
! 251:
! 252: my $symbparm=$symbp{$sresid}.'.'.$spnam;
! 253: my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
! 254:
! 255: my $seclevel=
! 256: $ENV{'request.course.id'}.'.['.
! 257: $csec.'].'.$spnam;
! 258: my $seclevelr=
! 259: $ENV{'request.course.id'}.'.['.
! 260: $csec.'].'.$symbparm;
! 261: my $seclevelm=
! 262: $ENV{'request.course.id'}.'.['.
! 263: $csec.'].'.$mapparm;
! 264:
! 265: my $courselevel=
! 266: $ENV{'request.course.id'}.'.'.$spnam;
! 267: my $courselevelr=
! 268: $ENV{'request.course.id'}.'.'.$symbparm;
! 269: my $courselevelm=
! 270: $ENV{'request.course.id'}.'.'.$mapparm;
! 271:
! 272: my $storeunder='';
! 273: if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
! 274: if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
! 275: if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
! 276: if ($snum==6) { $storeunder=$seclevel; }
! 277: if ($snum==5) { $storeunder=$seclevelm; }
! 278: if ($snum==4) { $storeunder=$seclevelr; }
! 279:
! 280:
! 281: $message.="<h1>Storing $ENV{'form.pres_value'} type $ENV{'form.pres_type'} under $ENV{'form.pres_marker'} in $storeunder</h1>";
! 282:
! 283:
! 284: # ---------------------------------------------------------- Construct prefixes
! 285: if ($snum>3) {
! 286: # ---------------------------------------------------------------- Store Course
! 287: } else {
! 288: # ------------------------------------------------------------------ Store User
! 289: }
! 290: }
! 291:
1.2 www 292: # -------------------------------------------------------------- Get coursedata
293: my $reply=&Apache::lonnet::reply('dump:'.
294: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
295: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata',
296: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
297: if ($reply!~/^error\:/) {
298: map {
299: my ($name,$value)=split(/\=/,$_);
300: $courseopt{unescape($name)}=unescape($value);
301: } split(/\&/,$reply);
302: }
303: # --------------------------------------------------- Get userdata (if present)
304: if ($uname) {
305: my $reply=
306: &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
307: if ($reply!~/^error\:/) {
308: map {
309: my ($name,$value)=split(/\=/,$_);
310: $useropt{unescape($name)}=unescape($value);
311: } split(/\&/,$reply);
312: }
313: }
1.14 ! www 314:
1.2 www 315: # ------------------------------------------------------------------- Sort this
1.3 www 316: @ids=sort bycat @ids;
1.2 www 317: # ------------------------------------------------------------------ Start page
1.1 www 318: $r->content_type('text/html');
319: $r->send_http_header;
1.5 www 320: $r->print(<<ENDHEAD);
321: <html>
322: <head>
323: <title>LON-CAPA Assessment Parameters</title>
324: <script>
1.13 www 325:
1.5 www 326: function pclose() {
327: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
328: "height=350,width=350,scrollbars=no,menubar=no");
329: parmwin.close();
330: }
331:
332: function pjump(type,dis,value,marker,ret,call) {
1.13 www 333: document.parmform.pres_marker.value='';
1.6 www 334: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
335: +"&value="+escape(value)+"&marker="+escape(marker)
336: +"&return="+escape(ret)
337: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
1.5 www 338: "height=350,width=350,scrollbars=no,menubar=no");
339:
340: }
1.13 www 341:
342: function psub() {
343: pclose();
344: if ((document.parmform.pres_value.value!='') &&
345: (document.parmform.pres_marker.value!='')) {
346: document.parmform.submit();
347: } else {
348: document.parmform.pres_value.value='';
349: document.parmform.pres_marker.value='';
350: }
351: }
352:
1.5 www 353: </script>
354: </head>
355: <body bgcolor="#FFFFFF" onUnload="pclose()">
356: <h1>Set Assessment Parameters</h1>
1.8 www 357: <form method="post" action="/adm/parmset" name="parmform">
358: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
359: <b>
360: Section/Group:
1.12 www 361: <input type="text" value="$csec" size="6" name="csec">
1.8 www 362: <br>
363: For User
1.12 www 364: <input type="text" value="$uname" size="12" name="uname">
365: or ID
366: <input type="text" value="$id" size="12" name="id">
1.8 www 367: at Domain
1.12 www 368: <input type="text" value="$udom" size="6" name="udom">
1.8 www 369: </b>
1.12 www 370: <input type="submit" value="Display">
1.13 www 371: <input type="hidden" value='' name="pres_value">
372: <input type="hidden" value='' name="pres_type">
373: <input type="hidden" value='' name="pres_marker">
1.5 www 374: ENDHEAD
1.12 www 375:
376: $r->print($message.'<p>Sort list by ');
1.8 www 377: $r->print('<select name="fcat" onChange="this.form.submit();">');
378: my $k;
379: my @sopt=('map','Map','name','Problem Name','deadline','Deadline');
380: for ($k=0;$k<$#sopt;$k=$k+2) {
381: $r->print('<option value="'.$sopt[$k].'"');
382: if ($fcat eq $sopt[$k]) { $r->print(' selected'); }
383: $r->print('>'.$sopt[$k+1].'</option>');
384: }
385: $r->print('</select>');
1.10 www 386: # ----------------------------------------------------------------- Start Table
387: my $coursespan=$csec?8:5;
1.9 www 388: $r->print(<<ENDTABLEHEAD);
389: <p><table border=2>
1.11 www 390: <tr><td colspan=5></td>
1.10 www 391: <th colspan=$coursespan>Any User</th>
1.9 www 392: ENDTABLEHEAD
1.10 www 393: if ($uname) {
394: $r->print("<th colspan=3 rowspan=2>User $uname at Domain $udom</th>");
395: }
396: $r->print(<<ENDTABLETWO);
1.11 www 397: <th rowspan=3>Parameter in Effect</th></tr><tr><td colspan=5></td>
1.10 www 398: <th colspan=2>Resource Level</th>
399: <th colspan=3>in Course</th>
400: ENDTABLETWO
1.9 www 401: if ($csec) {
1.10 www 402: $r->print("<th colspan=3>in Section/Group $csec</th>");
1.9 www 403: }
1.10 www 404: $r->print(<<ENDTABLEHEADFOUR);
1.11 www 405: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1.10 www 406: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
1.11 www 407: <th>default</th><th>from Enclosing Map</th>
1.10 www 408: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
409: ENDTABLEHEADFOUR
410: if ($csec) {
411: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
412: }
413: if ($uname) {
414: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
415: }
416: $r->print('</tr><tr>');
1.3 www 417: map {
1.4 www 418: # ------------------------------------------------------ Entry for one resource
1.8 www 419: @outpar=();
1.5 www 420: my $rid=$_;
421: my $thistitle='';
1.11 www 422: my %name= ('0_deadline' => 'deadline');
423: my %part= ('0_deadline' => '0');
424: my %display=('0_deadline' => 'Deadline');
425: my %type= ('0_deadline' => 'date_end');
426: my %default=('0_deadline' => time);
1.4 www 427: my %metadata=&Apache::lonmeta::unpackagemeta(
1.5 www 428: &Apache::lonnet::getfile('/home/httpd/html/'.$bighash{'src_'.$rid}.'.meta'),1);
1.4 www 429: map {
1.5 www 430: if ($_=~/^parameter\_(\d+)\_(\w+)$/) {
1.11 www 431: my $hashid=$1.'_'.$2;
432: $part{$hashid}=$1;
433: $name{$hashid}=$2;
434: my $tdef;
435: ($tdef,$display{$hashid})=
1.5 www 436: split(/\_\_dis\_\_/,$metadata{$_});
1.11 www 437: ($type{$hashid},$default{$hashid})=split(/\:/,$tdef);
438: unless ($display{$hashid}) {
439: $display{$hashid}=$name{$hashid};
1.5 www 440: }
441: }
442: if ($_ eq 'title') {
443: $thistitle=$metadata{$_};
1.4 www 444: }
445: } keys %metadata;
1.11 www 446: my $totalparms=scalar keys %name;
1.5 www 447: $r->print('<td rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 448: join(' / ',split(/\//,&Apache::lonnet::declutter($bighash{'src_'.$rid}))).
449: '</font></tt><p><b>'.
1.5 www 450: $bighash{'title_'.$rid});
451: if ($thistitle) {
452: $r->print(' ('.$thistitle.')');
453: }
1.11 www 454: $r->print('</b></td>');
455: $r->print('<td rowspan='.$totalparms.'>'.$typep{$rid}.'</td>');
456: $r->print('<td rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 457: join(' / ',split(/\//,$mapp{$rid})).'</font></tt></td>');
1.11 www 458: map {
459:
460: my $result=&parmval($part{$_}.'.'.$name{$_},$rid,$default{$_});
461:
462: $r->print("<td>$part{$_}</td><td>$display{$_}</td>");
1.12 www 463: my $mprefix=$rid.'&'.$_.'&';
1.13 www 464:
1.12 www 465: $r->print('<td'.(($result==11)?' bgcolor="#AAFFAA"':'').'>'.
466: &valout($outpar[11],$type{$_}).'</td>');
467: $r->print('<td'.(($result==10)?' bgcolor="#AAFFAA"':'').'>'.
468: &valout($outpar[10],$type{$_}).'</td>');
1.13 www 469:
1.12 www 470: $r->print('<td'.(($result==9)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 471: &plink($type{$_},$display{$_},$outpar[9],$mprefix.'9',
472: 'parmform.pres','psub').'</td>');
1.12 www 473: $r->print('<td'.(($result==8)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 474: &plink($type{$_},$display{$_},$outpar[8],$mprefix.'8',
475: 'parmform.pres','psub').'</td>');
1.12 www 476: $r->print('<td'.(($result==7)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 477: &plink($type{$_},$display{$_},$outpar[7],$mprefix.'7',
478: 'parmform.pres','psub').'</td>');
479:
1.9 www 480: if ($csec) {
1.12 www 481: $r->print('<td'.(($result==6)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 482: &plink($type{$_},$display{$_},$outpar[6],$mprefix.'6',
483: 'parmform.pres','psub').'</td>');
1.12 www 484: $r->print('<td'.(($result==5)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 485: &plink($type{$_},$display{$_},$outpar[5],$mprefix.'5',
486: 'parmform.pres','psub').'</td>');
1.12 www 487: $r->print('<td'.(($result==4)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 488: &plink($type{$_},$display{$_},$outpar[4],$mprefix.'4',
489: 'parmform.pres','psub').'</td>');
1.9 www 490: }
1.13 www 491:
1.9 www 492: if ($uname) {
1.12 www 493: $r->print('<td'.(($result==3)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 494: &plink($type{$_},$display{$_},$outpar[3],$mprefix.'3',
495: 'parmform.pres','psub').'</td>');
1.12 www 496: $r->print('<td'.(($result==2)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 497: &plink($type{$_},$display{$_},$outpar[2],$mprefix.'2',
498: 'parmform.pres','psub').'</td>');
1.12 www 499: $r->print('<td'.(($result==1)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 500: &plink($type{$_},$display{$_},$outpar[1],$mprefix.'1',
501: 'parmform.pres','psub').'</td>');
1.9 www 502: }
1.13 www 503:
1.11 www 504: $r->print('<td>'.&valout($outpar[$result],$type{$_}).'</td>');
1.5 www 505: $r->print("</tr>\n<tr>");
1.11 www 506: } sort keys %name;
1.4 www 507: # -------------------------------------------------- End entry for one resource
1.3 www 508: } @ids;
1.8 www 509: $r->print('</table></form></body></html>');
1.1 www 510: untie(%bighash);
1.2 www 511: untie(%parmhash);
1.1 www 512: }
513: } else {
514: # ----------------------------- Not in a course, or not allowed to modify parms
515: $ENV{'user.error.msg'}=
1.7 www 516: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
1.1 www 517: return HTTP_NOT_ACCEPTABLE;
518: }
519: return OK;
520: }
521:
522: 1;
523: __END__
524:
525:
526:
527:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>