File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.66: download - view: text, annotated - select for diffs
Sat Sep 7 17:30:31 2002 UTC (21 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
Toward bug 729. Also prints intervals now in &valout

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

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