File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.211: download - view: text, annotated - select for diffs
Mon Jun 6 02:25:09 2005 UTC (19 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Saving this wonderful piece of work.

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

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