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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to set parameters for assessments
                      3: #
1.51    ! matthew     4: # $Id: lonparmset.pm,v 1.50 2002/04/10 15:30:45 matthew 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)',
                    742:              'question.email' => '<b>Feedback Addresses for Content '.
                    743:                                  'Questions</b><br>(<tt>user:domain,'.
                    744:                                  'user:domain,...</tt>)',
                    745:              'comment.email'  => '<b>Feedback Addresses for Comments</b><br>'.
                    746:                                  '(<tt>user:domain,user:domain,...</tt>)',
                    747:              'policy.email'   => '<b>Feedback Addresses for Course Policy</b>'.
                    748:                                  '<br>(<tt>user:domain,user:domain,...</tt>)',
                    749:              'hideemptyrows'  => '<b>Hide Empty Rows in Spreadsheets</b><br>'.
                    750:                                  '("<tt>yes</tt>" for default hiding)',
                    751:              'pch.roles.denied'=> '<b>Disallow Resource Discussion for '.
                    752:                                   'Students</b><br>"<tt>st</tt>": '.
                    753:                                   'student, "<tt>ta</tt>": '.
                    754:                                   'TA, "<tt>in</tt>": '.
1.49      matthew   755:                                   'instructor;<br><tt>role,role,...</tt>)',
                    756:              'spreadsheet_default_classcalc' 
1.51    ! matthew   757:                  => '<b>Default course spreadsheet</b> '.
1.50      matthew   758:                     '<a href="javascript:openbrowser'.
                    759:                     "('envform','spreadsheet_default_classcalc'".
                    760:                     ",'spreadsheet')\">Browse</a><br>",
1.49      matthew   761:              'spreadsheet_default_studentcalc' 
1.51    ! matthew   762:                  => '<b>Default student spreadsheet</b> '.
1.50      matthew   763:                     '<a href="javascript:openbrowser'.
                    764:                     "('envform','spreadsheet_default_calc'".
                    765:                     ",'spreadsheet')\">Browse</a><br>",
1.49      matthew   766:              'spreadsheet_default_assesscalc' 
1.51    ! matthew   767:                  => '<b>Default assessment spreadsheet</b> '.
1.50      matthew   768:                     '<a href="javascript:openbrowser'.
                    769:                     "('envform','spreadsheet_default_assesscalc'".
                    770:                     ",'spreadsheet')\">Browse</a><br>",
1.45      matthew   771:              );
                    772: 	foreach (keys(%values)) {
                    773: 	    unless ($descriptions{$_}) {
                    774: 		$descriptions{$_}=$_;
1.43      albertel  775: 	    }
                    776: 	}
                    777: 	foreach (sort keys %descriptions) {
1.51    ! matthew   778:             # onchange is javascript to automatically check the 'Set' button.
        !           779:             my $onchange = 'onchange="javascript:window.document.forms'.
        !           780:                 '[\'envform\'].elements[\''.$_.'_setparmval\']'.
        !           781:                 '.checked=true;"';
        !           782: 	    $output.='<tr><td>'.$descriptions{$_}.'</td>'.
        !           783:                 '<td><input name="'.$_.'_value" size=40 '.
        !           784:                 'value="'.$values{$_}.'" '.$onchange.' /></td>'.
        !           785:                 '<td><input type=checkbox name="'.$_.'_setparmval"></td>'.
        !           786:                 '</tr>'."\n";
        !           787: 	}
        !           788:         my $onchange = 'onchange="javascript:window.document.forms'.
        !           789:             '[\'envform\'].elements[\'newp_setparmval\']'.
        !           790:             '.checked=true;"';
        !           791: 	$output.='<tr><td><i>Create New Environment Variable</i><br />'.
        !           792: 	    '<input type="text" size=40 name="newp_name" '.
        !           793:                 $onchange.' /></td><td>'.
        !           794:             '<input type="text" size=40 name="newp_value" '.
        !           795:                 $onchange.' /></td><td>'.
        !           796: 	    '<input type="checkbox" name="newp_setparmval" /></td></tr>';
1.43      albertel  797:     }
1.30      www       798:     $r->print(<<ENDENV);
                    799: <html>
1.46      matthew   800: <script type="text/javascript" language="Javascript" >
                    801:     var editbrowser;
