Annotation of loncom/interface/lonparmset.pm, revision 1.223

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Handler to set parameters for assessments
                      3: #
1.223   ! albertel    4: # $Id: lonparmset.pm,v 1.222 2005/06/14 15:43:54 www Exp $
1.40      albertel    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: #
1.59      matthew    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: ###################################################################
1.1       www        53: 
                     54: package Apache::lonparmset;
                     55: 
                     56: use strict;
                     57: use Apache::lonnet;
                     58: use Apache::Constants qw(:common :http REDIRECT);
1.88      matthew    59: use Apache::lonhtmlcommon();
1.36      albertel   60: use Apache::loncommon;
1.1       www        61: use GDBM_File;
1.57      albertel   62: use Apache::lonhomework;
                     63: use Apache::lonxml;
1.130     www        64: use Apache::lonlocal;
1.197     www        65: use Apache::lonnavmaps;
1.1       www        66: 
1.198     www        67: # --- Caches local to lonparmset
1.2       www        68: 
1.199     www        69: my $parmhashid;
                     70: my %parmhash;
1.201     www        71: my $symbsid;
                     72: my %symbs;
1.221     www        73: my $rulesid;
                     74: my %rules;
1.198     www        75: 
                     76: # --- end local caches
                     77: 
1.59      matthew    78: ##################################################
                     79: ##################################################
                     80: 
                     81: =pod
                     82: 
                     83: =item parmval
                     84: 
                     85: Figure out a cascading parameter.
                     86: 
1.71      albertel   87: Inputs:  $what - a parameter spec (incluse part info and name I.E. 0.weight)
1.162     albertel   88:          $id   - a bighash Id number
1.71      albertel   89:          $def  - the resource's default value   'stupid emacs
                     90: 
                     91: Returns:  A list, the first item is the index into the remaining list of items of parm valuse that is the active one, the list consists of parm values at the 11 possible levels
                     92: 
1.182     albertel   93: 11 - General Course
                     94: 10 - Map or Folder level in course
                     95: 9- resource default
                     96: 8- map default
1.71      albertel   97: 7 - resource level in course
                     98: 6 - General for section
1.82      www        99: 5 - Map or Folder level for section
1.71      albertel  100: 4 - resource level in section
                    101: 3 - General for specific student
1.82      www       102: 2 - Map or Folder level for specific student
1.71      albertel  103: 1 - resource level for specific student
1.2       www       104: 
1.59      matthew   105: =cut
                    106: 
                    107: ##################################################
1.2       www       108: sub parmval {
1.187     www       109:     my ($what,$id,$def,$uname,$udom,$csec)=@_;
1.201     www       110:     return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec);
                    111: }
                    112: 
                    113: sub parmval_by_symb {
                    114:     my ($what,$symb,$def,$uname,$udom,$csec)=@_;
1.198     www       115: # load caches
1.200     www       116: 
1.198     www       117:     &cacheparmhash();
1.200     www       118: 
                    119:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    120:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    121:     my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
                    122:     my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
                    123: 
1.198     www       124: 
1.8       www       125:     my $result='';
1.44      albertel  126:     my @outpar=();
1.2       www       127: # ----------------------------------------------------- Cascading lookup scheme
1.201     www       128:     my $map=(&Apache::lonnet::decode_symb($symb))[0];    
1.10      www       129: 
1.201     www       130:     my $symbparm=$symb.'.'.$what;
                    131:     my $mapparm=$map.'___(all).'.$what;
1.10      www       132: 
1.190     albertel  133:     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
                    134:     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
                    135:     my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
                    136: 
                    137:     my $courselevel=$env{'request.course.id'}.'.'.$what;
                    138:     my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
                    139:     my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
1.2       www       140: 
1.11      www       141: 
                    142: 
1.182     albertel  143: # --------------------------------------------------------- first, check course
1.11      www       144: 
1.200     www       145:     if (defined($$courseopt{$courselevel})) {
                    146: 	$outpar[11]=$$courseopt{$courselevel};
1.182     albertel  147: 	$result=11;
1.43      albertel  148:     }
1.11      www       149: 
1.200     www       150:     if (defined($$courseopt{$courselevelm})) {
                    151: 	$outpar[10]=$$courseopt{$courselevelm};
1.182     albertel  152: 	$result=10;
1.43      albertel  153:     }
1.11      www       154: 
1.182     albertel  155: # ------------------------------------------------------- second, check default
                    156: 
                    157:     if (defined($def)) { $outpar[9]=$def; $result=9; }
                    158: 
                    159: # ------------------------------------------------------ third, check map parms
                    160: 
                    161:     my $thisparm=$parmhash{$symbparm};
                    162:     if (defined($thisparm)) { $outpar[8]=$thisparm; $result=8; }
                    163: 
1.200     www       164:     if (defined($$courseopt{$courselevelr})) {
                    165: 	$outpar[7]=$$courseopt{$courselevelr};
1.43      albertel  166: 	$result=7;
                    167:     }
1.11      www       168: 
1.182     albertel  169: # ------------------------------------------------------ fourth, back to course
1.71      albertel  170:     if (defined($csec)) {
1.200     www       171:         if (defined($$courseopt{$seclevel})) {
                    172: 	    $outpar[6]=$$courseopt{$seclevel};
1.43      albertel  173: 	    $result=6;
                    174: 	}
1.200     www       175:         if (defined($$courseopt{$seclevelm})) {
                    176: 	    $outpar[5]=$$courseopt{$seclevelm};
1.43      albertel  177: 	    $result=5;
                    178: 	}
                    179: 
1.200     www       180:         if (defined($$courseopt{$seclevelr})) {
1.201     www       181: 	    $outpar[4]=$$courseopt{$seclevelr};
1.43      albertel  182: 	    $result=4;
                    183: 	}
                    184:     }
1.11      www       185: 
1.182     albertel  186: # ---------------------------------------------------------- fifth, check user
1.11      www       187: 
1.71      albertel  188:     if (defined($uname)) {
1.200     www       189: 	if (defined($$useropt{$courselevel})) {
                    190: 	    $outpar[3]=$$useropt{$courselevel};
1.43      albertel  191: 	    $result=3;
                    192: 	}
1.10      www       193: 
1.200     www       194: 	if (defined($$useropt{$courselevelm})) {
                    195: 	    $outpar[2]=$$useropt{$courselevelm};
1.43      albertel  196: 	    $result=2;
                    197: 	}
1.2       www       198: 
1.200     www       199: 	if (defined($$useropt{$courselevelr})) {
                    200: 	    $outpar[1]=$$useropt{$courselevelr};
1.43      albertel  201: 	    $result=1;
                    202: 	}
                    203:     }
1.44      albertel  204:     return ($result,@outpar);
1.2       www       205: }
                    206: 
1.198     www       207: sub resetparmhash {
                    208:     $parmhashid='';
                    209: }
                    210: 
                    211: sub cacheparmhash {
                    212:     if ($parmhashid eq  $env{'request.course.fn'}) { return; }
                    213:     my %parmhashfile;
                    214:     if (tie(%parmhashfile,'GDBM_File',
                    215: 	      $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
                    216: 	%parmhash=%parmhashfile;
                    217: 	untie %parmhashfile;
                    218: 	$parmhashid=$env{'request.course.fn'};
                    219:     }
                    220: }
                    221: 
1.203     www       222: sub resetsymbcache {
                    223:     $symbsid='';
                    224: }
                    225: 
1.201     www       226: sub symbcache {
                    227:     my $id=shift;
                    228:     if ($symbsid ne $env{'request.course.id'}) {
                    229: 	%symbs=();
                    230:     }
                    231:     unless ($symbs{$id}) {
                    232: 	my $navmap = Apache::lonnavmaps::navmap->new();
                    233: 	if ($id=~/\./) {
                    234: 	    my $resource=$navmap->getById($id);
                    235: 	    $symbs{$id}=$resource->symb();
                    236: 	} else {
                    237: 	    my $resource=$navmap->getByMapPc($id);
                    238: 	    $symbs{$id}=&Apache::lonnet::declutter($resource->src());
                    239: 	}
                    240: 	$symbsid=$env{'request.course.id'};
                    241:     }
                    242:     return $symbs{$id};
                    243: }
                    244: 
1.221     www       245: sub resetrulescache {
                    246:     $rulesid='';
                    247: }
                    248: 
                    249: sub rulescache {
                    250:     my $id=shift;
                    251:     if ($rulesid ne $env{'request.course.id'}) {
                    252: 	%rules=();
                    253:     }
                    254:     unless ($rules{$id}) {
                    255: 	my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    256: 	my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
                    257: 	my %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
                    258: 	$rulesid=$env{'request.course.id'};
                    259:     }
                    260:     return $rules{$id};
                    261: }
                    262: 
1.186     www       263: ##################################################
                    264: ##################################################
                    265: #
1.197     www       266: # Store a parameter by ID
1.186     www       267: #
                    268: # Takes
                    269: # - resource id
                    270: # - name of parameter
                    271: # - level
                    272: # - new value
                    273: # - new type
1.187     www       274: # - username
                    275: # - userdomain
                    276: 
1.186     www       277: sub storeparm {
1.187     www       278:     my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
1.201     www       279:     &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
1.197     www       280: }
                    281: 
                    282: #
                    283: # Store a parameter by symb
                    284: #
                    285: # Takes
                    286: # - symb
                    287: # - name of parameter
                    288: # - level
                    289: # - new value
                    290: # - new type
                    291: # - username
                    292: # - userdomain
                    293: 
                    294: sub storeparm_by_symb {
                    295: # ---------------------------------------------------------- Get symb, map, etc
                    296:     my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
                    297: # ---------------------------------------------------------- Construct prefixes
1.186     www       298:     $spnam=~s/\_([^\_]+)$/\.$1/;
1.197     www       299:     my $map=(&Apache::lonnet::decode_symb($symb))[0];    
                    300:     my $symbparm=$symb.'.'.$spnam;
                    301:     my $mapparm=$map.'___(all).'.$spnam;
                    302: 
1.190     albertel  303:     my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
                    304:     my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
                    305:     my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
1.186     www       306:     
1.190     albertel  307:     my $courselevel=$env{'request.course.id'}.'.'.$spnam;
                    308:     my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
                    309:     my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
1.186     www       310:     
                    311:     my $storeunder='';
                    312:     if (($snum==11) || ($snum==3)) { $storeunder=$courselevel; }
                    313:     if (($snum==10) || ($snum==2)) { $storeunder=$courselevelm; }
                    314:     if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
                    315:     if ($snum==6) { $storeunder=$seclevel; }
                    316:     if ($snum==5) { $storeunder=$seclevelm; }
                    317:     if ($snum==4) { $storeunder=$seclevelr; }
                    318:     
                    319:     my $delete;
                    320:     if ($nval eq '') { $delete=1;}
                    321:     my %storecontent = ($storeunder         => $nval,
                    322: 			$storeunder.'.type' => $ntype);
                    323:     my $reply='';
                    324:     if ($snum>3) {
                    325: # ---------------------------------------------------------------- Store Course
                    326: #
1.200     www       327: 	my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    328: 	my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.186     www       329: # Expire sheets
                    330: 	&Apache::lonnet::expirespread('','','studentcalc');
                    331: 	if (($snum==7) || ($snum==4)) {
1.197     www       332: 	    &Apache::lonnet::expirespread('','','assesscalc',$symb);
1.186     www       333: 	} elsif (($snum==8) || ($snum==5)) {
1.197     www       334: 	    &Apache::lonnet::expirespread('','','assesscalc',$map);
1.186     www       335: 	} else {
                    336: 	    &Apache::lonnet::expirespread('','','assesscalc');
                    337: 	}
                    338: # Store parameter
                    339: 	if ($delete) {
                    340: 	    $reply=&Apache::lonnet::del
1.200     www       341: 		('resourcedata',[keys(%storecontent)],$cdom,$cnum);
1.186     www       342: 	} else {
                    343: 	    $reply=&Apache::lonnet::cput
1.200     www       344: 		('resourcedata',\%storecontent,$cdom,$cnum);
1.186     www       345: 	}
1.200     www       346: 	&Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
1.186     www       347:     } else {
                    348: # ------------------------------------------------------------------ Store User
                    349: #
                    350: # Expire sheets
                    351: 	&Apache::lonnet::expirespread($uname,$udom,'studentcalc');
                    352: 	if ($snum==1) {
                    353: 	    &Apache::lonnet::expirespread
1.197     www       354: 		($uname,$udom,'assesscalc',$symb);
1.186     www       355: 	} elsif ($snum==2) {
                    356: 	    &Apache::lonnet::expirespread
1.197     www       357: 		($uname,$udom,'assesscalc',$map);
1.186     www       358: 	} else {
                    359: 	    &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
                    360: 	}
                    361: # Store parameter
                    362: 	if ($delete) {
                    363: 	    $reply=&Apache::lonnet::del
                    364: 		('resourcedata',[keys(%storecontent)],$udom,$uname);
                    365: 	} else {
                    366: 	    $reply=&Apache::lonnet::cput
                    367: 		('resourcedata',\%storecontent,$udom,$uname);
                    368: 	}
1.191     albertel  369: 	&Apache::lonnet::devalidateuserresdata($uname,$udom);
1.186     www       370:     }
                    371:     
                    372:     if ($reply=~/^error\:(.*)/) {
                    373: 	return "<font color=red>Write Error: $1</font>";
                    374:     }
                    375:     return '';
                    376: }
                    377: 
1.59      matthew   378: ##################################################
                    379: ##################################################
                    380: 
                    381: =pod
                    382: 
                    383: =item valout
                    384: 
                    385: Format a value for output.
                    386: 
                    387: Inputs:  $value, $type
                    388: 
                    389: Returns: $value, formatted for output.  If $type indicates it is a date,
                    390: localtime($value) is returned.
1.9       www       391: 
1.59      matthew   392: =cut
                    393: 
                    394: ##################################################
                    395: ##################################################
1.9       www       396: sub valout {
                    397:     my ($value,$type)=@_;
1.59      matthew   398:     my $result = '';
                    399:     # Values of zero are valid.
                    400:     if (! $value && $value ne '0') {
1.71      albertel  401: 	$result = '&nbsp;&nbsp;';
1.59      matthew   402:     } else {
1.66      www       403:         if ($type eq 'date_interval') {
                    404:             my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
                    405:             $year=$year-70;
                    406:             $mday--;
                    407:             if ($year) {
                    408: 		$result.=$year.' yrs ';
                    409:             }
                    410:             if ($mon) {
                    411: 		$result.=$mon.' mths ';
                    412:             }
                    413:             if ($mday) {
                    414: 		$result.=$mday.' days ';
                    415:             }
                    416:             if ($hour) {
                    417: 		$result.=$hour.' hrs ';
                    418:             }
                    419:             if ($min) {
                    420: 		$result.=$min.' mins ';
                    421:             }
                    422:             if ($sec) {
                    423: 		$result.=$sec.' secs ';
                    424:             }
                    425:             $result=~s/\s+$//;
1.213     www       426:         } elsif (&isdateparm($type)) {
1.59      matthew   427:             $result = localtime($value);
                    428:         } else {
                    429:             $result = $value;
                    430:         }
                    431:     }
                    432:     return $result;
1.9       www       433: }
                    434: 
1.59      matthew   435: ##################################################
                    436: ##################################################
                    437: 
                    438: =pod
1.5       www       439: 
1.59      matthew   440: =item plink
                    441: 
                    442: Produces a link anchor.
                    443: 
                    444: Inputs: $type,$dis,$value,$marker,$return,$call
                    445: 
                    446: Returns: scalar with html code for a link which will envoke the 
                    447: javascript function 'pjump'.
                    448: 
                    449: =cut
                    450: 
                    451: ##################################################
                    452: ##################################################
1.5       www       453: sub plink {
                    454:     my ($type,$dis,$value,$marker,$return,$call)=@_;
1.23      www       455:     my $winvalue=$value;
                    456:     unless ($winvalue) {
1.213     www       457: 	if (&isdateparm($type)) {
1.190     albertel  458:             $winvalue=$env{'form.recent_'.$type};
1.23      www       459:         } else {
1.190     albertel  460:             $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
1.23      www       461:         }
                    462:     }
1.209     www       463: 
                    464: 
1.23      www       465:     return 
1.43      albertel  466: 	'<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
                    467: 	    .$marker."','".$return."','".$call."'".');">'.
                    468: 		&valout($value,$type).'</a><a name="'.$marker.'"></a>';
1.5       www       469: }
                    470: 
1.44      albertel  471: sub startpage {
1.209     www       472:     my $r=shift;
1.99      albertel  473: 
1.120     www       474:     my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','',
1.98      www       475:                                             'onUnload="pclose()"');
1.204     www       476:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Table Mode Parameter Setting');
1.81      www       477:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
1.88      matthew   478:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.183     albertel  479:     my $html=&Apache::lonxml::xmlbegin();
1.44      albertel  480:     $r->print(<<ENDHEAD);
1.183     albertel  481: $html
1.44      albertel  482: <head>
                    483: <title>LON-CAPA Course Parameters</title>
                    484: <script>
                    485: 
                    486:     function pclose() {
                    487:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                    488:                  "height=350,width=350,scrollbars=no,menubar=no");
                    489:         parmwin.close();
                    490:     }
                    491: 
