Annotation of loncom/interface/lonparmset.pm, revision 1.33
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.20 www 12: # 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
1.21 www 13: # 12/08,12/12,
1.30 www 14: # 16/01/01,02/08,03/20,03/23,03/24,03/26,05/09,
1.33 ! www 15: # 07/05,07/06,08/08,08/09 Gerd Kortemeyer
1.1 www 16:
17: package Apache::lonparmset;
18:
19: use strict;
20: use Apache::lonnet;
21: use Apache::Constants qw(:common :http REDIRECT);
22: use GDBM_File;
1.4 www 23:
1.1 www 24:
1.2 www 25: my %courseopt;
26: my %useropt;
27: my %bighash;
28: my %parmhash;
29:
1.8 www 30: my @outpar;
31:
1.3 www 32: my @ids;
33: my %symbp;
1.10 www 34: my %mapp;
1.3 www 35: my %typep;
1.16 www 36: my %keyp;
1.17 www 37: my %defp;
1.16 www 38:
39: my %allkeys;
1.26 www 40: my %allmaps;
1.2 www 41:
42: my $uname;
43: my $udom;
44: my $uhome;
45:
46: my $csec;
47:
1.3 www 48: my $fcat;
49:
1.2 www 50: # -------------------------------------------- Figure out a cascading parameter
51:
52: sub parmval {
1.11 www 53: my ($what,$id,$def)=@_;
1.8 www 54: my $result='';
1.11 www 55: @outpar=();
1.2 www 56: # ----------------------------------------------------- Cascading lookup scheme
1.10 www 57:
1.3 www 58: my $symbparm=$symbp{$id}.'.'.$what;
1.10 www 59: my $mapparm=$mapp{$id}.'___(all).'.$what;
60:
1.2 www 61: my $seclevel=
1.10 www 62: $ENV{'request.course.id'}.'.['.
1.14 www 63: $csec.'].'.$what;
1.10 www 64: my $seclevelr=
65: $ENV{'request.course.id'}.'.['.
1.14 www 66: $csec.'].'.$symbparm;
1.10 www 67: my $seclevelm=
68: $ENV{'request.course.id'}.'.['.
1.14 www 69: $csec.'].'.$mapparm;
1.10 www 70:
1.2 www 71: my $courselevel=
72: $ENV{'request.course.id'}.'.'.$what;
1.10 www 73: my $courselevelr=
74: $ENV{'request.course.id'}.'.'.$symbparm;
75: my $courselevelm=
76: $ENV{'request.course.id'}.'.'.$mapparm;
1.2 www 77:
1.11 www 78: # -------------------------------------------------------- first, check default
79:
80: if ($def) { $outpar[11]=$def;
81: $result=11; }
82:
83: # ----------------------------------------------------- second, check map parms
84:
85: my $thisparm=$parmhash{$symbparm};
86: if ($thisparm) { $outpar[10]=$thisparm;
87: $result=10; }
88:
89: # --------------------------------------------------------- third, check course
90:
91: if ($courseopt{$courselevel}) { $outpar[9]=$courseopt{$courselevel};
92: $result=9; }
93:
94: if ($courseopt{$courselevelm}) { $outpar[8]=$courseopt{$courselevelm};
95: $result=8; }
96:
97: if ($courseopt{$courselevelr}) { $outpar[7]=$courseopt{$courselevelr};
98: $result=7; }
99:
100: if ($csec) {
101:
102: if ($courseopt{$seclevel}) { $outpar[6]=$courseopt{$seclevel};
103: $result=6; }
104:
105: if ($courseopt{$seclevelm}) { $outpar[5]=$courseopt{$seclevelm};
106: $result=5; }
107:
108: if ($courseopt{$seclevelr}) { $outpar[4]=$courseopt{$seclevelr};
109: $result=4; }
110:
111: }
112:
113: # ---------------------------------------------------------- fourth, check user
1.8 www 114:
115: if ($uname) {
1.11 www 116:
1.10 www 117: if ($useropt{$courselevel}) { $outpar[3]=$useropt{$courselevel};
118: $result=3; }
119:
1.11 www 120: if ($useropt{$courselevelm}) { $outpar[2]=$useropt{$courselevelm};
121: $result=2; }
1.2 www 122:
1.11 www 123: if ($useropt{$courselevelr}) { $outpar[1]=$useropt{$courselevelr};
124: $result=1; }
1.10 www 125:
1.11 www 126: }
1.2 www 127:
1.8 www 128: return $result;
1.2 www 129: }
130:
1.9 www 131: # ------------------------------------------------------------ Output for value
132:
133: sub valout {
134: my ($value,$type)=@_;
135: return
136: ($value?(($type=~/^date/)?localtime($value):$value):' ');
137: }
138:
1.5 www 139: # -------------------------------------------------------- Produces link anchor
140:
141: sub plink {
142: my ($type,$dis,$value,$marker,$return,$call)=@_;
1.23 www 143: my $winvalue=$value;
144: unless ($winvalue) {
145: if ($type=~/^date/) {
146: $winvalue=$ENV{'form.recent_'.$type};
147: } else {
148: $winvalue=$ENV{'form.recent_'.(split(/\_/,$type))[0]};
149: }
150: }
151: return
152: '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
1.8 www 153: .$marker."','".$return."','".$call."'".');">'.
1.22 www 154: &valout($value,$type).'</a><a name="'.$marker.'"></a>';
1.5 www 155: }
156:
1.30 www 157: sub assessparms {
1.1 www 158:
1.30 www 159: my $r=shift;
1.2 www 160: # -------------------------------------------------------- Variable declaration
161:
162: %courseopt=();
163: %useropt=();
164: %bighash=();
165:
1.3 www 166: @ids=();
167: %symbp=();
168: %typep=();
1.2 www 169:
1.12 www 170: my $message='';
171:
172: $csec=$ENV{'form.csec'};
1.2 www 173: $udom=$ENV{'form.udom'};
1.17 www 174: unless ($udom) { $udom=$r->dir_config('lonDefDomain'); }
175:
1.26 www 176: my $pscat=$ENV{'form.pscat'};
177: my $pschp=$ENV{'form.pschp'};
1.29 www 178: my $pssymb='';
1.26 www 179:
1.29 www 180: # ----------------------------------------------- Was this started from grades?
181:
182: if (($ENV{'form.command'} eq 'set') && ($ENV{'form.url'})
183: && (!$ENV{'form.dis'})) {
184: my $url=$ENV{'form.url'};
185: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
186: $pssymb=&Apache::lonnet::symbread($url);
187: $pscat='all';
188: $pschp='';
189: } else {
190: $ENV{'form.url'}='';
191: }
192:
1.12 www 193: my $id=$ENV{'form.id'};
194: if (($id) && ($udom)) {
195: $uname=(&Apache::lonnet::idget($udom,$id))[1];
196: if ($uname) {
197: $id='';
198: } else {
199: $message=
1.17 www 200: "<font color=red>Unknown ID '$id' at domain '$udom'</font>";
1.12 www 201: }
202: } else {
203: $uname=$ENV{'form.uname'};
204: }
1.2 www 205: unless ($udom) { $uname=''; }
206: $uhome='';
207: if ($uname) {
208: $uhome=&Apache::lonnet::homeserver($uname,$udom);
1.12 www 209:
210: if ($uhome eq 'no_host') {
1.3 www 211: $message=
1.17 www 212: "<font color=red>Unknown user '$uname' at domain '$udom'</font>";
1.3 www 213: $uname='';
1.12 www 214: } else {
215: $csec=&Apache::lonnet::usection(
216: $udom,$uname,$ENV{'request.course.id'});
217: if ($csec eq '-1') {
1.17 www 218: $message="<font color=red>".
219: "User '$uname' at domain '$udom' not in this course</font>";
1.12 www 220: $uname='';
221: $csec=$ENV{'form.csec'};
222: } else {
223: my %name=&Apache::lonnet::userenvironment($udom,$uname,
224: ('firstname','middlename','lastname','generation','id'));
225: $message="\n<p>\nFull Name: ".
226: $name{'firstname'}.' '.$name{'middlename'}
227: .$name{'lastname'}.' '.$name{'generation'}.
228: "<br>\nID: ".$name{'id'}.'<p>';
229: }
230: }
1.3 www 231: }
1.2 www 232:
1.3 www 233: unless ($csec) { $csec=''; }
1.12 www 234:
1.3 www 235: $fcat=$ENV{'form.fcat'};
236: unless ($fcat) { $fcat=''; }
1.2 www 237:
238: # ------------------------------------------------------------------- Tie hashs
239: if ((tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
240: &GDBM_READER,0640)) &&
241: (tie(%parmhash,'GDBM_File',
242: $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640))) {
243:
1.14 www 244: # --------------------------------------------------------- Get all assessments
1.26 www 245: undef %allkeys;
246: undef %allmaps;
247: undef %defp;
1.14 www 248: map {
249: if ($_=~/^src\_(\d+)\.(\d+)$/) {
250: my $mapid=$1;
251: my $resid=$2;
252: my $id=$mapid.'.'.$resid;
1.16 www 253: my $srcf=$bighash{$_};
254: if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.14 www 255: $ids[$#ids+1]=$id;
256: $typep{$id}=$1;
1.16 www 257: $keyp{$id}='';
258: map {
259: if ($_=~/^parameter\_(.*)/) {
260: my $key=$_;
261: my $allkey=$1;
1.17 www 262: $allkey=~s/\_/\./;
1.16 www 263: my $display=
264: &Apache::lonnet::metadata($srcf,$key.'.display');
265: unless ($display) {
266: $display=
267: &Apache::lonnet::metadata($srcf,$key.'.name');
268: }
269: $allkeys{$allkey}=$display;
1.17 www 270: if ($allkey eq $fcat) {
271: $defp{$id}=
1.20 www 272: &Apache::lonnet::metadata($srcf,$key);
1.17 www 273: }
1.16 www 274: if ($keyp{$id}) {
275: $keyp{$id}.=','.$key;
276: } else {
277: $keyp{$id}=$key;
278: }
279: }
280: } split(/\,/,
281: &Apache::lonnet::metadata($srcf,'keys'));
1.14 www 282: $mapp{$id}=
283: &Apache::lonnet::declutter($bighash{'map_id_'.$mapid});
1.26 www 284: $allmaps{$mapid}=$mapp{$id};
1.14 www 285: $symbp{$id}=$mapp{$id}.
286: '___'.$resid.'___'.
1.16 www 287: &Apache::lonnet::declutter($srcf);
1.14 www 288: }
289: }
290: } keys %bighash;
291: # ---------------------------------------------------------- Anything to store?
292: if ($ENV{'form.pres_marker'}) {
293: my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
1.32 www 294: $spnam=~s/\_([^\_]+)$/\.$1/;
1.15 www 295: # ---------------------------------------------------------- Construct prefixes
1.14 www 296:
297: my $symbparm=$symbp{$sresid}.'.'.$spnam;
298: my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
299:
300: my $seclevel=
301: $ENV{'request.course.id'}.'.['.
302: $csec.'].'.$spnam;
303: my $seclevelr=
304: $ENV{'request.course.id'}.'.['.
305: $csec.'].'.$symbparm;
306: my $seclevelm=
307: $ENV{'request.course.id'}.'.['.
308: $csec.'].'.$mapparm;
309:
310: my $courselevel=
311: $ENV{'request.course.id'}.'.'.$spnam;
312: my $courselevelr=
313: $ENV{'request.course.id'}.'.'.$symbparm;
314: my $courselevelm=
315: $ENV{'request.course.id'}.'.'.$mapparm;
316:
317: my $storeunder='';
318: if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
319: if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
320: if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
321: if ($snum==6) { $storeunder=$seclevel; }
322: if ($snum==5) { $storeunder=$seclevelm; }
323: if ($snum==4) { $storeunder=$seclevelr; }
1.15 www 324: $storeunder=&Apache::lonnet::escape($storeunder);
325:
326: my $storecontent=
327: $storeunder.'='.&Apache::lonnet::escape($ENV{'form.pres_value'}).'&'.
328: $storeunder.'.type='.&Apache::lonnet::escape($ENV{'form.pres_type'});
1.14 www 329:
1.15 www 330: my $reply='';
1.14 www 331: if ($snum>3) {
332: # ---------------------------------------------------------------- Store Course
1.24 www 333: #
334: # Expire sheets
1.25 www 335: &Apache::lonnet::expirespread('','','studentcalc');
1.24 www 336: if (($snum==7) || ($snum==4)) {
1.25 www 337: &Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
1.24 www 338: } elsif (($snum==8) || ($snum==5)) {
1.25 www 339: &Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
1.24 www 340: } else {
1.25 www 341: &Apache::lonnet::expirespread('','','assesscalc');
1.24 www 342: }
343:
344: # Store parameter
1.15 www 345: $reply=&Apache::lonnet::critical('put:'.
346: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
347: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata:'.
348: $storecontent,
349: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
1.14 www 350: } else {
351: # ------------------------------------------------------------------ Store User
1.24 www 352: #
353: # Expire sheets
354: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
355: if ($snum==1) {
356: &Apache::lonnet::expirespread
357: ($uname,$udom,'assesscalc',$symbp{$sresid});
358: } elsif ($snum==2) {
359: &Apache::lonnet::expirespread
360: ($uname,$udom,'assesscalc',$mapp{$sresid});
361: } else {
362: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
363: }
364:
365: # Store parameter
1.15 www 366: $reply=
367: &Apache::lonnet::critical('put:'.$udom.':'.$uname.':resourcedata:'.
368: $storecontent,$uhome);
369: }
370:
371: if ($reply=~/^error\:(.*)/) {
1.17 www 372: $message.="<font color=red>Write Error: $1</font>";
1.15 www 373: }
374: # ---------------------------------------------------------------- Done storing
375: }
1.2 www 376: # -------------------------------------------------------------- Get coursedata
377: my $reply=&Apache::lonnet::reply('dump:'.
378: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.':'.
379: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.':resourcedata',
380: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
381: if ($reply!~/^error\:/) {
382: map {
383: my ($name,$value)=split(/\=/,$_);
1.15 www 384: $courseopt{&Apache::lonnet::unescape($name)}=
385: &Apache::lonnet::unescape($value);
1.2 www 386: } split(/\&/,$reply);
387: }
388: # --------------------------------------------------- Get userdata (if present)
389: if ($uname) {
390: my $reply=
391: &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
392: if ($reply!~/^error\:/) {
393: map {
394: my ($name,$value)=split(/\=/,$_);
1.15 www 395: $useropt{&Apache::lonnet::unescape($name)}=
396: &Apache::lonnet::unescape($value);
1.2 www 397: } split(/\&/,$reply);
398: }
399: }
1.14 www 400:
1.2 www 401: # ------------------------------------------------------------------- Sort this
1.17 www 402:
403: @ids=sort {
404: if ($fcat eq '') {
405: $a<=>$b;
406: } else {
1.28 www 407: 1*$outpar[&parmval($fcat,$a,$defp{$a})]<=>
408: 1*$outpar[&parmval($fcat,$b,$defp{$b})];
1.17 www 409: }
1.28 www 410: } @ids;
411:
1.2 www 412: # ------------------------------------------------------------------ Start page
1.1 www 413: $r->content_type('text/html');
414: $r->send_http_header;
1.5 www 415: $r->print(<<ENDHEAD);
416: <html>
417: <head>
1.30 www 418: <title>LON-CAPA Course Parameters</title>
1.5 www 419: <script>
1.13 www 420:
1.5 www 421: function pclose() {
422: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
423: "height=350,width=350,scrollbars=no,menubar=no");
424: parmwin.close();
425: }
426:
427: function pjump(type,dis,value,marker,ret,call) {
1.13 www 428: document.parmform.pres_marker.value='';
1.6 www 429: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
430: +"&value="+escape(value)+"&marker="+escape(marker)
431: +"&return="+escape(ret)
432: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
1.5 www 433: "height=350,width=350,scrollbars=no,menubar=no");
434:
435: }
1.13 www 436:
437: function psub() {
438: pclose();
1.18 www 439: if (document.parmform.pres_marker.value!='') {
1.22 www 440: document.parmform.action+='#'+document.parmform.pres_marker.value;
1.23 www 441: var typedef=new Array();
442: typedef=document.parmform.pres_type.value.split('_');
1.27 www 443: if (document.parmform.pres_type.value!='') {
1.23 www 444: if (typedef[0]=='date') {
445: eval('document.parmform.recent_'+
446: document.parmform.pres_type.value+
447: '.value=document.parmform.pres_value.value;');
448: } else {
449: eval('document.parmform.recent_'+typedef[0]+
450: '.value=document.parmform.pres_value.value;');
451: }
1.27 www 452: }
1.13 www 453: document.parmform.submit();
454: } else {
455: document.parmform.pres_value.value='';
456: document.parmform.pres_marker.value='';
457: }
458: }
459:
1.5 www 460: </script>
461: </head>
462: <body bgcolor="#FFFFFF" onUnload="pclose()">
1.30 www 463: <h1>Set Course Parameters</h1>
464: <form method="post" action="/adm/parmset" name="envform">
465: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
466: <h3>Course Environment</h3>
467: <input type="submit" name="crsenv" value="Set Course Environment">
468: </form>
1.8 www 469: <form method="post" action="/adm/parmset" name="parmform">
1.30 www 470: <h3>Course Assessments</h3>
1.8 www 471: <b>
472: Section/Group:
1.12 www 473: <input type="text" value="$csec" size="6" name="csec">
1.8 www 474: <br>
475: For User
1.12 www 476: <input type="text" value="$uname" size="12" name="uname">
477: or ID
478: <input type="text" value="$id" size="12" name="id">
1.8 www 479: at Domain
1.12 www 480: <input type="text" value="$udom" size="6" name="udom">
1.8 www 481: </b>
1.13 www 482: <input type="hidden" value='' name="pres_value">
483: <input type="hidden" value='' name="pres_type">
1.29 www 484: <input type="hidden" value='' name="pres_marker">
1.5 www 485: ENDHEAD
1.29 www 486: if ($ENV{'form.url'}) {
487: $r->print('<input type="hidden" value="'.$ENV{'form.url'}.
488: '" name="url"><input type="hidden" name="command" value="set">');
489: }
1.23 www 490: map {
491: $r->print('<input type="hidden" value="'.
492: $ENV{'form.recent_'.$_}.'" name="recent_'.$_.'">');
493: } ('tolerance','date_default','date_start','date_end','date_interval',
494: 'int','float','string');
1.17 www 495:
1.26 www 496: $r->print('<h2>'.$message.'</h2><table><tr><td>Sort list by</td><td>');
497: $r->print('<select name="fcat">');
1.16 www 498: $r->print('<option value="">Enclosing Map</option>');
499: map {
500: $r->print('<option value="'.$_.'"');
501: if ($fcat eq $_) { $r->print(' selected'); }
502: $r->print('>'.$allkeys{$_}.'</option>');
503: } keys %allkeys;
1.26 www 504: $r->print(
505: '</select></tr><tr><td>Select Enclosing Map</td><td><select name=pschp>');
506: $r->print('<option value=all>All Maps</option>');
507: map {
508: $r->print('<option value="'.$_.'"');
1.29 www 509: if (($pssymb=~/^$allmaps{$_}/) ||
510: ($pschp eq $_)) { $r->print(' selected'); }
1.26 www 511: $r->print('>'.$allmaps{$_}.'</option>');
512: } keys %allmaps;
513: $r->print(
514: '</select></td></tr><tr><td>Select Parameter</td><td><select name=pscat>');
515: $r->print('<option value=all>All Parameters</option>');
516: map {
517: $r->print('<option value="'.$_.'"');
518: if ($pscat eq $_) { $r->print(' selected'); }
519: $r->print('>'.$allkeys{$_}.'</option>');
520: } keys %allkeys;
521: $r->print(
1.29 www 522: '</select></td></tr></table><br><input name=dis type="submit" value="Display">'
523: );
524: if (($pscat) || ($pschp) || ($pssymb)) {
1.10 www 525: # ----------------------------------------------------------------- Start Table
1.26 www 526: my $catmarker='parameter_'.$pscat;
527: $catmarker=~s/\./\_/g;
1.10 www 528: my $coursespan=$csec?8:5;
1.33 ! www 529: my $csuname=$ENV{'user.name'};
! 530: my $csudom=$ENV{'user.domain'};
1.9 www 531: $r->print(<<ENDTABLEHEAD);
532: <p><table border=2>
1.11 www 533: <tr><td colspan=5></td>
1.10 www 534: <th colspan=$coursespan>Any User</th>
1.9 www 535: ENDTABLEHEAD
1.10 www 536: if ($uname) {
537: $r->print("<th colspan=3 rowspan=2>User $uname at Domain $udom</th>");
538: }
539: $r->print(<<ENDTABLETWO);
1.33 ! www 540: <th rowspan=3>Parameter in Effect</th>
! 541: <th rowspan=3>Current Session Value<br>($csuname at $csudom)</th>
! 542: </tr><tr><td colspan=5></td>
1.10 www 543: <th colspan=2>Resource Level</th>
544: <th colspan=3>in Course</th>
545: ENDTABLETWO
1.9 www 546: if ($csec) {
1.10 www 547: $r->print("<th colspan=3>in Section/Group $csec</th>");
1.9 www 548: }
1.10 www 549: $r->print(<<ENDTABLEHEADFOUR);
1.11 www 550: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1.10 www 551: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
1.11 www 552: <th>default</th><th>from Enclosing Map</th>
1.10 www 553: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
554: ENDTABLEHEADFOUR
555: if ($csec) {
556: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
557: }
558: if ($uname) {
559: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
560: }
561: $r->print('</tr><tr>');
1.19 www 562: my $defbgone='';
563: my $defbgtwo='';
1.3 www 564: map {
1.26 www 565: my $rid=$_;
1.29 www 566: my ($inmapid)=($rid=~/\.(\d+)$/);
567: if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
568: ($pssymb eq $mapp{$rid}.'___'.$inmapid.'___'.
569: &Apache::lonnet::declutter($bighash{'src_'.$rid}))) {
1.4 www 570: # ------------------------------------------------------ Entry for one resource
1.19 www 571: if ($defbgone eq '"E0E099"') {
572: $defbgone='"E0E0DD"';
573: } else {
574: $defbgone='"E0E099"';
575: }
576: if ($defbgtwo eq '"FFFF99"') {
577: $defbgtwo='"FFFFDD"';
578: } else {
579: $defbgtwo='"FFFF99"';
580: }
1.8 www 581: @outpar=();
1.5 www 582: my $thistitle='';
1.16 www 583: my %name= ();
584: my %part= ();
585: my %display=();
586: my %type= ();
587: my %default=();
588: my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
589:
1.4 www 590: map {
1.16 www 591: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
592: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
593: $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
594: unless ($display{$_}) { $display{$_}=''; }
595: $display{$_}.=' ('.$name{$_}.')';
1.20 www 596: $default{$_}=&Apache::lonnet::metadata($uri,$_);
1.16 www 597: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
598: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
599: } split(/\,/,$keyp{$rid});
600:
1.11 www 601: my $totalparms=scalar keys %name;
1.21 www 602: my $isdef=1;
603: unless ($totalparms) { $totalparms=1; $isdef=0; }
1.26 www 604: if ($pscat ne 'all') { $totalparms=1; }
1.19 www 605: $r->print('<td bgcolor='.$defbgone.
606: ' rowspan='.$totalparms.'><tt><font size=-1>'.
1.16 www 607: join(' / ',split(/\//,$uri)).
608: '</font></tt><p><b>'.
1.5 www 609: $bighash{'title_'.$rid});
610: if ($thistitle) {
611: $r->print(' ('.$thistitle.')');
612: }
1.11 www 613: $r->print('</b></td>');
1.19 www 614: $r->print('<td bgcolor='.$defbgtwo.
615: ' rowspan='.$totalparms.'>'.$typep{$rid}.'</td>');
616: $r->print('<td bgcolor='.$defbgone.
617: ' rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 618: join(' / ',split(/\//,$mapp{$rid})).'</font></tt></td>');
1.21 www 619: if ($isdef) {
1.11 www 620: map {
1.26 www 621: if (($_ eq $catmarker) || ($pscat eq 'all')) {
1.11 www 622: my $result=&parmval($part{$_}.'.'.$name{$_},$rid,$default{$_});
623:
1.19 www 624: $r->print("<td bgcolor=".$defbgtwo.
625: ">$part{$_}</td><td bgcolor=".$defbgone.
626: ">$display{$_}</td>");
1.16 www 627: my $thismarker=$_;
628: $thismarker=~s/^parameter\_//;
629: my $mprefix=$rid.'&'.$thismarker.'&';
1.13 www 630:
1.19 www 631: $r->print('<td bgcolor='.
632: (($result==11)?'"#AAFFAA"':'#FFDDDD').'>'.
1.12 www 633: &valout($outpar[11],$type{$_}).'</td>');
1.19 www 634: $r->print('<td bgcolor='.
635: (($result==10)?'"#AAFFAA"':'#FFDDDD').'>'.
1.12 www 636: &valout($outpar[10],$type{$_}).'</td>');
1.13 www 637:
1.19 www 638: $r->print('<td bgcolor='.
639: (($result==9)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 640: &plink($type{$_},$display{$_},$outpar[9],$mprefix.'9',
641: 'parmform.pres','psub').'</td>');
1.19 www 642: $r->print('<td bgcolor='.
643: (($result==8)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 644: &plink($type{$_},$display{$_},$outpar[8],$mprefix.'8',
645: 'parmform.pres','psub').'</td>');
1.19 www 646: $r->print('<td bgcolor='.
647: (($result==7)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 648: &plink($type{$_},$display{$_},$outpar[7],$mprefix.'7',
649: 'parmform.pres','psub').'</td>');
650:
1.9 www 651: if ($csec) {
1.19 www 652: $r->print('<td bgcolor='.
653: (($result==6)?'"#AAFFAA"':$defbgtwo).'>'.
1.13 www 654: &plink($type{$_},$display{$_},$outpar[6],$mprefix.'6',
655: 'parmform.pres','psub').'</td>');
1.19 www 656: $r->print('<td bgcolor='.
657: (($result==5)?'"#AAFFAA"':$defbgtwo).'>'.
1.13 www 658: &plink($type{$_},$display{$_},$outpar[5],$mprefix.'5',
659: 'parmform.pres','psub').'</td>');
1.19 www 660: $r->print('<td bgcolor='.
661: (($result==4)?'"#AAFFAA"':$defbgtwo).'>'.
1.13 www 662: &plink($type{$_},$display{$_},$outpar[4],$mprefix.'4',
663: 'parmform.pres','psub').'</td>');
1.9 www 664: }
1.13 www 665:
1.9 www 666: if ($uname) {
1.19 www 667: $r->print('<td bgcolor='.
668: (($result==3)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 669: &plink($type{$_},$display{$_},$outpar[3],$mprefix.'3',
670: 'parmform.pres','psub').'</td>');
1.19 www 671: $r->print('<td bgcolor='.
672: (($result==2)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 673: &plink($type{$_},$display{$_},$outpar[2],$mprefix.'2',
674: 'parmform.pres','psub').'</td>');
1.19 www 675: $r->print('<td bgcolor='.
676: (($result==1)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 677: &plink($type{$_},$display{$_},$outpar[1],$mprefix.'1',
678: 'parmform.pres','psub').'</td>');
1.9 www 679: }
1.19 www 680: $r->print(
1.33 ! www 681: '<td bgcolor=#CCCCFF>'.&valout($outpar[$result],$type{$_}).'</td>');
! 682: my $sessionval=&Apache::lonnet::EXT('resource.'.$part{$_}.
! 683: '.'.$name{$_},$mapp{$rid}.'___'.$inmapid.'___'.$uri);
! 684: if (($type{$_}=~/^date/) && ($sessionval))
! 685: { $sessionval=localtime($sessionval); }
! 686: $r->print(
! 687: '<td bgcolor=#999999><font color=#FFFFFF>'.$sessionval.' '.
! 688: '</font></td>');
1.5 www 689: $r->print("</tr>\n<tr>");
1.26 www 690: }
1.11 www 691: } sort keys %name;
1.21 www 692: } else {
1.26 www 693: $r->print("</tr>\n<tr>");
1.21 www 694: }
1.4 www 695: # -------------------------------------------------- End entry for one resource
1.26 www 696: }
1.3 www 697: } @ids;
1.26 www 698: $r->print('</table>');
699: }
700: $r->print('</form></body></html>');
1.1 www 701: untie(%bighash);
1.2 www 702: untie(%parmhash);
1.1 www 703: }
1.30 www 704: }
705:
706: sub crsenv {
707: my $r=shift;
708: my $setoutput='';
709: # -------------------------------------------------- Go through list of changes
710: map {
711: if ($_=~/^form\.(.+)\_setparmval$/) {
712: my $name=$1;
713: my $value=$ENV{'form.'.$name.'_value'};
714: if ($name eq 'newp') {
715: $name=$ENV{'form.newp_name'};
716: }
717: if ($name eq 'url') {
718: $value=~s/^\/res\///;
719: $setoutput.='Backing up previous URL: '.
720: &Apache::lonnet::reply('put:'.
721: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
722: ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
723: ':environment:'.
724: &Apache::lonnet::escape('top level map backup '.
725: time).'='.
726: &Apache::lonnet::reply('get:'.
727: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
728: ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
729: ':environment:url',
730: $ENV{'course.'.$ENV{'request.course.id'}.'.home'}),
731: $ENV{'course.'.$ENV{'request.course.id'}.'.home'}).
732: '<br>';
733:
734: }
735: if ($name) {
736: $setoutput.='Setting <tt>'.$name.'</tt> to <tt>'.
737: $value.'</tt>: '.
738: &Apache::lonnet::reply('put:'.
739: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
740: ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
741: ':environment:'.
742: &Apache::lonnet::escape($name).'='.
743: &Apache::lonnet::escape($value),
744: $ENV{'course.'.$ENV{'request.course.id'}.'.home'}).
745: '<br>';
746: }
747: }
748: } keys %ENV;
749: # -------------------------------------------------------- Get parameters again
750: my $rep=&Apache::lonnet::reply
751: ('dump:'.$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
752: ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
753: ':environment',
754: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
755: my $output='';
756: if ($rep ne 'con_lost') {
757: my %values;
758: my %descriptions=
759: ('url' => '<b>Top Level Map</b><br><font color=red>'.
760: 'Modification may make assessment data inaccessible</font>',
761: 'description' => '<b>Course Description</b>',
762: 'courseid' => '<b>Course ID or number</b><br>(internal, optional)',
763: 'question.email' => '<b>Feedback Addresses for Content Questions</b><br>'.
764: '(<tt>user:domain,user:domain,...</tt>)',
765: 'comment.email' => '<b>Feedback Addresses for Comments</b><br>'.
766: '(<tt>user:domain,user:domain,...</tt>)',
767: 'policy.email' => '<b>Feedback Addresses for Course Policy</b><br>'.
768: '(<tt>user:domain,user:domain,...</tt>)'
769: );
770:
771: map {
772: my ($name,$value)=split(/\=/,$_);
773: $name=&Apache::lonnet::unescape($name);
774: $values{$name}=&Apache::lonnet::unescape($value);
775: unless ($descriptions{$name}) {
776: $descriptions{$name}=$name;
777: }
778: } split(/\&/,$rep);
779: map {
780: $output.='<tr><td>'.$descriptions{$_}.'</td><td><input name="'.
781: $_.'_value" size=40 value="'.
782: $values{$_}.
783: '"></td><td><input type=checkbox name="'.$_.
784: '_setparmval"></td></tr>';
785: } keys %descriptions;
786: $output.='<tr><td><i>Create New Environment Variable</i><br>'.
787: '<input type="text" size=40 name="newp_name"></td><td>'.
788: '<input type="text" size=40 name="newp_value"></td><td>'.
789: '<input type="checkbox" name="newp_setparmval"></td></tr>';
790: }
791: $r->print(<<ENDENV);
792: <html>
793: <head>
794: <title>LON-CAPA Course Environment</title>
795: </head>
796: <body bgcolor="#FFFFFF">
797: <h1>Set Course Parameters</h1>
798: <form method="post" action="/adm/parmset" name="envform">
799: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
800: <h3>Course Environment</h3>
801: $setoutput
802: <p>
803: <table border=2>
804: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
805: $output
806: </table>
807: <input type="submit" name="crsenv" value="Set Course Environment">
808: </form>
809: </body>
810: </html>
811: ENDENV
812: }
813:
814: # ================================================================ Main Handler
815:
816: sub handler {
817: my $r=shift;
818:
819: if ($r->header_only) {
820: $r->content_type('text/html');
821: $r->send_http_header;
822: return OK;
823: }
824:
825: # ----------------------------------------------------- Needs to be in a course
826:
1.31 www 827: if (($ENV{'request.course.id'}) &&
1.30 www 828: (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
829:
1.31 www 830: unless (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) {
1.30 www 831: # --------------------------------------------------------- Bring up assessment
832: &assessparms($r);
833: # ---------------------------------------------- This is for course environment
834: } else {
835: &crsenv($r);
836: }
1.1 www 837: } else {
838: # ----------------------------- Not in a course, or not allowed to modify parms
839: $ENV{'user.error.msg'}=
1.7 www 840: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
1.1 www 841: return HTTP_NOT_ACCEPTABLE;
842: }
843: return OK;
844: }
845:
846: 1;
847: __END__
848:
849:
850:
851:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>