File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.201: download - view: text, annotated - select for diffs
Thu Jun 2 19:17:12 2005 UTC (19 years ago) by www
Branches: MAIN
CVS tags: HEAD
Removed globals except caches

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

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