1.88      matthew   492:     $pjump_def
1.44      albertel  493: 
                    494:     function psub() {
                    495:         pclose();
                    496:         if (document.parmform.pres_marker.value!='') {
                    497:             document.parmform.action+='#'+document.parmform.pres_marker.value;
                    498:             var typedef=new Array();
                    499:             typedef=document.parmform.pres_type.value.split('_');
                    500:            if (document.parmform.pres_type.value!='') {
                    501:             if (typedef[0]=='date') {
                    502:                 eval('document.parmform.recent_'+
                    503:                      document.parmform.pres_type.value+
                    504: 		     '.value=document.parmform.pres_value.value;');
                    505:             } else {
                    506:                 eval('document.parmform.recent_'+typedef[0]+
                    507: 		     '.value=document.parmform.pres_value.value;');
                    508:             }
                    509: 	   }
                    510:             document.parmform.submit();
                    511:         } else {
                    512:             document.parmform.pres_value.value='';
                    513:             document.parmform.pres_marker.value='';
                    514:         }
                    515:     }
                    516: 
1.57      albertel  517:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                    518:         var options = "width=" + w + ",height=" + h + ",";
                    519:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                    520:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                    521:         var newWin = window.open(url, wdwName, options);
                    522:         newWin.focus();
                    523:     }
1.44      albertel  524: </script>
1.81      www       525: $selscript
1.44      albertel  526: </head>
1.64      www       527: $bodytag
1.193     albertel  528: $breadcrumbs
                    529: <form method="post" action="/adm/parmset?action=settable" name="parmform">
1.44      albertel  530: <input type="hidden" value='' name="pres_value">
                    531: <input type="hidden" value='' name="pres_type">
                    532: <input type="hidden" value='' name="pres_marker">
1.209     www       533: <input type="hidden" value='1' name="prevvisit">
1.44      albertel  534: ENDHEAD
                    535: }
                    536: 
1.209     www       537: 
1.44      albertel  538: sub print_row {
1.201     www       539:     my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
1.187     www       540: 	$defbgtwo,$parmlev,$uname,$udom,$csec)=@_;
1.66      www       541: # get the values for the parameter in cascading order
                    542: # empty levels will remain empty
1.44      albertel  543:     my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
1.187     www       544: 				  $rid,$$default{$which},$uname,$udom,$csec);
1.66      www       545: # get the type for the parameters
                    546: # problem: these may not be set for all levels
                    547:     my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
                    548:                                           $$name{$which}.'.type',
1.187     www       549: 				  $rid,$$defaulttype{$which},$uname,$udom,$csec);
1.66      www       550: # cascade down manually
1.182     albertel  551:     my $cascadetype=$$defaulttype{$which};
                    552:     for (my $i=11;$i>0;$i--) {
1.66      www       553: 	 if ($typeoutpar[$i]) { 
                    554:             $cascadetype=$typeoutpar[$i];
                    555: 	} else {
                    556:             $typeoutpar[$i]=$cascadetype;
                    557:         }
                    558:     }
1.57      albertel  559:     my $parm=$$display{$which};
                    560: 
1.203     www       561:     if ($parmlev eq 'full') {
1.57      albertel  562:         $r->print('<td bgcolor='.$defbgtwo.' align="center">'
                    563:                   .$$part{$which}.'</td>');
                    564:     } else {    
                    565:         $parm=~s|\[.*\]\s||g;
                    566:     }
                    567: 
1.159     albertel  568:     $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
1.57      albertel  569:    
1.44      albertel  570:     my $thismarker=$which;
                    571:     $thismarker=~s/^parameter\_//;
                    572:     my $mprefix=$rid.'&'.$thismarker.'&';
                    573: 
1.57      albertel  574:     if ($parmlev eq 'general') {
                    575: 
                    576:         if ($uname) {
1.66      www       577:             &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57      albertel  578:         } elsif ($csec) {
1.66      www       579:             &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); 
1.57      albertel  580:         } else {
1.182     albertel  581:             &print_td($r,11,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); 
1.57      albertel  582:         }
                    583:     } elsif ($parmlev eq 'map') {
                    584: 
                    585:         if ($uname) {
1.66      www       586:             &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57      albertel  587:         } elsif ($csec) {
1.66      www       588:             &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57      albertel  589:         } else {
1.182     albertel  590:             &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57      albertel  591:         }
                    592:     } else {
                    593: 
1.182     albertel  594:         &print_td($r,11,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57      albertel  595: 
1.203     www       596: 	&print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    597: 	&print_td($r,9,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    598: 	&print_td($r,8,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    599: 	&print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    600: 	
                    601: 	if ($csec) {
                    602: 	    &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    603: 	    &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    604: 	    &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    605: 	}
                    606: 	if ($uname) {
                    607: 	    &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    608: 	    &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    609: 	    &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
                    610: 	}
1.57      albertel  611: 
                    612:     } # end of $parmlev if/else
                    613: 
1.136     albertel  614:     $r->print('<td bgcolor=#CCCCFF align="center">'.
                    615:                   &valout($outpar[$result],$typeoutpar[$result]).'</td>');
                    616: 
1.203     www       617:     if ($parmlev eq 'full') {
1.136     albertel  618:         my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
1.201     www       619:                                         '.'.$$name{$which},$$symbp{$rid});
1.136     albertel  620:         my $sessionvaltype=$typeoutpar[$result];
                    621:         if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
                    622:         $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
1.66      www       623:                   &valout($sessionval,$sessionvaltype).'&nbsp;'.
1.57      albertel  624:                   '</font></td>');
1.136     albertel  625:     }
1.44      albertel  626:     $r->print('</tr>');
1.57      albertel  627:     $r->print("\n");
1.44      albertel  628: }
1.59      matthew   629: 
1.44      albertel  630: sub print_td {
1.66      www       631:     my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
1.57      albertel  632:     $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
1.114     www       633:               ' align="center">');
1.182     albertel  634:     if ($which<8 || $which > 9) {
1.114     www       635: 	$r->print(&plink($$typeoutpar[$which],
                    636: 			 $$display{$value},$$outpar[$which],
                    637: 			 $mprefix."$which",'parmform.pres','psub'));
                    638:     } else {
                    639: 	$r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
                    640:     }
                    641:     $r->print('</td>'."\n");
1.57      albertel  642: }
                    643: 
1.201     www       644: 
1.63      bowersj2  645: =pod
                    646: 
                    647: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
                    648: 
                    649: Input: See list below:
                    650: 
                    651: =over 4
                    652: 
                    653: =item B<ids>: An array that will contain all of the ids in the course.
                    654: 
                    655: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
                    656: 
1.171     www       657: =item B<keyp>: hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
1.63      bowersj2  658: 
                    659: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
                    660: 
                    661: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
                    662: 
                    663: =item B<allkeys>: hash, full key to part->display value (what's display value?)
                    664: 
                    665: =item B<allmaps>: hash, ???
                    666: 
                    667: =item B<fcat>: ???
                    668: 
                    669: =item B<defp>: hash, ???
                    670: 
                    671: =item B<mapp>: ??
                    672: 
                    673: =item B<symbp>: hash, id->full sym?
                    674: 
                    675: =back
                    676: 
                    677: =cut
                    678: 
                    679: sub extractResourceInformation {
                    680:     my $ids = shift;
                    681:     my $typep = shift;
                    682:     my $keyp = shift;
                    683:     my $allparms = shift;
                    684:     my $allparts = shift;
                    685:     my $allmaps = shift;
                    686:     my $mapp = shift;
                    687:     my $symbp = shift;
1.82      www       688:     my $maptitles=shift;
1.196     www       689:     my $uris=shift;
1.210     www       690:     my $keyorder=shift;
1.211     www       691:     my $defkeytype=shift;
1.196     www       692: 
1.210     www       693:     my $keyordercnt=100;
1.63      bowersj2  694: 
1.196     www       695:     my $navmap = Apache::lonnavmaps::navmap->new();
                    696:     my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
                    697:     foreach my $resource (@allres) {
                    698: 	my $id=$resource->id();
                    699:         my ($mapid,$resid)=split(/\./,$id);
                    700: 	if ($mapid eq '0') { next; }
                    701: 	$$ids[$#$ids+1]=$id;
                    702: 	my $srcf=$resource->src();
                    703: 	$srcf=~/\.(\w+)$/;
                    704: 	$$typep{$id}=$1;
                    705: 	$$keyp{$id}='';
                    706:         $$uris{$id}=$srcf;
                    707: 	foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
                    708: 	    if ($_=~/^parameter\_(.*)/) {
                    709: 		my $key=$_;
1.209     www       710: # Hidden parameters
                    711: 		if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm') {
                    712: 		    next;
1.63      bowersj2  713: 		}
1.196     www       714: 		my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
                    715: 		my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
                    716: 		my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
1.209     www       717: #
                    718: # allparms is a hash of parameter names
                    719: #
1.196     www       720: 		my $parmdis = $display;
1.209     www       721: 		$parmdis =~ s/\[Part.*$//g;
                    722:                 $$allparms{$name}=$parmdis;
1.211     www       723: 		$$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type');
1.209     www       724: #
                    725: # allparts is a hash of all parts
                    726: #
                    727: 		$$allparts{$part} = "Part: $part";
                    728: #
                    729: # Remember all keys going with this resource
                    730: #
1.196     www       731: 		if ($$keyp{$id}) {
                    732: 		    $$keyp{$id}.=','.$key;
1.175     albertel  733: 		} else {
1.196     www       734: 		    $$keyp{$id}=$key;
1.175     albertel  735: 		}
1.210     www       736: #
                    737: # Put in order
                    738: # 
                    739:                 unless ($$keyorder{$key}) {
                    740:                     $$keyorder{$key}=$keyordercnt;
                    741:                     $keyordercnt++;
                    742: 		}
                    743: 
1.63      bowersj2  744: 	    }
                    745: 	}
1.196     www       746: 	$$mapp{$id}=
                    747: 	    &Apache::lonnet::declutter($resource->enclosing_map_src());
                    748: 	$$mapp{$mapid}=$$mapp{$id};
                    749: 	$$allmaps{$mapid}=$$mapp{$id};
                    750: 	if ($mapid eq '1') {
                    751: 	    $$maptitles{$mapid}='Main Course Documents';
                    752: 	} else {
                    753: 	    $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));
                    754: 	}
                    755: 	$$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
                    756: 	$$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
                    757: 	$$symbp{$mapid}=$$mapp{$id}.'___(all)';
1.63      bowersj2  758:     }
                    759: }
                    760: 
1.208     www       761: 
                    762: ##################################################
                    763: ##################################################
                    764: 
1.213     www       765: sub isdateparm {
                    766:     my $type=shift;
                    767:     return (($type=~/^date/) && (!($type eq 'date_interval')));
                    768: }
                    769: 
1.208     www       770: sub parmmenu {
1.211     www       771:     my ($r,$allparms,$pscat,$keyorder)=@_;
1.208     www       772:     my $tempkey;
                    773:     $r->print(<<ENDSCRIPT);
                    774: <script type="text/javascript">
                    775:     function checkall(value, checkName) {
                    776: 	for (i=0; i<document.forms.parmform.elements.length; i++) {
                    777:             ele = document.forms.parmform.elements[i];
                    778:             if (ele.name == checkName) {
                    779:                 document.forms.parmform.elements[i].checked=value;
                    780:             }
                    781:         }
                    782:     }
1.210     www       783: 
                    784:     function checkthis(thisvalue, checkName) {
                    785: 	for (i=0; i<document.forms.parmform.elements.length; i++) {
                    786:             ele = document.forms.parmform.elements[i];
                    787:             if (ele.name == checkName) {
                    788: 		if (ele.value == thisvalue) {
                    789: 		    document.forms.parmform.elements[i].checked=true;
                    790: 		}
                    791:             }
                    792:         }
                    793:     }
                    794: 
                    795:     function checkdates() {
                    796: 	checkthis('duedate','pscat');
                    797:  	checkthis('opendate','pscat');
                    798: 	checkthis('answerdate','pscat');
1.218     www       799:     }
                    800: 
                    801:     function checkdisset() {
                    802: 	checkthis('discussend','pscat');
                    803:  	checkthis('discusshide','pscat');
                    804:     }
                    805: 
                    806:     function checkcontdates() {
                    807: 	checkthis('contentopen','pscat');
                    808:  	checkthis('contentclose','pscat');
                    809:     }
                    810:  
1.210     www       811: 
                    812:     function checkvisi() {
                    813: 	checkthis('hiddenresource','pscat');
                    814:  	checkthis('encrypturl','pscat');
                    815: 	checkthis('problemstatus','pscat');
                    816: 	checkthis('contentopen','pscat');
                    817: 	checkthis('opendate','pscat');
                    818:     }
                    819: 
                    820:     function checkparts() {
                    821: 	checkthis('hiddenparts','pscat');
                    822: 	checkthis('display','pscat');
                    823: 	checkthis('ordered','pscat');
                    824:     }
                    825: 
                    826:     function checkstandard() {
                    827:         checkall(false,'pscat');
                    828: 	checkdates();
                    829: 	checkthis('weight','pscat');
                    830: 	checkthis('maxtries','pscat');
                    831:     }
                    832: 
1.208     www       833: </script>
                    834: ENDSCRIPT
1.209     www       835:     $r->print();
1.208     www       836:     $r->print("\n<table><tr>");
                    837:     my $cnt=0;
1.211     www       838:     foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) {
1.209     www       839: 	$r->print("\n<td><font size='-1'><input type='checkbox' name='pscat' ");
1.208     www       840: 	$r->print('value="'.$tempkey.'"');
                    841: 	if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
                    842: 	    $r->print(' checked');
                    843: 	}
1.209     www       844: 	$r->print('>'.$$allparms{$tempkey}.'</font></td>');
                    845:  	$cnt++;
                    846:         if ($cnt==3) {
                    847: 	    $r->print("</tr>\n<tr>");
                    848: 	    $cnt=0;
                    849: 	}
