Annotation of loncom/interface/lonparmset.pm, revision 1.12
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:
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:
231: # -------------------------------------------------------------- Get coursedata
232: my $reply=&Apache::lonnet::reply('dump:'.
233: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
234: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata',
235: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
236: if ($reply!~/^error\:/) {
237: map {
238: my ($name,$value)=split(/\=/,$_);
239: $courseopt{unescape($name)}=unescape($value);
240: } split(/\&/,$reply);
241: }
242: # --------------------------------------------------- Get userdata (if present)
243: if ($uname) {
244: my $reply=
245: &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
246: if ($reply!~/^error\:/) {
247: map {
248: my ($name,$value)=split(/\=/,$_);
249: $useropt{unescape($name)}=unescape($value);
250: } split(/\&/,$reply);
251: }
252: }
253: # --------------------------------------------------------- Get all assessments
254: map {
255: if ($_=~/^src\_(\d+)\.(\d+)$/) {
256: my $mapid=$1;
257: my $resid=$2;
1.3 www 258: my $id=$mapid.'.'.$resid;
1.2 www 259: if ($bighash{$_}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.3 www 260: $ids[$#ids+1]=$id;
261: $typep{$id}=$1;
1.10 www 262: $mapp{$id}=
263: &Apache::lonnet::declutter($bighash{'map_id_'.$mapid});
264: $symbp{$id}=$mapp{$id}.
1.3 www 265: '___'.$resid.'___'.
266: &Apache::lonnet::declutter($bighash{$_});
1.2 www 267: }
268: }
269: } keys %bighash;
270: # ------------------------------------------------------------------- Sort this
1.3 www 271: @ids=sort bycat @ids;
1.2 www 272: # ------------------------------------------------------------------ Start page
1.1 www 273: $r->content_type('text/html');
274: $r->send_http_header;
1.5 www 275: $r->print(<<ENDHEAD);
276: <html>
277: <head>
278: <title>LON-CAPA Assessment Parameters</title>
279: <script>
280: function pclose() {
281: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
282: "height=350,width=350,scrollbars=no,menubar=no");
283: parmwin.close();
284: }
285:
286: function pjump(type,dis,value,marker,ret,call) {
1.6 www 287: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
288: +"&value="+escape(value)+"&marker="+escape(marker)
289: +"&return="+escape(ret)
290: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
1.5 www 291: "height=350,width=350,scrollbars=no,menubar=no");
292:
293: }
294: </script>
295: </head>
296: <body bgcolor="#FFFFFF" onUnload="pclose()">
297: <h1>Set Assessment Parameters</h1>
1.8 www 298: <form method="post" action="/adm/parmset" name="parmform">
299: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
300: <b>
301: Section/Group:
1.12 ! www 302: <input type="text" value="$csec" size="6" name="csec">
1.8 www 303: <br>
304: For User
1.12 ! www 305: <input type="text" value="$uname" size="12" name="uname">
! 306: or ID
! 307: <input type="text" value="$id" size="12" name="id">
1.8 www 308: at Domain
1.12 ! www 309: <input type="text" value="$udom" size="6" name="udom">
1.8 www 310: </b>
1.12 ! www 311: <input type="submit" value="Display">
1.5 www 312: ENDHEAD
1.12 ! www 313:
! 314: $r->print($message.'<p>Sort list by ');
1.8 www 315: $r->print('<select name="fcat" onChange="this.form.submit();">');
316: my $k;
317: my @sopt=('map','Map','name','Problem Name','deadline','Deadline');
318: for ($k=0;$k<$#sopt;$k=$k+2) {
319: $r->print('<option value="'.$sopt[$k].'"');
320: if ($fcat eq $sopt[$k]) { $r->print(' selected'); }
321: $r->print('>'.$sopt[$k+1].'</option>');
322: }
323: $r->print('</select>');
1.10 www 324: # ----------------------------------------------------------------- Start Table
325: my $coursespan=$csec?8:5;
1.9 www 326: $r->print(<<ENDTABLEHEAD);
327: <p><table border=2>
1.11 www 328: <tr><td colspan=5></td>
1.10 www 329: <th colspan=$coursespan>Any User</th>
1.9 www 330: ENDTABLEHEAD
1.10 www 331: if ($uname) {
332: $r->print("<th colspan=3 rowspan=2>User $uname at Domain $udom</th>");
333: }
334: $r->print(<<ENDTABLETWO);
1.11 www 335: <th rowspan=3>Parameter in Effect</th></tr><tr><td colspan=5></td>
1.10 www 336: <th colspan=2>Resource Level</th>
337: <th colspan=3>in Course</th>
338: ENDTABLETWO
1.9 www 339: if ($csec) {
1.10 www 340: $r->print("<th colspan=3>in Section/Group $csec</th>");
1.9 www 341: }
1.10 www 342: $r->print(<<ENDTABLEHEADFOUR);
1.11 www 343: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1.10 www 344: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
1.11 www 345: <th>default</th><th>from Enclosing Map</th>
1.10 www 346: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
347: ENDTABLEHEADFOUR
348: if ($csec) {
349: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
350: }
351: if ($uname) {
352: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
353: }
354: $r->print('</tr><tr>');
1.3 www 355: map {
1.4 www 356: # ------------------------------------------------------ Entry for one resource
1.8 www 357: @outpar=();
1.5 www 358: my $rid=$_;
359: my $thistitle='';
1.11 www 360: my %name= ('0_deadline' => 'deadline');
361: my %part= ('0_deadline' => '0');
362: my %display=('0_deadline' => 'Deadline');
363: my %type= ('0_deadline' => 'date_end');
364: my %default=('0_deadline' => time);
1.4 www 365: my %metadata=&Apache::lonmeta::unpackagemeta(
1.5 www 366: &Apache::lonnet::getfile('/home/httpd/html/'.$bighash{'src_'.$rid}.'.meta'),1);
1.4 www 367: map {
1.5 www 368: if ($_=~/^parameter\_(\d+)\_(\w+)$/) {
1.11 www 369: my $hashid=$1.'_'.$2;
370: $part{$hashid}=$1;
371: $name{$hashid}=$2;
372: my $tdef;
373: ($tdef,$display{$hashid})=
1.5 www 374: split(/\_\_dis\_\_/,$metadata{$_});
1.11 www 375: ($type{$hashid},$default{$hashid})=split(/\:/,$tdef);
376: unless ($display{$hashid}) {
377: $display{$hashid}=$name{$hashid};
1.5 www 378: }
379: }
380: if ($_ eq 'title') {
381: $thistitle=$metadata{$_};
1.4 www 382: }
383: } keys %metadata;
1.11 www 384: my $totalparms=scalar keys %name;
1.5 www 385: $r->print('<td rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 386: join(' / ',split(/\//,&Apache::lonnet::declutter($bighash{'src_'.$rid}))).
387: '</font></tt><p><b>'.
1.5 www 388: $bighash{'title_'.$rid});
389: if ($thistitle) {
390: $r->print(' ('.$thistitle.')');
391: }
1.11 www 392: $r->print('</b></td>');
393: $r->print('<td rowspan='.$totalparms.'>'.$typep{$rid}.'</td>');
394: $r->print('<td rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 395: join(' / ',split(/\//,$mapp{$rid})).'</font></tt></td>');
1.11 www 396: map {
397:
398: my $result=&parmval($part{$_}.'.'.$name{$_},$rid,$default{$_});
399:
400: $r->print("<td>$part{$_}</td><td>$display{$_}</td>");
1.12 ! www 401: my $mprefix=$rid.'&'.$_.'&';
! 402: $r->print('<td'.(($result==11)?' bgcolor="#AAFFAA"':'').'>'.
! 403: &valout($outpar[11],$type{$_}).'</td>');
! 404: $r->print('<td'.(($result==10)?' bgcolor="#AAFFAA"':'').'>'.
! 405: &valout($outpar[10],$type{$_}).'</td>');
! 406: $r->print('<td'.(($result==9)?' bgcolor="#AAFFAA"':'').'>'.
! 407: &plink($type{$_},$display{$_},$outpar[9],$mprefix.'9').'</td>');
! 408: $r->print('<td'.(($result==8)?' bgcolor="#AAFFAA"':'').'>'.
! 409: &plink($type{$_},$display{$_},$outpar[8],$mprefix.'8').'</td>');
! 410: $r->print('<td'.(($result==7)?' bgcolor="#AAFFAA"':'').'>'.
! 411: &plink($type{$_},$display{$_},$outpar[7],$mprefix.'7').'</td>');
1.9 www 412: if ($csec) {
1.12 ! www 413: $r->print('<td'.(($result==6)?' bgcolor="#AAFFAA"':'').'>'.
! 414: &plink($type{$_},$display{$_},$outpar[6],$mprefix.'6').'</td>');
! 415: $r->print('<td'.(($result==5)?' bgcolor="#AAFFAA"':'').'>'.
! 416: &plink($type{$_},$display{$_},$outpar[5],$mprefix.'5').'</td>');
! 417: $r->print('<td'.(($result==4)?' bgcolor="#AAFFAA"':'').'>'.
! 418: &plink($type{$_},$display{$_},$outpar[4],$mprefix.'4').'</td>');
1.9 www 419: }
420: if ($uname) {
1.12 ! www 421: $r->print('<td'.(($result==3)?' bgcolor="#AAFFAA"':'').'>'.
! 422: &plink($type{$_},$display{$_},$outpar[3],$mprefix.'3').'</td>');
! 423: $r->print('<td'.(($result==2)?' bgcolor="#AAFFAA"':'').'>'.
! 424: &plink($type{$_},$display{$_},$outpar[2],$mprefix.'2').'</td>');
! 425: $r->print('<td'.(($result==1)?' bgcolor="#AAFFAA"':'').'>'.
! 426: &plink($type{$_},$display{$_},$outpar[1],$mprefix.'1').'</td>');
1.9 www 427: }
1.11 www 428: $r->print('<td>'.&valout($outpar[$result],$type{$_}).'</td>');
1.5 www 429: $r->print("</tr>\n<tr>");
1.11 www 430: } sort keys %name;
1.4 www 431: # -------------------------------------------------- End entry for one resource
1.3 www 432: } @ids;
1.8 www 433: $r->print('</table></form></body></html>');
1.1 www 434: untie(%bighash);
1.2 www 435: untie(%parmhash);
1.1 www 436: }
437: } else {
438: # ----------------------------- Not in a course, or not allowed to modify parms
439: $ENV{'user.error.msg'}=
1.7 www 440: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
1.1 www 441: return HTTP_NOT_ACCEPTABLE;
442: }
443: return OK;
444: }
445:
446: 1;
447: __END__
448:
449:
450:
451:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>