File:  [LON-CAPA] / loncom / interface / lonparmset.pm
Revision 1.87: download - view: text, annotated - select for diffs
Fri Apr 18 15:24:53 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
This was emitting double http-headers.

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

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