1.208     www       850:     }
                    851:     $r->print('
                    852: </tr><tr><td>
1.218     www       853: <a href="javascript:checkall(true, \'pscat\')">Select All</a><br />
                    854: <a href="javascript:checkstandard()">Select Common Only</a>
1.210     www       855: </td><td>
1.218     www       856: <a href="javascript:checkdates()">Add Problem Dates</a>
                    857: <a href="javascript:checkcontdates()">Add Content Dates</a><br />
                    858: <a href="javascript:checkdisset()">Add Discussion Settings</a>
                    859: <a href="javascript:checkvisi()">Add Visibilities</a><br />
                    860: <a href="javascript:checkparts()">Add Part Parameters</a>
1.210     www       861: </td><td>
                    862: <a href="javascript:checkall(false, \'pscat\')">Unselect All</a>
1.208     www       863: </td>
                    864: ');
                    865:     $r->print('</tr></table>');
                    866: }
                    867: 
1.209     www       868: sub partmenu {
                    869:     my ($r,$allparts,$psprt)=@_;
1.211     www       870:     $r->print('<select multiple name="psprt" size="8">');
1.208     www       871:     $r->print('<option value="all"');
                    872:     $r->print(' selected') unless (@{$psprt});
                    873:     $r->print('>'.&mt('All Parts').'</option>');
                    874:     my %temphash=();
                    875:     foreach (@{$psprt}) { $temphash{$_}=1; }
1.209     www       876:     foreach my $tempkey (sort keys %{$allparts}) {
1.208     www       877: 	unless ($tempkey =~ /\./) {
                    878: 	    $r->print('<option value="'.$tempkey.'"');
                    879: 	    if ($$psprt[0] eq "all" ||  $temphash{$tempkey}) {
                    880: 		$r->print(' selected');
                    881: 	    }
                    882: 	    $r->print('>'.$$allparts{$tempkey}.'</option>');
                    883: 	}
                    884:     }
1.209     www       885:     $r->print('</select>');
                    886: }
                    887: 
                    888: sub usermenu {
                    889:     my ($r,$uname,$id,$udom,$csec)=@_;
                    890:     my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
                    891:         &Apache::loncommon::selectstudent_link('parmform','uname','udom');
                    892:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
                    893:     my %lt=&Apache::lonlocal::texthash(
                    894: 		    'sg'    => "Section/Group",
                    895: 		    'fu'    => "For User",
                    896: 		    'oi'    => "or ID",
                    897: 		    'ad'    => "at Domain"
                    898: 				       );
                    899:     my %sectionhash=();
                    900:     my $sections='';
                    901:     if (&Apache::loncommon::get_sections(
                    902:                  $env{'course.'.$env{'request.course.id'}.'.domain'},
                    903:                  $env{'course.'.$env{'request.course.id'}.'.num'},
                    904: 					 \%sectionhash)) {
                    905:         $sections=$lt{'sg'}.': <select name="csec">';
                    906: 	foreach ('',sort keys %sectionhash) {
                    907: 	    $sections.='<option value="'.$_.'"'.
                    908: 		($_ eq $csec?'selected="selected"':'').'>'.$_.'</option>';
                    909:         }
                    910:         $sections.='</select>';
                    911:      }
                    912:      $r->print(<<ENDMENU);
                    913: <b>
                    914: $sections
                    915: <br />
                    916: $lt{'fu'} 
                    917: <input type="text" value="$uname" size="12" name="uname" />
                    918: $lt{'oi'}
                    919: <input type="text" value="$id" size="12" name="id" /> 
                    920: $lt{'ad'}
                    921: $chooseopt
                    922: </b>
                    923: ENDMENU
                    924: }
                    925: 
                    926: sub displaymenu {
1.211     www       927:     my ($r,$allparms,$allparts,$pscat,$psprt,$keyorder)=@_;
1.209     www       928:     $r->print('<table border="1"><tr><th>'.&mt('Select Parameters to View').'</th><th>'.
                    929: 	     &mt('Select Parts to View').'</th></tr><tr><td>');  
1.211     www       930:     &parmmenu($r,$allparms,$pscat,$keyorder);
1.209     www       931:     $r->print('</td><td>');
                    932:     &partmenu($r,$allparts,$psprt);
                    933:     $r->print('</td></tr></table>');
                    934: }
                    935: 
                    936: sub mapmenu {
                    937:     my ($r,$allmaps,$pschp,$maptitles)=@_;
                    938:     $r->print(&mt('Select Enclosing Map or Folder').' ');
                    939:     $r->print('<select name="pschp">');
                    940:     $r->print('<option value="all">'.&mt('All Maps or Folders').'</option>');
                    941:     foreach (sort {$$allmaps{$a} cmp $$allmaps{$b}} keys %{$allmaps}) {
1.208     www       942: 	$r->print('<option value="'.$_.'"');
1.209     www       943: 	if (($pschp eq $_)) { $r->print(' selected'); }
                    944: 	$r->print('>'.$$maptitles{$_}.($$allmaps{$_}!~/^uploaded/?' ['.$$allmaps{$_}.']':'').'</option>');
                    945:     }
                    946:     $r->print("</select>");
                    947: }
                    948: 
                    949: sub levelmenu {
                    950:     my ($r,$alllevs,$parmlev)=@_;
                    951:     $r->print(&mt('Select Parameter Level').
                    952: 	      &Apache::loncommon::help_open_topic('Course_Parameter_Levels').' ');
                    953:     $r->print('<select name="parmlev">');
                    954:     foreach (reverse sort keys %{$alllevs}) {
                    955: 	$r->print('<option value="'.$$alllevs{$_}.'"');
                    956: 	if ($parmlev eq $$alllevs{$_}) {
                    957: 	    $r->print(' selected'); 
                    958: 	}
                    959: 	$r->print('>'.$_.'</option>');
1.208     www       960:     }
1.209     www       961:     $r->print("</select>");
1.208     www       962: }
                    963: 
1.211     www       964: 
                    965: sub sectionmenu {
                    966:     my ($r,$selectedsections)=@_;
1.212     www       967:     my %sectionhash=();
1.211     www       968: 
1.212     www       969:     if (&Apache::loncommon::get_sections(
                    970:                  $env{'course.'.$env{'request.course.id'}.'.domain'},
                    971:                  $env{'course.'.$env{'request.course.id'}.'.num'},
                    972: 					 \%sectionhash)) {
                    973: 	$r->print('<select name="Section" multiple="true" size="8" >');
                    974: 	foreach my $s ('all',sort keys %sectionhash) {
                    975: 	    $r->print('    <option value="'.$s.'"');
                    976: 	    foreach (@{$selectedsections}) {
                    977: 		if ($s eq $_) {
                    978: 		    $r->print(' selected');
                    979: 		    last;
                    980: 		}
                    981: 	    }
                    982: 	    $r->print('>'.$s."</option>\n");
                    983: 	}
                    984: 	$r->print("</select>\n");
1.211     www       985:     }
                    986: }
                    987: 
1.210     www       988: sub keysplit {
                    989:     my $keyp=shift;
                    990:     return (split(/\,/,$keyp));
                    991: }
                    992: 
                    993: sub keysinorder {
                    994:     my ($name,$keyorder)=@_;
                    995:     return sort {
                    996: 	$$keyorder{$a} <=> $$keyorder{$b};
                    997:     } (keys %{$name});
                    998: }
                    999: 
1.211     www      1000: sub keysindisplayorder {
                   1001:     my ($name,$keyorder)=@_;
                   1002:     return sort {
                   1003: 	$$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
                   1004:     } (keys %{$name});
                   1005: }
                   1006: 
1.214     www      1007: sub sortmenu {
                   1008:     my ($r,$sortorder)=@_;
                   1009:     $r->print('<br /><input type="radio" name="sortorder" value="realmstudent"');
                   1010:     if ($sortorder eq 'realmstudent') {
                   1011:        $r->print(' checked="on"');
                   1012:     }
                   1013:     $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
                   1014:     $r->print('<br /><input type="radio" name="sortorder" value="studentrealm"');
                   1015:     if ($sortorder eq 'studentrealm') {
                   1016:        $r->print(' checked="on"');
                   1017:     }
                   1018:     $r->print(' />'.&mt('Sort by student (group/section) first, then realm'));
                   1019: }
                   1020: 
1.211     www      1021: sub standardkeyorder {
                   1022:     return ('parameter_0_opendate' => 1,
                   1023: 	    'parameter_0_duedate' => 2,
                   1024: 	    'parameter_0_answerdate' => 3,
                   1025: 	    'parameter_0_interval' => 4,
                   1026: 	    'parameter_0_weight' => 5,
                   1027: 	    'parameter_0_maxtries' => 6,
                   1028: 	    'parameter_0_hinttries' => 7,
                   1029: 	    'parameter_0_contentopen' => 8,
                   1030: 	    'parameter_0_contentclose' => 9,
                   1031: 	    'parameter_0_type' => 10,
                   1032: 	    'parameter_0_problemstatus' => 11,
                   1033: 	    'parameter_0_hiddenresource' => 12,
                   1034: 	    'parameter_0_hiddenparts' => 13,
                   1035: 	    'parameter_0_display' => 14,
                   1036: 	    'parameter_0_ordered' => 15,
                   1037: 	    'parameter_0_tol' => 16,
                   1038: 	    'parameter_0_sig' => 17,
1.218     www      1039: 	    'parameter_0_turnoffunit' => 18,
                   1040:             'parameter_0_discussend' => 19,
                   1041:             'parameter_0_discusshide' => 20);
1.211     www      1042: }
                   1043: 
1.59      matthew  1044: ##################################################
                   1045: ##################################################
                   1046: 
                   1047: =pod
                   1048: 
                   1049: =item assessparms
                   1050: 
                   1051: Show assessment data and parameters.  This is a large routine that should
                   1052: be simplified and shortened... someday.
                   1053: 
                   1054: Inputs: $r
                   1055: 
                   1056: Returns: nothing
                   1057: 
1.63      bowersj2 1058: Variables used (guessed by Jeremy):
                   1059: 
                   1060: =over 4
                   1061: 
                   1062: =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.
                   1063: 
                   1064: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
                   1065: 
                   1066: =item B<allmaps>:
                   1067: 
                   1068: =back
                   1069: 
1.59      matthew  1070: =cut
                   1071: 
                   1072: ##################################################
                   1073: ##################################################
1.30      www      1074: sub assessparms {
1.1       www      1075: 
1.43      albertel 1076:     my $r=shift;
1.201     www      1077: 
                   1078:     my @ids=();
                   1079:     my %symbp=();
                   1080:     my %mapp=();
                   1081:     my %typep=();
                   1082:     my %keyp=();
                   1083:     my %uris=();
                   1084:     my %maptitles=();
                   1085: 
1.2       www      1086: # -------------------------------------------------------- Variable declaration
1.209     www      1087: 
1.129     www      1088:     my %allmaps=();
                   1089:     my %alllevs=();
1.57      albertel 1090: 
1.187     www      1091:     my $uname;
                   1092:     my $udom;
                   1093:     my $uhome;
                   1094:     my $csec;
                   1095:  
1.190     albertel 1096:     my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
1.187     www      1097: 
1.57      albertel 1098:     $alllevs{'Resource Level'}='full';
1.215     www      1099:     $alllevs{'Map/Folder Level'}='map';
1.57      albertel 1100:     $alllevs{'Course Level'}='general';
                   1101: 
                   1102:     my %allparms;
                   1103:     my %allparts;
1.210     www      1104: #
                   1105: # Order in which these parameters will be displayed
                   1106: #
1.211     www      1107:     my %keyorder=&standardkeyorder();
                   1108: 
1.43      albertel 1109:     @ids=();
                   1110:     %symbp=();
                   1111:     %typep=();
                   1112: 
                   1113:     my $message='';
                   1114: 
1.190     albertel 1115:     $csec=$env{'form.csec'};
1.188     www      1116: 
1.190     albertel 1117:     if      ($udom=$env{'form.udom'}) {
                   1118:     } elsif ($udom=$env{'request.role.domain'}) {
                   1119:     } elsif ($udom=$env{'user.domain'}) {
1.172     albertel 1120:     } else {
                   1121: 	$udom=$r->dir_config('lonDefDomain');
                   1122:     }
1.43      albertel 1123: 
1.134     albertel 1124:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
1.190     albertel 1125:     my $pschp=$env{'form.pschp'};
1.134     albertel 1126:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
1.76      www      1127:     if (!@psprt) { $psprt[0]='0'; }
1.57      albertel 1128: 
1.43      albertel 1129:     my $pssymb='';
1.57      albertel 1130:     my $parmlev='';
                   1131:  
1.190     albertel 1132:     unless ($env{'form.parmlev'}) {
1.57      albertel 1133:         $parmlev = 'map';
                   1134:     } else {
1.190     albertel 1135:         $parmlev = $env{'form.parmlev'};
1.57      albertel 1136:     }
1.26      www      1137: 
1.29      www      1138: # ----------------------------------------------- Was this started from grades?
                   1139: 
1.190     albertel 1140:     if (($env{'form.command'} eq 'set') && ($env{'form.url'})
                   1141: 	&& (!$env{'form.dis'})) {
                   1142: 	my $url=$env{'form.url'};
1.194     albertel 1143: 	$url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.43      albertel 1144: 	$pssymb=&Apache::lonnet::symbread($url);
1.92      albertel 1145: 	if (!@pscat) { @pscat=('all'); }
1.43      albertel 1146: 	$pschp='';
1.57      albertel 1147:         $parmlev = 'full';
1.190     albertel 1148:     } elsif ($env{'form.symb'}) {
                   1149: 	$pssymb=$env{'form.symb'};
1.92      albertel 1150: 	if (!@pscat) { @pscat=('all'); }
1.43      albertel 1151: 	$pschp='';
1.57      albertel 1152:         $parmlev = 'full';
1.43      albertel 1153:     } else {
1.190     albertel 1154: 	$env{'form.url'}='';
1.43      albertel 1155:     }
                   1156: 
1.190     albertel 1157:     my $id=$env{'form.id'};
1.43      albertel 1158:     if (($id) && ($udom)) {
                   1159: 	$uname=(&Apache::lonnet::idget($udom,$id))[1];
                   1160: 	if ($uname) {
                   1161: 	    $id='';
                   1162: 	} else {
                   1163: 	    $message=
1.133     www      1164: 		"<font color=red>".&mt("Unknown ID")." '$id' ".
                   1165: 		&mt('at domain')." '$udom'</font>";
1.43      albertel 1166: 	}
                   1167:     } else {
1.190     albertel 1168: 	$uname=$env{'form.uname'};
1.43      albertel 1169:     }
                   1170:     unless ($udom) { $uname=''; }
                   1171:     $uhome='';
                   1172:     if ($uname) {
                   1173: 	$uhome=&Apache::lonnet::homeserver($uname,$udom);
                   1174:         if ($uhome eq 'no_host') {
                   1175: 	    $message=
1.133     www      1176: 		"<font color=red>".&mt("Unknown user")." '$uname' ".
                   1177: 		&mt("at domain")." '$udom'</font>";
1.43      albertel 1178: 	    $uname='';
1.12      www      1179:         } else {
1.103     albertel 1180: 	    $csec=&Apache::lonnet::getsection($udom,$uname,
1.190     albertel 1181: 					      $env{'request.course.id'});
1.43      albertel 1182: 	    if ($csec eq '-1') {
                   1183: 		$message="<font color=red>".
1.133     www      1184: 		    &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
                   1185: 		    &mt("not in this course")."</font>";
1.43      albertel 1186: 		$uname='';
1.190     albertel 1187: 		$csec=$env{'form.csec'};
1.43      albertel 1188: 	    } else {
                   1189: 		my %name=&Apache::lonnet::userenvironment($udom,$uname,
                   1190: 		      ('firstname','middlename','lastname','generation','id'));
1.133     www      1191: 		$message="\n<p>\n".&mt("Full Name").": ".
1.43      albertel 1192: 		    $name{'firstname'}.' '.$name{'middlename'}.' '
                   1193: 			.$name{'lastname'}.' '.$name{'generation'}.
1.133     www      1194: 			    "<br>\n".&mt('ID').": ".$name{'id'}.'<p>';
1.43      albertel 1195: 	    }
1.12      www      1196:         }
1.43      albertel 1197:     }
1.2       www      1198: 
1.43      albertel 1199:     unless ($csec) { $csec=''; }
1.12      www      1200: 
1.14      www      1201: # --------------------------------------------------------- Get all assessments
1.210     www      1202:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, 
                   1203: 				\%mapp, \%symbp,\%maptitles,\%uris,
                   1204: 				\%keyorder);
