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