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