File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.196: download - view: text, annotated - select for diffs
Wed Jun 1 02:02:41 2005 UTC (19 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Well, it does use navmaps now ... but still a long way to go to actually
clean it up.

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

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