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