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