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