Annotation of loncom/interface/lonparmset.pm, revision 1.55

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>