File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.237: download - view: text, annotated - select for diffs
Tue Jun 28 16:28:16 2005 UTC (18 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- the 'All Student' 'All Resources' relam was un ordered

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

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