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