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