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