File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.276: download - view: text, annotated - select for diffs
Thu Feb 9 22:11:54 2006 UTC (18 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Bug 4651.  Specify which roles can edit their own discussion posts.

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

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