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