1.63      bowersj2 1205: 
1.57      albertel 1206:     $mapp{'0.0'} = '';
                   1207:     $symbp{'0.0'} = '';
1.99      albertel 1208: 
1.14      www      1209: # ---------------------------------------------------------- Anything to store?
1.190     albertel 1210:     if ($env{'form.pres_marker'}) {
1.205     www      1211:         my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
                   1212:         my @values=split(/\&\&\&/,$env{'form.pres_value'});
                   1213:         my @types=split(/\&\&\&/,$env{'form.pres_type'});
                   1214: 	for (my $i=0;$i<=$#markers;$i++) {
                   1215: 	    $message.=&storeparm(split(/\&/,$markers[$i]),
                   1216: 				 $values[$i],
                   1217: 				 $types[$i],
                   1218: 				 $uname,$udom,$csec);
                   1219: 	}
1.68      www      1220: # ---------------------------------------------------------------- Done storing
1.130     www      1221: 	$message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
1.68      www      1222:     }
1.57      albertel 1223: #----------------------------------------------- if all selected, fill in array
1.209     www      1224:     if ($pscat[0] eq "all") {@pscat = (keys %allparms);}
                   1225:     if (!@pscat) { @pscat=('duedate','opendate','answerdate','weight','maxtries') }; 
1.57      albertel 1226:     if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
1.2       www      1227: # ------------------------------------------------------------------ Start page
1.63      bowersj2 1228: 
1.209     www      1229:     &startpage($r);
1.57      albertel 1230: 
1.44      albertel 1231:     foreach ('tolerance','date_default','date_start','date_end',
                   1232: 	     'date_interval','int','float','string') {
                   1233: 	$r->print('<input type="hidden" value="'.
1.190     albertel 1234: 		  $env{'form.recent_'.$_}.'" name="recent_'.$_.'">');
1.44      albertel 1235:     }
1.57      albertel 1236:                         
1.44      albertel 1237:     if (!$pssymb) {
1.209     www      1238:         $r->print('<table border="1"><tr><td>');
                   1239:         &levelmenu($r,\%alllevs,$parmlev);
1.128     albertel 1240: 	if ($parmlev ne 'general') {
1.209     www      1241:             $r->print('<td>');
                   1242: 	    &mapmenu($r,\%allmaps,$pschp,\%maptitles);
                   1243: 	    $r->print('</td>');
1.128     albertel 1244: 	}
1.209     www      1245:         $r->print('</td></tr></table>');
1.211     www      1246: 	&displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder);
1.44      albertel 1247:     } else {
1.125     www      1248:         my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
1.209     www      1249:         $r->print(&mt('Specific Resource').": ".$resource.
1.212     www      1250:                   '<input type="hidden" value="'.$pssymb.'" name="symb"><br />');
1.57      albertel 1251:     }
1.209     www      1252:     &usermenu($r,$uname,$id,$udom,$csec);    
1.57      albertel 1253: 
1.210     www      1254:     $r->print('<p>'.$message.'</p>');
                   1255: 
1.209     www      1256:     $r->print('<br /><input type="submit" name="dis" value="'.&mt("Update Parameter Display").'" />');
1.57      albertel 1257: 
                   1258:     my @temp_pscat;
                   1259:     map {
                   1260:         my $cat = $_;
                   1261:         push(@temp_pscat, map { $_.'.'.$cat } @psprt);
                   1262:     } @pscat;
                   1263: 
                   1264:     @pscat = @temp_pscat;
                   1265: 
1.209     www      1266:     if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
1.10      www      1267: # ----------------------------------------------------------------- Start Table
1.57      albertel 1268:         my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
1.190     albertel 1269:         my $csuname=$env{'user.name'};
                   1270:         my $csudom=$env{'user.domain'};
1.57      albertel 1271: 
1.203     www      1272:         if ($parmlev eq 'full') {
1.57      albertel 1273:            my $coursespan=$csec?8:5;
                   1274:            $r->print('<p><table border=2>');
                   1275:            $r->print('<tr><td colspan=5></td>');
1.130     www      1276:            $r->print('<th colspan='.($coursespan).'>'.&mt('Any User').'</th>');
1.57      albertel 1277:            if ($uname) {
                   1278:                $r->print("<th colspan=3 rowspan=2>");
1.130     www      1279:                $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
1.57      albertel 1280:            }
1.133     www      1281: 	   my %lt=&Apache::lonlocal::texthash(
                   1282: 				  'pie'    => "Parameter in Effect",
                   1283: 				  'csv'    => "Current Session Value",
                   1284:                                   'at'     => 'at',
                   1285:                                   'rl'     => "Resource Level",
                   1286: 				  'ic'     => 'in Course',
                   1287: 				  'aut'    => "Assessment URL and Title",
1.143     albertel 1288: 				  'type'   => 'Type',
1.133     www      1289: 				  'emof'   => "Enclosing Map or Folder",
1.143     albertel 1290: 				  'part'   => 'Part',
1.133     www      1291:                                   'pn'     => 'Parameter Name',
                   1292: 				  'def'    => 'default',
                   1293: 				  'femof'  => 'from Enclosing Map or Folder',
                   1294: 				  'gen'    => 'general',
                   1295: 				  'foremf' => 'for Enclosing Map or Folder',
                   1296: 				  'fr'     => 'for Resource'
                   1297: 					      );
1.57      albertel 1298:            $r->print(<<ENDTABLETWO);
1.133     www      1299: <th rowspan=3>$lt{'pie'}</th>
                   1300: <th rowspan=3>$lt{'csv'}<br>($csuname $lt{'at'} $csudom)</th>
1.182     albertel 1301: </tr><tr><td colspan=5></td><th colspan=2>$lt{'ic'}</th><th colspan=2>$lt{'rl'}</th>
                   1302: <th colspan=1>$lt{'ic'}</th>
                   1303: 
1.10      www      1304: ENDTABLETWO
1.57      albertel 1305:            if ($csec) {
1.133     www      1306:                 $r->print("<th colspan=3>".
                   1307: 			  &mt("in Section/Group")." $csec</th>");
1.57      albertel 1308:            }
                   1309:            $r->print(<<ENDTABLEHEADFOUR);
1.133     www      1310: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
                   1311: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
1.192     albertel 1312: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
                   1313: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
1.10      www      1314: ENDTABLEHEADFOUR
1.57      albertel 1315: 
                   1316:            if ($csec) {
1.130     www      1317:                $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1.57      albertel 1318:            }
                   1319: 
                   1320:            if ($uname) {
1.130     www      1321:                $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1.57      albertel 1322:            }
                   1323: 
                   1324:            $r->print('</tr>');
                   1325: 
                   1326:            my $defbgone='';
                   1327:            my $defbgtwo='';
                   1328: 
                   1329:            foreach (@ids) {
                   1330: 
                   1331:                 my $rid=$_;
                   1332:                 my ($inmapid)=($rid=~/\.(\d+)$/);
                   1333: 
1.152     albertel 1334:                 if ((!$pssymb && 
                   1335: 		     (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
                   1336: 		    ||
                   1337: 		    ($pssymb && $pssymb eq $symbp{$rid})) {
1.4       www      1338: # ------------------------------------------------------ Entry for one resource
1.184     albertel 1339:                     if ($defbgone eq '"#E0E099"') {
                   1340:                         $defbgone='"#E0E0DD"';
1.57      albertel 1341:                     } else {
1.184     albertel 1342:                         $defbgone='"#E0E099"';
1.57      albertel 1343:                     }
1.184     albertel 1344:                     if ($defbgtwo eq '"#FFFF99"') {
                   1345:                         $defbgtwo='"#FFFFDD"';
1.57      albertel 1346:                     } else {
1.184     albertel 1347:                         $defbgtwo='"#FFFF99"';
1.57      albertel 1348:                     }
                   1349:                     my $thistitle='';
                   1350:                     my %name=   ();
                   1351:                     undef %name;
                   1352:                     my %part=   ();
                   1353:                     my %display=();
                   1354:                     my %type=   ();
                   1355:                     my %default=();
1.196     www      1356:                     my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57      albertel 1357: 
1.210     www      1358:                     foreach (&keysplit($keyp{$rid})) {
1.57      albertel 1359:                         my $tempkeyp = $_;
                   1360:                         if (grep $_ eq $tempkeyp, @catmarker) {
                   1361:                           $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
                   1362:                           $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
                   1363:                           $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
                   1364:                           unless ($display{$_}) { $display{$_}=''; }
                   1365:                           $display{$_}.=' ('.$name{$_}.')';
                   1366:                           $default{$_}=&Apache::lonnet::metadata($uri,$_);
                   1367:                           $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
                   1368:                           $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
                   1369:                         }
                   1370:                     }
                   1371:                     my $totalparms=scalar keys %name;
                   1372:                     if ($totalparms>0) {
                   1373:                         my $firstrow=1;
1.180     albertel 1374: 			my $title=&Apache::lonnet::gettitle($uri);
1.57      albertel 1375:                         $r->print('<tr><td bgcolor='.$defbgone.
                   1376:                              ' rowspan='.$totalparms.
                   1377:                              '><tt><font size=-1>'.
                   1378:                              join(' / ',split(/\//,$uri)).
                   1379:                              '</font></tt><p><b>'.
1.154     albertel 1380:                              "<a href=\"javascript:openWindow('".
                   1381: 				  &Apache::lonnet::clutter($uri).
1.57      albertel 1382:                              "', 'metadatafile', '450', '500', 'no', 'yes')\";".
1.127     albertel 1383:                              " TARGET=_self>$title");
1.57      albertel 1384: 
                   1385:                         if ($thistitle) {
                   1386:                             $r->print(' ('.$thistitle.')');
                   1387:                         }
                   1388:                         $r->print('</a></b></td>');
                   1389:                         $r->print('<td bgcolor='.$defbgtwo.
                   1390:                                       ' rowspan='.$totalparms.'>'.$typep{$rid}.
                   1391:                                       '</td>');
                   1392: 
                   1393:                         $r->print('<td bgcolor='.$defbgone.
                   1394:                                       ' rowspan='.$totalparms.
                   1395:                                       '><tt><font size=-1>');
                   1396: 
                   1397:                         $r->print(' / res / ');
                   1398:                         $r->print(join(' / ', split(/\//,$mapp{$rid})));
                   1399: 
                   1400:                         $r->print('</font></tt></td>');
                   1401: 
1.210     www      1402:                         foreach (&keysinorder(\%name,\%keyorder)) {
1.57      albertel 1403:                             unless ($firstrow) {
                   1404:                                 $r->print('<tr>');
                   1405:                             } else {
                   1406:                                 undef $firstrow;
                   1407:                             }
                   1408: 
1.201     www      1409:                             &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
1.57      albertel 1410:                                        \%type,\%display,$defbgone,$defbgtwo,
1.187     www      1411:                                        $parmlev,$uname,$udom,$csec);
1.57      albertel 1412:                         }
                   1413:                     }
                   1414:                 }
                   1415:             } # end foreach ids
1.43      albertel 1416: # -------------------------------------------------- End entry for one resource
1.57      albertel 1417:             $r->print('</table>');
1.203     www      1418:         } # end of  full
1.57      albertel 1419: #--------------------------------------------------- Entry for parm level map
                   1420:         if ($parmlev eq 'map') {
                   1421:             my $defbgone = '"E0E099"';
                   1422:             my $defbgtwo = '"FFFF99"';
                   1423: 
                   1424:             my %maplist;
                   1425: 
                   1426:             if ($pschp eq 'all') {
                   1427:                 %maplist = %allmaps; 
                   1428:             } else {
                   1429:                 %maplist = ($pschp => $mapp{$pschp});
                   1430:             }
                   1431: 
                   1432: #-------------------------------------------- for each map, gather information
                   1433:             my $mapid;
1.60      albertel 1434: 	    foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
                   1435:                 my $maptitle = $maplist{$mapid};
1.57      albertel 1436: 
                   1437: #-----------------------  loop through ids and get all parameter types for map
                   1438: #-----------------------------------------          and associated information
                   1439:                 my %name = ();
                   1440:                 my %part = ();
                   1441:                 my %display = ();
                   1442:                 my %type = ();
                   1443:                 my %default = ();
                   1444:                 my $map = 0;
                   1445: 
                   1446: #		$r->print("Catmarker: @catmarker<br />\n");
                   1447:                
                   1448:                 foreach (@ids) {
                   1449:                   ($map)=(/([\d]*?)\./);
                   1450:                   my $rid = $_;
                   1451:         
                   1452: #                  $r->print("$mapid:$map:   $rid <br /> \n");
                   1453: 
                   1454:                   if ($map eq $mapid) {
1.196     www      1455:                     my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57      albertel 1456: #                    $r->print("Keys: $keyp{$rid} <br />\n");
                   1457: 
                   1458: #--------------------------------------------------------------------
                   1459: # @catmarker contains list of all possible parameters including part #s
                   1460: # $fullkeyp contains the full part/id # for the extraction of proper parameters
                   1461: # $tempkeyp contains part 0 only (no ids - ie, subparts)
                   1462: # When storing information, store as part 0
                   1463: # When requesting information, request from full part
                   1464: #-------------------------------------------------------------------
1.210     www      1465:                     foreach (&keysplit($keyp{$rid})) {
1.57      albertel 1466:                       my $tempkeyp = $_;
                   1467:                       my $fullkeyp = $tempkeyp;
1.73      albertel 1468:                       $tempkeyp =~ s/_\w+_/_0_/;
1.57      albertel 1469:                       
                   1470:                       if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
                   1471:                         $part{$tempkeyp}="0";
                   1472:                         $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
                   1473:                         $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
                   1474:                         unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
                   1475:                         $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1.73      albertel 1476:                         $display{$tempkeyp} =~ s/_\w+_/_0_/;
1.57      albertel 1477:                         $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
                   1478:                         $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
                   1479:                       }
                   1480:                     } # end loop through keys
                   1481:                   }
                   1482:                 } # end loop through ids
                   1483:                                  
                   1484: #---------------------------------------------------- print header information
1.133     www      1485:                 my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
1.82      www      1486:                 my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
1.57      albertel 1487:                 $r->print(<<ENDMAPONE);
                   1488: <center><h4>
1.135     albertel 1489: Set Defaults for All Resources in $foldermap<br />
                   1490: <font color="red"><i>$showtitle</i></font><br />
1.57      albertel 1491: Specifically for
                   1492: ENDMAPONE
                   1493:                 if ($uname) {
                   1494:                     my %name=&Apache::lonnet::userenvironment($udom,$uname,
                   1495:                       ('firstname','middlename','lastname','generation', 'id'));
                   1496:                     my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
                   1497:                            .$name{'lastname'}.' '.$name{'generation'};
1.135     albertel 1498:                     $r->print(&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
1.130     www      1499:                         &mt('in')." \n");
1.57      albertel 1500:                 } else {
1.135     albertel 1501:                     $r->print("<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n");
1.57      albertel 1502:                 }
                   1503:             
1.135     albertel 1504:                 if ($csec) {$r->print(&mt("Section")." <font color=\"red\"><i>$csec</i></font> ".
1.130     www      1505: 				      &mt('of')." \n")};
1.57      albertel 1506: 
1.135     albertel 1507:                 $r->print("<font color=\"red\"><i>$coursename</i></font><br />");
                   1508:                 $r->print("</h4>\n");
1.57      albertel 1509: #---------------------------------------------------------------- print table
                   1510:                 $r->print('<p><table border="2">');
1.130     www      1511:                 $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
                   1512:                 $r->print('<th>'.&mt('Default Value').'</th>');
                   1513:                 $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1.57      albertel 1514: 
1.210     www      1515: 	        foreach (&keysinorder(\%name,\%keyorder)) {
1.168     matthew  1516:                     $r->print('<tr>');
1.201     www      1517:                     &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1.57      albertel 1518:                            \%type,\%display,$defbgone,$defbgtwo,
1.187     www      1519:                            $parmlev,$uname,$udom,$csec);
1.57      albertel 1520:                 }
                   1521:                 $r->print("</table></center>");
                   1522:             } # end each map
                   1523:         } # end of $parmlev eq map
                   1524: #--------------------------------- Entry for parm level general (Course level)
                   1525:         if ($parmlev eq 'general') {
                   1526:             my $defbgone = '"E0E099"';
                   1527:             my $defbgtwo = '"FFFF99"';
                   1528: 
                   1529: #-------------------------------------------- for each map, gather information
                   1530:             my $mapid="0.0";
                   1531: #-----------------------  loop through ids and get all parameter types for map
                   1532: #-----------------------------------------          and associated information
                   1533:             my %name = ();
                   1534:             my %part = ();
                   1535:             my %display = ();
                   1536:             my %type = ();
                   1537:             my %default = ();
                   1538:                
                   1539:             foreach (@ids) {
                   1540:                 my $rid = $_;
                   1541:         
1.196     www      1542:                 my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57      albertel 1543: 
                   1544: #--------------------------------------------------------------------
                   1545: # @catmarker contains list of all possible parameters including part #s
                   1546: # $fullkeyp contains the full part/id # for the extraction of proper parameters
                   1547: # $tempkeyp contains part 0 only (no ids - ie, subparts)
                   1548: # When storing information, store as part 0
                   1549: # When requesting information, request from full part
                   1550: #-------------------------------------------------------------------
1.210     www      1551:                 foreach (&keysplit($keyp{$rid})) {
1.57      albertel 1552:                   my $tempkeyp = $_;
                   1553:                   my $fullkeyp = $tempkeyp;
1.73      albertel 1554:                   $tempkeyp =~ s/_\w+_/_0_/;
1.57      albertel 1555:                   if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
                   1556:                     $part{$tempkeyp}="0";
                   1557:                     $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
                   1558:                     $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
                   1559:                     unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
                   1560:                     $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1.73      albertel 1561:                     $display{$tempkeyp} =~ s/_\w+_/_0_/;
1.57      albertel 1562:                     $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
                   1563:                     $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
                   1564:                   }
                   1565:                 } # end loop through keys
                   1566:             } # end loop through ids
                   1567:                                  
                   1568: #---------------------------------------------------- print header information
1.133     www      1569: 	    my $setdef=&mt("Set Defaults for All Resources in Course");
1.57      albertel 1570:             $r->print(<<ENDMAPONE);
1.133     www      1571: <center><h4>$setdef
1.135     albertel 1572: <font color="red"><i>$coursename</i></font><br />
1.57      albertel 1573: ENDMAPONE
                   1574:             if ($uname) {
                   1575:                 my %name=&Apache::lonnet::userenvironment($udom,$uname,
                   1576:                   ('firstname','middlename','lastname','generation', 'id'));
                   1577:                 my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
                   1578:                        .$name{'lastname'}.' '.$name{'generation'};
1.135     albertel 1579:                 $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
1.57      albertel 1580:             } else {
1.135     albertel 1581:                 $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
1.57      albertel 1582:             }
                   1583:             
1.135     albertel 1584:             if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
                   1585:             $r->print("</h4>\n");
1.57      albertel 1586: #---------------------------------------------------------------- print table
                   1587:             $r->print('<p><table border="2">');
1.130     www      1588:             $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
                   1589:             $r->print('<th>'.&mt('Default Value').'</th>');
                   1590:             $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1.57      albertel 1591: 
1.210     www      1592: 	    foreach (&keysinorder(\%name,\%keyorder)) {
1.168     matthew  1593:                 $r->print('<tr>');
1.201     www      1594:                 &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1.187     www      1595:                        \%type,\%display,$defbgone,$defbgtwo,$parmlev,$uname,$udom,$csec);
1.57      albertel 1596:             }
                   1597:             $r->print("</table></center>");
                   1598:         } # end of $parmlev eq general
1.43      albertel 1599:     }
1.44      albertel 1600:     $r->print('</form></body></html>');
1.57      albertel 1601: } # end sub assessparms
1.30      www      1602: 
1.59      matthew  1603: 
                   1604: ##################################################
                   1605: ##################################################
                   1606: 
                   1607: =pod
                   1608: 
                   1609: =item crsenv
                   1610: 
