File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.134: download - view: text, annotated - select for diffs
Mon Nov 10 16:33:57 2003 UTC (20 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- moved get_env_multiple to loncommon

    1: # The LearningOnline Network with CAPA
    2: # Handler to set parameters for assessments
    3: #
    4: # $Id: lonparmset.pm,v 1.134 2003/11/10 16:33:57 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::lonhtmlcommon();
   60: use Apache::loncommon;
   61: use GDBM_File;
   62: use Apache::lonhomework;
   63: use Apache::lonxml;
   64: use Apache::lonlocal;
   65: 
   66: my %courseopt;
   67: my %useropt;
   68: my %parmhash;
   69: 
   70: my @ids;
   71: my %symbp;
   72: my %mapp;
   73: my %typep;
   74: my %keyp;
   75: 
   76: my %maptitles;
   77: 
   78: my $uname;
   79: my $udom;
   80: my $uhome;
   81: my $csec;
   82: my $coursename;
   83: 
   84: ##################################################
   85: ##################################################
   86: 
   87: =pod
   88: 
   89: =item parmval
   90: 
   91: Figure out a cascading parameter.
   92: 
   93: Inputs:  $what - a parameter spec (incluse part info and name I.E. 0.weight)
   94:          $id   - a bighash Id number
   95:          $def  - the resource's default value   'stupid emacs
   96: 
   97: Returns:  A list, the first item is the index into the remaining list of items of parm valuse that is the active one, the list consists of parm values at the 11 possible levels
   98: 
   99: 11- resource default
  100: 10- map default
  101: 9 - General Course
  102: 8 - Map or Folder level in course
  103: 7 - resource level in course
  104: 6 - General for section
  105: 5 - Map or Folder level for section
  106: 4 - resource level in section
  107: 3 - General for specific student
  108: 2 - Map or Folder level for specific student
  109: 1 - resource level for specific student
  110: 
  111: =cut
  112: 
  113: ##################################################
  114: ##################################################
  115: sub parmval {
  116:     my ($what,$id,$def)=@_;
  117:     my $result='';
  118:     my @outpar=();
  119: # ----------------------------------------------------- Cascading lookup scheme
  120: 
  121:     my $symbparm=$symbp{$id}.'.'.$what;
  122:     my $mapparm=$mapp{$id}.'___(all).'.$what;
  123: 
  124:     my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$what;
  125:     my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  126:     my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  127: 
  128:     my $courselevel=$ENV{'request.course.id'}.'.'.$what;
  129:     my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
  130:     my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
  131: 
  132: # -------------------------------------------------------- first, check default
  133: 
  134:     if ($def) { $outpar[11]=$def; $result=11; }
  135: 
  136: # ----------------------------------------------------- second, check map parms
  137: 
  138:     my $thisparm=$parmhash{$symbparm};
  139:     if ($thisparm) { $outpar[10]=$thisparm; $result=10; }
  140: 
  141: # --------------------------------------------------------- third, check course
  142: 
  143:     if (defined($courseopt{$courselevel})) {
  144: 	$outpar[9]=$courseopt{$courselevel};
  145: 	$result=9;
  146:     }
  147: 
  148:     if (defined($courseopt{$courselevelm})) {
  149: 	$outpar[8]=$courseopt{$courselevelm};
  150: 	$result=8;
  151:     }
  152: 
  153:     if (defined($courseopt{$courselevelr})) {
  154: 	$outpar[7]=$courseopt{$courselevelr};
  155: 	$result=7;
  156:     }
  157: 
  158:     if (defined($csec)) {
  159:         if (defined($courseopt{$seclevel})) {
  160: 	    $outpar[6]=$courseopt{$seclevel};
  161: 	    $result=6;
  162: 	}
  163:         if (defined($courseopt{$seclevelm})) {
  164: 	    $outpar[5]=$courseopt{$seclevelm};
  165: 	    $result=5;
  166: 	}
  167: 
  168:         if (defined($courseopt{$seclevelr})) {
  169: 	    $outpar[4]=$courseopt{$seclevelr};
  170: 	    $result=4;
  171: 	}
  172:     }
  173: 
  174: # ---------------------------------------------------------- fourth, check user
  175: 
  176:     if (defined($uname)) {
  177: 	if (defined($useropt{$courselevel})) {
  178: 	    $outpar[3]=$useropt{$courselevel};
  179: 	    $result=3;
  180: 	}
  181: 
  182: 	if (defined($useropt{$courselevelm})) {
  183: 	    $outpar[2]=$useropt{$courselevelm};
  184: 	    $result=2;
  185: 	}
  186: 
  187: 	if (defined($useropt{$courselevelr})) {
  188: 	    $outpar[1]=$useropt{$courselevelr};
  189: 	    $result=1;
  190: 	}
  191:     }
  192:     return ($result,@outpar);
  193: }
  194: 
  195: ##################################################
  196: ##################################################
  197: 
  198: =pod
  199: 
  200: =item valout
  201: 
  202: Format a value for output.
  203: 
  204: Inputs:  $value, $type
  205: 
  206: Returns: $value, formatted for output.  If $type indicates it is a date,
  207: localtime($value) is returned.
  208: 
  209: =cut
  210: 
  211: ##################################################
  212: ##################################################
  213: sub valout {
  214:     my ($value,$type)=@_;
  215:     my $result = '';
  216:     # Values of zero are valid.
  217:     if (! $value && $value ne '0') {
  218: 	$result = '  ';
  219:     } else {
  220:         if ($type eq 'date_interval') {
  221:             my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
  222:             $year=$year-70;
  223:             $mday--;
  224:             if ($year) {
  225: 		$result.=$year.' yrs ';
  226:             }
  227:             if ($mon) {
  228: 		$result.=$mon.' mths ';
  229:             }
  230:             if ($mday) {
  231: 		$result.=$mday.' days ';
  232:             }
  233:             if ($hour) {
  234: 		$result.=$hour.' hrs ';
  235:             }
  236:             if ($min) {
  237: 		$result.=$min.' mins ';
  238:             }
  239:             if ($sec) {
  240: 		$result.=$sec.' secs ';
  241:             }
  242:             $result=~s/\s+$//;
  243:         } elsif ($type=~/^date/) {
  244:             $result = localtime($value);
  245:         } else {
  246:             $result = $value;
  247:         }
  248:     }
  249:     return $result;
  250: }
  251: 
  252: ##################################################
  253: ##################################################
  254: 
  255: =pod
  256: 
  257: =item plink
  258: 
  259: Produces a link anchor.
  260: 
  261: Inputs: $type,$dis,$value,$marker,$return,$call
  262: 
  263: Returns: scalar with html code for a link which will envoke the 
  264: javascript function 'pjump'.
  265: 
  266: =cut
  267: 
  268: ##################################################
  269: ##################################################
  270: sub plink {
  271:     my ($type,$dis,$value,$marker,$return,$call)=@_;
  272:     my $winvalue=$value;
  273:     unless ($winvalue) {
  274: 	if ($type=~/^date/) {
  275:             $winvalue=$ENV{'form.recent_'.$type};
  276:         } else {
  277:             $winvalue=$ENV{'form.recent_'.(split(/\_/,$type))[0]};
  278:         }
  279:     }
  280:     return 
  281: 	'<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
  282: 	    .$marker."','".$return."','".$call."'".');">'.
  283: 		&valout($value,$type).'</a><a name="'.$marker.'"></a>';
  284: }
  285: 
  286: 
  287: sub startpage {
  288:     my ($r,$id,$udom,$csec,$uname,$have_assesments)=@_;
  289: 
  290:     my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','',
  291:                                             'onUnload="pclose()"');
  292:     my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
  293:         &Apache::loncommon::selectstudent_link('parmform','uname','udom');
  294:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
  295:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  296:     my %lt=&Apache::lonlocal::texthash(
  297: 		    'cep'   => "Course Environment Parameters",
  298: 		    'scep'  => "Set Course Environment Parameters",
  299: 		    'smcap' => "Set/Modify Course Assessment Parameter",
  300: 		    'mcap'  => "Modify Course Assessment Parameters",
  301: 		    'caphm' => "Course Assessment Parameter - Helper Mode",
  302: 		    'capom' => "Course Assessment Parameters - Overview Mode",
  303:                     'captm' => "Course Assessments Parameters - Table Mode",
  304: 		    'sg'    => "Section/Group",
  305: 		    'fu'    => "For User",
  306: 		    'oi'    => "or ID",
  307: 		    'ad'    => "at Domain"
  308: 				       );
  309:     $r->print(<<ENDHEAD);
  310: <html>
  311: <head>
  312: <title>LON-CAPA Course Parameters</title>
  313: <script>
  314: 
  315:     function pclose() {
  316:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  317:                  "height=350,width=350,scrollbars=no,menubar=no");
  318:         parmwin.close();
  319:     }
  320: 
  321:     $pjump_def
  322: 
  323:     function psub() {
  324:         pclose();
  325:         if (document.parmform.pres_marker.value!='') {
  326:             document.parmform.action+='#'+document.parmform.pres_marker.value;
  327:             var typedef=new Array();
  328:             typedef=document.parmform.pres_type.value.split('_');
  329:            if (document.parmform.pres_type.value!='') {
  330:             if (typedef[0]=='date') {
  331:                 eval('document.parmform.recent_'+
  332:                      document.parmform.pres_type.value+
  333: 		     '.value=document.parmform.pres_value.value;');
  334:             } else {
  335:                 eval('document.parmform.recent_'+typedef[0]+
  336: 		     '.value=document.parmform.pres_value.value;');
  337:             }
  338: 	   }
  339:             document.parmform.submit();
  340:         } else {
  341:             document.parmform.pres_value.value='';
  342:             document.parmform.pres_marker.value='';
  343:         }
  344:     }
  345: 
  346:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
  347:         var options = "width=" + w + ",height=" + h + ",";
  348:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  349:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
  350:         var newWin = window.open(url, wdwName, options);
  351:         newWin.focus();
  352:     }
  353: </script>
  354: $selscript
  355: </head>
  356: $bodytag
  357: 
  358: <form method="post" action="/adm/parmset" name="envform">
  359: <h4>$lt{'cep'}</h4>
  360: <input type="submit" name="crsenv" value="$lt{'scep'}" />
  361: </form>
  362: <hr />
  363: <form method="post" action="/adm/helper/parameter.helper" name="helpform">
  364: <h4>$lt{'caphm'}</h4>
  365: <input type="submit" value="$lt{'smcap'}" />
  366: </form>
  367: <hr />
  368: <form method="post" action="/adm/parmset" name="overview">
  369: <h4>$lt{'capom'}</h4>
  370: <input type="submit" name="overview" value="$lt{'mcap'}" />
  371: </form>
  372: <hr />
  373: <form method="post" action="/adm/parmset" name="parmform">
  374: <h4>$lt{'captm'}</h4>
  375: ENDHEAD
  376: 
  377:     if (!$have_assesments) {
  378: 	$r->print('<font color="red">'.&mt('There are no assesment parameters in this course to set.').'</font><br />');	
  379:     } else {
  380: 	$r->print(<<ENDHEAD);
  381: <b>
  382: $lt{'sg'}:
  383: <input type="text" value="$csec" size="6" name="csec">
  384: <br>
  385: $lt{'fu'} 
  386: <input type="text" value="$uname" size="12" name="uname">
  387: $lt{'oi'}
  388: <input type="text" value="$id" size="12" name="id"> 
  389: $lt{'ad'}
  390: $chooseopt
  391: </b>
  392: <input type="hidden" value='' name="pres_value">
  393: <input type="hidden" value='' name="pres_type">
  394: <input type="hidden" value='' name="pres_marker">
  395: ENDHEAD
  396:     }
  397: }
  398: 
  399: sub print_row {
  400:     my ($r,$which,$part,$name,$rid,$default,$defaulttype,$display,$defbgone,
  401: 	$defbgtwo,$parmlev)=@_;
  402: # get the values for the parameter in cascading order
  403: # empty levels will remain empty
  404:     my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
  405: 				  $rid,$$default{$which});
  406: # get the type for the parameters
  407: # problem: these may not be set for all levels
  408:     my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
  409:                                           $$name{$which}.'.type',
  410: 				  $rid,$$defaulttype{$which});
  411: # cascade down manually
  412:     my $cascadetype=$defaulttype;
  413:     for (my $i=$#typeoutpar;$i>0;$i--) {
  414: 	 if ($typeoutpar[$i]) { 
  415:             $cascadetype=$typeoutpar[$i];
  416: 	} else {
  417:             $typeoutpar[$i]=$cascadetype;
  418:         }
  419:     }
  420:  
  421:     my $parm=$$display{$which};
  422: 
  423:     if ($parmlev eq 'full' || $parmlev eq 'brief') {
  424:         $r->print('<td bgcolor='.$defbgtwo.' align="center">'
  425:                   .$$part{$which}.'</td>');
  426:     } else {    
  427:         $parm=~s|\[.*\]\s||g;
  428:     }
  429: 
  430:     $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
  431:    
  432:     my $thismarker=$which;
  433:     $thismarker=~s/^parameter\_//;
  434:     my $mprefix=$rid.'&'.$thismarker.'&';
  435: 
  436:     if ($parmlev eq 'general') {
  437: 
  438:         if ($uname) {
  439:             &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  440:         } elsif ($csec) {
  441:             &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); 
  442:         } else {
  443:             &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); 
  444:         }
  445:     } elsif ($parmlev eq 'map') {
  446: 
  447:         if ($uname) {
  448:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  449:         } elsif ($csec) {
  450:             &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  451:         } else {
  452:             &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  453:         }
  454:     } else {
  455: 
  456:         &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  457: 
  458:         if ($parmlev eq 'brief') {
  459: 
  460:            &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  461: 
  462:            if ($csec) {
  463:                &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  464:            }
  465:            if ($uname) {
  466:                &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  467:            }
  468:         } else {
  469: 
  470:            &print_td($r,10,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  471:            &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  472:            &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  473:            &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  474: 
  475:            if ($csec) {
  476:                &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  477:                &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  478:                &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  479:            }
  480:            if ($uname) {
  481:                &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  482:                &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  483:                &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  484:            }
  485:         } # end of $brief if/else
  486:     } # end of $parmlev if/else
  487: 
  488:     if ($parmlev eq 'full' || $parmlev eq 'brief') {
  489:         $r->print('<td bgcolor=#CCCCFF align="center">'.
  490:                   &valout($outpar[$result],$typeoutpar[$result]).'</td>');
  491:     }
  492:     my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
  493:                                         '.'.$$name{$which},$symbp{$rid});
  494: # this doesn't seem to work, and I don't think is correct
  495: #    my $sessionvaltype=&Apache::lonnet::EXT('resource.'.$$part{$which}.
  496: #                                      '.'.$$name{$which}.'.type',$symbp{$rid});
  497: # this seems to work
  498:     my $sessionvaltype=$typeoutpar[$result];
  499:     if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
  500:     $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
  501:                   &valout($sessionval,$sessionvaltype).'&nbsp;'.
  502:                   '</font></td>');
  503:     $r->print('</tr>');
  504:     $r->print("\n");
  505: }
  506: 
  507: sub print_td {
  508:     my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
  509:     $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
  510:               ' align="center">');
  511:     if ($which<10) {
  512: 	$r->print(&plink($$typeoutpar[$which],
  513: 			 $$display{$value},$$outpar[$which],
  514: 			 $mprefix."$which",'parmform.pres','psub'));
  515:     } else {
  516: 	$r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
  517:     }
  518:     $r->print('</td>'."\n");
  519: }
  520: 
  521: =pod
  522: 
  523: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
  524: 
  525: Input: See list below:
  526: 
  527: =over 4
  528: 
  529: =item B<ids>: An array that will contain all of the ids in the course.
  530: 
  531: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
  532: 
  533: =item B<keyp>: hash, id->key list, will contain a comma seperated list of the meta-data keys available for the given id
  534: 
  535: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
  536: 
  537: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
  538: 
  539: =item B<allkeys>: hash, full key to part->display value (what's display value?)
  540: 
  541: =item B<allmaps>: hash, ???
  542: 
  543: =item B<fcat>: ???
  544: 
  545: =item B<defp>: hash, ???
  546: 
  547: =item B<mapp>: ??
  548: 
  549: =item B<symbp>: hash, id->full sym?
  550: 
  551: =back
  552: 
  553: =cut
  554: 
  555: sub extractResourceInformation {
  556:     my $bighash = shift;
  557:     my $ids = shift;
  558:     my $typep = shift;
  559:     my $keyp = shift;
  560:     my $allparms = shift;
  561:     my $allparts = shift;
  562:     my $allkeys = shift;
  563:     my $allmaps = shift;
  564:     my $fcat = shift;
  565:     my $defp = shift;
  566:     my $mapp = shift;
  567:     my $symbp = shift;
  568:     my $maptitles=shift;
  569: 
  570:     foreach (keys %$bighash) {
  571: 	if ($_=~/^src\_(\d+)\.(\d+)$/) {
  572: 	    my $mapid=$1;
  573: 	    my $resid=$2;
  574: 	    my $id=$mapid.'.'.$resid;
  575: 	    my $srcf=$$bighash{$_};
  576: 	    if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  577: 		$$ids[$#$ids+1]=$id;
  578: 		$$typep{$id}=$1;
  579: 		$$keyp{$id}='';
  580: 		foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
  581: 		  if ($_=~/^parameter\_(.*)/) {
  582:                     my $key=$_;
  583:                     my $allkey=$1;
  584:                     $allkey=~s/\_/\./g;
  585:                     my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
  586:                     my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
  587:                     my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
  588:                     my $parmdis = $display;
  589:                     $parmdis =~ s|(\[Part.*$)||g;
  590:                     my $partkey = $part;
  591:                     $partkey =~ tr|_|.|;
  592:                     $$allparms{$name} = $parmdis;
  593:                     $$allparts{$part} = "[Part $part]";
  594:                     $$allkeys{$allkey}=$display;
  595:                     if ($allkey eq $fcat) {
  596: 		        $$defp{$id}= &Apache::lonnet::metadata($srcf,$key);
  597: 		    }
  598: 		    if ($$keyp{$id}) {
  599: 		        $$keyp{$id}.=','.$key;
  600: 		    } else {
  601: 		        $$keyp{$id}=$key;
  602: 		    }
  603: 		  }
  604: 		}
  605: 		$$mapp{$id}=
  606: 		    &Apache::lonnet::declutter($$bighash{'map_id_'.$mapid});
  607:                 $$mapp{$mapid}=$$mapp{$id};
  608: 		$$allmaps{$mapid}=$$mapp{$id};
  609: 		$$maptitles{$mapid}=
  610:  $$bighash{'title_'.$$bighash{'ids_'.&Apache::lonnet::clutter($$mapp{$id})}};
  611: 		$$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
  612: 		$$symbp{$id}=$$mapp{$id}.
  613: 			'___'.$resid.'___'.
  614: 			    &Apache::lonnet::declutter($srcf);
  615:                 $$symbp{$mapid}=$$mapp{$id}.'___(all)';
  616: 	    }
  617: 	}
  618:     }
  619: }
  620: 
  621: ##################################################
  622: ##################################################
  623: 
  624: =pod
  625: 
  626: =item assessparms
  627: 
  628: Show assessment data and parameters.  This is a large routine that should
  629: be simplified and shortened... someday.
  630: 
  631: Inputs: $r
  632: 
  633: Returns: nothing
  634: 
  635: Variables used (guessed by Jeremy):
  636: 
  637: =over 4
  638: 
  639: =item B<pscat>: ParameterS CATegories? ends up a list of the types of parameters that exist, e.g., tol, weight, acc, opendate, duedate, answerdate, sig, maxtries, type.
  640: 
  641: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
  642: 
  643: =item B<allmaps>:
  644: 
  645: =back
  646: 
  647: =cut
  648: 
  649: ##################################################
  650: ##################################################
  651: sub assessparms {
  652: 
  653:     my $r=shift;
  654: # -------------------------------------------------------- Variable declaration
  655:     my %allkeys=();
  656:     my %allmaps=();
  657:     my %alllevs=();
  658: 
  659:     $alllevs{'Resource Level'}='full';
  660: #    $alllevs{'Resource Level [BRIEF]'}='brief';
  661:     $alllevs{'Map Level'}='map';
  662:     $alllevs{'Course Level'}='general';
  663: 
  664:     my %allparms;
  665:     my %allparts;
  666: 
  667:     my %defp;
  668:     %courseopt=();
  669:     %useropt=();
  670:     my %bighash=();
  671: 
  672:     @ids=();
  673:     %symbp=();
  674:     %typep=();
  675: 
  676:     my $message='';
  677: 
  678:     $csec=$ENV{'form.csec'};
  679:     $udom=$ENV{'form.udom'};
  680:     unless ($udom) { $udom=$r->dir_config('lonDefDomain'); }
  681: 
  682:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
  683:     my $pschp=$ENV{'form.pschp'};
  684:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
  685:     if (!@psprt) { $psprt[0]='0'; }
  686:     my $showoptions=$ENV{'form.showoptions'};
  687: 
  688:     my $pssymb='';
  689:     my $parmlev='';
  690:     my $prevvisit=$ENV{'form.prevvisit'};
  691: 
  692: #    unless ($parmlev==$ENV{'form.parmlev'}) {
  693: #        $parmlev = 'full';
  694: #    }
  695:  
  696:     unless ($ENV{'form.parmlev'}) {
  697:         $parmlev = 'map';
  698:     } else {
  699:         $parmlev = $ENV{'form.parmlev'};
  700:     }
  701: 
  702: # ----------------------------------------------- Was this started from grades?
  703: 
  704:     if (($ENV{'form.command'} eq 'set') && ($ENV{'form.url'})
  705: 	&& (!$ENV{'form.dis'})) {
  706: 	my $url=$ENV{'form.url'};
  707: 	$url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
  708: 	$pssymb=&Apache::lonnet::symbread($url);
  709: 	if (!@pscat) { @pscat=('all'); }
  710: 	$pschp='';
  711:         $parmlev = 'full';
  712:     } elsif ($ENV{'form.symb'}) {
  713: 	$pssymb=$ENV{'form.symb'};
  714: 	if (!@pscat) { @pscat=('all'); }
  715: 	$pschp='';
  716:         $parmlev = 'full';
  717:     } else {
  718: 	$ENV{'form.url'}='';
  719:     }
  720: 
  721:     my $id=$ENV{'form.id'};
  722:     if (($id) && ($udom)) {
  723: 	$uname=(&Apache::lonnet::idget($udom,$id))[1];
  724: 	if ($uname) {
  725: 	    $id='';
  726: 	} else {
  727: 	    $message=
  728: 		"<font color=red>".&mt("Unknown ID")." '$id' ".
  729: 		&mt('at domain')." '$udom'</font>";
  730: 	}
  731:     } else {
  732: 	$uname=$ENV{'form.uname'};
  733:     }
  734:     unless ($udom) { $uname=''; }
  735:     $uhome='';
  736:     if ($uname) {
  737: 	$uhome=&Apache::lonnet::homeserver($uname,$udom);
  738:         if ($uhome eq 'no_host') {
  739: 	    $message=
  740: 		"<font color=red>".&mt("Unknown user")." '$uname' ".
  741: 		&mt("at domain")." '$udom'</font>";
  742: 	    $uname='';
  743:         } else {
  744: 	    $csec=&Apache::lonnet::getsection($udom,$uname,
  745: 					      $ENV{'request.course.id'});
  746: 	    if ($csec eq '-1') {
  747: 		$message="<font color=red>".
  748: 		    &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
  749: 		    &mt("not in this course")."</font>";
  750: 		$uname='';
  751: 		$csec=$ENV{'form.csec'};
  752: 	    } else {
  753: 		my %name=&Apache::lonnet::userenvironment($udom,$uname,
  754: 		      ('firstname','middlename','lastname','generation','id'));
  755: 		$message="\n<p>\n".&mt("Full Name").": ".
  756: 		    $name{'firstname'}.' '.$name{'middlename'}.' '
  757: 			.$name{'lastname'}.' '.$name{'generation'}.
  758: 			    "<br>\n".&mt('ID').": ".$name{'id'}.'<p>';
  759: 	    }
  760:         }
  761:     }
  762: 
  763:     unless ($csec) { $csec=''; }
  764: 
  765:     my $fcat=$ENV{'form.fcat'};
  766:     unless ($fcat) { $fcat=''; }
  767: 
  768: # ------------------------------------------------------------------- Tie hashs
  769:     if (!(tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
  770: 	      &GDBM_READER(),0640))) {
  771: 	$r->print("Unable to access course data. (File $ENV{'request.course.fn'}.db not tieable)");
  772: 	return ;
  773:     }
  774:     if (!(tie(%parmhash,'GDBM_File',
  775: 	      $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640))) {
  776: 	$r->print("Unable to access parameter data. (File $ENV{'request.course.fn'}_parms.db not tieable)");
  777: 	return ;
  778:     }
  779: 
  780: # --------------------------------------------------------- Get all assessments
  781:     extractResourceInformation(\%bighash, \@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles);
  782: 
  783:     $mapp{'0.0'} = '';
  784:     $symbp{'0.0'} = '';
  785: 
  786: # ---------------------------------------------------------- Anything to store?
  787:     if ($ENV{'form.pres_marker'}) {
  788: 	my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
  789: 	$spnam=~s/\_([^\_]+)$/\.$1/;
  790: # ---------------------------------------------------------- Construct prefixes
  791: 
  792: 	my $symbparm=$symbp{$sresid}.'.'.$spnam;
  793: 	my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
  794: 	
  795: 	my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$spnam;
  796: 	my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  797: 	my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  798: 	
  799: 	my $courselevel=$ENV{'request.course.id'}.'.'.$spnam;
  800: 	my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
  801: 	my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
  802: 	
  803: 	my $storeunder='';
  804: 	if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
  805: 	if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
  806: 	if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
  807: 	if ($snum==6) { $storeunder=$seclevel; }
  808: 	if ($snum==5) { $storeunder=$seclevelm; }
  809: 	if ($snum==4) { $storeunder=$seclevelr; }
  810: 	
  811: 	my $delete;
  812: 	if ($ENV{'form.pres_value'} eq '') { $delete=1;}
  813:         my %storecontent = ($storeunder         => $ENV{'form.pres_value'},
  814:                             $storeunder.'.type' => $ENV{'form.pres_type'});
  815: 	my $reply='';
  816: 	if ($snum>3) {
  817: # ---------------------------------------------------------------- Store Course
  818: #
  819: # Expire sheets
  820: 	    &Apache::lonnet::expirespread('','','studentcalc');
  821: 	    if (($snum==7) || ($snum==4)) {
  822: 		&Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
  823: 	    } elsif (($snum==8) || ($snum==5)) {
  824: 		&Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
  825: 	    } else {
  826: 		&Apache::lonnet::expirespread('','','assesscalc');
  827: 	    }
  828: # Store parameter
  829: 	    if ($delete) {
  830: 		$reply=&Apache::lonnet::del
  831: 		    ('resourcedata',[keys(%storecontent)],
  832: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  833: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  834: 	    } else {
  835: 		$reply=&Apache::lonnet::cput
  836: 		    ('resourcedata',\%storecontent,
  837: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  838: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  839: 	    }
  840: 	} else {
  841: # ------------------------------------------------------------------ Store User
  842: #
  843: # Expire sheets
  844: 	    &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
  845: 	    if ($snum==1) {
  846: 		&Apache::lonnet::expirespread
  847: 		    ($uname,$udom,'assesscalc',$symbp{$sresid});
  848: 	    } elsif ($snum==2) {
  849: 		&Apache::lonnet::expirespread
  850: 		    ($uname,$udom,'assesscalc',$mapp{$sresid});
  851: 	    } else {
  852: 		&Apache::lonnet::expirespread($uname,$udom,'assesscalc');
  853: 	    }
  854: # Store parameter
  855: 	    if ($delete) {
  856: 		$reply=&Apache::lonnet::del
  857: 		    ('resourcedata',[keys(%storecontent)],$udom,$uname);
  858: 	    } else {
  859: 		$reply=&Apache::lonnet::cput
  860: 		    ('resourcedata',\%storecontent,$udom,$uname);
  861: 	    }
  862: 	}
  863: 
  864: 	if ($reply=~/^error\:(.*)/) {
  865: 	    $message.="<font color=red>Write Error: $1</font>";
  866: 	}
  867: # ---------------------------------------------------------------- Done storing
  868: 	$message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
  869:     }
  870: # --------------------------------------------- Devalidate cache for this child
  871:     &Apache::lonnet::devalidatecourseresdata(
  872:                  $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
  873:                  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'});
  874:     &Apache::lonnet::clear_EXT_cache_status();
  875: # -------------------------------------------------------------- Get coursedata
  876:     %courseopt = &Apache::lonnet::dump
  877:         ('resourcedata',
  878:          $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  879:          $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  880: # --------------------------------------------------- Get userdata (if present)
  881:     if ($uname) {
  882:         %useropt=&Apache::lonnet::dump('resourcedata',$udom,$uname);
  883:     }
  884: 
  885: # ------------------------------------------------------------------- Sort this
  886: 
  887:     @ids=sort  {
  888: 	if ($fcat eq '') {
  889: 	    $a<=>$b;
  890: 	} else {
  891: 	    my ($result,@outpar)=&parmval($fcat,$a,$defp{$a});
  892: 	    my $aparm=$outpar[$result];
  893: 	    ($result,@outpar)=&parmval($fcat,$b,$defp{$b});
  894: 	    my $bparm=$outpar[$result];
  895: 	    1*$aparm<=>1*$bparm;
  896: 	}
  897:     } @ids;
  898: #----------------------------------------------- if all selected, fill in array
  899:     if ($pscat[0] eq "all" || !@pscat) {@pscat = (keys %allparms);}
  900:     if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
  901: # ------------------------------------------------------------------ Start page
  902: 
  903:     my $have_assesments=1;
  904:     if (scalar(keys(%allkeys)) eq 0) { $have_assesments=0; }
  905: 
  906:     &startpage($r,$id,$udom,$csec,$uname,$have_assesments);
  907: 
  908:     if (!$have_assesments) {
  909: 	untie(%bighash);
  910: 	untie(%parmhash);
  911: 	return '';
  912:     }
  913: #    if ($ENV{'form.url'}) {
  914: #	$r->print('<input type="hidden" value="'.$ENV{'form.url'}.
  915: #		  '" name="url"><input type="hidden" name="command" value="set">');
  916: #    }
  917:     $r->print('<input type="hidden" value="true" name="prevvisit">');
  918: 
  919:     foreach ('tolerance','date_default','date_start','date_end',
  920: 	     'date_interval','int','float','string') {
  921: 	$r->print('<input type="hidden" value="'.
  922: 		  $ENV{'form.recent_'.$_}.'" name="recent_'.$_.'">');
  923:     }
  924: 
  925:     $r->print('<h2>'.$message.'</h2><table>');
  926:                         
  927:     my $submitmessage = &mt('Update Section or Specific User');
  928:     if (!$pssymb) {
  929:         $r->print('<tr><td>'.&mt('Select Parameter Level').'</td><td colspan="2">');
  930:         $r->print('<select name="parmlev">');
  931:         foreach (reverse sort keys %alllevs) {
  932:             $r->print('<option value="'.$alllevs{$_}.'"');
  933:             if ($parmlev eq $alllevs{$_}) {
  934:                $r->print(' selected'); 
  935:             }
  936:             $r->print('>'.$_.'</option>');
  937:         }
  938:         $r->print("</select></td>\n");
  939: 
  940:         $r->print('</tr>');
  941: 	if ($parmlev ne 'general') {
  942: 	    $r->print('<tr><td>'.&mt('Select Enclosing Map or Folder').'</td>');
  943: 	    $r->print('<td colspan="2"><select name="pschp">');
  944: 	    $r->print('<option value="all">'.&mt('All Maps or Folders').'</option>');
  945: 	    foreach (sort {$allmaps{$a} cmp $allmaps{$b}} keys %allmaps) {
  946: 		$r->print('<option value="'.$_.'"');
  947: 		if (($pschp eq $_)) { $r->print(' selected'); }
  948: 		$r->print('>'.$maptitles{$_}.($allmaps{$_}!~/^uploaded/?'  ['.$allmaps{$_}.']':'').'</option>');
  949: 	    }
  950: 	    $r->print("</select></td></tr>\n");
  951: 	}
  952:     } else {
  953:         my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
  954:         $r->print("<tr><td>".&mt('Specific Resource')."</td><td>$resource</td>");
  955:         $r->print('<td><input type="submit" name="dis" value="'.$submitmessage.'"></td>');
  956:         $r->print('</tr>');
  957:         $r->print('<input type="hidden" value="'.$pssymb.'" name="symb">');
  958:     }
  959: 
  960:     $r->print('<tr><td colspan="3"><hr /><input type="checkbox"');
  961:     if ($showoptions eq 'show') {$r->print(" checked ");}
  962:     $r->print(' name="showoptions" value="show">'.&mt('Show More Options').'<hr /></td></tr>');
  963: #    $r->print("<tr><td>Show: $showoptions</td></tr>");
  964: #    $r->print("<tr><td>pscat: @pscat</td></tr>");
  965: #    $r->print("<tr><td>psprt: @psprt</td></tr>");
  966: #    $r->print("<tr><td>fcat:  $fcat</td></tr>");
  967: 
  968:     if ($showoptions eq 'show') {
  969:         my $tempkey;
  970: 
  971:         $r->print('<tr><td colspan="3" align="center">'.&mt('Select Parameters to View').'</td></tr>');
  972: 
  973:         $r->print('<tr><td colspan="2"><table>');
  974:         $r->print('<tr><td><input type="checkbox" name="pscat" value="all"');
  975:         $r->print(' checked') unless (@pscat);
  976:         $r->print('>'.&mt('All Parameters').'</td>');
  977: 
  978:         my $cnt=0;
  979:         foreach $tempkey (sort { $allparms{$a} cmp $allparms{$b} }
  980:                       keys %allparms ) {
  981:             ++$cnt;
  982:             $r->print('</tr><tr>') unless ($cnt%2);
  983:             $r->print('<td><input type="checkbox" name="pscat" ');
  984:             $r->print('value="'.$tempkey.'"');
  985:             if ($pscat[0] eq "all" || grep $_ eq $tempkey, @pscat) {
  986:                 $r->print(' checked');
  987:             }
  988:             $r->print('>'.$allparms{$tempkey}.'</td>');
  989:         }
  990:         $r->print('</tr></table>');
  991: 
  992: #        $r->print('<tr><td>Select Parts</td><td>');
  993:         $r->print('<td><select multiple name="psprt" size="5">');
  994:         $r->print('<option value="all"');
  995:         $r->print(' selected') unless (@psprt);
  996:         $r->print('>'.&mt('All Parts').'</option>');
  997:         my %temphash=();
  998:         foreach (@psprt) { $temphash{$_}=1; }
  999:         foreach $tempkey (sort keys %allparts) {
 1000:             unless ($tempkey =~ /\./) {
 1001:                 $r->print('<option value="'.$tempkey.'"');
 1002:                 if ($psprt[0] eq "all" ||  $temphash{$tempkey}) {
 1003:                     $r->print(' selected');
 1004:                 }
 1005:                 $r->print('>'.$allparts{$tempkey}.'</option>');
 1006:             }
 1007:         }
 1008:         $r->print('</select></td></tr><tr><td colspan="3"><hr /></td></tr>');
 1009: 
 1010:         $r->print('<tr><td>'.&mt('Sort list by').'</td><td>');
 1011:         $r->print('<select name="fcat">');
 1012:         $r->print('<option value="">'.&mt('Enclosing Map or Folder').'</option>');
 1013:         foreach (sort keys %allkeys) {
 1014:             $r->print('<option value="'.$_.'"');
 1015:             if ($fcat eq $_) { $r->print(' selected'); }
 1016:             $r->print('>'.$allkeys{$_}.'</option>');
 1017:         }
 1018:         $r->print('</select></td>');
 1019: 
 1020:         $r->print('</tr><tr><td colspan="3"><hr /></td></tr>');
 1021: 
 1022:     } else { # hide options - include any necessary extras here
 1023: 
 1024:         $r->print('<input type="hidden" name="fcat" value="'.$fcat.'">'."\n");
 1025: 
 1026:         unless (@pscat) {
 1027:           foreach (keys %allparms ) {
 1028:             $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
 1029:           }
 1030:         } else {
 1031:           foreach (@pscat) {
 1032:             $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
 1033:           }
 1034:         }
 1035: 
 1036:         unless (@psprt) {
 1037:           foreach (keys %allparts ) {
 1038:             $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
 1039:           }
 1040:         } else {
 1041:           foreach (@psprt) {
 1042:             $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
 1043:           }
 1044:         }
 1045: 
 1046:     }
 1047:     $r->print('</table><br />');
 1048:     if (($prevvisit) || ($pschp) || ($pssymb)) {
 1049:         $submitmessage = &mt("Update Course Assessment Parameter Display");
 1050:     } else {
 1051:         $submitmessage = &mt("Set/Modify Course Assessment Parameters");
 1052:     }
 1053:     $r->print('<input type="submit" name="dis" value="'.$submitmessage.'">');
 1054: 
 1055: #    my @temp_psprt;
 1056: #    foreach my $t (@psprt) {
 1057: #	push(@temp_psprt, grep {eval (/^$t\./ || ($_ == $t))} (keys %allparts));
 1058: #    }
 1059: 
 1060: #    @psprt = @temp_psprt;
 1061: 
 1062:     my @temp_pscat;
 1063:     map {
 1064:         my $cat = $_;
 1065:         push(@temp_pscat, map { $_.'.'.$cat } @psprt);
 1066:     } @pscat;
 1067: 
 1068:     @pscat = @temp_pscat;
 1069: 
 1070:     if (($prevvisit) || ($pschp) || ($pssymb)) {
 1071: # ----------------------------------------------------------------- Start Table
 1072:         my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
 1073:         my $csuname=$ENV{'user.name'};
 1074:         my $csudom=$ENV{'user.domain'};
 1075: 
 1076:         if ($parmlev eq 'full' || $parmlev eq 'brief') {
 1077:            my $coursespan=$csec?8:5;
 1078:            $r->print('<p><table border=2>');
 1079:            $r->print('<tr><td colspan=5></td>');
 1080:            $r->print('<th colspan='.($coursespan).'>'.&mt('Any User').'</th>');
 1081:            if ($uname) {
 1082:                $r->print("<th colspan=3 rowspan=2>");
 1083:                $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
 1084:            }
 1085: 	   my %lt=&Apache::lonlocal::texthash(
 1086: 				  'pie'    => "Parameter in Effect",
 1087: 				  'csv'    => "Current Session Value",
 1088:                                   'at'     => 'at',
 1089:                                   'rl'     => "Resource Level",
 1090: 				  'ic'     => 'in Course',
 1091: 				  'aut'    => "Assessment URL and Title",
 1092: 				  'type'   => 'Type',
 1093: 				  'emof'   => "Enclosing Map or Folder",
 1094: 				  'part'   => 'Part',
 1095:                                   'pn'     => 'Parameter Name',
 1096: 				  'def'    => 'default',
 1097: 				  'femof'  => 'from Enclosing Map or Folder',
 1098: 				  'gen'    => 'general',
 1099: 				  'foremf' => 'for Enclosing Map or Folder',
 1100: 				  'fr'     => 'for Resource'
 1101: 					      );
 1102:            $r->print(<<ENDTABLETWO);
 1103: <th rowspan=3>$lt{'pie'}</th>
 1104: <th rowspan=3>$lt{'csv'}<br>($csuname $lt{'at'} $csudom)</th>
 1105: </tr><tr><td colspan=5></td><th colspan=2>$lt{'rl'}</th>
 1106: <th colspan=3>$lt{'ic'}</th>
 1107: ENDTABLETWO
 1108:            if ($csec) {
 1109:                 $r->print("<th colspan=3>".
 1110: 			  &mt("in Section/Group")." $csec</th>");
 1111:            }
 1112:            $r->print(<<ENDTABLEHEADFOUR);
 1113: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
 1114: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
 1115: <th>$lt{'def'}</th><th>$lt{'femof'}</th>
 1116: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th><th>$lt{'fr'}</th>
 1117: ENDTABLEHEADFOUR
 1118: 
 1119:            if ($csec) {
 1120:                $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
 1121:            }
 1122: 
 1123:            if ($uname) {
 1124:                $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
 1125:            }
 1126: 
 1127:            $r->print('</tr>');
 1128: 
 1129:            my $defbgone='';
 1130:            my $defbgtwo='';
 1131: 
 1132:            foreach (@ids) {
 1133: 
 1134:                 my $rid=$_;
 1135:                 my ($inmapid)=($rid=~/\.(\d+)$/);
 1136: 
 1137:                 if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
 1138:                     ($pssymb eq $symbp{$rid})) {
 1139: # ------------------------------------------------------ Entry for one resource
 1140:                     if ($defbgone eq '"E0E099"') {
 1141:                         $defbgone='"E0E0DD"';
 1142:                     } else {
 1143:                         $defbgone='"E0E099"';
 1144:                     }
 1145:                     if ($defbgtwo eq '"FFFF99"') {
 1146:                         $defbgtwo='"FFFFDD"';
 1147:                     } else {
 1148:                         $defbgtwo='"FFFF99"';
 1149:                     }
 1150:                     my $thistitle='';
 1151:                     my %name=   ();
 1152:                     undef %name;
 1153:                     my %part=   ();
 1154:                     my %display=();
 1155:                     my %type=   ();
 1156:                     my %default=();
 1157:                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1158: 
 1159:                     foreach (split(/\,/,$keyp{$rid})) {
 1160:                         my $tempkeyp = $_;
 1161:                         if (grep $_ eq $tempkeyp, @catmarker) {
 1162:                           $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
 1163:                           $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
 1164:                           $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
 1165:                           unless ($display{$_}) { $display{$_}=''; }
 1166:                           $display{$_}.=' ('.$name{$_}.')';
 1167:                           $default{$_}=&Apache::lonnet::metadata($uri,$_);
 1168:                           $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
 1169:                           $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
 1170:                         }
 1171:                     }
 1172:                     my $totalparms=scalar keys %name;
 1173:                     if ($totalparms>0) {
 1174:                         my $firstrow=1;
 1175: 			my $title=$bighash{'title_'.$rid};
 1176: 			$title=~s/\&colon;/:/g;
 1177:                         $r->print('<tr><td bgcolor='.$defbgone.
 1178:                              ' rowspan='.$totalparms.
 1179:                              '><tt><font size=-1>'.
 1180:                              join(' / ',split(/\//,$uri)).
 1181:                              '</font></tt><p><b>'.
 1182:                              "<a href=\"javascript:openWindow('/res/".$uri.
 1183:                              "', 'metadatafile', '450', '500', 'no', 'yes')\";".
 1184:                              " TARGET=_self>$title");
 1185: 
 1186:                         if ($thistitle) {
 1187:                             $r->print(' ('.$thistitle.')');
 1188:                         }
 1189:                         $r->print('</a></b></td>');
 1190:                         $r->print('<td bgcolor='.$defbgtwo.
 1191:                                       ' rowspan='.$totalparms.'>'.$typep{$rid}.
 1192:                                       '</td>');
 1193: 
 1194:                         $r->print('<td bgcolor='.$defbgone.
 1195:                                       ' rowspan='.$totalparms.
 1196:                                       '><tt><font size=-1>');
 1197: 
 1198:                         $r->print(' / res / ');
 1199:                         $r->print(join(' / ', split(/\//,$mapp{$rid})));
 1200: 
 1201:                         $r->print('</font></tt></td>');
 1202: 
 1203:                         foreach (sort keys %name) {
 1204:                             unless ($firstrow) {
 1205:                                 $r->print('<tr>');
 1206:                             } else {
 1207:                                 undef $firstrow;
 1208:                             }
 1209: 
 1210:                             &print_row($r,$_,\%part,\%name,$rid,\%default,
 1211:                                        \%type,\%display,$defbgone,$defbgtwo,
 1212:                                        $parmlev);
 1213:                         }
 1214:                     }
 1215:                 }
 1216:             } # end foreach ids
 1217: # -------------------------------------------------- End entry for one resource
 1218:             $r->print('</table>');
 1219:         } # end of  brief/full
 1220: #--------------------------------------------------- Entry for parm level map
 1221:         if ($parmlev eq 'map') {
 1222:             my $defbgone = '"E0E099"';
 1223:             my $defbgtwo = '"FFFF99"';
 1224: 
 1225:             my %maplist;
 1226: 
 1227:             if ($pschp eq 'all') {
 1228:                 %maplist = %allmaps; 
 1229:             } else {
 1230:                 %maplist = ($pschp => $mapp{$pschp});
 1231:             }
 1232: 
 1233: #-------------------------------------------- for each map, gather information
 1234:             my $mapid;
 1235: 	    foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
 1236:                 my $maptitle = $maplist{$mapid};
 1237: 
 1238: #-----------------------  loop through ids and get all parameter types for map
 1239: #-----------------------------------------          and associated information
 1240:                 my %name = ();
 1241:                 my %part = ();
 1242:                 my %display = ();
 1243:                 my %type = ();
 1244:                 my %default = ();
 1245:                 my $map = 0;
 1246: 
 1247: #		$r->print("Catmarker: @catmarker<br />\n");
 1248:                
 1249:                 foreach (@ids) {
 1250:                   ($map)=(/([\d]*?)\./);
 1251:                   my $rid = $_;
 1252:         
 1253: #                  $r->print("$mapid:$map:   $rid <br /> \n");
 1254: 
 1255:                   if ($map eq $mapid) {
 1256:                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1257: #                    $r->print("Keys: $keyp{$rid} <br />\n");
 1258: 
 1259: #--------------------------------------------------------------------
 1260: # @catmarker contains list of all possible parameters including part #s
 1261: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1262: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1263: # When storing information, store as part 0
 1264: # When requesting information, request from full part
 1265: #-------------------------------------------------------------------
 1266:                     foreach (split(/\,/,$keyp{$rid})) {
 1267:                       my $tempkeyp = $_;
 1268:                       my $fullkeyp = $tempkeyp;
 1269:                       $tempkeyp =~ s/_\w+_/_0_/;
 1270:                       
 1271:                       if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1272:                         $part{$tempkeyp}="0";
 1273:                         $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1274:                         $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1275:                         unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1276:                         $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1277:                         $display{$tempkeyp} =~ s/_\w+_/_0_/;
 1278:                         $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1279:                         $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1280:                       }
 1281:                     } # end loop through keys
 1282:                   }
 1283:                 } # end loop through ids
 1284:                                  
 1285: #---------------------------------------------------- print header information
 1286:                 my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
 1287:                 my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
 1288:                 $r->print(<<ENDMAPONE);
 1289: <center><h4>
 1290: <font color="red">Set Defaults for All Resources in $foldermap<br />
 1291: <i>$showtitle</i><br />
 1292: Specifically for
 1293: ENDMAPONE
 1294:                 if ($uname) {
 1295:                     my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1296:                       ('firstname','middlename','lastname','generation', 'id'));
 1297:                     my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1298:                            .$name{'lastname'}.' '.$name{'generation'};
 1299:                     $r->print(&mt("User")." <i>$uname \($person\) </i> ".
 1300:                         &mt('in')." \n");
 1301:                 } else {
 1302:                     $r->print("<i>".&mt('all').'</i> '.&mt('users in')." \n");
 1303:                 }
 1304:             
 1305:                 if ($csec) {$r->print(&mt("Section")." <i>$csec</i> ".
 1306: 				      &mt('of')." \n")};
 1307: 
 1308:                 $r->print("<i>$coursename</i><br />");
 1309:                 $r->print("</font></h4>\n");
 1310: #---------------------------------------------------------------- print table
 1311:                 $r->print('<p><table border="2">');
 1312:                 $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
 1313:                 $r->print('<th>'.&mt('Default Value').'</th>');
 1314:                 $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
 1315: 
 1316: 	        foreach (sort keys %name) {
 1317:                     &print_row($r,$_,\%part,\%name,$mapid,\%default,
 1318:                            \%type,\%display,$defbgone,$defbgtwo,
 1319:                            $parmlev);
 1320: #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
 1321:                 }
 1322:                 $r->print("</table></center>");
 1323:             } # end each map
 1324:         } # end of $parmlev eq map
 1325: #--------------------------------- Entry for parm level general (Course level)
 1326:         if ($parmlev eq 'general') {
 1327:             my $defbgone = '"E0E099"';
 1328:             my $defbgtwo = '"FFFF99"';
 1329: 
 1330: #-------------------------------------------- for each map, gather information
 1331:             my $mapid="0.0";
 1332: #-----------------------  loop through ids and get all parameter types for map
 1333: #-----------------------------------------          and associated information
 1334:             my %name = ();
 1335:             my %part = ();
 1336:             my %display = ();
 1337:             my %type = ();
 1338:             my %default = ();
 1339:                
 1340:             foreach (@ids) {
 1341:                 my $rid = $_;
 1342:         
 1343:                 my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1344: 
 1345: #--------------------------------------------------------------------
 1346: # @catmarker contains list of all possible parameters including part #s
 1347: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1348: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1349: # When storing information, store as part 0
 1350: # When requesting information, request from full part
 1351: #-------------------------------------------------------------------
 1352:                 foreach (split(/\,/,$keyp{$rid})) {
 1353:                   my $tempkeyp = $_;
 1354:                   my $fullkeyp = $tempkeyp;
 1355:                   $tempkeyp =~ s/_\w+_/_0_/;
 1356:                   if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1357:                     $part{$tempkeyp}="0";
 1358:                     $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1359:                     $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1360:                     unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1361:                     $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1362:                     $display{$tempkeyp} =~ s/_\w+_/_0_/;
 1363:                     $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1364:                     $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1365:                   }
 1366:                 } # end loop through keys
 1367:             } # end loop through ids
 1368:                                  
 1369: #---------------------------------------------------- print header information
 1370: 	    my $setdef=&mt("Set Defaults for All Resources in Course");
 1371:             $r->print(<<ENDMAPONE);
 1372: <center><h4>$setdef
 1373: <font color="red">
 1374: <i>$coursename</i><br />
 1375: ENDMAPONE
 1376:             if ($uname) {
 1377:                 my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1378:                   ('firstname','middlename','lastname','generation', 'id'));
 1379:                 my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1380:                        .$name{'lastname'}.' '.$name{'generation'};
 1381:                 $r->print(" ".&mt("User")." <i>$uname \($person\) </i> \n");
 1382:             } else {
 1383:                 $r->print("<i>".&mt("ALL")."</i> ".&mt("USERS")." \n");
 1384:             }
 1385:             
 1386:             if ($csec) {$r->print(&mt("Section")." <i>$csec</i>\n")};
 1387:             $r->print("</font></h4>\n");
 1388: #---------------------------------------------------------------- print table
 1389:             $r->print('<p><table border="2">');
 1390:             $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
 1391:             $r->print('<th>'.&mt('Default Value').'</th>');
 1392:             $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
 1393: 
 1394: 	    foreach (sort keys %name) {
 1395:                 &print_row($r,$_,\%part,\%name,$mapid,\%default,
 1396:                        \%type,\%display,$defbgone,$defbgtwo,$parmlev);
 1397: #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
 1398:             }
 1399:             $r->print("</table></center>");
 1400:         } # end of $parmlev eq general
 1401:     }
 1402:     $r->print('</form></body></html>');
 1403:     untie(%bighash);
 1404:     untie(%parmhash);
 1405: } # end sub assessparms
 1406: 
 1407: 
 1408: ##################################################
 1409: ##################################################
 1410: 
 1411: =pod
 1412: 
 1413: =item crsenv
 1414: 
 1415: Show and set course data and parameters.  This is a large routine that should
 1416: be simplified and shortened... someday.
 1417: 
 1418: Inputs: $r
 1419: 
 1420: Returns: nothing
 1421: 
 1422: =cut
 1423: 
 1424: ##################################################
 1425: ##################################################
 1426: sub crsenv {
 1427:     my $r=shift;
 1428:     my $setoutput='';
 1429:     my $bodytag=&Apache::loncommon::bodytag(
 1430:                              'Set Course Environment Parameters');
 1431:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
 1432:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
 1433: 
 1434:     #
 1435:     # Go through list of changes
 1436:     foreach (keys %ENV) {
 1437:         next if ($_!~/^form\.(.+)\_setparmval$/);
 1438:         my $name  = $1;
 1439:         my $value = $ENV{'form.'.$name.'_value'};
 1440:         if ($name eq 'newp') {
 1441:             $name = $ENV{'form.newp_name'};
 1442:         }
 1443:         if ($name eq 'url') {
 1444:             $value=~s/^\/res\///;
 1445:             my $bkuptime=time;
 1446:             my @tmp = &Apache::lonnet::get
 1447:                 ('environment',['url'],$dom,$crs);
 1448:             $setoutput.=&mt('Backing up previous URL').': '.
 1449:                 &Apache::lonnet::put
 1450:                 ('environment',
 1451:                  {'top level map backup '.$bkuptime => $tmp[1] },
 1452:                  $dom,$crs).
 1453:                      '<br>';
 1454:         }
 1455:         #
 1456:         # Deal with modified default spreadsheets
 1457:         if ($name =~ /^spreadsheet_default_(classcalc|
 1458:                                             studentcalc|
 1459:                                             assesscalc)$/x) {
 1460:             my $sheettype = $1; 
 1461:             if ($sheettype eq 'classcalc') {
 1462:                 # no need to do anything since viewing the sheet will
 1463:                 # cause it to be updated. 
 1464:             } elsif ($sheettype eq 'studentcalc') {
 1465:                 # expire all the student spreadsheets
 1466:                 &Apache::lonnet::expirespread('','','studentcalc');
 1467:             } else {
 1468:                 # expire all the assessment spreadsheets 
 1469:                 #    this includes non-default spreadsheets, but better to
 1470:                 #    be safe than sorry.
 1471:                 &Apache::lonnet::expirespread('','','assesscalc');
 1472:                 # expire all the student spreadsheets
 1473:                 &Apache::lonnet::expirespread('','','studentcalc');
 1474:             }
 1475:         }
 1476:         #
 1477:         # Deal with the enrollment dates
 1478:         if ($name =~ /^default_enrollment_(start|end)_date$/) {
 1479:             $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
 1480:         }
 1481:         #
 1482:         # Let the user know we made the changes
 1483:         if ($name) {
 1484:             my $put_result = &Apache::lonnet::put('environment',
 1485:                                                   {$name=>$value},$dom,$crs);
 1486:             if ($put_result eq 'ok') {
 1487:                 $setoutput.=&mt('Set').' <b>'.$name.'</b> '.&mt('to').' <b>'.$value.'</b>.<br />';
 1488:             } else {
 1489:                 $setoutput.=&mt('Unable to set').' <b>'.$name.'</b> '.&mt('to').
 1490: 		    ' <b>'.$value.'</b> '.&mt('due to').' '.$put_result.'.<br />';
 1491:             }
 1492:         }
 1493:     }
 1494: # ------------------------- Re-init course environment entries for this session
 1495: 
 1496:     &Apache::lonnet::coursedescription($ENV{'request.course.id'});
 1497: 
 1498: # -------------------------------------------------------- Get parameters again
 1499: 
 1500:     my %values=&Apache::lonnet::dump('environment',$dom,$crs);
 1501:     my $output='';
 1502:     if (! exists($values{'con_lost'})) {
 1503:         my %descriptions=
 1504: 	    ('url'            => '<b>Top Level Map</b> '.
 1505:                                  '<a href="javascript:openbrowser'.
 1506:                                  "('envform','url','sequence')\">".
 1507:                                  'Select Map</a><br /><font color=red> '.
 1508:                                  'Modification may make assessment data '.
 1509:                                  'inaccessible</font>',
 1510:              'description'    => '<b>Course Description</b>',
 1511:              'courseid'       => '<b>Course ID or number</b><br />'.
 1512:                                  '(internal, optional)',
 1513:              'grading'        => '<b>Grading</b>'.
 1514:                                  '"standard" or any other value.  '.
 1515:                                  'Default for new courses is "standard".',
 1516: 
 1517:              'default_xml_style' => '<b>Default XML Style File</b> '.
 1518:                     '<a href="javascript:openbrowser'.
 1519:                     "('envform','default_xml_style'".
 1520:                     ",'sty')\">Select Style File</a><br>",
 1521:              'question.email' => '<b>Feedback Addresses for Resource Content '.
 1522:                                  'Questions</b><br />(<tt>user:domain,'.
 1523:                                  'user:domain(section;section;...;*;...),...</tt>)',
 1524:              'comment.email'  => '<b>Feedback Addresses for Course Content Comments</b><br />'.
 1525:                                  '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
 1526:              'policy.email'   => '<b>Feedback Addresses for Course Policy</b>'.
 1527:                                  '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
 1528:              'hideemptyrows'  => '<b>Hide Empty Rows in Spreadsheets</b><br />'.
 1529:                                  '("<tt>yes</tt>" for default hiding)',
 1530:              'pageseparators'  => '<b>Visibly Separate Items on Pages</b><br />'.
 1531:                                  '("<tt>yes</tt>" for visible separation, '.
 1532:                                  'changes will not show until next login)',
 1533: 
 1534:              'plc.roles.denied'=> '<b>Disallow live chatroom use for '.
 1535:                                   'Roles</b><br />"<tt>st</tt>": '.
 1536:                                   'student, "<tt>ta</tt>": '.
 1537:                                   'TA, "<tt>in</tt>": '.
 1538:                                   'instructor;<br /><tt>role,role,...</tt>) '.
 1539: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
 1540:              'plc.users.denied' => 
 1541:                           '<b>Disallow live chatroom use for Users</b><br />'.
 1542:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1543: 
 1544:              'pch.roles.denied'=> '<b>Disallow Resource Discussion for '.
 1545:                                   'Roles</b><br />"<tt>st</tt>": '.
 1546:                                   'student, "<tt>ta</tt>": '.
 1547:                                   'TA, "<tt>in</tt>": '.
 1548:                                   'instructor;<br /><tt>role,role,...</tt>) '.
 1549: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
 1550:              'pch.users.denied' => 
 1551:                           '<b>Disallow Resource Discussion for Users</b><br />'.
 1552:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1553:              'spreadsheet_default_classcalc' 
 1554:                  => '<b>Default Course Spreadsheet</b> '.
 1555:                     '<a href="javascript:openbrowser'.
 1556:                     "('envform','spreadsheet_default_classcalc'".
 1557:                     ",'spreadsheet')\">Select Spreadsheet File</a><br />",
 1558:              'spreadsheet_default_studentcalc' 
 1559:                  => '<b>Default Student Spreadsheet</b> '.
 1560:                     '<a href="javascript:openbrowser'.
 1561:                     "('envform','spreadsheet_default_calc'".
 1562:                     ",'spreadsheet')\">Select Spreadsheet File</a><br />",
 1563:              'spreadsheet_default_assesscalc' 
 1564:                  => '<b>Default Assessment Spreadsheet</b> '.
 1565:                     '<a href="javascript:openbrowser'.
 1566:                     "('envform','spreadsheet_default_assesscalc'".
 1567:                     ",'spreadsheet')\">Select Spreadsheet File</a><br />",
 1568: 	     'allow_limited_html_in_feedback'
 1569: 	         => '<b>Allow limited HTML in discussion posts</b><br />'.
 1570: 	            '(Set value to "<tt>yes</tt>" to allow)',
 1571: 	     'rndseed'
 1572: 	         => '<b>Randomization algorithm used</b> <br />'.
 1573:                     '<font color="red">Modifying this will make problems '.
 1574:                     'have different numbers and answers</font>',
 1575:              'problem_stream_switch'
 1576:                  => '<b>Allow problems to be split over pages</b><br />'.
 1577:                     ' ("<tt>yes</tt>" if allowed, anything else if not)',
 1578:              'anonymous_quiz'
 1579:                  => '<b>Anonimous quiz/exam</b><br />'.
 1580:                     ' (<tt><b>yes</b> to avoid print students names </tt>)',
 1581:              'default_enrollment_start_date' => '<b>Default beginning date '.
 1582:                                                 'when enrolling students</b>',
 1583:              'default_enrollment_end_date'   => '<b>Default ending date '.
 1584:                                                 'when enrolling students</b>',
 1585:              'languages' => '<b>Languages used</b>',
 1586:              'disable_receipt_display'
 1587:                  => '<b>Disable display of problem receipts</b><br />'.
 1588:                     ' ("<tt>yes</tt>" to disable, anything else if not)'
 1589:              ); 
 1590:         my @Display_Order = ('url','description','courseid','grading',
 1591:                              'default_xml_style','pageseparators',
 1592:                              'question.email','comment.email','policy.email',
 1593:                              'plc.roles.denied','plc.users.denied',
 1594:                              'pch.roles.denied','pch.users.denied',
 1595:                              'allow_limited_html_in_feedback',
 1596:                              'languages',
 1597:                              'rndseed',
 1598:                              'problem_stream_switch',
 1599:                              'disable_receipt_display',
 1600:                              'spreadsheet_default_classcalc',
 1601:                              'spreadsheet_default_studentcalc',
 1602:                              'spreadsheet_default_assesscalc', 
 1603:                              'hideemptyrows',
 1604:                              'default_enrollment_start_date',
 1605:                              'default_enrollment_end_date',
 1606:                              );
 1607: 	foreach my $parameter (sort(keys(%values))) {
 1608: 	    if (! $descriptions{$parameter}) {
 1609:                 $descriptions{$parameter}=$parameter;
 1610:                 push(@Display_Order,$parameter);
 1611: 	    }
 1612: 	}
 1613:         foreach my $parameter (@Display_Order) {
 1614:             my $description = $descriptions{$parameter};
 1615:             # onchange is javascript to automatically check the 'Set' button.
 1616:             my $onchange = 'onFocus="javascript:window.document.forms'.
 1617:                 "['envform'].elements['".$parameter."_setparmval']".
 1618:                 '.checked=true;"';
 1619:             $output .= '<tr><td>'.$description.'</td>';
 1620:             if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
 1621:                 $output .= '<td>'.
 1622:                     &Apache::lonhtmlcommon::date_setter('envform',
 1623:                                                         $parameter.'_value',
 1624:                                                         $values{$parameter},
 1625:                                                         $onchange).
 1626:                                                         '</td>';
 1627:             } else {
 1628:                 $output .= '<td>'.
 1629:                     &Apache::lonhtmlcommon::textbox($parameter.'_value',
 1630:                                                     $values{$parameter},
 1631:                                                     40,$onchange).'</td>';
 1632:             }
 1633:             $output .= '<td>'.
 1634:                 &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
 1635:                 '</td>';
 1636:             $output .= "</tr>\n";
 1637: 	}
 1638:         my $onchange = 'onFocus="javascript:window.document.forms'.
 1639:             '[\'envform\'].elements[\'newp_setparmval\']'.
 1640:             '.checked=true;"';
 1641: 	$output.='<tr><td><i>'.&mt('Create New Environment Variable').'</i><br />'.
 1642: 	    '<input type="text" size=40 name="newp_name" '.
 1643:                 $onchange.' /></td><td>'.
 1644:             '<input type="text" size=40 name="newp_value" '.
 1645:                 $onchange.' /></td><td>'.
 1646: 	    '<input type="checkbox" name="newp_setparmval" /></td></tr>';
 1647:     }
 1648:     $r->print(<<ENDENV);
 1649: <html>
 1650: <script type="text/javascript" language="Javascript" >
 1651:     var editbrowser;
 1652:     function openbrowser(formname,elementname,only,omit) {
 1653:         var url = '/res/?';
 1654:         if (editbrowser == null) {
 1655:             url += 'launch=1&';
 1656:         }
 1657:         url += 'catalogmode=interactive&';
 1658:         url += 'mode=parmset&';
 1659:         url += 'form=' + formname + '&';
 1660:         if (only != null) {
 1661:             url += 'only=' + only + '&';
 1662:         } 
 1663:         if (omit != null) {
 1664:             url += 'omit=' + omit + '&';
 1665:         }
 1666:         url += 'element=' + elementname + '';
 1667:         var title = 'Browser';
 1668:         var options = 'scrollbars=1,resizable=1,menubar=0';
 1669:         options += ',width=700,height=600';
 1670:         editbrowser = open(url,title,options,'1');
 1671:         editbrowser.focus();
 1672:     }
 1673: </script>
 1674: <head>
 1675: <title>LON-CAPA Course Environment</title>
 1676: </head>
 1677: $bodytag
 1678: <form method="post" action="/adm/parmset" name="envform">
 1679: $setoutput
 1680: <p>
 1681: <table border=2>
 1682: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
 1683: $output
 1684: </table>
 1685: <input type="submit" name="crsenv" value="Set Course Environment">
 1686: </form>
 1687: </body>
 1688: </html>    
 1689: ENDENV
 1690: }
 1691: ##################################################
 1692: 
 1693: my $tableopen;
 1694: 
 1695: sub tablestart {
 1696:     if ($tableopen) {
 1697: 	return '';
 1698:     } else {
 1699: 	$tableopen=1;
 1700: 	return '<table border="2"><tr><th>'.&mt('Parameter').'</th><th>'.
 1701: 	    &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
 1702:     }
 1703: }
 1704: 
 1705: sub tableend {
 1706:     if ($tableopen) {
 1707: 	$tableopen=0;
 1708: 	return '</table>';
 1709:     } else {
 1710: 	return'';
 1711:     }
 1712: }
 1713: 
 1714: sub overview {
 1715:     my $r=shift;
 1716:     my $bodytag=&Apache::loncommon::bodytag(
 1717:                              'Set/Modify Course Assessment Parameters');
 1718:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
 1719:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
 1720:     $r->print(<<ENDOVER);
 1721: <html>
 1722: <head>
 1723: <title>LON-CAPA Course Environment</title>
 1724: </head>
 1725: $bodytag
 1726: <form method="post" action="/adm/parmset" name="overviewform">
 1727: <input type="hidden" name="overview" value="1" />
 1728: ENDOVER
 1729: # Setting
 1730:     my %olddata=&Apache::lonnet::dump('resourcedata',$dom,$crs);
 1731:     my %newdata=();
 1732:     undef %newdata;
 1733:     my @deldata=();
 1734:     undef @deldata;
 1735:     foreach (keys %ENV) {
 1736: 	if ($_=~/^form\.([a-z]+)\_(.+)$/) {
 1737: 	    my $cmd=$1;
 1738: 	    my $thiskey=$2;
 1739: 	    if ($cmd eq 'set') {
 1740: 		my $data=$ENV{$_};
 1741: 		if ($olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; }
 1742: 	    } elsif ($cmd eq 'del') {
 1743: 		push (@deldata,$thiskey);
 1744: 	    } elsif ($cmd eq 'datepointer') {
 1745: 		my $data=&Apache::lonhtmlcommon::get_date_from_form($ENV{$_});
 1746: 		if ($olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; }
 1747: 	    }
 1748: 	}
 1749:     }
 1750: # Store
 1751:     &Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs);
 1752:     &Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs);
 1753: # Read and display
 1754:     my %resourcedata=&Apache::lonnet::dump('resourcedata',$dom,$crs);
 1755:     my $oldsection='';
 1756:     my $oldrealm='';
 1757:     my $oldpart='';
 1758:     my $pointer=0;
 1759:     $tableopen=0;
 1760:     foreach my $thiskey (sort keys %resourcedata) {
 1761: 	if ($resourcedata{$thiskey.'.type'}) {
 1762: 	    my ($course,$middle,$part,$name)=
 1763: 		($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
 1764: 	    my $section=&mt('All Students');
 1765: 	    if ($middle=~/^\[(.*)\]\./) {
 1766: 		$section=&mt('Group/Section').': '.$1;
 1767: 		$middle=~s/^\[(.*)\]\.//;
 1768: 	    }
 1769: 	    $middle=~s/\.$//;
 1770: 	    my $realm='<font color="red">'.&mt('All Resources').'</font>';
 1771: 	    if ($middle=~/^(.+)\_\_\_\(all\)$/) {
 1772: 		$realm='<font color="green">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).'</font>';
 1773: 	    } elsif ($middle) {
 1774: 		$realm='<font color="orange">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).'</font>';
 1775: 	    }
 1776: 	    if ($section ne $oldsection) {
 1777: 		$r->print(&tableend()."\n<hr /><h1>$section</h1>");
 1778: 		$oldsection=$section;
 1779: 		$oldrealm='';
 1780: 	    }
 1781: 	    if ($realm ne $oldrealm) {
 1782: 		$r->print(&tableend()."\n<h2>$realm</h2>");
 1783: 		$oldrealm=$realm;
 1784: 		$oldpart='';
 1785: 	    }
 1786: 	    if ($part ne $oldpart) {
 1787: 		$r->print(&tableend().
 1788: 			  "\n<h3><font color='blue'>".&mt('Part').": $part</font></h3>");
 1789: 		$oldpart=$part;
 1790: 	    }
 1791: #
 1792: # Ready to print
 1793: #
 1794: 	    $r->print(&tablestart().'<tr><td><b>'.$name.
 1795: 		      ':</b></td><td><input type="checkbox" name="del_'.
 1796: 		      $thiskey.'" /></td><td>');
 1797: 	    if ($resourcedata{$thiskey.'.type'}=~/^date/) {
 1798: 		my $jskey='key_'.$pointer;
 1799: 		$pointer++;
 1800: 		$r->print(
 1801: 			  &Apache::lonhtmlcommon::date_setter('overviewform',
 1802: 							      $jskey,
 1803: 						      $resourcedata{$thiskey}).
 1804: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'
 1805: 			  );
 1806: 	    } else {
 1807: 		$r->print(
 1808: 			  '<input type="text" name="set_'.$thiskey.'" value="'.
 1809: 			  $resourcedata{$thiskey}.'">');
 1810: 	    }
 1811: 	    $r->print('</td></tr>');
 1812: 	}
 1813:     }
 1814:     
 1815:     $r->print(&tableend().
 1816: 	      '<p><input type="submit" value="'.&mt('Modify Parameters').'" /></p></form></body></html>');
 1817: }
 1818: 
 1819: ##################################################
 1820: ##################################################
 1821: 
 1822: =pod
 1823: 
 1824: =item * handler
 1825: 
 1826: Main handler.  Calls &assessparms and &crsenv subroutines.
 1827: 
 1828: =cut
 1829: 
 1830: ##################################################
 1831: ##################################################
 1832:     use Data::Dumper;
 1833: sub handler {
 1834:     my $r=shift;
 1835: 
 1836:     if ($r->header_only) {
 1837: 	&Apache::loncommon::content_type($r,'text/html');
 1838: 	$r->send_http_header;
 1839: 	return OK;
 1840:     }
 1841:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
 1842: 
 1843: # ----------------------------------------------------------- Clear out garbage
 1844: 
 1845:     %courseopt=();
 1846:     %useropt=();
 1847:     %parmhash=();
 1848: 
 1849:     @ids=();
 1850:     %symbp=();
 1851:     %mapp=();
 1852:     %typep=();
 1853:     %keyp=();
 1854: 
 1855:     %maptitles=();
 1856: 
 1857: # ----------------------------------------------------- Needs to be in a course
 1858: 
 1859:     if (($ENV{'request.course.id'}) && 
 1860: 	(&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
 1861: 
 1862:         &Apache::loncommon::content_type($r,'text/html');
 1863:         $r->send_http_header;
 1864:  
 1865:         $coursename=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
 1866: 
 1867: 	if (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) {
 1868: # ---------------------------------------------- This is for course environment
 1869: # -------------------------- also call if toplevel map coudl not be initialized
 1870: 	    &crsenv($r);
 1871: 	} elsif ($ENV{'form.overview'}) {
 1872: # --------------------------------------------------------------- Overview mode
 1873: 	    &overview($r);
 1874: 	} else {
 1875: # --------------------------------------------------------- Bring up assessment
 1876: 	    &assessparms($r);
 1877: 	}
 1878:     } else {
 1879: # ----------------------------- Not in a course, or not allowed to modify parms
 1880: 	$ENV{'user.error.msg'}=
 1881: 	    "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
 1882: 	return HTTP_NOT_ACCEPTABLE;
 1883:     }
 1884:     return OK;
 1885: }
 1886: 
 1887: 1;
 1888: __END__
 1889: 
 1890: =pod
 1891: 
 1892: =back
 1893: 
 1894: =cut
 1895: 
 1896: 
 1897: 

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