Annotation of loncom/interface/lonparmset.pm, revision 1.30
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,
! 15: # 07/05,07/06 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.15 www 294: $spnam=~s/\_/\./;
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.9 www 529: $r->print(<<ENDTABLEHEAD);
530: <p><table border=2>
1.11 www 531: <tr><td colspan=5></td>
1.10 www 532: <th colspan=$coursespan>Any User</th>
1.9 www 533: ENDTABLEHEAD
1.10 www 534: if ($uname) {
535: $r->print("<th colspan=3 rowspan=2>User $uname at Domain $udom</th>");
536: }
537: $r->print(<<ENDTABLETWO);
1.11 www 538: <th rowspan=3>Parameter in Effect</th></tr><tr><td colspan=5></td>
1.10 www 539: <th colspan=2>Resource Level</th>
540: <th colspan=3>in Course</th>
541: ENDTABLETWO
1.9 www 542: if ($csec) {
1.10 www 543: $r->print("<th colspan=3>in Section/Group $csec</th>");
1.9 www 544: }
1.10 www 545: $r->print(<<ENDTABLEHEADFOUR);
1.11 www 546: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1.10 www 547: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
1.11 www 548: <th>default</th><th>from Enclosing Map</th>
1.10 www 549: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
550: ENDTABLEHEADFOUR
551: if ($csec) {
552: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
553: }
554: if ($uname) {
555: $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
556: }
557: $r->print('</tr><tr>');
1.19 www 558: my $defbgone='';
559: my $defbgtwo='';
1.3 www 560: map {
1.26 www 561: my $rid=$_;
1.29 www 562: my ($inmapid)=($rid=~/\.(\d+)$/);
563: if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
564: ($pssymb eq $mapp{$rid}.'___'.$inmapid.'___'.
565: &Apache::lonnet::declutter($bighash{'src_'.$rid}))) {
1.4 www 566: # ------------------------------------------------------ Entry for one resource
1.19 www 567: if ($defbgone eq '"E0E099"') {
568: $defbgone='"E0E0DD"';
569: } else {
570: $defbgone='"E0E099"';
571: }
572: if ($defbgtwo eq '"FFFF99"') {
573: $defbgtwo='"FFFFDD"';
574: } else {
575: $defbgtwo='"FFFF99"';
576: }
1.8 www 577: @outpar=();
1.5 www 578: my $thistitle='';
1.16 www 579: my %name= ();
580: my %part= ();
581: my %display=();
582: my %type= ();
583: my %default=();
584: my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
585:
1.4 www 586: map {
1.16 www 587: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
588: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
589: $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
590: unless ($display{$_}) { $display{$_}=''; }
591: $display{$_}.=' ('.$name{$_}.')';
1.20 www 592: $default{$_}=&Apache::lonnet::metadata($uri,$_);
1.16 www 593: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
594: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
595: } split(/\,/,$keyp{$rid});
596:
1.11 www 597: my $totalparms=scalar keys %name;
1.21 www 598: my $isdef=1;
599: unless ($totalparms) { $totalparms=1; $isdef=0; }
1.26 www 600: if ($pscat ne 'all') { $totalparms=1; }
1.19 www 601: $r->print('<td bgcolor='.$defbgone.
602: ' rowspan='.$totalparms.'><tt><font size=-1>'.
1.16 www 603: join(' / ',split(/\//,$uri)).
604: '</font></tt><p><b>'.
1.5 www 605: $bighash{'title_'.$rid});
606: if ($thistitle) {
607: $r->print(' ('.$thistitle.')');
608: }
1.11 www 609: $r->print('</b></td>');
1.19 www 610: $r->print('<td bgcolor='.$defbgtwo.
611: ' rowspan='.$totalparms.'>'.$typep{$rid}.'</td>');
612: $r->print('<td bgcolor='.$defbgone.
613: ' rowspan='.$totalparms.'><tt><font size=-1>'.
1.10 www 614: join(' / ',split(/\//,$mapp{$rid})).'</font></tt></td>');
1.21 www 615: if ($isdef) {
1.11 www 616: map {
1.26 www 617: if (($_ eq $catmarker) || ($pscat eq 'all')) {
1.11 www 618: my $result=&parmval($part{$_}.'.'.$name{$_},$rid,$default{$_});
619:
1.19 www 620: $r->print("<td bgcolor=".$defbgtwo.
621: ">$part{$_}</td><td bgcolor=".$defbgone.
622: ">$display{$_}</td>");
1.16 www 623: my $thismarker=$_;
624: $thismarker=~s/^parameter\_//;
625: my $mprefix=$rid.'&'.$thismarker.'&';
1.13 www 626:
1.19 www 627: $r->print('<td bgcolor='.
628: (($result==11)?'"#AAFFAA"':'#FFDDDD').'>'.
1.12 www 629: &valout($outpar[11],$type{$_}).'</td>');
1.19 www 630: $r->print('<td bgcolor='.
631: (($result==10)?'"#AAFFAA"':'#FFDDDD').'>'.
1.12 www 632: &valout($outpar[10],$type{$_}).'</td>');
1.13 www 633:
1.19 www 634: $r->print('<td bgcolor='.
635: (($result==9)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 636: &plink($type{$_},$display{$_},$outpar[9],$mprefix.'9',
637: 'parmform.pres','psub').'</td>');
1.19 www 638: $r->print('<td bgcolor='.
639: (($result==8)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 640: &plink($type{$_},$display{$_},$outpar[8],$mprefix.'8',
641: 'parmform.pres','psub').'</td>');
1.19 www 642: $r->print('<td bgcolor='.
643: (($result==7)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 644: &plink($type{$_},$display{$_},$outpar[7],$mprefix.'7',
645: 'parmform.pres','psub').'</td>');
646:
1.9 www 647: if ($csec) {
1.19 www 648: $r->print('<td bgcolor='.
649: (($result==6)?'"#AAFFAA"':$defbgtwo).'>'.
1.13 www 650: &plink($type{$_},$display{$_},$outpar[6],$mprefix.'6',
651: 'parmform.pres','psub').'</td>');
1.19 www 652: $r->print('<td bgcolor='.
653: (($result==5)?'"#AAFFAA"':$defbgtwo).'>'.
1.13 www 654: &plink($type{$_},$display{$_},$outpar[5],$mprefix.'5',
655: 'parmform.pres','psub').'</td>');
1.19 www 656: $r->print('<td bgcolor='.
657: (($result==4)?'"#AAFFAA"':$defbgtwo).'>'.
1.13 www 658: &plink($type{$_},$display{$_},$outpar[4],$mprefix.'4',
659: 'parmform.pres','psub').'</td>');
1.9 www 660: }
1.13 www 661:
1.9 www 662: if ($uname) {
1.19 www 663: $r->print('<td bgcolor='.
664: (($result==3)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 665: &plink($type{$_},$display{$_},$outpar[3],$mprefix.'3',
666: 'parmform.pres','psub').'</td>');
1.19 www 667: $r->print('<td bgcolor='.
668: (($result==2)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 669: &plink($type{$_},$display{$_},$outpar[2],$mprefix.'2',
670: 'parmform.pres','psub').'</td>');
1.19 www 671: $r->print('<td bgcolor='.
672: (($result==1)?'"#AAFFAA"':$defbgone).'>'.
1.13 www 673: &plink($type{$_},$display{$_},$outpar[1],$mprefix.'1',
674: 'parmform.pres','psub').'</td>');
1.9 www 675: }
1.19 www 676: $r->print(
677: '<td bgcolor=#CCCCFF>'.&valout($outpar[$result],$type{$_}).'</td>');
1.5 www 678: $r->print("</tr>\n<tr>");
1.26 www 679: }
1.11 www 680: } sort keys %name;
1.21 www 681: } else {
1.26 www 682: $r->print("</tr>\n<tr>");
1.21 www 683: }
1.4 www 684: # -------------------------------------------------- End entry for one resource
1.26 www 685: }
1.3 www 686: } @ids;
1.26 www 687: $r->print('</table>');
688: }
689: $r->print('</form></body></html>');
1.1 www 690: untie(%bighash);
1.2 www 691: untie(%parmhash);
1.1 www 692: }
1.30 ! www 693: }
! 694:
! 695: sub crsenv {
! 696: my $r=shift;
! 697: my $setoutput='';
! 698: # -------------------------------------------------- Go through list of changes
! 699: map {
! 700: if ($_=~/^form\.(.+)\_setparmval$/) {
! 701: my $name=$1;
! 702: my $value=$ENV{'form.'.$name.'_value'};
! 703: if ($name eq 'newp') {
! 704: $name=$ENV{'form.newp_name'};
! 705: }
! 706: if ($name eq 'url') {
! 707: $value=~s/^\/res\///;
! 708: $setoutput.='Backing up previous URL: '.
! 709: &Apache::lonnet::reply('put:'.
! 710: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
! 711: ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
! 712: ':environment:'.
! 713: &Apache::lonnet::escape('top level map backup '.
! 714: time).'='.
! 715: &Apache::lonnet::reply('get:'.
! 716: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
! 717: ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
! 718: ':environment:url',
! 719: $ENV{'course.'.$ENV{'request.course.id'}.'.home'}),
! 720: $ENV{'course.'.$ENV{'request.course.id'}.'.home'}).
! 721: '<br>';
! 722:
! 723: }
! 724: if ($name) {
! 725: $setoutput.='Setting <tt>'.$name.'</tt> to <tt>'.
! 726: $value.'</tt>: '.
! 727: &Apache::lonnet::reply('put:'.
! 728: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
! 729: ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
! 730: ':environment:'.
! 731: &Apache::lonnet::escape($name).'='.
! 732: &Apache::lonnet::escape($value),
! 733: $ENV{'course.'.$ENV{'request.course.id'}.'.home'}).
! 734: '<br>';
! 735: }
! 736: }
! 737: } keys %ENV;
! 738: # -------------------------------------------------------- Get parameters again
! 739: my $rep=&Apache::lonnet::reply
! 740: ('dump:'.$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.
! 741: ':'.$ENV{'course.'.$ENV{'request.course.id'}.'.num'}.
! 742: ':environment',
! 743: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
! 744: my $output='';
! 745: if ($rep ne 'con_lost') {
! 746: my %values;
! 747: my %descriptions=
! 748: ('url' => '<b>Top Level Map</b><br><font color=red>'.
! 749: 'Modification may make assessment data inaccessible</font>',
! 750: 'description' => '<b>Course Description</b>',
! 751: 'courseid' => '<b>Course ID or number</b><br>(internal, optional)',
! 752: 'question.email' => '<b>Feedback Addresses for Content Questions</b><br>'.
! 753: '(<tt>user:domain,user:domain,...</tt>)',
! 754: 'comment.email' => '<b>Feedback Addresses for Comments</b><br>'.
! 755: '(<tt>user:domain,user:domain,...</tt>)',
! 756: 'policy.email' => '<b>Feedback Addresses for Course Policy</b><br>'.
! 757: '(<tt>user:domain,user:domain,...</tt>)'
! 758: );
! 759:
! 760: map {
! 761: my ($name,$value)=split(/\=/,$_);
! 762: $name=&Apache::lonnet::unescape($name);
! 763: $values{$name}=&Apache::lonnet::unescape($value);
! 764: unless ($descriptions{$name}) {
! 765: $descriptions{$name}=$name;
! 766: }
! 767: } split(/\&/,$rep);
! 768: map {
! 769: $output.='<tr><td>'.$descriptions{$_}.'</td><td><input name="'.
! 770: $_.'_value" size=40 value="'.
! 771: $values{$_}.
! 772: '"></td><td><input type=checkbox name="'.$_.
! 773: '_setparmval"></td></tr>';
! 774: } keys %descriptions;
! 775: $output.='<tr><td><i>Create New Environment Variable</i><br>'.
! 776: '<input type="text" size=40 name="newp_name"></td><td>'.
! 777: '<input type="text" size=40 name="newp_value"></td><td>'.
! 778: '<input type="checkbox" name="newp_setparmval"></td></tr>';
! 779: }
! 780: $r->print(<<ENDENV);
! 781: <html>
! 782: <head>
! 783: <title>LON-CAPA Course Environment</title>
! 784: </head>
! 785: <body bgcolor="#FFFFFF">
! 786: <h1>Set Course Parameters</h1>
! 787: <form method="post" action="/adm/parmset" name="envform">
! 788: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
! 789: <h3>Course Environment</h3>
! 790: $setoutput
! 791: <p>
! 792: <table border=2>
! 793: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
! 794: $output
! 795: </table>
! 796: <input type="submit" name="crsenv" value="Set Course Environment">
! 797: </form>
! 798: </body>
! 799: </html>
! 800: ENDENV
! 801: }
! 802:
! 803: # ================================================================ Main Handler
! 804:
! 805: sub handler {
! 806: my $r=shift;
! 807:
! 808: if ($r->header_only) {
! 809: $r->content_type('text/html');
! 810: $r->send_http_header;
! 811: return OK;
! 812: }
! 813:
! 814: # ----------------------------------------------------- Needs to be in a course
! 815:
! 816: if (($ENV{'request.course.fn'}) &&
! 817: (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
! 818:
! 819: unless ($ENV{'form.crsenv'}) {
! 820: # --------------------------------------------------------- Bring up assessment
! 821: &assessparms($r);
! 822: # ---------------------------------------------- This is for course environment
! 823: } else {
! 824: &crsenv($r);
! 825: }
1.1 www 826: } else {
827: # ----------------------------- Not in a course, or not allowed to modify parms
828: $ENV{'user.error.msg'}=
1.7 www 829: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
1.1 www 830: return HTTP_NOT_ACCEPTABLE;
831: }
832: return OK;
833: }
834:
835: 1;
836: __END__
837:
838:
839:
840:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>