1.105     matthew  1611: Show and set course data and parameters.  This is a large routine that should
1.59      matthew  1612: be simplified and shortened... someday.
                   1613: 
                   1614: Inputs: $r
                   1615: 
                   1616: Returns: nothing
                   1617: 
                   1618: =cut
                   1619: 
                   1620: ##################################################
                   1621: ##################################################
1.30      www      1622: sub crsenv {
                   1623:     my $r=shift;
                   1624:     my $setoutput='';
1.64      www      1625:     my $bodytag=&Apache::loncommon::bodytag(
                   1626:                              'Set Course Environment Parameters');
1.194     albertel 1627:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,
                   1628: 						    'Edit Course Environment');
1.190     albertel 1629:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   1630:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.105     matthew  1631: 
                   1632:     #
                   1633:     # Go through list of changes
1.190     albertel 1634:     foreach (keys %env) {
1.105     matthew  1635:         next if ($_!~/^form\.(.+)\_setparmval$/);
                   1636:         my $name  = $1;
1.190     albertel 1637:         my $value = $env{'form.'.$name.'_value'};
1.105     matthew  1638:         if ($name eq 'newp') {
1.190     albertel 1639:             $name = $env{'form.newp_name'};
1.105     matthew  1640:         }
                   1641:         if ($name eq 'url') {
                   1642:             $value=~s/^\/res\///;
                   1643:             my $bkuptime=time;
                   1644:             my @tmp = &Apache::lonnet::get
                   1645:                 ('environment',['url'],$dom,$crs);
1.130     www      1646:             $setoutput.=&mt('Backing up previous URL').': '.
1.105     matthew  1647:                 &Apache::lonnet::put
                   1648:                 ('environment',
                   1649:                  {'top level map backup '.$bkuptime => $tmp[1] },
                   1650:                  $dom,$crs).
                   1651:                      '<br>';
                   1652:         }
                   1653:         #
                   1654:         # Deal with modified default spreadsheets
                   1655:         if ($name =~ /^spreadsheet_default_(classcalc|
                   1656:                                             studentcalc|
                   1657:                                             assesscalc)$/x) {
                   1658:             my $sheettype = $1; 
                   1659:             if ($sheettype eq 'classcalc') {
                   1660:                 # no need to do anything since viewing the sheet will
                   1661:                 # cause it to be updated. 
                   1662:             } elsif ($sheettype eq 'studentcalc') {
                   1663:                 # expire all the student spreadsheets
                   1664:                 &Apache::lonnet::expirespread('','','studentcalc');
                   1665:             } else {
                   1666:                 # expire all the assessment spreadsheets 
                   1667:                 #    this includes non-default spreadsheets, but better to
                   1668:                 #    be safe than sorry.
                   1669:                 &Apache::lonnet::expirespread('','','assesscalc');
                   1670:                 # expire all the student spreadsheets
                   1671:                 &Apache::lonnet::expirespread('','','studentcalc');
1.30      www      1672:             }
1.105     matthew  1673:         }
                   1674:         #
1.107     matthew  1675:         # Deal with the enrollment dates
                   1676:         if ($name =~ /^default_enrollment_(start|end)_date$/) {
                   1677:             $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
                   1678:         }
1.178     raeburn  1679:         # Get existing cloners
                   1680:         my @oldcloner = ();
                   1681:         if ($name eq 'cloners') {
                   1682:             my %clonenames=&Apache::lonnet::dump('environment',$dom,$crs,'cloners');
                   1683:             if ($clonenames{'cloners'} =~ /,/) {
                   1684:                 @oldcloner = split/,/,$clonenames{'cloners'};
                   1685:             } else {
                   1686:                 $oldcloner[0] = $clonenames{'cloners'};
                   1687:             }
                   1688:         }
1.107     matthew  1689:         #
1.105     matthew  1690:         # Let the user know we made the changes
1.153     albertel 1691:         if ($name && defined($value)) {
1.178     raeburn  1692:             if ($name eq 'cloners') {
                   1693:                 $value =~ s/^,//;
                   1694:                 $value =~ s/,$//;
                   1695:             }
1.105     matthew  1696:             my $put_result = &Apache::lonnet::put('environment',
                   1697:                                                   {$name=>$value},$dom,$crs);
                   1698:             if ($put_result eq 'ok') {
1.130     www      1699:                 $setoutput.=&mt('Set').' <b>'.$name.'</b> '.&mt('to').' <b>'.$value.'</b>.<br />';
1.178     raeburn  1700:                 if ($name eq 'cloners') {
                   1701:                     &change_clone($value,\@oldcloner);
                   1702:                 }
1.179     raeburn  1703:                 # Flush the course logs so course description is immediately updated
                   1704:                 if ($name eq 'description' && defined($value)) {
                   1705:                     &Apache::lonnet::flushcourselogs();
                   1706:                 }
1.105     matthew  1707:             } else {
1.130     www      1708:                 $setoutput.=&mt('Unable to set').' <b>'.$name.'</b> '.&mt('to').
                   1709: 		    ' <b>'.$value.'</b> '.&mt('due to').' '.$put_result.'.<br />';
1.30      www      1710:             }
                   1711:         }
1.38      harris41 1712:     }
1.108     www      1713: # ------------------------- Re-init course environment entries for this session
                   1714: 
1.190     albertel 1715:     &Apache::lonnet::coursedescription($env{'request.course.id'});
1.105     matthew  1716: 
1.30      www      1717: # -------------------------------------------------------- Get parameters again
1.45      matthew  1718: 
                   1719:     my %values=&Apache::lonnet::dump('environment',$dom,$crs);
1.140     sakharuk 1720:     my $SelectStyleFile=&mt('Select Style File');
1.141     sakharuk 1721:     my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
1.30      www      1722:     my $output='';
1.45      matthew  1723:     if (! exists($values{'con_lost'})) {
1.30      www      1724:         my %descriptions=
1.140     sakharuk 1725: 	    ('url'            => '<b>'.&mt('Top Level Map').'</b> '.
1.46      matthew  1726:                                  '<a href="javascript:openbrowser'.
1.47      matthew  1727:                                  "('envform','url','sequence')\">".
1.140     sakharuk 1728:                                  &mt('Select Map').'</a><br /><font color=red> '.
                   1729:                                  &mt('Modification may make assessment data inaccessible').
                   1730:                                  '</font>',
                   1731:              'description'    => '<b>'.&mt('Course Description').'</b>',
1.158     sakharuk 1732:              'courseid'       => '<b>'.&mt('Course ID or number').
1.140     sakharuk 1733:                                  '</b><br />'.
                   1734:                                  '('.&mt('internal').', '.&mt('optional').')',
1.177     raeburn  1735:              'cloners'        => '<b>'.&mt('Users allowed to clone course').'</b><br /><tt>(user:domain,user:domain)</tt><br />'.&mt('Users with active Course Coordinator role in the course automatically have the right to clone it, and can be omitted from list.'),
1.150     www      1736:              'grading'        => '<b>'.&mt('Grading').'</b><br />'.
                   1737:                                  '<tt>"standard", "external", or "spreadsheet"</tt> '.&Apache::loncommon::help_open_topic('GradingOptions'),
1.140     sakharuk 1738:              'default_xml_style' => '<b>'.&mt('Default XML Style File').'</b> '.
1.52      www      1739:                     '<a href="javascript:openbrowser'.
                   1740:                     "('envform','default_xml_style'".
1.140     sakharuk 1741:                     ",'sty')\">$SelectStyleFile</a><br>",
1.141     sakharuk 1742:              'question.email' => '<b>'.&mt('Feedback Addresses for Resource Content Question').
                   1743:                                  '</b><br />(<tt>user:domain,'.
1.74      www      1744:                                  'user:domain(section;section;...;*;...),...</tt>)',
1.141     sakharuk 1745:              'comment.email'  => '<b>'.&mt('Feedback Addresses for Course Content Comments').'</b><br />'.
1.74      www      1746:                                  '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1.141     sakharuk 1747:              'policy.email'   => '<b>'.&mt('Feedback Addresses for Course Policy').'</b>'.
1.75      albertel 1748:                                  '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1.141     sakharuk 1749:              'hideemptyrows'  => '<b>'.&mt('Hide Empty Rows in Spreadsheets').'</b><br />'.
1.158     sakharuk 1750:                                  '('.&mt('"[_1]" for default hiding','<tt>yes</tt>').')',
1.141     sakharuk 1751:              'pageseparators'  => '<b>'.&mt('Visibly Separate Items on Pages').'</b><br />'.
1.158     sakharuk 1752:                                  '('.&mt('"[_1]" for visible separation','<tt>yes</tt>').', '.
1.141     sakharuk 1753:                                  &mt('changes will not show until next login').')',
1.169     matthew  1754:              'student_classlist_view' => '<b>'.&mt('Allow students to view classlist.').'</b>'.&mt('("all":students can view all sections,"section":students can only view their own section.blank or "disabled" prevents student view.'),
1.118     matthew  1755: 
1.141     sakharuk 1756:              'plc.roles.denied'=> '<b>'.&mt('Disallow live chatroom use for Roles').
                   1757:                                   '</b><br />"<tt>st</tt>": '.
1.158     sakharuk 1758:                                   &mt('student').', "<tt>ta</tt>": '.
1.118     matthew  1759:                                   'TA, "<tt>in</tt>": '.
1.158     sakharuk 1760:                                   &mt('instructor').';<br /><tt>'.&mt('role,role,...').'</tt>) '.
1.118     matthew  1761: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
                   1762:              'plc.users.denied' => 
1.141     sakharuk 1763:                           '<b>'.&mt('Disallow live chatroom use for Users').'</b><br />'.
1.118     matthew  1764:                                  '(<tt>user:domain,user:domain,...</tt>)',
                   1765: 
1.141     sakharuk 1766:              'pch.roles.denied'=> '<b>'.&mt('Disallow Resource Discussion for Roles').
                   1767:                                   '</b><br />"<tt>st</tt>": '.
1.61      albertel 1768:                                   'student, "<tt>ta</tt>": '.
                   1769:                                   'TA, "<tt>in</tt>": '.
1.75      albertel 1770:                                   'instructor;<br /><tt>role,role,...</tt>) '.
1.61      albertel 1771: 	       Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
1.53      www      1772:              'pch.users.denied' => 
1.141     sakharuk 1773:                           '<b>'.&mt('Disallow Resource Discussion for Users').'</b><br />'.
1.53      www      1774:                                  '(<tt>user:domain,user:domain,...</tt>)',
1.49      matthew  1775:              'spreadsheet_default_classcalc' 
1.141     sakharuk 1776:                  => '<b>'.&mt('Default Course Spreadsheet').'</b> '.
1.50      matthew  1777:                     '<a href="javascript:openbrowser'.
                   1778:                     "('envform','spreadsheet_default_classcalc'".
1.141     sakharuk 1779:                     ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1.49      matthew  1780:              'spreadsheet_default_studentcalc' 
1.141     sakharuk 1781:                  => '<b>'.&mt('Default Student Spreadsheet').'</b> '.
1.50      matthew  1782:                     '<a href="javascript:openbrowser'.
                   1783:                     "('envform','spreadsheet_default_calc'".
1.141     sakharuk 1784:                     ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1.49      matthew  1785:              'spreadsheet_default_assesscalc' 
1.141     sakharuk 1786:                  => '<b>'.&mt('Default Assessment Spreadsheet').'</b> '.
1.50      matthew  1787:                     '<a href="javascript:openbrowser'.
                   1788:                     "('envform','spreadsheet_default_assesscalc'".
1.141     sakharuk 1789:                     ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1.75      albertel 1790: 	     'allow_limited_html_in_feedback'
1.141     sakharuk 1791: 	         => '<b>'.&mt('Allow limited HTML in discussion posts').'</b><br />'.
1.158     sakharuk 1792: 	            '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
1.170     raeburn  1793:              'allow_discussion_post_editing'
                   1794:                  => '<b>'.&mt('Allow users to edit/delete their own discussion posts').'</b><br />'.
                   1795:                     '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
1.89      albertel 1796: 	     'rndseed'
1.140     sakharuk 1797: 	         => '<b>'.&mt('Randomization algorithm used').'</b> <br />'.
                   1798:                     '<font color="red">'.&mt('Modifying this will make problems').' '.
                   1799:                     &mt('have different numbers and answers').'</font>',
1.151     albertel 1800: 	     'receiptalg'
                   1801: 	         => '<b>'.&mt('Receipt algorithm used').'</b> <br />'.
                   1802:                     &mt('This controls how receipt numbers are generated.'),
1.164     sakharuk 1803:              'suppress_tries'
                   1804:                  => '<b>'.&mt('Suppress number of tries in printing').'</b>('.
                   1805:                     &mt('yes if supress').')',
1.113     sakharuk 1806:              'problem_stream_switch'
1.141     sakharuk 1807:                  => '<b>'.&mt('Allow problems to be split over pages').'</b><br />'.
1.158     sakharuk 1808:                     ' ('.&mt('"[_1]" if allowed, anything else if not','<tt>yes</tt>').')',
1.161     sakharuk 1809:              'default_paper_size' 
                   1810:                  => '<b>'.&mt('Default paper type').'</b><br />'.
                   1811:                     ' ('.&mt('supported types').': Letter [8 1/2x11 in], Legal [8 1/2x14 in],'. 
                   1812:                     ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'. 
                   1813:                     ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])',
