File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.61: download - view: text, annotated - select for diffs
Fri Aug 16 20:47:26 2002 UTC (21 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_0_5_1, version_0_5, HEAD
- lost ver 1.56 changes

    1: # The LearningOnline Network with CAPA
    2: # Handler to set parameters for assessments
    3: #
    4: # $Id: lonparmset.pm,v 1.61 2002/08/16 20:47:26 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###################################################################
   29: ###################################################################
   30: 
   31: =pod
   32: 
   33: =head1 NAME
   34: 
   35: lonparmset - Handler to set parameters for assessments and course
   36: 
   37: =head1 SYNOPSIS
   38: 
   39: lonparmset provides an interface to setting course parameters. 
   40: 
   41: =head1 DESCRIPTION
   42: 
   43: This module sets coursewide and assessment parameters.
   44: 
   45: =head1 INTERNAL SUBROUTINES
   46: 
   47: =over 4
   48: 
   49: =cut
   50: 
   51: ###################################################################
   52: ###################################################################
   53: 
   54: package Apache::lonparmset;
   55: 
   56: use strict;
   57: use Apache::lonnet;
   58: use Apache::Constants qw(:common :http REDIRECT);
   59: use Apache::loncommon;
   60: use GDBM_File;
   61: use Apache::lonhomework;
   62: use Apache::lonxml;
   63: 
   64: 
   65: my %courseopt;
   66: my %useropt;
   67: my %parmhash;
   68: 
   69: my @ids;
   70: my %symbp;
   71: my %mapp;
   72: my %typep;
   73: my %keyp;
   74: 
   75: my $uname;
   76: my $udom;
   77: my $uhome;
   78: my $csec;
   79: my $coursename;
   80: 
   81: ##################################################
   82: ##################################################
   83: 
   84: =pod
   85: 
   86: =item parmval
   87: 
   88: Figure out a cascading parameter.
   89: 
   90: Inputs:  $what $id $def
   91: 
   92: Returns: I am not entirely sure.
   93: 
   94: =cut
   95: 
   96: ##################################################
   97: ##################################################
   98: sub parmval {
   99:     my ($what,$id,$def)=@_;
  100:     my $result='';
  101:     my @outpar=();
  102: # ----------------------------------------------------- Cascading lookup scheme
  103: 
  104:     my $symbparm=$symbp{$id}.'.'.$what;
  105:     my $mapparm=$mapp{$id}.'___(all).'.$what;
  106: 
  107:     my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$what;
  108:     my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  109:     my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  110: 
  111:     my $courselevel=$ENV{'request.course.id'}.'.'.$what;
  112:     my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
  113:     my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
  114: 
  115: # -------------------------------------------------------- first, check default
  116: 
  117:     if ($def) { $outpar[11]=$def; $result=11; }
  118: 
  119: # ----------------------------------------------------- second, check map parms
  120: 
  121:     my $thisparm=$parmhash{$symbparm};
  122:     if ($thisparm) { $outpar[10]=$thisparm; $result=10; }
  123: 
  124: # --------------------------------------------------------- third, check course
  125: 
  126:     if ($courseopt{$courselevel}) {
  127: 	$outpar[9]=$courseopt{$courselevel};
  128: 	$result=9;
  129:     }
  130: 
  131:     if ($courseopt{$courselevelm}) {
  132: 	$outpar[8]=$courseopt{$courselevelm};
  133: 	$result=8;
  134:     }
  135: 
  136:     if ($courseopt{$courselevelr}) {
  137: 	$outpar[7]=$courseopt{$courselevelr};
  138: 	$result=7;
  139:     }
  140: 
  141:     if ($csec) {
  142:         if ($courseopt{$seclevel}) {
  143: 	    $outpar[6]=$courseopt{$seclevel};
  144: 	    $result=6;
  145: 	}
  146:         if ($courseopt{$seclevelm}) {
  147: 	    $outpar[5]=$courseopt{$seclevelm};
  148: 	    $result=5;
  149: 	}
  150: 
  151:         if ($courseopt{$seclevelr}) {
  152: 	    $outpar[4]=$courseopt{$seclevelr};
  153: 	    $result=4;
  154: 	}
  155:     }
  156: 
  157: # ---------------------------------------------------------- fourth, check user
  158: 
  159:     if ($uname) {
  160: 	if ($useropt{$courselevel}) {
  161: 	    $outpar[3]=$useropt{$courselevel};
  162: 	    $result=3;
  163: 	}
  164: 
  165: 	if ($useropt{$courselevelm}) {
  166: 	    $outpar[2]=$useropt{$courselevelm};
  167: 	    $result=2;
  168: 	}
  169: 
  170: 	if ($useropt{$courselevelr}) {
  171: 	    $outpar[1]=$useropt{$courselevelr};
  172: 	    $result=1;
  173: 	}
  174:     }
  175: 
  176:     return ($result,@outpar);
  177: }
  178: 
  179: ##################################################
  180: ##################################################
  181: 
  182: =pod
  183: 
  184: =item valout
  185: 
  186: Format a value for output.
  187: 
  188: Inputs:  $value, $type
  189: 
  190: Returns: $value, formatted for output.  If $type indicates it is a date,
  191: localtime($value) is returned.
  192: 
  193: =cut
  194: 
  195: ##################################################
  196: ##################################################
  197: sub valout {
  198:     my ($value,$type)=@_;
  199:     my $result = '';
  200:     # Values of zero are valid.
  201:     if (! $value && $value ne '0') {
  202:         $result = '  ';
  203:     } else {
  204:         if ($type=~/^date/) {
  205:             $result = localtime($value);
  206:         } else {
  207:             $result = $value;
  208:         }
  209:     }
  210:     return $result;
  211: }
  212: 
  213: ##################################################
  214: ##################################################
  215: 
  216: =pod
  217: 
  218: =item plink
  219: 
  220: Produces a link anchor.
  221: 
  222: Inputs: $type,$dis,$value,$marker,$return,$call
  223: 
  224: Returns: scalar with html code for a link which will envoke the 
  225: javascript function 'pjump'.
  226: 
  227: =cut
  228: 
  229: ##################################################
  230: ##################################################
  231: sub plink {
  232:     my ($type,$dis,$value,$marker,$return,$call)=@_;
  233:     my $winvalue=$value;
  234:     unless ($winvalue) {
  235: 	if ($type=~/^date/) {
  236:             $winvalue=$ENV{'form.recent_'.$type};
  237:         } else {
  238:             $winvalue=$ENV{'form.recent_'.(split(/\_/,$type))[0]};
  239:         }
  240:     }
  241:     return 
  242: 	'<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
  243: 	    .$marker."','".$return."','".$call."'".');">'.
  244: 		&valout($value,$type).'</a><a name="'.$marker.'"></a>';
  245: }
  246: 
  247: 
  248: sub startpage {
  249:     my ($r,$id,$udom,$csec,$uname)=@_;
  250:     $r->content_type('text/html');
  251:     $r->send_http_header;
  252:     $r->print(<<ENDHEAD);
  253: <html>
  254: <head>
  255: <title>LON-CAPA Course Parameters</title>
  256: <script>
  257: 
  258:     function pclose() {
  259:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  260:                  "height=350,width=350,scrollbars=no,menubar=no");
  261:         parmwin.close();
  262:     }
  263: 
  264:     function pjump(type,dis,value,marker,ret,call) {
  265:         document.parmform.pres_marker.value='';
  266:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
  267:                  +"&value="+escape(value)+"&marker="+escape(marker)
  268:                  +"&return="+escape(ret)
  269:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
  270:                  "height=350,width=350,scrollbars=no,menubar=no");
  271: 
  272:     }
  273: 
  274:     function psub() {
  275:         pclose();
  276:         if (document.parmform.pres_marker.value!='') {
  277:             document.parmform.action+='#'+document.parmform.pres_marker.value;
  278:             var typedef=new Array();
  279:             typedef=document.parmform.pres_type.value.split('_');
  280:            if (document.parmform.pres_type.value!='') {
  281:             if (typedef[0]=='date') {
  282:                 eval('document.parmform.recent_'+
  283:                      document.parmform.pres_type.value+
  284: 		     '.value=document.parmform.pres_value.value;');
  285:             } else {
  286:                 eval('document.parmform.recent_'+typedef[0]+
  287: 		     '.value=document.parmform.pres_value.value;');
  288:             }
  289: 	   }
  290:             document.parmform.submit();
  291:         } else {
  292:             document.parmform.pres_value.value='';
  293:             document.parmform.pres_marker.value='';
  294:         }
  295:     }
  296: 
  297:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
  298:         var options = "width=" + w + ",height=" + h + ",";
  299:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  300:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
  301:         var newWin = window.open(url, wdwName, options);
  302:         newWin.focus();
  303:     }
  304: </script>
  305: </head>
  306: <body bgcolor="#FFFFFF" onUnload="pclose()">
  307: <h1>Set Course Parameters for Course:
  308: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h1>
  309: <form method="post" action="/adm/parmset" name="envform">
  310: <h3>Course Environment</h3>
  311: <input type="submit" name="crsenv" value="Set Course Environment">
  312: </form>
  313: <form method="post" action="/adm/parmset" name="parmform">
  314: <h3>Course Assessments</h3>
  315: <b>
  316: Section/Group:
  317: <input type="text" value="$csec" size="6" name="csec">
  318: <br>
  319: For User 
  320: <input type="text" value="$uname" size="12" name="uname">
  321: or ID
  322: <input type="text" value="$id" size="12" name="id"> 
  323: at Domain 
  324: <input type="text" value="$udom" size="6" name="udom">
  325: </b>
  326: <input type="hidden" value='' name="pres_value">
  327: <input type="hidden" value='' name="pres_type">
  328: <input type="hidden" value='' name="pres_marker">
  329: ENDHEAD
  330: 
  331: }
  332: 
  333: sub print_row {
  334:     my ($r,$which,$part,$name,$rid,$default,$type,$display,$defbgone,
  335: 	$defbgtwo,$parmlev)=@_;
  336:     my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
  337: 				  $rid,$$default{$which});
  338:     my $parm=$$display{$which};
  339: 
  340:     if ($parmlev eq 'full' || $parmlev eq 'brief') {
  341:         $r->print('<td bgcolor='.$defbgtwo.' align="center">'
  342:                   .$$part{$which}.'</td>');
  343:     } else {    
  344:         $parm=~s|\[.*\]\s||g;
  345:     }
  346: 
  347:     $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
  348:    
  349:     my $thismarker=$which;
  350:     $thismarker=~s/^parameter\_//;
  351:     my $mprefix=$rid.'&'.$thismarker.'&';
  352: 
  353:     if ($parmlev eq 'general') {
  354: 
  355:         if ($uname) {
  356:             &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  357:         } elsif ($csec) {
  358:             &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display); 
  359:         } else {
  360:             &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display); 
  361:         }
  362:     } elsif ($parmlev eq 'map') {
  363: 
  364:         if ($uname) {
  365:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  366:         } elsif ($csec) {
  367:             &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display);
  368:         } else {
  369:             &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  370:         }
  371:     } else {
  372: 
  373:         &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,$type,$display);
  374: 
  375:         if ($parmlev eq 'brief') {
  376: 
  377:            &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  378: 
  379:            if ($csec) {
  380:                &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display);
  381:            }
  382:            if ($uname) {
  383:                &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  384:            }
  385:         } else {
  386: 
  387:            &print_td($r,10,'#FFDDDD',$result,\@outpar,$mprefix,$_,$type,$display);
  388:            &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  389:            &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  390:            &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  391: 
  392:            if ($csec) {
  393:                &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display);
  394:                &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display);
  395:                &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,$type,$display);
  396:            }
  397:            if ($uname) {
  398:                &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  399:                &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  400:                &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,$type,$display);
  401:            }
  402:         } # end of $brief if/else
  403:     } # end of $parmlev if/else
  404: 
  405:     if ($parmlev eq 'full' || $parmlev eq 'brief') {
  406:         $r->print('<td bgcolor=#CCCCFF align="center">'.
  407:                   &valout($outpar[$result],$$type{$which}).'</td>');
  408:     }
  409:     my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
  410:                                         '.'.$$name{$which},$symbp{$rid});
  411:     $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
  412:                   &valout($sessionval,$$type{$which}).'&nbsp;'.
  413:                   '</font></td>');
  414:     $r->print('</tr>');
  415:     $r->print("\n");
  416: }
  417: 
  418: sub print_td {
  419:     my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$type,$display)=@_;
  420:     $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
  421:               ' align="center">'.
  422:               &plink($$type{$value},$$display{$value},$$outpar[$which],
  423:                      $mprefix."$which",'parmform.pres','psub').'</td>'."\n");
  424: }
  425: 
  426: sub get_env_multiple {
  427:     my ($name) = @_;
  428:     my @values;
  429:     if (defined($ENV{$name})) {
  430:         # exists is it an array
  431:         if (ref($ENV{$name})) {
  432:             @values=@{ $ENV{$name} };
  433:         } else {
  434:             $values[0]=$ENV{$name};
  435:         }
  436:     }
  437:     return(@values);
  438: }
  439: 
  440: ##################################################
  441: ##################################################
  442: 
  443: =pod
  444: 
  445: =item assessparms
  446: 
  447: Show assessment data and parameters.  This is a large routine that should
  448: be simplified and shortened... someday.
  449: 
  450: Inputs: $r
  451: 
  452: Returns: nothing
  453: 
  454: =cut
  455: 
  456: ##################################################
  457: ##################################################
  458: sub assessparms {
  459: 
  460:     my $r=shift;
  461: # -------------------------------------------------------- Variable declaration
  462:     my %allkeys;
  463:     my %allmaps;
  464:     my %alllevs;
  465: 
  466:     $alllevs{'Resource Level'}='full';
  467: #    $alllevs{'Resource Level [BRIEF]'}='brief';
  468:     $alllevs{'Map Level'}='map';
  469:     $alllevs{'Course Level'}='general';
  470: 
  471:     my %allparms;
  472:     my %allparts;
  473: 
  474:     my %defp;
  475:     %courseopt=();
  476:     %useropt=();
  477:     my %bighash=();
  478: 
  479:     @ids=();
  480:     %symbp=();
  481:     %typep=();
  482: 
  483:     my $message='';
  484: 
  485:     $csec=$ENV{'form.csec'};
  486:     $udom=$ENV{'form.udom'};
  487:     unless ($udom) { $udom=$r->dir_config('lonDefDomain'); }
  488: 
  489:     my @pscat=&get_env_multiple('form.pscat');
  490:     my $pschp=$ENV{'form.pschp'};
  491:     my @psprt=&get_env_multiple('form.psprt');
  492:     my $showoptions=$ENV{'form.showoptions'};
  493: 
  494:     my $pssymb='';
  495:     my $parmlev='';
  496:     my $prevvisit=$ENV{'form.prevvisit'};
  497: 
  498: #    unless ($parmlev==$ENV{'form.parmlev'}) {
  499: #        $parmlev = 'full';
  500: #    }
  501:  
  502:     unless ($ENV{'form.parmlev'}) {
  503:         $parmlev = 'map';
  504:     } else {
  505:         $parmlev = $ENV{'form.parmlev'};
  506:     }
  507: 
  508: # ----------------------------------------------- Was this started from grades?
  509: 
  510:     if (($ENV{'form.command'} eq 'set') && ($ENV{'form.url'})
  511: 	&& (!$ENV{'form.dis'})) {
  512: 	my $url=$ENV{'form.url'};
  513: 	$url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
  514: 	$pssymb=&Apache::lonnet::symbread($url);
  515: 	@pscat='all';
  516: 	$pschp='';
  517:         $parmlev = 'full';
  518:     } elsif ($ENV{'form.symb'}) {
  519: 	$pssymb=$ENV{'form.symb'};
  520: 	@pscat='all';
  521: 	$pschp='';
  522:         $parmlev = 'full';
  523:     } else {
  524: 	$ENV{'form.url'}='';
  525:     }
  526: 
  527:     my $id=$ENV{'form.id'};
  528:     if (($id) && ($udom)) {
  529: 	$uname=(&Apache::lonnet::idget($udom,$id))[1];
  530: 	if ($uname) {
  531: 	    $id='';
  532: 	} else {
  533: 	    $message=
  534: 		"<font color=red>Unknown ID '$id' at domain '$udom'</font>";
  535: 	}
  536:     } else {
  537: 	$uname=$ENV{'form.uname'};
  538:     }
  539:     unless ($udom) { $uname=''; }
  540:     $uhome='';
  541:     if ($uname) {
  542: 	$uhome=&Apache::lonnet::homeserver($uname,$udom);
  543:         if ($uhome eq 'no_host') {
  544: 	    $message=
  545: 		"<font color=red>Unknown user '$uname' at domain '$udom'</font>";
  546: 	    $uname='';
  547:         } else {
  548: 	    $csec=&Apache::lonnet::usection($udom,$uname,
  549: 					    $ENV{'request.course.id'});
  550: 	    if ($csec eq '-1') {
  551: 		$message="<font color=red>".
  552: 		    "User '$uname' at domain '$udom' not ".
  553:                     "in this course</font>";
  554: 		$uname='';
  555: 		$csec=$ENV{'form.csec'};
  556: 	    } else {
  557: 		my %name=&Apache::lonnet::userenvironment($udom,$uname,
  558: 		      ('firstname','middlename','lastname','generation','id'));
  559: 		$message="\n<p>\nFull Name: ".
  560: 		    $name{'firstname'}.' '.$name{'middlename'}.' '
  561: 			.$name{'lastname'}.' '.$name{'generation'}.
  562: 			    "<br>\nID: ".$name{'id'}.'<p>';
  563: 	    }
  564:         }
  565:     }
  566: 
  567:     unless ($csec) { $csec=''; }
  568: 
  569:     my $fcat=$ENV{'form.fcat'};
  570:     unless ($fcat) { $fcat=''; }
  571: 
  572: # ------------------------------------------------------------------- Tie hashs
  573:     if (!(tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
  574: 	      &GDBM_READER(),0640))) {
  575: 	$r->print("Unable to access course data. (File $ENV{'request.course.fn'}.db not tieable)");
  576: 	return ;
  577:     }
  578:     if (!(tie(%parmhash,'GDBM_File',
  579: 	      $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640))) {
  580: 	$r->print("Unable to access parameter data. (File $ENV{'request.course.fn'}_parms.db not tieable)");
  581: 	return ;
  582:     }
  583: # --------------------------------------------------------- Get all assessments
  584:     foreach (keys %bighash) {
  585: 	if ($_=~/^src\_(\d+)\.(\d+)$/) {
  586: 	    my $mapid=$1;
  587: 	    my $resid=$2;
  588: 	    my $id=$mapid.'.'.$resid;
  589: 	    my $srcf=$bighash{$_};
  590: 	    if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  591: 		$ids[$#ids+1]=$id;
  592: 		$typep{$id}=$1;
  593: 		$keyp{$id}='';
  594: 		foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'keys'))) {
  595: 		  if ($_=~/^parameter\_(.*)/) {
  596:                     my $key=$_;
  597:                     my $allkey=$1;
  598:                     $allkey=~s/\_/\./g;
  599:                     my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
  600:                     my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
  601:                     my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
  602:                     my $parmdis = $display;
  603:                     $parmdis =~ s|(\[Part.*$)||g;
  604:                     my $partkey = $part;
  605:                     $partkey =~ tr|_|.|;
  606:                     $allparms{$name} = $parmdis;
  607:                     $allparts{$part} = "[Part $part]";
  608:                     $allkeys{$allkey}=$display;
  609:                     if ($allkey eq $fcat) {
  610: 		        $defp{$id}= &Apache::lonnet::metadata($srcf,$key);
  611: 		    }
  612: 		    if ($keyp{$id}) {
  613: 		        $keyp{$id}.=','.$key;
  614: 		    } else {
  615: 		        $keyp{$id}=$key;
  616: 		    }
  617: 		  }
  618: 		}
  619: 		$mapp{$id}=
  620: 		    &Apache::lonnet::declutter($bighash{'map_id_'.$mapid});
  621:                 $mapp{$mapid}=$mapp{$id};
  622: 		$allmaps{$mapid}=$mapp{$id};
  623: 		$symbp{$id}=$mapp{$id}.
  624: 			'___'.$resid.'___'.
  625: 			    &Apache::lonnet::declutter($srcf);
  626:                 $symbp{$mapid}=$mapp{$id}.'___(all)';
  627: 	    }
  628: 	}
  629:     }
  630:     $mapp{'0.0'} = '';
  631:     $symbp{'0.0'} = '';
  632: # ---------------------------------------------------------- Anything to store?
  633:     if ($ENV{'form.pres_marker'}) {
  634: 	my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
  635: 	$spnam=~s/\_([^\_]+)$/\.$1/;
  636: # ---------------------------------------------------------- Construct prefixes
  637: 
  638: 	my $symbparm=$symbp{$sresid}.'.'.$spnam;
  639: 	my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
  640: 	
  641: 	my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$spnam;
  642: 	my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  643: 	my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  644: 	
  645: 	my $courselevel=$ENV{'request.course.id'}.'.'.$spnam;
  646: 	my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
  647: 	my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
  648: 	
  649: 	my $storeunder='';
  650: 	if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
  651: 	if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
  652: 	if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
  653: 	if ($snum==6) { $storeunder=$seclevel; }
  654: 	if ($snum==5) { $storeunder=$seclevelm; }
  655: 	if ($snum==4) { $storeunder=$seclevelr; }
  656: 	
  657:         my %storecontent = ($storeunder        => $ENV{'form.pres_value'},
  658:                             $storeunder.'type' => $ENV{'form.pres_type'});
  659: 	my $reply='';
  660: 	if ($snum>3) {
  661: # ---------------------------------------------------------------- Store Course
  662: #
  663: # Expire sheets
  664: 	    &Apache::lonnet::expirespread('','','studentcalc');
  665: 	    if (($snum==7) || ($snum==4)) {
  666: 		&Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
  667: 	    } elsif (($snum==8) || ($snum==5)) {
  668: 		&Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
  669: 	    } else {
  670: 		&Apache::lonnet::expirespread('','','assesscalc');
  671: 	    }
  672: # Store parameter
  673:             $reply=&Apache::lonnet::cput
  674:                 ('resourcedata',\%storecontent,
  675:                  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  676:                  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  677: 	} else {
  678: # ------------------------------------------------------------------ Store User
  679: #
  680: # Expire sheets
  681: 	    &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
  682: 	    if ($snum==1) {
  683: 		&Apache::lonnet::expirespread
  684: 		    ($uname,$udom,'assesscalc',$symbp{$sresid});
  685: 	    } elsif ($snum==2) {
  686: 		&Apache::lonnet::expirespread
  687: 		    ($uname,$udom,'assesscalc',$mapp{$sresid});
  688: 	    } else {
  689: 		&Apache::lonnet::expirespread($uname,$udom,'assesscalc');
  690: 	    }
  691: # Store parameter
  692: 	    $reply=&Apache::lonnet::cput
  693:                 ('resourcedata',\%storecontent,$udom,$uname);
  694: 	}
  695: 
  696: 	if ($reply=~/^error\:(.*)/) {
  697: 	    $message.="<font color=red>Write Error: $1</font>";
  698: 	}
  699: # ---------------------------------------------------------------- Done storing
  700:     }
  701: # -------------------------------------------------------------- Get coursedata
  702:     %courseopt = &Apache::lonnet::dump
  703:         ('resourcedata',
  704:          $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  705:          $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  706: # --------------------------------------------------- Get userdata (if present)
  707:     if ($uname) {
  708:         %useropt=&Apache::lonnet::dump('resourcedata',$udom,$uname);
  709:     }
  710: 
  711: # ------------------------------------------------------------------- Sort this
  712: 
  713:     @ids=sort  {
  714: 	if ($fcat eq '') {
  715: 	    $a<=>$b;
  716: 	} else {
  717: 	    my ($result,@outpar)=&parmval($fcat,$a,$defp{$a});
  718: 	    my $aparm=$outpar[$result];
  719: 	    ($result,@outpar)=&parmval($fcat,$b,$defp{$b});
  720: 	    my $bparm=$outpar[$result];
  721: 	    1*$aparm<=>1*$bparm;
  722: 	}
  723:     } @ids;
  724: #----------------------------------------------- if all selected, fill in array
  725:     if ($pscat[0] eq "all" || !@pscat) {@pscat = (keys %allparms);}
  726:     if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
  727: # ------------------------------------------------------------------ Start page
  728:     &startpage($r,$id,$udom,$csec,$uname);
  729: #    if ($ENV{'form.url'}) {
  730: #	$r->print('<input type="hidden" value="'.$ENV{'form.url'}.
  731: #		  '" name="url"><input type="hidden" name="command" value="set">');
  732: #    }
  733:     $r->print('<input type="hidden" value="true" name="prevvisit">');
  734: 
  735:     foreach ('tolerance','date_default','date_start','date_end',
  736: 	     'date_interval','int','float','string') {
  737: 	$r->print('<input type="hidden" value="'.
  738: 		  $ENV{'form.recent_'.$_}.'" name="recent_'.$_.'">');
  739:     }
  740: 
  741:     $r->print('<h2>'.$message.'</h2><table>');
  742:                         
  743:     $r->print('<tr><td><hr /></td></tr>');
  744: 
  745:     my $submitmessage;
  746:     if (($prevvisit) || ($pschp) || ($pssymb)) {
  747:         $submitmessage = "Update Display";
  748:     } else {
  749:         $submitmessage = "Display";
  750:     }
  751:     if (!$pssymb) {
  752:         $r->print('<tr><td>Select Parameter Level</td><td>');
  753:         $r->print('<select name="parmlev">');
  754:         foreach (reverse sort keys %alllevs) {
  755:             $r->print('<option value="'.$alllevs{$_}.'"');
  756:             if ($parmlev eq $alllevs{$_}) {
  757:                $r->print(' selected'); 
  758:             }
  759:             $r->print('>'.$_.'</option>');
  760:         }
  761:         $r->print("</select></td>\n");
  762:     
  763:         $r->print('<td><input type="submit" name="dis" value="'.$submitmessage.'"></td>');
  764: 
  765:         $r->print('</tr><tr><td><hr /></td>');
  766: 
  767:         $r->print('<tr><td>Select Enclosing Map</td>');
  768:         $r->print('<td colspan="2"><select name="pschp">');
  769:         $r->print('<option value="all">All Maps</option>');
  770:         foreach (sort {$allmaps{$a} cmp $allmaps{$b}} keys %allmaps) {
  771:             $r->print('<option value="'.$_.'"');
  772:             if (($pschp eq $_)) { $r->print(' selected'); }
  773:             $r->print('>/res/'.$allmaps{$_}.'</option>');
  774:         }
  775:         $r->print("</select></td></tr>\n");
  776:     } else {
  777:         my ($map,$id,$resource)=split(/___/,$pssymb);
  778:         $r->print("<tr><td>Specific Resource</td><td>$resource</td>");
  779:         $r->print('<td><input type="submit" name="dis" value="'.$submitmessage.'"></td>');
  780:         $r->print('</tr>');
  781:         $r->print('<input type="hidden" value="'.$pssymb.'" name="symb">');
  782:     }
  783: 
  784:     $r->print('<tr><td colspan="3"><hr /><input type="checkbox"');
  785:     if ($showoptions eq 'show') {$r->print(" checked ");}
  786:     $r->print(' name="showoptions" value="show" onclick="form.submit();">Show More Options<hr /></td></tr>');
  787: #    $r->print("<tr><td>Show: $showoptions</td></tr>");
  788: #    $r->print("<tr><td>pscat: @pscat</td></tr>");
  789: #    $r->print("<tr><td>psprt: @psprt</td></tr>");
  790: #    $r->print("<tr><td>fcat:  $fcat</td></tr>");
  791: 
  792:     if ($showoptions eq 'show') {
  793:         my $tempkey;
  794: 
  795:         $r->print('<tr><td colspan="3" align="center">Select Parameters to View</td></tr>');
  796: 
  797:         $r->print('<tr><td colspan="2"><table>');
  798:         $r->print('<tr><td><input type="checkbox" name="pscat" value="all"');
  799:         $r->print(' checked') unless (@pscat);
  800:         $r->print('>All Parameters</td>');
  801: 
  802:         my $cnt=0;
  803: 
  804:         foreach $tempkey (sort { $allparms{$a} cmp $allparms{$b} }
  805:                       keys %allparms ) {
  806:             ++$cnt;
  807:             $r->print('</tr><tr>') unless ($cnt%2);
  808:             $r->print('<td><input type="checkbox" name="pscat" ');
  809:             $r->print('value="'.$tempkey.'"');
  810:             if ($pscat[0] eq "all" || grep $_ eq $tempkey, @pscat) {
  811:                 $r->print(' checked');
  812:             }
  813:             $r->print('>'.$allparms{$tempkey}.'</td>');
  814:         }
  815:         $r->print('</tr></table>');
  816: 
  817: #        $r->print('<tr><td>Select Parts</td><td>');
  818:         $r->print('<td><select multiple name="psprt" size="5">');
  819:         $r->print('<option value="all"');
  820:         $r->print(' selected') unless (@psprt);
  821:         $r->print('>All Parts</option>');
  822:         foreach $tempkey (sort keys %allparts) {
  823:             unless ($tempkey =~ /\./) {
  824:                 $r->print('<option value="'.$tempkey.'"');
  825:                 if ($psprt[0] eq "all" ||  grep $_ == $tempkey, @psprt) {
  826:                     $r->print(' selected');
  827:                 }
  828:                 $r->print('>'.$allparts{$tempkey}.'</option>');
  829:             }
  830:         }
  831:         $r->print('</select></td></tr><tr><td colspan="3"><hr /></td></tr>');
  832: 
  833:         $r->print('<tr><td>Sort list by</td><td>');
  834:         $r->print('<select name="fcat">');
  835:         $r->print('<option value="">Enclosing Map</option>');
  836:         foreach (sort keys %allkeys) {
  837:             $r->print('<option value="'.$_.'"');
  838:             if ($fcat eq $_) { $r->print(' selected'); }
  839:             $r->print('>'.$allkeys{$_}.'</option>');
  840:         }
  841:         $r->print('</select></td>');
  842: 
  843:         $r->print('</tr><tr><td colspan="3"><hr /></td></tr>');
  844: 
  845:     } else { # hide options - include any necessary extras here
  846: 
  847:         $r->print('<input type="hidden" name="fcat" value="'.$fcat.'">'."\n");
  848: 
  849:         unless (@pscat) {
  850:           foreach (keys %allparms ) {
  851:             $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
  852:           }
  853:         } else {
  854:           foreach (@pscat) {
  855:             $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
  856:           }
  857:         }
  858: 
  859:         unless (@psprt) {
  860:           foreach (keys %allparts ) {
  861:             $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
  862:           }
  863:         } else {
  864:           foreach (@psprt) {
  865:             $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
  866:           }
  867:         }
  868: 
  869:     }
  870:     $r->print('</table>');
  871: 
  872:     my @temp_psprt;
  873:     foreach my $t (@psprt) {
  874: 	push(@temp_psprt, grep {eval (/^$t\./ || ($_ == $t))} (keys %allparts));
  875:     }
  876: 
  877:     @psprt = @temp_psprt;
  878: 
  879:     my @temp_pscat;
  880:     map {
  881:         my $cat = $_;
  882:         push(@temp_pscat, map { $_.'.'.$cat } @psprt);
  883:     } @pscat;
  884: 
  885:     @pscat = @temp_pscat;
  886: 
  887:     if (($prevvisit) || ($pschp) || ($pssymb)) {
  888: # ----------------------------------------------------------------- Start Table
  889:         my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
  890:         my $csuname=$ENV{'user.name'};
  891:         my $csudom=$ENV{'user.domain'};
  892: 
  893: 
  894:         if ($parmlev eq 'full' || $parmlev eq 'brief') {
  895: 
  896:            my $coursespan=$csec?8:5;
  897:            $r->print('<p><table border=2>');
  898:            $r->print('<tr><td colspan=5></td>');
  899:            $r->print('<th colspan='.($coursespan).'>Any User</th>');
  900:            if ($uname) {
  901:                $r->print("<th colspan=3 rowspan=2>");
  902:                $r->print("User $uname at Domain $udom</th>");
  903:            }
  904:            $r->print(<<ENDTABLETWO);
  905: <th rowspan=3>Parameter in Effect</th>
  906: <th rowspan=3>Current Session Value<br>($csuname at $csudom)</th>
  907: </tr><tr><td colspan=5></td><th colspan=2>Resource Level</th>
  908: <th colspan=3>in Course</th>
  909: ENDTABLETWO
  910:            if ($csec) {
  911:                 $r->print("<th colspan=3>in Section/Group $csec</th>");
  912:            }
  913:            $r->print(<<ENDTABLEHEADFOUR);
  914: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
  915: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
  916: <th>default</th><th>from Enclosing Map</th>
  917: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
  918: ENDTABLEHEADFOUR
  919: 
  920:            if ($csec) {
  921:                $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
  922:            }
  923: 
  924:            if ($uname) {
  925:                $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
  926:            }
  927: 
  928:            $r->print('</tr>');
  929: 
  930:            my $defbgone='';
  931:            my $defbgtwo='';
  932: 
  933:            foreach (@ids) {
  934: 
  935:                 my $rid=$_;
  936:                 my ($inmapid)=($rid=~/\.(\d+)$/);
  937: 
  938:                 if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
  939:                     ($pssymb eq $symbp{$rid})) {
  940: # ------------------------------------------------------ Entry for one resource
  941:                     if ($defbgone eq '"E0E099"') {
  942:                         $defbgone='"E0E0DD"';
  943:                     } else {
  944:                         $defbgone='"E0E099"';
  945:                     }
  946:                     if ($defbgtwo eq '"FFFF99"') {
  947:                         $defbgtwo='"FFFFDD"';
  948:                     } else {
  949:                         $defbgtwo='"FFFF99"';
  950:                     }
  951:                     my $thistitle='';
  952:                     my %name=   ();
  953:                     undef %name;
  954:                     my %part=   ();
  955:                     my %display=();
  956:                     my %type=   ();
  957:                     my %default=();
  958:                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
  959: 
  960:                     foreach (split(/\,/,$keyp{$rid})) {
  961:                         my $tempkeyp = $_;
  962:                         if (grep $_ eq $tempkeyp, @catmarker) {
  963:                           $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
  964:                           $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
  965:                           $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
  966:                           unless ($display{$_}) { $display{$_}=''; }
  967:                           $display{$_}.=' ('.$name{$_}.')';
  968:                           $default{$_}=&Apache::lonnet::metadata($uri,$_);
  969:                           $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
  970:                           $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
  971:                         }
  972:                     }
  973:                     my $totalparms=scalar keys %name;
  974:                     if ($totalparms>0) {
  975:                         my $firstrow=1;
  976: 
  977:                         $r->print('<tr><td bgcolor='.$defbgone.
  978:                              ' rowspan='.$totalparms.
  979:                              '><tt><font size=-1>'.
  980:                              join(' / ',split(/\//,$uri)).
  981:                              '</font></tt><p><b>'.
  982:                              "<a href=\"javascript:openWindow('/res/".$uri.
  983:                              "', 'metadatafile', '450', '500', 'no', 'yes')\";".
  984:                              " TARGET=_self>$bighash{'title_'.$rid}");
  985: 
  986:                         if ($thistitle) {
  987:                             $r->print(' ('.$thistitle.')');
  988:                         }
  989:                         $r->print('</a></b></td>');
  990:                         $r->print('<td bgcolor='.$defbgtwo.
  991:                                       ' rowspan='.$totalparms.'>'.$typep{$rid}.
  992:                                       '</td>');
  993: 
  994:                         $r->print('<td bgcolor='.$defbgone.
  995:                                       ' rowspan='.$totalparms.
  996:                                       '><tt><font size=-1>');
  997: 
  998:                         $r->print(' / res / ');
  999:                         $r->print(join(' / ', split(/\//,$mapp{$rid})));
 1000: 
 1001:                         $r->print('</font></tt></td>');
 1002: 
 1003:                         foreach (sort keys %name) {
 1004:                             unless ($firstrow) {
 1005:                                 $r->print('<tr>');
 1006:                             } else {
 1007:                                 undef $firstrow;
 1008:                             }
 1009: 
 1010:                             &print_row($r,$_,\%part,\%name,$rid,\%default,
 1011:                                        \%type,\%display,$defbgone,$defbgtwo,
 1012:                                        $parmlev);
 1013:                         }
 1014:                     }
 1015:                 }
 1016:             } # end foreach ids
 1017: # -------------------------------------------------- End entry for one resource
 1018:             $r->print('</table>');
 1019:         } # end of  brief/full
 1020: #--------------------------------------------------- Entry for parm level map
 1021:         if ($parmlev eq 'map') {
 1022:             my $defbgone = '"E0E099"';
 1023:             my $defbgtwo = '"FFFF99"';
 1024: 
 1025:             my %maplist;
 1026: 
 1027:             if ($pschp eq 'all') {
 1028:                 %maplist = %allmaps; 
 1029:             } else {
 1030:                 %maplist = ($pschp => $mapp{$pschp});
 1031:             }
 1032: 
 1033: #-------------------------------------------- for each map, gather information
 1034:             my $mapid;
 1035: 	    foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
 1036:                 my $maptitle = $maplist{$mapid};
 1037: 
 1038: #-----------------------  loop through ids and get all parameter types for map
 1039: #-----------------------------------------          and associated information
 1040:                 my %name = ();
 1041:                 my %part = ();
 1042:                 my %display = ();
 1043:                 my %type = ();
 1044:                 my %default = ();
 1045:                 my $map = 0;
 1046: 
 1047: #		$r->print("Catmarker: @catmarker<br />\n");
 1048:                
 1049:                 foreach (@ids) {
 1050:                   ($map)=(/([\d]*?)\./);
 1051:                   my $rid = $_;
 1052:         
 1053: #                  $r->print("$mapid:$map:   $rid <br /> \n");
 1054: 
 1055:                   if ($map eq $mapid) {
 1056:                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1057: #                    $r->print("Keys: $keyp{$rid} <br />\n");
 1058: 
 1059: #--------------------------------------------------------------------
 1060: # @catmarker contains list of all possible parameters including part #s
 1061: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1062: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1063: # When storing information, store as part 0
 1064: # When requesting information, request from full part
 1065: #-------------------------------------------------------------------
 1066:                     foreach (split(/\,/,$keyp{$rid})) {
 1067:                       my $tempkeyp = $_;
 1068:                       my $fullkeyp = $tempkeyp;
 1069:                       $tempkeyp =~ s/_[\d_]+_/_0_/;
 1070:                       
 1071:                       if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1072:                         $part{$tempkeyp}="0";
 1073:                         $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1074:                         $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1075:                         unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1076:                         $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1077:                         $display{$tempkeyp} =~ s/_[\d_]+_/_0_/;
 1078:                         $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1079:                         $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1080:                       }
 1081:                     } # end loop through keys
 1082:                   }
 1083:                 } # end loop through ids
 1084:                                  
 1085: #---------------------------------------------------- print header information
 1086:                 $r->print(<<ENDMAPONE);
 1087: <center><h4>
 1088: <font color="red">Set Defaults for All Resources in map
 1089: <i>$maptitle</i><br />
 1090: Specifically for
 1091: ENDMAPONE
 1092:                 if ($uname) {
 1093:                     my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1094:                       ('firstname','middlename','lastname','generation', 'id'));
 1095:                     my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1096:                            .$name{'lastname'}.' '.$name{'generation'};
 1097:                     $r->print("User <i>$uname \($person\) </i> in \n");
 1098:                 } else {
 1099:                     $r->print("<i>all</i> users in \n");
 1100:                 }
 1101:             
 1102:                 if ($csec) {$r->print("Section <i>$csec</i> of \n")};
 1103: 
 1104:                 $r->print("<i>$coursename</i><br />");
 1105:                 $r->print("</font></h4>\n");
 1106: #---------------------------------------------------------------- print table
 1107:                 $r->print('<p><table border="2">');
 1108:                 $r->print('<tr><th>Parameter Name</th>');
 1109:                 $r->print('<th>Default Value</th>');
 1110:                 $r->print('<th>Parameter in Effect</th></tr>');
 1111: 
 1112: 	        foreach (sort keys %name) {
 1113:                     &print_row($r,$_,\%part,\%name,$mapid,\%default,
 1114:                            \%type,\%display,$defbgone,$defbgtwo,
 1115:                            $parmlev);
 1116: #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
 1117:                 }
 1118:                 $r->print("</table></center>");
 1119:             } # end each map
 1120:         } # end of $parmlev eq map
 1121: #--------------------------------- Entry for parm level general (Course level)
 1122:         if ($parmlev eq 'general') {
 1123:             my $defbgone = '"E0E099"';
 1124:             my $defbgtwo = '"FFFF99"';
 1125: 
 1126: #-------------------------------------------- for each map, gather information
 1127:             my $mapid="0.0";
 1128: #-----------------------  loop through ids and get all parameter types for map
 1129: #-----------------------------------------          and associated information
 1130:             my %name = ();
 1131:             my %part = ();
 1132:             my %display = ();
 1133:             my %type = ();
 1134:             my %default = ();
 1135:                
 1136:             foreach (@ids) {
 1137:                 my $rid = $_;
 1138:         
 1139:                 my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1140: 
 1141: #--------------------------------------------------------------------
 1142: # @catmarker contains list of all possible parameters including part #s
 1143: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1144: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1145: # When storing information, store as part 0
 1146: # When requesting information, request from full part
 1147: #-------------------------------------------------------------------
 1148:                 foreach (split(/\,/,$keyp{$rid})) {
 1149:                   my $tempkeyp = $_;
 1150:                   my $fullkeyp = $tempkeyp;
 1151:                   $tempkeyp =~ s/_[\d_]+_/_0_/;
 1152:                   if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1153:                     $part{$tempkeyp}="0";
 1154:                     $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1155:                     $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1156:                     unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1157:                     $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1158:                     $display{$tempkeyp} =~ s/_[\d_]+_/_0_/;
 1159:                     $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1160:                     $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1161:                   }
 1162:                 } # end loop through keys
 1163:             } # end loop through ids
 1164:                                  
 1165: #---------------------------------------------------- print header information
 1166:             $r->print(<<ENDMAPONE);
 1167: <center><h4>
 1168: <font color="red">Set Defaults for All Resources in Course
 1169: <i>$coursename</i><br />
 1170: ENDMAPONE
 1171:             if ($uname) {
 1172:                 my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1173:                   ('firstname','middlename','lastname','generation', 'id'));
 1174:                 my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1175:                        .$name{'lastname'}.' '.$name{'generation'};
 1176:                 $r->print(" User <i>$uname \($person\) </i> \n");
 1177:             } else {
 1178:                 $r->print("<i>ALL</i> USERS \n");
 1179:             }
 1180:             
 1181:             if ($csec) {$r->print("Section <i>$csec</i>\n")};
 1182:             $r->print("</font></h4>\n");
 1183: #---------------------------------------------------------------- print table
 1184:             $r->print('<p><table border="2">');
 1185:             $r->print('<tr><th>Parameter Name</th>');
 1186:             $r->print('<th>Default Value</th>');
 1187:             $r->print('<th>Parameter in Effect</th></tr>');
 1188: 
 1189: 	    foreach (sort keys %name) {
 1190:                 &print_row($r,$_,\%part,\%name,$mapid,\%default,
 1191:                        \%type,\%display,$defbgone,$defbgtwo,$parmlev);
 1192: #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
 1193:             }
 1194:             $r->print("</table></center>");
 1195:         } # end of $parmlev eq general
 1196:     }
 1197:     $r->print('</form></body></html>');
 1198:     untie(%bighash);
 1199:     untie(%parmhash);
 1200: } # end sub assessparms
 1201: 
 1202: 
 1203: ##################################################
 1204: ##################################################
 1205: 
 1206: =pod
 1207: 
 1208: =item crsenv
 1209: 
 1210: Show course data and parameters.  This is a large routine that should
 1211: be simplified and shortened... someday.
 1212: 
 1213: Inputs: $r
 1214: 
 1215: Returns: nothing
 1216: 
 1217: =cut
 1218: 
 1219: ##################################################
 1220: ##################################################
 1221: sub crsenv {
 1222:     my $r=shift;
 1223:     my $setoutput='';
 1224:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
 1225:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
 1226: # -------------------------------------------------- Go through list of changes
 1227:     foreach (keys %ENV) {
 1228: 	if ($_=~/^form\.(.+)\_setparmval$/) {
 1229:             my $name=$1;
 1230:             my $value=$ENV{'form.'.$name.'_value'};
 1231:             if ($name eq 'newp') {
 1232:                 $name=$ENV{'form.newp_name'};
 1233:             }
 1234:             if ($name eq 'url') {
 1235: 		$value=~s/^\/res\///;
 1236:                 my @tmp = &Apache::lonnet::get
 1237:                     ('environment',['url'],$dom,$crs);
 1238:                 $setoutput.='Backing up previous URL: '.
 1239:                     &Apache::lonnet::put
 1240:                         ('environment',
 1241:                          {'top level map backup ' => $tmp[1] },
 1242:                          $dom,$crs).
 1243:                     '<br>';
 1244:             }
 1245:             if ($name) {
 1246:                 $setoutput.='Setting <tt>'.$name.'</tt> to <tt>'.
 1247:                     $value.'</tt>: '.
 1248:                     &Apache::lonnet::put
 1249:                             ('environment',{$name=>$value},$dom,$crs).
 1250:                     '<br>';
 1251: 	    }
 1252:         }
 1253:     }
 1254: # -------------------------------------------------------- Get parameters again
 1255: 
 1256:     my %values=&Apache::lonnet::dump('environment',$dom,$crs);
 1257:     my $output='';
 1258:     if (! exists($values{'con_lost'})) {
 1259:         my %descriptions=
 1260: 	    ('url'            => '<b>Top Level Map</b> '.
 1261:                                  '<a href="javascript:openbrowser'.
 1262:                                  "('envform','url','sequence')\">".
 1263:                                  'Browse</a><br><font color=red> '.
 1264:                                  'Modification may make assessment data '.
 1265:                                  'inaccessible</font>',
 1266:              'description'    => '<b>Course Description</b>',
 1267:              'courseid'       => '<b>Course ID or number</b><br>'.
 1268:                                  '(internal, optional)',
 1269:              'default_xml_style' => '<b>Default XML Style File</b> '.
 1270:                     '<a href="javascript:openbrowser'.
 1271:                     "('envform','default_xml_style'".
 1272:                     ",'sty')\">Browse</a><br>",
 1273:              'question.email' => '<b>Feedback Addresses for Content '.
 1274:                                  'Questions</b><br>(<tt>user:domain,'.
 1275:                                  'user:domain,...</tt>)',
 1276:              'comment.email'  => '<b>Feedback Addresses for Comments</b><br>'.
 1277:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1278:              'policy.email'   => '<b>Feedback Addresses for Course Policy</b>'.
 1279:                                  '<br>(<tt>user:domain,user:domain,...</tt>)',
 1280:              'hideemptyrows'  => '<b>Hide Empty Rows in Spreadsheets</b><br>'.
 1281:                                  '("<tt>yes</tt>" for default hiding)',
 1282:              'pageseparators'  => '<b>Visibly Separate Items on Pages</b><br>'.
 1283:                                  '("<tt>yes</tt>" for visible separation)',
 1284:              'pch.roles.denied'=> '<b>Disallow Resource Discussion for '.
 1285:                                   'Roles</b><br>"<tt>st</tt>": '.
 1286:                                   'student, "<tt>ta</tt>": '.
 1287:                                   'TA, "<tt>in</tt>": '.
 1288:                                   'instructor;<br><tt>role,role,...</tt>) '.
 1289: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
 1290:              'pch.users.denied' => 
 1291:                           '<b>Disallow Resource Discussion for Users</b><br>'.
 1292:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1293:              'spreadsheet_default_classcalc' 
 1294:                  => '<b>Default Course Spreadsheet</b> '.
 1295:                     '<a href="javascript:openbrowser'.
 1296:                     "('envform','spreadsheet_default_classcalc'".
 1297:                     ",'spreadsheet')\">Browse</a><br>",
 1298:              'spreadsheet_default_studentcalc' 
 1299:                  => '<b>Default Student Spreadsheet</b> '.
 1300:                     '<a href="javascript:openbrowser'.
 1301:                     "('envform','spreadsheet_default_calc'".
 1302:                     ",'spreadsheet')\">Browse</a><br>",
 1303:              'spreadsheet_default_assesscalc' 
 1304:                  => '<b>Default Assessment Spreadsheet</b> '.
 1305:                     '<a href="javascript:openbrowser'.
 1306:                     "('envform','spreadsheet_default_assesscalc'".
 1307:                     ",'spreadsheet')\">Browse</a><br>",
 1308:              );
 1309: 	foreach (keys(%values)) {
 1310: 	    unless ($descriptions{$_}) {
 1311: 		$descriptions{$_}=$_;
 1312: 	    }
 1313: 	}
 1314: 	foreach (sort keys %descriptions) {
 1315:             # onchange is javascript to automatically check the 'Set' button.
 1316:             my $onchange = 'onchange="javascript:window.document.forms'.
 1317:                 '[\'envform\'].elements[\''.$_.'_setparmval\']'.
 1318:                 '.checked=true;"';
 1319: 	    $output.='<tr><td>'.$descriptions{$_}.'</td>'.
 1320:                 '<td><input name="'.$_.'_value" size=40 '.
 1321:                 'value="'.$values{$_}.'" '.$onchange.' /></td>'.
 1322:                 '<td><input type=checkbox name="'.$_.'_setparmval"></td>'.
 1323:                 '</tr>'."\n";
 1324: 	}
 1325:         my $onchange = 'onchange="javascript:window.document.forms'.
 1326:             '[\'envform\'].elements[\'newp_setparmval\']'.
 1327:             '.checked=true;"';
 1328: 	$output.='<tr><td><i>Create New Environment Variable</i><br />'.
 1329: 	    '<input type="text" size=40 name="newp_name" '.
 1330:                 $onchange.' /></td><td>'.
 1331:             '<input type="text" size=40 name="newp_value" '.
 1332:                 $onchange.' /></td><td>'.
 1333: 	    '<input type="checkbox" name="newp_setparmval" /></td></tr>';
 1334:     }
 1335:     $r->print(<<ENDENV);
 1336: <html>
 1337: <script type="text/javascript" language="Javascript" >
 1338:     var editbrowser;
 1339:     function openbrowser(formname,elementname,only,omit) {
 1340:         var url = '/res/?';
 1341:         if (editbrowser == null) {
 1342:             url += 'launch=1&';
 1343:         }
 1344:         url += 'catalogmode=interactive&';
 1345:         url += 'mode=parmset&';
 1346:         url += 'form=' + formname + '&';
 1347:         if (only != null) {
 1348:             url += 'only=' + only + '&';
 1349:         } 
 1350:         if (omit != null) {
 1351:             url += 'omit=' + omit + '&';
 1352:         }
 1353:         url += 'element=' + elementname + '';
 1354:         var title = 'Browser';
 1355:         var options = 'scrollbars=1,resizable=1,menubar=0';
 1356:         options += ',width=700,height=600';
 1357:         editbrowser = open(url,title,options,'1');
 1358:         editbrowser.focus();
 1359:     }
 1360: </script>
 1361: <head>
 1362: <title>LON-CAPA Course Environment</title>
 1363: </head>
 1364: <body bgcolor="#FFFFFF">
 1365: <h1>Set Course Parameters</h1>
 1366: <form method="post" action="/adm/parmset" name="envform">
 1367: <h2>Course: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}</h2>
 1368: <h3>Course Environment</h3>
 1369: $setoutput
 1370: <p>
 1371: <table border=2>
 1372: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
 1373: $output
 1374: </table>
 1375: <input type="submit" name="crsenv" value="Set Course Environment">
 1376: </form>
 1377: </body>
 1378: </html>    
 1379: ENDENV
 1380: }
 1381: 
 1382: ##################################################
 1383: ##################################################
 1384: 
 1385: =pod
 1386: 
 1387: =item handler
 1388: 
 1389: Main handler.  Calls &assessparms and &crsenv subroutines.
 1390: 
 1391: =cut
 1392: 
 1393: ##################################################
 1394: ##################################################
 1395: sub handler {
 1396:     my $r=shift;
 1397: 
 1398:     if ($r->header_only) {
 1399: 	$r->content_type('text/html');
 1400: 	$r->send_http_header;
 1401: 	return OK;
 1402:     }
 1403:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
 1404: # ----------------------------------------------------- Needs to be in a course
 1405: 
 1406:     if (($ENV{'request.course.id'}) && 
 1407: 	(&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
 1408:  
 1409:         $coursename=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
 1410: 
 1411: 	unless (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) {
 1412: # --------------------------------------------------------- Bring up assessment
 1413: 	    &assessparms($r);
 1414: # ---------------------------------------------- This is for course environment
 1415: 	} else {
 1416: 	    &crsenv($r);
 1417: 	}
 1418:     } else {
 1419: # ----------------------------- Not in a course, or not allowed to modify parms
 1420: 	$ENV{'user.error.msg'}=
 1421: 	    "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
 1422: 	return HTTP_NOT_ACCEPTABLE;
 1423:     }
 1424:     return OK;
 1425: }
 1426: 
 1427: 1;
 1428: __END__
 1429: 
 1430: =pod
 1431: 
 1432: =back
 1433: 
 1434: =cut
 1435: 
 1436: 
 1437: 

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