Annotation of loncom/interface/lonparmset.pm, revision 1.15
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'});
1.15 ! www 251: $spnam=~s/\_/\./;
! 252: # ---------------------------------------------------------- Construct prefixes
1.14 www 253:
254: my $symbparm=$symbp{$sresid}.'.'.$spnam;
255: my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
256:
257: my $seclevel=
258: $ENV{'request.course.id'}.'.['.
259: $csec.'].'.$spnam;
260: my $seclevelr=
261: $ENV{'request.course.id'}.'.['.
262: $csec.'].'.$symbparm;
263: my $seclevelm=
264: $ENV{'request.course.id'}.'.['.
265: $csec.'].'.$mapparm;
266:
267: my $courselevel=
268: $ENV{'request.course.id'}.'.'.$spnam;
269: my $courselevelr=
270: $ENV{'request.course.id'}.'.'.$symbparm;
271: my $courselevelm=
272: $ENV{'request.course.id'}.'.'.$mapparm;
273:
274: my $storeunder='';
275: if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
276: if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
277: if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
278: if ($snum==6) { $storeunder=$seclevel; }
279: if ($snum==5) { $storeunder=$seclevelm; }
280: if ($snum==4) { $storeunder=$seclevelr; }
1.15 ! www 281: $storeunder=&Apache::lonnet::escape($storeunder);
! 282:
! 283: my $storecontent=
! 284: $storeunder.'='.&Apache::lonnet::escape($ENV{'form.pres_value'}).'&'.
! 285: $storeunder.'.type='.&Apache::lonnet::escape($ENV{'form.pres_type'});
1.14 www 286:
1.15 ! www 287: my $reply='';
1.14 www 288: if ($snum>3) {
289: # ---------------------------------------------------------------- Store Course
1.15 ! www 290: $reply=&Apache::lonnet::critical('put:'.
! 291: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
! 292: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata:'.
! 293: $storecontent,
! 294: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
1.14 www 295: } else {
296: # ------------------------------------------------------------------ Store User
1.15 ! www 297: $reply=
! 298: &Apache::lonnet::critical('put:'.$udom.':'.$uname.':resourcedata:'.
! 299: $storecontent,$uhome);
! 300: }
! 301:
! 302: if ($reply=~/^error\:(.*)/) {
! 303: $message.="<h3><font color=red>Write Error: $1</font></h3>";
! 304: }
! 305: # ---------------------------------------------------------------- Done storing
! 306: }
1.2 www 307: # -------------------------------------------------------------- Get coursedata
308: my $reply=&Apache::lonnet::reply('dump:'.
309: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
310: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata',
311: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
312: if ($reply!~/^error\:/) {
313: map {
314: my ($name,$value)=split(/\=/,$_);
1.15 ! www 315: $courseopt{&Apache::lonnet::unescape($name)}=
! 316: &Apache::lonnet::unescape($value);
1.2 www 317: } split(/\&/,$reply);
318: }
319: # --------------------------------------------------- Get userdata (if present)
320: if ($uname) {
321: my $reply=
322: &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
323: if ($reply!~/^error\:/) {
324: map {
325: my ($name,$value)=split(/\=/,$_);
1.15 ! www 326: $useropt{&Apache::lonnet::unescape($name)}=
! 327: &Apache::lonnet::unescape($value);
1.2 www 328: } split(/\&/,$reply);
329: }
330: }
1.14 www 331:
1.2 www 332: # ------------------------------------------------------------------- Sort this
1.3 www 333: @ids=sort bycat @ids;
1.2 www 334: # ------------------------------------------------------------------ Start page
1.1 www 335: $r->content_type('text/html');
336: $r->send_http_header;
1.5 www 337: $r->print(<<ENDHEAD);
338: <html>
339: <head>
340: <title>LON-CAPA Assessment Parameters</title>
341: <script>
1.13 www 342:
1.5 www 343: function pclose() {
344: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
345: "height=350,width=350,scrollbars=no,menubar=no");
346: parmwin.close();
347: }
348:
349: function pjump(type,dis,value,marker,ret,call) {
1.13 www 350: document.parmform.pres_marker.value='';
1.6 www 351: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
352: +"&value="+escape(value)+"&marker="+escape(marker)
353: +"&return="+escape(ret)
354: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
1.5 www 355: "height=350,width=350,scrollbars=no,menubar=no");
356:
357: }
1.13 www 358:
359: function psub() {
360: pclose();
361: if ((document.parmform.pres_value.value!='') &&
362: (document.parmform.pres_marker.value!='')) {
363: document.parmform.submit();
364: } else {
365: document.parmform.pres_value.value='';
366: document.parmform.pres_marker.value='';
367: }
368: }
369:
1.5 www 370: </script>
371: </head>
372: <body bgcolor="#FFFFFF" onUnload="pclose()">
373: <h1>Set Assessment Parameters</h1>
1.8 www 374: <form method="post" action="/adm/parmset" name="parmform">
375: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
376: <b>
377: Section/Group:
1.12 www 378: <input type="text" value="$csec" size="6" name="csec">
1.8 www 379: <br>
380: For User
1.12 www 381: <input type="text" value="$uname" size="12" name="uname">
382: or ID
383: <input type="text" value="$id" size="12" name="id">
1.8 www 384: at Domain
1.12 www 385: <input type="text" value="$udom" size="6" name="udom">
1.8 www 386: </b>
1.12 www 387: <input type="submit" value="Display">
1.13 www 388: <input type="hidden" value='' name="pres_value">
389: <input type="hidden" value='' name="pres_type">
390: <input type="hidden" value='' name="pres_marker">
1.5 www 391: ENDHEAD
1.12 www 392:
393: $r->print($message.'<p>Sort list by ');
1.8 www 394: $r->print('<select name="fcat" onChange="this.form.submit();">');
395: my $k;
396: my @sopt=('map','Map','name','Problem Name','deadline','Deadline');
397: for ($k=0;$k<$#sopt;$k=$k+2) {
398: $r->print('<option value="'.$sopt[$k].'"');
399: if ($fcat eq $sopt[$k]) { $r->print(' selected'); }
400: $r->print('>'.$sopt[$k+1].'</option>');
401: }
402: $r->print('</select>');
1.10 www 403: # ----------------------------------------------------------------- Start Table
404: my $coursespan=$csec?8:5;
1.9 www 405: $r->print(<<ENDTABLEHEAD);
406: <p><table border=2>
1.11 www 407: <tr><td colspan=5></td>
1.10 www 408: <th colspan=$coursespan>Any User</th>
1.9 www 409: ENDTABLEHEAD
1.10 www 410: if ($uname) {
411: $r->print("<th colspan=3 rowspan=2>User $uname at Domain $udom</th>");
412: }
413: $r->print(<<ENDTABLETWO);
1.11 www 414: <th rowspan=3>Parameter in Effect</th></tr><tr><td colspan=5></td>
1.10 www 415: <th colspan=2>Resource Level</th>
416: <th colspan=3>in Course</th>
417: ENDTABLETWO
1.9 www 418: if ($csec) {
1.10 www 419: $r->print("<th colspan=3>in Section/Group $csec</th>");
1.9 www 420: }
1.10 www 421: $r->print(<<ENDTABLEHEADFOUR);
1.11 www 422: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1.10 www 423: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
1.11 www 424: <th>default</th><th>from Enclosing Map</th>
1.10 www 425: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
426: ENDTABLEHEADFOUR
427: if ($csec) {
428: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
429: }
430: if ($uname) {
431: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
432: }
433: $r->print('</tr><tr>');
1.3 www 434: map {
1.4 www 435: # ------------------------------------------------------ Entry for one resource
1.8 www 436: @outpar=();
1.5 www 437: my $rid=$_;
438: my $thistitle='';
1.11 www 439: my %name= ('0_deadline' => 'deadline');
440: my %part= ('0_deadline' => '0');
441: my %display=('0_deadline' => 'Deadline');
442: my %type= ('0_deadline' => 'date_end');
443: my %default=('0_deadline' => time);
1.4 www 444: my %metadata=&Apache::lonmeta::unpackagemeta(
1.5 www 445: &Apache::lonnet::getfile('/home/httpd/html/'.$bighash{'src_'.$rid}.'.meta'),1);
1.4 www 446: map {
1.5 www 447: if ($_=~/^parameter\_(\d+)\_(\w+)$/) {
1.11 www 448: my $hashid=$1.'_'.$2;
449: $part{$hashid}=$1;
450: $name{$hashid}=$2;
451: my $tdef;
452: ($tdef,$display{$hashid})=
1.5 www 453: split(/\_\_dis\_\_/,$metadata{$_});
1.11 www 454: ($type{$hashid},$default{$hashid})=split(/\:/,$tdef);
455: unless ($display{$hashid}) {
456: $display{$hashid}=$name{$hashid};
1.5 www 457: }
458: }
459: if ($_ eq 'title') {
460: $thistitle=$metadata{$_};
1.4 www 461: }
462: } keys %metadata;
1.11 www 463: my $totalparms=scalar keys %name;
1.5 www 464: $r->print('<td rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 465: join(' / ',split(/\//,&Apache::lonnet::declutter($bighash{'src_'.$rid}))).
466: '</font></tt><p><b>'.
1.5 www 467: $bighash{'title_'.$rid});
468: if ($thistitle) {
469: $r->print(' ('.$thistitle.')');
470: }
1.11 www 471: $r->print('</b></td>');
472: $r->print('<td rowspan='.$totalparms.'>'.$typep{$rid}.'</td>');
473: $r->print('<td rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 474: join(' / ',split(/\//,$mapp{$rid})).'</font></tt></td>');
1.11 www 475: map {
476:
477: my $result=&parmval($part{$_}.'.'.$name{$_},$rid,$default{$_});
478:
479: $r->print("<td>$part{$_}</td><td>$display{$_}</td>");
1.12 www 480: my $mprefix=$rid.'&'.$_.'&';
1.13 www 481:
1.12 www 482: $r->print('<td'.(($result==11)?' bgcolor="#AAFFAA"':'').'>'.
483: &valout($outpar[11],$type{$_}).'</td>');
484: $r->print('<td'.(($result==10)?' bgcolor="#AAFFAA"':'').'>'.
485: &valout($outpar[10],$type{$_}).'</td>');
1.13 www 486:
1.12 www 487: $r->print('<td'.(($result==9)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 488: &plink($type{$_},$display{$_},$outpar[9],$mprefix.'9',
489: 'parmform.pres','psub').'</td>');
1.12 www 490: $r->print('<td'.(($result==8)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 491: &plink($type{$_},$display{$_},$outpar[8],$mprefix.'8',
492: 'parmform.pres','psub').'</td>');
1.12 www 493: $r->print('<td'.(($result==7)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 494: &plink($type{$_},$display{$_},$outpar[7],$mprefix.'7',
495: 'parmform.pres','psub').'</td>');
496:
1.9 www 497: if ($csec) {
1.12 www 498: $r->print('<td'.(($result==6)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 499: &plink($type{$_},$display{$_},$outpar[6],$mprefix.'6',
500: 'parmform.pres','psub').'</td>');
1.12 www 501: $r->print('<td'.(($result==5)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 502: &plink($type{$_},$display{$_},$outpar[5],$mprefix.'5',
503: 'parmform.pres','psub').'</td>');
1.12 www 504: $r->print('<td'.(($result==4)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 505: &plink($type{$_},$display{$_},$outpar[4],$mprefix.'4',
506: 'parmform.pres','psub').'</td>');
1.9 www 507: }
1.13 www 508:
1.9 www 509: if ($uname) {
1.12 www 510: $r->print('<td'.(($result==3)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 511: &plink($type{$_},$display{$_},$outpar[3],$mprefix.'3',
512: 'parmform.pres','psub').'</td>');
1.12 www 513: $r->print('<td'.(($result==2)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 514: &plink($type{$_},$display{$_},$outpar[2],$mprefix.'2',
515: 'parmform.pres','psub').'</td>');
1.12 www 516: $r->print('<td'.(($result==1)?' bgcolor="#AAFFAA"':'').'>'.
1.13 www 517: &plink($type{$_},$display{$_},$outpar[1],$mprefix.'1',
518: 'parmform.pres','psub').'</td>');
1.9 www 519: }
1.13 www 520:
1.11 www 521: $r->print('<td>'.&valout($outpar[$result],$type{$_}).'</td>');
1.5 www 522: $r->print("</tr>\n<tr>");
1.11 www 523: } sort keys %name;
1.4 www 524: # -------------------------------------------------- End entry for one resource
1.3 www 525: } @ids;
1.8 www 526: $r->print('</table></form></body></html>');
1.1 www 527: untie(%bighash);
1.2 www 528: untie(%parmhash);
1.1 www 529: }
530: } else {
531: # ----------------------------- Not in a course, or not allowed to modify parms
532: $ENV{'user.error.msg'}=
1.7 www 533: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
1.1 www 534: return HTTP_NOT_ACCEPTABLE;
535: }
536: return OK;
537: }
538:
539: 1;
540: __END__
541:
542:
543:
544:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>