1.111     sakharuk 1814:              'anonymous_quiz'
1.150     www      1815:                  => '<b>'.&mt('Anonymous quiz/exam').'</b><br />'.
1.141     sakharuk 1816:                     ' (<tt><b>'.&mt('yes').'</b> '.&mt('to avoid print students names').' </tt>)',
1.217     albertel 1817:              'default_enrollment_start_date' => '<b>'.&mt('Default beginning date for student access.').'</b>',
                   1818:              'default_enrollment_end_date'   => '<b>'.&mt('Default ending date for student access.').'</b>',
1.150     www      1819:              'nothideprivileged'   => '<b>'.&mt('Privileged users that should not be hidden on staff listings').'</b>'.
                   1820:                                  '<br />(<tt>user:domain,user:domain,...</tt>)',
1.140     sakharuk 1821:              'languages' => '<b>'.&mt('Languages used').'</b>',
1.115     www      1822:              'disable_receipt_display'
1.141     sakharuk 1823:                  => '<b>'.&mt('Disable display of problem receipts').'</b><br />'.
1.158     sakharuk 1824:                     ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
1.163     albertel 1825: 	     'disablesigfigs'
                   1826: 	         => '<b>'.&mt('Disable checking of Significant Figures').'</b><br />'.
                   1827:                     ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
1.149     albertel 1828: 	     'tthoptions'
                   1829: 	         => '<b>'.&mt('Default set of options to pass to tth/m when converting tex').'</b>'
1.107     matthew  1830:              ); 
1.177     raeburn  1831:         my @Display_Order = ('url','description','courseid','cloners','grading',
1.107     matthew  1832:                              'default_xml_style','pageseparators',
                   1833:                              'question.email','comment.email','policy.email',
1.169     matthew  1834:                              'student_classlist_view',
1.118     matthew  1835:                              'plc.roles.denied','plc.users.denied',
1.107     matthew  1836:                              'pch.roles.denied','pch.users.denied',
                   1837:                              'allow_limited_html_in_feedback',
1.170     raeburn  1838:                              'allow_discussion_post_editing',
1.108     www      1839:                              'languages',
1.150     www      1840: 			     'nothideprivileged',
1.107     matthew  1841:                              'rndseed',
1.151     albertel 1842:                              'receiptalg',
1.107     matthew  1843:                              'problem_stream_switch',
1.164     sakharuk 1844: 			     'suppress_tries',
1.161     sakharuk 1845:                              'default_paper_size',
1.115     www      1846:                              'disable_receipt_display',
1.107     matthew  1847:                              'spreadsheet_default_classcalc',
                   1848:                              'spreadsheet_default_studentcalc',
                   1849:                              'spreadsheet_default_assesscalc', 
                   1850:                              'hideemptyrows',
                   1851:                              'default_enrollment_start_date',
                   1852:                              'default_enrollment_end_date',
1.163     albertel 1853: 			     'tthoptions',
                   1854: 			     'disablesigfigs'
1.107     matthew  1855:                              );
                   1856: 	foreach my $parameter (sort(keys(%values))) {
1.142     raeburn  1857:             unless ($parameter =~ m/^internal\./) {
                   1858:                 if (! $descriptions{$parameter}) {
                   1859:                     $descriptions{$parameter}=$parameter;
                   1860:                     push(@Display_Order,$parameter);
                   1861:                 }
                   1862:             }
1.43      albertel 1863: 	}
1.107     matthew  1864:         foreach my $parameter (@Display_Order) {
                   1865:             my $description = $descriptions{$parameter};
1.51      matthew  1866:             # onchange is javascript to automatically check the 'Set' button.
1.69      www      1867:             my $onchange = 'onFocus="javascript:window.document.forms'.
1.107     matthew  1868:                 "['envform'].elements['".$parameter."_setparmval']".
1.51      matthew  1869:                 '.checked=true;"';
1.107     matthew  1870:             $output .= '<tr><td>'.$description.'</td>';
                   1871:             if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
                   1872:                 $output .= '<td>'.
                   1873:                     &Apache::lonhtmlcommon::date_setter('envform',
                   1874:                                                         $parameter.'_value',
                   1875:                                                         $values{$parameter},
                   1876:                                                         $onchange).
                   1877:                                                         '</td>';
                   1878:             } else {
                   1879:                 $output .= '<td>'.
                   1880:                     &Apache::lonhtmlcommon::textbox($parameter.'_value',
                   1881:                                                     $values{$parameter},
                   1882:                                                     40,$onchange).'</td>';
                   1883:             }
                   1884:             $output .= '<td>'.
                   1885:                 &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
                   1886:                 '</td>';
                   1887:             $output .= "</tr>\n";
1.51      matthew  1888: 	}
1.69      www      1889:         my $onchange = 'onFocus="javascript:window.document.forms'.
1.51      matthew  1890:             '[\'envform\'].elements[\'newp_setparmval\']'.
                   1891:             '.checked=true;"';
1.130     www      1892: 	$output.='<tr><td><i>'.&mt('Create New Environment Variable').'</i><br />'.
1.51      matthew  1893: 	    '<input type="text" size=40 name="newp_name" '.
                   1894:                 $onchange.' /></td><td>'.
                   1895:             '<input type="text" size=40 name="newp_value" '.
                   1896:                 $onchange.' /></td><td>'.
                   1897: 	    '<input type="checkbox" name="newp_setparmval" /></td></tr>';
1.43      albertel 1898:     }
1.157     sakharuk 1899:     my %lt=&Apache::lonlocal::texthash(
                   1900: 		    'par'   => 'Parameter',
                   1901: 		    'val'   => 'Value',
                   1902: 		    'set'   => 'Set',
                   1903: 		    'sce'   => 'Set Course Environment'
                   1904: 				       );
                   1905: 
1.140     sakharuk 1906:     my $Parameter=&mt('Parameter');
                   1907:     my $Value=&mt('Value');
1.141     sakharuk 1908:     my $Set=&mt('Set');
1.167     albertel 1909:     my $browse_js=&Apache::loncommon::browser_and_searcher_javascript('parmset');
1.183     albertel 1910:     my $html=&Apache::lonxml::xmlbegin();
1.190     albertel 1911:     $r->print(<<ENDenv);
1.183     albertel 1912: $html
                   1913: <head>
1.46      matthew  1914: <script type="text/javascript" language="Javascript" >
1.155     albertel 1915: $browse_js
1.46      matthew  1916: </script>
1.30      www      1917: <title>LON-CAPA Course Environment</title>
                   1918: </head>
1.64      www      1919: $bodytag
1.193     albertel 1920: $breadcrumbs
                   1921: <form method="post" action="/adm/parmset?action=crsenv" name="envform">
1.30      www      1922: $setoutput
                   1923: <p>
                   1924: <table border=2>
1.157     sakharuk 1925: <tr><th>$lt{'par'}</th><th>$lt{'val'}</th><th>$lt{'set'}?</th></tr>
1.30      www      1926: $output
                   1927: </table>
1.157     sakharuk 1928: <input type="submit" name="crsenv" value="$lt{'sce'}">
1.30      www      1929: </form>
                   1930: </body>
                   1931: </html>    
1.190     albertel 1932: ENDenv
1.30      www      1933: }
1.120     www      1934: ##################################################
1.207     www      1935: # Overview mode
                   1936: ##################################################
1.124     www      1937: my $tableopen;
                   1938: 
                   1939: sub tablestart {
                   1940:     if ($tableopen) {
                   1941: 	return '';
                   1942:     } else {
                   1943: 	$tableopen=1;
1.130     www      1944: 	return '<table border="2"><tr><th>'.&mt('Parameter').'</th><th>'.
                   1945: 	    &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
1.124     www      1946:     }
                   1947: }
                   1948: 
                   1949: sub tableend {
                   1950:     if ($tableopen) {
                   1951: 	$tableopen=0;
                   1952: 	return '</table>';
                   1953:     } else {
                   1954: 	return'';
                   1955:     }
                   1956: }
                   1957: 
1.207     www      1958: sub readdata {
                   1959:     my ($crs,$dom)=@_;
                   1960: # Read coursedata
                   1961:     my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
                   1962: # Read userdata
                   1963: 
                   1964:     my $classlist=&Apache::loncoursedata::get_classlist();
                   1965:     foreach (keys %$classlist) {
                   1966:         # the following undefs are for 'domain', and 'username' respectively.
                   1967:         if ($_=~/^(\w+)\:(\w+)$/) {
                   1968: 	    my ($tuname,$tudom)=($1,$2);
                   1969: 	    my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
                   1970:             foreach my $userkey (keys %{$useropt}) {
                   1971: 		if ($userkey=~/^$env{'request.course.id'}/) {
                   1972:                     my $newkey=$userkey;
                   1973: 		    $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
                   1974: 		    $$resourcedata{$newkey}=$$useropt{$userkey};
                   1975: 		}
                   1976: 	    }
                   1977: 	}
                   1978:     }
                   1979:     return $resourcedata;
                   1980: }
                   1981: 
                   1982: 
1.124     www      1983: # Setting
1.208     www      1984: 
                   1985: sub storedata {
                   1986:     my ($r,$crs,$dom)=@_;
1.207     www      1987: # Set userlevel immediately
                   1988: # Do an intermediate store of course level
                   1989:     my $olddata=&readdata($crs,$dom);
1.124     www      1990:     my %newdata=();
                   1991:     undef %newdata;
                   1992:     my @deldata=();
                   1993:     undef @deldata;
1.190     albertel 1994:     foreach (keys %env) {
1.124     www      1995: 	if ($_=~/^form\.([a-z]+)\_(.+)$/) {
                   1996: 	    my $cmd=$1;
                   1997: 	    my $thiskey=$2;
1.207     www      1998: 	    my ($tuname,$tudom)=&extractuser($thiskey);
                   1999: 	    my $tkey=$thiskey;
                   2000:             if ($tuname) {
                   2001: 		$tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
                   2002: 	    }
1.124     www      2003: 	    if ($cmd eq 'set') {
1.190     albertel 2004: 		my $data=$env{$_};
1.212     www      2005:                 my $typeof=$env{'form.typeof_'.$thiskey};
                   2006:  		if ($$olddata{$thiskey} ne $data) { 
1.207     www      2007: 		    if ($tuname) {
1.212     www      2008: 			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
                   2009: 								 $tkey.'.type' => $typeof},
                   2010: 						 $tudom,$tuname) eq 'ok') {
1.207     www      2011: 			    $r->print('<br />'.&mt('Stored modified parameter for').' '.
                   2012: 				      &Apache::loncommon::plainname($tuname,$tudom));
                   2013: 			} else {
                   2014: 			    $r->print('<h2><font color="red">'.
                   2015: 				      &mt('Error storing parameters').'</font></h2>');
                   2016: 			}
                   2017: 			&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
                   2018: 		    } else {
                   2019: 			$newdata{$thiskey}=$data;
1.212     www      2020:  			$newdata{$thiskey.'.type'}=$typeof; 
                   2021:                    } 
1.207     www      2022: 		}
1.124     www      2023: 	    } elsif ($cmd eq 'del') {
1.207     www      2024: 		if ($tuname) {
                   2025: 		    if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
                   2026: 			$r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
                   2027: 		    } else {
                   2028: 			$r->print('<h2><font color="red">'.
                   2029: 				  &mt('Error deleting parameters').'</font></h2>');
                   2030: 		    }
                   2031: 		    &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
                   2032: 		} else {
                   2033: 		    push (@deldata,$thiskey);
                   2034: 		}
1.124     www      2035: 	    } elsif ($cmd eq 'datepointer') {
1.190     albertel 2036: 		my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
1.212     www      2037:                 my $typeof=$env{'form.typeof_'.$thiskey};
1.207     www      2038: 		if (defined($data) and $$olddata{$thiskey} ne $data) { 
                   2039: 		    if ($tuname) {
1.212     www      2040: 			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
                   2041: 								 $tkey.'.type' => $typeof},
                   2042: 						 $tudom,$tuname) eq 'ok') {
1.207     www      2043: 			    $r->print('<br />'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
                   2044: 			} else {
                   2045: 			    $r->print('<h2><font color="red">'.
                   2046: 				      &mt('Error storing parameters').'</font></h2>');
                   2047: 			}
                   2048: 			&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
                   2049: 		    } else {
1.212     www      2050: 			$newdata{$thiskey}=$data;
                   2051: 			$newdata{$thiskey.'.type'}=$typeof; 
1.207     www      2052: 		    }
                   2053: 		}
1.124     www      2054: 	    }
                   2055: 	}
                   2056:     }
1.207     www      2057: # Store all course level
1.144     www      2058:     my $delentries=$#deldata+1;
                   2059:     my @newdatakeys=keys %newdata;
                   2060:     my $putentries=$#newdatakeys+1;
                   2061:     if ($delentries) {
                   2062: 	if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
                   2063: 	    $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
                   2064: 	} else {
                   2065: 	    $r->print('<h2><font color="red">'.
                   2066: 		      &mt('Error deleting parameters').'</font></h2>');
                   2067: 	}
1.205     www      2068: 	&Apache::lonnet::devalidatecourseresdata($crs,$dom);
1.144     www      2069:     }
                   2070:     if ($putentries) {
                   2071: 	if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
1.212     www      2072: 	    $r->print('<h3>'.&mt('Stored [_1] parameter(s)',$putentries/2).'</h3>');
1.144     www      2073: 	} else {
                   2074: 	    $r->print('<h2><font color="red">'.
                   2075: 		      &mt('Error storing parameters').'</font></h2>');
                   2076: 	}