1.47      matthew   802:     function openbrowser(formname,elementname,only,omit) {
1.46      matthew   803:         var url = '/res/?';
                    804:         if (editbrowser == null) {
                    805:             url += 'launch=1&';
                    806:         }
                    807:         url += 'catalogmode=interactive&';
                    808:         url += 'mode=parmset&';
                    809:         url += 'form=' + formname + '&';
1.47      matthew   810:         if (only != null) {
                    811:             url += 'only=' + only + '&';
                    812:         } 
                    813:         if (omit != null) {
                    814:             url += 'omit=' + omit + '&';
                    815:         }
1.46      matthew   816:         url += 'element=' + elementname + '';
                    817:         var title = 'Browser';
                    818:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    819:         options += ',width=700,height=600';
                    820:         editbrowser = open(url,title,options,'1');
                    821:         editbrowser.focus();
                    822:     }
                    823: </script>
1.30      www       824: <head>
                    825: <title>LON-CAPA Course Environment</title>
                    826: </head>
                    827: <body bgcolor="#FFFFFF">
                    828: <h1>Set Course Parameters</h1>
                    829: <form method="post" action="/adm/parmset" name="envform">
                    830: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
                    831: <h3>Course Environment</h3>
                    832: $setoutput
                    833: <p>
                    834: <table border=2>
                    835: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
                    836: $output
                    837: </table>
                    838: <input type="submit" name="crsenv" value="Set Course Environment">
                    839: </form>
                    840: </body>
                    841: </html>    
                    842: ENDENV
                    843: }
                    844: 
                    845: # ================================================================ Main Handler
                    846: 
                    847: sub handler {
1.43      albertel  848:     my $r=shift;
1.30      www       849: 
1.43      albertel  850:     if ($r->header_only) {
                    851: 	$r->content_type('text/html');
                    852: 	$r->send_http_header;
                    853: 	return OK;
                    854:     }
                    855:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.30      www       856: # ----------------------------------------------------- Needs to be in a course
                    857: 
1.43      albertel  858:     if (($ENV{'request.course.id'}) && 
                    859: 	(&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
1.30      www       860: 
1.43      albertel  861: 	unless (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) {
1.30      www       862: # --------------------------------------------------------- Bring up assessment
1.43      albertel  863: 	    &assessparms($r);
1.30      www       864: # ---------------------------------------------- This is for course environment
1.43      albertel  865: 	} else {
                    866: 	    &crsenv($r);
                    867: 	}
                    868:     } else {
1.1       www       869: # ----------------------------- Not in a course, or not allowed to modify parms
1.43      albertel  870: 	$ENV{'user.error.msg'}=
                    871: 	    "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
                    872: 	return HTTP_NOT_ACCEPTABLE;
                    873:     }
                    874:     return OK;
1.1       www       875: }
                    876: 
                    877: 1;
                    878: __END__
                    879: 
1.38      harris41  880: 
                    881: =head1 NAME
                    882: 
                    883: Apache::lonparmset - Handler to set parameters for assessments
                    884: 
                    885: =head1 SYNOPSIS
                    886: 
                    887: Invoked by /etc/httpd/conf/srm.conf:
                    888: 
                    889:  <Location /adm/parmset>
                    890:  PerlAccessHandler       Apache::lonacc
                    891:  SetHandler perl-script
                    892:  PerlHandler Apache::lonparmset
                    893:  ErrorDocument     403 /adm/login
                    894:  ErrorDocument     406 /adm/roles
                    895:  ErrorDocument	  500 /adm/errorhandler
                    896:  </Location>
                    897: 
                    898: =head1 INTRODUCTION
                    899: 
                    900: This module sets assessment parameters.
                    901: 
                    902: This is part of the LearningOnline Network with CAPA project
                    903: described at http://www.lon-capa.org.
                    904: 
                    905: =head1 HANDLER SUBROUTINE
                    906: 
                    907: This routine is called by Apache and mod_perl.
                    908: 
                    909: =over 4
                    910: 
                    911: =item *
                    912: 
                    913: need to be in course
                    914: 
                    915: =item *
                    916: 
                    917: bring up assessment screen or course environment
                    918: 
                    919: =back
                    920: 
                    921: =head1 OTHER SUBROUTINES
                    922: 
                    923: =over 4
                    924: 
                    925: =item *
                    926: 
                    927: parmval() : figure out a cascading parameter
                    928: 
                    929: =item *
                    930: 
1.44      albertel  931: valout() : format a value for output
1.38      harris41  932: 
                    933: =item *
                    934: 
                    935: plink() : produces link anchor
                    936: 
                    937: =item *
                    938: 
                    939: assessparms() : show assess data and parameters
                    940: 
                    941: =item *
                    942: 
                    943: crsenv() : for the course environment
                    944: 
                    945: =back
                    946: 
                    947: =cut
1.1       www       948: 
                    949: 
                    950: 

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