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