File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.124: download - view: text, annotated - select for diffs
Fri Sep 5 03:47:47 2003 UTC (20 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #2110: Overview mode appears to be working.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set parameters for assessments
    3: #
    4: # $Id: lonparmset.pm,v 1.124 2003/09/05 03:47:47 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: 
   65: 
   66: my %courseopt;
   67: my %useropt;
   68: my %parmhash;
   69: 
   70: my @ids;
   71: my %symbp;
   72: my %mapp;
   73: my %typep;
   74: my %keyp;
   75: 
   76: my %maptitles;
   77: 
   78: my $uname;
   79: my $udom;
   80: my $uhome;
   81: my $csec;
   82: my $coursename;
   83: 
   84: ##################################################
   85: ##################################################
   86: 
   87: =pod
   88: 
   89: =item parmval
   90: 
   91: Figure out a cascading parameter.
   92: 
   93: Inputs:  $what - a parameter spec (incluse part info and name I.E. 0.weight)
   94:          $id   - a bighash Id number
   95:          $def  - the resource's default value   'stupid emacs
   96: 
   97: 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
   98: 
   99: 11- resource default
  100: 10- map default
  101: 9 - General Course
  102: 8 - Map or Folder level in course
  103: 7 - resource level in course
  104: 6 - General for section
  105: 5 - Map or Folder level for section
  106: 4 - resource level in section
  107: 3 - General for specific student
  108: 2 - Map or Folder level for specific student
  109: 1 - resource level for specific student
  110: 
  111: =cut
  112: 
  113: ##################################################
  114: ##################################################
  115: sub parmval {
  116:     my ($what,$id,$def)=@_;
  117:     my $result='';
  118:     my @outpar=();
  119: # ----------------------------------------------------- Cascading lookup scheme
  120: 
  121:     my $symbparm=$symbp{$id}.'.'.$what;
  122:     my $mapparm=$mapp{$id}.'___(all).'.$what;
  123: 
  124:     my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$what;
  125:     my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  126:     my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  127: 
  128:     my $courselevel=$ENV{'request.course.id'}.'.'.$what;
  129:     my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
  130:     my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
  131: 
  132: # -------------------------------------------------------- first, check default
  133: 
  134:     if ($def) { $outpar[11]=$def; $result=11; }
  135: 
  136: # ----------------------------------------------------- second, check map parms
  137: 
  138:     my $thisparm=$parmhash{$symbparm};
  139:     if ($thisparm) { $outpar[10]=$thisparm; $result=10; }
  140: 
  141: # --------------------------------------------------------- third, check course
  142: 
  143:     if (defined($courseopt{$courselevel})) {
  144: 	$outpar[9]=$courseopt{$courselevel};
  145: 	$result=9;
  146:     }
  147: 
  148:     if (defined($courseopt{$courselevelm})) {
  149: 	$outpar[8]=$courseopt{$courselevelm};
  150: 	$result=8;
  151:     }
  152: 
  153:     if (defined($courseopt{$courselevelr})) {
  154: 	$outpar[7]=$courseopt{$courselevelr};
  155: 	$result=7;
  156:     }
  157: 
  158:     if (defined($csec)) {
  159:         if (defined($courseopt{$seclevel})) {
  160: 	    $outpar[6]=$courseopt{$seclevel};
  161: 	    $result=6;
  162: 	}
  163:         if (defined($courseopt{$seclevelm})) {
  164: 	    $outpar[5]=$courseopt{$seclevelm};
  165: 	    $result=5;
  166: 	}
  167: 
  168:         if (defined($courseopt{$seclevelr})) {
  169: 	    $outpar[4]=$courseopt{$seclevelr};
  170: 	    $result=4;
  171: 	}
  172:     }
  173: 
  174: # ---------------------------------------------------------- fourth, check user
  175: 
  176:     if (defined($uname)) {
  177: 	if (defined($useropt{$courselevel})) {
  178: 	    $outpar[3]=$useropt{$courselevel};
  179: 	    $result=3;
  180: 	}
  181: 
  182: 	if (defined($useropt{$courselevelm})) {
  183: 	    $outpar[2]=$useropt{$courselevelm};
  184: 	    $result=2;
  185: 	}
  186: 
  187: 	if (defined($useropt{$courselevelr})) {
  188: 	    $outpar[1]=$useropt{$courselevelr};
  189: 	    $result=1;
  190: 	}
  191:     }
  192:     return ($result,@outpar);
  193: }
  194: 
  195: ##################################################
  196: ##################################################
  197: 
  198: =pod
  199: 
  200: =item valout
  201: 
  202: Format a value for output.
  203: 
  204: Inputs:  $value, $type
  205: 
  206: Returns: $value, formatted for output.  If $type indicates it is a date,
  207: localtime($value) is returned.
  208: 
  209: =cut
  210: 
  211: ##################################################
  212: ##################################################
  213: sub valout {
  214:     my ($value,$type)=@_;
  215:     my $result = '';
  216:     # Values of zero are valid.
  217:     if (! $value && $value ne '0') {
  218: 	$result = '  ';
  219:     } else {
  220:         if ($type eq 'date_interval') {
  221:             my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
  222:             $year=$year-70;
  223:             $mday--;
  224:             if ($year) {
  225: 		$result.=$year.' yrs ';
  226:             }
  227:             if ($mon) {
  228: 		$result.=$mon.' mths ';
  229:             }
  230:             if ($mday) {
  231: 		$result.=$mday.' days ';
  232:             }
  233:             if ($hour) {
  234: 		$result.=$hour.' hrs ';
  235:             }
  236:             if ($min) {
  237: 		$result.=$min.' mins ';
  238:             }
  239:             if ($sec) {
  240: 		$result.=$sec.' secs ';
  241:             }
  242:             $result=~s/\s+$//;
  243:         } elsif ($type=~/^date/) {
  244:             $result = localtime($value);
  245:         } else {
  246:             $result = $value;
  247:         }
  248:     }
  249:     return $result;
  250: }
  251: 
  252: ##################################################
  253: ##################################################
  254: 
  255: =pod
  256: 
  257: =item plink
  258: 
  259: Produces a link anchor.
  260: 
  261: Inputs: $type,$dis,$value,$marker,$return,$call
  262: 
  263: Returns: scalar with html code for a link which will envoke the 
  264: javascript function 'pjump'.
  265: 
  266: =cut
  267: 
  268: ##################################################
  269: ##################################################
  270: sub plink {
  271:     my ($type,$dis,$value,$marker,$return,$call)=@_;
  272:     my $winvalue=$value;
  273:     unless ($winvalue) {
  274: 	if ($type=~/^date/) {
  275:             $winvalue=$ENV{'form.recent_'.$type};
  276:         } else {
  277:             $winvalue=$ENV{'form.recent_'.(split(/\_/,$type))[0]};
  278:         }
  279:     }
  280:     return 
  281: 	'<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
  282: 	    .$marker."','".$return."','".$call."'".');">'.
  283: 		&valout($value,$type).'</a><a name="'.$marker.'"></a>';
  284: }
  285: 
  286: 
  287: sub startpage {
  288:     my ($r,$id,$udom,$csec,$uname,$have_assesments)=@_;
  289: 
  290:     my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','',
  291:                                             'onUnload="pclose()"');
  292:     my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
  293:         &Apache::loncommon::selectstudent_link('parmform','uname','udom');
  294:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
  295:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  296:     $r->print(<<ENDHEAD);
  297: <html>
  298: <head>
  299: <title>LON-CAPA Course Parameters</title>
  300: <script>
  301: 
  302:     function pclose() {
  303:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  304:                  "height=350,width=350,scrollbars=no,menubar=no");
  305:         parmwin.close();
  306:     }
  307: 
  308:     $pjump_def
  309: 
  310:     function psub() {
  311:         pclose();
  312:         if (document.parmform.pres_marker.value!='') {
  313:             document.parmform.action+='#'+document.parmform.pres_marker.value;
  314:             var typedef=new Array();
  315:             typedef=document.parmform.pres_type.value.split('_');
  316:            if (document.parmform.pres_type.value!='') {
  317:             if (typedef[0]=='date') {
  318:                 eval('document.parmform.recent_'+
  319:                      document.parmform.pres_type.value+
  320: 		     '.value=document.parmform.pres_value.value;');
  321:             } else {
  322:                 eval('document.parmform.recent_'+typedef[0]+
  323: 		     '.value=document.parmform.pres_value.value;');
  324:             }
  325: 	   }
  326:             document.parmform.submit();
  327:         } else {
  328:             document.parmform.pres_value.value='';
  329:             document.parmform.pres_marker.value='';
  330:         }
  331:     }
  332: 
  333:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
  334:         var options = "width=" + w + ",height=" + h + ",";
  335:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  336:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
  337:         var newWin = window.open(url, wdwName, options);
  338:         newWin.focus();
  339:     }
  340: </script>
  341: $selscript
  342: </head>
  343: $bodytag
  344: 
  345: <form method="post" action="/adm/parmset" name="envform">
  346: <h4>Course Environment Parameters</h4>
  347: <input type="submit" name="crsenv" value="Set Course Environment Parameters" />
  348: </form>
  349: <hr />
  350: <form method="post" action="/adm/helper/parameter.helper" name="helpform">
  351: <h4>Course Assessment Parameter - Helper Mode</h4>
  352: <input type="submit" value="Set/Modify Course Assessment Parameter" />
  353: </form>
  354: <hr />
  355: <form method="post" action="/adm/parmset" name="overview">
  356: <h4>Course Assessment Parameters - Overview Mode</h4>
  357: <input type="submit" name="overview" value="Modify Course Assessment Parameters" />
  358: </form>
  359: <hr />
  360: <form method="post" action="/adm/parmset" name="parmform">
  361: <h4>Course Assessments Parameters - Table Mode</h4>
  362: ENDHEAD
  363: 
  364:     if (!$have_assesments) {
  365: 	$r->print('<font color="red">There are no assesment parameters in this course to set.</font><br />');	
  366:     } else {
  367: 	$r->print(<<ENDHEAD);
  368: <b>
  369: Section/Group:
  370: <input type="text" value="$csec" size="6" name="csec">
  371: <br>
  372: For User 
  373: <input type="text" value="$uname" size="12" name="uname">
  374: or ID
  375: <input type="text" value="$id" size="12" name="id"> 
  376: at Domain 
  377: $chooseopt
  378: </b>
  379: <input type="hidden" value='' name="pres_value">
  380: <input type="hidden" value='' name="pres_type">
  381: <input type="hidden" value='' name="pres_marker">
  382: ENDHEAD
  383:     }
  384: }
  385: 
  386: sub print_row {
  387:     my ($r,$which,$part,$name,$rid,$default,$defaulttype,$display,$defbgone,
  388: 	$defbgtwo,$parmlev)=@_;
  389: # get the values for the parameter in cascading order
  390: # empty levels will remain empty
  391:     my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
  392: 				  $rid,$$default{$which});
  393: # get the type for the parameters
  394: # problem: these may not be set for all levels
  395:     my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
  396:                                           $$name{$which}.'.type',
  397: 				  $rid,$$defaulttype{$which});
  398: # cascade down manually
  399:     my $cascadetype=$defaulttype;
  400:     for (my $i=$#typeoutpar;$i>0;$i--) {
  401: 	 if ($typeoutpar[$i]) { 
  402:             $cascadetype=$typeoutpar[$i];
  403: 	} else {
  404:             $typeoutpar[$i]=$cascadetype;
  405:         }
  406:     }
  407:  
  408:     my $parm=$$display{$which};
  409: 
  410:     if ($parmlev eq 'full' || $parmlev eq 'brief') {
  411:         $r->print('<td bgcolor='.$defbgtwo.' align="center">'
  412:                   .$$part{$which}.'</td>');
  413:     } else {    
  414:         $parm=~s|\[.*\]\s||g;
  415:     }
  416: 
  417:     $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
  418:    
  419:     my $thismarker=$which;
  420:     $thismarker=~s/^parameter\_//;
  421:     my $mprefix=$rid.'&'.$thismarker.'&';
  422: 
  423:     if ($parmlev eq 'general') {
  424: 
  425:         if ($uname) {
  426:             &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  427:         } elsif ($csec) {
  428:             &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); 
  429:         } else {
  430:             &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); 
  431:         }
  432:     } elsif ($parmlev eq 'map') {
  433: 
  434:         if ($uname) {
  435:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  436:         } elsif ($csec) {
  437:             &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  438:         } else {
  439:             &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  440:         }
  441:     } else {
  442: 
  443:         &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  444: 
  445:         if ($parmlev eq 'brief') {
  446: 
  447:            &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  448: 
  449:            if ($csec) {
  450:                &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  451:            }
  452:            if ($uname) {
  453:                &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  454:            }
  455:         } else {
  456: 
  457:            &print_td($r,10,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  458:            &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  459:            &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  460:            &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  461: 
  462:            if ($csec) {
  463:                &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  464:                &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  465:                &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  466:            }
  467:            if ($uname) {
  468:                &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  469:                &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  470:                &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
  471:            }
  472:         } # end of $brief if/else
  473:     } # end of $parmlev if/else
  474: 
  475:     if ($parmlev eq 'full' || $parmlev eq 'brief') {
  476:         $r->print('<td bgcolor=#CCCCFF align="center">'.
  477:                   &valout($outpar[$result],$typeoutpar[$result]).'</td>');
  478:     }
  479:     my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
  480:                                         '.'.$$name{$which},$symbp{$rid});
  481: # this doesn't seem to work, and I don't think is correct
  482: #    my $sessionvaltype=&Apache::lonnet::EXT('resource.'.$$part{$which}.
  483: #                                      '.'.$$name{$which}.'.type',$symbp{$rid});
  484: # this seems to work
  485:     my $sessionvaltype=$typeoutpar[$result];
  486:     if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
  487:     $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
  488:                   &valout($sessionval,$sessionvaltype).'&nbsp;'.
  489:                   '</font></td>');
  490:     $r->print('</tr>');
  491:     $r->print("\n");
  492: }
  493: 
  494: sub print_td {
  495:     my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
  496:     $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
  497:               ' align="center">');
  498:     if ($which<10) {
  499: 	$r->print(&plink($$typeoutpar[$which],
  500: 			 $$display{$value},$$outpar[$which],
  501: 			 $mprefix."$which",'parmform.pres','psub'));
  502:     } else {
  503: 	$r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
  504:     }
  505:     $r->print('</td>'."\n");
  506: }
  507: 
  508: sub get_env_multiple {
  509:     my ($name) = @_;
  510:     my @values;
  511:     if (defined($ENV{$name})) {
  512:         # exists is it an array
  513:         if (ref($ENV{$name})) {
  514:             @values=@{ $ENV{$name} };
  515:         } else {
  516:             $values[0]=$ENV{$name};
  517:         }
  518:     }
  519:     return(@values);
  520: }
  521: 
  522: =pod
  523: 
  524: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
  525: 
  526: Input: See list below:
  527: 
  528: =over 4
  529: 
  530: =item B<ids>: An array that will contain all of the ids in the course.
  531: 
  532: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
  533: 
  534: =item B<keyp>: hash, id->key list, will contain a comma seperated list of the meta-data keys available for the given id
  535: 
  536: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
  537: 
  538: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
  539: 
  540: =item B<allkeys>: hash, full key to part->display value (what's display value?)
  541: 
  542: =item B<allmaps>: hash, ???
  543: 
  544: =item B<fcat>: ???
  545: 
  546: =item B<defp>: hash, ???
  547: 
  548: =item B<mapp>: ??
  549: 
  550: =item B<symbp>: hash, id->full sym?
  551: 
  552: =back
  553: 
  554: =cut
  555: 
  556: sub extractResourceInformation {
  557:     my $bighash = shift;
  558:     my $ids = shift;
  559:     my $typep = shift;
  560:     my $keyp = shift;
  561:     my $allparms = shift;
  562:     my $allparts = shift;
  563:     my $allkeys = shift;
  564:     my $allmaps = shift;
  565:     my $fcat = shift;
  566:     my $defp = shift;
  567:     my $mapp = shift;
  568:     my $symbp = shift;
  569:     my $maptitles=shift;
  570: 
  571:     foreach (keys %$bighash) {
  572: 	if ($_=~/^src\_(\d+)\.(\d+)$/) {
  573: 	    my $mapid=$1;
  574: 	    my $resid=$2;
  575: 	    my $id=$mapid.'.'.$resid;
  576: 	    my $srcf=$$bighash{$_};
  577: 	    if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  578: 		$$ids[$#$ids+1]=$id;
  579: 		$$typep{$id}=$1;
  580: 		$$keyp{$id}='';
  581: 		foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
  582: 		  if ($_=~/^parameter\_(.*)/) {
  583:                     my $key=$_;
  584:                     my $allkey=$1;
  585:                     $allkey=~s/\_/\./g;
  586:                     my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
  587:                     my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
  588:                     my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
  589:                     my $parmdis = $display;
  590:                     $parmdis =~ s|(\[Part.*$)||g;
  591:                     my $partkey = $part;
  592:                     $partkey =~ tr|_|.|;
  593:                     $$allparms{$name} = $parmdis;
  594:                     $$allparts{$part} = "[Part $part]";
  595:                     $$allkeys{$allkey}=$display;
  596:                     if ($allkey eq $fcat) {
  597: 		        $$defp{$id}= &Apache::lonnet::metadata($srcf,$key);
  598: 		    }
  599: 		    if ($$keyp{$id}) {
  600: 		        $$keyp{$id}.=','.$key;
  601: 		    } else {
  602: 		        $$keyp{$id}=$key;
  603: 		    }
  604: 		  }
  605: 		}
  606: 		$$mapp{$id}=
  607: 		    &Apache::lonnet::declutter($$bighash{'map_id_'.$mapid});
  608:                 $$mapp{$mapid}=$$mapp{$id};
  609: 		$$allmaps{$mapid}=$$mapp{$id};
  610: 		$$maptitles{$mapid}=
  611:  $$bighash{'title_'.$$bighash{'ids_'.&Apache::lonnet::clutter($$mapp{$id})}};
  612: 		$$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
  613: 		$$symbp{$id}=$$mapp{$id}.
  614: 			'___'.$resid.'___'.
  615: 			    &Apache::lonnet::declutter($srcf);
  616:                 $$symbp{$mapid}=$$mapp{$id}.'___(all)';
  617: 	    }
  618: 	}
  619:     }
  620: }
  621: 
  622: ##################################################
  623: ##################################################
  624: 
  625: =pod
  626: 
  627: =item assessparms
  628: 
  629: Show assessment data and parameters.  This is a large routine that should
  630: be simplified and shortened... someday.
  631: 
  632: Inputs: $r
  633: 
  634: Returns: nothing
  635: 
  636: Variables used (guessed by Jeremy):
  637: 
  638: =over 4
  639: 
  640: =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.
  641: 
  642: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
  643: 
  644: =item B<allmaps>:
  645: 
  646: =back
  647: 
  648: =cut
  649: 
  650: ##################################################
  651: ##################################################
  652: sub assessparms {
  653: 
  654:     my $r=shift;
  655: # -------------------------------------------------------- Variable declaration
  656:     my %allkeys;
  657:     my %allmaps;
  658:     my %alllevs;
  659: 
  660:     $alllevs{'Resource Level'}='full';
  661: #    $alllevs{'Resource Level [BRIEF]'}='brief';
  662:     $alllevs{'Map Level'}='map';
  663:     $alllevs{'Course Level'}='general';
  664: 
  665:     my %allparms;
  666:     my %allparts;
  667: 
  668:     my %defp;
  669:     %courseopt=();
  670:     %useropt=();
  671:     my %bighash=();
  672: 
  673:     @ids=();
  674:     %symbp=();
  675:     %typep=();
  676: 
  677:     my $message='';
  678: 
  679:     $csec=$ENV{'form.csec'};
  680:     $udom=$ENV{'form.udom'};
  681:     unless ($udom) { $udom=$r->dir_config('lonDefDomain'); }
  682: 
  683:     my @pscat=&get_env_multiple('form.pscat');
  684:     my $pschp=$ENV{'form.pschp'};
  685:     my @psprt=&get_env_multiple('form.psprt');
  686:     if (!@psprt) { $psprt[0]='0'; }
  687:     my $showoptions=$ENV{'form.showoptions'};
  688: 
  689:     my $pssymb='';
  690:     my $parmlev='';
  691:     my $prevvisit=$ENV{'form.prevvisit'};
  692: 
  693: #    unless ($parmlev==$ENV{'form.parmlev'}) {
  694: #        $parmlev = 'full';
  695: #    }
  696:  
  697:     unless ($ENV{'form.parmlev'}) {
  698:         $parmlev = 'map';
  699:     } else {
  700:         $parmlev = $ENV{'form.parmlev'};
  701:     }
  702: 
  703: # ----------------------------------------------- Was this started from grades?
  704: 
  705:     if (($ENV{'form.command'} eq 'set') && ($ENV{'form.url'})
  706: 	&& (!$ENV{'form.dis'})) {
  707: 	my $url=$ENV{'form.url'};
  708: 	$url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
  709: 	$pssymb=&Apache::lonnet::symbread($url);
  710: 	if (!@pscat) { @pscat=('all'); }
  711: 	$pschp='';
  712:         $parmlev = 'full';
  713:     } elsif ($ENV{'form.symb'}) {
  714: 	$pssymb=$ENV{'form.symb'};
  715: 	if (!@pscat) { @pscat=('all'); }
  716: 	$pschp='';
  717:         $parmlev = 'full';
  718:     } else {
  719: 	$ENV{'form.url'}='';
  720:     }
  721: 
  722:     my $id=$ENV{'form.id'};
  723:     if (($id) && ($udom)) {
  724: 	$uname=(&Apache::lonnet::idget($udom,$id))[1];
  725: 	if ($uname) {
  726: 	    $id='';
  727: 	} else {
  728: 	    $message=
  729: 		"<font color=red>Unknown ID '$id' at domain '$udom'</font>";
  730: 	}
  731:     } else {
  732: 	$uname=$ENV{'form.uname'};
  733:     }
  734:     unless ($udom) { $uname=''; }
  735:     $uhome='';
  736:     if ($uname) {
  737: 	$uhome=&Apache::lonnet::homeserver($uname,$udom);
  738:         if ($uhome eq 'no_host') {
  739: 	    $message=
  740: 		"<font color=red>Unknown user '$uname' at domain '$udom'</font>";
  741: 	    $uname='';
  742:         } else {
  743: 	    $csec=&Apache::lonnet::getsection($udom,$uname,
  744: 					      $ENV{'request.course.id'});
  745: 	    if ($csec eq '-1') {
  746: 		$message="<font color=red>".
  747: 		    "User '$uname' at domain '$udom' not ".
  748:                     "in this course</font>";
  749: 		$uname='';
  750: 		$csec=$ENV{'form.csec'};
  751: 	    } else {
  752: 		my %name=&Apache::lonnet::userenvironment($udom,$uname,
  753: 		      ('firstname','middlename','lastname','generation','id'));
  754: 		$message="\n<p>\nFull Name: ".
  755: 		    $name{'firstname'}.' '.$name{'middlename'}.' '
  756: 			.$name{'lastname'}.' '.$name{'generation'}.
  757: 			    "<br>\nID: ".$name{'id'}.'<p>';
  758: 	    }
  759:         }
  760:     }
  761: 
  762:     unless ($csec) { $csec=''; }
  763: 
  764:     my $fcat=$ENV{'form.fcat'};
  765:     unless ($fcat) { $fcat=''; }
  766: 
  767: # ------------------------------------------------------------------- Tie hashs
  768:     if (!(tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
  769: 	      &GDBM_READER(),0640))) {
  770: 	$r->print("Unable to access course data. (File $ENV{'request.course.fn'}.db not tieable)");
  771: 	return ;
  772:     }
  773:     if (!(tie(%parmhash,'GDBM_File',
  774: 	      $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640))) {
  775: 	$r->print("Unable to access parameter data. (File $ENV{'request.course.fn'}_parms.db not tieable)");
  776: 	return ;
  777:     }
  778: 
  779: # --------------------------------------------------------- Get all assessments
  780:     extractResourceInformation(\%bighash, \@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles);
  781: 
  782:     $mapp{'0.0'} = '';
  783:     $symbp{'0.0'} = '';
  784: 
  785: # ---------------------------------------------------------- Anything to store?
  786:     if ($ENV{'form.pres_marker'}) {
  787: 	my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
  788: 	$spnam=~s/\_([^\_]+)$/\.$1/;
  789: # ---------------------------------------------------------- Construct prefixes
  790: 
  791: 	my $symbparm=$symbp{$sresid}.'.'.$spnam;
  792: 	my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
  793: 	
  794: 	my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$spnam;
  795: 	my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
  796: 	my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
  797: 	
  798: 	my $courselevel=$ENV{'request.course.id'}.'.'.$spnam;
  799: 	my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
  800: 	my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
  801: 	
  802: 	my $storeunder='';
  803: 	if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
  804: 	if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
  805: 	if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
  806: 	if ($snum==6) { $storeunder=$seclevel; }
  807: 	if ($snum==5) { $storeunder=$seclevelm; }
  808: 	if ($snum==4) { $storeunder=$seclevelr; }
  809: 	
  810: 	my $delete;
  811: 	if ($ENV{'form.pres_value'} eq '') { $delete=1;}
  812:         my %storecontent = ($storeunder         => $ENV{'form.pres_value'},
  813:                             $storeunder.'.type' => $ENV{'form.pres_type'});
  814: 	my $reply='';
  815: 	if ($snum>3) {
  816: # ---------------------------------------------------------------- Store Course
  817: #
  818: # Expire sheets
  819: 	    &Apache::lonnet::expirespread('','','studentcalc');
  820: 	    if (($snum==7) || ($snum==4)) {
  821: 		&Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
  822: 	    } elsif (($snum==8) || ($snum==5)) {
  823: 		&Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
  824: 	    } else {
  825: 		&Apache::lonnet::expirespread('','','assesscalc');
  826: 	    }
  827: # Store parameter
  828: 	    if ($delete) {
  829: 		$reply=&Apache::lonnet::del
  830: 		    ('resourcedata',[keys(%storecontent)],
  831: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  832: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  833: 	    } else {
  834: 		$reply=&Apache::lonnet::cput
  835: 		    ('resourcedata',\%storecontent,
  836: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  837: 		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  838: 	    }
  839: 	} else {
  840: # ------------------------------------------------------------------ Store User
  841: #
  842: # Expire sheets
  843: 	    &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
  844: 	    if ($snum==1) {
  845: 		&Apache::lonnet::expirespread
  846: 		    ($uname,$udom,'assesscalc',$symbp{$sresid});
  847: 	    } elsif ($snum==2) {
  848: 		&Apache::lonnet::expirespread
  849: 		    ($uname,$udom,'assesscalc',$mapp{$sresid});
  850: 	    } else {
  851: 		&Apache::lonnet::expirespread($uname,$udom,'assesscalc');
  852: 	    }
  853: # Store parameter
  854: 	    if ($delete) {
  855: 		$reply=&Apache::lonnet::del
  856: 		    ('resourcedata',[keys(%storecontent)],$udom,$uname);
  857: 	    } else {
  858: 		$reply=&Apache::lonnet::cput
  859: 		    ('resourcedata',\%storecontent,$udom,$uname);
  860: 	    }
  861: 	}
  862: 
  863: 	if ($reply=~/^error\:(.*)/) {
  864: 	    $message.="<font color=red>Write Error: $1</font>";
  865: 	}
  866: # ---------------------------------------------------------------- Done storing
  867: 	$message.='<h3>Changes can take up to 10 minutes before being active for all students.'.&Apache::loncommon::help_open_topic('Caching').'</h3>';
  868:     }
  869: # --------------------------------------------- Devalidate cache for this child
  870:     &Apache::lonnet::devalidatecourseresdata(
  871:                  $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
  872:                  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'});
  873:     &Apache::lonnet::clear_EXT_cache_status();
  874: # -------------------------------------------------------------- Get coursedata
  875:     %courseopt = &Apache::lonnet::dump
  876:         ('resourcedata',
  877:          $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
  878:          $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
  879: # --------------------------------------------------- Get userdata (if present)
  880:     if ($uname) {
  881:         %useropt=&Apache::lonnet::dump('resourcedata',$udom,$uname);
  882:     }
  883: 
  884: # ------------------------------------------------------------------- Sort this
  885: 
  886:     @ids=sort  {
  887: 	if ($fcat eq '') {
  888: 	    $a<=>$b;
  889: 	} else {
  890: 	    my ($result,@outpar)=&parmval($fcat,$a,$defp{$a});
  891: 	    my $aparm=$outpar[$result];
  892: 	    ($result,@outpar)=&parmval($fcat,$b,$defp{$b});
  893: 	    my $bparm=$outpar[$result];
  894: 	    1*$aparm<=>1*$bparm;
  895: 	}
  896:     } @ids;
  897: #----------------------------------------------- if all selected, fill in array
  898:     if ($pscat[0] eq "all" || !@pscat) {@pscat = (keys %allparms);}
  899:     if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
  900: # ------------------------------------------------------------------ Start page
  901: 
  902:     my $have_assesments=1;
  903:     if (scalar(keys(%allkeys)) eq 0) { $have_assesments=0; }
  904: 
  905:     &startpage($r,$id,$udom,$csec,$uname,$have_assesments);
  906: 
  907:     if (!$have_assesments) {
  908: 	untie(%bighash);
  909: 	untie(%parmhash);
  910: 	return '';
  911:     }
  912: #    if ($ENV{'form.url'}) {
  913: #	$r->print('<input type="hidden" value="'.$ENV{'form.url'}.
  914: #		  '" name="url"><input type="hidden" name="command" value="set">');
  915: #    }
  916:     $r->print('<input type="hidden" value="true" name="prevvisit">');
  917: 
  918:     foreach ('tolerance','date_default','date_start','date_end',
  919: 	     'date_interval','int','float','string') {
  920: 	$r->print('<input type="hidden" value="'.
  921: 		  $ENV{'form.recent_'.$_}.'" name="recent_'.$_.'">');
  922:     }
  923: 
  924:     $r->print('<h2>'.$message.'</h2><table>');
  925:                         
  926:     my $submitmessage = 'Update Section or Specific User';
  927:     if (!$pssymb) {
  928:         $r->print('<tr><td>Select Parameter Level</td><td colspan="2">');
  929:         $r->print('<select name="parmlev">');
  930:         foreach (reverse sort keys %alllevs) {
  931:             $r->print('<option value="'.$alllevs{$_}.'"');
  932:             if ($parmlev eq $alllevs{$_}) {
  933:                $r->print(' selected'); 
  934:             }
  935:             $r->print('>'.$_.'</option>');
  936:         }
  937:         $r->print("</select></td>\n");
  938: 
  939:         $r->print('</tr>');
  940: 
  941:         $r->print('<tr><td>Select Enclosing Map or Folder</td>');
  942:         $r->print('<td colspan="2"><select name="pschp">');
  943:         $r->print('<option value="all">All Maps or Folders</option>');
  944:         foreach (sort {$allmaps{$a} cmp $allmaps{$b}} keys %allmaps) {
  945:             $r->print('<option value="'.$_.'"');
  946:             if (($pschp eq $_)) { $r->print(' selected'); }
  947:             $r->print('>'.$maptitles{$_}.($allmaps{$_}!~/^uploaded/?'  ['.$allmaps{$_}.']':'').'</option>');
  948:         }
  949:         $r->print("</select></td></tr>\n");
  950:     } else {
  951:         my ($map,$id,$resource)=split(/___/,$pssymb);
  952:         $r->print("<tr><td>Specific Resource</td><td>$resource</td>");
  953:         $r->print('<td><input type="submit" name="dis" value="'.$submitmessage.'"></td>');
  954:         $r->print('</tr>');
  955:         $r->print('<input type="hidden" value="'.$pssymb.'" name="symb">');
  956:     }
  957: 
  958:     $r->print('<tr><td colspan="3"><hr /><input type="checkbox"');
  959:     if ($showoptions eq 'show') {$r->print(" checked ");}
  960:     $r->print(' name="showoptions" value="show">Show More Options<hr /></td></tr>');
  961: #    $r->print("<tr><td>Show: $showoptions</td></tr>");
  962: #    $r->print("<tr><td>pscat: @pscat</td></tr>");
  963: #    $r->print("<tr><td>psprt: @psprt</td></tr>");
  964: #    $r->print("<tr><td>fcat:  $fcat</td></tr>");
  965: 
  966:     if ($showoptions eq 'show') {
  967:         my $tempkey;
  968: 
  969:         $r->print('<tr><td colspan="3" align="center">Select Parameters to View</td></tr>');
  970: 
  971:         $r->print('<tr><td colspan="2"><table>');
  972:         $r->print('<tr><td><input type="checkbox" name="pscat" value="all"');
  973:         $r->print(' checked') unless (@pscat);
  974:         $r->print('>All Parameters</td>');
  975: 
  976:         my $cnt=0;
  977:         foreach $tempkey (sort { $allparms{$a} cmp $allparms{$b} }
  978:                       keys %allparms ) {
  979:             ++$cnt;
  980:             $r->print('</tr><tr>') unless ($cnt%2);
  981:             $r->print('<td><input type="checkbox" name="pscat" ');
  982:             $r->print('value="'.$tempkey.'"');
  983:             if ($pscat[0] eq "all" || grep $_ eq $tempkey, @pscat) {
  984:                 $r->print(' checked');
  985:             }
  986:             $r->print('>'.$allparms{$tempkey}.'</td>');
  987:         }
  988:         $r->print('</tr></table>');
  989: 
  990: #        $r->print('<tr><td>Select Parts</td><td>');
  991:         $r->print('<td><select multiple name="psprt" size="5">');
  992:         $r->print('<option value="all"');
  993:         $r->print(' selected') unless (@psprt);
  994:         $r->print('>All Parts</option>');
  995:         my %temphash=();
  996:         foreach (@psprt) { $temphash{$_}=1; }
  997:         foreach $tempkey (sort keys %allparts) {
  998:             unless ($tempkey =~ /\./) {
  999:                 $r->print('<option value="'.$tempkey.'"');
 1000:                 if ($psprt[0] eq "all" ||  $temphash{$tempkey}) {
 1001:                     $r->print(' selected');
 1002:                 }
 1003:                 $r->print('>'.$allparts{$tempkey}.'</option>');
 1004:             }
 1005:         }
 1006:         $r->print('</select></td></tr><tr><td colspan="3"><hr /></td></tr>');
 1007: 
 1008:         $r->print('<tr><td>Sort list by</td><td>');
 1009:         $r->print('<select name="fcat">');
 1010:         $r->print('<option value="">Enclosing Map or Folder</option>');
 1011:         foreach (sort keys %allkeys) {
 1012:             $r->print('<option value="'.$_.'"');
 1013:             if ($fcat eq $_) { $r->print(' selected'); }
 1014:             $r->print('>'.$allkeys{$_}.'</option>');
 1015:         }
 1016:         $r->print('</select></td>');
 1017: 
 1018:         $r->print('</tr><tr><td colspan="3"><hr /></td></tr>');
 1019: 
 1020:     } else { # hide options - include any necessary extras here
 1021: 
 1022:         $r->print('<input type="hidden" name="fcat" value="'.$fcat.'">'."\n");
 1023: 
 1024:         unless (@pscat) {
 1025:           foreach (keys %allparms ) {
 1026:             $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
 1027:           }
 1028:         } else {
 1029:           foreach (@pscat) {
 1030:             $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
 1031:           }
 1032:         }
 1033: 
 1034:         unless (@psprt) {
 1035:           foreach (keys %allparts ) {
 1036:             $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
 1037:           }
 1038:         } else {
 1039:           foreach (@psprt) {
 1040:             $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
 1041:           }
 1042:         }
 1043: 
 1044:     }
 1045:     $r->print('</table><br />');
 1046:     if (($prevvisit) || ($pschp) || ($pssymb)) {
 1047:         $submitmessage = "Update Course Assessment Parameter Display";
 1048:     } else {
 1049:         $submitmessage = "Set/Modify Course Assessment Parameters";
 1050:     }
 1051:     $r->print('<input type="submit" name="dis" value="'.$submitmessage.'">');
 1052: 
 1053: #    my @temp_psprt;
 1054: #    foreach my $t (@psprt) {
 1055: #	push(@temp_psprt, grep {eval (/^$t\./ || ($_ == $t))} (keys %allparts));
 1056: #    }
 1057: 
 1058: #    @psprt = @temp_psprt;
 1059: 
 1060:     my @temp_pscat;
 1061:     map {
 1062:         my $cat = $_;
 1063:         push(@temp_pscat, map { $_.'.'.$cat } @psprt);
 1064:     } @pscat;
 1065: 
 1066:     @pscat = @temp_pscat;
 1067: 
 1068:     if (($prevvisit) || ($pschp) || ($pssymb)) {
 1069: # ----------------------------------------------------------------- Start Table
 1070:         my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
 1071:         my $csuname=$ENV{'user.name'};
 1072:         my $csudom=$ENV{'user.domain'};
 1073: 
 1074:         if ($parmlev eq 'full' || $parmlev eq 'brief') {
 1075:            my $coursespan=$csec?8:5;
 1076:            $r->print('<p><table border=2>');
 1077:            $r->print('<tr><td colspan=5></td>');
 1078:            $r->print('<th colspan='.($coursespan).'>Any User</th>');
 1079:            if ($uname) {
 1080:                $r->print("<th colspan=3 rowspan=2>");
 1081:                $r->print("User $uname at Domain $udom</th>");
 1082:            }
 1083:            $r->print(<<ENDTABLETWO);
 1084: <th rowspan=3>Parameter in Effect</th>
 1085: <th rowspan=3>Current Session Value<br>($csuname at $csudom)</th>
 1086: </tr><tr><td colspan=5></td><th colspan=2>Resource Level</th>
 1087: <th colspan=3>in Course</th>
 1088: ENDTABLETWO
 1089:            if ($csec) {
 1090:                 $r->print("<th colspan=3>in Section/Group $csec</th>");
 1091:            }
 1092:            $r->print(<<ENDTABLEHEADFOUR);
 1093: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
 1094: <th>Enclosing Map or Folder</th><th>Part</th><th>Parameter Name</th>
 1095: <th>default</th><th>from Enclosing Map or Folder</th>
 1096: <th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>
 1097: ENDTABLEHEADFOUR
 1098: 
 1099:            if ($csec) {
 1100:                $r->print('<th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>');
 1101:            }
 1102: 
 1103:            if ($uname) {
 1104:                $r->print('<th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>');
 1105:            }
 1106: 
 1107:            $r->print('</tr>');
 1108: 
 1109:            my $defbgone='';
 1110:            my $defbgtwo='';
 1111: 
 1112:            foreach (@ids) {
 1113: 
 1114:                 my $rid=$_;
 1115:                 my ($inmapid)=($rid=~/\.(\d+)$/);
 1116: 
 1117:                 if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
 1118:                     ($pssymb eq $symbp{$rid})) {
 1119: # ------------------------------------------------------ Entry for one resource
 1120:                     if ($defbgone eq '"E0E099"') {
 1121:                         $defbgone='"E0E0DD"';
 1122:                     } else {
 1123:                         $defbgone='"E0E099"';
 1124:                     }
 1125:                     if ($defbgtwo eq '"FFFF99"') {
 1126:                         $defbgtwo='"FFFFDD"';
 1127:                     } else {
 1128:                         $defbgtwo='"FFFF99"';
 1129:                     }
 1130:                     my $thistitle='';
 1131:                     my %name=   ();
 1132:                     undef %name;
 1133:                     my %part=   ();
 1134:                     my %display=();
 1135:                     my %type=   ();
 1136:                     my %default=();
 1137:                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1138: 
 1139:                     foreach (split(/\,/,$keyp{$rid})) {
 1140:                         my $tempkeyp = $_;
 1141:                         if (grep $_ eq $tempkeyp, @catmarker) {
 1142:                           $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
 1143:                           $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
 1144:                           $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
 1145:                           unless ($display{$_}) { $display{$_}=''; }
 1146:                           $display{$_}.=' ('.$name{$_}.')';
 1147:                           $default{$_}=&Apache::lonnet::metadata($uri,$_);
 1148:                           $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
 1149:                           $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
 1150:                         }
 1151:                     }
 1152:                     my $totalparms=scalar keys %name;
 1153:                     if ($totalparms>0) {
 1154:                         my $firstrow=1;
 1155: 
 1156:                         $r->print('<tr><td bgcolor='.$defbgone.
 1157:                              ' rowspan='.$totalparms.
 1158:                              '><tt><font size=-1>'.
 1159:                              join(' / ',split(/\//,$uri)).
 1160:                              '</font></tt><p><b>'.
 1161:                              "<a href=\"javascript:openWindow('/res/".$uri.
 1162:                              "', 'metadatafile', '450', '500', 'no', 'yes')\";".
 1163:                              " TARGET=_self>$bighash{'title_'.$rid}");
 1164: 
 1165:                         if ($thistitle) {
 1166:                             $r->print(' ('.$thistitle.')');
 1167:                         }
 1168:                         $r->print('</a></b></td>');
 1169:                         $r->print('<td bgcolor='.$defbgtwo.
 1170:                                       ' rowspan='.$totalparms.'>'.$typep{$rid}.
 1171:                                       '</td>');
 1172: 
 1173:                         $r->print('<td bgcolor='.$defbgone.
 1174:                                       ' rowspan='.$totalparms.
 1175:                                       '><tt><font size=-1>');
 1176: 
 1177:                         $r->print(' / res / ');
 1178:                         $r->print(join(' / ', split(/\//,$mapp{$rid})));
 1179: 
 1180:                         $r->print('</font></tt></td>');
 1181: 
 1182:                         foreach (sort keys %name) {
 1183:                             unless ($firstrow) {
 1184:                                 $r->print('<tr>');
 1185:                             } else {
 1186:                                 undef $firstrow;
 1187:                             }
 1188: 
 1189:                             &print_row($r,$_,\%part,\%name,$rid,\%default,
 1190:                                        \%type,\%display,$defbgone,$defbgtwo,
 1191:                                        $parmlev);
 1192:                         }
 1193:                     }
 1194:                 }
 1195:             } # end foreach ids
 1196: # -------------------------------------------------- End entry for one resource
 1197:             $r->print('</table>');
 1198:         } # end of  brief/full
 1199: #--------------------------------------------------- Entry for parm level map
 1200:         if ($parmlev eq 'map') {
 1201:             my $defbgone = '"E0E099"';
 1202:             my $defbgtwo = '"FFFF99"';
 1203: 
 1204:             my %maplist;
 1205: 
 1206:             if ($pschp eq 'all') {
 1207:                 %maplist = %allmaps; 
 1208:             } else {
 1209:                 %maplist = ($pschp => $mapp{$pschp});
 1210:             }
 1211: 
 1212: #-------------------------------------------- for each map, gather information
 1213:             my $mapid;
 1214: 	    foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
 1215:                 my $maptitle = $maplist{$mapid};
 1216: 
 1217: #-----------------------  loop through ids and get all parameter types for map
 1218: #-----------------------------------------          and associated information
 1219:                 my %name = ();
 1220:                 my %part = ();
 1221:                 my %display = ();
 1222:                 my %type = ();
 1223:                 my %default = ();
 1224:                 my $map = 0;
 1225: 
 1226: #		$r->print("Catmarker: @catmarker<br />\n");
 1227:                
 1228:                 foreach (@ids) {
 1229:                   ($map)=(/([\d]*?)\./);
 1230:                   my $rid = $_;
 1231:         
 1232: #                  $r->print("$mapid:$map:   $rid <br /> \n");
 1233: 
 1234:                   if ($map eq $mapid) {
 1235:                     my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1236: #                    $r->print("Keys: $keyp{$rid} <br />\n");
 1237: 
 1238: #--------------------------------------------------------------------
 1239: # @catmarker contains list of all possible parameters including part #s
 1240: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1241: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1242: # When storing information, store as part 0
 1243: # When requesting information, request from full part
 1244: #-------------------------------------------------------------------
 1245:                     foreach (split(/\,/,$keyp{$rid})) {
 1246:                       my $tempkeyp = $_;
 1247:                       my $fullkeyp = $tempkeyp;
 1248:                       $tempkeyp =~ s/_\w+_/_0_/;
 1249:                       
 1250:                       if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1251:                         $part{$tempkeyp}="0";
 1252:                         $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1253:                         $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1254:                         unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1255:                         $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1256:                         $display{$tempkeyp} =~ s/_\w+_/_0_/;
 1257:                         $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1258:                         $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1259:                       }
 1260:                     } # end loop through keys
 1261:                   }
 1262:                 } # end loop through ids
 1263:                                  
 1264: #---------------------------------------------------- print header information
 1265:                 my $foldermap=($maptitle=~/^uploaded/?'Folder':'Map');
 1266:                 my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
 1267:                 $r->print(<<ENDMAPONE);
 1268: <center><h4>
 1269: <font color="red">Set Defaults for All Resources in $foldermap<br />
 1270: <i>$showtitle</i><br />
 1271: Specifically for
 1272: ENDMAPONE
 1273:                 if ($uname) {
 1274:                     my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1275:                       ('firstname','middlename','lastname','generation', 'id'));
 1276:                     my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1277:                            .$name{'lastname'}.' '.$name{'generation'};
 1278:                     $r->print("User <i>$uname \($person\) </i> in \n");
 1279:                 } else {
 1280:                     $r->print("<i>all</i> users in \n");
 1281:                 }
 1282:             
 1283:                 if ($csec) {$r->print("Section <i>$csec</i> of \n")};
 1284: 
 1285:                 $r->print("<i>$coursename</i><br />");
 1286:                 $r->print("</font></h4>\n");
 1287: #---------------------------------------------------------------- print table
 1288:                 $r->print('<p><table border="2">');
 1289:                 $r->print('<tr><th>Parameter Name</th>');
 1290:                 $r->print('<th>Default Value</th>');
 1291:                 $r->print('<th>Parameter in Effect</th></tr>');
 1292: 
 1293: 	        foreach (sort keys %name) {
 1294:                     &print_row($r,$_,\%part,\%name,$mapid,\%default,
 1295:                            \%type,\%display,$defbgone,$defbgtwo,
 1296:                            $parmlev);
 1297: #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
 1298:                 }
 1299:                 $r->print("</table></center>");
 1300:             } # end each map
 1301:         } # end of $parmlev eq map
 1302: #--------------------------------- Entry for parm level general (Course level)
 1303:         if ($parmlev eq 'general') {
 1304:             my $defbgone = '"E0E099"';
 1305:             my $defbgtwo = '"FFFF99"';
 1306: 
 1307: #-------------------------------------------- for each map, gather information
 1308:             my $mapid="0.0";
 1309: #-----------------------  loop through ids and get all parameter types for map
 1310: #-----------------------------------------          and associated information
 1311:             my %name = ();
 1312:             my %part = ();
 1313:             my %display = ();
 1314:             my %type = ();
 1315:             my %default = ();
 1316:                
 1317:             foreach (@ids) {
 1318:                 my $rid = $_;
 1319:         
 1320:                 my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
 1321: 
 1322: #--------------------------------------------------------------------
 1323: # @catmarker contains list of all possible parameters including part #s
 1324: # $fullkeyp contains the full part/id # for the extraction of proper parameters
 1325: # $tempkeyp contains part 0 only (no ids - ie, subparts)
 1326: # When storing information, store as part 0
 1327: # When requesting information, request from full part
 1328: #-------------------------------------------------------------------
 1329:                 foreach (split(/\,/,$keyp{$rid})) {
 1330:                   my $tempkeyp = $_;
 1331:                   my $fullkeyp = $tempkeyp;
 1332:                   $tempkeyp =~ s/_\w+_/_0_/;
 1333:                   if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
 1334:                     $part{$tempkeyp}="0";
 1335:                     $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
 1336:                     $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
 1337:                     unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
 1338:                     $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
 1339:                     $display{$tempkeyp} =~ s/_\w+_/_0_/;
 1340:                     $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
 1341:                     $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
 1342:                   }
 1343:                 } # end loop through keys
 1344:             } # end loop through ids
 1345:                                  
 1346: #---------------------------------------------------- print header information
 1347:             $r->print(<<ENDMAPONE);
 1348: <center><h4>
 1349: <font color="red">Set Defaults for All Resources in Course
 1350: <i>$coursename</i><br />
 1351: ENDMAPONE
 1352:             if ($uname) {
 1353:                 my %name=&Apache::lonnet::userenvironment($udom,$uname,
 1354:                   ('firstname','middlename','lastname','generation', 'id'));
 1355:                 my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
 1356:                        .$name{'lastname'}.' '.$name{'generation'};
 1357:                 $r->print(" User <i>$uname \($person\) </i> \n");
 1358:             } else {
 1359:                 $r->print("<i>ALL</i> USERS \n");
 1360:             }
 1361:             
 1362:             if ($csec) {$r->print("Section <i>$csec</i>\n")};
 1363:             $r->print("</font></h4>\n");
 1364: #---------------------------------------------------------------- print table
 1365:             $r->print('<p><table border="2">');
 1366:             $r->print('<tr><th>Parameter Name</th>');
 1367:             $r->print('<th>Default Value</th>');
 1368:             $r->print('<th>Parameter in Effect</th></tr>');
 1369: 
 1370: 	    foreach (sort keys %name) {
 1371:                 &print_row($r,$_,\%part,\%name,$mapid,\%default,
 1372:                        \%type,\%display,$defbgone,$defbgtwo,$parmlev);
 1373: #                    $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
 1374:             }
 1375:             $r->print("</table></center>");
 1376:         } # end of $parmlev eq general
 1377:     }
 1378:     $r->print('</form></body></html>');
 1379:     untie(%bighash);
 1380:     untie(%parmhash);
 1381: } # end sub assessparms
 1382: 
 1383: 
 1384: ##################################################
 1385: ##################################################
 1386: 
 1387: =pod
 1388: 
 1389: =item crsenv
 1390: 
 1391: Show and set course data and parameters.  This is a large routine that should
 1392: be simplified and shortened... someday.
 1393: 
 1394: Inputs: $r
 1395: 
 1396: Returns: nothing
 1397: 
 1398: =cut
 1399: 
 1400: ##################################################
 1401: ##################################################
 1402: sub crsenv {
 1403:     my $r=shift;
 1404:     my $setoutput='';
 1405:     my $bodytag=&Apache::loncommon::bodytag(
 1406:                              'Set Course Environment Parameters');
 1407:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
 1408:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
 1409: 
 1410:     #
 1411:     # Go through list of changes
 1412:     foreach (keys %ENV) {
 1413:         next if ($_!~/^form\.(.+)\_setparmval$/);
 1414:         my $name  = $1;
 1415:         my $value = $ENV{'form.'.$name.'_value'};
 1416:         if ($name eq 'newp') {
 1417:             $name = $ENV{'form.newp_name'};
 1418:         }
 1419:         if ($name eq 'url') {
 1420:             $value=~s/^\/res\///;
 1421:             my $bkuptime=time;
 1422:             my @tmp = &Apache::lonnet::get
 1423:                 ('environment',['url'],$dom,$crs);
 1424:             $setoutput.='Backing up previous URL: '.
 1425:                 &Apache::lonnet::put
 1426:                 ('environment',
 1427:                  {'top level map backup '.$bkuptime => $tmp[1] },
 1428:                  $dom,$crs).
 1429:                      '<br>';
 1430:         }
 1431:         #
 1432:         # Deal with modified default spreadsheets
 1433:         if ($name =~ /^spreadsheet_default_(classcalc|
 1434:                                             studentcalc|
 1435:                                             assesscalc)$/x) {
 1436:             my $sheettype = $1; 
 1437:             if ($sheettype eq 'classcalc') {
 1438:                 # no need to do anything since viewing the sheet will
 1439:                 # cause it to be updated. 
 1440:             } elsif ($sheettype eq 'studentcalc') {
 1441:                 # expire all the student spreadsheets
 1442:                 &Apache::lonnet::expirespread('','','studentcalc');
 1443:             } else {
 1444:                 # expire all the assessment spreadsheets 
 1445:                 #    this includes non-default spreadsheets, but better to
 1446:                 #    be safe than sorry.
 1447:                 &Apache::lonnet::expirespread('','','assesscalc');
 1448:                 # expire all the student spreadsheets
 1449:                 &Apache::lonnet::expirespread('','','studentcalc');
 1450:             }
 1451:         }
 1452:         #
 1453:         # Deal with the enrollment dates
 1454:         if ($name =~ /^default_enrollment_(start|end)_date$/) {
 1455:             $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
 1456:         }
 1457:         #
 1458:         # Let the user know we made the changes
 1459:         if ($name) {
 1460:             my $put_result = &Apache::lonnet::put('environment',
 1461:                                                   {$name=>$value},$dom,$crs);
 1462:             if ($put_result eq 'ok') {
 1463:                 $setoutput.='Set <b>'.$name.'</b> to <b>'.$value.'</b>.<br />';
 1464:             } else {
 1465:                 $setoutput.='Unable to set <b>'.$name.'</b> to '.
 1466:                     '<b>'.$value.'</b> due to '.$put_result.'.<br />';
 1467:             }
 1468:         }
 1469:     }
 1470: # ------------------------- Re-init course environment entries for this session
 1471: 
 1472:     &Apache::lonnet::coursedescription($ENV{'request.course.id'});
 1473: 
 1474: # -------------------------------------------------------- Get parameters again
 1475: 
 1476:     my %values=&Apache::lonnet::dump('environment',$dom,$crs);
 1477:     my $output='';
 1478:     if (! exists($values{'con_lost'})) {
 1479:         my %descriptions=
 1480: 	    ('url'            => '<b>Top Level Map</b> '.
 1481:                                  '<a href="javascript:openbrowser'.
 1482:                                  "('envform','url','sequence')\">".
 1483:                                  'Select Map</a><br /><font color=red> '.
 1484:                                  'Modification may make assessment data '.
 1485:                                  'inaccessible</font>',
 1486:              'description'    => '<b>Course Description</b>',
 1487:              'courseid'       => '<b>Course ID or number</b><br />'.
 1488:                                  '(internal, optional)',
 1489:              'grading'        => '<b>Grading</b>'.
 1490:                                  '"standard" or any other value.  '.
 1491:                                  'Default for new courses is "standard".',
 1492: 
 1493:              'default_xml_style' => '<b>Default XML Style File</b> '.
 1494:                     '<a href="javascript:openbrowser'.
 1495:                     "('envform','default_xml_style'".
 1496:                     ",'sty')\">Select Style File</a><br>",
 1497:              'question.email' => '<b>Feedback Addresses for Resource Content '.
 1498:                                  'Questions</b><br />(<tt>user:domain,'.
 1499:                                  'user:domain(section;section;...;*;...),...</tt>)',
 1500:              'comment.email'  => '<b>Feedback Addresses for Course Content Comments</b><br />'.
 1501:                                  '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
 1502:              'policy.email'   => '<b>Feedback Addresses for Course Policy</b>'.
 1503:                                  '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
 1504:              'hideemptyrows'  => '<b>Hide Empty Rows in Spreadsheets</b><br />'.
 1505:                                  '("<tt>yes</tt>" for default hiding)',
 1506:              'pageseparators'  => '<b>Visibly Separate Items on Pages</b><br />'.
 1507:                                  '("<tt>yes</tt>" for visible separation, '.
 1508:                                  'changes will not show until next login)',
 1509: 
 1510:              'plc.roles.denied'=> '<b>Disallow live chatroom use for '.
 1511:                                   'Roles</b><br />"<tt>st</tt>": '.
 1512:                                   'student, "<tt>ta</tt>": '.
 1513:                                   'TA, "<tt>in</tt>": '.
 1514:                                   'instructor;<br /><tt>role,role,...</tt>) '.
 1515: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
 1516:              'plc.users.denied' => 
 1517:                           '<b>Disallow live chatroom use for Users</b><br />'.
 1518:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1519: 
 1520:              'pch.roles.denied'=> '<b>Disallow Resource Discussion for '.
 1521:                                   'Roles</b><br />"<tt>st</tt>": '.
 1522:                                   'student, "<tt>ta</tt>": '.
 1523:                                   'TA, "<tt>in</tt>": '.
 1524:                                   'instructor;<br /><tt>role,role,...</tt>) '.
 1525: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
 1526:              'pch.users.denied' => 
 1527:                           '<b>Disallow Resource Discussion for Users</b><br />'.
 1528:                                  '(<tt>user:domain,user:domain,...</tt>)',
 1529:              'spreadsheet_default_classcalc' 
 1530:                  => '<b>Default Course Spreadsheet</b> '.
 1531:                     '<a href="javascript:openbrowser'.
 1532:                     "('envform','spreadsheet_default_classcalc'".
 1533:                     ",'spreadsheet')\">Select Spreadsheet File</a><br />",
 1534:              'spreadsheet_default_studentcalc' 
 1535:                  => '<b>Default Student Spreadsheet</b> '.
 1536:                     '<a href="javascript:openbrowser'.
 1537:                     "('envform','spreadsheet_default_calc'".
 1538:                     ",'spreadsheet')\">Select Spreadsheet File</a><br />",
 1539:              'spreadsheet_default_assesscalc' 
 1540:                  => '<b>Default Assessment Spreadsheet</b> '.
 1541:                     '<a href="javascript:openbrowser'.
 1542:                     "('envform','spreadsheet_default_assesscalc'".
 1543:                     ",'spreadsheet')\">Select Spreadsheet File</a><br />",
 1544: 	     'allow_limited_html_in_feedback'
 1545: 	         => '<b>Allow limited HTML in discussion posts</b><br />'.
 1546: 	            '(Set value to "<tt>yes</tt>" to allow)',
 1547: 	     'rndseed'
 1548: 	         => '<b>Randomization algorithm used</b> <br />'.
 1549:                     '<font color="red">Modifying this will make problems '.
 1550:                     'have different numbers and answers</font>',
 1551:              'problem_stream_switch'
 1552:                  => '<b>Allow problems to be split over pages</b><br />'.
 1553:                     ' ("<tt>yes</tt>" if allowed, anything else if not)',
 1554:              'anonymous_quiz'
 1555:                  => '<b>Anonimous quiz/exam</b><br />'.
 1556:                     ' (<tt><b>yes</b> to avoid print students names </tt>)',
 1557:              'default_enrollment_start_date' => '<b>Default beginning date '.
 1558:                                                 'when enrolling students</b>',
 1559:              'default_enrollment_end_date'   => '<b>Default ending date '.
 1560:                                                 'when enrolling students</b>',
 1561:              'languages' => '<b>Languages used</b>',
 1562:              'disable_receipt_display'
 1563:                  => '<b>Disable display of problem receipts</b><br />'.
 1564:                     ' ("<tt>yes</tt>" to disable, anything else if not)'
 1565:              ); 
 1566:         my @Display_Order = ('url','description','courseid','grading',
 1567:                              'default_xml_style','pageseparators',
 1568:                              'question.email','comment.email','policy.email',
 1569:                              'plc.roles.denied','plc.users.denied',
 1570:                              'pch.roles.denied','pch.users.denied',
 1571:                              'allow_limited_html_in_feedback',
 1572:                              'languages',
 1573:                              'rndseed',
 1574:                              'problem_stream_switch',
 1575:                              'disable_receipt_display',
 1576:                              'spreadsheet_default_classcalc',
 1577:                              'spreadsheet_default_studentcalc',
 1578:                              'spreadsheet_default_assesscalc', 
 1579:                              'hideemptyrows',
 1580:                              'default_enrollment_start_date',
 1581:                              'default_enrollment_end_date',
 1582:                              );
 1583: 	foreach my $parameter (sort(keys(%values))) {
 1584: 	    if (! $descriptions{$parameter}) {
 1585:                 $descriptions{$parameter}=$parameter;
 1586:                 push(@Display_Order,$parameter);
 1587: 	    }
 1588: 	}
 1589:         foreach my $parameter (@Display_Order) {
 1590:             my $description = $descriptions{$parameter};
 1591:             # onchange is javascript to automatically check the 'Set' button.
 1592:             my $onchange = 'onFocus="javascript:window.document.forms'.
 1593:                 "['envform'].elements['".$parameter."_setparmval']".
 1594:                 '.checked=true;"';
 1595:             $output .= '<tr><td>'.$description.'</td>';
 1596:             if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
 1597:                 $output .= '<td>'.
 1598:                     &Apache::lonhtmlcommon::date_setter('envform',
 1599:                                                         $parameter.'_value',
 1600:                                                         $values{$parameter},
 1601:                                                         $onchange).
 1602:                                                         '</td>';
 1603:             } else {
 1604:                 $output .= '<td>'.
 1605:                     &Apache::lonhtmlcommon::textbox($parameter.'_value',
 1606:                                                     $values{$parameter},
 1607:                                                     40,$onchange).'</td>';
 1608:             }
 1609:             $output .= '<td>'.
 1610:                 &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
 1611:                 '</td>';
 1612:             $output .= "</tr>\n";
 1613: 	}
 1614:         my $onchange = 'onFocus="javascript:window.document.forms'.
 1615:             '[\'envform\'].elements[\'newp_setparmval\']'.
 1616:             '.checked=true;"';
 1617: 	$output.='<tr><td><i>Create New Environment Variable</i><br />'.
 1618: 	    '<input type="text" size=40 name="newp_name" '.
 1619:                 $onchange.' /></td><td>'.
 1620:             '<input type="text" size=40 name="newp_value" '.
 1621:                 $onchange.' /></td><td>'.
 1622: 	    '<input type="checkbox" name="newp_setparmval" /></td></tr>';
 1623:     }
 1624:     $r->print(<<ENDENV);
 1625: <html>
 1626: <script type="text/javascript" language="Javascript" >
 1627:     var editbrowser;
 1628:     function openbrowser(formname,elementname,only,omit) {
 1629:         var url = '/res/?';
 1630:         if (editbrowser == null) {
 1631:             url += 'launch=1&';
 1632:         }
 1633:         url += 'catalogmode=interactive&';
 1634:         url += 'mode=parmset&';
 1635:         url += 'form=' + formname + '&';
 1636:         if (only != null) {
 1637:             url += 'only=' + only + '&';
 1638:         } 
 1639:         if (omit != null) {
 1640:             url += 'omit=' + omit + '&';
 1641:         }
 1642:         url += 'element=' + elementname + '';
 1643:         var title = 'Browser';
 1644:         var options = 'scrollbars=1,resizable=1,menubar=0';
 1645:         options += ',width=700,height=600';
 1646:         editbrowser = open(url,title,options,'1');
 1647:         editbrowser.focus();
 1648:     }
 1649: </script>
 1650: <head>
 1651: <title>LON-CAPA Course Environment</title>
 1652: </head>
 1653: $bodytag
 1654: <form method="post" action="/adm/parmset" name="envform">
 1655: $setoutput
 1656: <p>
 1657: <table border=2>
 1658: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
 1659: $output
 1660: </table>
 1661: <input type="submit" name="crsenv" value="Set Course Environment">
 1662: </form>
 1663: </body>
 1664: </html>    
 1665: ENDENV
 1666: }
 1667: ##################################################
 1668: 
 1669: my $tableopen;
 1670: 
 1671: sub tablestart {
 1672:     if ($tableopen) {
 1673: 	return '';
 1674:     } else {
 1675: 	$tableopen=1;
 1676: 	return '<table border="2"><tr><th>Parameter</th><th>Delete</th><th>Set to ...</th></tr>';
 1677:     }
 1678: }
 1679: 
 1680: sub tableend {
 1681:     if ($tableopen) {
 1682: 	$tableopen=0;
 1683: 	return '</table>';
 1684:     } else {
 1685: 	return'';
 1686:     }
 1687: }
 1688: 
 1689: sub overview {
 1690:     my $r=shift;
 1691:     my $bodytag=&Apache::loncommon::bodytag(
 1692:                              'Set/Modify Course Assessment Parameters');
 1693:     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
 1694:     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
 1695:     $r->print(<<ENDOVER);
 1696: <html>
 1697: <head>
 1698: <title>LON-CAPA Course Environment</title>
 1699: </head>
 1700: $bodytag
 1701: <form method="post" action="/adm/parmset" name="overviewform">
 1702: <input type="hidden" name="overview" value="1" />
 1703: ENDOVER
 1704: # Setting
 1705:     my %olddata=&Apache::lonnet::dump('resourcedata',$dom,$crs);
 1706:     my %newdata=();
 1707:     undef %newdata;
 1708:     my @deldata=();
 1709:     undef @deldata;
 1710:     foreach (keys %ENV) {
 1711: 	if ($_=~/^form\.([a-z]+)\_(.+)$/) {
 1712: 	    my $cmd=$1;
 1713: 	    my $thiskey=$2;
 1714: 	    if ($cmd eq 'set') {
 1715: 		my $data=$ENV{$_};
 1716: 		if ($olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; }
 1717: 	    } elsif ($cmd eq 'del') {
 1718: 		push (@deldata,$thiskey);
 1719: 	    } elsif ($cmd eq 'datepointer') {
 1720: 		my $data=&Apache::lonhtmlcommon::get_date_from_form($ENV{$_});
 1721: 		if ($olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; }
 1722: 	    }
 1723: 	}
 1724:     }
 1725: # Store
 1726:     &Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs);
 1727:     &Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs);
 1728: # Read and display
 1729:     my %resourcedata=&Apache::lonnet::dump('resourcedata',$dom,$crs);
 1730:     my $oldsection='';
 1731:     my $oldrealm='';
 1732:     my $oldpart='';
 1733:     my $pointer=0;
 1734:     $tableopen=0;
 1735:     foreach my $thiskey (sort keys %resourcedata) {
 1736: 	if ($resourcedata{$thiskey.'.type'}) {
 1737: 	    my ($course,$middle,$part,$name)=
 1738: 		($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
 1739: 	    my $section='All Students';
 1740: 	    if ($middle=~/^\[(.*)\]\./) {
 1741: 		$section='Group/Section: '.$1;
 1742: 		$middle=~s/^\[(.*)\]\.//;
 1743: 	    }
 1744: 	    $middle=~s/\.$//;
 1745: 	    my $realm='<font color="red">All Resources</font>';
 1746: 	    if ($middle=~/^(.+)\_\_\_\(all\)$/) {
 1747: 		$realm='<font color="green">Folder/Map: '.&Apache::lonnet::gettitle($1).'</font>';
 1748: 	    } elsif ($middle) {
 1749: 		$realm='<font color="orange">Resource: '.&Apache::lonnet::gettitle($middle).'</font>';
 1750: 	    }
 1751: 	    if ($section ne $oldsection) {
 1752: 		$r->print(&tableend()."\n<hr /><h1>$section</h1>");
 1753: 		$oldsection=$section;
 1754: 		$oldrealm='';
 1755: 	    }
 1756: 	    if ($realm ne $oldrealm) {
 1757: 		$r->print(&tableend()."\n<h2>$realm</h2>");
 1758: 		$oldrealm=$realm;
 1759: 		$oldpart='';
 1760: 	    }
 1761: 	    if ($part ne $oldpart) {
 1762: 		$r->print(&tableend().
 1763: 			  "\n<h3><font color='blue'>Part: $part</font></h3>");
 1764: 		$oldpart=$part;
 1765: 	    }
 1766: #
 1767: # Ready to print
 1768: #
 1769: 	    $r->print(&tablestart().'<tr><td><b>'.$name.
 1770: 		      ':</b></td><td><input type="checkbox" name="del_'.
 1771: 		      $thiskey.'" /></td><td>');
 1772: 	    if ($resourcedata{$thiskey.'.type'}=~/^date/) {
 1773: 		my $jskey='key_'.$pointer;
 1774: 		$pointer++;
 1775: 		$r->print(
 1776: 			  &Apache::lonhtmlcommon::date_setter('overviewform',
 1777: 							      $jskey,
 1778: 						      $resourcedata{$thiskey}).
 1779: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'
 1780: 			  );
 1781: 	    } else {
 1782: 		$r->print(
 1783: 			  '<input type="text" name="set_'.$thiskey.'" value="'.
 1784: 			  $resourcedata{$thiskey}.'">');
 1785: 	    }
 1786: 	    $r->print('</td></tr>');
 1787: 	}
 1788:     }
 1789:     
 1790:     $r->print(&tableend().
 1791: 	      '<p><input type="submit" value="Modify Parameters" /></p></form></body></html>');
 1792: }
 1793: 
 1794: ##################################################
 1795: ##################################################
 1796: 
 1797: =pod
 1798: 
 1799: =item * handler
 1800: 
 1801: Main handler.  Calls &assessparms and &crsenv subroutines.
 1802: 
 1803: =cut
 1804: 
 1805: ##################################################
 1806: ##################################################
 1807:     use Data::Dumper;
 1808: sub handler {
 1809:     my $r=shift;
 1810: 
 1811:     if ($r->header_only) {
 1812: 	$r->content_type('text/html');
 1813: 	$r->send_http_header;
 1814: 	return OK;
 1815:     }
 1816:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
 1817: 
 1818: # ----------------------------------------------------- Needs to be in a course
 1819: 
 1820:     if (($ENV{'request.course.id'}) && 
 1821: 	(&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
 1822: 
 1823:         $r->content_type('text/html');
 1824:         $r->send_http_header;
 1825:  
 1826:         $coursename=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
 1827: 
 1828: 	if (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) {
 1829: # ---------------------------------------------- This is for course environment
 1830: # -------------------------- also call if toplevel map coudl not be initialized
 1831: 	    &crsenv($r);
 1832: 	} elsif ($ENV{'form.overview'}) {
 1833: # --------------------------------------------------------------- Overview mode
 1834: 	    &overview($r);
 1835: 	} else {
 1836: # --------------------------------------------------------- Bring up assessment
 1837: 	    &assessparms($r);
 1838: 	}
 1839:     } else {
 1840: # ----------------------------- Not in a course, or not allowed to modify parms
 1841: 	$ENV{'user.error.msg'}=
 1842: 	    "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
 1843: 	return HTTP_NOT_ACCEPTABLE;
 1844:     }
 1845:     return OK;
 1846: }
 1847: 
 1848: 1;
 1849: __END__
 1850: 
 1851: =pod
 1852: 
 1853: =back
 1854: 
 1855: =cut
 1856: 
 1857: 
 1858: 

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