File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.59: download - view: text, annotated - select for diffs
Mon Aug 12 18:54:16 2002 UTC (21 years, 10 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
(failed) attempt to address bug 166.  Added the usual POD nonsense.
More to come.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set parameters for assessments
    3: #
    4: # $Id: lonparmset.pm,v 1.59 2002/08/12 18:54:16 matthew 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:     map {
  874:          my $t = $_;
  875:          push(@temp_psprt,
  876:          grep {eval (/^$t\./ || ($_ == $t))} (keys %allparts));
  877:     } @psprt;
  878: 
  879:     @psprt = @temp_psprt;
  880: 
  881:     my @temp_pscat;
  882:     map {
  883:         my $cat = $_;
  884:         push(@temp_pscat, map { $_.'.'.$cat } @psprt);
  885:     } @pscat;
  886: 
  887:     @pscat = @temp_pscat;
  888: 
  889:     if (($prevvisit) || ($pschp) || ($pssymb)) {
  890: # ----------------------------------------------------------------- Start Table
  891:         my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
  892:         my $csuname=$ENV{'user.name'};
  893:         my $csudom=$ENV{'user.domain'};
  894: 
  895: 
  896:         if ($parmlev eq 'full' || $parmlev eq 'brief') {
  897: 
  898:            my $coursespan=$csec?8:5;
  899:            $r->print('<p><table border=2>');
  900:            $r->print('<tr><td colspan=5></td>');
  901:            $r->print('<th colspan='.($coursespan).'>Any User</th>');
  902:            if ($uname) {
  903:                $r->print("<th colspan=3 rowspan=2>");
  904:                $r->print("User $uname at Domain $udom</th>");
  905:            }
  906:            $r->print(<<ENDTABLETWO);
  907: <th rowspan=3>Parameter in Effect</th>
  908: <th rowspan=3>Current Session Value<br>($csuname at $csudom)</th>
  909: </tr><tr><td colspan=5></td><th colspan=2>Resource Level</th>
  910: <th colspan=3>in Course</th>
  911: ENDTABLETWO
  912:            if ($csec) {
  913:                 $r->print("<th colspan=3>in Section/Group $csec</th>");
  914:            }
  915:            $r->print(<<ENDTABLEHEADFOUR);
  916: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
  917: <th>Enclosing Map</th><th>Part No.</th><th>Parameter Name</th>
  918: <th>default</th><th>from Enclosing Map</th>
  919: <th>general</th><th>for Enclosing Map</th><th>for Resource</th>
  920: ENDTABLEHEADFOUR
  921: 
  922:            if ($csec) {
  923:                $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
  924:            }
  925: 
  926:            if ($uname) {
  927:                $r->print('<th>general</th><th>for Enclosing Map</th><th>for Resource</th>');
  928:            }
  929: 
  930:            $r->print('</tr>');
  931: 
  932:            my $defbgone='';
  933:            my $defbgtwo='';
  934: 
  935:            foreach (@ids) {
  936: 
  937:                 my $rid=$_;
  938:                 my ($inmapid)=($rid=~/\.(\d+)$/);
  939: 
  940:                 if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
  941:                     ($pssymb eq $symbp{$rid})) {
  942: # ------------------------------------------------------ Entry for one resource
  943:                     if ($defbgone eq '"E0E099"') {
  944:                         $defbgone='"E0E0DD"';
  945:                     } else {
  946:                         $defbgone='"E0E099"';
  947:                     }
  948:                     if ($defbgtwo eq '"FFFF99"') {
  949:                         $defbgtwo='"FFFFDD"';
  950:                     } else {
  951:                         $defbgtwo='"FFFF99"';
  952:                     }
  953:                     my $thistitle='';
  954:                     my %name=   ();
  955:                     undef %name;
  956:                     my %part=   ();
  957:                     my %display=();
  958:                     my %type=   ();
  959:                     my %default=();
  960:                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
  961: 
  962:                     foreach (split(/\,/,$keyp{$rid})) {
  963:                         my $tempkeyp = $_;
  964:                         if (grep $_ eq $tempkeyp, @catmarker) {
  965:                           $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
  966:                           $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
  967:                           $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
  968:                           unless ($display{$_}) { $display{$_}=''; }
  969:                           $display{$_}.=' ('.$name{$_}.')';
  970:                           $default{$_}=&Apache::lonnet::metadata($uri,$_);
  971:                           $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
  972:                           $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
  973:                         }
  974:                     }
  975:                     my $totalparms=scalar keys %name;
  976:                     if ($totalparms>0) {
  977:                         my $firstrow=1;
  978: 
  979:                         $r->print('<tr><td bgcolor='.$defbgone.
  980:                              ' rowspan='.$totalparms.
  981:                              '><tt><font size=-1>'.
  982:                              join(' / ',split(/\//,$uri)).
  983:                              '</font></tt><p><b>'.
  984:                              "<a href=\"javascript:openWindow('/res/".$uri.
  985:                              "', 'metadatafile', '450', '500', 'no', 'yes')\";".
  986:                              " TARGET=_self>$bighash{'title_'.$rid}");
  987: 
  988:                         if ($thistitle) {
  989:                             $r->print(' ('.$thistitle.')');
  990:                         }
  991:                         $r->print('</a></b></td>');
  992:                         $r->print('<td bgcolor='.$defbgtwo.
  993:                                       ' rowspan='.$totalparms.'>'.$typep{$rid}.
  994:                                       '</td>');
  995: 
  996:                         $r->print('<td bgcolor='.$defbgone.
  997:                                       ' rowspan='.$totalparms.
  998:                                       '><tt><font size=-1>');
  999: 
 1000:                         $r->print(' / res / ');
 1001:                         $r->print(join(' / ', split(/\//,$mapp{$rid})));
 1002: 
 1003:                         $r->print('</font></tt></td>');
 1004: 
 1005:                         foreach (sort keys %name) {
 1006:                             unless ($firstrow) {
 1007:                                 $r->print('<tr>');
 1008:                             } else {
 1009:                                 undef $firstrow;
 1010:                             }
 1011: 
 1012:                             &print_row($r,$_,\%part,\%name,$rid,\%default,
 1013:                                        \%type,\%display,$defbgone,$defbgtwo,
 1014:                                        $parmlev);
 1015:                         }
 1016:                     }
 1017:                 }
 1018:             } # end foreach ids
 1019: # -------------------------------------------------- End entry for one resource
 1020:             $r->print('</table>');
 1021:         } # end of  brief/full
 1022: #--------------------------------------------------- Entry for parm level map
 1023:         if ($parmlev eq 'map') {
 1024:             my $defbgone = '"E0E099"';
 1025:             my $defbgtwo = '"FFFF99"';
 1026: 
 1027:             my %maplist;
 1028: 
 1029:             if ($pschp eq 'all') {
 1030:                 %maplist = %allmaps; 
 1031:             } else {
 1032:                 %maplist = ($pschp => $mapp{$pschp});
 1033:             }
 1034: 
 1035: #-------------------------------------------- for each map, gather information
 1036:             my $mapid;
 1037:             foreach $mapid (keys %maplist) {
 1038:                 my $maptitle = $allmaps{$mapid};
 1039: 
 1040: #-----------------------  loop through ids and get all parameter types for map
 1041: #-----------------------------------------          and associated information
 1042:                 my %name = ();
 1043:                 my %part = ();
 1044:                 my %display = ();
 1045:                 my %type = ();
 1046:                 my %default = ();
 1047:                 my $map = 0;
 1048: 
 1049: #		$r->print("Catmarker: @catmarker<br />\n");
 1050:                
 1051:                 foreach (@ids) {
 1052:                   ($map)=(/([\d]*?)\./);
 1053:                   my $rid = $_;
 1054:         
 1055: #                  $r->print("$mapid:$map:   $rid <br /> \n");
 1056: 
 1057:                   if ($map eq $mapid) {
 1058:                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1059: #                    $r->print("Keys: $keyp{$rid} <br />\n");
 1060: 
 1061: #--------------------------------------------------------------------
 1062: # @catmarker contains list of all possible parameters including part #s
 1063: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1064: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1065: # When storing information, store as part 0
 1066: # When requesting information, request from full part
 1067: #-------------------------------------------------------------------
 1068:                     foreach (split(/\,/,$keyp{$rid})) {
 1069:                       my $tempkeyp = $_;
 1070:                       my $fullkeyp = $tempkeyp;
 1071:                       $tempkeyp =~ s/_[\d_]+_/_0_/;
 1072:                       
 1073:                       if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1074:                         $part{$tempkeyp}="0";
 1075:                         $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1076:                         $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1077:                         unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1078:                         $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1079:                         $display{$tempkeyp} =~ s/_[\d_]+_/_0_/;
 1080:                         $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1081:                         $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1082:                       }
 1083:                     } # end loop through keys
 1084:                   }
 1085:                 } # end loop through ids
 1086:                                  
 1087: #---------------------------------------------------- print header information
 1088:                 $r->print(<<ENDMAPONE);
 1089: <center><h4>
 1090: <font color="red">Set Defaults for All Resources in map
 1091: <i>$maptitle</i><br />
 1092: Specifically for
 1093: ENDMAPONE
 1094:                 if ($uname) {
 1095:                     my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1096:                       ('firstname','middlename','lastname','generation', 'id'));
 1097:                     my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1098:                            .$name{'lastname'}.' '.$name{'generation'};
 1099:                     $r->print("User <i>$uname \($person\) </i> in \n");
 1100:                 } else {
 1101:                     $r->print("<i>all</i> users in \n");
 1102:                 }
 1103:             
 1104:                 if ($csec) {$r->print("Section <i>$csec</i> of \n")};
 1105: 
 1106:                 $r->print("<i>$coursename</i><br />");
 1107:                 $r->print("</font></h4>\n");
 1108: #---------------------------------------------------------------- print table
 1109:                 $r->print('<p><table border="2">');
 1110:                 $r->print('<tr><th>Parameter Name</th>');
 1111:                 $r->print('<th>Default Value</th>');
 1112:                 $r->print('<th>Parameter in Effect</th></tr>');
 1113: 
 1114: 	        foreach (sort keys %name) {
 1115:                     &print_row($r,$_,\%part,\%name,$mapid,\%default,
 1116:                            \%type,\%display,$defbgone,$defbgtwo,
 1117:                            $parmlev);
 1118: #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
 1119:                 }
 1120:                 $r->print("</table></center>");
 1121:             } # end each map
 1122:         } # end of $parmlev eq map
 1123: #--------------------------------- Entry for parm level general (Course level)
 1124:         if ($parmlev eq 'general') {
 1125:             my $defbgone = '"E0E099"';
 1126:             my $defbgtwo = '"FFFF99"';
 1127: 
 1128: #-------------------------------------------- for each map, gather information
 1129:             my $mapid="0.0";
 1130: #-----------------------  loop through ids and get all parameter types for map
 1131: #-----------------------------------------          and associated information
 1132:             my %name = ();
 1133:             my %part = ();
 1134:             my %display = ();
 1135:             my %type = ();
 1136:             my %default = ();
 1137:                
 1138:             foreach (@ids) {
 1139:                 my $rid = $_;
 1140:         
 1141:                 my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1142: 
 1143: #--------------------------------------------------------------------
 1144: # @catmarker contains list of all possible parameters including part #s
 1145: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1146: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1147: # When storing information, store as part 0
 1148: # When requesting information, request from full part
 1149: #-------------------------------------------------------------------
 1150:                 foreach (split(/\,/,$keyp{$rid})) {
 1151:                   my $tempkeyp = $_;
 1152:                   my $fullkeyp = $tempkeyp;
 1153:                   $tempkeyp =~ s/_[\d_]+_/_0_/;
 1154:                   if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1155:                     $part{$tempkeyp}="0";
 1156:                     $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1157:                     $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1158:                     unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1159:                     $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1160:                     $display{$tempkeyp} =~ s/_[\d_]+_/_0_/;
 1161:                     $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1162:                     $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1163:                   }
 1164:                 } # end loop through keys
 1165:             } # end loop through ids
 1166:                                  
 1167: #---------------------------------------------------- print header information
 1168:             $r->print(<<ENDMAPONE);
 1169: <center><h4>
 1170: <font color="red">Set Defaults for All Resources in Course
 1171: <i>$coursename</i><br />
 1172: ENDMAPONE
 1173:             if ($uname) {
 1174:                 my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1175:                   ('firstname','middlename','lastname','generation', 'id'));
 1176:                 my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1177:                        .$name{'lastname'}.' '.$name{'generation'};
 1178:                 $r->print(" User <i>$uname \($person\) </i> \n");
 1179:             } else {
 1180:                 $r->print("<i>ALL</i> USERS \n");
 1181:             }
 1182:             
 1183:             if ($csec) {$r->print("Section <i>$csec</i>\n")};
 1184:             $r->print("</font></h4>\n");
 1185: #---------------------------------------------------------------- print table
 1186:             $r->print('<p><table border="2">');
 1187:             $r->print('<tr><th>Parameter Name</th>');
 1188:             $r->print('<th>Default Value</th>');
 1189:             $r->print('<th>Parameter in Effect</th></tr>');
 1190: 
 1191: 	    foreach (sort keys %name) {
 1192:                 &print_row($r,$_,\%part,\%name,$mapid,\%default,
 1193:                        \%type,\%display,$defbgone,$defbgtwo,$parmlev);
 1194: #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
 1195:             }
 1196:             $r->print("</table></center>");
 1197:         } # end of $parmlev eq general
 1198:     }
 1199:     $r->print('</form></body></html>');
 1200:     untie(%bighash);
 1201:     untie(%parmhash);
 1202: } # end sub assessparms
 1203: 
 1204: 
 1205: ##################################################
 1206: ##################################################
 1207: 
 1208: =pod
 1209: 
 1210: =item crsenv
 1211: 
 1212: Show course data and parameters.  This is a large routine that should
 1213: be simplified and shortened... someday.
 1214: 
 1215: Inputs: $r
 1216: 
 1217: Returns: nothing
 1218: 
 1219: =cut
 1220: 
 1221: ##################################################
 1222: ##################################################
 1223: sub crsenv {
 1224:     my $r=shift;
 1225:     my $setoutput='';
 1226:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
 1227:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
 1228: # -------------------------------------------------- Go through list of changes
 1229:     foreach (keys %ENV) {
 1230: 	if ($_=~/^form\.(.+)\_setparmval$/) {
 1231:             my $name=$1;
 1232:             my $value=$ENV{'form.'.$name.'_value'};
 1233:             if ($name eq 'newp') {
 1234:                 $name=$ENV{'form.newp_name'};
 1235:             }
 1236:             if ($name eq 'url') {
 1237: 		$value=~s/^\/res\///;
 1238:                 my @tmp = &Apache::lonnet::get
 1239:                     ('environment',['url'],$dom,$crs);
 1240:                 $setoutput.='Backing up previous URL: '.
 1241:                     &Apache::lonnet::put
 1242:                         ('environment',
 1243:                          {'top level map backup ' => $tmp[1] },
 1244:                          $dom,$crs).
 1245:                     '<br>';
 1246:             }
 1247:             if ($name) {
 1248:                 $setoutput.='Setting <tt>'.$name.'</tt> to <tt>'.
 1249:                     $value.'</tt>: '.
 1250:                     &Apache::lonnet::put
 1251:                             ('environment',{$name=>$value},$dom,$crs).
 1252:                     '<br>';
 1253: 	    }
 1254:         }
 1255:     }
 1256: # -------------------------------------------------------- Get parameters again
 1257: 
 1258:     my %values=&Apache::lonnet::dump('environment',$dom,$crs);
 1259:     my $output='';
 1260:     if (! exists($values{'con_lost'})) {
 1261:         my %descriptions=
 1262: 	    ('url'            => '<b>Top Level Map</b> '.
 1263:                                  '<a href="javascript:openbrowser'.
 1264:                                  "('envform','url','sequence')\">".
 1265:                                  'Browse</a><br><font color=red> '.
 1266:                                  'Modification may make assessment data '.
 1267:                                  'inaccessible</font>',
 1268:              'description'    => '<b>Course Description</b>',
 1269:              'courseid'       => '<b>Course ID or number</b><br>'.
 1270:                                  '(internal, optional)',
 1271:              'default_xml_style' => '<b>Default XML Style File</b> '.
 1272:                     '<a href="javascript:openbrowser'.
 1273:                     "('envform','default_xml_style'".
 1274:                     ",'sty')\">Browse</a><br>",
 1275:              'question.email' => '<b>Feedback Addresses for Content '.
 1276:                                  'Questions</b><br>(<tt>user:domain,'.
 1277:                                  'user:domain,...</tt>)',
 1278:              'comment.email'  => '<b>Feedback Addresses for Comments</b><br>'.
 1279:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1280:              'policy.email'   => '<b>Feedback Addresses for Course Policy</b>'.
 1281:                                  '<br>(<tt>user:domain,user:domain,...</tt>)',
 1282:              'hideemptyrows'  => '<b>Hide Empty Rows in Spreadsheets</b><br>'.
 1283:                                  '("<tt>yes</tt>" for default hiding)',
 1284:              'pageseparators'  => '<b>Visibly Separate Items on Pages</b><br>'.
 1285:                                  '("<tt>yes</tt>" for visible separation)',
 1286:              'pch.roles.denied'=> '<b>Disallow Resource Discussion for '.
 1287:                                   'Roles</b> ' . 
 1288: 	   Apache::loncommon::help_open_topic("Course_Disable_Discussion")
 1289: 	                          ,
 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>