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