1.205     www      2077: 	&Apache::lonnet::devalidatecourseresdata($crs,$dom);
1.144     www      2078:     }
1.208     www      2079: }
1.207     www      2080: 
1.208     www      2081: sub extractuser {
                   2082:     my $key=shift;
                   2083:     return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./);
                   2084: }
1.206     www      2085: 
1.208     www      2086: sub listdata {
1.214     www      2087:     my ($r,$resourcedata,$listdata,$sortorder)=@_;
1.207     www      2088: # Start list output
1.206     www      2089: 
1.122     www      2090:     my $oldsection='';
                   2091:     my $oldrealm='';
                   2092:     my $oldpart='';
1.123     www      2093:     my $pointer=0;
1.124     www      2094:     $tableopen=0;
1.145     www      2095:     my $foundkeys=0;
1.214     www      2096:     foreach my $thiskey (sort {
                   2097: 	if ($sortorder eq 'realmstudent') {
                   2098: 	    my ($astudent,$arealm)=($a=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/);
                   2099: 	    my ($bstudent,$brealm)=($b=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/);
                   2100:             ($arealm cmp $brealm) || ($astudent cmp $bstudent);
                   2101: 	} else {
                   2102: 	    $a cmp $b;
                   2103: 	}
                   2104:     } keys %{$listdata}) {
1.211     www      2105: 	if ($$listdata{$thiskey.'.type'}) {
                   2106:             my $thistype=$$listdata{$thiskey.'.type'};
                   2107:             if ($$resourcedata{$thiskey.'.type'}) {
                   2108: 		$thistype=$$resourcedata{$thiskey.'.type'};
                   2109: 	    }
1.207     www      2110: 	    my ($middle,$part,$name)=
                   2111: 		($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
1.130     www      2112: 	    my $section=&mt('All Students');
1.207     www      2113: 	    if ($middle=~/^\[(.*)\]/) {
1.206     www      2114: 		my $issection=$1;
                   2115: 		if ($issection=~/^useropt\:(\w+)\:(\w+)/) {
                   2116: 		    $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
                   2117: 		} else {
                   2118: 		    $section=&mt('Group/Section').': '.$issection;
                   2119: 		}
1.207     www      2120: 		$middle=~s/^\[(.*)\]//;
1.122     www      2121: 	    }
1.207     www      2122: 	    $middle=~s/\.+$//;
                   2123: 	    $middle=~s/^\.+//;
1.130     www      2124: 	    my $realm='<font color="red">'.&mt('All Resources').'</font>';
1.122     www      2125: 	    if ($middle=~/^(.+)\_\_\_\(all\)$/) {
1.174     albertel 2126: 		$realm='<font color="green">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><font color="#aaaaaa" size="-2">('.$1.')</font></font>';
1.122     www      2127: 	    } elsif ($middle) {
1.174     albertel 2128: 		my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
                   2129: 		$realm='<font color="orange">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><font color="#aaaaaa" size="-2">('.$url.' in '.$map.' id: '.$id.')</font></font>';
1.122     www      2130: 	    }
1.214     www      2131: 	    if ($sortorder eq 'realmstudent') {
                   2132: 		if ($realm ne $oldrealm) {
                   2133: 		    $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
                   2134: 		    $oldrealm=$realm;
                   2135: 		    $oldsection='';
                   2136: 		}
                   2137: 		if ($section ne $oldsection) {
                   2138: 		    $r->print(&tableend()."\n<h2>$section</h2>");
                   2139: 		    $oldsection=$section;
                   2140: 		    $oldpart='';
                   2141: 		}
                   2142: 	    } else {
                   2143: 		if ($section ne $oldsection) {
                   2144: 		    $r->print(&tableend()."\n<hr /><h1>$section</h1>");
                   2145: 		    $oldsection=$section;
                   2146: 		    $oldrealm='';
                   2147: 		}
                   2148: 		if ($realm ne $oldrealm) {
                   2149: 		    $r->print(&tableend()."\n<h2>$realm</h2>");
                   2150: 		    $oldrealm=$realm;
                   2151: 		    $oldpart='';
                   2152: 		}
1.122     www      2153: 	    }
                   2154: 	    if ($part ne $oldpart) {
1.124     www      2155: 		$r->print(&tableend().
1.214     www      2156: 			  "\n<font color='blue'>".&mt('Part').": $part</font>");
1.122     www      2157: 		$oldpart=$part;
                   2158: 	    }
1.123     www      2159: #
                   2160: # Ready to print
                   2161: #
1.124     www      2162: 	    $r->print(&tablestart().'<tr><td><b>'.$name.
                   2163: 		      ':</b></td><td><input type="checkbox" name="del_'.
                   2164: 		      $thiskey.'" /></td><td>');
1.145     www      2165: 	    $foundkeys++;
1.213     www      2166: 	    if (&isdateparm($thistype)) {
1.123     www      2167: 		my $jskey='key_'.$pointer;
                   2168: 		$pointer++;
                   2169: 		$r->print(
                   2170: 			  &Apache::lonhtmlcommon::date_setter('overviewform',
                   2171: 							      $jskey,
1.219     www      2172: 						      $$resourcedata{$thiskey},
                   2173: 							      '',1).
1.123     www      2174: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'
                   2175: 			  );
1.219     www      2176: 	    } elsif ($thistype eq 'string_yesno') {
                   2177: 		$r->print('<label><input type="radio" name="set_'.$thiskey.
                   2178: 			  '" value="yes"');
                   2179: 		if ($$resourcedata{$thiskey} eq 'yes') {
                   2180: 		    $r->print(' checked="checked"');
                   2181: 		}
                   2182:                 $r->print(' />'.&mt('Yes').'</label> ');
                   2183: 		$r->print('<label><input type="radio" name="set_'.$thiskey.
                   2184: 			  '" value="no"');
                   2185: 		if ($$resourcedata{$thiskey} eq 'no') {
                   2186: 		    $r->print(' checked="checked"');
                   2187: 		}
                   2188:                 $r->print(' />'.&mt('No').'</label>');
1.123     www      2189: 	    } else {
1.211     www      2190: 		$r->print('<input type="text" name="set_'.$thiskey.'" value="'.
1.206     www      2191: 			  $$resourcedata{$thiskey}.'">');
1.123     www      2192: 	    }
1.211     www      2193: 	    $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
                   2194: 		      $thistype.'">');
1.124     www      2195: 	    $r->print('</td></tr>');
1.122     www      2196: 	}
1.121     www      2197:     }
1.208     www      2198:     return $foundkeys;
                   2199: }
                   2200: 
                   2201: sub newoverview {
                   2202:     my $r=shift;
1.216     www      2203:     my $bodytag=&Apache::loncommon::bodytag('Set Parameters');
1.208     www      2204:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2205:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2206:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
                   2207:     my $html=&Apache::lonxml::xmlbegin();
                   2208:     $r->print(<<ENDOVER);
                   2209: $html
                   2210: <head>
                   2211: <title>LON-CAPA Parameters</title>
                   2212: </head>
                   2213: $bodytag
                   2214: $breadcrumbs
1.211     www      2215: <form method="post" action="/adm/parmset?action=newoverview" name="parmform">
1.208     www      2216: ENDOVER
1.211     www      2217:     my @ids=();
                   2218:     my %typep=();
                   2219:     my %keyp=();
                   2220:     my %allparms=();
                   2221:     my %allparts=();
                   2222:     my %allmaps=();
                   2223:     my %mapp=();
                   2224:     my %symbp=();
                   2225:     my %maptitles=();
                   2226:     my %uris=();
                   2227:     my %keyorder=&standardkeyorder();
                   2228:     my %defkeytype=();
                   2229: 
                   2230:     my %alllevs=();
                   2231:     $alllevs{'Resource Level'}='full';
1.215     www      2232:     $alllevs{'Map/Folder Level'}='map';
1.211     www      2233:     $alllevs{'Course Level'}='general';
                   2234: 
                   2235:     my $csec=$env{'form.csec'};
                   2236: 
                   2237:     my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
                   2238:     my $pschp=$env{'form.pschp'};
                   2239:     my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
                   2240:     if (!@psprt) { $psprt[0]='0'; }
                   2241: 
                   2242:     my @selected_sections = 
                   2243: 	&Apache::loncommon::get_env_multiple('form.Section');
                   2244:     @selected_sections = ('all') if (! @selected_sections);
                   2245:     foreach (@selected_sections) {
                   2246:         if ($_ eq 'all') {
                   2247:             @selected_sections = ('all');
                   2248:         }
                   2249:     }
                   2250: 
                   2251:     my $pssymb='';
                   2252:     my $parmlev='';
                   2253:  
                   2254:     unless ($env{'form.parmlev'}) {
                   2255:         $parmlev = 'map';
                   2256:     } else {
                   2257:         $parmlev = $env{'form.parmlev'};
                   2258:     }
                   2259: 
                   2260:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, 
                   2261: 				\%mapp, \%symbp,\%maptitles,\%uris,
                   2262: 				\%keyorder,\%defkeytype);
                   2263: 
                   2264: # Menu to select levels, etc
                   2265: 
                   2266:     $r->print('<table border="1"><tr><td>');
                   2267:     &levelmenu($r,\%alllevs,$parmlev);
                   2268:     if ($parmlev ne 'general') {
                   2269: 	$r->print('<td>');
                   2270: 	&mapmenu($r,\%allmaps,$pschp,\%maptitles);
                   2271: 	$r->print('</td>');
                   2272:     }
                   2273:     $r->print('</td></tr></table>');
                   2274: 
                   2275:     $r->print('<table border="1"><tr><td>');  
                   2276:     &parmmenu($r,\%allparms,\@pscat,\%keyorder);
                   2277:     $r->print('</td><td>');
                   2278:     &partmenu($r,\%allparts,\@psprt);
                   2279:     $r->print('</td><td>');
                   2280:     &sectionmenu($r,\@selected_sections);
1.214     www      2281: 
                   2282:     $r->print('</td></tr></table>');
                   2283:  
                   2284:     my $sortorder=$env{'form.sortorder'};
                   2285:     unless ($sortorder) { $sortorder='realmstudent'; }
                   2286:     &sortmenu($r,$sortorder);
                   2287: 
                   2288:     $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
1.211     www      2289: 
                   2290: # Build the list data hash from the specified parms
                   2291: 
                   2292:     my $listdata;
                   2293:     %{$listdata}=();
                   2294: 
                   2295:     foreach my $cat (@pscat) {
                   2296: 	foreach my $section (@selected_sections) {
                   2297: 	    foreach my $part (@psprt) {
1.212     www      2298:                 my $rootparmkey=$env{'request.course.id'};
1.211     www      2299:                 if (($section ne 'all') && ($section ne 'none') && ($section)) {
1.212     www      2300: 		    $rootparmkey.='.['.$section.']';
1.211     www      2301: 		}
                   2302: 		if ($parmlev eq 'general') {
                   2303: # course-level parameter
1.212     www      2304: 		    my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
                   2305: 		    $$listdata{$newparmkey}=1;
                   2306: 		    $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
1.211     www      2307: 		} elsif ($parmlev eq 'map') {
1.212     www      2308: # map-level parameter
                   2309: 		    foreach my $mapid (keys %allmaps) {
                   2310: 			if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
                   2311: 			my $newparmkey=$rootparmkey.'.'.$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
1.211     www      2312:                         $$listdata{$newparmkey}=1;
                   2313:                         $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
                   2314: 		    }
                   2315: 		} else {
                   2316: # resource-level parameter
1.212     www      2317: 		    foreach my $rid (@ids) {
                   2318: 			my ($map,$resid,$url)=&Apache::lonnet::decode_symb($symbp{$rid});
                   2319: 			if (($pschp ne 'all') && ($allmaps{$pschp} ne $map)) { next; }
                   2320: 			my $newparmkey=$rootparmkey.'.'.$symbp{$rid}.'.'.$part.'.'.$cat;
                   2321:                         $$listdata{$newparmkey}=1;
                   2322:                         $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
                   2323: 		    }
1.211     www      2324: 		}
                   2325: 	    }
                   2326: 	}
                   2327:     }
                   2328: 
1.212     www      2329:     if (($env{'form.store'}) || ($env{'form.dis'})) {
1.211     www      2330: 
1.212     www      2331: 	if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
1.211     www      2332: 
                   2333: # Read modified data
                   2334: 
                   2335: 	my $resourcedata=&readdata($crs,$dom);
                   2336: 
                   2337: # List data
                   2338: 
1.214     www      2339: 	&listdata($r,$resourcedata,$listdata,$sortorder);
1.211     www      2340:     }
                   2341:     $r->print(&tableend().
1.212     www      2342: 	     ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Store').'" /></p>':'').
                   2343: 	      '</form></body></html>');
1.208     www      2344: }
                   2345: 
                   2346: sub overview {
                   2347:     my $r=shift;
1.216     www      2348:     my $bodytag=&Apache::loncommon::bodytag('Modify Parameters');
1.208     www      2349:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2350:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2351:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
                   2352:     my $html=&Apache::lonxml::xmlbegin();
                   2353:     $r->print(<<ENDOVER);
                   2354: $html
                   2355: <head>
                   2356: <title>LON-CAPA Parameters</title>
                   2357: </head>
                   2358: $bodytag
                   2359: $breadcrumbs
                   2360: <form method="post" action="/adm/parmset?action=setoverview" name="overviewform">
                   2361: ENDOVER
                   2362: # Store modified
                   2363: 
                   2364:     &storedata($r,$crs,$dom);
                   2365: 
                   2366: # Read modified data
                   2367: 
                   2368:     my $resourcedata=&readdata($crs,$dom);
                   2369: 
1.214     www      2370: 
                   2371:     my $sortorder=$env{'form.sortorder'};
                   2372:     unless ($sortorder) { $sortorder='realmstudent'; }
                   2373:     &sortmenu($r,$sortorder);
                   2374: 
1.208     www      2375: # List data
                   2376: 
1.214     www      2377:     my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder);
1.208     www      2378: 
1.145     www      2379:     $r->print(&tableend().'<p>'.
1.208     www      2380: 	($foundkeys?'<input type="submit" value="'.&mt('Modify Parameters').'" />':&mt('There are no parameters.')).'</p></form></body></html>');
1.120     www      2381: }
1.121     www      2382: 
1.59      matthew  2383: ##################################################
                   2384: ##################################################
