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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to set parameters for assessments
                      3: #
1.54    ! www         4: # $Id: lonparmset.pm,v 1.53 2002/06/14 20:19:45 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: #
                     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>".
1.45      matthew   369: 		    "User '$uname' at domain '$udom' not ".
                    370:                     "in this course</font>";
1.43      albertel  371: 		$uname='';
                    372: 		$csec=$ENV{'form.csec'};
                    373: 	    } else {
                    374: 		my %name=&Apache::lonnet::userenvironment($udom,$uname,
                    375: 		      ('firstname','middlename','lastname','generation','id'));
                    376: 		$message="\n<p>\nFull Name: ".
                    377: 		    $name{'firstname'}.' '.$name{'middlename'}.' '
                    378: 			.$name{'lastname'}.' '.$name{'generation'}.
                    379: 			    "<br>\nID: ".$name{'id'}.'<p>';
                    380: 	    }
1.12      www       381:         }
1.43      albertel  382:     }
1.2       www       383: 
1.43      albertel  384:     unless ($csec) { $csec=''; }
1.12      www       385: 
1.44      albertel  386:     my $fcat=$ENV{'form.fcat'};
1.43      albertel  387:     unless ($fcat) { $fcat=''; }
1.2       www       388: 
                    389: # ------------------------------------------------------------------- Tie hashs
1.44      albertel  390:     if (!(tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                    391: 	      &GDBM_READER,0640))) {
                    392: 	$r->print("Unable to access course data. (File $ENV{'request.course.fn'}.db not tieable)");
                    393: 	return ;
                    394:     }
                    395:     if (!(tie(%parmhash,'GDBM_File',
                    396: 	      $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER,0640))) {
                    397: 	$r->print("Unable to access parameter data. (File $ENV{'request.course.fn'}_parms.db not tieable)");
                    398: 	return ;
                    399:     }
1.14      www       400: # --------------------------------------------------------- Get all assessments
1.44      albertel  401:     foreach (keys %bighash) {
                    402: 	if ($_=~/^src\_(\d+)\.(\d+)$/) {
                    403: 	    my $mapid=$1;
                    404: 	    my $resid=$2;
                    405: 	    my $id=$mapid.'.'.$resid;
                    406: 	    my $srcf=$bighash{$_};
                    407: 	    if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    408: 		$ids[$#ids+1]=$id;
                    409: 		$typep{$id}=$1;
                    410: 		$keyp{$id}='';
                    411: 		foreach (split(/\,/,
                    412: 			       &Apache::lonnet::metadata($srcf,'keys'))) {
                    413: 		    if ($_=~/^parameter\_(.*)/) {
                    414: 			my $key=$_;
                    415: 			my $allkey=$1;
                    416: 			$allkey=~s/\_/\./;
                    417: 			my $display=
                    418: 			    &Apache::lonnet::metadata($srcf,$key.'.display');
                    419: 			unless ($display) {
                    420: 			    $display=
                    421: 				&Apache::lonnet::metadata($srcf,$key.'.name');
                    422: 			}
                    423: 			$allkeys{$allkey}=$display;
                    424: 			if ($allkey eq $fcat) {
                    425: 			    $defp{$id}=
                    426: 				&Apache::lonnet::metadata($srcf,$key);
                    427: 			}
                    428: 			if ($keyp{$id}) {
                    429: 			    $keyp{$id}.=','.$key;
                    430: 			} else {
                    431: 			    $keyp{$id}=$key;
1.43      albertel  432: 			}
                    433: 		    }
1.44      albertel  434: 		}
                    435: 		$mapp{$id}=
                    436: 		    &Apache::lonnet::declutter($bighash{'map_id_'.$mapid});
                    437: 		$allmaps{$mapid}=$mapp{$id};
                    438: 		$symbp{$id}=$mapp{$id}.
1.14      www       439: 			'___'.$resid.'___'.
1.16      www       440: 			    &Apache::lonnet::declutter($srcf);
1.44      albertel  441: 	    }
                    442: 	}
                    443:     }
