1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
4: # $Id: lonparmset.pm,v 1.200 2005/06/02 16:35:32 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###################################################################
29: ###################################################################
30:
31: =pod
32:
33: =head1 NAME
34:
35: lonparmset - Handler to set parameters for assessments and course
36:
37: =head1 SYNOPSIS
38:
39: lonparmset provides an interface to setting course parameters.
40:
41: =head1 DESCRIPTION
42:
43: This module sets coursewide and assessment parameters.
44:
45: =head1 INTERNAL SUBROUTINES
46:
47: =over 4
48:
49: =cut
50:
51: ###################################################################
52: ###################################################################
53:
54: package Apache::lonparmset;
55:
56: use strict;
57: use Apache::lonnet;
58: use Apache::Constants qw(:common :http REDIRECT);
59: use Apache::lonhtmlcommon();
60: use Apache::loncommon;
61: use GDBM_File;
62: use Apache::lonhomework;
63: use Apache::lonxml;
64: use Apache::lonlocal;
65: use Apache::lonnavmaps;
66:
67: # --- Caches local to lonparmset
68:
69: my $parmhashid;
70: my %parmhash;
71:
72: # --- end local caches
73:
74: #
75: # FIXME: get rid of items below
76: #
77: my @ids;
78: my %symbp;
79: my %mapp;
80: my %typep;
81: my %keyp;
82: my %uris;
83: my %maptitles;
84:
85: ##################################################
86: ##################################################
87:
88: =pod
89:
90: =item parmval
91:
92: Figure out a cascading parameter.
93:
94: Inputs: $what - a parameter spec (incluse part info and name I.E. 0.weight)
95: $id - a bighash Id number
96: $def - the resource's default value 'stupid emacs
97:
98: 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
99:
100: 11 - General Course
101: 10 - Map or Folder level in course
102: 9- resource default
103: 8- map default
104: 7 - resource level in course
105: 6 - General for section
106: 5 - Map or Folder level for section
107: 4 - resource level in section
108: 3 - General for specific student
109: 2 - Map or Folder level for specific student
110: 1 - resource level for specific student
111:
112: =cut
113:
114: ##################################################
115: ##################################################
116: sub parmval {
117: my ($what,$id,$def,$uname,$udom,$csec)=@_;
118: # load caches
119:
120: &cacheparmhash();
121:
122: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
123: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
124: my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
125: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
126:
127:
128: my $result='';
129: my @outpar=();
130: # ----------------------------------------------------- Cascading lookup scheme
131:
132: my $symbparm=$symbp{$id}.'.'.$what;
133: my $mapparm=$mapp{$id}.'___(all).'.$what;
134:
135: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
136: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
137: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
138:
139: my $courselevel=$env{'request.course.id'}.'.'.$what;
140: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
141: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
142:
143:
144:
145: # --------------------------------------------------------- first, check course
146:
147: if (defined($$courseopt{$courselevel})) {
148: $outpar[11]=$$courseopt{$courselevel};
149: $result=11;
150: }
151:
152: if (defined($$courseopt{$courselevelm})) {
153: $outpar[10]=$$courseopt{$courselevelm};
154: $result=10;
155: }
156:
157: # ------------------------------------------------------- second, check default
158:
159: if (defined($def)) { $outpar[9]=$def; $result=9; }
160:
161: # ------------------------------------------------------ third, check map parms
162:
163: my $thisparm=$parmhash{$symbparm};
164: if (defined($thisparm)) { $outpar[8]=$thisparm; $result=8; }
165:
166: if (defined($$courseopt{$courselevelr})) {
167: $outpar[7]=$$courseopt{$courselevelr};
168: $result=7;
169: }
170:
171: # ------------------------------------------------------ fourth, back to course
172: if (defined($csec)) {
173: if (defined($$courseopt{$seclevel})) {
174: $outpar[6]=$$courseopt{$seclevel};
175: $result=6;
176: }
177: if (defined($$courseopt{$seclevelm})) {
178: $outpar[5]=$$courseopt{$seclevelm};
179: $result=5;
180: }
181:
182: if (defined($$courseopt{$seclevelr})) {
183: $outpar[4]=$$courseopt
184: {$seclevelr};
185: $result=4;
186: }
187: }
188:
189: # ---------------------------------------------------------- fifth, check user
190:
191: if (defined($uname)) {
192: if (defined($$useropt{$courselevel})) {
193: $outpar[3]=$$useropt{$courselevel};
194: $result=3;
195: }
196:
197: if (defined($$useropt{$courselevelm})) {
198: $outpar[2]=$$useropt{$courselevelm};
199: $result=2;
200: }
201:
202: if (defined($$useropt{$courselevelr})) {
203: $outpar[1]=$$useropt{$courselevelr};
204: $result=1;
205: }
206: }
207: return ($result,@outpar);
208: }
209:
210: sub resetparmhash {
211: $parmhashid='';
212: }
213:
214: sub cacheparmhash {
215: if ($parmhashid eq $env{'request.course.fn'}) { return; }
216: my %parmhashfile;
217: if (tie(%parmhashfile,'GDBM_File',
218: $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
219: %parmhash=%parmhashfile;
220: untie %parmhashfile;
221: $parmhashid=$env{'request.course.fn'};
222: }
223: }
224:
225: ##################################################
226: ##################################################
227: #
228: # Store a parameter by ID
229: #
230: # Takes
231: # - resource id
232: # - name of parameter
233: # - level
234: # - new value
235: # - new type
236: # - username
237: # - userdomain
238:
239: sub storeparm {
240: my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
241: my $navmap = Apache::lonnavmaps::navmap->new();
242: if ($sresid=~/\./) {
243: my $resource=$navmap->getById($sresid);
244: &storeparm_by_symb($resource->symb(),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
245: } else {
246: my $resource=$navmap->getByMapPc($sresid);
247: &storeparm_by_symb(&Apache::lonnet::declutter($resource->src()),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
248: }
249: }
250:
251: #
252: # Store a parameter by symb
253: #
254: # Takes
255: # - symb
256: # - name of parameter
257: # - level
258: # - new value
259: # - new type
260: # - username
261: # - userdomain
262:
263: sub storeparm_by_symb {
264: # ---------------------------------------------------------- Get symb, map, etc
265: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
266: # ---------------------------------------------------------- Construct prefixes
267: $spnam=~s/\_([^\_]+)$/\.$1/;
268: my $map=(&Apache::lonnet::decode_symb($symb))[0];
269: my $symbparm=$symb.'.'.$spnam;
270: my $mapparm=$map.'___(all).'.$spnam;
271:
272: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
273: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
274: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
275:
276: my $courselevel=$env{'request.course.id'}.'.'.$spnam;
277: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
278: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
279:
280: my $storeunder='';
281: if (($snum==11) || ($snum==3)) { $storeunder=$courselevel; }
282: if (($snum==10) || ($snum==2)) { $storeunder=$courselevelm; }
283: if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
284: if ($snum==6) { $storeunder=$seclevel; }
285: if ($snum==5) { $storeunder=$seclevelm; }
286: if ($snum==4) { $storeunder=$seclevelr; }
287:
288: my $delete;
289: if ($nval eq '') { $delete=1;}
290: my %storecontent = ($storeunder => $nval,
291: $storeunder.'.type' => $ntype);
292: my $reply='';
293: if ($snum>3) {
294: # ---------------------------------------------------------------- Store Course
295: #
296: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
297: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
298: # Expire sheets
299: &Apache::lonnet::expirespread('','','studentcalc');
300: if (($snum==7) || ($snum==4)) {
301: &Apache::lonnet::expirespread('','','assesscalc',$symb);
302: } elsif (($snum==8) || ($snum==5)) {
303: &Apache::lonnet::expirespread('','','assesscalc',$map);
304: } else {
305: &Apache::lonnet::expirespread('','','assesscalc');
306: }
307: # Store parameter
308: if ($delete) {
309: $reply=&Apache::lonnet::del
310: ('resourcedata',[keys(%storecontent)],$cdom,$cnum);
311: } else {
312: $reply=&Apache::lonnet::cput
313: ('resourcedata',\%storecontent,$cdom,$cnum);
314: }
315: &Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
316: } else {
317: # ------------------------------------------------------------------ Store User
318: #
319: # Expire sheets
320: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
321: if ($snum==1) {
322: &Apache::lonnet::expirespread
323: ($uname,$udom,'assesscalc',$symb);
324: } elsif ($snum==2) {
325: &Apache::lonnet::expirespread
326: ($uname,$udom,'assesscalc',$map);
327: } else {
328: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
329: }
330: # Store parameter
331: if ($delete) {
332: $reply=&Apache::lonnet::del
333: ('resourcedata',[keys(%storecontent)],$udom,$uname);
334: } else {
335: $reply=&Apache::lonnet::cput
336: ('resourcedata',\%storecontent,$udom,$uname);
337: }
338: &Apache::lonnet::devalidateuserresdata($uname,$udom);
339: }
340:
341: if ($reply=~/^error\:(.*)/) {
342: return "<font color=red>Write Error: $1</font>";
343: }
344: return '';
345: }
346:
347: ##################################################
348: ##################################################
349:
350: =pod
351:
352: =item valout
353:
354: Format a value for output.
355:
356: Inputs: $value, $type
357:
358: Returns: $value, formatted for output. If $type indicates it is a date,
359: localtime($value) is returned.
360:
361: =cut
362:
363: ##################################################
364: ##################################################
365: sub valout {
366: my ($value,$type)=@_;
367: my $result = '';
368: # Values of zero are valid.
369: if (! $value && $value ne '0') {
370: $result = ' ';
371: } else {
372: if ($type eq 'date_interval') {
373: my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
374: $year=$year-70;
375: $mday--;
376: if ($year) {
377: $result.=$year.' yrs ';
378: }
379: if ($mon) {
380: $result.=$mon.' mths ';
381: }
382: if ($mday) {
383: $result.=$mday.' days ';
384: }
385: if ($hour) {
386: $result.=$hour.' hrs ';
387: }
388: if ($min) {
389: $result.=$min.' mins ';
390: }
391: if ($sec) {
392: $result.=$sec.' secs ';
393: }
394: $result=~s/\s+$//;
395: } elsif ($type=~/^date/) {
396: $result = localtime($value);
397: } else {
398: $result = $value;
399: }
400: }
401: return $result;
402: }
403:
404: ##################################################
405: ##################################################
406:
407: =pod
408:
409: =item plink
410:
411: Produces a link anchor.
412:
413: Inputs: $type,$dis,$value,$marker,$return,$call
414:
415: Returns: scalar with html code for a link which will envoke the
416: javascript function 'pjump'.
417:
418: =cut
419:
420: ##################################################
421: ##################################################
422: sub plink {
423: my ($type,$dis,$value,$marker,$return,$call)=@_;
424: my $winvalue=$value;
425: unless ($winvalue) {
426: if ($type=~/^date/) {
427: $winvalue=$env{'form.recent_'.$type};
428: } else {
429: $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
430: }
431: }
432: return
433: '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
434: .$marker."','".$return."','".$call."'".');">'.
435: &valout($value,$type).'</a><a name="'.$marker.'"></a>';
436: }
437:
438:
439: sub startpage {
440: my ($r,$id,$udom,$csec,$uname,$have_assesments,$trimheader)=@_;
441:
442: my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','',
443: 'onUnload="pclose()"');
444: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Table');
445: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
446: &Apache::loncommon::selectstudent_link('parmform','uname','udom');
447: my $selscript=&Apache::loncommon::studentbrowser_javascript();
448: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
449: my %lt=&Apache::lonlocal::texthash(
450: 'cep' => "Course Environment Parameters",
451: 'scep' => "Set Course Environment Parameters",
452: 'smcap' => "Set/Modify Course Assessment Parameter",
453: 'mcap' => "Modify Course Assessment Parameters",
454: 'caphm' => "Course Assessment Parameter - Helper Mode",
455: 'capom' => "Course Assessment Parameters - Overview Mode",
456: 'captm' => "Course Assessments Parameters - Table Mode",
457: 'sg' => "Section/Group",
458: 'fu' => "For User",
459: 'oi' => "or ID",
460: 'ad' => "at Domain"
461: );
462: my $overallhelp=
463: &Apache::loncommon::help_open_menu('','Setting Parameters','Course_Setting_Parameters','',10,'Instructor Interface');
464: my $assessparmhelp=&Apache::loncommon::help_open_topic("Cascading_Parameters","Assessment Parameters");
465: my $html=&Apache::lonxml::xmlbegin();
466: $r->print(<<ENDHEAD);
467: $html
468: <head>
469: <title>LON-CAPA Course Parameters</title>
470: <script>
471:
472: function pclose() {
473: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
474: "height=350,width=350,scrollbars=no,menubar=no");
475: parmwin.close();
476: }
477:
478: $pjump_def
479:
480: function psub() {
481: pclose();
482: if (document.parmform.pres_marker.value!='') {
483: document.parmform.action+='#'+document.parmform.pres_marker.value;
484: var typedef=new Array();
485: typedef=document.parmform.pres_type.value.split('_');
486: if (document.parmform.pres_type.value!='') {
487: if (typedef[0]=='date') {
488: eval('document.parmform.recent_'+
489: document.parmform.pres_type.value+
490: '.value=document.parmform.pres_value.value;');
491: } else {
492: eval('document.parmform.recent_'+typedef[0]+
493: '.value=document.parmform.pres_value.value;');
494: }
495: }
496: document.parmform.submit();
497: } else {
498: document.parmform.pres_value.value='';
499: document.parmform.pres_marker.value='';
500: }
501: }
502:
503: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
504: var options = "width=" + w + ",height=" + h + ",";
505: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
506: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
507: var newWin = window.open(url, wdwName, options);
508: newWin.focus();
509: }
510: </script>
511: $selscript
512: </head>
513: $bodytag
514: $breadcrumbs
515: $overallhelp
516: ENDHEAD
517:
518: unless ($trimheader) {$r->print(<<ENDHEAD2);
519: <form method="post" action="/adm/parmset" name="envform">
520: <h4>$lt{'cep'}</h4>
521: <input type="submit" name="crsenv" value="$lt{'scep'}" />
522: </form>
523: <hr />
524: $assessparmhelp
525: <form method="post" action="/adm/helper/parameter.helper" name="helpform">
526: <h4>$lt{'caphm'}</h4>
527: <input type="submit" value="$lt{'smcap'}" />
528: </form>
529: <hr />
530: <form method="post" action="/adm/parmset" name="overview">
531: <h4>$lt{'capom'}</h4>
532: <input type="submit" name="overview" value="$lt{'mcap'}" />
533: </form>
534: <hr />
535: ENDHEAD2
536: }
537: my %sectionhash=();
538: my $sections='';
539: if (&Apache::loncommon::get_sections(
540: $env{'course.'.$env{'request.course.id'}.'.domain'},
541: $env{'course.'.$env{'request.course.id'}.'.num'},
542: \%sectionhash)) {
543: $sections=$lt{'sg'}.': <select name="csec">';
544: foreach ('',sort keys %sectionhash) {
545: $sections.='<option value="'.$_.'"'.
546: ($_ eq $csec?'selected="selected"':'').'>'.$_.'</option>';
547: }
548: $sections.='</select>';
549: }
550: $r->print(<<ENDHEAD3);
551: <form method="post" action="/adm/parmset?action=settable" name="parmform">
552: <h4>$lt{'captm'}</h4>
553: ENDHEAD3
554:
555: if (!$have_assesments) {
556: $r->print('<font color="red">'.&mt('There are no assesment parameters in this course to set.').'</font><br />');
557: } else {
558: $r->print(<<ENDHEAD);
559: <b>
560: $sections
561: <br />
562: $lt{'fu'}
563: <input type="text" value="$uname" size="12" name="uname" />
564: $lt{'oi'}
565: <input type="text" value="$id" size="12" name="id" />
566: $lt{'ad'}
567: $chooseopt
568: </b>
569: <input type="hidden" value='' name="pres_value">
570: <input type="hidden" value='' name="pres_type">
571: <input type="hidden" value='' name="pres_marker">
572: ENDHEAD
573: }
574: }
575:
576: sub print_row {
577: my ($r,$which,$part,$name,$rid,$default,$defaulttype,$display,$defbgone,
578: $defbgtwo,$parmlev,$uname,$udom,$csec)=@_;
579: # get the values for the parameter in cascading order
580: # empty levels will remain empty
581: my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
582: $rid,$$default{$which},$uname,$udom,$csec);
583: # get the type for the parameters
584: # problem: these may not be set for all levels
585: my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
586: $$name{$which}.'.type',
587: $rid,$$defaulttype{$which},$uname,$udom,$csec);
588: # cascade down manually
589: my $cascadetype=$$defaulttype{$which};
590: for (my $i=11;$i>0;$i--) {
591: if ($typeoutpar[$i]) {
592: $cascadetype=$typeoutpar[$i];
593: } else {
594: $typeoutpar[$i]=$cascadetype;
595: }
596: }
597: my $parm=$$display{$which};
598:
599: if ($parmlev eq 'full' || $parmlev eq 'brief') {
600: $r->print('<td bgcolor='.$defbgtwo.' align="center">'
601: .$$part{$which}.'</td>');
602: } else {
603: $parm=~s|\[.*\]\s||g;
604: }
605:
606: $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
607:
608: my $thismarker=$which;
609: $thismarker=~s/^parameter\_//;
610: my $mprefix=$rid.'&'.$thismarker.'&';
611:
612: if ($parmlev eq 'general') {
613:
614: if ($uname) {
615: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
616: } elsif ($csec) {
617: &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
618: } else {
619: &print_td($r,11,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
620: }
621: } elsif ($parmlev eq 'map') {
622:
623: if ($uname) {
624: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
625: } elsif ($csec) {
626: &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
627: } else {
628: &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
629: }
630: } else {
631:
632: &print_td($r,11,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
633:
634: if ($parmlev eq 'brief') {
635:
636: &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
637:
638: if ($csec) {
639: &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
640: }
641: if ($uname) {
642: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
643: }
644: } else {
645:
646: &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
647: &print_td($r,9,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
648: &print_td($r,8,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
649: &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
650:
651: if ($csec) {
652: &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
653: &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
654: &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
655: }
656: if ($uname) {
657: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
658: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
659: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
660: }
661: } # end of $brief if/else
662: } # end of $parmlev if/else
663:
664: $r->print('<td bgcolor=#CCCCFF align="center">'.
665: &valout($outpar[$result],$typeoutpar[$result]).'</td>');
666:
667: if ($parmlev eq 'full' || $parmlev eq 'brief') {
668: my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
669: '.'.$$name{$which},$symbp{$rid});
670:
671: # this doesn't seem to work, and I don't think is correct
672: # my $sessionvaltype=&Apache::lonnet::EXT('resource.'.$$part{$which}.
673: # '.'.$$name{$which}.'.type',$symbp{$rid});
674: # this seems to work
675: my $sessionvaltype=$typeoutpar[$result];
676: if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
677: $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
678: &valout($sessionval,$sessionvaltype).' '.
679: '</font></td>');
680: }
681: $r->print('</tr>');
682: $r->print("\n");
683: }
684:
685: sub print_td {
686: my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
687: $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
688: ' align="center">');
689: if ($which<8 || $which > 9) {
690: $r->print(&plink($$typeoutpar[$which],
691: $$display{$value},$$outpar[$which],
692: $mprefix."$which",'parmform.pres','psub'));
693: } else {
694: $r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
695: }
696: $r->print('</td>'."\n");
697: }
698:
699: =pod
700:
701: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
702:
703: Input: See list below:
704:
705: =over 4
706:
707: =item B<ids>: An array that will contain all of the ids in the course.
708:
709: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
710:
711: =item B<keyp>: hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
712:
713: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
714:
715: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
716:
717: =item B<allkeys>: hash, full key to part->display value (what's display value?)
718:
719: =item B<allmaps>: hash, ???
720:
721: =item B<fcat>: ???
722:
723: =item B<defp>: hash, ???
724:
725: =item B<mapp>: ??
726:
727: =item B<symbp>: hash, id->full sym?
728:
729: =back
730:
731: =cut
732:
733: sub extractResourceInformation {
734: my $ids = shift;
735: my $typep = shift;
736: my $keyp = shift;
737: my $allparms = shift;
738: my $allparts = shift;
739: my $allkeys = shift;
740: my $allmaps = shift;
741: my $fcat = shift;
742: my $defp = shift;
743: my $mapp = shift;
744: my $symbp = shift;
745: my $maptitles=shift;
746: my $uris=shift;
747:
748:
749: my $navmap = Apache::lonnavmaps::navmap->new();
750: my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
751: foreach my $resource (@allres) {
752: my $id=$resource->id();
753: my ($mapid,$resid)=split(/\./,$id);
754: if ($mapid eq '0') { next; }
755: $$ids[$#$ids+1]=$id;
756: my $srcf=$resource->src();
757: $srcf=~/\.(\w+)$/;
758: $$typep{$id}=$1;
759: $$keyp{$id}='';
760: $$uris{$id}=$srcf;
761: foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
762: if ($_=~/^parameter\_(.*)/) {
763: my $key=$_;
764: my $allkey=$1;
765: $allkey=~s/\_/\./g;
766: if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq
767: 'parm') {
768: next; #hide hidden things
769: }
770: my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
771: my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
772: my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
773: my $parmdis = $display;
774: $parmdis =~ s|(\[Part.*)$||g;
775: my $partkey = $part;
776: $partkey =~ tr|_|.|;
777: $$allparms{$name} = $parmdis;
778: $$allparts{$part} = "[Part $part]";
779: $$allkeys{$allkey}=$display;
780: if ($allkey eq $fcat) {
781: $$defp{$id}= &Apache::lonnet::metadata($srcf,$key);
782: }
783: if ($$keyp{$id}) {
784: $$keyp{$id}.=','.$key;
785: } else {
786: $$keyp{$id}=$key;
787: }
788: }
789: }
790: $$mapp{$id}=
791: &Apache::lonnet::declutter($resource->enclosing_map_src());
792: $$mapp{$mapid}=$$mapp{$id};
793: $$allmaps{$mapid}=$$mapp{$id};
794: if ($mapid eq '1') {
795: $$maptitles{$mapid}='Main Course Documents';
796: } else {
797: $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));
798: }
799: $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
800: $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
801: $$symbp{$mapid}=$$mapp{$id}.'___(all)';
802: }
803: }
804:
805: ##################################################
806: ##################################################
807:
808: =pod
809:
810: =item assessparms
811:
812: Show assessment data and parameters. This is a large routine that should
813: be simplified and shortened... someday.
814:
815: Inputs: $r
816:
817: Returns: nothing
818:
819: Variables used (guessed by Jeremy):
820:
821: =over 4
822:
823: =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.
824:
825: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
826:
827: =item B<allmaps>:
828:
829: =back
830:
831: =cut
832:
833: ##################################################
834: ##################################################
835: sub assessparms {
836:
837: my $r=shift;
838: # -------------------------------------------------------- Variable declaration
839: my %allkeys=();
840: my %allmaps=();
841: my %alllevs=();
842:
843: my $uname;
844: my $udom;
845: my $uhome;
846: my $csec;
847:
848: my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
849:
850: $alllevs{'Resource Level'}='full';
851: $alllevs{'Map Level'}='map';
852: $alllevs{'Course Level'}='general';
853:
854: my %allparms;
855: my %allparts;
856:
857: my %defp;
858:
859: @ids=();
860: %symbp=();
861: %typep=();
862:
863: my $message='';
864:
865: $csec=$env{'form.csec'};
866:
867: if ($udom=$env{'form.udom'}) {
868: } elsif ($udom=$env{'request.role.domain'}) {
869: } elsif ($udom=$env{'user.domain'}) {
870: } else {
871: $udom=$r->dir_config('lonDefDomain');
872: }
873:
874: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
875: my $pschp=$env{'form.pschp'};
876: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
877: if (!@psprt) { $psprt[0]='0'; }
878: my $showoptions=$env{'form.showoptions'};
879:
880: my $pssymb='';
881: my $parmlev='';
882: my $trimheader='';
883: my $prevvisit=$env{'form.prevvisit'};
884:
885: unless ($env{'form.parmlev'}) {
886: $parmlev = 'map';
887: } else {
888: $parmlev = $env{'form.parmlev'};
889: }
890:
891: # ----------------------------------------------- Was this started from grades?
892:
893: if (($env{'form.command'} eq 'set') && ($env{'form.url'})
894: && (!$env{'form.dis'})) {
895: my $url=$env{'form.url'};
896: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
897: $pssymb=&Apache::lonnet::symbread($url);
898: if (!@pscat) { @pscat=('all'); }
899: $pschp='';
900: $parmlev = 'full';
901: $trimheader='yes';
902: } elsif ($env{'form.symb'}) {
903: $pssymb=$env{'form.symb'};
904: if (!@pscat) { @pscat=('all'); }
905: $pschp='';
906: $parmlev = 'full';
907: $trimheader='yes';
908: } else {
909: $env{'form.url'}='';
910: }
911:
912: my $id=$env{'form.id'};
913: if (($id) && ($udom)) {
914: $uname=(&Apache::lonnet::idget($udom,$id))[1];
915: if ($uname) {
916: $id='';
917: } else {
918: $message=
919: "<font color=red>".&mt("Unknown ID")." '$id' ".
920: &mt('at domain')." '$udom'</font>";
921: }
922: } else {
923: $uname=$env{'form.uname'};
924: }
925: unless ($udom) { $uname=''; }
926: $uhome='';
927: if ($uname) {
928: $uhome=&Apache::lonnet::homeserver($uname,$udom);
929: if ($uhome eq 'no_host') {
930: $message=
931: "<font color=red>".&mt("Unknown user")." '$uname' ".
932: &mt("at domain")." '$udom'</font>";
933: $uname='';
934: } else {
935: $csec=&Apache::lonnet::getsection($udom,$uname,
936: $env{'request.course.id'});
937: if ($csec eq '-1') {
938: $message="<font color=red>".
939: &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
940: &mt("not in this course")."</font>";
941: $uname='';
942: $csec=$env{'form.csec'};
943: } else {
944: my %name=&Apache::lonnet::userenvironment($udom,$uname,
945: ('firstname','middlename','lastname','generation','id'));
946: $message="\n<p>\n".&mt("Full Name").": ".
947: $name{'firstname'}.' '.$name{'middlename'}.' '
948: .$name{'lastname'}.' '.$name{'generation'}.
949: "<br>\n".&mt('ID').": ".$name{'id'}.'<p>';
950: }
951: }
952: }
953:
954: unless ($csec) { $csec=''; }
955:
956: my $fcat=$env{'form.fcat'};
957: unless ($fcat) { $fcat=''; }
958:
959: # --------------------------------------------------------- Get all assessments
960: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles,\%uris);
961:
962: $mapp{'0.0'} = '';
963: $symbp{'0.0'} = '';
964:
965: # ---------------------------------------------------------- Anything to store?
966: if ($env{'form.pres_marker'}) {
967: $message.=&storeparm(split(/\&/,$env{'form.pres_marker'}),
968: $env{'form.pres_value'},
969: $env{'form.pres_type'},
970: $uname,$udom,$csec);
971: # ---------------------------------------------------------------- Done storing
972: $message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
973: }
974: # ------------------------------------------------------------------- Sort this
975:
976: @ids=sort {
977: if ($fcat eq '') {
978: $a<=>$b;
979: } else {
980: my ($result,@outpar)=&parmval($fcat,$a,$defp{$a},$uname,$udom,$csec);
981: my $aparm=$outpar[$result];
982: ($result,@outpar)=&parmval($fcat,$b,$defp{$b},$uname,$udom,$csec);
983: my $bparm=$outpar[$result];
984: 1*$aparm<=>1*$bparm;
985: }
986: } @ids;
987: #----------------------------------------------- if all selected, fill in array
988: if ($pscat[0] eq "all" || !@pscat) {@pscat = (keys %allparms);}
989: if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
990: # ------------------------------------------------------------------ Start page
991:
992: my $have_assesments=1;
993: if (scalar(keys(%allkeys)) eq 0) { $have_assesments=0; }
994:
995: $trimheader = 'yes';
996: &startpage($r,$id,$udom,$csec,$uname,$have_assesments,$trimheader);
997:
998: # if ($env{'form.url'}) {
999: # $r->print('<input type="hidden" value="'.$env{'form.url'}.
1000: # '" name="url"><input type="hidden" name="command" value="set">');
1001: # }
1002: $r->print('<input type="hidden" value="true" name="prevvisit">');
1003:
1004: foreach ('tolerance','date_default','date_start','date_end',
1005: 'date_interval','int','float','string') {
1006: $r->print('<input type="hidden" value="'.
1007: $env{'form.recent_'.$_}.'" name="recent_'.$_.'">');
1008: }
1009:
1010: $r->print('<h2>'.$message.'</h2><table>');
1011:
1012: my $submitmessage = &mt('Update Section or Specific User');
1013: if (!$pssymb) {
1014: $r->print('<tr><td>'.&mt('Select Parameter Level').
1015: &Apache::loncommon::help_open_topic('Course_Parameter_Levels').
1016: '</td><td colspan="2">');
1017: $r->print('<select name="parmlev">');
1018: foreach (reverse sort keys %alllevs) {
1019: $r->print('<option value="'.$alllevs{$_}.'"');
1020: if ($parmlev eq $alllevs{$_}) {
1021: $r->print(' selected');
1022: }
1023: $r->print('>'.$_.'</option>');
1024: }
1025: $r->print("</select></td>\n");
1026:
1027: $r->print('</tr>');
1028: if ($parmlev ne 'general') {
1029: $r->print('<tr><td>'.&mt('Select Enclosing Map or Folder').'</td>');
1030: $r->print('<td colspan="2"><select name="pschp">');
1031: $r->print('<option value="all">'.&mt('All Maps or Folders').'</option>');
1032: foreach (sort {$allmaps{$a} cmp $allmaps{$b}} keys %allmaps) {
1033: $r->print('<option value="'.$_.'"');
1034: if (($pschp eq $_)) { $r->print(' selected'); }
1035: $r->print('>'.$maptitles{$_}.($allmaps{$_}!~/^uploaded/?' ['.$allmaps{$_}.']':'').'</option>');
1036: }
1037: $r->print("</select></td></tr>\n");
1038: }
1039: } else {
1040: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
1041: $r->print("<tr><td>".&mt('Specific Resource')."</td><td>$resource</td>");
1042: $r->print('<td><input type="submit" name="dis" value="'.$submitmessage.'"></td>');
1043: $r->print('</tr>');
1044: $r->print('<input type="hidden" value="'.$pssymb.'" name="symb">');
1045: }
1046:
1047: $r->print('<tr><td colspan="3"><hr /><label><input type="checkbox"');
1048: if ($showoptions eq 'show') {$r->print(" checked ");}
1049: $r->print(' name="showoptions" value="show" />'.&mt('Show More Options').'</label><hr /></td></tr>');
1050: # $r->print("<tr><td>Show: $showoptions</td></tr>");
1051: # $r->print("<tr><td>pscat: @pscat</td></tr>");
1052: # $r->print("<tr><td>psprt: @psprt</td></tr>");
1053: # $r->print("<tr><td>fcat: $fcat</td></tr>");
1054:
1055: if ($showoptions eq 'show') {
1056: my $tempkey;
1057:
1058: $r->print('<tr><td colspan="3" align="center">'.&mt('Select Parameters to View').'</td></tr>');
1059:
1060: $r->print('<tr><td colspan="2"><table><tr>');
1061: my $cnt=0;
1062: foreach $tempkey (sort { $allparms{$a} cmp $allparms{$b} }
1063: keys %allparms ) {
1064: ++$cnt;
1065: $r->print('</tr><tr>') if ($cnt%2);
1066: $r->print('<td><input type="checkbox" name="pscat" ');
1067: $r->print('value="'.$tempkey.'"');
1068: if ($pscat[0] eq "all" || grep $_ eq $tempkey, @pscat) {
1069: $r->print(' checked');
1070: }
1071: $r->print('>'.$allparms{$tempkey}.'</td>');
1072: }
1073: $r->print('
1074: </tr><tr><td>
1075: <script type="text/javascript">
1076: function checkall(value, checkName) {
1077: for (i=0; i<document.forms.parmform.elements.length; i++) {
1078: ele = document.forms.parmform.elements[i];
1079: if (ele.name == checkName) {
1080: document.forms.parmform.elements[i].checked=value;
1081: }
1082: }
1083: }
1084: </script>
1085: <input type="button" onclick="checkall(true, \'pscat\')" value="Select All" />
1086: </td><td>
1087: <input type="button" onclick="checkall(false, \'pscat\')" value="Unselect All" />
1088: </td>
1089: ');
1090: $r->print('</tr></table>');
1091:
1092: # $r->print('<tr><td>Select Parts</td><td>');
1093: $r->print('<td><select multiple name="psprt" size="5">');
1094: $r->print('<option value="all"');
1095: $r->print(' selected') unless (@psprt);
1096: $r->print('>'.&mt('All Parts').'</option>');
1097: my %temphash=();
1098: foreach (@psprt) { $temphash{$_}=1; }
1099: foreach $tempkey (sort keys %allparts) {
1100: unless ($tempkey =~ /\./) {
1101: $r->print('<option value="'.$tempkey.'"');
1102: if ($psprt[0] eq "all" || $temphash{$tempkey}) {
1103: $r->print(' selected');
1104: }
1105: $r->print('>'.$allparts{$tempkey}.'</option>');
1106: }
1107: }
1108: $r->print('</select></td></tr><tr><td colspan="3"><hr /></td></tr>');
1109:
1110: $r->print('<tr><td>'.&mt('Sort list by').'</td><td>');
1111: $r->print('<select name="fcat">');
1112: $r->print('<option value="">'.&mt('Enclosing Map or Folder').'</option>');
1113: foreach (sort keys %allkeys) {
1114: $r->print('<option value="'.$_.'"');
1115: if ($fcat eq $_) { $r->print(' selected'); }
1116: $r->print('>'.$allkeys{$_}.'</option>');
1117: }
1118: $r->print('</select></td>');
1119:
1120: $r->print('</tr><tr><td colspan="3"><hr /></td></tr>');
1121:
1122: } else { # hide options - include any necessary extras here
1123:
1124: $r->print('<input type="hidden" name="fcat" value="'.$fcat.'">'."\n");
1125:
1126: unless (@pscat) {
1127: foreach (keys %allparms ) {
1128: $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
1129: }
1130: } else {
1131: foreach (@pscat) {
1132: $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
1133: }
1134: }
1135:
1136: unless (@psprt) {
1137: foreach (keys %allparts ) {
1138: $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
1139: }
1140: } else {
1141: foreach (@psprt) {
1142: $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
1143: }
1144: }
1145:
1146: }
1147: $r->print('</table><br />');
1148: if (($prevvisit) || ($pschp) || ($pssymb)) {
1149: $submitmessage = &mt("Update Course Assessment Parameter Display");
1150: } else {
1151: $submitmessage = &mt("Set/Modify Course Assessment Parameters");
1152: }
1153: $r->print('<input type="submit" name="dis" value="'.$submitmessage.'">');
1154:
1155: # my @temp_psprt;
1156: # foreach my $t (@psprt) {
1157: # push(@temp_psprt, grep {eval (/^$t\./ || ($_ == $t))} (keys %allparts));
1158: # }
1159:
1160: # @psprt = @temp_psprt;
1161:
1162: my @temp_pscat;
1163: map {
1164: my $cat = $_;
1165: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
1166: } @pscat;
1167:
1168: @pscat = @temp_pscat;
1169:
1170: if (($prevvisit) || ($pschp) || ($pssymb)) {
1171: # ----------------------------------------------------------------- Start Table
1172: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
1173: my $csuname=$env{'user.name'};
1174: my $csudom=$env{'user.domain'};
1175:
1176: if ($parmlev eq 'full' || $parmlev eq 'brief') {
1177: my $coursespan=$csec?8:5;
1178: $r->print('<p><table border=2>');
1179: $r->print('<tr><td colspan=5></td>');
1180: $r->print('<th colspan='.($coursespan).'>'.&mt('Any User').'</th>');
1181: if ($uname) {
1182: $r->print("<th colspan=3 rowspan=2>");
1183: $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
1184: }
1185: my %lt=&Apache::lonlocal::texthash(
1186: 'pie' => "Parameter in Effect",
1187: 'csv' => "Current Session Value",
1188: 'at' => 'at',
1189: 'rl' => "Resource Level",
1190: 'ic' => 'in Course',
1191: 'aut' => "Assessment URL and Title",
1192: 'type' => 'Type',
1193: 'emof' => "Enclosing Map or Folder",
1194: 'part' => 'Part',
1195: 'pn' => 'Parameter Name',
1196: 'def' => 'default',
1197: 'femof' => 'from Enclosing Map or Folder',
1198: 'gen' => 'general',
1199: 'foremf' => 'for Enclosing Map or Folder',
1200: 'fr' => 'for Resource'
1201: );
1202: $r->print(<<ENDTABLETWO);
1203: <th rowspan=3>$lt{'pie'}</th>
1204: <th rowspan=3>$lt{'csv'}<br>($csuname $lt{'at'} $csudom)</th>
1205: </tr><tr><td colspan=5></td><th colspan=2>$lt{'ic'}</th><th colspan=2>$lt{'rl'}</th>
1206: <th colspan=1>$lt{'ic'}</th>
1207:
1208: ENDTABLETWO
1209: if ($csec) {
1210: $r->print("<th colspan=3>".
1211: &mt("in Section/Group")." $csec</th>");
1212: }
1213: $r->print(<<ENDTABLEHEADFOUR);
1214: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
1215: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
1216: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
1217: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
1218: ENDTABLEHEADFOUR
1219:
1220: if ($csec) {
1221: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1222: }
1223:
1224: if ($uname) {
1225: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1226: }
1227:
1228: $r->print('</tr>');
1229:
1230: my $defbgone='';
1231: my $defbgtwo='';
1232:
1233: foreach (@ids) {
1234:
1235: my $rid=$_;
1236: my ($inmapid)=($rid=~/\.(\d+)$/);
1237:
1238: if ((!$pssymb &&
1239: (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
1240: ||
1241: ($pssymb && $pssymb eq $symbp{$rid})) {
1242: # ------------------------------------------------------ Entry for one resource
1243: if ($defbgone eq '"#E0E099"') {
1244: $defbgone='"#E0E0DD"';
1245: } else {
1246: $defbgone='"#E0E099"';
1247: }
1248: if ($defbgtwo eq '"#FFFF99"') {
1249: $defbgtwo='"#FFFFDD"';
1250: } else {
1251: $defbgtwo='"#FFFF99"';
1252: }
1253: my $thistitle='';
1254: my %name= ();
1255: undef %name;
1256: my %part= ();
1257: my %display=();
1258: my %type= ();
1259: my %default=();
1260: my $uri=&Apache::lonnet::declutter($uris{$rid});
1261:
1262: foreach (split(/\,/,$keyp{$rid})) {
1263: my $tempkeyp = $_;
1264: if (grep $_ eq $tempkeyp, @catmarker) {
1265: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
1266: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
1267: $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
1268: unless ($display{$_}) { $display{$_}=''; }
1269: $display{$_}.=' ('.$name{$_}.')';
1270: $default{$_}=&Apache::lonnet::metadata($uri,$_);
1271: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
1272: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
1273: }
1274: }
1275: my $totalparms=scalar keys %name;
1276: if ($totalparms>0) {
1277: my $firstrow=1;
1278: my $title=&Apache::lonnet::gettitle($uri);
1279: $r->print('<tr><td bgcolor='.$defbgone.
1280: ' rowspan='.$totalparms.
1281: '><tt><font size=-1>'.
1282: join(' / ',split(/\//,$uri)).
1283: '</font></tt><p><b>'.
1284: "<a href=\"javascript:openWindow('".
1285: &Apache::lonnet::clutter($uri).
1286: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
1287: " TARGET=_self>$title");
1288:
1289: if ($thistitle) {
1290: $r->print(' ('.$thistitle.')');
1291: }
1292: $r->print('</a></b></td>');
1293: $r->print('<td bgcolor='.$defbgtwo.
1294: ' rowspan='.$totalparms.'>'.$typep{$rid}.
1295: '</td>');
1296:
1297: $r->print('<td bgcolor='.$defbgone.
1298: ' rowspan='.$totalparms.
1299: '><tt><font size=-1>');
1300:
1301: $r->print(' / res / ');
1302: $r->print(join(' / ', split(/\//,$mapp{$rid})));
1303:
1304: $r->print('</font></tt></td>');
1305:
1306: foreach (sort keys %name) {
1307: unless ($firstrow) {
1308: $r->print('<tr>');
1309: } else {
1310: undef $firstrow;
1311: }
1312:
1313: &print_row($r,$_,\%part,\%name,$rid,\%default,
1314: \%type,\%display,$defbgone,$defbgtwo,
1315: $parmlev,$uname,$udom,$csec);
1316: }
1317: }
1318: }
1319: } # end foreach ids
1320: # -------------------------------------------------- End entry for one resource
1321: $r->print('</table>');
1322: } # end of brief/full
1323: #--------------------------------------------------- Entry for parm level map
1324: if ($parmlev eq 'map') {
1325: my $defbgone = '"E0E099"';
1326: my $defbgtwo = '"FFFF99"';
1327:
1328: my %maplist;
1329:
1330: if ($pschp eq 'all') {
1331: %maplist = %allmaps;
1332: } else {
1333: %maplist = ($pschp => $mapp{$pschp});
1334: }
1335:
1336: #-------------------------------------------- for each map, gather information
1337: my $mapid;
1338: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
1339: my $maptitle = $maplist{$mapid};
1340:
1341: #----------------------- loop through ids and get all parameter types for map
1342: #----------------------------------------- and associated information
1343: my %name = ();
1344: my %part = ();
1345: my %display = ();
1346: my %type = ();
1347: my %default = ();
1348: my $map = 0;
1349:
1350: # $r->print("Catmarker: @catmarker<br />\n");
1351:
1352: foreach (@ids) {
1353: ($map)=(/([\d]*?)\./);
1354: my $rid = $_;
1355:
1356: # $r->print("$mapid:$map: $rid <br /> \n");
1357:
1358: if ($map eq $mapid) {
1359: my $uri=&Apache::lonnet::declutter($uris{$rid});
1360: # $r->print("Keys: $keyp{$rid} <br />\n");
1361:
1362: #--------------------------------------------------------------------
1363: # @catmarker contains list of all possible parameters including part #s
1364: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1365: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1366: # When storing information, store as part 0
1367: # When requesting information, request from full part
1368: #-------------------------------------------------------------------
1369: foreach (split(/\,/,$keyp{$rid})) {
1370: my $tempkeyp = $_;
1371: my $fullkeyp = $tempkeyp;
1372: $tempkeyp =~ s/_\w+_/_0_/;
1373:
1374: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1375: $part{$tempkeyp}="0";
1376: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1377: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1378: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1379: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1380: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1381: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1382: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1383: }
1384: } # end loop through keys
1385: }
1386: } # end loop through ids
1387:
1388: #---------------------------------------------------- print header information
1389: my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
1390: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
1391: $r->print(<<ENDMAPONE);
1392: <center><h4>
1393: Set Defaults for All Resources in $foldermap<br />
1394: <font color="red"><i>$showtitle</i></font><br />
1395: Specifically for
1396: ENDMAPONE
1397: if ($uname) {
1398: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1399: ('firstname','middlename','lastname','generation', 'id'));
1400: my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
1401: .$name{'lastname'}.' '.$name{'generation'};
1402: $r->print(&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
1403: &mt('in')." \n");
1404: } else {
1405: $r->print("<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n");
1406: }
1407:
1408: if ($csec) {$r->print(&mt("Section")." <font color=\"red\"><i>$csec</i></font> ".
1409: &mt('of')." \n")};
1410:
1411: $r->print("<font color=\"red\"><i>$coursename</i></font><br />");
1412: $r->print("</h4>\n");
1413: #---------------------------------------------------------------- print table
1414: $r->print('<p><table border="2">');
1415: $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
1416: $r->print('<th>'.&mt('Default Value').'</th>');
1417: $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1418:
1419: foreach (sort keys %name) {
1420: $r->print('<tr>');
1421: &print_row($r,$_,\%part,\%name,$mapid,\%default,
1422: \%type,\%display,$defbgone,$defbgtwo,
1423: $parmlev,$uname,$udom,$csec);
1424: # $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
1425: }
1426: $r->print("</table></center>");
1427: } # end each map
1428: } # end of $parmlev eq map
1429: #--------------------------------- Entry for parm level general (Course level)
1430: if ($parmlev eq 'general') {
1431: my $defbgone = '"E0E099"';
1432: my $defbgtwo = '"FFFF99"';
1433:
1434: #-------------------------------------------- for each map, gather information
1435: my $mapid="0.0";
1436: #----------------------- loop through ids and get all parameter types for map
1437: #----------------------------------------- and associated information
1438: my %name = ();
1439: my %part = ();
1440: my %display = ();
1441: my %type = ();
1442: my %default = ();
1443:
1444: foreach (@ids) {
1445: my $rid = $_;
1446:
1447: my $uri=&Apache::lonnet::declutter($uris{$rid});
1448:
1449: #--------------------------------------------------------------------
1450: # @catmarker contains list of all possible parameters including part #s
1451: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1452: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1453: # When storing information, store as part 0
1454: # When requesting information, request from full part
1455: #-------------------------------------------------------------------
1456: foreach (split(/\,/,$keyp{$rid})) {
1457: my $tempkeyp = $_;
1458: my $fullkeyp = $tempkeyp;
1459: $tempkeyp =~ s/_\w+_/_0_/;
1460: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1461: $part{$tempkeyp}="0";
1462: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1463: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1464: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1465: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1466: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1467: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1468: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1469: }
1470: } # end loop through keys
1471: } # end loop through ids
1472:
1473: #---------------------------------------------------- print header information
1474: my $setdef=&mt("Set Defaults for All Resources in Course");
1475: $r->print(<<ENDMAPONE);
1476: <center><h4>$setdef
1477: <font color="red"><i>$coursename</i></font><br />
1478: ENDMAPONE
1479: if ($uname) {
1480: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1481: ('firstname','middlename','lastname','generation', 'id'));
1482: my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
1483: .$name{'lastname'}.' '.$name{'generation'};
1484: $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
1485: } else {
1486: $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
1487: }
1488:
1489: if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
1490: $r->print("</h4>\n");
1491: #---------------------------------------------------------------- print table
1492: $r->print('<p><table border="2">');
1493: $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
1494: $r->print('<th>'.&mt('Default Value').'</th>');
1495: $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1496:
1497: foreach (sort keys %name) {
1498: $r->print('<tr>');
1499: &print_row($r,$_,\%part,\%name,$mapid,\%default,
1500: \%type,\%display,$defbgone,$defbgtwo,$parmlev,$uname,$udom,$csec);
1501: # $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
1502: }
1503: $r->print("</table></center>");
1504: } # end of $parmlev eq general
1505: }
1506: $r->print('</form></body></html>');
1507: } # end sub assessparms
1508:
1509:
1510: ##################################################
1511: ##################################################
1512:
1513: =pod
1514:
1515: =item crsenv
1516:
1517: Show and set course data and parameters. This is a large routine that should
1518: be simplified and shortened... someday.
1519:
1520: Inputs: $r
1521:
1522: Returns: nothing
1523:
1524: =cut
1525:
1526: ##################################################
1527: ##################################################
1528: sub crsenv {
1529: my $r=shift;
1530: my $setoutput='';
1531: my $bodytag=&Apache::loncommon::bodytag(
1532: 'Set Course Environment Parameters');
1533: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,
1534: 'Edit Course Environment');
1535: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1536: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1537:
1538: #
1539: # Go through list of changes
1540: foreach (keys %env) {
1541: next if ($_!~/^form\.(.+)\_setparmval$/);
1542: my $name = $1;
1543: my $value = $env{'form.'.$name.'_value'};
1544: if ($name eq 'newp') {
1545: $name = $env{'form.newp_name'};
1546: }
1547: if ($name eq 'url') {
1548: $value=~s/^\/res\///;
1549: my $bkuptime=time;
1550: my @tmp = &Apache::lonnet::get
1551: ('environment',['url'],$dom,$crs);
1552: $setoutput.=&mt('Backing up previous URL').': '.
1553: &Apache::lonnet::put
1554: ('environment',
1555: {'top level map backup '.$bkuptime => $tmp[1] },
1556: $dom,$crs).
1557: '<br>';
1558: }
1559: #
1560: # Deal with modified default spreadsheets
1561: if ($name =~ /^spreadsheet_default_(classcalc|
1562: studentcalc|
1563: assesscalc)$/x) {
1564: my $sheettype = $1;
1565: if ($sheettype eq 'classcalc') {
1566: # no need to do anything since viewing the sheet will
1567: # cause it to be updated.
1568: } elsif ($sheettype eq 'studentcalc') {
1569: # expire all the student spreadsheets
1570: &Apache::lonnet::expirespread('','','studentcalc');
1571: } else {
1572: # expire all the assessment spreadsheets
1573: # this includes non-default spreadsheets, but better to
1574: # be safe than sorry.
1575: &Apache::lonnet::expirespread('','','assesscalc');
1576: # expire all the student spreadsheets
1577: &Apache::lonnet::expirespread('','','studentcalc');
1578: }
1579: }
1580: #
1581: # Deal with the enrollment dates
1582: if ($name =~ /^default_enrollment_(start|end)_date$/) {
1583: $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
1584: }
1585: # Get existing cloners
1586: my @oldcloner = ();
1587: if ($name eq 'cloners') {
1588: my %clonenames=&Apache::lonnet::dump('environment',$dom,$crs,'cloners');
1589: if ($clonenames{'cloners'} =~ /,/) {
1590: @oldcloner = split/,/,$clonenames{'cloners'};
1591: } else {
1592: $oldcloner[0] = $clonenames{'cloners'};
1593: }
1594: }
1595: #
1596: # Let the user know we made the changes
1597: if ($name && defined($value)) {
1598: if ($name eq 'cloners') {
1599: $value =~ s/^,//;
1600: $value =~ s/,$//;
1601: }
1602: my $put_result = &Apache::lonnet::put('environment',
1603: {$name=>$value},$dom,$crs);
1604: if ($put_result eq 'ok') {
1605: $setoutput.=&mt('Set').' <b>'.$name.'</b> '.&mt('to').' <b>'.$value.'</b>.<br />';
1606: if ($name eq 'cloners') {
1607: &change_clone($value,\@oldcloner);
1608: }
1609: # Flush the course logs so course description is immediately updated
1610: if ($name eq 'description' && defined($value)) {
1611: &Apache::lonnet::flushcourselogs();
1612: }
1613: } else {
1614: $setoutput.=&mt('Unable to set').' <b>'.$name.'</b> '.&mt('to').
1615: ' <b>'.$value.'</b> '.&mt('due to').' '.$put_result.'.<br />';
1616: }
1617: }
1618: }
1619: # ------------------------- Re-init course environment entries for this session
1620:
1621: &Apache::lonnet::coursedescription($env{'request.course.id'});
1622:
1623: # -------------------------------------------------------- Get parameters again
1624:
1625: my %values=&Apache::lonnet::dump('environment',$dom,$crs);
1626: my $SelectStyleFile=&mt('Select Style File');
1627: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
1628: my $output='';
1629: if (! exists($values{'con_lost'})) {
1630: my %descriptions=
1631: ('url' => '<b>'.&mt('Top Level Map').'</b> '.
1632: '<a href="javascript:openbrowser'.
1633: "('envform','url','sequence')\">".
1634: &mt('Select Map').'</a><br /><font color=red> '.
1635: &mt('Modification may make assessment data inaccessible').
1636: '</font>',
1637: 'description' => '<b>'.&mt('Course Description').'</b>',
1638: 'courseid' => '<b>'.&mt('Course ID or number').
1639: '</b><br />'.
1640: '('.&mt('internal').', '.&mt('optional').')',
1641: 'cloners' => '<b>'.&mt('Users allowed to clone course').'</b><br /><tt>(user:domain,user:domain)</tt><br />'.&mt('Users with active Course Coordinator role in the course automatically have the right to clone it, and can be omitted from list.'),
1642: 'grading' => '<b>'.&mt('Grading').'</b><br />'.
1643: '<tt>"standard", "external", or "spreadsheet"</tt> '.&Apache::loncommon::help_open_topic('GradingOptions'),
1644: 'default_xml_style' => '<b>'.&mt('Default XML Style File').'</b> '.
1645: '<a href="javascript:openbrowser'.
1646: "('envform','default_xml_style'".
1647: ",'sty')\">$SelectStyleFile</a><br>",
1648: 'question.email' => '<b>'.&mt('Feedback Addresses for Resource Content Question').
1649: '</b><br />(<tt>user:domain,'.
1650: 'user:domain(section;section;...;*;...),...</tt>)',
1651: 'comment.email' => '<b>'.&mt('Feedback Addresses for Course Content Comments').'</b><br />'.
1652: '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1653: 'policy.email' => '<b>'.&mt('Feedback Addresses for Course Policy').'</b>'.
1654: '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1655: 'hideemptyrows' => '<b>'.&mt('Hide Empty Rows in Spreadsheets').'</b><br />'.
1656: '('.&mt('"[_1]" for default hiding','<tt>yes</tt>').')',
1657: 'pageseparators' => '<b>'.&mt('Visibly Separate Items on Pages').'</b><br />'.
1658: '('.&mt('"[_1]" for visible separation','<tt>yes</tt>').', '.
1659: &mt('changes will not show until next login').')',
1660: 'student_classlist_view' => '<b>'.&mt('Allow students to view classlist.').'</b>'.&mt('("all":students can view all sections,"section":students can only view their own section.blank or "disabled" prevents student view.'),
1661:
1662: 'plc.roles.denied'=> '<b>'.&mt('Disallow live chatroom use for Roles').
1663: '</b><br />"<tt>st</tt>": '.
1664: &mt('student').', "<tt>ta</tt>": '.
1665: 'TA, "<tt>in</tt>": '.
1666: &mt('instructor').';<br /><tt>'.&mt('role,role,...').'</tt>) '.
1667: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
1668: 'plc.users.denied' =>
1669: '<b>'.&mt('Disallow live chatroom use for Users').'</b><br />'.
1670: '(<tt>user:domain,user:domain,...</tt>)',
1671:
1672: 'pch.roles.denied'=> '<b>'.&mt('Disallow Resource Discussion for Roles').
1673: '</b><br />"<tt>st</tt>": '.
1674: 'student, "<tt>ta</tt>": '.
1675: 'TA, "<tt>in</tt>": '.
1676: 'instructor;<br /><tt>role,role,...</tt>) '.
1677: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
1678: 'pch.users.denied' =>
1679: '<b>'.&mt('Disallow Resource Discussion for Users').'</b><br />'.
1680: '(<tt>user:domain,user:domain,...</tt>)',
1681: 'spreadsheet_default_classcalc'
1682: => '<b>'.&mt('Default Course Spreadsheet').'</b> '.
1683: '<a href="javascript:openbrowser'.
1684: "('envform','spreadsheet_default_classcalc'".
1685: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1686: 'spreadsheet_default_studentcalc'
1687: => '<b>'.&mt('Default Student Spreadsheet').'</b> '.
1688: '<a href="javascript:openbrowser'.
1689: "('envform','spreadsheet_default_calc'".
1690: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1691: 'spreadsheet_default_assesscalc'
1692: => '<b>'.&mt('Default Assessment Spreadsheet').'</b> '.
1693: '<a href="javascript:openbrowser'.
1694: "('envform','spreadsheet_default_assesscalc'".
1695: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1696: 'allow_limited_html_in_feedback'
1697: => '<b>'.&mt('Allow limited HTML in discussion posts').'</b><br />'.
1698: '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
1699: 'allow_discussion_post_editing'
1700: => '<b>'.&mt('Allow users to edit/delete their own discussion posts').'</b><br />'.
1701: '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
1702: 'rndseed'
1703: => '<b>'.&mt('Randomization algorithm used').'</b> <br />'.
1704: '<font color="red">'.&mt('Modifying this will make problems').' '.
1705: &mt('have different numbers and answers').'</font>',
1706: 'receiptalg'
1707: => '<b>'.&mt('Receipt algorithm used').'</b> <br />'.
1708: &mt('This controls how receipt numbers are generated.'),
1709: 'suppress_tries'
1710: => '<b>'.&mt('Suppress number of tries in printing').'</b>('.
1711: &mt('yes if supress').')',
1712: 'problem_stream_switch'
1713: => '<b>'.&mt('Allow problems to be split over pages').'</b><br />'.
1714: ' ('.&mt('"[_1]" if allowed, anything else if not','<tt>yes</tt>').')',
1715: 'default_paper_size'
1716: => '<b>'.&mt('Default paper type').'</b><br />'.
1717: ' ('.&mt('supported types').': Letter [8 1/2x11 in], Legal [8 1/2x14 in],'.
1718: ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'.
1719: ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])',
1720: 'anonymous_quiz'
1721: => '<b>'.&mt('Anonymous quiz/exam').'</b><br />'.
1722: ' (<tt><b>'.&mt('yes').'</b> '.&mt('to avoid print students names').' </tt>)',
1723: 'default_enrollment_start_date' => '<b>'.&mt('Default beginning date when enrolling students').'</b>',
1724: 'default_enrollment_end_date' => '<b>'.&mt('Default ending date when enrolling students').'</b>',
1725: 'nothideprivileged' => '<b>'.&mt('Privileged users that should not be hidden on staff listings').'</b>'.
1726: '<br />(<tt>user:domain,user:domain,...</tt>)',
1727: 'languages' => '<b>'.&mt('Languages used').'</b>',
1728: 'disable_receipt_display'
1729: => '<b>'.&mt('Disable display of problem receipts').'</b><br />'.
1730: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
1731: 'disablesigfigs'
1732: => '<b>'.&mt('Disable checking of Significant Figures').'</b><br />'.
1733: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
1734: 'tthoptions'
1735: => '<b>'.&mt('Default set of options to pass to tth/m when converting tex').'</b>'
1736: );
1737: my @Display_Order = ('url','description','courseid','cloners','grading',
1738: 'default_xml_style','pageseparators',
1739: 'question.email','comment.email','policy.email',
1740: 'student_classlist_view',
1741: 'plc.roles.denied','plc.users.denied',
1742: 'pch.roles.denied','pch.users.denied',
1743: 'allow_limited_html_in_feedback',
1744: 'allow_discussion_post_editing',
1745: 'languages',
1746: 'nothideprivileged',
1747: 'rndseed',
1748: 'receiptalg',
1749: 'problem_stream_switch',
1750: 'suppress_tries',
1751: 'default_paper_size',
1752: 'disable_receipt_display',
1753: 'spreadsheet_default_classcalc',
1754: 'spreadsheet_default_studentcalc',
1755: 'spreadsheet_default_assesscalc',
1756: 'hideemptyrows',
1757: 'default_enrollment_start_date',
1758: 'default_enrollment_end_date',
1759: 'tthoptions',
1760: 'disablesigfigs'
1761: );
1762: foreach my $parameter (sort(keys(%values))) {
1763: unless ($parameter =~ m/^internal\./) {
1764: if (! $descriptions{$parameter}) {
1765: $descriptions{$parameter}=$parameter;
1766: push(@Display_Order,$parameter);
1767: }
1768: }
1769: }
1770: foreach my $parameter (@Display_Order) {
1771: my $description = $descriptions{$parameter};
1772: # onchange is javascript to automatically check the 'Set' button.
1773: my $onchange = 'onFocus="javascript:window.document.forms'.
1774: "['envform'].elements['".$parameter."_setparmval']".
1775: '.checked=true;"';
1776: $output .= '<tr><td>'.$description.'</td>';
1777: if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
1778: $output .= '<td>'.
1779: &Apache::lonhtmlcommon::date_setter('envform',
1780: $parameter.'_value',
1781: $values{$parameter},
1782: $onchange).
1783: '</td>';
1784: } else {
1785: $output .= '<td>'.
1786: &Apache::lonhtmlcommon::textbox($parameter.'_value',
1787: $values{$parameter},
1788: 40,$onchange).'</td>';
1789: }
1790: $output .= '<td>'.
1791: &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
1792: '</td>';
1793: $output .= "</tr>\n";
1794: }
1795: my $onchange = 'onFocus="javascript:window.document.forms'.
1796: '[\'envform\'].elements[\'newp_setparmval\']'.
1797: '.checked=true;"';
1798: $output.='<tr><td><i>'.&mt('Create New Environment Variable').'</i><br />'.
1799: '<input type="text" size=40 name="newp_name" '.
1800: $onchange.' /></td><td>'.
1801: '<input type="text" size=40 name="newp_value" '.
1802: $onchange.' /></td><td>'.
1803: '<input type="checkbox" name="newp_setparmval" /></td></tr>';
1804: }
1805: my %lt=&Apache::lonlocal::texthash(
1806: 'par' => 'Parameter',
1807: 'val' => 'Value',
1808: 'set' => 'Set',
1809: 'sce' => 'Set Course Environment'
1810: );
1811:
1812: my $Parameter=&mt('Parameter');
1813: my $Value=&mt('Value');
1814: my $Set=&mt('Set');
1815: my $browse_js=&Apache::loncommon::browser_and_searcher_javascript('parmset');
1816: my $html=&Apache::lonxml::xmlbegin();
1817: $r->print(<<ENDenv);
1818: $html
1819: <head>
1820: <script type="text/javascript" language="Javascript" >
1821: $browse_js
1822: </script>
1823: <title>LON-CAPA Course Environment</title>
1824: </head>
1825: $bodytag
1826: $breadcrumbs
1827: <form method="post" action="/adm/parmset?action=crsenv" name="envform">
1828: $setoutput
1829: <p>
1830: <table border=2>
1831: <tr><th>$lt{'par'}</th><th>$lt{'val'}</th><th>$lt{'set'}?</th></tr>
1832: $output
1833: </table>
1834: <input type="submit" name="crsenv" value="$lt{'sce'}">
1835: </form>
1836: </body>
1837: </html>
1838: ENDenv
1839: }
1840: ##################################################
1841:
1842: my $tableopen;
1843:
1844: sub tablestart {
1845: if ($tableopen) {
1846: return '';
1847: } else {
1848: $tableopen=1;
1849: return '<table border="2"><tr><th>'.&mt('Parameter').'</th><th>'.
1850: &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
1851: }
1852: }
1853:
1854: sub tableend {
1855: if ($tableopen) {
1856: $tableopen=0;
1857: return '</table>';
1858: } else {
1859: return'';
1860: }
1861: }
1862:
1863: sub overview {
1864: my $r=shift;
1865: my $bodytag=&Apache::loncommon::bodytag(
1866: 'Set/Modify Course Assessment Parameters');
1867: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1868: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1869: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
1870: my $html=&Apache::lonxml::xmlbegin();
1871: $r->print(<<ENDOVER);
1872: $html
1873: <head>
1874: <title>LON-CAPA Course Environment</title>
1875: </head>
1876: $bodytag
1877: $breadcrumbs
1878: <form method="post" action="/adm/parmset?action=setoverview" name="overviewform">
1879: <input type="hidden" name="overview" value="1" />
1880: ENDOVER
1881: # Setting
1882: my %olddata=&Apache::lonnet::dump('resourcedata',$dom,$crs);
1883: my %newdata=();
1884: undef %newdata;
1885: my @deldata=();
1886: undef @deldata;
1887: foreach (keys %env) {
1888: if ($_=~/^form\.([a-z]+)\_(.+)$/) {
1889: my $cmd=$1;
1890: my $thiskey=$2;
1891: if ($cmd eq 'set') {
1892: my $data=$env{$_};
1893: if ($olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; }
1894: } elsif ($cmd eq 'del') {
1895: push (@deldata,$thiskey);
1896: } elsif ($cmd eq 'datepointer') {
1897: my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
1898: if (defined($data) and $olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; }
1899: }
1900: }
1901: }
1902: # Store
1903: my $delentries=$#deldata+1;
1904: my @newdatakeys=keys %newdata;
1905: my $putentries=$#newdatakeys+1;
1906: if ($delentries) {
1907: if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
1908: $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
1909: } else {
1910: $r->print('<h2><font color="red">'.
1911: &mt('Error deleting parameters').'</font></h2>');
1912: }
1913: }
1914: if ($putentries) {
1915: if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
1916: $r->print('<h2>'.&mt('Stored [_1] parameter(s)</h2>',$putentries));
1917: } else {
1918: $r->print('<h2><font color="red">'.
1919: &mt('Error storing parameters').'</font></h2>');
1920: }
1921: }
1922: # Read and display
1923: my %resourcedata=&Apache::lonnet::dump('resourcedata',$dom,$crs);
1924: my $oldsection='';
1925: my $oldrealm='';
1926: my $oldpart='';
1927: my $pointer=0;
1928: $tableopen=0;
1929: my $foundkeys=0;
1930: foreach my $thiskey (sort keys %resourcedata) {
1931: if ($resourcedata{$thiskey.'.type'}) {
1932: my ($course,$middle,$part,$name)=
1933: ($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
1934: my $section=&mt('All Students');
1935: if ($middle=~/^\[(.*)\]\./) {
1936: $section=&mt('Group/Section').': '.$1;
1937: $middle=~s/^\[(.*)\]\.//;
1938: }
1939: $middle=~s/\.$//;
1940: my $realm='<font color="red">'.&mt('All Resources').'</font>';
1941: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
1942: $realm='<font color="green">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><font color="#aaaaaa" size="-2">('.$1.')</font></font>';
1943: } elsif ($middle) {
1944: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
1945: $realm='<font color="orange">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><font color="#aaaaaa" size="-2">('.$url.' in '.$map.' id: '.$id.')</font></font>';
1946: }
1947: if ($section ne $oldsection) {
1948: $r->print(&tableend()."\n<hr /><h1>$section</h1>");
1949: $oldsection=$section;
1950: $oldrealm='';
1951: }
1952: if ($realm ne $oldrealm) {
1953: $r->print(&tableend()."\n<h2>$realm</h2>");
1954: $oldrealm=$realm;
1955: $oldpart='';
1956: }
1957: if ($part ne $oldpart) {
1958: $r->print(&tableend().
1959: "\n<h3><font color='blue'>".&mt('Part').": $part</font></h3>");
1960: $oldpart=$part;
1961: }
1962: #
1963: # Ready to print
1964: #
1965: $r->print(&tablestart().'<tr><td><b>'.$name.
1966: ':</b></td><td><input type="checkbox" name="del_'.
1967: $thiskey.'" /></td><td>');
1968: $foundkeys++;
1969: if ($resourcedata{$thiskey.'.type'}=~/^date/) {
1970: my $jskey='key_'.$pointer;
1971: $pointer++;
1972: $r->print(
1973: &Apache::lonhtmlcommon::date_setter('overviewform',
1974: $jskey,
1975: $resourcedata{$thiskey}).
1976: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'
1977: );
1978: } else {
1979: $r->print(
1980: '<input type="text" name="set_'.$thiskey.'" value="'.
1981: $resourcedata{$thiskey}.'">');
1982: }
1983: $r->print('</td></tr>');
1984: }
1985: }
1986:
1987: $r->print(&tableend().'<p>'.
1988: ($foundkeys?'<input type="submit" value="'.&mt('Modify Parameters').'" />':&mt('There are no course or section parameters.')).'</p></form></body></html>');
1989: }
1990:
1991: ##################################################
1992: ##################################################
1993:
1994: =pod
1995:
1996: =item change clone
1997:
1998: Modifies the list of courses a user can clone (stored
1999: in the user's environemnt.db file), called when a
2000: change is made to the list of users allowed to clone
2001: a course.
2002:
2003: Inputs: $action,$cloner
2004: where $action is add or drop, and $cloner is identity of
2005: user for whom cloning ability is to be changed in course.
2006:
2007: Returns:
2008:
2009: =cut
2010:
2011: ##################################################
2012: ##################################################
2013:
2014:
2015: sub change_clone {
2016: my ($clonelist,$oldcloner) = @_;
2017: my ($uname,$udom);
2018: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2019: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2020: my $clone_crs = $cnum.':'.$cdom;
2021:
2022: if ($cnum && $cdom) {
2023: my @allowclone = ();
2024: if ($clonelist =~ /,/) {
2025: @allowclone = split/,/,$clonelist;
2026: } else {
2027: $allowclone[0] = $clonelist;
2028: }
2029: foreach my $currclone (@allowclone) {
2030: if (!grep/^$currclone$/,@$oldcloner) {
2031: ($uname,$udom) = split/:/,$currclone;
2032: if ($uname && $udom) {
2033: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
2034: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
2035: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
2036: if ($currclonecrs{'cloneable'} eq '') {
2037: $currclonecrs{'cloneable'} = $clone_crs;
2038: } else {
2039: $currclonecrs{'cloneable'} .= ','.$clone_crs;
2040: }
2041: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
2042: }
2043: }
2044: }
2045: }
2046: }
2047: foreach my $oldclone (@$oldcloner) {
2048: if (!grep/^$oldclone$/,@allowclone) {
2049: ($uname,$udom) = split/:/,$oldclone;
2050: if ($uname && $udom) {
2051: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
2052: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
2053: my %newclonecrs = ();
2054: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
2055: if ($currclonecrs{'cloneable'} =~ /,/) {
2056: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
2057: foreach (@currclonecrs) {
2058: unless ($_ eq $clone_crs) {
2059: $newclonecrs{'cloneable'} .= $_.',';
2060: }
2061: }
2062: $newclonecrs{'cloneable'} =~ s/,$//;
2063: } else {
2064: $newclonecrs{'cloneable'} = '';
2065: }
2066: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
2067: }
2068: }
2069: }
2070: }
2071: }
2072: }
2073: }
2074:
2075:
2076: ##################################################
2077: ##################################################
2078:
2079: =pod
2080:
2081: =item * header
2082:
2083: Output html header for page
2084:
2085: =cut
2086:
2087: ##################################################
2088: ##################################################
2089: sub header {
2090: my $html=&Apache::lonxml::xmlbegin();
2091: my $bodytag=&Apache::loncommon::bodytag('Parameter Manager');
2092: my $title = &mt('LON-CAPA Parameter Manager');
2093: return(<<ENDHEAD);
2094: $html
2095: <head>
2096: <title>$title</title>
2097: </head>
2098: $bodytag
2099: ENDHEAD
2100: }
2101: ##################################################
2102: ##################################################
2103: sub print_main_menu {
2104: my ($r,$parm_permission)=@_;
2105: #
2106: $r->print(<<ENDMAINFORMHEAD);
2107: <form method="post" enctype="multipart/form-data"
2108: action="/adm/parmset" name="studentform">
2109: ENDMAINFORMHEAD
2110: #
2111: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2112: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2113: my @menu =
2114: (
2115: { text => 'Set Course Environment Parameters',
2116: help => 'Course_Setting_Parameters',
2117: action => 'crsenv',
2118: permission => $parm_permission,
2119: },
2120: { text => 'Set/Modify Course Assessment Parameters - Helper Mode',
2121: url => '/adm/helper/parameter.helper',
2122: permission => $parm_permission,
2123: },
2124: { text => 'Modify Course Assessment Parameters - Overview Mode',
2125: action => 'setoverview',
2126: permission => $parm_permission,
2127: },
2128: { text => 'Set/Modify Course Assessment Parameters - Table Mode',
2129: action => 'settable',
2130: permission => $parm_permission,
2131: },
2132: # { text => 'Set Parameter Default Preferences',
2133: # help => 'Course_View_Class_List',
2134: # action => 'setdefaults',
2135: # permission => $parm_permission,
2136: # },
2137: );
2138: my $menu_html = '';
2139: foreach my $menu_item (@menu) {
2140: next if (! $menu_item->{'permission'});
2141: $menu_html.='<p>';
2142: $menu_html.='<font size="+1">';
2143: if (exists($menu_item->{'url'})) {
2144: $menu_html.=qq{<a href="$menu_item->{'url'}">};
2145: } else {
2146: $menu_html.=
2147: qq{<a href="/adm/parmset?action=$menu_item->{'action'}">};
2148: }
2149: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
2150: if (exists($menu_item->{'help'})) {
2151: $menu_html.=
2152: &Apache::loncommon::help_open_topic($menu_item->{'help'});
2153: }
2154: $menu_html.='</p>'.$/;
2155: }
2156: $r->print($menu_html);
2157: return;
2158: }
2159:
2160:
2161:
2162:
2163: ##################################################
2164: ##################################################
2165:
2166: =pod
2167:
2168: =item * handler
2169:
2170: Main handler. Calls &assessparms and &crsenv subroutines.
2171:
2172: =cut
2173: ##################################################
2174: ##################################################
2175: use Data::Dumper;
2176: sub handler {
2177: my $r=shift;
2178:
2179: if ($r->header_only) {
2180: &Apache::loncommon::content_type($r,'text/html');
2181: $r->send_http_header;
2182: return OK;
2183: }
2184: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2185: ['action','state']);
2186:
2187: # ----------------------------------------------------------- Clear out garbage
2188:
2189:
2190: @ids=();
2191: %symbp=();
2192: %mapp=();
2193: %typep=();
2194: %keyp=();
2195:
2196: %maptitles=();
2197:
2198: &Apache::lonhtmlcommon::clear_breadcrumbs();
2199: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
2200: text=>"Parameter Manager",
2201: faq=>9,
2202: bug=>'Instructor Interface'});
2203: # ----------------------------------------------------- Needs to be in a course
2204: my $parm_permission =
2205: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
2206: &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
2207: $env{'request.course.sec'}));
2208: if ($env{'request.course.id'} && $parm_permission) {
2209:
2210: # Start Page
2211: &Apache::loncommon::content_type($r,'text/html');
2212: $r->send_http_header;
2213:
2214: #
2215: # Main switch on form.action and form.state, as appropriate
2216: #
2217: # Check first if coming from someone else headed directly for
2218: # the table mode
2219: if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
2220: && (!$env{'form.dis'})) || ($env{'form.symb'})) {
2221: &assessparms($r);
2222:
2223: } elsif (! exists($env{'form.action'})) {
2224: $r->print(&header());
2225: $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
2226: 'Parameter Manager'));
2227: &print_main_menu($r,$parm_permission);
2228: } elsif ($env{'form.action'} eq 'crsenv' && $parm_permission) {
2229: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=crsenv',
2230: text=>"Course Environment"});
2231: $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
2232: 'Edit Course Environment'));
2233: &crsenv($r);
2234: } elsif ($env{'form.action'} eq 'setoverview' && $parm_permission) {
2235: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
2236: text=>"Overview Mode"});
2237: &overview($r);
2238: } elsif ($env{'form.action'} eq 'settable' && $parm_permission) {
2239: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
2240: text=>"Table Mode"});
2241: &assessparms($r);
2242: }
2243:
2244: } else {
2245: # ----------------------------- Not in a course, or not allowed to modify parms
2246: $env{'user.error.msg'}=
2247: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
2248: return HTTP_NOT_ACCEPTABLE;
2249: }
2250: return OK;
2251: }
2252:
2253: 1;
2254: __END__
2255:
2256: =pod
2257:
2258: =back
2259:
2260: =cut
2261:
2262:
2263:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>