1.178     raeburn  2385:                                                                                             
                   2386: =pod
                   2387:                                                                                             
                   2388: =item change clone
                   2389:                                                                                             
                   2390: Modifies the list of courses a user can clone (stored
                   2391: in the user's environemnt.db file), called when a
                   2392: change is made to the list of users allowed to clone
                   2393: a course.
                   2394:                                                                                             
                   2395: Inputs: $action,$cloner
                   2396: where $action is add or drop, and $cloner is identity of 
                   2397: user for whom cloning ability is to be changed in course. 
                   2398:                                                                                             
                   2399: Returns: 
                   2400: 
                   2401: =cut
                   2402:                                                                                             
                   2403: ##################################################
                   2404: ##################################################
                   2405: 
                   2406: 
                   2407: sub change_clone {
                   2408:     my ($clonelist,$oldcloner) = @_;
                   2409:     my ($uname,$udom);
1.190     albertel 2410:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2411:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.178     raeburn  2412:     my $clone_crs = $cnum.':'.$cdom;
                   2413:     
                   2414:     if ($cnum && $cdom) {
                   2415:         my @allowclone = ();
                   2416:         if ($clonelist =~ /,/) {
                   2417:             @allowclone = split/,/,$clonelist;
                   2418:         } else {
                   2419:             $allowclone[0] = $clonelist;
                   2420:         }
                   2421:         foreach my $currclone (@allowclone) {
                   2422:             if (!grep/^$currclone$/,@$oldcloner) {
                   2423:                 ($uname,$udom) = split/:/,$currclone;
                   2424:                 if ($uname && $udom) {
                   2425:                     unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
                   2426:                         my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
                   2427:                         if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
                   2428:                             if ($currclonecrs{'cloneable'} eq '') {
                   2429:                                 $currclonecrs{'cloneable'} = $clone_crs;
                   2430:                             } else {
                   2431:                                 $currclonecrs{'cloneable'} .= ','.$clone_crs;
                   2432:                             }
                   2433:                             &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
                   2434:                         }
                   2435:                     }
                   2436:                 }
                   2437:             }
                   2438:         }
                   2439:         foreach my $oldclone (@$oldcloner) {
                   2440:             if (!grep/^$oldclone$/,@allowclone) {
                   2441:                 ($uname,$udom) = split/:/,$oldclone;
                   2442:                 if ($uname && $udom) {
                   2443:                     unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
                   2444:                         my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
                   2445:                         my %newclonecrs = ();
                   2446:                         if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
                   2447:                             if ($currclonecrs{'cloneable'} =~ /,/) {
                   2448:                                 my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
                   2449:                                 foreach (@currclonecrs) {
                   2450:                                     unless ($_ eq $clone_crs) {
                   2451:                                         $newclonecrs{'cloneable'} .= $_.',';
                   2452:                                     }
                   2453:                                 }
                   2454:                                 $newclonecrs{'cloneable'} =~ s/,$//;
                   2455:                             } else {
                   2456:                                 $newclonecrs{'cloneable'} = '';
                   2457:                             }
                   2458:                             &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
                   2459:                         }
                   2460:                     }
                   2461:                 }
                   2462:             }
                   2463:         }
                   2464:     }
                   2465: }
                   2466: 
1.193     albertel 2467: 
                   2468: ##################################################
                   2469: ##################################################
                   2470: 
                   2471: =pod
                   2472: 
                   2473: =item * header
                   2474: 
                   2475: Output html header for page
                   2476: 
                   2477: =cut
                   2478: 
                   2479: ##################################################
                   2480: ##################################################
                   2481: sub header {
                   2482:     my $html=&Apache::lonxml::xmlbegin();
                   2483:     my $bodytag=&Apache::loncommon::bodytag('Parameter Manager');
                   2484:     my $title = &mt('LON-CAPA Parameter Manager');
                   2485:     return(<<ENDHEAD);
                   2486: $html
                   2487: <head>
                   2488: <title>$title</title>
                   2489: </head>
                   2490: $bodytag
                   2491: ENDHEAD
                   2492: }
                   2493: ##################################################
                   2494: ##################################################
                   2495: sub print_main_menu {
                   2496:     my ($r,$parm_permission)=@_;
                   2497:     #
                   2498:     $r->print(<<ENDMAINFORMHEAD);
                   2499: <form method="post" enctype="multipart/form-data"
                   2500:       action="/adm/parmset" name="studentform">
                   2501: ENDMAINFORMHEAD
                   2502: #
1.195     albertel 2503:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2504:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.193     albertel 2505:     my @menu =
                   2506:         (
                   2507:           { text => 'Set Course Environment Parameters',
1.204     www      2508: 	    action => 'crsenv',
1.193     albertel 2509:             permission => $parm_permission,
                   2510:             },
1.216     www      2511:           { text => 'Set/Modify Resource Parameters - Helper Mode',
1.193     albertel 2512:             url => '/adm/helper/parameter.helper',
                   2513:             permission => $parm_permission,
                   2514:             },
1.216     www      2515:           { text => 'Modify Resource Parameters - Overview Mode',
1.193     albertel 2516:             action => 'setoverview',
                   2517:             permission => $parm_permission,
1.208     www      2518:             },          
1.216     www      2519: 	  { text => 'Set Resource Parameters - Overview Mode',
1.208     www      2520:             action => 'newoverview',
                   2521:             permission => $parm_permission,
1.193     albertel 2522:             },
1.216     www      2523:           { text => 'Set/Modify Resource Parameters - Table Mode',
1.193     albertel 2524:             action => 'settable',
                   2525:             permission => $parm_permission,
1.204     www      2526:             help => 'Cascading_Parameters',
1.193     albertel 2527:             },
1.220     www      2528:           { text => 'Set Parameter Setting Default Actions',
                   2529:             action => 'setdefaults',
                   2530:             permission => $parm_permission,
                   2531:             },
1.193     albertel 2532:           );
                   2533:     my $menu_html = '';
                   2534:     foreach my $menu_item (@menu) {
                   2535:         next if (! $menu_item->{'permission'});
                   2536:         $menu_html.='<p>';
                   2537:         $menu_html.='<font size="+1">';
                   2538:         if (exists($menu_item->{'url'})) {
                   2539:             $menu_html.=qq{<a href="$menu_item->{'url'}">};
                   2540:         } else {
                   2541:             $menu_html.=
                   2542:                 qq{<a href="/adm/parmset?action=$menu_item->{'action'}">};
                   2543:         }
                   2544:         $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
                   2545:         if (exists($menu_item->{'help'})) {
                   2546:             $menu_html.=
                   2547:                 &Apache::loncommon::help_open_topic($menu_item->{'help'});
                   2548:         }
                   2549:         $menu_html.='</p>'.$/;
                   2550:     }
                   2551:     $r->print($menu_html);
                   2552:     return;
                   2553: }
                   2554: 
                   2555: 
1.220     www      2556: ##################################################
1.193     albertel 2557: 
1.220     www      2558: sub defaultsetter {
                   2559:     my $r=shift;
                   2560:     my $bodytag=&Apache::loncommon::bodytag('Parameter Setting Default Actions');
                   2561:     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   2562:     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
                   2563:     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Defaults');
                   2564:     my $html=&Apache::lonxml::xmlbegin();
                   2565:     $r->print(<<ENDDEFHEAD);
                   2566: $html
                   2567: <head>
                   2568: <title>LON-CAPA Parameters</title>
                   2569: </head>
                   2570: $bodytag
                   2571: $breadcrumbs
                   2572: <form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">
                   2573: ENDDEFHEAD
                   2574:     if ($env{'form.storerules'}) {
1.222     www      2575: # storage here
1.221     www      2576: 	&resetrulescache();
1.220     www      2577:     }
1.221     www      2578:     my @ids=();
                   2579:     my %typep=();
                   2580:     my %keyp=();
                   2581:     my %allparms=();
                   2582:     my %allparts=();
                   2583:     my %allmaps=();
                   2584:     my %mapp=();
                   2585:     my %symbp=();
                   2586:     my %maptitles=();
                   2587:     my %uris=();
                   2588:     my %keyorder=&standardkeyorder();
                   2589:     my %defkeytype=();
                   2590: 
                   2591:     &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps, 
                   2592: 				\%mapp, \%symbp,\%maptitles,\%uris,
                   2593: 				\%keyorder,\%defkeytype);
                   2594:     my %lt=&Apache::lonlocal::texthash('hours' => 'Hours',
                   2595: 				       'min' => 'Minutes',
                   2596: 				       'sec' => 'Seconds',
                   2597: 				       'yes' => 'Yes',
                   2598: 				       'no' => 'No');
1.222     www      2599:     my @standardoptions=('','default');
                   2600:     my @standarddisplay=('',&mt('Default value when manually setting'));
                   2601:     my @dateoptions=('','default');
                   2602:     my @datedisplay=('',&mt('Default value when manually setting'));
                   2603:     foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
                   2604: 	unless ($tempkey) { next; }
                   2605: 	push @standardoptions,'when_setting_'.$tempkey;
                   2606: 	push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
                   2607: 	if (&isdateparm($defkeytype{$tempkey})) {
                   2608: 	    push @dateoptions,'later_than_'.$tempkey;
                   2609: 	    push @datedisplay,&mt('Automatically set later than ').$tempkey;
                   2610: 	    push @dateoptions,'earlier_than_'.$tempkey;
                   2611: 	    push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
                   2612: 	} 
                   2613:     }
1.221     www      2614:     $r->print("\n<table border='1'><tr><th>".&mt('Rule for parameter').'</th><th>'.
1.222     www      2615: 	      &mt('Action').'</th><th>'.&mt('Value').'</th></tr>');
1.221     www      2616:     foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
1.222     www      2617: 	unless ($tempkey) { next; }
1.221     www      2618: 	$r->print("\n<tr><td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
1.222     www      2619: 
                   2620: 	my $action=&rulescache($tempkey.'_action');
                   2621: 	$r->print('<select name="'.$tempkey.'_action">');
                   2622: 	if (&isdateparm($defkeytype{$tempkey})) {
                   2623: 	    for (my $i=0;$i<=$#dateoptions;$i++) {
                   2624: 		if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
                   2625: 		$r->print("\n<option value='$dateoptions[$i]'".
                   2626: 			  ($dateoptions[$i] eq $action?' selected="selected"':'').
                   2627: 			  ">$datedisplay[$i]</option>");
                   2628: 	    }
                   2629: 	} else {
                   2630: 	    for (my $i=0;$i<=$#standardoptions;$i++) {
                   2631: 		if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
                   2632: 		$r->print("\n<option value='$standardoptions[$i]'".
                   2633: 			  ($standardoptions[$i] eq $action?' selected="selected"':'').
                   2634: 			  ">$standarddisplay[$i]</option>");
                   2635: 	    }
                   2636: 	}
                   2637: 	$r->print('</select>');
                   2638: 
                   2639: 
                   2640: 	$r->print("\n</td><td>\n");
                   2641: 
1.221     www      2642:         if (&isdateparm($defkeytype{$tempkey})) {
1.222     www      2643: 	    my $hours=&rulescache($tempkey.'_hours');
                   2644: 	    my $min=&rulescache($tempkey.'_min');
                   2645: 	    my $sec=&rulescache($tempkey.'_sec');
1.221     www      2646: 	    $r->print(<<ENDINPUTDATE);
1.222     www      2647: <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
                   2648: <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
                   2649: <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
1.221     www      2650: ENDINPUTDATE
                   2651: 	} elsif ($defkeytype{$tempkey} eq 'string_yesno') {
1.222     www      2652:             my $yeschecked='';
                   2653:             my $nochecked='';
                   2654:             if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked='checked="checked"'; }
                   2655:             if (&rulescache($tempkey.'_value') eq 'no') { $nochecked='checked="checked"'; }
                   2656: 
1.221     www      2657: 	    $r->print(<<ENDYESNO);
1.222     www      2658: <label><input type="radio" name="$tempkey" value="yes" $yeschecked /> $lt{'yes'}</label><br />
                   2659: <label><input type="radio" name="$tempkey" value="no" $nochecked /> $lt{'no'}</label>
1.221     www      2660: ENDYESNO
                   2661:         } else {
1.222     www      2662: 	    $r->print('<input type="text" size="20" name="'.$tempkey.'" value="'.&rulescache($tempkey.'_value').'" />');
1.221     www      2663: 	}
                   2664:         $r->print('</td></tr>');
                   2665:     }
                   2666:     $r->print("</table></form></body></html>");
1.220     www      2667:     return;
                   2668: }
1.193     albertel 2669: 
1.178     raeburn  2670: ##################################################
                   2671: ##################################################
1.30      www      2672: 
1.59      matthew  2673: =pod
                   2674: 
1.83      bowersj2 2675: =item * handler
1.59      matthew  2676: 
                   2677: Main handler.  Calls &assessparms and &crsenv subroutines.
                   2678: 
                   2679: =cut
                   2680: ##################################################
                   2681: ##################################################
1.220     www      2682: #    use Data::Dumper;
                   2683: 
1.30      www      2684: sub handler {
1.43      albertel 2685:     my $r=shift;
1.30      www      2686: 
1.43      albertel 2687:     if ($r->header_only) {
1.126     www      2688: 	&Apache::loncommon::content_type($r,'text/html');
1.43      albertel 2689: 	$r->send_http_header;
                   2690: 	return OK;
                   2691:     }
1.193     albertel 2692:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.205     www      2693: 					    ['action','state',
                   2694:                                              'pres_marker',
                   2695:                                              'pres_value',
1.206     www      2696:                                              'pres_type',
1.215     www      2697:                                              'udom','uname','symb']);
1.131     www      2698: 
1.83      bowersj2 2699: 
1.193     albertel 2700:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.194     albertel 2701:     &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
                   2702: 					    text=>"Parameter Manager",
1.204     www      2703: 					    faq=>10,
1.194     albertel 2704: 					    bug=>'Instructor Interface'});
1.203     www      2705: 
1.30      www      2706: # ----------------------------------------------------- Needs to be in a course
1.194     albertel 2707:     my $parm_permission =
                   2708: 	(&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
1.190     albertel 2709: 	 &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
1.193     albertel 2710: 				  $env{'request.course.sec'}));
1.194     albertel 2711:     if ($env{'request.course.id'} &&  $parm_permission) {
1.193     albertel 2712: 
                   2713:         # Start Page
1.126     www      2714:         &Apache::loncommon::content_type($r,'text/html');
1.106     www      2715:         $r->send_http_header;
1.30      www      2716: 
1.203     www      2717: 
                   2718:         # id numbers can change on re-ordering of folders
                   2719: 
                   2720:         &resetsymbcache();
                   2721: 
1.193     albertel 2722:         #
                   2723:         # Main switch on form.action and form.state, as appropriate
                   2724:         #
                   2725:         # Check first if coming from someone else headed directly for
                   2726:         #  the table mode
                   2727:         if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
                   2728: 	     && (!$env{'form.dis'})) || ($env{'form.symb'})) {
                   2729: 	    &assessparms($r);
                   2730: 
                   2731:         } elsif (! exists($env{'form.action'})) {
                   2732:             $r->print(&header());
1.194     albertel 2733:             $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
                   2734: 							 'Parameter Manager'));
1.193     albertel 2735:             &print_main_menu($r,$parm_permission);
                   2736:         } elsif ($env{'form.action'} eq 'crsenv' && $parm_permission) {
1.194     albertel 2737:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=crsenv',
                   2738: 						    text=>"Course Environment"});
1.193     albertel 2739:             &crsenv($r); 
                   2740:         } elsif ($env{'form.action'} eq 'setoverview' && $parm_permission) {
1.194     albertel 2741:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
                   2742: 						    text=>"Overview Mode"});
1.121     www      2743: 	    &overview($r);
1.208     www      2744:         } elsif ($env{'form.action'} eq 'newoverview' && $parm_permission) {
                   2745:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
                   2746: 						    text=>"Overview Mode"});
                   2747: 	    &newoverview($r);
1.220     www      2748:         }  elsif ($env{'form.action'} eq 'setdefaults' && $parm_permission) {
                   2749:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
                   2750: 						    text=>"Set Defaults"});
                   2751: 	    &defaultsetter($r);
                   2752: 	} elsif ($env{'form.action'} eq 'settable' && $parm_permission) {
1.194     albertel 2753:             &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
1.204     www      2754: 						    text=>"Table Mode",
                   2755: 						    help => 'Course_Setting_Parameters'});
1.121     www      2756: 	    &assessparms($r);
1.193     albertel 2757:         }
                   2758:         
1.43      albertel 2759:     } else {
1.1       www      2760: # ----------------------------- Not in a course, or not allowed to modify parms
1.190     albertel 2761: 	$env{'user.error.msg'}=
1.43      albertel 2762: 	    "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
                   2763: 	return HTTP_NOT_ACCEPTABLE;
                   2764:     }
                   2765:     return OK;
1.1       www      2766: }
                   2767: 
                   2768: 1;
                   2769: __END__
                   2770: 
1.59      matthew  2771: =pod
1.38      harris41 2772: 
                   2773: =back
                   2774: 
                   2775: =cut
1.1       www      2776: 
                   2777: 
                   2778: 

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