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