1.14      www       444: # ---------------------------------------------------------- Anything to store?
1.44      albertel  445:     if ($ENV{'form.pres_marker'}) {
                    446: 	my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
                    447: 	$spnam=~s/\_([^\_]+)$/\.$1/;
1.15      www       448: # ---------------------------------------------------------- Construct prefixes
1.14      www       449: 
1.44      albertel  450: 	my $symbparm=$symbp{$sresid}.'.'.$spnam;
                    451: 	my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
                    452: 	
                    453: 	my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$spnam;
                    454: 	my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
                    455: 	my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
                    456: 	
                    457: 	my $courselevel=$ENV{'request.course.id'}.'.'.$spnam;
                    458: 	my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
                    459: 	my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
                    460: 	
                    461: 	my $storeunder='';
                    462: 	if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
                    463: 	if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
                    464: 	if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
                    465: 	if ($snum==6) { $storeunder=$seclevel; }
                    466: 	if ($snum==5) { $storeunder=$seclevelm; }
                    467: 	if ($snum==4) { $storeunder=$seclevelr; }
                    468: 	
1.45      matthew   469:         my %storecontent = ($storeunder        => $ENV{'form.pres_value'},
                    470:                             $storeunder.'type' => $ENV{'form.pres_type'});
1.44      albertel  471: 	my $reply='';
                    472: 	if ($snum>3) {
1.14      www       473: # ---------------------------------------------------------------- Store Course
1.24      www       474: #
                    475: # Expire sheets
1.44      albertel  476: 	    &Apache::lonnet::expirespread('','','studentcalc');
                    477: 	    if (($snum==7) || ($snum==4)) {
                    478: 		&Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
                    479: 	    } elsif (($snum==8) || ($snum==5)) {
                    480: 		&Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
                    481: 	    } else {
                    482: 		&Apache::lonnet::expirespread('','','assesscalc');
                    483: 	    }
1.24      www       484: # Store parameter
1.45      matthew   485:             $reply=&Apache::lonnet::cput
                    486:                 ('resourcedata',\%storecontent,
                    487:                  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    488:                  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.44      albertel  489: 	} else {
1.14      www       490: # ------------------------------------------------------------------ Store User
1.24      www       491: #
                    492: # Expire sheets
1.44      albertel  493: 	    &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
                    494: 	    if ($snum==1) {
                    495: 		&Apache::lonnet::expirespread
                    496: 		    ($uname,$udom,'assesscalc',$symbp{$sresid});
                    497: 	    } elsif ($snum==2) {
                    498: 		&Apache::lonnet::expirespread
                    499: 		    ($uname,$udom,'assesscalc',$mapp{$sresid});
                    500: 	    } else {
                    501: 		&Apache::lonnet::expirespread($uname,$udom,'assesscalc');
                    502: 	    }
1.24      www       503: # Store parameter
1.45      matthew   504: 	    $reply=&Apache::lonnet::cput
                    505:                 ('resourcedata',\%storecontent,$udom,$uname);
1.44      albertel  506: 	}
1.15      www       507: 
1.44      albertel  508: 	if ($reply=~/^error\:(.*)/) {
                    509: 	    $message.="<font color=red>Write Error: $1</font>";
                    510: 	}
1.15      www       511: # ---------------------------------------------------------------- Done storing
1.44      albertel  512:     }
1.2       www       513: # -------------------------------------------------------------- Get coursedata
1.45      matthew   514:     %courseopt = &Apache::lonnet::dump
                    515:         ('resourcedata',
                    516:          $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    517:          $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.44      albertel  518: # --------------------------------------------------- Get userdata (if present)
                    519:     if ($uname) {
1.45      matthew   520:         %useropt=&Apache::lonnet::dump('resourcedata',$udom,$uname);
1.44      albertel  521:     }
1.14      www       522: 
1.2       www       523: # ------------------------------------------------------------------- Sort this
1.17      www       524: 
1.44      albertel  525:     @ids=sort  {
                    526: 	if ($fcat eq '') {
                    527: 	    $a<=>$b;
                    528: 	} else {
                    529: 	    my ($result,@outpar)=&parmval($fcat,$a,$defp{$a});
                    530: 	    my $aparm=$outpar[$result];
                    531: 	    ($result,@outpar)=&parmval($fcat,$b,$defp{$b});
                    532: 	    my $bparm=$outpar[$result];
                    533: 	    1*$aparm<=>1*$bparm;
                    534: 	}
                    535:     } @ids;
1.28      www       536: 
1.2       www       537: # ------------------------------------------------------------------ Start page
1.44      albertel  538:     &startpage($r,$id,$udom,$csec,$uname);
                    539: #    if ($ENV{'form.url'}) {
                    540: #	$r->print('<input type="hidden" value="'.$ENV{'form.url'}.
                    541: #		  '" name="url"><input type="hidden" name="command" value="set">');
                    542: #    }
                    543:     foreach ('tolerance','date_default','date_start','date_end',
                    544: 	     'date_interval','int','float','string') {
                    545: 	$r->print('<input type="hidden" value="'.
                    546: 		  $ENV{'form.recent_'.$_}.'" name="recent_'.$_.'">');
                    547:     }
                    548: 
                    549:     $r->print('<h2>'.$message.'</h2><table><tr><td>Sort list by</td><td>');
                    550:     $r->print('<select name="fcat">');
                    551:     $r->print('<option value="">Enclosing Map</option>');
                    552:     foreach (reverse sort keys %allkeys) {
                    553: 	$r->print('<option value="'.$_.'"');
                    554: 	if ($fcat eq $_) { $r->print(' selected'); }
                    555: 	$r->print('>'.$allkeys{$_}.'</option>');
1.13      www       556:     }
1.44      albertel  557:     if (!$pssymb) {
1.43      albertel  558: 	$r->print('</select></tr><tr><td>Select Enclosing Map</td><td><select name=pschp>');
1.44      albertel  559: 	$r->print('<option value=all>All Maps</option>');
1.48      matthew   560: 	foreach (sort keys %allmaps) {
1.26      www       561: 	    $r->print('<option value="'.$_.'"');
1.44      albertel  562: 	    if (($pssymb=~/^$allmaps{$_}/) || 
                    563: 		($pschp eq $_)) { $r->print(' selected'); }
                    564: 	    $r->print('>'.$allmaps{$_}.'</option>');
                    565: 	}
                    566:     } else {
                    567: 	my ($map,$id,$resource)=split(/___/,$pssymb);
                    568: 	$r->print('<tr><td>Specfic Resource</td><td>&nbsp;</td></tr>');
                    569: 	$r->print('<input type="hidden" value="'.$pssymb.'" name="symb">');
                    570:     }
                    571:     $r->print('</select></td></tr><tr><td>Select Parameter</td><td><select name=pscat>');
                    572:     $r->print('<option value=all>All Parameters</option>');
                    573:     foreach (reverse sort keys %allkeys) {
                    574: 	$r->print('<option value="'.$_.'"');
                    575: 	if ($pscat eq $_) { $r->print(' selected'); }
                    576: 	$r->print('>'.$allkeys{$_}.'</option>');
                    577:     }
                    578:     $r->print('</select></td></tr></table><br><input name=dis type="submit" value="Display">');
                    579:     if (($pscat) || ($pschp) || ($pssymb)) {
1.10      www       580: # ----------------------------------------------------------------- Start Table
1.44      albertel  581: 	my $catmarker='parameter_'.$pscat;
                    582: 	$catmarker=~s/\./\_/g;
                    583: 	my $coursespan=$csec?8:5;
                    584: 	my $csuname=$ENV{'user.name'};
                    585: 	my $csudom=$ENV{'user.domain'};
                    586: 	$r->print(<<ENDTABLEHEAD);
1.9       www       587: <p><table border=2>
1.11      www       588: <tr><td colspan=5></td>
1.10      www       589: <th colspan=$coursespan>Any User</th>
1.9       www       590: ENDTABLEHEAD
1.44      albertel  591: 	if ($uname) {
                    592: 	    $r->print("<th colspan=3 rowspan=2>User $uname at Domain $udom</th>");
                    593: 	}
                    594: 	$r->print(<<ENDTABLETWO);
1.33      www       595: <th rowspan=3>Parameter in Effect</th>
                    596: <th rowspan=3>Current Session Value<br>($csuname at $csudom)</th>
                    597: </tr><tr><td colspan=5></td>
1.10      www       598: <th colspan=2>Resource Level</th>
                    599: <th colspan=3>in Course</th>
                    600: ENDTABLETWO
1.44      albertel  601: 	if ($csec) {
                    602: 	    $r->print("<th colspan=3>in Section/Group $csec</th>");
                    603: 	}
                    604: 	$r->print(<<ENDTABLEHEADFOUR);
1.11      www       605: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1.10      www       606: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
1.11      www       607: <th>default</th><th>from Enclosing Map</th>
1.10      www       608: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
                    609: ENDTABLEHEADFOUR
1.44      albertel  610: 	if ($csec) {
                    611: 	    $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
                    612: 	}
                    613: 	if ($uname) {
                    614: 	    $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
                    615: 	}
                    616: 	$r->print('</tr>');
                    617: 	my $defbgone='';
                    618: 	my $defbgtwo='';
                    619: 	foreach (@ids) {
                    620: 	    my $rid=$_;
                    621: 	    my ($inmapid)=($rid=~/\.(\d+)$/);
                    622: 	    if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
                    623: 		($pssymb eq $symbp{$rid})) {
1.4       www       624: # ------------------------------------------------------ Entry for one resource
1.44      albertel  625: 		if ($defbgone eq '"E0E099"') {
                    626: 		    $defbgone='"E0E0DD"';
                    627: 		} else {
                    628: 		    $defbgone='"E0E099"';
                    629: 		}
                    630: 		if ($defbgtwo eq '"FFFF99"') {
                    631: 		    $defbgtwo='"FFFFDD"';
                    632: 		} else {
                    633: 		    $defbgtwo='"FFFF99"';
                    634: 		}
                    635: 		my $thistitle='';
                    636: 		my %name=   ();
                    637: 		undef %name;
                    638: 		my %part=   ();
                    639: 		my %display=();
                    640: 		my %type=   ();
                    641: 		my %default=();
                    642: 		my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
                    643: 		
                    644: 		foreach (split(/\,/,$keyp{$rid})) {
                    645: 		    if (($_ eq $catmarker) || ($pscat eq 'all')) {
                    646: 			$part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
                    647: 			$name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
                    648: 			$display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
                    649: 			unless ($display{$_}) { $display{$_}=''; }
                    650: 			$display{$_}.=' ('.$name{$_}.')';
                    651: 			$default{$_}=&Apache::lonnet::metadata($uri,$_);
                    652: 			$type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
                    653: 			$thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
1.43      albertel  654: 		    }
1.44      albertel  655: 		}
                    656: 		my $totalparms=scalar keys %name;
                    657: 		if ($totalparms>0) {
                    658: 		    my $firstrow=1;
                    659: 		    $r->print('<tr><td bgcolor='.$defbgone.
                    660: 			      ' rowspan='.$totalparms.'><tt><font size=-1>'.
                    661: 			      join(' / ',split(/\//,$uri)).
                    662: 			      '</font></tt><p><b>'.
                    663: 			      $bighash{'title_'.$rid});
                    664: 		    if ($thistitle) {
                    665: 			$r->print(' ('.$thistitle.')');
1.43      albertel  666: 		    }
1.44      albertel  667: 		    $r->print('</b></td>');
                    668: 		    $r->print('<td bgcolor='.$defbgtwo.
                    669: 			      ' rowspan='.$totalparms.'>'.$typep{$rid}.'</td>');
                    670: 		    $r->print('<td bgcolor='.$defbgone.
                    671: 			      ' rowspan='.$totalparms.'><tt><font size=-1>'.
                    672: 			      join(' / ',split(/\//,$mapp{$rid})).'</font></tt></td>');
                    673: 		    foreach (sort keys %name) {
                    674: 			unless ($firstrow) {
                    675: 			    $r->print('<tr>');
                    676: 			} else {
                    677: 			    $firstrow=0;
1.43      albertel  678: 			}
1.44      albertel  679: 			&print_row($r,$_,\%part,\%name,$rid,\%default,
                    680: 				   \%type,\%display,$defbgone,$defbgtwo);
1.43      albertel  681: 		    }
1.44      albertel  682: 		}
1.43      albertel  683: # -------------------------------------------------- End entry for one resource
                    684: 	    }
1.34      www       685: 	}
1.44      albertel  686: 	$r->print('</table>');
1.43      albertel  687:     }
1.44      albertel  688:     $r->print('</form></body></html>');
                    689:     untie(%bighash);
                    690:     untie(%parmhash);
1.30      www       691: }
                    692: 
1.45      matthew   693: # Set course environment parameters
1.30      www       694: sub crsenv {
                    695:     my $r=shift;
                    696:     my $setoutput='';
1.45      matthew   697:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                    698:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1.30      www       699: # -------------------------------------------------- Go through list of changes
1.38      harris41  700:     foreach (keys %ENV) {
1.30      www       701: 	if ($_=~/^form\.(.+)\_setparmval$/) {
                    702:             my $name=$1;
                    703:             my $value=$ENV{'form.'.$name.'_value'};
                    704:             if ($name eq 'newp') {
                    705:                 $name=$ENV{'form.newp_name'};
                    706:             }
                    707:             if ($name eq 'url') {
                    708: 		$value=~s/^\/res\///;
1.45      matthew   709:                 my @tmp = &Apache::lonnet::get
                    710:                     ('environment',['url'],$dom,$crs);
1.30      www       711:                 $setoutput.='Backing up previous URL: '.
1.45      matthew   712:                     &Apache::lonnet::put
                    713:                         ('environment',
                    714:                          {'top level map backup ' => $tmp[1] },
                    715:                          $dom,$crs).
                    716:                     '<br>';
1.30      www       717:             }
                    718:             if ($name) {
1.45      matthew   719:                 $setoutput.='Setting <tt>'.$name.'</tt> to <tt>'.
                    720:                     $value.'</tt>: '.
                    721:                     &Apache::lonnet::put
                    722:                             ('environment',{$name=>$value},$dom,$crs).
                    723:                     '<br>';
1.30      www       724: 	    }
                    725:         }
1.38      harris41  726:     }
1.30      www       727: # -------------------------------------------------------- Get parameters again
1.45      matthew   728: 
                    729:     my %values=&Apache::lonnet::dump('environment',$dom,$crs);
1.30      www       730:     my $output='';
1.45      matthew   731:     if (! exists($values{'con_lost'})) {
1.30      www       732:         my %descriptions=
1.47      matthew   733: 	    ('url'            => '<b>Top Level Map</b> '.
1.46      matthew   734:                                  '<a href="javascript:openbrowser'.
1.47      matthew   735:                                  "('envform','url','sequence')\">".
1.46      matthew   736:                                  'Browse</a><br><font color=red> '.
1.45      matthew   737:                                  'Modification may make assessment data '.
                    738:                                  'inaccessible</font>',
                    739:              'description'    => '<b>Course Description</b>',
                    740:              'courseid'       => '<b>Course ID or number</b><br>'.
                    741:                                  '(internal, optional)',
1.52      www       742:              'default_xml_style' => '<b>Default XML Style File</b> '.
                    743:                     '<a href="javascript:openbrowser'.
                    744:                     "('envform','default_xml_style'".
                    745:                     ",'sty')\">Browse</a><br>",
1.45      matthew   746:              'question.email' => '<b>Feedback Addresses for Content '.
                    747:                                  'Questions</b><br>(<tt>user:domain,'.
                    748:                                  'user:domain,...</tt>)',
                    749:              'comment.email'  => '<b>Feedback Addresses for Comments</b><br>'.
                    750:                                  '(<tt>user:domain,user:domain,...</tt>)',
                    751:              'policy.email'   => '<b>Feedback Addresses for Course Policy</b>'.
                    752:                                  '<br>(<tt>user:domain,user:domain,...</tt>)',
                    753:              'hideemptyrows'  => '<b>Hide Empty Rows in Spreadsheets</b><br>'.
                    754:                                  '("<tt>yes</tt>" for default hiding)',
1.54    ! www       755:              'pageseparators'  => '<b>Visibly Separate Items on Pages</b><br>'.
        !           756:                                  '("<tt>yes</tt>" for visible separation)',
1.45      matthew   757:              'pch.roles.denied'=> '<b>Disallow Resource Discussion for '.
1.53      www       758:                                   'Roles</b><br>"<tt>st</tt>": '.
1.45      matthew   759:                                   'student, "<tt>ta</tt>": '.
                    760:                                   'TA, "<tt>in</tt>": '.
1.49      matthew   761:                                   'instructor;<br><tt>role,role,...</tt>)',
1.53      www       762:              'pch.users.denied' => 
                    763:                           '<b>Disallow Resource Discussion for Users</b><br>'.
                    764:                                  '(<tt>user:domain,user:domain,...</tt>)',
1.49      matthew   765:              'spreadsheet_default_classcalc' 
1.52      www       766:                  => '<b>Default Course Spreadsheet</b> '.
1.50      matthew   767:                     '<a href="javascript:openbrowser'.
                    768:                     "('envform','spreadsheet_default_classcalc'".
                    769:                     ",'spreadsheet')\">Browse</a><br>",
1.49      matthew   770:              'spreadsheet_default_studentcalc' 
1.52      www       771:                  => '<b>Default Student Spreadsheet</b> '.
1.50      matthew   772:                     '<a href="javascript:openbrowser'.
                    773:                     "('envform','spreadsheet_default_calc'".
                    774:                     ",'spreadsheet')\">Browse</a><br>",
1.49      matthew   775:              'spreadsheet_default_assesscalc' 
1.52      www       776:                  => '<b>Default Assessment Spreadsheet</b> '.
1.50      matthew   777:                     '<a href="javascript:openbrowser'.
                    778:                     "('envform','spreadsheet_default_assesscalc'".
                    779:                     ",'spreadsheet')\">Browse</a><br>",
1.45      matthew   780:              );
                    781: 	foreach (keys(%values)) {
                    782: 	    unless ($descriptions{$_}) {
                    783: 		$descriptions{$_}=$_;
1.43      albertel  784: 	    }
                    785: 	}
                    786: 	foreach (sort keys %descriptions) {
1.51      matthew   787:             # onchange is javascript to automatically check the 'Set' button.
                    788:             my $onchange = 'onchange="javascript:window.document.forms'.
                    789:                 '[\'envform\'].elements[\''.$_.'_setparmval\']'.
                    790:                 '.checked=true;"';
                    791: 	    $output.='<tr><td>'.$descriptions{$_}.'</td>'.
                    792:                 '<td><input name="'.$_.'_value" size=40 '.
                    793:                 'value="'.$values{$_}.'" '.$onchange.' /></td>'.
                    794:                 '<td><input type=checkbox name="'.$_.'_setparmval"></td>'.
                    795:                 '</tr>'."\n";
                    796: 	}
                    797:         my $onchange = 'onchange="javascript:window.document.forms'.
                    798:             '[\'envform\'].elements[\'newp_setparmval\']'.
                    799:             '.checked=true;"';
                    800: 	$output.='<tr><td><i>Create New Environment Variable</i><br />'.
                    801: 	    '<input type="text" size=40 name="newp_name" '.
                    802:                 $onchange.' /></td><td>'.
                    803:             '<input type="text" size=40 name="newp_value" '.
                    804:                 $onchange.' /></td><td>'.
                    805: 	    '<input type="checkbox" name="newp_setparmval" /></td></tr>';
1.43      albertel  806:     }
1.30      www       807:     $r->print(<<ENDENV);
                    808: <html>
1.46      matthew   809: <script type="text/javascript" language="Javascript" >
                    810:     var editbrowser;
1.47      matthew   811:     function openbrowser(formname,elementname,only,omit) {
1.46      matthew   812:         var url = '/res/?';
                    813:         if (editbrowser == null) {
                    814:             url += 'launch=1&';
                    815:         }
                    816:         url += 'catalogmode=interactive&';
                    817:         url += 'mode=parmset&';
                    818:         url += 'form=' + formname + '&';
1.47      matthew   819:         if (only != null) {
                    820:             url += 'only=' + only + '&';
                    821:         } 
                    822:         if (omit != null) {
                    823:             url += 'omit=' + omit + '&';
                    824:         }
1.46      matthew   825:         url += 'element=' + elementname + '';
                    826:         var title = 'Browser';
                    827:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    828:         options += ',width=700,height=600';
                    829:         editbrowser = open(url,title,options,'1');
                    830:         editbrowser.focus();
                    831:     }
                    832: </script>
1.30      www       833: <head>
                    834: <title>LON-CAPA Course Environment</title>
                    835: </head>
                    836: <body bgcolor="#FFFFFF">
                    837: <h1>Set Course Parameters</h1>
                    838: <form method="post" action="/adm/parmset" name="envform">
                    839: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
                    840: <h3>Course Environment</h3>
                    841: $setoutput
                    842: <p>
                    843: <table border=2>
                    844: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
                    845: $output
                    846: </table>
                    847: <input type="submit" name="crsenv" value="Set Course Environment">
                    848: </form>
                    849: </body>
                    850: </html>    
                    851: ENDENV
                    852: }
                    853: 
                    854: # ================================================================ Main Handler
                    855: 
                    856: sub handler {
1.43      albertel  857:     my $r=shift;
1.30      www       858: 
1.43      albertel  859:     if ($r->header_only) {
                    860: 	$r->content_type('text/html');
                    861: 	$r->send_http_header;
                    862: 	return OK;
                    863:     }
                    864:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.30      www       865: # ----------------------------------------------------- Needs to be in a course
                    866: 
1.43      albertel  867:     if (($ENV{'request.course.id'}) && 
                    868: 	(&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
1.30      www       869: 
1.43      albertel  870: 	unless (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) {
1.30      www       871: # --------------------------------------------------------- Bring up assessment
1.43      albertel  872: 	    &assessparms($r);
1.30      www       873: # ---------------------------------------------- This is for course environment
1.43      albertel  874: 	} else {
                    875: 	    &crsenv($r);
                    876: 	}
                    877:     } else {
1.1       www       878: # ----------------------------- Not in a course, or not allowed to modify parms
1.43      albertel  879: 	$ENV{'user.error.msg'}=
                    880: 	    "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
                    881: 	return HTTP_NOT_ACCEPTABLE;
                    882:     }
                    883:     return OK;
1.1       www       884: }
                    885: 
                    886: 1;
                    887: __END__
                    888: 
1.38      harris41  889: 
                    890: =head1 NAME
                    891: 
                    892: Apache::lonparmset - Handler to set parameters for assessments
                    893: 
                    894: =head1 SYNOPSIS
                    895: 
                    896: Invoked by /etc/httpd/conf/srm.conf:
                    897: 
                    898:  <Location /adm/parmset>
                    899:  PerlAccessHandler       Apache::lonacc
                    900:  SetHandler perl-script
                    901:  PerlHandler Apache::lonparmset
                    902:  ErrorDocument     403 /adm/login
                    903:  ErrorDocument     406 /adm/roles
                    904:  ErrorDocument	  500 /adm/errorhandler
                    905:  </Location>
                    906: 
                    907: =head1 INTRODUCTION
                    908: 
                    909: This module sets assessment parameters.
                    910: 
                    911: This is part of the LearningOnline Network with CAPA project
                    912: described at http://www.lon-capa.org.
                    913: 
                    914: =head1 HANDLER SUBROUTINE
                    915: 
                    916: This routine is called by Apache and mod_perl.
                    917: 
                    918: =over 4
                    919: 
                    920: =item *
                    921: 
                    922: need to be in course
                    923: 
                    924: =item *
                    925: 
                    926: bring up assessment screen or course environment
                    927: 
                    928: =back
                    929: 
                    930: =head1 OTHER SUBROUTINES
                    931: 
                    932: =over 4
                    933: 
                    934: =item *
                    935: 
                    936: parmval() : figure out a cascading parameter
                    937: 
                    938: =item *
                    939: 
1.44      albertel  940: valout() : format a value for output
1.38      harris41  941: 
                    942: =item *
                    943: 
                    944: plink() : produces link anchor
                    945: 
                    946: =item *
                    947: 
                    948: assessparms() : show assess data and parameters
                    949: 
                    950: =item *
                    951: 
                    952: crsenv() : for the course environment
                    953: 
                    954: =back
                    955: 
                    956: =cut
1.1       www       957: 
                    958: 
                    959: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.