File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.193: download - view: text, annotated - select for diffs
Mon May 30 17:50:18 2005 UTC (18 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- patch from Mark Lucas for adding breadcrumbs ro the parmset interface
- adds menu for selceting different screens

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

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