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

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

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