File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.222: download - view: text, annotated - select for diffs
Tue Jun 14 15:43:54 2005 UTC (18 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Saving my work

    1: # The LearningOnline Network with CAPA
    2: # Handler to set parameters for assessments
    3: #
    4: # $Id: lonparmset.pm,v 1.222 2005/06/14 15:43:54 www 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: use Apache::lonnavmaps;
   66: 
   67: # --- Caches local to lonparmset
   68: 
   69: my $parmhashid;
   70: my %parmhash;
   71: my $symbsid;
   72: my %symbs;
   73: my $rulesid;
   74: my %rules;
   75: 
   76: # --- end local caches
   77: 
   78: ##################################################
   79: ##################################################
   80: 
   81: =pod
   82: 
   83: =item parmval
   84: 
   85: Figure out a cascading parameter.
   86: 
   87: Inputs:  $what - a parameter spec (incluse part info and name I.E. 0.weight)
   88:          $id   - a bighash Id number
   89:          $def  - the resource's default value   'stupid emacs
   90: 
   91: 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
   92: 
   93: 11 - General Course
   94: 10 - Map or Folder level in course
   95: 9- resource default
   96: 8- map default
   97: 7 - resource level in course
   98: 6 - General for section
   99: 5 - Map or Folder level for section
  100: 4 - resource level in section
  101: 3 - General for specific student
  102: 2 - Map or Folder level for specific student
  103: 1 - resource level for specific student
  104: 
  105: =cut
  106: 
  107: ##################################################
  108: sub parmval {
  109:     my ($what,$id,$def,$uname,$udom,$csec)=@_;
  110:     return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec);
  111: }
  112: 
  113: sub parmval_by_symb {
  114:     my ($what,$symb,$def,$uname,$udom,$csec)=@_;
  115: # load caches
  116: 
  117:     &cacheparmhash();
  118: 
  119:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  120:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  121:     my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
  122:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
  123: 
  124: 
  125:     my $result='';
  126:     my @outpar=();
  127: # ----------------------------------------------------- Cascading lookup scheme
  128:     my $map=(&Apache::lonnet::decode_symb($symb))[0];    
  129: 
  130:     my $symbparm=$symb.'.'.$what;
  131:     my $mapparm=$map.'___(all).'.$what;
  132: 
  133:     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
  134:     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  135:     my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  136: 
  137:     my $courselevel=$env{'request.course.id'}.'.'.$what;
  138:     my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
  139:     my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
  140: 
  141: 
  142: 
  143: # --------------------------------------------------------- first, check course
  144: 
  145:     if (defined($$courseopt{$courselevel})) {
  146: 	$outpar[11]=$$courseopt{$courselevel};
  147: 	$result=11;
  148:     }
  149: 
  150:     if (defined($$courseopt{$courselevelm})) {
  151: 	$outpar[10]=$$courseopt{$courselevelm};
  152: 	$result=10;
  153:     }
  154: 
  155: # ------------------------------------------------------- second, check default
  156: 
  157:     if (defined($def)) { $outpar[9]=$def; $result=9; }
  158: 
  159: # ------------------------------------------------------ third, check map parms
  160: 
  161:     my $thisparm=$parmhash{$symbparm};
  162:     if (defined($thisparm)) { $outpar[8]=$thisparm; $result=8; }
  163: 
  164:     if (defined($$courseopt{$courselevelr})) {
  165: 	$outpar[7]=$$courseopt{$courselevelr};
  166: 	$result=7;
  167:     }
  168: 
  169: # ------------------------------------------------------ fourth, back to course
  170:     if (defined($csec)) {
  171:         if (defined($$courseopt{$seclevel})) {
  172: 	    $outpar[6]=$$courseopt{$seclevel};
  173: 	    $result=6;
  174: 	}
  175:         if (defined($$courseopt{$seclevelm})) {
  176: 	    $outpar[5]=$$courseopt{$seclevelm};
  177: 	    $result=5;
  178: 	}
  179: 
  180:         if (defined($$courseopt{$seclevelr})) {
  181: 	    $outpar[4]=$$courseopt{$seclevelr};
  182: 	    $result=4;
  183: 	}
  184:     }
  185: 
  186: # ---------------------------------------------------------- fifth, check user
  187: 
  188:     if (defined($uname)) {
  189: 	if (defined($$useropt{$courselevel})) {
  190: 	    $outpar[3]=$$useropt{$courselevel};
  191: 	    $result=3;
  192: 	}
  193: 
  194: 	if (defined($$useropt{$courselevelm})) {
  195: 	    $outpar[2]=$$useropt{$courselevelm};
  196: 	    $result=2;
  197: 	}
  198: 
  199: 	if (defined($$useropt{$courselevelr})) {
  200: 	    $outpar[1]=$$useropt{$courselevelr};
  201: 	    $result=1;
  202: 	}
  203:     }
  204:     return ($result,@outpar);
  205: }
  206: 
  207: sub resetparmhash {
  208:     $parmhashid='';
  209: }
  210: 
  211: sub cacheparmhash {
  212:     if ($parmhashid eq  $env{'request.course.fn'}) { return; }
  213:     my %parmhashfile;
  214:     if (tie(%parmhashfile,'GDBM_File',
  215: 	      $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
  216: 	%parmhash=%parmhashfile;
  217: 	untie %parmhashfile;
  218: 	$parmhashid=$env{'request.course.fn'};
  219:     }
  220: }
  221: 
  222: sub resetsymbcache {
  223:     $symbsid='';
  224: }
  225: 
  226: sub symbcache {
  227:     my $id=shift;
  228:     if ($symbsid ne $env{'request.course.id'}) {
  229: 	%symbs=();
  230:     }
  231:     unless ($symbs{$id}) {
  232: 	my $navmap = Apache::lonnavmaps::navmap->new();
  233: 	if ($id=~/\./) {
  234: 	    my $resource=$navmap->getById($id);
  235: 	    $symbs{$id}=$resource->symb();
  236: 	} else {
  237: 	    my $resource=$navmap->getByMapPc($id);
  238: 	    $symbs{$id}=&Apache::lonnet::declutter($resource->src());
  239: 	}
  240: 	$symbsid=$env{'request.course.id'};
  241:     }
  242:     return $symbs{$id};
  243: }
  244: 
  245: sub resetrulescache {
  246:     $rulesid='';
  247: }
  248: 
  249: sub rulescache {
  250:     my $id=shift;
  251:     if ($rulesid ne $env{'request.course.id'}) {
  252: 	%rules=();
  253:     }
  254:     unless ($rules{$id}) {
  255: 	my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  256: 	my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
  257: 	my %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
  258: 	$rulesid=$env{'request.course.id'};
  259:     }
  260:     return $rules{$id};
  261: }
  262: 
  263: ##################################################
  264: ##################################################
  265: #
  266: # Store a parameter by ID
  267: #
  268: # Takes
  269: # - resource id
  270: # - name of parameter
  271: # - level
  272: # - new value
  273: # - new type
  274: # - username
  275: # - userdomain
  276: 
  277: sub storeparm {
  278:     my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
  279:     &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
  280: }
  281: 
  282: #
  283: # Store a parameter by symb
  284: #
  285: # Takes
  286: # - symb
  287: # - name of parameter
  288: # - level
  289: # - new value
  290: # - new type
  291: # - username
  292: # - userdomain
  293: 
  294: sub storeparm_by_symb {
  295: # ---------------------------------------------------------- Get symb, map, etc
  296:     my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
  297: # ---------------------------------------------------------- Construct prefixes
  298:     $spnam=~s/\_([^\_]+)$/\.$1/;
  299:     my $map=(&Apache::lonnet::decode_symb($symb))[0];    
  300:     my $symbparm=$symb.'.'.$spnam;
  301:     my $mapparm=$map.'___(all).'.$spnam;
  302: 
  303:     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
  304:     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  305:     my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  306:     
  307:     my $courselevel=$env{'request.course.id'}.'.'.$spnam;
  308:     my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
  309:     my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
  310:     
  311:     my $storeunder='';
  312:     if (($snum==11) || ($snum==3)) { $storeunder=$courselevel; }
  313:     if (($snum==10) || ($snum==2)) { $storeunder=$courselevelm; }
  314:     if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
  315:     if ($snum==6) { $storeunder=$seclevel; }
  316:     if ($snum==5) { $storeunder=$seclevelm; }
  317:     if ($snum==4) { $storeunder=$seclevelr; }
  318:     
  319:     my $delete;
  320:     if ($nval eq '') { $delete=1;}
  321:     my %storecontent = ($storeunder         => $nval,
  322: 			$storeunder.'.type' => $ntype);
  323:     my $reply='';
  324:     if ($snum>3) {
  325: # ---------------------------------------------------------------- Store Course
  326: #
  327: 	my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  328: 	my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  329: # Expire sheets
  330: 	&Apache::lonnet::expirespread('','','studentcalc');
  331: 	if (($snum==7) || ($snum==4)) {
  332: 	    &Apache::lonnet::expirespread('','','assesscalc',$symb);
  333: 	} elsif (($snum==8) || ($snum==5)) {
  334: 	    &Apache::lonnet::expirespread('','','assesscalc',$map);
  335: 	} else {
  336: 	    &Apache::lonnet::expirespread('','','assesscalc');
  337: 	}
  338: # Store parameter
  339: 	if ($delete) {
  340: 	    $reply=&Apache::lonnet::del
  341: 		('resourcedata',[keys(%storecontent)],$cdom,$cnum);
  342: 	} else {
  343: 	    $reply=&Apache::lonnet::cput
  344: 		('resourcedata',\%storecontent,$cdom,$cnum);
  345: 	}
  346: 	&Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
  347:     } else {
  348: # ------------------------------------------------------------------ Store User
  349: #
  350: # Expire sheets
  351: 	&Apache::lonnet::expirespread($uname,$udom,'studentcalc');
  352: 	if ($snum==1) {
  353: 	    &Apache::lonnet::expirespread
  354: 		($uname,$udom,'assesscalc',$symb);
  355: 	} elsif ($snum==2) {
  356: 	    &Apache::lonnet::expirespread
  357: 		($uname,$udom,'assesscalc',$map);
  358: 	} else {
  359: 	    &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
  360: 	}
  361: # Store parameter
  362: 	if ($delete) {
  363: 	    $reply=&Apache::lonnet::del
  364: 		('resourcedata',[keys(%storecontent)],$udom,$uname);
  365: 	} else {
  366: 	    $reply=&Apache::lonnet::cput
  367: 		('resourcedata',\%storecontent,$udom,$uname);
  368: 	}
  369: 	&Apache::lonnet::devalidateuserresdata($uname,$udom);
  370:     }
  371:     
  372:     if ($reply=~/^error\:(.*)/) {
  373: 	return "<font color=red>Write Error: $1</font>";
  374:     }
  375:     return '';
  376: }
  377: 
  378: ##################################################
  379: ##################################################
  380: 
  381: =pod
  382: 
  383: =item valout
  384: 
  385: Format a value for output.
  386: 
  387: Inputs:  $value, $type
  388: 
  389: Returns: $value, formatted for output.  If $type indicates it is a date,
  390: localtime($value) is returned.
  391: 
  392: =cut
  393: 
  394: ##################################################
  395: ##################################################
  396: sub valout {
  397:     my ($value,$type)=@_;
  398:     my $result = '';
  399:     # Values of zero are valid.
  400:     if (! $value && $value ne '0') {
  401: 	$result = '&nbsp;&nbsp;';
  402:     } else {
  403:         if ($type eq 'date_interval') {
  404:             my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
  405:             $year=$year-70;
  406:             $mday--;
  407:             if ($year) {
  408: 		$result.=$year.' yrs ';
  409:             }
  410:             if ($mon) {
  411: 		$result.=$mon.' mths ';
  412:             }
  413:             if ($mday) {
  414: 		$result.=$mday.' days ';
  415:             }
  416:             if ($hour) {
  417: 		$result.=$hour.' hrs ';
  418:             }
  419:             if ($min) {
  420: 		$result.=$min.' mins ';
  421:             }
  422:             if ($sec) {
  423: 		$result.=$sec.' secs ';
  424:             }
  425:             $result=~s/\s+$//;
  426:         } elsif (&isdateparm($type)) {
  427:             $result = localtime($value);
  428:         } else {
  429:             $result = $value;
  430:         }
  431:     }
  432:     return $result;
  433: }
  434: 
  435: ##################################################
  436: ##################################################
  437: 
  438: =pod
  439: 
  440: =item plink
  441: 
  442: Produces a link anchor.
  443: 
  444: Inputs: $type,$dis,$value,$marker,$return,$call
  445: 
  446: Returns: scalar with html code for a link which will envoke the 
  447: javascript function 'pjump'.
  448: 
  449: =cut
  450: 
  451: ##################################################
  452: ##################################################
  453: sub plink {
  454:     my ($type,$dis,$value,$marker,$return,$call)=@_;
  455:     my $winvalue=$value;
  456:     unless ($winvalue) {
  457: 	if (&isdateparm($type)) {
  458:             $winvalue=$env{'form.recent_'.$type};
  459:         } else {
  460:             $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
  461:         }
  462:     }
  463: 
  464: 
  465:     return 
  466: 	'<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
  467: 	    .$marker."','".$return."','".$call."'".');">'.
  468: 		&valout($value,$type).'</a><a name="'.$marker.'"></a>';
  469: }
  470: 
  471: sub startpage {
  472:     my $r=shift;
  473: 
  474:     my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','',
  475:                                             'onUnload="pclose()"');
  476:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Table Mode Parameter Setting');
  477:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
  478:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  479:     my $html=&Apache::lonxml::xmlbegin();
  480:     $r->print(<<ENDHEAD);
  481: $html
  482: <head>
  483: <title>LON-CAPA Course Parameters</title>
  484: <script>
  485: 
  486:     function pclose() {
  487:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  488:                  "height=350,width=350,scrollbars=no,menubar=no");
  489:         parmwin.close();
  490:     }
  491: 
  492:     $pjump_def
  493: 
  494:     function psub() {
  495:         pclose();
  496:         if (document.parmform.pres_marker.value!='') {
  497:             document.parmform.action+='#'+document.parmform.pres_marker.value;
  498:             var typedef=new Array();
  499:             typedef=document.parmform.pres_type.value.split('_');
  500:            if (document.parmform.pres_type.value!='') {
  501:             if (typedef[0]=='date') {
  502:                 eval('document.parmform.recent_'+
  503:                      document.parmform.pres_type.value+
  504: 		     '.value=document.parmform.pres_value.value;');
  505:             } else {
  506:                 eval('document.parmform.recent_'+typedef[0]+
  507: 		     '.value=document.parmform.pres_value.value;');
  508:             }
  509: 	   }
  510:             document.parmform.submit();
  511:         } else {
  512:             document.parmform.pres_value.value='';
  513:             document.parmform.pres_marker.value='';
  514:         }
  515:     }
  516: 
  517:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
  518:         var options = "width=" + w + ",height=" + h + ",";
  519:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  520:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
  521:         var newWin = window.open(url, wdwName, options);
  522:         newWin.focus();
  523:     }
  524: </script>
  525: $selscript
  526: </head>
  527: $bodytag
  528: $breadcrumbs
  529: <form method="post" action="/adm/parmset?action=settable" name="parmform">
  530: <input type="hidden" value='' name="pres_value">
  531: <input type="hidden" value='' name="pres_type">
  532: <input type="hidden" value='' name="pres_marker">
  533: <input type="hidden" value='1' name="prevvisit">
  534: ENDHEAD
  535: }
  536: 
  537: 
  538: sub print_row {
  539:     my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
  540: 	$defbgtwo,$parmlev,$uname,$udom,$csec)=@_;
  541: # get the values for the parameter in cascading order
  542: # empty levels will remain empty
  543:     my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
  544: 				  $rid,$$default{$which},$uname,$udom,$csec);
  545: # get the type for the parameters
  546: # problem: these may not be set for all levels
  547:     my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
  548:                                           $$name{$which}.'.type',
  549: 				  $rid,$$defaulttype{$which},$uname,$udom,$csec);
  550: # cascade down manually
  551:     my $cascadetype=$$defaulttype{$which};
  552:     for (my $i=11;$i>0;$i--) {
  553: 	 if ($typeoutpar[$i]) { 
  554:             $cascadetype=$typeoutpar[$i];
  555: 	} else {
  556:             $typeoutpar[$i]=$cascadetype;
  557:         }
  558:     }
  559:     my $parm=$$display{$which};
  560: 
  561:     if ($parmlev eq 'full') {
  562:         $r->print('<td bgcolor='.$defbgtwo.' align="center">'
  563:                   .$$part{$which}.'</td>');
  564:     } else {    
  565:         $parm=~s|\[.*\]\s||g;
  566:     }
  567: 
  568:     $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
  569:    
  570:     my $thismarker=$which;
  571:     $thismarker=~s/^parameter\_//;
  572:     my $mprefix=$rid.'&'.$thismarker.'&';
  573: 
  574:     if ($parmlev eq 'general') {
  575: 
  576:         if ($uname) {
  577:             &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  578:         } elsif ($csec) {
  579:             &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); 
  580:         } else {
  581:             &print_td($r,11,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); 
  582:         }
  583:     } elsif ($parmlev eq 'map') {
  584: 
  585:         if ($uname) {
  586:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  587:         } elsif ($csec) {
  588:             &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  589:         } else {
  590:             &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  591:         }
  592:     } else {
  593: 
  594:         &print_td($r,11,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  595: 
  596: 	&print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  597: 	&print_td($r,9,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  598: 	&print_td($r,8,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  599: 	&print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  600: 	
  601: 	if ($csec) {
  602: 	    &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  603: 	    &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  604: 	    &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  605: 	}
  606: 	if ($uname) {
  607: 	    &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  608: 	    &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  609: 	    &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  610: 	}
  611: 
  612:     } # end of $parmlev if/else
  613: 
  614:     $r->print('<td bgcolor=#CCCCFF align="center">'.
  615:                   &valout($outpar[$result],$typeoutpar[$result]).'</td>');
  616: 
  617:     if ($parmlev eq 'full') {
  618:         my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
  619:                                         '.'.$$name{$which},$$symbp{$rid});
  620:         my $sessionvaltype=$typeoutpar[$result];
  621:         if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
  622:         $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
  623:                   &valout($sessionval,$sessionvaltype).'&nbsp;'.
  624:                   '</font></td>');
  625:     }
  626:     $r->print('</tr>');
  627:     $r->print("\n");
  628: }
  629: 
  630: sub print_td {
  631:     my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
  632:     $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
  633:               ' align="center">');
  634:     if ($which<8 || $which > 9) {
  635: 	$r->print(&plink($$typeoutpar[$which],
  636: 			 $$display{$value},$$outpar[$which],
  637: 			 $mprefix."$which",'parmform.pres','psub'));
  638:     } else {
  639: 	$r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
  640:     }
  641:     $r->print('</td>'."\n");
  642: }
  643: 
  644: 
  645: =pod
  646: 
  647: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
  648: 
  649: Input: See list below:
  650: 
  651: =over 4
  652: 
  653: =item B<ids>: An array that will contain all of the ids in the course.
  654: 
  655: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
  656: 
  657: =item B<keyp>: hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
  658: 
  659: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
  660: 
  661: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
  662: 
  663: =item B<allkeys>: hash, full key to part->display value (what's display value?)
  664: 
  665: =item B<allmaps>: hash, ???
  666: 
  667: =item B<fcat>: ???
  668: 
  669: =item B<defp>: hash, ???
  670: 
  671: =item B<mapp>: ??
  672: 
  673: =item B<symbp>: hash, id->full sym?
  674: 
  675: =back
  676: 
  677: =cut
  678: 
  679: sub extractResourceInformation {
  680:     my $ids = shift;
  681:     my $typep = shift;
  682:     my $keyp = shift;
  683:     my $allparms = shift;
  684:     my $allparts = shift;
  685:     my $allmaps = shift;
  686:     my $mapp = shift;
  687:     my $symbp = shift;
  688:     my $maptitles=shift;
  689:     my $uris=shift;
  690:     my $keyorder=shift;
  691:     my $defkeytype=shift;
  692: 
  693:     my $keyordercnt=100;
  694: 
  695:     my $navmap = Apache::lonnavmaps::navmap->new();
  696:     my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
  697:     foreach my $resource (@allres) {
  698: 	my $id=$resource->id();
  699:         my ($mapid,$resid)=split(/\./,$id);
  700: 	if ($mapid eq '0') { next; }
  701: 	$$ids[$#$ids+1]=$id;
  702: 	my $srcf=$resource->src();
  703: 	$srcf=~/\.(\w+)$/;
  704: 	$$typep{$id}=$1;
  705: 	$$keyp{$id}='';
  706:         $$uris{$id}=$srcf;
  707: 	foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
  708: 	    if ($_=~/^parameter\_(.*)/) {
  709: 		my $key=$_;
  710: # Hidden parameters
  711: 		if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm') {
  712: 		    next;
  713: 		}
  714: 		my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
  715: 		my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
  716: 		my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
  717: #
  718: # allparms is a hash of parameter names
  719: #
  720: 		my $parmdis = $display;
  721: 		$parmdis =~ s/\[Part.*$//g;
  722:                 $$allparms{$name}=$parmdis;
  723: 		$$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type');
  724: #
  725: # allparts is a hash of all parts
  726: #
  727: 		$$allparts{$part} = "Part: $part";
  728: #
  729: # Remember all keys going with this resource
  730: #
  731: 		if ($$keyp{$id}) {
  732: 		    $$keyp{$id}.=','.$key;
  733: 		} else {
  734: 		    $$keyp{$id}=$key;
  735: 		}
  736: #
  737: # Put in order
  738: # 
  739:                 unless ($$keyorder{$key}) {
  740:                     $$keyorder{$key}=$keyordercnt;
  741:                     $keyordercnt++;
  742: 		}
  743: 
  744: 	    }
  745: 	}
  746: 	$$mapp{$id}=
  747: 	    &Apache::lonnet::declutter($resource->enclosing_map_src());
  748: 	$$mapp{$mapid}=$$mapp{$id};
  749: 	$$allmaps{$mapid}=$$mapp{$id};
  750: 	if ($mapid eq '1') {
  751: 	    $$maptitles{$mapid}='Main Course Documents';
  752: 	} else {
  753: 	    $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));
  754: 	}
  755: 	$$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
  756: 	$$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
  757: 	$$symbp{$mapid}=$$mapp{$id}.'___(all)';
  758:     }
  759: }
  760: 
  761: 
  762: ##################################################
  763: ##################################################
  764: 
  765: sub isdateparm {
  766:     my $type=shift;
  767:     return (($type=~/^date/) && (!($type eq 'date_interval')));
  768: }
  769: 
  770: sub parmmenu {
  771:     my ($r,$allparms,$pscat,$keyorder)=@_;
  772:     my $tempkey;
  773:     $r->print(<<ENDSCRIPT);
  774: <script type="text/javascript">
  775:     function checkall(value, checkName) {
  776: 	for (i=0; i<document.forms.parmform.elements.length; i++) {
  777:             ele = document.forms.parmform.elements[i];
  778:             if (ele.name == checkName) {
  779:                 document.forms.parmform.elements[i].checked=value;
  780:             }
  781:         }
  782:     }
  783: 
  784:     function checkthis(thisvalue, checkName) {
  785: 	for (i=0; i<document.forms.parmform.elements.length; i++) {
  786:             ele = document.forms.parmform.elements[i];
  787:             if (ele.name == checkName) {
  788: 		if (ele.value == thisvalue) {
  789: 		    document.forms.parmform.elements[i].checked=true;
  790: 		}
  791:             }
  792:         }
  793:     }
  794: 
  795:     function checkdates() {
  796: 	checkthis('duedate','pscat');
  797:  	checkthis('opendate','pscat');
  798: 	checkthis('answerdate','pscat');
  799:     }
  800: 
  801:     function checkdisset() {
  802: 	checkthis('discussend','pscat');
  803:  	checkthis('discusshide','pscat');
  804:     }
  805: 
  806:     function checkcontdates() {
  807: 	checkthis('contentopen','pscat');
  808:  	checkthis('contentclose','pscat');
  809:     }
  810:  
  811: 
  812:     function checkvisi() {
  813: 	checkthis('hiddenresource','pscat');
  814:  	checkthis('encrypturl','pscat');
  815: 	checkthis('problemstatus','pscat');
  816: 	checkthis('contentopen','pscat');
  817: 	checkthis('opendate','pscat');
  818:     }
  819: 
  820:     function checkparts() {
  821: 	checkthis('hiddenparts','pscat');
  822: 	checkthis('display','pscat');
  823: 	checkthis('ordered','pscat');
  824:     }
  825: 
  826:     function checkstandard() {
  827:         checkall(false,'pscat');
  828: 	checkdates();
  829: 	checkthis('weight','pscat');
  830: 	checkthis('maxtries','pscat');
  831:     }
  832: 
  833: </script>
  834: ENDSCRIPT
  835:     $r->print();
  836:     $r->print("\n<table><tr>");
  837:     my $cnt=0;
  838:     foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) {
  839: 	$r->print("\n<td><font size='-1'><input type='checkbox' name='pscat' ");
  840: 	$r->print('value="'.$tempkey.'"');
  841: 	if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
  842: 	    $r->print(' checked');
  843: 	}
  844: 	$r->print('>'.$$allparms{$tempkey}.'</font></td>');
  845:  	$cnt++;
  846:         if ($cnt==3) {
  847: 	    $r->print("</tr>\n<tr>");
  848: 	    $cnt=0;
  849: 	}
  850:     }
  851:     $r->print('
  852: </tr><tr><td>
  853: <a href="javascript:checkall(true, \'pscat\')">Select All</a><br />
  854: <a href="javascript:checkstandard()">Select Common Only</a>
  855: </td><td>
  856: <a href="javascript:checkdates()">Add Problem Dates</a>
  857: <a href="javascript:checkcontdates()">Add Content Dates</a><br />
  858: <a href="javascript:checkdisset()">Add Discussion Settings</a>
  859: <a href="javascript:checkvisi()">Add Visibilities</a><br />
  860: <a href="javascript:checkparts()">Add Part Parameters</a>
  861: </td><td>
  862: <a href="javascript:checkall(false, \'pscat\')">Unselect All</a>
  863: </td>
  864: ');
  865:     $r->print('</tr></table>');
  866: }
  867: 
  868: sub partmenu {
  869:     my ($r,$allparts,$psprt)=@_;
  870:     $r->print('<select multiple name="psprt" size="8">');
  871:     $r->print('<option value="all"');
  872:     $r->print(' selected') unless (@{$psprt});
  873:     $r->print('>'.&mt('All Parts').'</option>');
  874:     my %temphash=();
  875:     foreach (@{$psprt}) { $temphash{$_}=1; }
  876:     foreach my $tempkey (sort keys %{$allparts}) {
  877: 	unless ($tempkey =~ /\./) {
  878: 	    $r->print('<option value="'.$tempkey.'"');
  879: 	    if ($$psprt[0] eq "all" ||  $temphash{$tempkey}) {
  880: 		$r->print(' selected');
  881: 	    }
  882: 	    $r->print('>'.$$allparts{$tempkey}.'</option>');
  883: 	}
  884:     }
  885:     $r->print('</select>');
  886: }
  887: 
  888: sub usermenu {
  889:     my ($r,$uname,$id,$udom,$csec)=@_;
  890:     my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
  891:         &Apache::loncommon::selectstudent_link('parmform','uname','udom');
  892:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
  893:     my %lt=&Apache::lonlocal::texthash(
  894: 		    'sg'    => "Section/Group",
  895: 		    'fu'    => "For User",
  896: 		    'oi'    => "or ID",
  897: 		    'ad'    => "at Domain"
  898: 				       );
  899:     my %sectionhash=();
  900:     my $sections='';
  901:     if (&Apache::loncommon::get_sections(
  902:                  $env{'course.'.$env{'request.course.id'}.'.domain'},
  903:                  $env{'course.'.$env{'request.course.id'}.'.num'},
  904: 					 \%sectionhash)) {
  905:         $sections=$lt{'sg'}.': <select name="csec">';
  906: 	foreach ('',sort keys %sectionhash) {
  907: 	    $sections.='<option value="'.$_.'"'.
  908: 		($_ eq $csec?'selected="selected"':'').'>'.$_.'</option>';
  909:         }
  910:         $sections.='</select>';
  911:      }
  912:      $r->print(<<ENDMENU);
  913: <b>
  914: $sections
  915: <br />
  916: $lt{'fu'} 
  917: <input type="text" value="$uname" size="12" name="uname" />
  918: $lt{'oi'}
  919: <input type="text" value="$id" size="12" name="id" /> 
  920: $lt{'ad'}
  921: $chooseopt
  922: </b>
  923: ENDMENU
  924: }
  925: 
  926: sub displaymenu {
  927:     my ($r,$allparms,$allparts,$pscat,$psprt,$keyorder)=@_;
  928:     $r->print('<table border="1"><tr><th>'.&mt('Select Parameters to View').'</th><th>'.
  929: 	     &mt('Select Parts to View').'</th></tr><tr><td>');  
  930:     &parmmenu($r,$allparms,$pscat,$keyorder);
  931:     $r->print('</td><td>');
  932:     &partmenu($r,$allparts,$psprt);
  933:     $r->print('</td></tr></table>');
  934: }
  935: 
  936: sub mapmenu {
  937:     my ($r,$allmaps,$pschp,$maptitles)=@_;
  938:     $r->print(&mt('Select Enclosing Map or Folder').' ');
  939:     $r->print('<select name="pschp">');
  940:     $r->print('<option value="all">'.&mt('All Maps or Folders').'</option>');
  941:     foreach (sort {$$allmaps{$a} cmp $$allmaps{$b}} keys %{$allmaps}) {
  942: 	$r->print('<option value="'.$_.'"');
  943: 	if (($pschp eq $_)) { $r->print(' selected'); }
  944: 	$r->print('>'.$$maptitles{$_}.($$allmaps{$_}!~/^uploaded/?' ['.$$allmaps{$_}.']':'').'</option>');
  945:     }
  946:     $r->print("</select>");
  947: }
  948: 
  949: sub levelmenu {
  950:     my ($r,$alllevs,$parmlev)=@_;
  951:     $r->print(&mt('Select Parameter Level').
  952: 	      &Apache::loncommon::help_open_topic('Course_Parameter_Levels').' ');
  953:     $r->print('<select name="parmlev">');
  954:     foreach (reverse sort keys %{$alllevs}) {
  955: 	$r->print('<option value="'.$$alllevs{$_}.'"');
  956: 	if ($parmlev eq $$alllevs{$_}) {
  957: 	    $r->print(' selected'); 
  958: 	}
  959: 	$r->print('>'.$_.'</option>');
  960:     }
  961:     $r->print("</select>");
  962: }
  963: 
  964: 
  965: sub sectionmenu {
  966:     my ($r,$selectedsections)=@_;
  967:     my %sectionhash=();
  968: 
  969:     if (&Apache::loncommon::get_sections(
  970:                  $env{'course.'.$env{'request.course.id'}.'.domain'},
  971:                  $env{'course.'.$env{'request.course.id'}.'.num'},
  972: 					 \%sectionhash)) {
  973: 	$r->print('<select name="Section" multiple="true" size="8" >');
  974: 	foreach my $s ('all',sort keys %sectionhash) {
  975: 	    $r->print('    <option value="'.$s.'"');
  976: 	    foreach (@{$selectedsections}) {
  977: 		if ($s eq $_) {
  978: 		    $r->print(' selected');
  979: 		    last;
  980: 		}
  981: 	    }
  982: 	    $r->print('>'.$s."</option>\n");
  983: 	}
  984: 	$r->print("</select>\n");
  985:     }
  986: }
  987: 
  988: sub keysplit {
  989:     my $keyp=shift;
  990:     return (split(/\,/,$keyp));
  991: }
  992: 
  993: sub keysinorder {
  994:     my ($name,$keyorder)=@_;
  995:     return sort {
  996: 	$$keyorder{$a} <=> $$keyorder{$b};
  997:     } (keys %{$name});
  998: }
  999: 
 1000: sub keysindisplayorder {
 1001:     my ($name,$keyorder)=@_;
 1002:     return sort {
 1003: 	$$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
 1004:     } (keys %{$name});
 1005: }
 1006: 
 1007: sub sortmenu {
 1008:     my ($r,$sortorder)=@_;
 1009:     $r->print('<br /><input type="radio" name="sortorder" value="realmstudent"');
 1010:     if ($sortorder eq 'realmstudent') {
 1011:        $r->print(' checked="on"');
 1012:     }
 1013:     $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
 1014:     $r->print('<br /><input type="radio" name="sortorder" value="studentrealm"');
 1015:     if ($sortorder eq 'studentrealm') {
 1016:        $r->print(' checked="on"');
 1017:     }
 1018:     $r->print(' />'.&mt('Sort by student (group/section) first, then realm'));
 1019: }
 1020: 
 1021: sub standardkeyorder {
 1022:     return ('parameter_0_opendate' => 1,
 1023: 	    'parameter_0_duedate' => 2,
 1024: 	    'parameter_0_answerdate' => 3,
 1025: 	    'parameter_0_interval' => 4,
 1026: 	    'parameter_0_weight' => 5,
 1027: 	    'parameter_0_maxtries' => 6,
 1028: 	    'parameter_0_hinttries' => 7,
 1029: 	    'parameter_0_contentopen' => 8,
 1030: 	    'parameter_0_contentclose' => 9,
 1031: 	    'parameter_0_type' => 10,
 1032: 	    'parameter_0_problemstatus' => 11,
 1033: 	    'parameter_0_hiddenresource' => 12,
 1034: 	    'parameter_0_hiddenparts' => 13,
 1035: 	    'parameter_0_display' => 14,
 1036: 	    'parameter_0_ordered' => 15,
 1037: 	    'parameter_0_tol' => 16,
 1038: 	    'parameter_0_sig' => 17,
 1039: 	    'parameter_0_turnoffunit' => 18,
 1040:             'parameter_0_discussend' => 19,
 1041:             'parameter_0_discusshide' => 20);
 1042: }
 1043: 
 1044: ##################################################
 1045: ##################################################
 1046: 
 1047: =pod
 1048: 
 1049: =item assessparms
 1050: 
 1051: Show assessment data and parameters.  This is a large routine that should
 1052: be simplified and shortened... someday.
 1053: 
 1054: Inputs: $r
 1055: 
 1056: Returns: nothing
 1057: 
 1058: Variables used (guessed by Jeremy):
 1059: 
 1060: =over 4
 1061: 
 1062: =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.
 1063: 
 1064: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
 1065: 
 1066: =item B<allmaps>:
 1067: 
 1068: =back
 1069: 
 1070: =cut
 1071: 
 1072: ##################################################
 1073: ##################################################
 1074: sub assessparms {
 1075: 
 1076:     my $r=shift;
 1077: 
 1078:     my @ids=();
 1079:     my %symbp=();
 1080:     my %mapp=();
 1081:     my %typep=();
 1082:     my %keyp=();
 1083:     my %uris=();
 1084:     my %maptitles=();
 1085: 
 1086: # -------------------------------------------------------- Variable declaration
 1087: 
 1088:     my %allmaps=();
 1089:     my %alllevs=();
 1090: 
 1091:     my $uname;
 1092:     my $udom;
 1093:     my $uhome;
 1094:     my $csec;
 1095:  
 1096:     my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
 1097: 
 1098:     $alllevs{'Resource Level'}='full';
 1099:     $alllevs{'Map/Folder Level'}='map';
 1100:     $alllevs{'Course Level'}='general';
 1101: 
 1102:     my %allparms;
 1103:     my %allparts;
 1104: #
 1105: # Order in which these parameters will be displayed
 1106: #
 1107:     my %keyorder=&standardkeyorder();
 1108: 
 1109:     @ids=();
 1110:     %symbp=();
 1111:     %typep=();
 1112: 
 1113:     my $message='';
 1114: 
 1115:     $csec=$env{'form.csec'};
 1116: 
 1117:     if      ($udom=$env{'form.udom'}) {
 1118:     } elsif ($udom=$env{'request.role.domain'}) {
 1119:     } elsif ($udom=$env{'user.domain'}) {
 1120:     } else {
 1121: 	$udom=$r->dir_config('lonDefDomain');
 1122:     }
 1123: 
 1124:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
 1125:     my $pschp=$env{'form.pschp'};
 1126:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
 1127:     if (!@psprt) { $psprt[0]='0'; }
 1128: 
 1129:     my $pssymb='';
 1130:     my $parmlev='';
 1131:  
 1132:     unless ($env{'form.parmlev'}) {
 1133:         $parmlev = 'map';
 1134:     } else {
 1135:         $parmlev = $env{'form.parmlev'};
 1136:     }
 1137: 
 1138: # ----------------------------------------------- Was this started from grades?
 1139: 
 1140:     if (($env{'form.command'} eq 'set') && ($env{'form.url'})
 1141: 	&& (!$env{'form.dis'})) {
 1142: 	my $url=$env{'form.url'};
 1143: 	$url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
 1144: 	$pssymb=&Apache::lonnet::symbread($url);
 1145: 	if (!@pscat) { @pscat=('all'); }
 1146: 	$pschp='';
 1147:         $parmlev = 'full';
 1148:     } elsif ($env{'form.symb'}) {
 1149: 	$pssymb=$env{'form.symb'};
 1150: 	if (!@pscat) { @pscat=('all'); }
 1151: 	$pschp='';
 1152:         $parmlev = 'full';
 1153:     } else {
 1154: 	$env{'form.url'}='';
 1155:     }
 1156: 
 1157:     my $id=$env{'form.id'};
 1158:     if (($id) && ($udom)) {
 1159: 	$uname=(&Apache::lonnet::idget($udom,$id))[1];
 1160: 	if ($uname) {
 1161: 	    $id='';
 1162: 	} else {
 1163: 	    $message=
 1164: 		"<font color=red>".&mt("Unknown ID")." '$id' ".
 1165: 		&mt('at domain')." '$udom'</font>";
 1166: 	}
 1167:     } else {
 1168: 	$uname=$env{'form.uname'};
 1169:     }
 1170:     unless ($udom) { $uname=''; }
 1171:     $uhome='';
 1172:     if ($uname) {
 1173: 	$uhome=&Apache::lonnet::homeserver($uname,$udom);
 1174:         if ($uhome eq 'no_host') {
 1175: 	    $message=
 1176: 		"<font color=red>".&mt("Unknown user")." '$uname' ".
 1177: 		&mt("at domain")." '$udom'</font>";
 1178: 	    $uname='';
 1179:         } else {
 1180: 	    $csec=&Apache::lonnet::getsection($udom,$uname,
 1181: 					      $env{'request.course.id'});
 1182: 	    if ($csec eq '-1') {
 1183: 		$message="<font color=red>".
 1184: 		    &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
 1185: 		    &mt("not in this course")."</font>";
 1186: 		$uname='';
 1187: 		$csec=$env{'form.csec'};
 1188: 	    } else {
 1189: 		my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1190: 		      ('firstname','middlename','lastname','generation','id'));
 1191: 		$message="\n<p>\n".&mt("Full Name").": ".
 1192: 		    $name{'firstname'}.' '.$name{'middlename'}.' '
 1193: 			.$name{'lastname'}.' '.$name{'generation'}.
 1194: 			    "<br>\n".&mt('ID').": ".$name{'id'}.'<p>';
 1195: 	    }
 1196:         }
 1197:     }
 1198: 
 1199:     unless ($csec) { $csec=''; }
 1200: 
 1201: # --------------------------------------------------------- Get all assessments
 1202:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, 
 1203: 				\%mapp, \%symbp,\%maptitles,\%uris,
 1204: 				\%keyorder);
 1205: 
 1206:     $mapp{'0.0'} = '';
 1207:     $symbp{'0.0'} = '';
 1208: 
 1209: # ---------------------------------------------------------- Anything to store?
 1210:     if ($env{'form.pres_marker'}) {
 1211:         my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
 1212:         my @values=split(/\&\&\&/,$env{'form.pres_value'});
 1213:         my @types=split(/\&\&\&/,$env{'form.pres_type'});
 1214: 	for (my $i=0;$i<=$#markers;$i++) {
 1215: 	    $message.=&storeparm(split(/\&/,$markers[$i]),
 1216: 				 $values[$i],
 1217: 				 $types[$i],
 1218: 				 $uname,$udom,$csec);
 1219: 	}
 1220: # ---------------------------------------------------------------- Done storing
 1221: 	$message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
 1222:     }
 1223: #----------------------------------------------- if all selected, fill in array
 1224:     if ($pscat[0] eq "all") {@pscat = (keys %allparms);}
 1225:     if (!@pscat) { @pscat=('duedate','opendate','answerdate','weight','maxtries') }; 
 1226:     if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
 1227: # ------------------------------------------------------------------ Start page
 1228: 
 1229:     &startpage($r);
 1230: 
 1231:     foreach ('tolerance','date_default','date_start','date_end',
 1232: 	     'date_interval','int','float','string') {
 1233: 	$r->print('<input type="hidden" value="'.
 1234: 		  $env{'form.recent_'.$_}.'" name="recent_'.$_.'">');
 1235:     }
 1236:                         
 1237:     if (!$pssymb) {
 1238:         $r->print('<table border="1"><tr><td>');
 1239:         &levelmenu($r,\%alllevs,$parmlev);
 1240: 	if ($parmlev ne 'general') {
 1241:             $r->print('<td>');
 1242: 	    &mapmenu($r,\%allmaps,$pschp,\%maptitles);
 1243: 	    $r->print('</td>');
 1244: 	}
 1245:         $r->print('</td></tr></table>');
 1246: 	&displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder);
 1247:     } else {
 1248:         my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
 1249:         $r->print(&mt('Specific Resource').": ".$resource.
 1250:                   '<input type="hidden" value="'.$pssymb.'" name="symb"><br />');
 1251:     }
 1252:     &usermenu($r,$uname,$id,$udom,$csec);    
 1253: 
 1254:     $r->print('<p>'.$message.'</p>');
 1255: 
 1256:     $r->print('<br /><input type="submit" name="dis" value="'.&mt("Update Parameter Display").'" />');
 1257: 
 1258:     my @temp_pscat;
 1259:     map {
 1260:         my $cat = $_;
 1261:         push(@temp_pscat, map { $_.'.'.$cat } @psprt);
 1262:     } @pscat;
 1263: 
 1264:     @pscat = @temp_pscat;
 1265: 
 1266:     if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
 1267: # ----------------------------------------------------------------- Start Table
 1268:         my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
 1269:         my $csuname=$env{'user.name'};
 1270:         my $csudom=$env{'user.domain'};
 1271: 
 1272:         if ($parmlev eq 'full') {
 1273:            my $coursespan=$csec?8:5;
 1274:            $r->print('<p><table border=2>');
 1275:            $r->print('<tr><td colspan=5></td>');
 1276:            $r->print('<th colspan='.($coursespan).'>'.&mt('Any User').'</th>');
 1277:            if ($uname) {
 1278:                $r->print("<th colspan=3 rowspan=2>");
 1279:                $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
 1280:            }
 1281: 	   my %lt=&Apache::lonlocal::texthash(
 1282: 				  'pie'    => "Parameter in Effect",
 1283: 				  'csv'    => "Current Session Value",
 1284:                                   'at'     => 'at',
 1285:                                   'rl'     => "Resource Level",
 1286: 				  'ic'     => 'in Course',
 1287: 				  'aut'    => "Assessment URL and Title",
 1288: 				  'type'   => 'Type',
 1289: 				  'emof'   => "Enclosing Map or Folder",
 1290: 				  'part'   => 'Part',
 1291:                                   'pn'     => 'Parameter Name',
 1292: 				  'def'    => 'default',
 1293: 				  'femof'  => 'from Enclosing Map or Folder',
 1294: 				  'gen'    => 'general',
 1295: 				  'foremf' => 'for Enclosing Map or Folder',
 1296: 				  'fr'     => 'for Resource'
 1297: 					      );
 1298:            $r->print(<<ENDTABLETWO);
 1299: <th rowspan=3>$lt{'pie'}</th>
 1300: <th rowspan=3>$lt{'csv'}<br>($csuname $lt{'at'} $csudom)</th>
 1301: </tr><tr><td colspan=5></td><th colspan=2>$lt{'ic'}</th><th colspan=2>$lt{'rl'}</th>
 1302: <th colspan=1>$lt{'ic'}</th>
 1303: 
 1304: ENDTABLETWO
 1305:            if ($csec) {
 1306:                 $r->print("<th colspan=3>".
 1307: 			  &mt("in Section/Group")." $csec</th>");
 1308:            }
 1309:            $r->print(<<ENDTABLEHEADFOUR);
 1310: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
 1311: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
 1312: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
 1313: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
 1314: ENDTABLEHEADFOUR
 1315: 
 1316:            if ($csec) {
 1317:                $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
 1318:            }
 1319: 
 1320:            if ($uname) {
 1321:                $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
 1322:            }
 1323: 
 1324:            $r->print('</tr>');
 1325: 
 1326:            my $defbgone='';
 1327:            my $defbgtwo='';
 1328: 
 1329:            foreach (@ids) {
 1330: 
 1331:                 my $rid=$_;
 1332:                 my ($inmapid)=($rid=~/\.(\d+)$/);
 1333: 
 1334:                 if ((!$pssymb && 
 1335: 		     (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
 1336: 		    ||
 1337: 		    ($pssymb && $pssymb eq $symbp{$rid})) {
 1338: # ------------------------------------------------------ Entry for one resource
 1339:                     if ($defbgone eq '"#E0E099"') {
 1340:                         $defbgone='"#E0E0DD"';
 1341:                     } else {
 1342:                         $defbgone='"#E0E099"';
 1343:                     }
 1344:                     if ($defbgtwo eq '"#FFFF99"') {
 1345:                         $defbgtwo='"#FFFFDD"';
 1346:                     } else {
 1347:                         $defbgtwo='"#FFFF99"';
 1348:                     }
 1349:                     my $thistitle='';
 1350:                     my %name=   ();
 1351:                     undef %name;
 1352:                     my %part=   ();
 1353:                     my %display=();
 1354:                     my %type=   ();
 1355:                     my %default=();
 1356:                     my $uri=&Apache::lonnet::declutter($uris{$rid});
 1357: 
 1358:                     foreach (&keysplit($keyp{$rid})) {
 1359:                         my $tempkeyp = $_;
 1360:                         if (grep $_ eq $tempkeyp, @catmarker) {
 1361:                           $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
 1362:                           $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
 1363:                           $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
 1364:                           unless ($display{$_}) { $display{$_}=''; }
 1365:                           $display{$_}.=' ('.$name{$_}.')';
 1366:                           $default{$_}=&Apache::lonnet::metadata($uri,$_);
 1367:                           $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
 1368:                           $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
 1369:                         }
 1370:                     }
 1371:                     my $totalparms=scalar keys %name;
 1372:                     if ($totalparms>0) {
 1373:                         my $firstrow=1;
 1374: 			my $title=&Apache::lonnet::gettitle($uri);
 1375:                         $r->print('<tr><td bgcolor='.$defbgone.
 1376:                              ' rowspan='.$totalparms.
 1377:                              '><tt><font size=-1>'.
 1378:                              join(' / ',split(/\//,$uri)).
 1379:                              '</font></tt><p><b>'.
 1380:                              "<a href=\"javascript:openWindow('".
 1381: 				  &Apache::lonnet::clutter($uri).
 1382:                              "', 'metadatafile', '450', '500', 'no', 'yes')\";".
 1383:                              " TARGET=_self>$title");
 1384: 
 1385:                         if ($thistitle) {
 1386:                             $r->print(' ('.$thistitle.')');
 1387:                         }
 1388:                         $r->print('</a></b></td>');
 1389:                         $r->print('<td bgcolor='.$defbgtwo.
 1390:                                       ' rowspan='.$totalparms.'>'.$typep{$rid}.
 1391:                                       '</td>');
 1392: 
 1393:                         $r->print('<td bgcolor='.$defbgone.
 1394:                                       ' rowspan='.$totalparms.
 1395:                                       '><tt><font size=-1>');
 1396: 
 1397:                         $r->print(' / res / ');
 1398:                         $r->print(join(' / ', split(/\//,$mapp{$rid})));
 1399: 
 1400:                         $r->print('</font></tt></td>');
 1401: 
 1402:                         foreach (&keysinorder(\%name,\%keyorder)) {
 1403:                             unless ($firstrow) {
 1404:                                 $r->print('<tr>');
 1405:                             } else {
 1406:                                 undef $firstrow;
 1407:                             }
 1408: 
 1409:                             &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
 1410:                                        \%type,\%display,$defbgone,$defbgtwo,
 1411:                                        $parmlev,$uname,$udom,$csec);
 1412:                         }
 1413:                     }
 1414:                 }
 1415:             } # end foreach ids
 1416: # -------------------------------------------------- End entry for one resource
 1417:             $r->print('</table>');
 1418:         } # end of  full
 1419: #--------------------------------------------------- Entry for parm level map
 1420:         if ($parmlev eq 'map') {
 1421:             my $defbgone = '"E0E099"';
 1422:             my $defbgtwo = '"FFFF99"';
 1423: 
 1424:             my %maplist;
 1425: 
 1426:             if ($pschp eq 'all') {
 1427:                 %maplist = %allmaps; 
 1428:             } else {
 1429:                 %maplist = ($pschp => $mapp{$pschp});
 1430:             }
 1431: 
 1432: #-------------------------------------------- for each map, gather information
 1433:             my $mapid;
 1434: 	    foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
 1435:                 my $maptitle = $maplist{$mapid};
 1436: 
 1437: #-----------------------  loop through ids and get all parameter types for map
 1438: #-----------------------------------------          and associated information
 1439:                 my %name = ();
 1440:                 my %part = ();
 1441:                 my %display = ();
 1442:                 my %type = ();
 1443:                 my %default = ();
 1444:                 my $map = 0;
 1445: 
 1446: #		$r->print("Catmarker: @catmarker<br />\n");
 1447:                
 1448:                 foreach (@ids) {
 1449:                   ($map)=(/([\d]*?)\./);
 1450:                   my $rid = $_;
 1451:         
 1452: #                  $r->print("$mapid:$map:   $rid <br /> \n");
 1453: 
 1454:                   if ($map eq $mapid) {
 1455:                     my $uri=&Apache::lonnet::declutter($uris{$rid});
 1456: #                    $r->print("Keys: $keyp{$rid} <br />\n");
 1457: 
 1458: #--------------------------------------------------------------------
 1459: # @catmarker contains list of all possible parameters including part #s
 1460: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1461: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1462: # When storing information, store as part 0
 1463: # When requesting information, request from full part
 1464: #-------------------------------------------------------------------
 1465:                     foreach (&keysplit($keyp{$rid})) {
 1466:                       my $tempkeyp = $_;
 1467:                       my $fullkeyp = $tempkeyp;
 1468:                       $tempkeyp =~ s/_\w+_/_0_/;
 1469:                       
 1470:                       if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1471:                         $part{$tempkeyp}="0";
 1472:                         $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1473:                         $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1474:                         unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1475:                         $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1476:                         $display{$tempkeyp} =~ s/_\w+_/_0_/;
 1477:                         $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1478:                         $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1479:                       }
 1480:                     } # end loop through keys
 1481:                   }
 1482:                 } # end loop through ids
 1483:                                  
 1484: #---------------------------------------------------- print header information
 1485:                 my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
 1486:                 my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
 1487:                 $r->print(<<ENDMAPONE);
 1488: <center><h4>
 1489: Set Defaults for All Resources in $foldermap<br />
 1490: <font color="red"><i>$showtitle</i></font><br />
 1491: Specifically for
 1492: ENDMAPONE
 1493:                 if ($uname) {
 1494:                     my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1495:                       ('firstname','middlename','lastname','generation', 'id'));
 1496:                     my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1497:                            .$name{'lastname'}.' '.$name{'generation'};
 1498:                     $r->print(&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
 1499:                         &mt('in')." \n");
 1500:                 } else {
 1501:                     $r->print("<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n");
 1502:                 }
 1503:             
 1504:                 if ($csec) {$r->print(&mt("Section")." <font color=\"red\"><i>$csec</i></font> ".
 1505: 				      &mt('of')." \n")};
 1506: 
 1507:                 $r->print("<font color=\"red\"><i>$coursename</i></font><br />");
 1508:                 $r->print("</h4>\n");
 1509: #---------------------------------------------------------------- print table
 1510:                 $r->print('<p><table border="2">');
 1511:                 $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
 1512:                 $r->print('<th>'.&mt('Default Value').'</th>');
 1513:                 $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
 1514: 
 1515: 	        foreach (&keysinorder(\%name,\%keyorder)) {
 1516:                     $r->print('<tr>');
 1517:                     &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
 1518:                            \%type,\%display,$defbgone,$defbgtwo,
 1519:                            $parmlev,$uname,$udom,$csec);
 1520:                 }
 1521:                 $r->print("</table></center>");
 1522:             } # end each map
 1523:         } # end of $parmlev eq map
 1524: #--------------------------------- Entry for parm level general (Course level)
 1525:         if ($parmlev eq 'general') {
 1526:             my $defbgone = '"E0E099"';
 1527:             my $defbgtwo = '"FFFF99"';
 1528: 
 1529: #-------------------------------------------- for each map, gather information
 1530:             my $mapid="0.0";
 1531: #-----------------------  loop through ids and get all parameter types for map
 1532: #-----------------------------------------          and associated information
 1533:             my %name = ();
 1534:             my %part = ();
 1535:             my %display = ();
 1536:             my %type = ();
 1537:             my %default = ();
 1538:                
 1539:             foreach (@ids) {
 1540:                 my $rid = $_;
 1541:         
 1542:                 my $uri=&Apache::lonnet::declutter($uris{$rid});
 1543: 
 1544: #--------------------------------------------------------------------
 1545: # @catmarker contains list of all possible parameters including part #s
 1546: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1547: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1548: # When storing information, store as part 0
 1549: # When requesting information, request from full part
 1550: #-------------------------------------------------------------------
 1551:                 foreach (&keysplit($keyp{$rid})) {
 1552:                   my $tempkeyp = $_;
 1553:                   my $fullkeyp = $tempkeyp;
 1554:                   $tempkeyp =~ s/_\w+_/_0_/;
 1555:                   if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1556:                     $part{$tempkeyp}="0";
 1557:                     $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1558:                     $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1559:                     unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1560:                     $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1561:                     $display{$tempkeyp} =~ s/_\w+_/_0_/;
 1562:                     $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1563:                     $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1564:                   }
 1565:                 } # end loop through keys
 1566:             } # end loop through ids
 1567:                                  
 1568: #---------------------------------------------------- print header information
 1569: 	    my $setdef=&mt("Set Defaults for All Resources in Course");
 1570:             $r->print(<<ENDMAPONE);
 1571: <center><h4>$setdef
 1572: <font color="red"><i>$coursename</i></font><br />
 1573: ENDMAPONE
 1574:             if ($uname) {
 1575:                 my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1576:                   ('firstname','middlename','lastname','generation', 'id'));
 1577:                 my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1578:                        .$name{'lastname'}.' '.$name{'generation'};
 1579:                 $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
 1580:             } else {
 1581:                 $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
 1582:             }
 1583:             
 1584:             if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
 1585:             $r->print("</h4>\n");
 1586: #---------------------------------------------------------------- print table
 1587:             $r->print('<p><table border="2">');
 1588:             $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
 1589:             $r->print('<th>'.&mt('Default Value').'</th>');
 1590:             $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
 1591: 
 1592: 	    foreach (&keysinorder(\%name,\%keyorder)) {
 1593:                 $r->print('<tr>');
 1594:                 &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
 1595:                        \%type,\%display,$defbgone,$defbgtwo,$parmlev,$uname,$udom,$csec);
 1596:             }
 1597:             $r->print("</table></center>");
 1598:         } # end of $parmlev eq general
 1599:     }
 1600:     $r->print('</form></body></html>');
 1601: } # end sub assessparms
 1602: 
 1603: 
 1604: ##################################################
 1605: ##################################################
 1606: 
 1607: =pod
 1608: 
 1609: =item crsenv
 1610: 
 1611: Show and set course data and parameters.  This is a large routine that should
 1612: be simplified and shortened... someday.
 1613: 
 1614: Inputs: $r
 1615: 
 1616: Returns: nothing
 1617: 
 1618: =cut
 1619: 
 1620: ##################################################
 1621: ##################################################
 1622: sub crsenv {
 1623:     my $r=shift;
 1624:     my $setoutput='';
 1625:     my $bodytag=&Apache::loncommon::bodytag(
 1626:                              'Set Course Environment Parameters');
 1627:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,
 1628: 						    'Edit Course Environment');
 1629:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1630:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 1631: 
 1632:     #
 1633:     # Go through list of changes
 1634:     foreach (keys %env) {
 1635:         next if ($_!~/^form\.(.+)\_setparmval$/);
 1636:         my $name  = $1;
 1637:         my $value = $env{'form.'.$name.'_value'};
 1638:         if ($name eq 'newp') {
 1639:             $name = $env{'form.newp_name'};
 1640:         }
 1641:         if ($name eq 'url') {
 1642:             $value=~s/^\/res\///;
 1643:             my $bkuptime=time;
 1644:             my @tmp = &Apache::lonnet::get
 1645:                 ('environment',['url'],$dom,$crs);
 1646:             $setoutput.=&mt('Backing up previous URL').': '.
 1647:                 &Apache::lonnet::put
 1648:                 ('environment',
 1649:                  {'top level map backup '.$bkuptime => $tmp[1] },
 1650:                  $dom,$crs).
 1651:                      '<br>';
 1652:         }
 1653:         #
 1654:         # Deal with modified default spreadsheets
 1655:         if ($name =~ /^spreadsheet_default_(classcalc|
 1656:                                             studentcalc|
 1657:                                             assesscalc)$/x) {
 1658:             my $sheettype = $1; 
 1659:             if ($sheettype eq 'classcalc') {
 1660:                 # no need to do anything since viewing the sheet will
 1661:                 # cause it to be updated. 
 1662:             } elsif ($sheettype eq 'studentcalc') {
 1663:                 # expire all the student spreadsheets
 1664:                 &Apache::lonnet::expirespread('','','studentcalc');
 1665:             } else {
 1666:                 # expire all the assessment spreadsheets 
 1667:                 #    this includes non-default spreadsheets, but better to
 1668:                 #    be safe than sorry.
 1669:                 &Apache::lonnet::expirespread('','','assesscalc');
 1670:                 # expire all the student spreadsheets
 1671:                 &Apache::lonnet::expirespread('','','studentcalc');
 1672:             }
 1673:         }
 1674:         #
 1675:         # Deal with the enrollment dates
 1676:         if ($name =~ /^default_enrollment_(start|end)_date$/) {
 1677:             $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
 1678:         }
 1679:         # Get existing cloners
 1680:         my @oldcloner = ();
 1681:         if ($name eq 'cloners') {
 1682:             my %clonenames=&Apache::lonnet::dump('environment',$dom,$crs,'cloners');
 1683:             if ($clonenames{'cloners'} =~ /,/) {
 1684:                 @oldcloner = split/,/,$clonenames{'cloners'};
 1685:             } else {
 1686:                 $oldcloner[0] = $clonenames{'cloners'};
 1687:             }
 1688:         }
 1689:         #
 1690:         # Let the user know we made the changes
 1691:         if ($name && defined($value)) {
 1692:             if ($name eq 'cloners') {
 1693:                 $value =~ s/^,//;
 1694:                 $value =~ s/,$//;
 1695:             }
 1696:             my $put_result = &Apache::lonnet::put('environment',
 1697:                                                   {$name=>$value},$dom,$crs);
 1698:             if ($put_result eq 'ok') {
 1699:                 $setoutput.=&mt('Set').' <b>'.$name.'</b> '.&mt('to').' <b>'.$value.'</b>.<br />';
 1700:                 if ($name eq 'cloners') {
 1701:                     &change_clone($value,\@oldcloner);
 1702:                 }
 1703:                 # Flush the course logs so course description is immediately updated
 1704:                 if ($name eq 'description' && defined($value)) {
 1705:                     &Apache::lonnet::flushcourselogs();
 1706:                 }
 1707:             } else {
 1708:                 $setoutput.=&mt('Unable to set').' <b>'.$name.'</b> '.&mt('to').
 1709: 		    ' <b>'.$value.'</b> '.&mt('due to').' '.$put_result.'.<br />';
 1710:             }
 1711:         }
 1712:     }
 1713: # ------------------------- Re-init course environment entries for this session
 1714: 
 1715:     &Apache::lonnet::coursedescription($env{'request.course.id'});
 1716: 
 1717: # -------------------------------------------------------- Get parameters again
 1718: 
 1719:     my %values=&Apache::lonnet::dump('environment',$dom,$crs);
 1720:     my $SelectStyleFile=&mt('Select Style File');
 1721:     my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
 1722:     my $output='';
 1723:     if (! exists($values{'con_lost'})) {
 1724:         my %descriptions=
 1725: 	    ('url'            => '<b>'.&mt('Top Level Map').'</b> '.
 1726:                                  '<a href="javascript:openbrowser'.
 1727:                                  "('envform','url','sequence')\">".
 1728:                                  &mt('Select Map').'</a><br /><font color=red> '.
 1729:                                  &mt('Modification may make assessment data inaccessible').
 1730:                                  '</font>',
 1731:              'description'    => '<b>'.&mt('Course Description').'</b>',
 1732:              'courseid'       => '<b>'.&mt('Course ID or number').
 1733:                                  '</b><br />'.
 1734:                                  '('.&mt('internal').', '.&mt('optional').')',
 1735:              'cloners'        => '<b>'.&mt('Users allowed to clone course').'</b><br /><tt>(user:domain,user:domain)</tt><br />'.&mt('Users with active Course Coordinator role in the course automatically have the right to clone it, and can be omitted from list.'),
 1736:              'grading'        => '<b>'.&mt('Grading').'</b><br />'.
 1737:                                  '<tt>"standard", "external", or "spreadsheet"</tt> '.&Apache::loncommon::help_open_topic('GradingOptions'),
 1738:              'default_xml_style' => '<b>'.&mt('Default XML Style File').'</b> '.
 1739:                     '<a href="javascript:openbrowser'.
 1740:                     "('envform','default_xml_style'".
 1741:                     ",'sty')\">$SelectStyleFile</a><br>",
 1742:              'question.email' => '<b>'.&mt('Feedback Addresses for Resource Content Question').
 1743:                                  '</b><br />(<tt>user:domain,'.
 1744:                                  'user:domain(section;section;...;*;...),...</tt>)',
 1745:              'comment.email'  => '<b>'.&mt('Feedback Addresses for Course Content Comments').'</b><br />'.
 1746:                                  '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
 1747:              'policy.email'   => '<b>'.&mt('Feedback Addresses for Course Policy').'</b>'.
 1748:                                  '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
 1749:              'hideemptyrows'  => '<b>'.&mt('Hide Empty Rows in Spreadsheets').'</b><br />'.
 1750:                                  '('.&mt('"[_1]" for default hiding','<tt>yes</tt>').')',
 1751:              'pageseparators'  => '<b>'.&mt('Visibly Separate Items on Pages').'</b><br />'.
 1752:                                  '('.&mt('"[_1]" for visible separation','<tt>yes</tt>').', '.
 1753:                                  &mt('changes will not show until next login').')',
 1754:              'student_classlist_view' => '<b>'.&mt('Allow students to view classlist.').'</b>'.&mt('("all":students can view all sections,"section":students can only view their own section.blank or "disabled" prevents student view.'),
 1755: 
 1756:              'plc.roles.denied'=> '<b>'.&mt('Disallow live chatroom use for Roles').
 1757:                                   '</b><br />"<tt>st</tt>": '.
 1758:                                   &mt('student').', "<tt>ta</tt>": '.
 1759:                                   'TA, "<tt>in</tt>": '.
 1760:                                   &mt('instructor').';<br /><tt>'.&mt('role,role,...').'</tt>) '.
 1761: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
 1762:              'plc.users.denied' => 
 1763:                           '<b>'.&mt('Disallow live chatroom use for Users').'</b><br />'.
 1764:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1765: 
 1766:              'pch.roles.denied'=> '<b>'.&mt('Disallow Resource Discussion for Roles').
 1767:                                   '</b><br />"<tt>st</tt>": '.
 1768:                                   'student, "<tt>ta</tt>": '.
 1769:                                   'TA, "<tt>in</tt>": '.
 1770:                                   'instructor;<br /><tt>role,role,...</tt>) '.
 1771: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
 1772:              'pch.users.denied' => 
 1773:                           '<b>'.&mt('Disallow Resource Discussion for Users').'</b><br />'.
 1774:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1775:              'spreadsheet_default_classcalc' 
 1776:                  => '<b>'.&mt('Default Course Spreadsheet').'</b> '.
 1777:                     '<a href="javascript:openbrowser'.
 1778:                     "('envform','spreadsheet_default_classcalc'".
 1779:                     ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
 1780:              'spreadsheet_default_studentcalc' 
 1781:                  => '<b>'.&mt('Default Student Spreadsheet').'</b> '.
 1782:                     '<a href="javascript:openbrowser'.
 1783:                     "('envform','spreadsheet_default_calc'".
 1784:                     ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
 1785:              'spreadsheet_default_assesscalc' 
 1786:                  => '<b>'.&mt('Default Assessment Spreadsheet').'</b> '.
 1787:                     '<a href="javascript:openbrowser'.
 1788:                     "('envform','spreadsheet_default_assesscalc'".
 1789:                     ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
 1790: 	     'allow_limited_html_in_feedback'
 1791: 	         => '<b>'.&mt('Allow limited HTML in discussion posts').'</b><br />'.
 1792: 	            '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
 1793:              'allow_discussion_post_editing'
 1794:                  => '<b>'.&mt('Allow users to edit/delete their own discussion posts').'</b><br />'.
 1795:                     '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
 1796: 	     'rndseed'
 1797: 	         => '<b>'.&mt('Randomization algorithm used').'</b> <br />'.
 1798:                     '<font color="red">'.&mt('Modifying this will make problems').' '.
 1799:                     &mt('have different numbers and answers').'</font>',
 1800: 	     'receiptalg'
 1801: 	         => '<b>'.&mt('Receipt algorithm used').'</b> <br />'.
 1802:                     &mt('This controls how receipt numbers are generated.'),
 1803:              'suppress_tries'
 1804:                  => '<b>'.&mt('Suppress number of tries in printing').'</b>('.
 1805:                     &mt('yes if supress').')',
 1806:              'problem_stream_switch'
 1807:                  => '<b>'.&mt('Allow problems to be split over pages').'</b><br />'.
 1808:                     ' ('.&mt('"[_1]" if allowed, anything else if not','<tt>yes</tt>').')',
 1809:              'default_paper_size' 
 1810:                  => '<b>'.&mt('Default paper type').'</b><br />'.
 1811:                     ' ('.&mt('supported types').': Letter [8 1/2x11 in], Legal [8 1/2x14 in],'. 
 1812:                     ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'. 
 1813:                     ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])',
 1814:              'anonymous_quiz'
 1815:                  => '<b>'.&mt('Anonymous quiz/exam').'</b><br />'.
 1816:                     ' (<tt><b>'.&mt('yes').'</b> '.&mt('to avoid print students names').' </tt>)',
 1817:              'default_enrollment_start_date' => '<b>'.&mt('Default beginning date for student access.').'</b>',
 1818:              'default_enrollment_end_date'   => '<b>'.&mt('Default ending date for student access.').'</b>',
 1819:              'nothideprivileged'   => '<b>'.&mt('Privileged users that should not be hidden on staff listings').'</b>'.
 1820:                                  '<br />(<tt>user:domain,user:domain,...</tt>)',
 1821:              'languages' => '<b>'.&mt('Languages used').'</b>',
 1822:              'disable_receipt_display'
 1823:                  => '<b>'.&mt('Disable display of problem receipts').'</b><br />'.
 1824:                     ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
 1825: 	     'disablesigfigs'
 1826: 	         => '<b>'.&mt('Disable checking of Significant Figures').'</b><br />'.
 1827:                     ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
 1828: 	     'tthoptions'
 1829: 	         => '<b>'.&mt('Default set of options to pass to tth/m when converting tex').'</b>'
 1830:              ); 
 1831:         my @Display_Order = ('url','description','courseid','cloners','grading',
 1832:                              'default_xml_style','pageseparators',
 1833:                              'question.email','comment.email','policy.email',
 1834:                              'student_classlist_view',
 1835:                              'plc.roles.denied','plc.users.denied',
 1836:                              'pch.roles.denied','pch.users.denied',
 1837:                              'allow_limited_html_in_feedback',
 1838:                              'allow_discussion_post_editing',
 1839:                              'languages',
 1840: 			     'nothideprivileged',
 1841:                              'rndseed',
 1842:                              'receiptalg',
 1843:                              'problem_stream_switch',
 1844: 			     'suppress_tries',
 1845:                              'default_paper_size',
 1846:                              'disable_receipt_display',
 1847:                              'spreadsheet_default_classcalc',
 1848:                              'spreadsheet_default_studentcalc',
 1849:                              'spreadsheet_default_assesscalc', 
 1850:                              'hideemptyrows',
 1851:                              'default_enrollment_start_date',
 1852:                              'default_enrollment_end_date',
 1853: 			     'tthoptions',
 1854: 			     'disablesigfigs'
 1855:                              );
 1856: 	foreach my $parameter (sort(keys(%values))) {
 1857:             unless ($parameter =~ m/^internal\./) {
 1858:                 if (! $descriptions{$parameter}) {
 1859:                     $descriptions{$parameter}=$parameter;
 1860:                     push(@Display_Order,$parameter);
 1861:                 }
 1862:             }
 1863: 	}
 1864:         foreach my $parameter (@Display_Order) {
 1865:             my $description = $descriptions{$parameter};
 1866:             # onchange is javascript to automatically check the 'Set' button.
 1867:             my $onchange = 'onFocus="javascript:window.document.forms'.
 1868:                 "['envform'].elements['".$parameter."_setparmval']".
 1869:                 '.checked=true;"';
 1870:             $output .= '<tr><td>'.$description.'</td>';
 1871:             if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
 1872:                 $output .= '<td>'.
 1873:                     &Apache::lonhtmlcommon::date_setter('envform',
 1874:                                                         $parameter.'_value',
 1875:                                                         $values{$parameter},
 1876:                                                         $onchange).
 1877:                                                         '</td>';
 1878:             } else {
 1879:                 $output .= '<td>'.
 1880:                     &Apache::lonhtmlcommon::textbox($parameter.'_value',
 1881:                                                     $values{$parameter},
 1882:                                                     40,$onchange).'</td>';
 1883:             }
 1884:             $output .= '<td>'.
 1885:                 &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
 1886:                 '</td>';
 1887:             $output .= "</tr>\n";
 1888: 	}
 1889:         my $onchange = 'onFocus="javascript:window.document.forms'.
 1890:             '[\'envform\'].elements[\'newp_setparmval\']'.
 1891:             '.checked=true;"';
 1892: 	$output.='<tr><td><i>'.&mt('Create New Environment Variable').'</i><br />'.
 1893: 	    '<input type="text" size=40 name="newp_name" '.
 1894:                 $onchange.' /></td><td>'.
 1895:             '<input type="text" size=40 name="newp_value" '.
 1896:                 $onchange.' /></td><td>'.
 1897: 	    '<input type="checkbox" name="newp_setparmval" /></td></tr>';
 1898:     }
 1899:     my %lt=&Apache::lonlocal::texthash(
 1900: 		    'par'   => 'Parameter',
 1901: 		    'val'   => 'Value',
 1902: 		    'set'   => 'Set',
 1903: 		    'sce'   => 'Set Course Environment'
 1904: 				       );
 1905: 
 1906:     my $Parameter=&mt('Parameter');
 1907:     my $Value=&mt('Value');
 1908:     my $Set=&mt('Set');
 1909:     my $browse_js=&Apache::loncommon::browser_and_searcher_javascript('parmset');
 1910:     my $html=&Apache::lonxml::xmlbegin();
 1911:     $r->print(<<ENDenv);
 1912: $html
 1913: <head>
 1914: <script type="text/javascript" language="Javascript" >
 1915: $browse_js
 1916: </script>
 1917: <title>LON-CAPA Course Environment</title>
 1918: </head>
 1919: $bodytag
 1920: $breadcrumbs
 1921: <form method="post" action="/adm/parmset?action=crsenv" name="envform">
 1922: $setoutput
 1923: <p>
 1924: <table border=2>
 1925: <tr><th>$lt{'par'}</th><th>$lt{'val'}</th><th>$lt{'set'}?</th></tr>
 1926: $output
 1927: </table>
 1928: <input type="submit" name="crsenv" value="$lt{'sce'}">
 1929: </form>
 1930: </body>
 1931: </html>    
 1932: ENDenv
 1933: }
 1934: ##################################################
 1935: # Overview mode
 1936: ##################################################
 1937: my $tableopen;
 1938: 
 1939: sub tablestart {
 1940:     if ($tableopen) {
 1941: 	return '';
 1942:     } else {
 1943: 	$tableopen=1;
 1944: 	return '<table border="2"><tr><th>'.&mt('Parameter').'</th><th>'.
 1945: 	    &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
 1946:     }
 1947: }
 1948: 
 1949: sub tableend {
 1950:     if ($tableopen) {
 1951: 	$tableopen=0;
 1952: 	return '</table>';
 1953:     } else {
 1954: 	return'';
 1955:     }
 1956: }
 1957: 
 1958: sub readdata {
 1959:     my ($crs,$dom)=@_;
 1960: # Read coursedata
 1961:     my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
 1962: # Read userdata
 1963: 
 1964:     my $classlist=&Apache::loncoursedata::get_classlist();
 1965:     foreach (keys %$classlist) {
 1966:         # the following undefs are for 'domain', and 'username' respectively.
 1967:         if ($_=~/^(\w+)\:(\w+)$/) {
 1968: 	    my ($tuname,$tudom)=($1,$2);
 1969: 	    my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
 1970:             foreach my $userkey (keys %{$useropt}) {
 1971: 		if ($userkey=~/^$env{'request.course.id'}/) {
 1972:                     my $newkey=$userkey;
 1973: 		    $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
 1974: 		    $$resourcedata{$newkey}=$$useropt{$userkey};
 1975: 		}
 1976: 	    }
 1977: 	}
 1978:     }
 1979:     return $resourcedata;
 1980: }
 1981: 
 1982: 
 1983: # Setting
 1984: 
 1985: sub storedata {
 1986:     my ($r,$crs,$dom)=@_;
 1987: # Set userlevel immediately
 1988: # Do an intermediate store of course level
 1989:     my $olddata=&readdata($crs,$dom);
 1990:     my %newdata=();
 1991:     undef %newdata;
 1992:     my @deldata=();
 1993:     undef @deldata;
 1994:     foreach (keys %env) {
 1995: 	if ($_=~/^form\.([a-z]+)\_(.+)$/) {
 1996: 	    my $cmd=$1;
 1997: 	    my $thiskey=$2;
 1998: 	    my ($tuname,$tudom)=&extractuser($thiskey);
 1999: 	    my $tkey=$thiskey;
 2000:             if ($tuname) {
 2001: 		$tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
 2002: 	    }
 2003: 	    if ($cmd eq 'set') {
 2004: 		my $data=$env{$_};
 2005:                 my $typeof=$env{'form.typeof_'.$thiskey};
 2006:  		if ($$olddata{$thiskey} ne $data) { 
 2007: 		    if ($tuname) {
 2008: 			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
 2009: 								 $tkey.'.type' => $typeof},
 2010: 						 $tudom,$tuname) eq 'ok') {
 2011: 			    $r->print('<br />'.&mt('Stored modified parameter for').' '.
 2012: 				      &Apache::loncommon::plainname($tuname,$tudom));
 2013: 			} else {
 2014: 			    $r->print('<h2><font color="red">'.
 2015: 				      &mt('Error storing parameters').'</font></h2>');
 2016: 			}
 2017: 			&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 2018: 		    } else {
 2019: 			$newdata{$thiskey}=$data;
 2020:  			$newdata{$thiskey.'.type'}=$typeof; 
 2021:                    } 
 2022: 		}
 2023: 	    } elsif ($cmd eq 'del') {
 2024: 		if ($tuname) {
 2025: 		    if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
 2026: 			$r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 2027: 		    } else {
 2028: 			$r->print('<h2><font color="red">'.
 2029: 				  &mt('Error deleting parameters').'</font></h2>');
 2030: 		    }
 2031: 		    &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 2032: 		} else {
 2033: 		    push (@deldata,$thiskey);
 2034: 		}
 2035: 	    } elsif ($cmd eq 'datepointer') {
 2036: 		my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
 2037:                 my $typeof=$env{'form.typeof_'.$thiskey};
 2038: 		if (defined($data) and $$olddata{$thiskey} ne $data) { 
 2039: 		    if ($tuname) {
 2040: 			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
 2041: 								 $tkey.'.type' => $typeof},
 2042: 						 $tudom,$tuname) eq 'ok') {
 2043: 			    $r->print('<br />'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 2044: 			} else {
 2045: 			    $r->print('<h2><font color="red">'.
 2046: 				      &mt('Error storing parameters').'</font></h2>');
 2047: 			}
 2048: 			&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 2049: 		    } else {
 2050: 			$newdata{$thiskey}=$data;
 2051: 			$newdata{$thiskey.'.type'}=$typeof; 
 2052: 		    }
 2053: 		}
 2054: 	    }
 2055: 	}
 2056:     }
 2057: # Store all course level
 2058:     my $delentries=$#deldata+1;
 2059:     my @newdatakeys=keys %newdata;
 2060:     my $putentries=$#newdatakeys+1;
 2061:     if ($delentries) {
 2062: 	if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
 2063: 	    $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
 2064: 	} else {
 2065: 	    $r->print('<h2><font color="red">'.
 2066: 		      &mt('Error deleting parameters').'</font></h2>');
 2067: 	}
 2068: 	&Apache::lonnet::devalidatecourseresdata($crs,$dom);
 2069:     }
 2070:     if ($putentries) {
 2071: 	if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
 2072: 	    $r->print('<h3>'.&mt('Stored [_1] parameter(s)',$putentries/2).'</h3>');
 2073: 	} else {
 2074: 	    $r->print('<h2><font color="red">'.
 2075: 		      &mt('Error storing parameters').'</font></h2>');
 2076: 	}
 2077: 	&Apache::lonnet::devalidatecourseresdata($crs,$dom);
 2078:     }
 2079: }
 2080: 
 2081: sub extractuser {
 2082:     my $key=shift;
 2083:     return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./);
 2084: }
 2085: 
 2086: sub listdata {
 2087:     my ($r,$resourcedata,$listdata,$sortorder)=@_;
 2088: # Start list output
 2089: 
 2090:     my $oldsection='';
 2091:     my $oldrealm='';
 2092:     my $oldpart='';
 2093:     my $pointer=0;
 2094:     $tableopen=0;
 2095:     my $foundkeys=0;
 2096:     foreach my $thiskey (sort {
 2097: 	if ($sortorder eq 'realmstudent') {
 2098: 	    my ($astudent,$arealm)=($a=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/);
 2099: 	    my ($bstudent,$brealm)=($b=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/);
 2100:             ($arealm cmp $brealm) || ($astudent cmp $bstudent);
 2101: 	} else {
 2102: 	    $a cmp $b;
 2103: 	}
 2104:     } keys %{$listdata}) {
 2105: 	if ($$listdata{$thiskey.'.type'}) {
 2106:             my $thistype=$$listdata{$thiskey.'.type'};
 2107:             if ($$resourcedata{$thiskey.'.type'}) {
 2108: 		$thistype=$$resourcedata{$thiskey.'.type'};
 2109: 	    }
 2110: 	    my ($middle,$part,$name)=
 2111: 		($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
 2112: 	    my $section=&mt('All Students');
 2113: 	    if ($middle=~/^\[(.*)\]/) {
 2114: 		my $issection=$1;
 2115: 		if ($issection=~/^useropt\:(\w+)\:(\w+)/) {
 2116: 		    $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
 2117: 		} else {
 2118: 		    $section=&mt('Group/Section').': '.$issection;
 2119: 		}
 2120: 		$middle=~s/^\[(.*)\]//;
 2121: 	    }
 2122: 	    $middle=~s/\.+$//;
 2123: 	    $middle=~s/^\.+//;
 2124: 	    my $realm='<font color="red">'.&mt('All Resources').'</font>';
 2125: 	    if ($middle=~/^(.+)\_\_\_\(all\)$/) {
 2126: 		$realm='<font color="green">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><font color="#aaaaaa" size="-2">('.$1.')</font></font>';
 2127: 	    } elsif ($middle) {
 2128: 		my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
 2129: 		$realm='<font color="orange">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><font color="#aaaaaa" size="-2">('.$url.' in '.$map.' id: '.$id.')</font></font>';
 2130: 	    }
 2131: 	    if ($sortorder eq 'realmstudent') {
 2132: 		if ($realm ne $oldrealm) {
 2133: 		    $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
 2134: 		    $oldrealm=$realm;
 2135: 		    $oldsection='';
 2136: 		}
 2137: 		if ($section ne $oldsection) {
 2138: 		    $r->print(&tableend()."\n<h2>$section</h2>");
 2139: 		    $oldsection=$section;
 2140: 		    $oldpart='';
 2141: 		}
 2142: 	    } else {
 2143: 		if ($section ne $oldsection) {
 2144: 		    $r->print(&tableend()."\n<hr /><h1>$section</h1>");
 2145: 		    $oldsection=$section;
 2146: 		    $oldrealm='';
 2147: 		}
 2148: 		if ($realm ne $oldrealm) {
 2149: 		    $r->print(&tableend()."\n<h2>$realm</h2>");
 2150: 		    $oldrealm=$realm;
 2151: 		    $oldpart='';
 2152: 		}
 2153: 	    }
 2154: 	    if ($part ne $oldpart) {
 2155: 		$r->print(&tableend().
 2156: 			  "\n<font color='blue'>".&mt('Part').": $part</font>");
 2157: 		$oldpart=$part;
 2158: 	    }
 2159: #
 2160: # Ready to print
 2161: #
 2162: 	    $r->print(&tablestart().'<tr><td><b>'.$name.
 2163: 		      ':</b></td><td><input type="checkbox" name="del_'.
 2164: 		      $thiskey.'" /></td><td>');
 2165: 	    $foundkeys++;
 2166: 	    if (&isdateparm($thistype)) {
 2167: 		my $jskey='key_'.$pointer;
 2168: 		$pointer++;
 2169: 		$r->print(
 2170: 			  &Apache::lonhtmlcommon::date_setter('overviewform',
 2171: 							      $jskey,
 2172: 						      $$resourcedata{$thiskey},
 2173: 							      '',1).
 2174: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'
 2175: 			  );
 2176: 	    } elsif ($thistype eq 'string_yesno') {
 2177: 		$r->print('<label><input type="radio" name="set_'.$thiskey.
 2178: 			  '" value="yes"');
 2179: 		if ($$resourcedata{$thiskey} eq 'yes') {
 2180: 		    $r->print(' checked="checked"');
 2181: 		}
 2182:                 $r->print(' />'.&mt('Yes').'</label> ');
 2183: 		$r->print('<label><input type="radio" name="set_'.$thiskey.
 2184: 			  '" value="no"');
 2185: 		if ($$resourcedata{$thiskey} eq 'no') {
 2186: 		    $r->print(' checked="checked"');
 2187: 		}
 2188:                 $r->print(' />'.&mt('No').'</label>');
 2189: 	    } else {
 2190: 		$r->print('<input type="text" name="set_'.$thiskey.'" value="'.
 2191: 			  $$resourcedata{$thiskey}.'">');
 2192: 	    }
 2193: 	    $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
 2194: 		      $thistype.'">');
 2195: 	    $r->print('</td></tr>');
 2196: 	}
 2197:     }
 2198:     return $foundkeys;
 2199: }
 2200: 
 2201: sub newoverview {
 2202:     my $r=shift;
 2203:     my $bodytag=&Apache::loncommon::bodytag('Set Parameters');
 2204:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2205:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 2206:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
 2207:     my $html=&Apache::lonxml::xmlbegin();
 2208:     $r->print(<<ENDOVER);
 2209: $html
 2210: <head>
 2211: <title>LON-CAPA Parameters</title>
 2212: </head>
 2213: $bodytag
 2214: $breadcrumbs
 2215: <form method="post" action="/adm/parmset?action=newoverview" name="parmform">
 2216: ENDOVER
 2217:     my @ids=();
 2218:     my %typep=();
 2219:     my %keyp=();
 2220:     my %allparms=();
 2221:     my %allparts=();
 2222:     my %allmaps=();
 2223:     my %mapp=();
 2224:     my %symbp=();
 2225:     my %maptitles=();
 2226:     my %uris=();
 2227:     my %keyorder=&standardkeyorder();
 2228:     my %defkeytype=();
 2229: 
 2230:     my %alllevs=();
 2231:     $alllevs{'Resource Level'}='full';
 2232:     $alllevs{'Map/Folder Level'}='map';
 2233:     $alllevs{'Course Level'}='general';
 2234: 
 2235:     my $csec=$env{'form.csec'};
 2236: 
 2237:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
 2238:     my $pschp=$env{'form.pschp'};
 2239:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
 2240:     if (!@psprt) { $psprt[0]='0'; }
 2241: 
 2242:     my @selected_sections = 
 2243: 	&Apache::loncommon::get_env_multiple('form.Section');
 2244:     @selected_sections = ('all') if (! @selected_sections);
 2245:     foreach (@selected_sections) {
 2246:         if ($_ eq 'all') {
 2247:             @selected_sections = ('all');
 2248:         }
 2249:     }
 2250: 
 2251:     my $pssymb='';
 2252:     my $parmlev='';
 2253:  
 2254:     unless ($env{'form.parmlev'}) {
 2255:         $parmlev = 'map';
 2256:     } else {
 2257:         $parmlev = $env{'form.parmlev'};
 2258:     }
 2259: 
 2260:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, 
 2261: 				\%mapp, \%symbp,\%maptitles,\%uris,
 2262: 				\%keyorder,\%defkeytype);
 2263: 
 2264: # Menu to select levels, etc
 2265: 
 2266:     $r->print('<table border="1"><tr><td>');
 2267:     &levelmenu($r,\%alllevs,$parmlev);
 2268:     if ($parmlev ne 'general') {
 2269: 	$r->print('<td>');
 2270: 	&mapmenu($r,\%allmaps,$pschp,\%maptitles);
 2271: 	$r->print('</td>');
 2272:     }
 2273:     $r->print('</td></tr></table>');
 2274: 
 2275:     $r->print('<table border="1"><tr><td>');  
 2276:     &parmmenu($r,\%allparms,\@pscat,\%keyorder);
 2277:     $r->print('</td><td>');
 2278:     &partmenu($r,\%allparts,\@psprt);
 2279:     $r->print('</td><td>');
 2280:     &sectionmenu($r,\@selected_sections);
 2281: 
 2282:     $r->print('</td></tr></table>');
 2283:  
 2284:     my $sortorder=$env{'form.sortorder'};
 2285:     unless ($sortorder) { $sortorder='realmstudent'; }
 2286:     &sortmenu($r,$sortorder);
 2287: 
 2288:     $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
 2289: 
 2290: # Build the list data hash from the specified parms
 2291: 
 2292:     my $listdata;
 2293:     %{$listdata}=();
 2294: 
 2295:     foreach my $cat (@pscat) {
 2296: 	foreach my $section (@selected_sections) {
 2297: 	    foreach my $part (@psprt) {
 2298:                 my $rootparmkey=$env{'request.course.id'};
 2299:                 if (($section ne 'all') && ($section ne 'none') && ($section)) {
 2300: 		    $rootparmkey.='.['.$section.']';
 2301: 		}
 2302: 		if ($parmlev eq 'general') {
 2303: # course-level parameter
 2304: 		    my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
 2305: 		    $$listdata{$newparmkey}=1;
 2306: 		    $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
 2307: 		} elsif ($parmlev eq 'map') {
 2308: # map-level parameter
 2309: 		    foreach my $mapid (keys %allmaps) {
 2310: 			if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
 2311: 			my $newparmkey=$rootparmkey.'.'.$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
 2312:                         $$listdata{$newparmkey}=1;
 2313:                         $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
 2314: 		    }
 2315: 		} else {
 2316: # resource-level parameter
 2317: 		    foreach my $rid (@ids) {
 2318: 			my ($map,$resid,$url)=&Apache::lonnet::decode_symb($symbp{$rid});
 2319: 			if (($pschp ne 'all') && ($allmaps{$pschp} ne $map)) { next; }
 2320: 			my $newparmkey=$rootparmkey.'.'.$symbp{$rid}.'.'.$part.'.'.$cat;
 2321:                         $$listdata{$newparmkey}=1;
 2322:                         $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
 2323: 		    }
 2324: 		}
 2325: 	    }
 2326: 	}
 2327:     }
 2328: 
 2329:     if (($env{'form.store'}) || ($env{'form.dis'})) {
 2330: 
 2331: 	if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
 2332: 
 2333: # Read modified data
 2334: 
 2335: 	my $resourcedata=&readdata($crs,$dom);
 2336: 
 2337: # List data
 2338: 
 2339: 	&listdata($r,$resourcedata,$listdata,$sortorder);
 2340:     }
 2341:     $r->print(&tableend().
 2342: 	     ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Store').'" /></p>':'').
 2343: 	      '</form></body></html>');
 2344: }
 2345: 
 2346: sub overview {
 2347:     my $r=shift;
 2348:     my $bodytag=&Apache::loncommon::bodytag('Modify Parameters');
 2349:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2350:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 2351:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
 2352:     my $html=&Apache::lonxml::xmlbegin();
 2353:     $r->print(<<ENDOVER);
 2354: $html
 2355: <head>
 2356: <title>LON-CAPA Parameters</title>
 2357: </head>
 2358: $bodytag
 2359: $breadcrumbs
 2360: <form method="post" action="/adm/parmset?action=setoverview" name="overviewform">
 2361: ENDOVER
 2362: # Store modified
 2363: 
 2364:     &storedata($r,$crs,$dom);
 2365: 
 2366: # Read modified data
 2367: 
 2368:     my $resourcedata=&readdata($crs,$dom);
 2369: 
 2370: 
 2371:     my $sortorder=$env{'form.sortorder'};
 2372:     unless ($sortorder) { $sortorder='realmstudent'; }
 2373:     &sortmenu($r,$sortorder);
 2374: 
 2375: # List data
 2376: 
 2377:     my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder);
 2378: 
 2379:     $r->print(&tableend().'<p>'.
 2380: 	($foundkeys?'<input type="submit" value="'.&mt('Modify Parameters').'" />':&mt('There are no parameters.')).'</p></form></body></html>');
 2381: }
 2382: 
 2383: ##################################################
 2384: ##################################################
 2385:                                                                                             
 2386: =pod
 2387:                                                                                             
 2388: =item change clone
 2389:                                                                                             
 2390: Modifies the list of courses a user can clone (stored
 2391: in the user's environemnt.db file), called when a
 2392: change is made to the list of users allowed to clone
 2393: a course.
 2394:                                                                                             
 2395: Inputs: $action,$cloner
 2396: where $action is add or drop, and $cloner is identity of 
 2397: user for whom cloning ability is to be changed in course. 
 2398:                                                                                             
 2399: Returns: 
 2400: 
 2401: =cut
 2402:                                                                                             
 2403: ##################################################
 2404: ##################################################
 2405: 
 2406: 
 2407: sub change_clone {
 2408:     my ($clonelist,$oldcloner) = @_;
 2409:     my ($uname,$udom);
 2410:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 2411:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2412:     my $clone_crs = $cnum.':'.$cdom;
 2413:     
 2414:     if ($cnum && $cdom) {
 2415:         my @allowclone = ();
 2416:         if ($clonelist =~ /,/) {
 2417:             @allowclone = split/,/,$clonelist;
 2418:         } else {
 2419:             $allowclone[0] = $clonelist;
 2420:         }
 2421:         foreach my $currclone (@allowclone) {
 2422:             if (!grep/^$currclone$/,@$oldcloner) {
 2423:                 ($uname,$udom) = split/:/,$currclone;
 2424:                 if ($uname && $udom) {
 2425:                     unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
 2426:                         my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
 2427:                         if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
 2428:                             if ($currclonecrs{'cloneable'} eq '') {
 2429:                                 $currclonecrs{'cloneable'} = $clone_crs;
 2430:                             } else {
 2431:                                 $currclonecrs{'cloneable'} .= ','.$clone_crs;
 2432:                             }
 2433:                             &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
 2434:                         }
 2435:                     }
 2436:                 }
 2437:             }
 2438:         }
 2439:         foreach my $oldclone (@$oldcloner) {
 2440:             if (!grep/^$oldclone$/,@allowclone) {
 2441:                 ($uname,$udom) = split/:/,$oldclone;
 2442:                 if ($uname && $udom) {
 2443:                     unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
 2444:                         my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
 2445:                         my %newclonecrs = ();
 2446:                         if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
 2447:                             if ($currclonecrs{'cloneable'} =~ /,/) {
 2448:                                 my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
 2449:                                 foreach (@currclonecrs) {
 2450:                                     unless ($_ eq $clone_crs) {
 2451:                                         $newclonecrs{'cloneable'} .= $_.',';
 2452:                                     }
 2453:                                 }
 2454:                                 $newclonecrs{'cloneable'} =~ s/,$//;
 2455:                             } else {
 2456:                                 $newclonecrs{'cloneable'} = '';
 2457:                             }
 2458:                             &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
 2459:                         }
 2460:                     }
 2461:                 }
 2462:             }
 2463:         }
 2464:     }
 2465: }
 2466: 
 2467: 
 2468: ##################################################
 2469: ##################################################
 2470: 
 2471: =pod
 2472: 
 2473: =item * header
 2474: 
 2475: Output html header for page
 2476: 
 2477: =cut
 2478: 
 2479: ##################################################
 2480: ##################################################
 2481: sub header {
 2482:     my $html=&Apache::lonxml::xmlbegin();
 2483:     my $bodytag=&Apache::loncommon::bodytag('Parameter Manager');
 2484:     my $title = &mt('LON-CAPA Parameter Manager');
 2485:     return(<<ENDHEAD);
 2486: $html
 2487: <head>
 2488: <title>$title</title>
 2489: </head>
 2490: $bodytag
 2491: ENDHEAD
 2492: }
 2493: ##################################################
 2494: ##################################################
 2495: sub print_main_menu {
 2496:     my ($r,$parm_permission)=@_;
 2497:     #
 2498:     $r->print(<<ENDMAINFORMHEAD);
 2499: <form method="post" enctype="multipart/form-data"
 2500:       action="/adm/parmset" name="studentform">
 2501: ENDMAINFORMHEAD
 2502: #
 2503:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 2504:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2505:     my @menu =
 2506:         (
 2507:           { text => 'Set Course Environment Parameters',
 2508: 	    action => 'crsenv',
 2509:             permission => $parm_permission,
 2510:             },
 2511:           { text => 'Set/Modify Resource Parameters - Helper Mode',
 2512:             url => '/adm/helper/parameter.helper',
 2513:             permission => $parm_permission,
 2514:             },
 2515:           { text => 'Modify Resource Parameters - Overview Mode',
 2516:             action => 'setoverview',
 2517:             permission => $parm_permission,
 2518:             },          
 2519: 	  { text => 'Set Resource Parameters - Overview Mode',
 2520:             action => 'newoverview',
 2521:             permission => $parm_permission,
 2522:             },
 2523:           { text => 'Set/Modify Resource Parameters - Table Mode',
 2524:             action => 'settable',
 2525:             permission => $parm_permission,
 2526:             help => 'Cascading_Parameters',
 2527:             },
 2528:           { text => 'Set Parameter Setting Default Actions',
 2529:             action => 'setdefaults',
 2530:             permission => $parm_permission,
 2531:             },
 2532:           );
 2533:     my $menu_html = '';
 2534:     foreach my $menu_item (@menu) {
 2535:         next if (! $menu_item->{'permission'});
 2536:         $menu_html.='<p>';
 2537:         $menu_html.='<font size="+1">';
 2538:         if (exists($menu_item->{'url'})) {
 2539:             $menu_html.=qq{<a href="$menu_item->{'url'}">};
 2540:         } else {
 2541:             $menu_html.=
 2542:                 qq{<a href="/adm/parmset?action=$menu_item->{'action'}">};
 2543:         }
 2544:         $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
 2545:         if (exists($menu_item->{'help'})) {
 2546:             $menu_html.=
 2547:                 &Apache::loncommon::help_open_topic($menu_item->{'help'});
 2548:         }
 2549:         $menu_html.='</p>'.$/;
 2550:     }
 2551:     $r->print($menu_html);
 2552:     return;
 2553: }
 2554: 
 2555: 
 2556: ##################################################
 2557: 
 2558: sub defaultsetter {
 2559:     my $r=shift;
 2560:     my $bodytag=&Apache::loncommon::bodytag('Parameter Setting Default Actions');
 2561:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2562:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
 2563:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Defaults');
 2564:     my $html=&Apache::lonxml::xmlbegin();
 2565:     $r->print(<<ENDDEFHEAD);
 2566: $html
 2567: <head>
 2568: <title>LON-CAPA Parameters</title>
 2569: </head>
 2570: $bodytag
 2571: $breadcrumbs
 2572: <form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">
 2573: ENDDEFHEAD
 2574:     if ($env{'form.storerules'}) {
 2575: # storage here
 2576: 	&resetrulescache();
 2577:     }
 2578:     my @ids=();
 2579:     my %typep=();
 2580:     my %keyp=();
 2581:     my %allparms=();
 2582:     my %allparts=();
 2583:     my %allmaps=();
 2584:     my %mapp=();
 2585:     my %symbp=();
 2586:     my %maptitles=();
 2587:     my %uris=();
 2588:     my %keyorder=&standardkeyorder();
 2589:     my %defkeytype=();
 2590: 
 2591:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, 
 2592: 				\%mapp, \%symbp,\%maptitles,\%uris,
 2593: 				\%keyorder,\%defkeytype);
 2594:     my %lt=&Apache::lonlocal::texthash('hours' => 'Hours',
 2595: 				       'min' => 'Minutes',
 2596: 				       'sec' => 'Seconds',
 2597: 				       'yes' => 'Yes',
 2598: 				       'no' => 'No');
 2599:     my @standardoptions=('','default');
 2600:     my @standarddisplay=('',&mt('Default value when manually setting'));
 2601:     my @dateoptions=('','default');
 2602:     my @datedisplay=('',&mt('Default value when manually setting'));
 2603:     foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
 2604: 	unless ($tempkey) { next; }
 2605: 	push @standardoptions,'when_setting_'.$tempkey;
 2606: 	push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
 2607: 	if (&isdateparm($defkeytype{$tempkey})) {
 2608: 	    push @dateoptions,'later_than_'.$tempkey;
 2609: 	    push @datedisplay,&mt('Automatically set later than ').$tempkey;
 2610: 	    push @dateoptions,'earlier_than_'.$tempkey;
 2611: 	    push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
 2612: 	} 
 2613:     }
 2614:     $r->print("\n<table border='1'><tr><th>".&mt('Rule for parameter').'</th><th>'.
 2615: 	      &mt('Action').'</th><th>'.&mt('Value').'</th></tr>');
 2616:     foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
 2617: 	unless ($tempkey) { next; }
 2618: 	$r->print("\n<tr><td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
 2619: 
 2620: 	my $action=&rulescache($tempkey.'_action');
 2621: 	$r->print('<select name="'.$tempkey.'_action">');
 2622: 	if (&isdateparm($defkeytype{$tempkey})) {
 2623: 	    for (my $i=0;$i<=$#dateoptions;$i++) {
 2624: 		if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
 2625: 		$r->print("\n<option value='$dateoptions[$i]'".
 2626: 			  ($dateoptions[$i] eq $action?' selected="selected"':'').
 2627: 			  ">$datedisplay[$i]</option>");
 2628: 	    }
 2629: 	} else {
 2630: 	    for (my $i=0;$i<=$#standardoptions;$i++) {
 2631: 		if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
 2632: 		$r->print("\n<option value='$standardoptions[$i]'".
 2633: 			  ($standardoptions[$i] eq $action?' selected="selected"':'').
 2634: 			  ">$standarddisplay[$i]</option>");
 2635: 	    }
 2636: 	}
 2637: 	$r->print('</select>');
 2638: 
 2639: 
 2640: 	$r->print("\n</td><td>\n");
 2641: 
 2642:         if (&isdateparm($defkeytype{$tempkey})) {
 2643: 	    my $hours=&rulescache($tempkey.'_hours');
 2644: 	    my $min=&rulescache($tempkey.'_min');
 2645: 	    my $sec=&rulescache($tempkey.'_sec');
 2646: 	    $r->print(<<ENDINPUTDATE);
 2647: <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
 2648: <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
 2649: <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
 2650: ENDINPUTDATE
 2651: 	} elsif ($defkeytype{$tempkey} eq 'string_yesno') {
 2652:             my $yeschecked='';
 2653:             my $nochecked='';
 2654:             if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked='checked="checked"'; }
 2655:             if (&rulescache($tempkey.'_value') eq 'no') { $nochecked='checked="checked"'; }
 2656: 
 2657: 	    $r->print(<<ENDYESNO);
 2658: <label><input type="radio" name="$tempkey" value="yes" $yeschecked /> $lt{'yes'}</label><br />
 2659: <label><input type="radio" name="$tempkey" value="no" $nochecked /> $lt{'no'}</label>
 2660: ENDYESNO
 2661:         } else {
 2662: 	    $r->print('<input type="text" size="20" name="'.$tempkey.'" value="'.&rulescache($tempkey.'_value').'" />');
 2663: 	}
 2664:         $r->print('</td></tr>');
 2665:     }
 2666:     $r->print("</table></form></body></html>");
 2667:     return;
 2668: }
 2669: 
 2670: ##################################################
 2671: ##################################################
 2672: 
 2673: =pod
 2674: 
 2675: =item * handler
 2676: 
 2677: Main handler.  Calls &assessparms and &crsenv subroutines.
 2678: 
 2679: =cut
 2680: ##################################################
 2681: ##################################################
 2682: #    use Data::Dumper;
 2683: 
 2684: sub handler {
 2685:     my $r=shift;
 2686: 
 2687:     if ($r->header_only) {
 2688: 	&Apache::loncommon::content_type($r,'text/html');
 2689: 	$r->send_http_header;
 2690: 	return OK;
 2691:     }
 2692:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2693: 					    ['action','state',
 2694:                                              'pres_marker',
 2695:                                              'pres_value',
 2696:                                              'pres_type',
 2697:                                              'udom','uname','symb']);
 2698: 
 2699: 
 2700:     &Apache::lonhtmlcommon::clear_breadcrumbs();
 2701:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
 2702: 					    text=>"Parameter Manager",
 2703: 					    faq=>10,
 2704: 					    bug=>'Instructor Interface'});
 2705: 
 2706: # ----------------------------------------------------- Needs to be in a course
 2707:     my $parm_permission =
 2708: 	(&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
 2709: 	 &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
 2710: 				  $env{'request.course.sec'}));
 2711:     if ($env{'request.course.id'} &&  $parm_permission) {
 2712: 
 2713:         # Start Page
 2714:         &Apache::loncommon::content_type($r,'text/html');
 2715:         $r->send_http_header;
 2716: 
 2717: 
 2718:         # id numbers can change on re-ordering of folders
 2719: 
 2720:         &resetsymbcache();
 2721: 
 2722:         #
 2723:         # Main switch on form.action and form.state, as appropriate
 2724:         #
 2725:         # Check first if coming from someone else headed directly for
 2726:         #  the table mode
 2727:         if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
 2728: 	     && (!$env{'form.dis'})) || ($env{'form.symb'})) {
 2729: 	    &assessparms($r);
 2730: 
 2731:         } elsif (! exists($env{'form.action'})) {
 2732:             $r->print(&header());
 2733:             $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
 2734: 							 'Parameter Manager'));
 2735:             &print_main_menu($r,$parm_permission);
 2736:         } elsif ($env{'form.action'} eq 'crsenv' && $parm_permission) {
 2737:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=crsenv',
 2738: 						    text=>"Course Environment"});
 2739:             $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
 2740: 						   'Edit Course Environment'));
 2741:             &crsenv($r); 
 2742:         } elsif ($env{'form.action'} eq 'setoverview' && $parm_permission) {
 2743:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
 2744: 						    text=>"Overview Mode"});
 2745: 	    &overview($r);
 2746:         } elsif ($env{'form.action'} eq 'newoverview' && $parm_permission) {
 2747:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
 2748: 						    text=>"Overview Mode"});
 2749: 	    &newoverview($r);
 2750:         }  elsif ($env{'form.action'} eq 'setdefaults' && $parm_permission) {
 2751:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
 2752: 						    text=>"Set Defaults"});
 2753: 	    &defaultsetter($r);
 2754: 	} elsif ($env{'form.action'} eq 'settable' && $parm_permission) {
 2755:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
 2756: 						    text=>"Table Mode",
 2757: 						    help => 'Course_Setting_Parameters'});
 2758: 	    &assessparms($r);
 2759:         }
 2760:         
 2761:     } else {
 2762: # ----------------------------- Not in a course, or not allowed to modify parms
 2763: 	$env{'user.error.msg'}=
 2764: 	    "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
 2765: 	return HTTP_NOT_ACCEPTABLE;
 2766:     }
 2767:     return OK;
 2768: }
 2769: 
 2770: 1;
 2771: __END__
 2772: 
 2773: =pod
 2774: 
 2775: =back
 2776: 
 2777: =cut
 2778: 
 2779: 
 2780: 

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