1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
4: # $Id: lonparmset.pm,v 1.274 2005/12/29 17:58:13 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###################################################################
29: ###################################################################
30:
31: =pod
32:
33: =head1 NAME
34:
35: lonparmset - Handler to set parameters for assessments and course
36:
37: =head1 SYNOPSIS
38:
39: lonparmset provides an interface to setting course parameters.
40:
41: =head1 DESCRIPTION
42:
43: This module sets coursewide and assessment parameters.
44:
45: =head1 INTERNAL SUBROUTINES
46:
47: =over 4
48:
49: =cut
50:
51: ###################################################################
52: ###################################################################
53:
54: package Apache::lonparmset;
55:
56: use strict;
57: use Apache::lonnet;
58: use Apache::Constants qw(:common :http REDIRECT);
59: use Apache::lonhtmlcommon();
60: use Apache::loncommon;
61: use GDBM_File;
62: use Apache::lonhomework;
63: use Apache::lonxml;
64: use Apache::lonlocal;
65: use Apache::lonnavmaps;
66:
67: # --- Caches local to lonparmset
68:
69: my $parmhashid;
70: my %parmhash;
71: my $symbsid;
72: my %symbs;
73: my $rulesid;
74: my %rules;
75:
76: # --- end local caches
77:
78: ##################################################
79: ##################################################
80:
81: =pod
82:
83: =item parmval
84:
85: Figure out a cascading parameter.
86:
87: Inputs: $what - a parameter spec (incluse part info and name I.E. 0.weight)
88: $id - a bighash Id number
89: $def - the resource's default value 'stupid emacs
90:
91: 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 14 possible levels
92:
93: 14 - General Course
94: 13 - Map or Folder level in course
95: 12- resource default
96: 11- map default
97: 10 - resource level in course
98: 9 - General for section
99: 8 - Map or Folder level for section
100: 7 - resource level in section
101: 6 - General for group
102: 5 - Map or Folder level for group
103: 4 - resource level in group
104: 3 - General for specific student
105: 2 - Map or Folder level for specific student
106: 1 - resource level for specific student
107:
108: =cut
109:
110: ##################################################
111: sub parmval {
112: my ($what,$id,$def,$uname,$udom,$csec,$cgroup)=@_;
113: return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec,$cgroup);
114: }
115:
116: sub parmval_by_symb {
117: my ($what,$symb,$def,$uname,$udom,$csec,$cgroup)=@_;
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: my $result='';
128: my @outpar=();
129: # ----------------------------------------------------- Cascading lookup scheme
130: my $map=(&Apache::lonnet::decode_symb($symb))[0];
131:
132: my $symbparm=$symb.'.'.$what;
133: my $mapparm=$map.'___(all).'.$what;
134:
135: my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$what;
136: my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
137: my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
138:
139: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
140: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
141: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
142:
143: my $courselevel=$env{'request.course.id'}.'.'.$what;
144: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
145: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
146:
147:
148: # --------------------------------------------------------- first, check course
149:
150: if (defined($$courseopt{$courselevel})) {
151: $outpar[14]=$$courseopt{$courselevel};
152: $result=14;
153: }
154:
155: if (defined($$courseopt{$courselevelm})) {
156: $outpar[13]=$$courseopt{$courselevelm};
157: $result=13;
158: }
159:
160: # ------------------------------------------------------- second, check default
161:
162: if (defined($def)) { $outpar[12]=$def; $result=12; }
163:
164: # ------------------------------------------------------ third, check map parms
165:
166: my $thisparm=$parmhash{$symbparm};
167: if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }
168:
169: if (defined($$courseopt{$courselevelr})) {
170: $outpar[10]=$$courseopt{$courselevelr};
171: $result=10;
172: }
173:
174: # ------------------------------------------------------ fourth, back to course
175: if (defined($csec)) {
176: if (defined($$courseopt{$seclevel})) {
177: $outpar[9]=$$courseopt{$seclevel};
178: $result=9;
179: }
180: if (defined($$courseopt{$seclevelm})) {
181: $outpar[8]=$$courseopt{$seclevelm};
182: $result=8;
183: }
184:
185: if (defined($$courseopt{$seclevelr})) {
186: $outpar[7]=$$courseopt{$seclevelr};
187: $result=7;
188: }
189: }
190: # ------------------------------------------------------ fifth, check gourse group
191: if (defined($cgroup)) {
192: if (defined($$courseopt{$grplevel})) {
193: $outpar[6]=$$courseopt{$grplevel};
194: $result=6;
195: }
196: if (defined($$courseopt{$grplevelm})) {
197: $outpar[5]=$$courseopt{$grplevelm};
198: $result=5;
199: }
200: if (defined($$courseopt{$grplevelr})) {
201: $outpar[4]=$$courseopt{$grplevelr};
202: $result=4;
203: }
204: }
205:
206: # ---------------------------------------------------------- fifth, check user
207:
208: if (defined($uname)) {
209: if (defined($$useropt{$courselevel})) {
210: $outpar[3]=$$useropt{$courselevel};
211: $result=3;
212: }
213:
214: if (defined($$useropt{$courselevelm})) {
215: $outpar[2]=$$useropt{$courselevelm};
216: $result=2;
217: }
218:
219: if (defined($$useropt{$courselevelr})) {
220: $outpar[1]=$$useropt{$courselevelr};
221: $result=1;
222: }
223: }
224: return ($result,@outpar);
225: }
226:
227: sub resetparmhash {
228: $parmhashid='';
229: }
230:
231: sub cacheparmhash {
232: if ($parmhashid eq $env{'request.course.fn'}) { return; }
233: my %parmhashfile;
234: if (tie(%parmhashfile,'GDBM_File',
235: $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
236: %parmhash=%parmhashfile;
237: untie %parmhashfile;
238: $parmhashid=$env{'request.course.fn'};
239: }
240: }
241:
242: sub resetsymbcache {
243: $symbsid='';
244: }
245:
246: sub symbcache {
247: my $id=shift;
248: if ($symbsid ne $env{'request.course.id'}) {
249: %symbs=();
250: }
251: unless ($symbs{$id}) {
252: my $navmap = Apache::lonnavmaps::navmap->new();
253: if ($id=~/\./) {
254: my $resource=$navmap->getById($id);
255: $symbs{$id}=$resource->symb();
256: } else {
257: my $resource=$navmap->getByMapPc($id);
258: $symbs{$id}=&Apache::lonnet::declutter($resource->src());
259: }
260: $symbsid=$env{'request.course.id'};
261: }
262: return $symbs{$id};
263: }
264:
265: sub resetrulescache {
266: $rulesid='';
267: }
268:
269: sub rulescache {
270: my $id=shift;
271: if ($rulesid ne $env{'request.course.id'}) {
272: %rules=();
273: }
274: unless (defined($rules{$id})) {
275: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
276: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
277: %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
278: $rulesid=$env{'request.course.id'};
279: }
280: return $rules{$id};
281: }
282:
283: sub preset_defaults {
284: my $type=shift;
285: if (&rulescache($type.'_action') eq 'default') {
286: # yes, there is something
287: return (&rulescache($type.'_hours'),
288: &rulescache($type.'_min'),
289: &rulescache($type.'_sec'),
290: &rulescache($type.'_value'));
291: } else {
292: # nothing there or something else
293: return ('','','','','');
294: }
295: }
296:
297: ##################################################
298: ##################################################
299: #
300: # Store a parameter by ID
301: #
302: # Takes
303: # - resource id
304: # - name of parameter
305: # - level
306: # - new value
307: # - new type
308: # - username
309: # - userdomain
310:
311: sub storeparm {
312: my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
313: &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup);
314: }
315:
316: #
317: # Store a parameter by symb
318: #
319: # Takes
320: # - symb
321: # - name of parameter
322: # - level
323: # - new value
324: # - new type
325: # - username
326: # - userdomain
327:
328: my %recstack;
329: sub storeparm_by_symb {
330: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup,$recflag)=@_;
331: unless ($recflag) {
332: # first time call
333: %recstack=();
334: $recflag=1;
335: }
336: # store parameter
337: &storeparm_by_symb_inner
338: ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup);
339: # don't do anything if parameter was reset
340: unless ($nval) { return; }
341: my ($prefix,$parm)=($spnam=~/^(.*[\_\.])([^\_\.]+)$/);
342: # remember that this was set
343: $recstack{$parm}=1;
344: # what does this trigger?
345: foreach my $triggered (split(/\:/,&rulescache($parm.'_triggers'))) {
346: # don't backfire
347: unless ((!$triggered) || ($recstack{$triggered})) {
348: my $action=&rulescache($triggered.'_action');
349: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
350: # set triggered parameter on same level
351: my $newspnam=$prefix.$triggered;
352: my $newvalue='';
353: my $active=1;
354: if ($action=~/^when\_setting/) {
355: # are there restrictions?
356: if (&rulescache($triggered.'_triggervalue')=~/\w/) {
357: $active=0;
358: foreach my $possiblevalue (split(/\s*\,\s*/,&rulescache($triggered.'_triggervalue'))) {
359: if (lc($possiblevalue) eq lc($nval)) { $active=1; }
360: }
361: }
362: $newvalue=&rulescache($triggered.'_value');
363: } else {
364: my $totalsecs=((&rulescache($triggered.'_days')*24+&rulescache($triggered.'_hours'))*60+&rulescache($triggered.'_min'))*60+&rulescache($triggered.'_sec');
365: if ($action=~/^later\_than/) {
366: $newvalue=$nval+$totalsecs;
367: } else {
368: $newvalue=$nval-$totalsecs;
369: }
370: }
371: if ($active) {
372: &storeparm_by_symb($symb,$newspnam,$snum,$newvalue,&rulescache($triggered.'_type'),
373: $uname,$udom,$csec,$cgroup,$recflag);
374: }
375: }
376: }
377: return '';
378: }
379:
380: sub storeparm_by_symb_inner {
381: # ---------------------------------------------------------- Get symb, map, etc
382: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
383: # ---------------------------------------------------------- Construct prefixes
384: $spnam=~s/\_([^\_]+)$/\.$1/;
385: my $map=(&Apache::lonnet::decode_symb($symb))[0];
386: my $symbparm=$symb.'.'.$spnam;
387: my $mapparm=$map.'___(all).'.$spnam;
388:
389: my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$spnam;
390: my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
391: my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
392:
393: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
394: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
395: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
396:
397: my $courselevel=$env{'request.course.id'}.'.'.$spnam;
398: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
399: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
400:
401: my $storeunder='';
402: if (($snum==14) || ($snum==3)) { $storeunder=$courselevel; }
403: if (($snum==13) || ($snum==2)) { $storeunder=$courselevelm; }
404: if (($snum==10) || ($snum==1)) { $storeunder=$courselevelr; }
405: if ($snum==9) { $storeunder=$seclevel; }
406: if ($snum==8) { $storeunder=$seclevelm; }
407: if ($snum==7) { $storeunder=$seclevelr; }
408: if ($snum==6) { $storeunder=$grplevel; }
409: if ($snum==5) { $storeunder=$grplevelm; }
410: if ($snum==4) { $storeunder=$grplevelr; }
411:
412:
413: my $delete;
414: if ($nval eq '') { $delete=1;}
415: my %storecontent = ($storeunder => $nval,
416: $storeunder.'.type' => $ntype);
417: my $reply='';
418: if ($snum>3) {
419: # ---------------------------------------------------------------- Store Course
420: #
421: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
422: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
423: # Expire sheets
424: &Apache::lonnet::expirespread('','','studentcalc');
425: if (($snum==10) || ($snum==7) || ($snum==4)) {
426: &Apache::lonnet::expirespread('','','assesscalc',$symb);
427: } elsif (($snum==11) || ($snum==8) || ($snum==5)) {
428: &Apache::lonnet::expirespread('','','assesscalc',$map);
429: } else {
430: &Apache::lonnet::expirespread('','','assesscalc');
431: }
432: # Store parameter
433: if ($delete) {
434: $reply=&Apache::lonnet::del
435: ('resourcedata',[keys(%storecontent)],$cdom,$cnum);
436: } else {
437: $reply=&Apache::lonnet::cput
438: ('resourcedata',\%storecontent,$cdom,$cnum);
439: }
440: &Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
441: } else {
442: # ------------------------------------------------------------------ Store User
443: #
444: # Expire sheets
445: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
446: if ($snum==1) {
447: &Apache::lonnet::expirespread
448: ($uname,$udom,'assesscalc',$symb);
449: } elsif ($snum==2) {
450: &Apache::lonnet::expirespread
451: ($uname,$udom,'assesscalc',$map);
452: } else {
453: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
454: }
455: # Store parameter
456: if ($delete) {
457: $reply=&Apache::lonnet::del
458: ('resourcedata',[keys(%storecontent)],$udom,$uname);
459: } else {
460: $reply=&Apache::lonnet::cput
461: ('resourcedata',\%storecontent,$udom,$uname);
462: }
463: &Apache::lonnet::devalidateuserresdata($uname,$udom);
464: }
465:
466: if ($reply=~/^error\:(.*)/) {
467: return "<font color=red>Write Error: $1</font>";
468: }
469: return '';
470: }
471:
472: ##################################################
473: ##################################################
474:
475: =pod
476:
477: =item valout
478:
479: Format a value for output.
480:
481: Inputs: $value, $type
482:
483: Returns: $value, formatted for output. If $type indicates it is a date,
484: localtime($value) is returned.
485:
486: =cut
487:
488: ##################################################
489: ##################################################
490: sub valout {
491: my ($value,$type)=@_;
492: my $result = '';
493: # Values of zero are valid.
494: if (! $value && $value ne '0') {
495: $result = ' ';
496: } else {
497: if ($type eq 'date_interval') {
498: my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
499: $year=$year-70;
500: $mday--;
501: if ($year) {
502: $result.=$year.' yrs ';
503: }
504: if ($mon) {
505: $result.=$mon.' mths ';
506: }
507: if ($mday) {
508: $result.=$mday.' days ';
509: }
510: if ($hour) {
511: $result.=$hour.' hrs ';
512: }
513: if ($min) {
514: $result.=$min.' mins ';
515: }
516: if ($sec) {
517: $result.=$sec.' secs ';
518: }
519: $result=~s/\s+$//;
520: } elsif (&isdateparm($type)) {
521: $result = localtime($value);
522: } else {
523: $result = $value;
524: }
525: }
526: return $result;
527: }
528:
529: ##################################################
530: ##################################################
531:
532: =pod
533:
534: =item plink
535:
536: Produces a link anchor.
537:
538: Inputs: $type,$dis,$value,$marker,$return,$call
539:
540: Returns: scalar with html code for a link which will envoke the
541: javascript function 'pjump'.
542:
543: =cut
544:
545: ##################################################
546: ##################################################
547: sub plink {
548: my ($type,$dis,$value,$marker,$return,$call)=@_;
549: my $winvalue=$value;
550: unless ($winvalue) {
551: if (&isdateparm($type)) {
552: $winvalue=$env{'form.recent_'.$type};
553: } else {
554: $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
555: }
556: }
557: my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/);
558: my ($hour,$min,$sec,$val)=&preset_defaults($parmname);
559: unless (defined($winvalue)) { $winvalue=$val; }
560: return '<table width="100%"><tr valign="top" align="right"><td><a name="'.$marker.'" /></td></tr><tr><td align="center">'.
561: '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
562: .$marker."','".$return."','".$call."','".$hour."','".$min."','".$sec."'".');">'.
563: &valout($value,$type).'</a></td></tr></table>';
564: }
565:
566: sub startpage {
567: my $r=shift;
568: my $loaditems = qq|onUnload="pclose()" onLoad="group_or_section('cgroup')"|;
569: my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','',
570: $loaditems);
571: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Table Mode Parameter Setting');
572: my $selscript=&Apache::loncommon::studentbrowser_javascript();
573: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
574: my $html=&Apache::lonxml::xmlbegin();
575: $r->print(<<ENDHEAD);
576: $html
577: <head>
578: <title>LON-CAPA Course Parameters</title>
579: <script>
580:
581: function pclose() {
582: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
583: "height=350,width=350,scrollbars=no,menubar=no");
584: parmwin.close();
585: }
586:
587: $pjump_def
588:
589: function psub() {
590: pclose();
591: if (document.parmform.pres_marker.value!='') {
592: document.parmform.action+='#'+document.parmform.pres_marker.value;
593: var typedef=new Array();
594: typedef=document.parmform.pres_type.value.split('_');
595: if (document.parmform.pres_type.value!='') {
596: if (typedef[0]=='date') {
597: eval('document.parmform.recent_'+
598: document.parmform.pres_type.value+
599: '.value=document.parmform.pres_value.value;');
600: } else {
601: eval('document.parmform.recent_'+typedef[0]+
602: '.value=document.parmform.pres_value.value;');
603: }
604: }
605: document.parmform.submit();
606: } else {
607: document.parmform.pres_value.value='';
608: document.parmform.pres_marker.value='';
609: }
610: }
611:
612: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
613: var options = "width=" + w + ",height=" + h + ",";
614: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
615: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
616: var newWin = window.open(url, wdwName, options);
617: newWin.focus();
618: }
619: </script>
620: $selscript
621: </head>
622: $bodytag
623: $breadcrumbs
624: <form method="post" action="/adm/parmset?action=settable" name="parmform">
625: <input type="hidden" value='' name="pres_value">
626: <input type="hidden" value='' name="pres_type">
627: <input type="hidden" value='' name="pres_marker">
628: <input type="hidden" value='1' name="prevvisit">
629: ENDHEAD
630: }
631:
632:
633: sub print_row {
634: my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
635: $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup)=@_;
636: # get the values for the parameter in cascading order
637: # empty levels will remain empty
638: my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
639: $rid,$$default{$which},$uname,$udom,$csec,$cgroup);
640: # get the type for the parameters
641: # problem: these may not be set for all levels
642: my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
643: $$name{$which}.'.type',
644: $rid,$$defaulttype{$which},$uname,$udom,$csec,$cgroup);
645: # cascade down manually
646: my $cascadetype=$$defaulttype{$which};
647: for (my $i=14;$i>0;$i--) {
648: if ($typeoutpar[$i]) {
649: $cascadetype=$typeoutpar[$i];
650: } else {
651: $typeoutpar[$i]=$cascadetype;
652: }
653: }
654: my $parm=$$display{$which};
655:
656: if ($parmlev eq 'full') {
657: $r->print('<td bgcolor='.$defbgtwo.' align="center">'
658: .$$part{$which}.'</td>');
659: } else {
660: $parm=~s|\[.*\]\s||g;
661: }
662: my $automatic=&rulescache(($which=~/\_([^\_]+)$/)[0].'_triggers');
663: if ($automatic) {
664: $parm.='<font color="red"><br />'.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).'</font>';
665: }
666: $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
667:
668: my $thismarker=$which;
669: $thismarker=~s/^parameter\_//;
670: my $mprefix=$rid.'&'.$thismarker.'&';
671:
672: if ($parmlev eq 'general') {
673:
674: if ($uname) {
675: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
676: } elsif ($cgroup) {
677: &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
678: } elsif ($csec) {
679: &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
680: } else {
681: &print_td($r,14,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
682: }
683: } elsif ($parmlev eq 'map') {
684:
685: if ($uname) {
686: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
687: } elsif ($cgroup) {
688: &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
689: } elsif ($csec) {
690: &print_td($r,8,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
691: } else {
692: &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
693: }
694: } else {
695:
696: &print_td($r,14,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
697:
698: &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
699: &print_td($r,12,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
700: &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
701: &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
702:
703: if ($csec) {
704: &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
705: &print_td($r,8,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
706: &print_td($r,7,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
707: }
708:
709: if ($cgroup) {
710: &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
711: &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
712: &print_td($r,4,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
713: }
714:
715: if ($uname) {
716: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
717: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
718: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
719: }
720:
721: } # end of $parmlev if/else
722:
723: $r->print('<td bgcolor=#CCCCFF align="center">'.
724: &valout($outpar[$result],$typeoutpar[$result]).'</td>');
725:
726: if ($parmlev eq 'full') {
727: my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
728: '.'.$$name{$which},$$symbp{$rid});
729: my $sessionvaltype=$typeoutpar[$result];
730: if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
731: $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
732: &valout($sessionval,$sessionvaltype).' '.
733: '</font></td>');
734: }
735: $r->print('</tr>');
736: $r->print("\n");
737: }
738:
739: sub print_td {
740: my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
741: $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
742: ' align="center">');
743: if ($which<11 || $which > 12) {
744: $r->print(&plink($$typeoutpar[$which],
745: $$display{$value},$$outpar[$which],
746: $mprefix."$which",'parmform.pres','psub'));
747: } else {
748: $r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
749: }
750: $r->print('</td>'."\n");
751: }
752:
753:
754: =pod
755:
756: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
757:
758: Input: See list below:
759:
760: =over 4
761:
762: =item B<ids>: An array that will contain all of the ids in the course.
763:
764: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
765:
766: =item B<keyp>: hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
767:
768: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
769:
770: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
771:
772: =item B<allkeys>: hash, full key to part->display value (what's display value?)
773:
774: =item B<allmaps>: hash, ???
775:
776: =item B<fcat>: ???
777:
778: =item B<defp>: hash, ???
779:
780: =item B<mapp>: ??
781:
782: =item B<symbp>: hash, id->full sym?
783:
784: =back
785:
786: =cut
787:
788: sub extractResourceInformation {
789: my $ids = shift;
790: my $typep = shift;
791: my $keyp = shift;
792: my $allparms = shift;
793: my $allparts = shift;
794: my $allmaps = shift;
795: my $mapp = shift;
796: my $symbp = shift;
797: my $maptitles=shift;
798: my $uris=shift;
799: my $keyorder=shift;
800: my $defkeytype=shift;
801:
802: my $keyordercnt=100;
803:
804: my $navmap = Apache::lonnavmaps::navmap->new();
805: my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
806: foreach my $resource (@allres) {
807: my $id=$resource->id();
808: my ($mapid,$resid)=split(/\./,$id);
809: if ($mapid eq '0') { next; }
810: $$ids[$#$ids+1]=$id;
811: my $srcf=$resource->src();
812: $srcf=~/\.(\w+)$/;
813: $$typep{$id}=$1;
814: $$keyp{$id}='';
815: $$uris{$id}=$srcf;
816: foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
817: if ($_=~/^parameter\_(.*)/) {
818: my $key=$_;
819: # Hidden parameters
820: if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm') {
821: next;
822: }
823: my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
824: my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
825: my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
826: #
827: # allparms is a hash of parameter names
828: #
829: my $parmdis = $display;
830: $parmdis =~ s/\[Part.*$//g;
831: $$allparms{$name}=$parmdis;
832: $$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type');
833: #
834: # allparts is a hash of all parts
835: #
836: $$allparts{$part} = "Part: $part";
837: #
838: # Remember all keys going with this resource
839: #
840: if ($$keyp{$id}) {
841: $$keyp{$id}.=','.$key;
842: } else {
843: $$keyp{$id}=$key;
844: }
845: #
846: # Put in order
847: #
848: unless ($$keyorder{$key}) {
849: $$keyorder{$key}=$keyordercnt;
850: $keyordercnt++;
851: }
852:
853: }
854: }
855: $$mapp{$id}=
856: &Apache::lonnet::declutter($resource->enclosing_map_src());
857: $$mapp{$mapid}=$$mapp{$id};
858: $$allmaps{$mapid}=$$mapp{$id};
859: if ($mapid eq '1') {
860: $$maptitles{$mapid}='Main Course Documents';
861: } else {
862: $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));
863: }
864: $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
865: $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
866: $$symbp{$mapid}=$$mapp{$id}.'___(all)';
867: }
868: }
869:
870:
871: ##################################################
872: ##################################################
873:
874: sub isdateparm {
875: my $type=shift;
876: return (($type=~/^date/) && (!($type eq 'date_interval')));
877: }
878:
879: sub parmmenu {
880: my ($r,$allparms,$pscat,$keyorder)=@_;
881: my $tempkey;
882: $r->print(<<ENDSCRIPT);
883: <script type="text/javascript">
884: function checkall(value, checkName) {
885: for (i=0; i<document.forms.parmform.elements.length; i++) {
886: ele = document.forms.parmform.elements[i];
887: if (ele.name == checkName) {
888: document.forms.parmform.elements[i].checked=value;
889: }
890: }
891: }
892:
893: function checkthis(thisvalue, checkName) {
894: for (i=0; i<document.forms.parmform.elements.length; i++) {
895: ele = document.forms.parmform.elements[i];
896: if (ele.name == checkName) {
897: if (ele.value == thisvalue) {
898: document.forms.parmform.elements[i].checked=true;
899: }
900: }
901: }
902: }
903:
904: function checkdates() {
905: checkthis('duedate','pscat');
906: checkthis('opendate','pscat');
907: checkthis('answerdate','pscat');
908: }
909:
910: function checkdisset() {
911: checkthis('discussend','pscat');
912: checkthis('discusshide','pscat');
913: }
914:
915: function checkcontdates() {
916: checkthis('contentopen','pscat');
917: checkthis('contentclose','pscat');
918: }
919:
920:
921: function checkvisi() {
922: checkthis('hiddenresource','pscat');
923: checkthis('encrypturl','pscat');
924: checkthis('problemstatus','pscat');
925: checkthis('contentopen','pscat');
926: checkthis('opendate','pscat');
927: }
928:
929: function checkparts() {
930: checkthis('hiddenparts','pscat');
931: checkthis('display','pscat');
932: checkthis('ordered','pscat');
933: }
934:
935: function checkstandard() {
936: checkall(false,'pscat');
937: checkdates();
938: checkthis('weight','pscat');
939: checkthis('maxtries','pscat');
940: }
941:
942: </script>
943: ENDSCRIPT
944: $r->print();
945: $r->print("\n<table><tr>");
946: my $cnt=0;
947: foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) {
948: $r->print("\n<td><font size='-1'><label><input type='checkbox' name='pscat' ");
949: $r->print('value="'.$tempkey.'"');
950: if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
951: $r->print(' checked');
952: }
953: $r->print('>'.$$allparms{$tempkey}.'</label></font></td>');
954: $cnt++;
955: if ($cnt==3) {
956: $r->print("</tr>\n<tr>");
957: $cnt=0;
958: }
959: }
960: $r->print('
961: </tr><tr><td>
962: <a href="javascript:checkall(true, \'pscat\')">Select All</a><br />
963: <a href="javascript:checkstandard()">Select Common Only</a>
964: </td><td>
965: <a href="javascript:checkdates()">Add Problem Dates</a>
966: <a href="javascript:checkcontdates()">Add Content Dates</a><br />
967: <a href="javascript:checkdisset()">Add Discussion Settings</a>
968: <a href="javascript:checkvisi()">Add Visibilities</a><br />
969: <a href="javascript:checkparts()">Add Part Parameters</a>
970: </td><td>
971: <a href="javascript:checkall(false, \'pscat\')">Unselect All</a>
972: </td>
973: ');
974: $r->print('</tr></table>');
975: }
976:
977: sub partmenu {
978: my ($r,$allparts,$psprt)=@_;
979: $r->print('<select multiple name="psprt" size="8">');
980: $r->print('<option value="all"');
981: $r->print(' selected') unless (@{$psprt});
982: $r->print('>'.&mt('All Parts').'</option>');
983: my %temphash=();
984: foreach (@{$psprt}) { $temphash{$_}=1; }
985: foreach my $tempkey (sort {
986: if ($a==$b) { return ($a cmp $b) } else { return ($a <=> $b); }
987: } keys(%{$allparts})) {
988: unless ($tempkey =~ /\./) {
989: $r->print('<option value="'.$tempkey.'"');
990: if ($$psprt[0] eq "all" || $temphash{$tempkey}) {
991: $r->print(' selected');
992: }
993: $r->print('>'.$$allparts{$tempkey}.'</option>');
994: }
995: }
996: $r->print('</select>');
997: }
998:
999: sub usermenu {
1000: my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev)=@_;
1001: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
1002: &Apache::loncommon::selectstudent_link('parmform','uname','udom');
1003: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1004: my %lt=&Apache::lonlocal::texthash(
1005: 'se' => "Section",
1006: 'gr' => "Group",
1007: 'fu' => "For User",
1008: 'oi' => "or ID",
1009: 'ad' => "at Domain"
1010: );
1011: my %sectionhash=();
1012: my $sections='';
1013: my $numsec = &Apache::loncommon::get_sections(
1014: $env{'course.'.$env{'request.course.id'}.'.domain'},
1015: $env{'course.'.$env{'request.course.id'}.'.num'},
1016: \%sectionhash);
1017: my $groups;
1018: my %grouphash;
1019: my $numgrp = &Apache::loncommon::coursegroups(
1020: \%grouphash,
1021: $env{'course.'.$env{'request.course.id'}.'.domain'},
1022: $env{'course.'.$env{'request.course.id'}.'.num'});
1023: if ($numsec > 0) {
1024: $sections=$lt{'se'}.': <select name="csec"';
1025: if ($numsec && $numgrp && $parmlev ne 'full') {
1026: $sections .= qq| onchange="group_or_section('csec')" |;
1027: }
1028: $sections .= '>';
1029: foreach ('',sort keys %sectionhash) {
1030: $sections.='<option value="'.$_.'"'.
1031: ($_ eq $csec?'selected="selected"':'').'>'.$_.'</option>';
1032: }
1033: $sections.='</select>';
1034: }
1035: if ($numsec && $numgrp && $parmlev ne 'full') {
1036: $sections .= ' or ';
1037: $sections .= qq|
1038: <script type="text/javascript">
1039: function group_or_section(caller) {
1040: if (caller == "cgroup") {
1041: if (document.parmform.cgroup.selectedIndex != 0) {
1042: document.parmform.csec.selectedIndex = 0;
1043: }
1044: } else {
1045: if (document.parmform.csec.selectedIndex != 0) {
1046: document.parmform.cgroup.selectedIndex = 0;
1047: }
1048: }
1049: }
1050: </script>
1051: |;
1052: } else {
1053: $sections .= qq|
1054: <script type="text/javascript">
1055: function group_or_section(caller) {
1056: return;
1057: }
1058: </script>
1059: |;
1060: }
1061: if ($numgrp > 0) {
1062: $groups=$lt{'gr'}.': <select name="cgroup"';
1063: if ($numsec && $numgrp && $env{'form.action'} eq 'settable') {
1064: $groups .= qq| onchange="group_or_section('cgroup')" |;
1065: }
1066: $groups .= '>';
1067: foreach ('',sort keys %grouphash) {
1068: $groups.='<option value="'.$_.'"'.
1069: ($_ eq $cgroup?'selected="selected"':'').'>'.
1070: $_.'</option>';
1071: }
1072: $groups.='</select>';
1073: }
1074: $r->print(<<ENDMENU);
1075: <b>
1076: $sections
1077: $groups
1078: <br />
1079: $lt{'fu'}
1080: <input type="text" value="$uname" size="12" name="uname" />
1081: $lt{'oi'}
1082: <input type="text" value="$id" size="12" name="id" />
1083: $lt{'ad'}
1084: $chooseopt
1085: </b>
1086: ENDMENU
1087: }
1088:
1089: sub displaymenu {
1090: my ($r,$allparms,$allparts,$pscat,$psprt,$keyorder)=@_;
1091: $r->print('<table border="1"><tr><th>'.&mt('Select Parameters to View').'</th><th>'.
1092: &mt('Select Parts to View').'</th></tr><tr><td>');
1093: &parmmenu($r,$allparms,$pscat,$keyorder);
1094: $r->print('</td><td>');
1095: &partmenu($r,$allparts,$psprt);
1096: $r->print('</td></tr></table>');
1097: }
1098:
1099: sub mapmenu {
1100: my ($r,$allmaps,$pschp,$maptitles)=@_;
1101: $r->print('<b>'.&mt('Select Enclosing Map or Folder').'</b> ');
1102: $r->print('<select name="pschp">');
1103: $r->print('<option value="all">'.&mt('All Maps or Folders').'</option>');
1104: foreach (sort {$$allmaps{$a} cmp $$allmaps{$b}} keys %{$allmaps}) {
1105: $r->print('<option value="'.$_.'"');
1106: if (($pschp eq $_)) { $r->print(' selected'); }
1107: $r->print('>'.$$maptitles{$_}.($$allmaps{$_}!~/^uploaded/?' ['.$$allmaps{$_}.']':'').'</option>');
1108: }
1109: $r->print("</select>");
1110: }
1111:
1112: sub levelmenu {
1113: my ($r,$alllevs,$parmlev)=@_;
1114: $r->print('<b>'.&mt('Select Parameter Level').
1115: &Apache::loncommon::help_open_topic('Course_Parameter_Levels').'</b> ');
1116: $r->print('<select name="parmlev">');
1117: foreach (reverse sort keys %{$alllevs}) {
1118: $r->print('<option value="'.$$alllevs{$_}.'"');
1119: if ($parmlev eq $$alllevs{$_}) {
1120: $r->print(' selected');
1121: }
1122: $r->print('>'.$_.'</option>');
1123: }
1124: $r->print("</select>");
1125: }
1126:
1127:
1128: sub sectionmenu {
1129: my ($r,$selectedsections)=@_;
1130: my %sectionhash=();
1131: my $sections='';
1132: my $numsec = &Apache::loncommon::get_sections(
1133: $env{'course.'.$env{'request.course.id'}.'.domain'},
1134: $env{'course.'.$env{'request.course.id'}.'.num'},
1135: \%sectionhash);
1136: if ($numsec) {
1137: $r->print('<select name="Section" multiple="true" size="8" >');
1138: foreach my $s ('all',sort keys %sectionhash) {
1139: $r->print(' <option value="'.$s.'"');
1140: foreach (@{$selectedsections}) {
1141: if ($s eq $_) {
1142: $r->print(' selected');
1143: last;
1144: }
1145: }
1146: $r->print('>'.$s."</option>\n");
1147: }
1148: $r->print("</select>\n");
1149: }
1150: }
1151:
1152: sub groupmenu {
1153: my ($r,$selectedgroups)=@_;
1154: my %grouphash;
1155: my $numgrp = &Apache::loncommon::coursegroups(
1156: \%grouphash,
1157: $env{'course.'.$env{'request.course.id'}.'.domain'},
1158: $env{'course.'.$env{'request.course.id'}.'.num'});
1159: if ($numgrp) {
1160: $r->print('<select name="Group" multiple="true" size="8" >');
1161: foreach my $group (sort(keys(%grouphash))) {
1162: $r->print(' <option value="'.$group.'"');
1163: foreach (@{$selectedgroups}) {
1164: if ($group eq $_) {
1165: $r->print(' selected');
1166: last;
1167: }
1168: }
1169: $r->print('>'.$group."</option>\n");
1170: }
1171: $r->print("</select>\n");
1172: }
1173: }
1174:
1175:
1176: sub keysplit {
1177: my $keyp=shift;
1178: return (split(/\,/,$keyp));
1179: }
1180:
1181: sub keysinorder {
1182: my ($name,$keyorder)=@_;
1183: return sort {
1184: $$keyorder{$a} <=> $$keyorder{$b};
1185: } (keys %{$name});
1186: }
1187:
1188: sub keysinorder_bytype {
1189: my ($name,$keyorder)=@_;
1190: return sort {
1191: my $ta=(split('_',$a))[-1];
1192: my $tb=(split('_',$b))[-1];
1193: if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) {
1194: return ($a cmp $b);
1195: }
1196: $$keyorder{'parameter_0_'.$ta} <=> $$keyorder{'parameter_0_'.$tb};
1197: } (keys %{$name});
1198: }
1199:
1200: sub keysindisplayorder {
1201: my ($name,$keyorder)=@_;
1202: return sort {
1203: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
1204: } (keys %{$name});
1205: }
1206:
1207: sub sortmenu {
1208: my ($r,$sortorder)=@_;
1209: $r->print('<br /><label><input type="radio" name="sortorder" value="realmstudent"');
1210: if ($sortorder eq 'realmstudent') {
1211: $r->print(' checked="on"');
1212: }
1213: $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
1214: $r->print('</label><br /><label><input type="radio" name="sortorder" value="studentrealm"');
1215: if ($sortorder eq 'studentrealm') {
1216: $r->print(' checked="on"');
1217: }
1218: $r->print(' />'.&mt('Sort by student (group/section) first, then realm').
1219: '</label>');
1220: }
1221:
1222: sub standardkeyorder {
1223: return ('parameter_0_opendate' => 1,
1224: 'parameter_0_duedate' => 2,
1225: 'parameter_0_answerdate' => 3,
1226: 'parameter_0_interval' => 4,
1227: 'parameter_0_weight' => 5,
1228: 'parameter_0_maxtries' => 6,
1229: 'parameter_0_hinttries' => 7,
1230: 'parameter_0_contentopen' => 8,
1231: 'parameter_0_contentclose' => 9,
1232: 'parameter_0_type' => 10,
1233: 'parameter_0_problemstatus' => 11,
1234: 'parameter_0_hiddenresource' => 12,
1235: 'parameter_0_hiddenparts' => 13,
1236: 'parameter_0_display' => 14,
1237: 'parameter_0_ordered' => 15,
1238: 'parameter_0_tol' => 16,
1239: 'parameter_0_sig' => 17,
1240: 'parameter_0_turnoffunit' => 18,
1241: 'parameter_0_discussend' => 19,
1242: 'parameter_0_discusshide' => 20);
1243: }
1244:
1245: ##################################################
1246: ##################################################
1247:
1248: =pod
1249:
1250: =item assessparms
1251:
1252: Show assessment data and parameters. This is a large routine that should
1253: be simplified and shortened... someday.
1254:
1255: Inputs: $r
1256:
1257: Returns: nothing
1258:
1259: Variables used (guessed by Jeremy):
1260:
1261: =over 4
1262:
1263: =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.
1264:
1265: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
1266:
1267: =item B<allmaps>:
1268:
1269: =back
1270:
1271: =cut
1272:
1273: ##################################################
1274: ##################################################
1275: sub assessparms {
1276:
1277: my $r=shift;
1278:
1279: my @ids=();
1280: my %symbp=();
1281: my %mapp=();
1282: my %typep=();
1283: my %keyp=();
1284: my %uris=();
1285: my %maptitles=();
1286:
1287: # -------------------------------------------------------- Variable declaration
1288:
1289: my %allmaps=();
1290: my %alllevs=();
1291:
1292: my $uname;
1293: my $udom;
1294: my $uhome;
1295: my $csec;
1296: my $cgroup;
1297:
1298: my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
1299:
1300: $alllevs{'Resource Level'}='full';
1301: $alllevs{'Map/Folder Level'}='map';
1302: $alllevs{'Course Level'}='general';
1303:
1304: my %allparms;
1305: my %allparts;
1306: #
1307: # Order in which these parameters will be displayed
1308: #
1309: my %keyorder=&standardkeyorder();
1310:
1311: @ids=();
1312: %symbp=();
1313: %typep=();
1314:
1315: my $message='';
1316:
1317: $csec=$env{'form.csec'};
1318: $cgroup=$env{'form.cgroup'};
1319:
1320: if ($udom=$env{'form.udom'}) {
1321: } elsif ($udom=$env{'request.role.domain'}) {
1322: } elsif ($udom=$env{'user.domain'}) {
1323: } else {
1324: $udom=$r->dir_config('lonDefDomain');
1325: }
1326:
1327: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
1328: my $pschp=$env{'form.pschp'};
1329: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
1330: if (!@psprt) { $psprt[0]='0'; }
1331:
1332: my $pssymb='';
1333: my $parmlev='';
1334:
1335: unless ($env{'form.parmlev'}) {
1336: $parmlev = 'map';
1337: } else {
1338: $parmlev = $env{'form.parmlev'};
1339: }
1340:
1341: # ----------------------------------------------- Was this started from grades?
1342:
1343: if (($env{'form.command'} eq 'set') && ($env{'form.url'})
1344: && (!$env{'form.dis'})) {
1345: my $url=$env{'form.url'};
1346: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1347: $pssymb=&Apache::lonnet::symbread($url);
1348: if (!@pscat) { @pscat=('all'); }
1349: $pschp='';
1350: $parmlev = 'full';
1351: } elsif ($env{'form.symb'}) {
1352: $pssymb=$env{'form.symb'};
1353: if (!@pscat) { @pscat=('all'); }
1354: $pschp='';
1355: $parmlev = 'full';
1356: } else {
1357: $env{'form.url'}='';
1358: }
1359:
1360: my $id=$env{'form.id'};
1361: if (($id) && ($udom)) {
1362: $uname=(&Apache::lonnet::idget($udom,$id))[1];
1363: if ($uname) {
1364: $id='';
1365: } else {
1366: $message=
1367: "<font color=red>".&mt("Unknown ID")." '$id' ".
1368: &mt('at domain')." '$udom'</font>";
1369: }
1370: } else {
1371: $uname=$env{'form.uname'};
1372: }
1373: unless ($udom) { $uname=''; }
1374: $uhome='';
1375: if ($uname) {
1376: $uhome=&Apache::lonnet::homeserver($uname,$udom);
1377: if ($uhome eq 'no_host') {
1378: $message=
1379: "<font color=red>".&mt("Unknown user")." '$uname' ".
1380: &mt("at domain")." '$udom'</font>";
1381: $uname='';
1382: } else {
1383: $csec=&Apache::lonnet::getsection($udom,$uname,
1384: $env{'request.course.id'});
1385:
1386: if ($csec eq '-1') {
1387: $message="<font color=red>".
1388: &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
1389: &mt("not in this course")."</font>";
1390: $uname='';
1391: $csec=$env{'form.csec'};
1392: $cgroup=$env{'form.cgroup'};
1393: } else {
1394: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1395: ('firstname','middlename','lastname','generation','id'));
1396: $message="\n<p>\n".&mt("Full Name").": ".
1397: $name{'firstname'}.' '.$name{'middlename'}.' '
1398: .$name{'lastname'}.' '.$name{'generation'}.
1399: "<br>\n".&mt('ID').": ".$name{'id'}.'<p>';
1400: }
1401: my $grouplist = &Apache::lonnet::get_users_groups(
1402: $udom,$uname,$env{'request.course.id'});
1403: if ($grouplist) {
1404: my @groups = split(/:/,$grouplist);
1405: @groups = sort(@groups);
1406: $cgroup = $groups[0];
1407: }
1408: }
1409: }
1410:
1411: unless ($csec) { $csec=''; }
1412: unless ($cgroup) { $cgroup=''; }
1413:
1414: # --------------------------------------------------------- Get all assessments
1415: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
1416: \%mapp, \%symbp,\%maptitles,\%uris,
1417: \%keyorder);
1418:
1419: $mapp{'0.0'} = '';
1420: $symbp{'0.0'} = '';
1421:
1422: # ---------------------------------------------------------- Anything to store?
1423: if ($env{'form.pres_marker'}) {
1424: my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
1425: my @values=split(/\&\&\&/,$env{'form.pres_value'});
1426: my @types=split(/\&\&\&/,$env{'form.pres_type'});
1427: for (my $i=0;$i<=$#markers;$i++) {
1428: $message.=&storeparm(split(/\&/,$markers[$i]),
1429: $values[$i],
1430: $types[$i],
1431: $uname,$udom,$csec,$cgroup);
1432: }
1433: # ---------------------------------------------------------------- Done storing
1434: $message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
1435: }
1436: #----------------------------------------------- if all selected, fill in array
1437: if ($pscat[0] eq "all") {@pscat = (keys %allparms);}
1438: if (!@pscat) { @pscat=('duedate','opendate','answerdate','weight','maxtries') };
1439: if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
1440: # ------------------------------------------------------------------ Start page
1441:
1442: &startpage($r);
1443:
1444: foreach ('tolerance','date_default','date_start','date_end',
1445: 'date_interval','int','float','string') {
1446: $r->print('<input type="hidden" value="'.
1447: $env{'form.recent_'.$_}.'" name="recent_'.$_.'">');
1448: }
1449:
1450: if (!$pssymb) {
1451: $r->print('<table border="1"><tr><td>');
1452: &levelmenu($r,\%alllevs,$parmlev);
1453: if ($parmlev ne 'general') {
1454: $r->print('<td>');
1455: &mapmenu($r,\%allmaps,$pschp,\%maptitles);
1456: $r->print('</td>');
1457: }
1458: $r->print('</td></tr></table>');
1459: &displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder);
1460: } else {
1461: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
1462: $r->print(&mt('Specific Resource').": ".$resource.
1463: '<input type="hidden" value="'.$pssymb.'" name="symb">'.
1464: '<br /><label><b>'.&mt('Show all parts').': <input type="checkbox" name="psprt" value="all"'.
1465: ($env{'form.psprt'}?' checked="checked"':'').' /></b></label><br />');
1466: }
1467: &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev);
1468:
1469: $r->print('<p>'.$message.'</p>');
1470:
1471: $r->print('<br /><input type="submit" name="dis" value="'.&mt("Update Parameter Display").'" />');
1472:
1473: my @temp_pscat;
1474: map {
1475: my $cat = $_;
1476: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
1477: } @pscat;
1478:
1479: @pscat = @temp_pscat;
1480:
1481: if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
1482: # ----------------------------------------------------------------- Start Table
1483: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
1484: my $csuname=$env{'user.name'};
1485: my $csudom=$env{'user.domain'};
1486:
1487: if ($parmlev eq 'full') {
1488: my $coursespan=$csec?8:5;
1489: if ($cgroup ne '') {
1490: $coursespan += 3;
1491: }
1492:
1493: $r->print('<p><table border=2>');
1494: $r->print('<tr><td colspan=5></td>');
1495: $r->print('<th colspan='.($coursespan).'>'.&mt('Any User').'</th>');
1496: if ($uname) {
1497: $r->print("<th colspan=3 rowspan=2>");
1498: $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
1499: }
1500: my %lt=&Apache::lonlocal::texthash(
1501: 'pie' => "Parameter in Effect",
1502: 'csv' => "Current Session Value",
1503: 'at' => 'at',
1504: 'rl' => "Resource Level",
1505: 'ic' => 'in Course',
1506: 'aut' => "Assessment URL and Title",
1507: 'type' => 'Type',
1508: 'emof' => "Enclosing Map or Folder",
1509: 'part' => 'Part',
1510: 'pn' => 'Parameter Name',
1511: 'def' => 'default',
1512: 'femof' => 'from Enclosing Map or Folder',
1513: 'gen' => 'general',
1514: 'foremf' => 'for Enclosing Map or Folder',
1515: 'fr' => 'for Resource'
1516: );
1517: $r->print(<<ENDTABLETWO);
1518: <th rowspan=3>$lt{'pie'}</th>
1519: <th rowspan=3>$lt{'csv'}<br>($csuname $lt{'at'} $csudom)</th>
1520: </tr><tr><td colspan=5></td><th colspan=2>$lt{'ic'}</th><th colspan=2>$lt{'rl'}</th>
1521: <th colspan=1>$lt{'ic'}</th>
1522:
1523: ENDTABLETWO
1524: if ($csec) {
1525: $r->print("<th colspan=3>".
1526: &mt("in Section")." $csec</th>");
1527: }
1528: if ($cgroup) {
1529: $r->print("<th colspan=3>".
1530: &mt("in Group")." $cgroup</th>");
1531: }
1532: $r->print(<<ENDTABLEHEADFOUR);
1533: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
1534: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
1535: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
1536: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
1537: ENDTABLEHEADFOUR
1538:
1539: if ($csec) {
1540: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1541: }
1542:
1543: if ($cgroup) {
1544: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1545: }
1546:
1547: if ($uname) {
1548: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1549: }
1550:
1551: $r->print('</tr>');
1552:
1553: my $defbgone='';
1554: my $defbgtwo='';
1555: my $defbgthree = '';
1556:
1557: foreach (@ids) {
1558:
1559: my $rid=$_;
1560: my ($inmapid)=($rid=~/\.(\d+)$/);
1561:
1562: if ((!$pssymb &&
1563: (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
1564: ||
1565: ($pssymb && $pssymb eq $symbp{$rid})) {
1566: # ------------------------------------------------------ Entry for one resource
1567: if ($defbgone eq '"#E0E099"') {
1568: $defbgone='"#E0E0DD"';
1569: } else {
1570: $defbgone='"#E0E099"';
1571: }
1572: if ($defbgtwo eq '"#FFFF99"') {
1573: $defbgtwo='"#FFFFDD"';
1574: } else {
1575: $defbgtwo='"#FFFF99"';
1576: }
1577: if ($defbgthree eq '"#FFBB99"') {
1578: $defbgthree='"#FFBBDD"';
1579: } else {
1580: $defbgthree='"#FFBB99"';
1581: }
1582:
1583: my $thistitle='';
1584: my %name= ();
1585: undef %name;
1586: my %part= ();
1587: my %display=();
1588: my %type= ();
1589: my %default=();
1590: my $uri=&Apache::lonnet::declutter($uris{$rid});
1591:
1592: foreach (&keysplit($keyp{$rid})) {
1593: my $tempkeyp = $_;
1594: if (grep $_ eq $tempkeyp, @catmarker) {
1595: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
1596: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
1597: $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
1598: unless ($display{$_}) { $display{$_}=''; }
1599: $display{$_}.=' ('.$name{$_}.')';
1600: $default{$_}=&Apache::lonnet::metadata($uri,$_);
1601: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
1602: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
1603: }
1604: }
1605: my $totalparms=scalar keys %name;
1606: if ($totalparms>0) {
1607: my $firstrow=1;
1608: my $title=&Apache::lonnet::gettitle($symbp{$rid});
1609: $r->print('<tr><td bgcolor='.$defbgone.
1610: ' rowspan='.$totalparms.
1611: '><tt><font size=-1>'.
1612: join(' / ',split(/\//,$uri)).
1613: '</font></tt><p><b>'.
1614: "<a href=\"javascript:openWindow('".
1615: &Apache::lonnet::clutter($uri).'?symb='.
1616: &Apache::lonnet::escape($symbp{$rid}).
1617: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
1618: " TARGET=_self>$title");
1619:
1620: if ($thistitle) {
1621: $r->print(' ('.$thistitle.')');
1622: }
1623: $r->print('</a></b></td>');
1624: $r->print('<td bgcolor='.$defbgtwo.
1625: ' rowspan='.$totalparms.'>'.$typep{$rid}.
1626: '</td>');
1627:
1628: $r->print('<td bgcolor='.$defbgone.
1629: ' rowspan='.$totalparms.
1630: '>'.$maptitles{$mapp{$rid}}.'</td>');
1631:
1632: foreach (&keysinorder_bytype(\%name,\%keyorder)) {
1633: unless ($firstrow) {
1634: $r->print('<tr>');
1635: } else {
1636: undef $firstrow;
1637: }
1638: &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
1639: \%type,\%display,$defbgone,$defbgtwo,
1640: $defbgthree,$parmlev,$uname,$udom,$csec,
1641: $cgroup);
1642: }
1643: }
1644: }
1645: } # end foreach ids
1646: # -------------------------------------------------- End entry for one resource
1647: $r->print('</table>');
1648: } # end of full
1649: #--------------------------------------------------- Entry for parm level map
1650: if ($parmlev eq 'map') {
1651: my $defbgone = '"E0E099"';
1652: my $defbgtwo = '"FFFF99"';
1653: my $defbgthree = '"FFBB99"';
1654:
1655: my %maplist;
1656:
1657: if ($pschp eq 'all') {
1658: %maplist = %allmaps;
1659: } else {
1660: %maplist = ($pschp => $mapp{$pschp});
1661: }
1662:
1663: #-------------------------------------------- for each map, gather information
1664: my $mapid;
1665: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
1666: my $maptitle = $maplist{$mapid};
1667:
1668: #----------------------- loop through ids and get all parameter types for map
1669: #----------------------------------------- and associated information
1670: my %name = ();
1671: my %part = ();
1672: my %display = ();
1673: my %type = ();
1674: my %default = ();
1675: my $map = 0;
1676:
1677: # $r->print("Catmarker: @catmarker<br />\n");
1678:
1679: foreach (@ids) {
1680: ($map)=(/([\d]*?)\./);
1681: my $rid = $_;
1682:
1683: # $r->print("$mapid:$map: $rid <br /> \n");
1684:
1685: if ($map eq $mapid) {
1686: my $uri=&Apache::lonnet::declutter($uris{$rid});
1687: # $r->print("Keys: $keyp{$rid} <br />\n");
1688:
1689: #--------------------------------------------------------------------
1690: # @catmarker contains list of all possible parameters including part #s
1691: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1692: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1693: # When storing information, store as part 0
1694: # When requesting information, request from full part
1695: #-------------------------------------------------------------------
1696: foreach (&keysplit($keyp{$rid})) {
1697: my $tempkeyp = $_;
1698: my $fullkeyp = $tempkeyp;
1699: $tempkeyp =~ s/_\w+_/_0_/;
1700:
1701: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1702: $part{$tempkeyp}="0";
1703: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1704: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1705: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1706: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1707: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1708: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1709: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1710: }
1711: } # end loop through keys
1712: }
1713: } # end loop through ids
1714:
1715: #---------------------------------------------------- print header information
1716: my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
1717: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
1718: $r->print(<<ENDMAPONE);
1719: <center><h4>
1720: Set Defaults for All Resources in $foldermap<br />
1721: <font color="red"><i>$showtitle</i></font><br />
1722: Specifically for
1723: ENDMAPONE
1724: if ($uname) {
1725: my $person=&Apache::loncommon::plainname($uname,$udom);
1726: $r->print(&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
1727: &mt('in')." \n");
1728: } else {
1729: $r->print("<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n");
1730: }
1731: if ($cgroup) {
1732: $r->print(&mt("Group")." <font color=\"red\"><i>$cgroup".
1733: "</i></font> ".&mt('of')." \n");
1734: $csec = '';
1735: } elsif ($csec) {
1736: $r->print(&mt("Section")." <font color=\"red\"><i>$csec".
1737: "</i></font> ".&mt('of')." \n");
1738: }
1739: $r->print("<font color=\"red\"><i>$coursename</i></font><br />");
1740: $r->print("</h4>\n");
1741: #---------------------------------------------------------------- print table
1742: $r->print('<p><table border="2">');
1743: $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
1744: $r->print('<th>'.&mt('Default Value').'</th>');
1745: $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1746:
1747: foreach (&keysinorder(\%name,\%keyorder)) {
1748: $r->print('<tr>');
1749: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1750: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
1751: $parmlev,$uname,$udom,$csec,$cgroup);
1752: }
1753: $r->print("</table></center>");
1754: } # end each map
1755: } # end of $parmlev eq map
1756: #--------------------------------- Entry for parm level general (Course level)
1757: if ($parmlev eq 'general') {
1758: my $defbgone = '"E0E099"';
1759: my $defbgtwo = '"FFFF99"';
1760: my $defbgthree = '"FFBB99"';
1761:
1762: #-------------------------------------------- for each map, gather information
1763: my $mapid="0.0";
1764: #----------------------- loop through ids and get all parameter types for map
1765: #----------------------------------------- and associated information
1766: my %name = ();
1767: my %part = ();
1768: my %display = ();
1769: my %type = ();
1770: my %default = ();
1771:
1772: foreach (@ids) {
1773: my $rid = $_;
1774:
1775: my $uri=&Apache::lonnet::declutter($uris{$rid});
1776:
1777: #--------------------------------------------------------------------
1778: # @catmarker contains list of all possible parameters including part #s
1779: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1780: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1781: # When storing information, store as part 0
1782: # When requesting information, request from full part
1783: #-------------------------------------------------------------------
1784: foreach (&keysplit($keyp{$rid})) {
1785: my $tempkeyp = $_;
1786: my $fullkeyp = $tempkeyp;
1787: $tempkeyp =~ s/_\w+_/_0_/;
1788: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1789: $part{$tempkeyp}="0";
1790: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1791: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1792: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1793: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1794: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1795: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1796: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1797: }
1798: } # end loop through keys
1799: } # end loop through ids
1800:
1801: #---------------------------------------------------- print header information
1802: my $setdef=&mt("Set Defaults for All Resources in Course");
1803: $r->print(<<ENDMAPONE);
1804: <center><h4>$setdef
1805: <font color="red"><i>$coursename</i></font><br />
1806: ENDMAPONE
1807: if ($uname) {
1808: my $person=&Apache::loncommon::plainname($uname,$udom);
1809: $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
1810: } else {
1811: $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
1812: }
1813:
1814: if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
1815: if ($cgroup) {$r->print(&mt("Group")."<font color=\"red\"> <i>$csec</i></font>\n")};
1816: $r->print("</h4>\n");
1817: #---------------------------------------------------------------- print table
1818: $r->print('<p><table border="2">');
1819: $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
1820: $r->print('<th>'.&mt('Default Value').'</th>');
1821: $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1822:
1823: foreach (&keysinorder(\%name,\%keyorder)) {
1824: $r->print('<tr>');
1825: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1826: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
1827: $parmlev,$uname,$udom,$csec,$cgroup);
1828: }
1829: $r->print("</table></center>");
1830: } # end of $parmlev eq general
1831: }
1832: $r->print('</form></body></html>');
1833: } # end sub assessparms
1834:
1835:
1836: ##################################################
1837: ##################################################
1838:
1839: =pod
1840:
1841: =item crsenv
1842:
1843: Show and set course data and parameters. This is a large routine that should
1844: be simplified and shortened... someday.
1845:
1846: Inputs: $r
1847:
1848: Returns: nothing
1849:
1850: =cut
1851:
1852: ##################################################
1853: ##################################################
1854: sub crsenv {
1855: my $r=shift;
1856: my $setoutput='';
1857: my $bodytag=&Apache::loncommon::bodytag(
1858: 'Set Course Environment Parameters');
1859: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,
1860: 'Edit Course Environment');
1861: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1862: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1863:
1864: #
1865: # Go through list of changes
1866: foreach (keys %env) {
1867: next if ($_!~/^form\.(.+)\_setparmval$/);
1868: my $name = $1;
1869: my $value = $env{'form.'.$name.'_value'};
1870: if ($name eq 'newp') {
1871: $name = $env{'form.newp_name'};
1872: }
1873: if ($name eq 'url') {
1874: $value=~s/^\/res\///;
1875: my $bkuptime=time;
1876: my @tmp = &Apache::lonnet::get
1877: ('environment',['url'],$dom,$crs);
1878: $setoutput.=&mt('Backing up previous URL').': '.
1879: &Apache::lonnet::put
1880: ('environment',
1881: {'top level map backup '.$bkuptime => $tmp[1] },
1882: $dom,$crs).
1883: '<br>';
1884: }
1885: #
1886: # Deal with modified default spreadsheets
1887: if ($name =~ /^spreadsheet_default_(classcalc|
1888: studentcalc|
1889: assesscalc)$/x) {
1890: my $sheettype = $1;
1891: if ($sheettype eq 'classcalc') {
1892: # no need to do anything since viewing the sheet will
1893: # cause it to be updated.
1894: } elsif ($sheettype eq 'studentcalc') {
1895: # expire all the student spreadsheets
1896: &Apache::lonnet::expirespread('','','studentcalc');
1897: } else {
1898: # expire all the assessment spreadsheets
1899: # this includes non-default spreadsheets, but better to
1900: # be safe than sorry.
1901: &Apache::lonnet::expirespread('','','assesscalc');
1902: # expire all the student spreadsheets
1903: &Apache::lonnet::expirespread('','','studentcalc');
1904: }
1905: }
1906: #
1907: # Deal with the enrollment dates
1908: if ($name =~ /^default_enrollment_(start|end)_date$/) {
1909: $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
1910: }
1911: # Get existing cloners
1912: my @oldcloner = ();
1913: if ($name eq 'cloners') {
1914: my %clonenames=&Apache::lonnet::dump('environment',$dom,$crs,'cloners');
1915: if ($clonenames{'cloners'} =~ /,/) {
1916: @oldcloner = split/,/,$clonenames{'cloners'};
1917: } else {
1918: $oldcloner[0] = $clonenames{'cloners'};
1919: }
1920: }
1921: #
1922: # Let the user know we made the changes
1923: if ($name && defined($value)) {
1924: my $failed_cloners;
1925: if ($name eq 'cloners') {
1926: $value =~ s/\s//g;
1927: $value =~ s/^,//;
1928: $value =~ s/,$//;
1929: # check requested clones are valid users.
1930: $failed_cloners = &check_cloners(\$value,\@oldcloner);
1931: }
1932: my $put_result = &Apache::lonnet::put('environment',
1933: {$name=>$value},$dom,$crs);
1934: if ($put_result eq 'ok') {
1935: $setoutput.=&mt('Set').' <b>'.$name.'</b> '.&mt('to').' <b>'.$value.'</b>.<br />';
1936: if ($name eq 'cloners') {
1937: &change_clone($value,\@oldcloner);
1938: }
1939: # Flush the course logs so course description is immediately updated
1940: if ($name eq 'description' && defined($value)) {
1941: &Apache::lonnet::flushcourselogs();
1942: }
1943: } else {
1944: $setoutput.=&mt('Unable to set').' <b>'.$name.'</b> '.&mt('to').
1945: ' <b>'.$value.'</b> '.&mt('due to').' '.$put_result.'.<br />';
1946: }
1947: if (($name eq 'cloners') && ($failed_cloners)) {
1948: $setoutput.= &mt('Unable to include').' - <b>'.$failed_cloners.'</b>, '.
1949: &mt('reason').' - '.&mt('LON-CAPA user(s) do(es) not exist').
1950: '.<br />'.&mt('Please ').
1951: ' <a href="/adm/createuser">'.
1952: &mt('add the user(s)').'</a>, '.
1953: &mt('and then return to the ').
1954: '<a href="/admparmset?action=crsenv">'.
1955: &mt('Course Parameters page').'</a> '.
1956: &mt('to add the new user(s) to the list of possible cloners').
1957: '.<br />';
1958: }
1959: }
1960: }
1961: # ------------------------- Re-init course environment entries for this session
1962:
1963: &Apache::lonnet::coursedescription($env{'request.course.id'});
1964:
1965: # -------------------------------------------------------- Get parameters again
1966:
1967: my %values=&Apache::lonnet::dump('environment',$dom,$crs);
1968: my $SelectStyleFile=&mt('Select Style File');
1969: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
1970: my $output='';
1971: if (! exists($values{'con_lost'})) {
1972: my %descriptions=
1973: ('url' => '<b>'.&mt('Top Level Map').'</b> '.
1974: '<a href="javascript:openbrowser'.
1975: "('envform','url','sequence')\">".
1976: &mt('Select Map').'</a><br /><font color=red> '.
1977: &mt('Modification may make assessment data inaccessible').
1978: '</font>',
1979: 'description' => '<b>'.&mt('Course Description').'</b>',
1980: 'courseid' => '<b>'.&mt('Course ID or number').
1981: '</b><br />'.
1982: '('.&mt('internal').', '.&mt('optional').')',
1983: '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.'),
1984: 'grading' => '<b>'.&mt('Grading').'</b><br />'.
1985: '<tt>"standard", "external", or "spreadsheet"</tt> '.&Apache::loncommon::help_open_topic('GradingOptions'),
1986: 'default_xml_style' => '<b>'.&mt('Default XML Style File').'</b> '.
1987: '<a href="javascript:openbrowser'.
1988: "('envform','default_xml_style'".
1989: ",'sty')\">$SelectStyleFile</a><br>",
1990: 'question.email' => '<b>'.&mt('Feedback Addresses for Resource Content Question').
1991: '</b><br />(<tt>user:domain,'.
1992: 'user:domain(section;section;...;*;...),...</tt>)',
1993: 'comment.email' => '<b>'.&mt('Feedback Addresses for Course Content Comments').'</b><br />'.
1994: '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1995: 'policy.email' => '<b>'.&mt('Feedback Addresses for Course Policy').'</b>'.
1996: '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1997: 'hideemptyrows' => '<b>'.&mt('Hide Empty Rows in Spreadsheets').'</b><br />'.
1998: '('.&mt('"[_1]" for default hiding','<tt>yes</tt>').')',
1999: 'pageseparators' => '<b>'.&mt('Visibly Separate Items on Pages').'</b><br />'.
2000: '('.&mt('"[_1]" for visible separation','<tt>yes</tt>').', '.
2001: &mt('changes will not show until next login').')',
2002: '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.'),
2003:
2004: 'plc.roles.denied'=> '<b>'.&mt('Disallow live chatroom use for Roles').
2005: '</b><br />"<tt>st</tt>": '.
2006: &mt('student').', "<tt>ta</tt>": '.
2007: 'TA, "<tt>in</tt>": '.
2008: &mt('instructor').';<br /><tt>'.&mt('role,role,...').'</tt>) '.
2009: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
2010: 'plc.users.denied' =>
2011: '<b>'.&mt('Disallow live chatroom use for Users').'</b><br />'.
2012: '(<tt>user:domain,user:domain,...</tt>)',
2013:
2014: 'pch.roles.denied'=> '<b>'.&mt('Disallow Resource Discussion for Roles').
2015: '</b><br />"<tt>st</tt>": '.
2016: 'student, "<tt>ta</tt>": '.
2017: 'TA, "<tt>in</tt>": '.
2018: 'instructor;<br /><tt>role,role,...</tt>) '.
2019: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
2020: 'pch.users.denied' =>
2021: '<b>'.&mt('Disallow Resource Discussion for Users').'</b><br />'.
2022: '(<tt>user:domain,user:domain,...</tt>)',
2023: 'spreadsheet_default_classcalc'
2024: => '<b>'.&mt('Default Course Spreadsheet').'</b> '.
2025: '<a href="javascript:openbrowser'.
2026: "('envform','spreadsheet_default_classcalc'".
2027: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
2028: 'spreadsheet_default_studentcalc'
2029: => '<b>'.&mt('Default Student Spreadsheet').'</b> '.
2030: '<a href="javascript:openbrowser'.
2031: "('envform','spreadsheet_default_calc'".
2032: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
2033: 'spreadsheet_default_assesscalc'
2034: => '<b>'.&mt('Default Assessment Spreadsheet').'</b> '.
2035: '<a href="javascript:openbrowser'.
2036: "('envform','spreadsheet_default_assesscalc'".
2037: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
2038: 'allow_limited_html_in_feedback'
2039: => '<b>'.&mt('Allow limited HTML in discussion posts').'</b><br />'.
2040: '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
2041: 'allow_discussion_post_editing'
2042: => '<b>'.&mt('Allow users to edit/delete their own discussion posts').'</b><br />'.
2043: '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
2044: 'rndseed'
2045: => '<b>'.&mt('Randomization algorithm used').'</b> <br />'.
2046: '<font color="red">'.&mt('Modifying this will make problems').' '.
2047: &mt('have different numbers and answers').'</font>',
2048: 'receiptalg'
2049: => '<b>'.&mt('Receipt algorithm used').'</b> <br />'.
2050: &mt('This controls how receipt numbers are generated.'),
2051: 'suppress_tries'
2052: => '<b>'.&mt('Suppress number of tries in printing').'</b><br />'.
2053: ' ('.&mt('"[_1]" to suppress, anything else to not suppress','<tt>yes</tt>').')',
2054: 'problem_stream_switch'
2055: => '<b>'.&mt('Allow problems to be split over pages').'</b><br />'.
2056: ' ('.&mt('"[_1]" if allowed, anything else if not','<tt>yes</tt>').')',
2057: 'default_paper_size'
2058: => '<b>'.&mt('Default paper type').'</b><br />'.
2059: ' ('.&mt('supported types').': Letter [8 1/2x11 in], Legal [8 1/2x14 in],'.
2060: ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'.
2061: ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])',
2062: 'anonymous_quiz'
2063: => '<b>'.&mt('Anonymous quiz/exam').'</b><br />'.
2064: ' (<tt><b>'.&mt('yes').'</b> '.&mt('to avoid print students names').' </tt>)',
2065: 'default_enrollment_start_date' => '<b>'.&mt('Default beginning date for student access.').'</b>',
2066: 'default_enrollment_end_date' => '<b>'.&mt('Default ending date for student access.').'</b>',
2067: 'nothideprivileged' => '<b>'.&mt('Privileged users that should not be hidden on staff listings').'</b>'.
2068: '<br />(<tt>user:domain,user:domain,...</tt>)',
2069: 'languages' => '<b>'.&mt('Languages used').'</b>',
2070: 'disable_receipt_display'
2071: => '<b>'.&mt('Disable display of problem receipts').'</b><br />'.
2072: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
2073: 'disablesigfigs'
2074: => '<b>'.&mt('Disable checking of Significant Figures').'</b><br />'.
2075: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
2076: 'disableexampointprint'
2077: => '<b>'.&mt('Disable automatically printing point values onto exams.').'</b><br />'.
2078: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
2079: 'tthoptions'
2080: => '<b>'.&mt('Default set of options to pass to tth/m when converting tex').'</b>'
2081: );
2082: my @Display_Order = ('url','description','courseid','cloners','grading',
2083: 'default_xml_style','pageseparators',
2084: 'question.email','comment.email','policy.email',
2085: 'student_classlist_view',
2086: 'plc.roles.denied','plc.users.denied',
2087: 'pch.roles.denied','pch.users.denied',
2088: 'allow_limited_html_in_feedback',
2089: 'allow_discussion_post_editing',
2090: 'languages',
2091: 'nothideprivileged',
2092: 'rndseed',
2093: 'receiptalg',
2094: 'problem_stream_switch',
2095: 'suppress_tries',
2096: 'default_paper_size',
2097: 'disable_receipt_display',
2098: 'spreadsheet_default_classcalc',
2099: 'spreadsheet_default_studentcalc',
2100: 'spreadsheet_default_assesscalc',
2101: 'hideemptyrows',
2102: 'default_enrollment_start_date',
2103: 'default_enrollment_end_date',
2104: 'tthoptions',
2105: 'disablesigfigs',
2106: 'disableexampointprint'
2107: );
2108: foreach my $parameter (sort(keys(%values))) {
2109: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./)) {
2110: if (! $descriptions{$parameter}) {
2111: $descriptions{$parameter}=$parameter;
2112: push(@Display_Order,$parameter);
2113: }
2114: }
2115: }
2116: foreach my $parameter (@Display_Order) {
2117: my $description = $descriptions{$parameter};
2118: # onchange is javascript to automatically check the 'Set' button.
2119: my $onchange = 'onFocus="javascript:window.document.forms'.
2120: "['envform'].elements['".$parameter."_setparmval']".
2121: '.checked=true;"';
2122: $output .= '<tr><td>'.$description.'</td>';
2123: if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
2124: $output .= '<td>'.
2125: &Apache::lonhtmlcommon::date_setter('envform',
2126: $parameter.'_value',
2127: $values{$parameter},
2128: $onchange).
2129: '</td>';
2130: } else {
2131: $output .= '<td>'.
2132: &Apache::lonhtmlcommon::textbox($parameter.'_value',
2133: $values{$parameter},
2134: 40,$onchange).'</td>';
2135: }
2136: $output .= '<td>'.
2137: &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
2138: '</td>';
2139: $output .= "</tr>\n";
2140: }
2141: my $onchange = 'onFocus="javascript:window.document.forms'.
2142: '[\'envform\'].elements[\'newp_setparmval\']'.
2143: '.checked=true;"';
2144: $output.='<tr><td><i>'.&mt('Create New Environment Variable').'</i><br />'.
2145: '<input type="text" size=40 name="newp_name" '.
2146: $onchange.' /></td><td>'.
2147: '<input type="text" size=40 name="newp_value" '.
2148: $onchange.' /></td><td>'.
2149: '<input type="checkbox" name="newp_setparmval" /></td></tr>';
2150: }
2151: my %lt=&Apache::lonlocal::texthash(
2152: 'par' => 'Parameter',
2153: 'val' => 'Value',
2154: 'set' => 'Set',
2155: 'sce' => 'Set Course Environment'
2156: );
2157:
2158: my $Parameter=&mt('Parameter');
2159: my $Value=&mt('Value');
2160: my $Set=&mt('Set');
2161: my $browse_js=&Apache::loncommon::browser_and_searcher_javascript('parmset');
2162: my $html=&Apache::lonxml::xmlbegin();
2163: $r->print(<<ENDenv);
2164: $html
2165: <head>
2166: <script type="text/javascript" language="Javascript" >
2167: $browse_js
2168: </script>
2169: <title>LON-CAPA Course Environment</title>
2170: </head>
2171: $bodytag
2172: $breadcrumbs
2173: <form method="post" action="/adm/parmset?action=crsenv" name="envform">
2174: $setoutput
2175: <p>
2176: <table border=2>
2177: <tr><th>$lt{'par'}</th><th>$lt{'val'}</th><th>$lt{'set'}?</th></tr>
2178: $output
2179: </table>
2180: <input type="submit" name="crsenv" value="$lt{'sce'}">
2181: </form>
2182: </body>
2183: </html>
2184: ENDenv
2185: }
2186: ##################################################
2187: # Overview mode
2188: ##################################################
2189: my $tableopen;
2190:
2191: sub tablestart {
2192: if ($tableopen) {
2193: return '';
2194: } else {
2195: $tableopen=1;
2196: return '<table border="2"><tr><th>'.&mt('Parameter').'</th><th>'.
2197: &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
2198: }
2199: }
2200:
2201: sub tableend {
2202: if ($tableopen) {
2203: $tableopen=0;
2204: return '</table>';
2205: } else {
2206: return'';
2207: }
2208: }
2209:
2210: sub readdata {
2211: my ($crs,$dom)=@_;
2212: # Read coursedata
2213: my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
2214: # Read userdata
2215:
2216: my $classlist=&Apache::loncoursedata::get_classlist();
2217: foreach (keys %$classlist) {
2218: # the following undefs are for 'domain', and 'username' respectively.
2219: if ($_=~/^(\w+)\:(\w+)$/) {
2220: my ($tuname,$tudom)=($1,$2);
2221: my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
2222: foreach my $userkey (keys %{$useropt}) {
2223: if ($userkey=~/^$env{'request.course.id'}/) {
2224: my $newkey=$userkey;
2225: $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
2226: $$resourcedata{$newkey}=$$useropt{$userkey};
2227: }
2228: }
2229: }
2230: }
2231: return $resourcedata;
2232: }
2233:
2234:
2235: # Setting
2236:
2237: sub storedata {
2238: my ($r,$crs,$dom)=@_;
2239: # Set userlevel immediately
2240: # Do an intermediate store of course level
2241: my $olddata=&readdata($crs,$dom);
2242: my %newdata=();
2243: undef %newdata;
2244: my @deldata=();
2245: undef @deldata;
2246: foreach (keys %env) {
2247: if ($_=~/^form\.([a-z]+)\_(.+)$/) {
2248: my $cmd=$1;
2249: my $thiskey=$2;
2250: my ($tuname,$tudom)=&extractuser($thiskey);
2251: my $tkey=$thiskey;
2252: if ($tuname) {
2253: $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
2254: }
2255: if ($cmd eq 'set') {
2256: my $data=$env{$_};
2257: my $typeof=$env{'form.typeof_'.$thiskey};
2258: if ($$olddata{$thiskey} ne $data) {
2259: if ($tuname) {
2260: if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
2261: $tkey.'.type' => $typeof},
2262: $tudom,$tuname) eq 'ok') {
2263: $r->print('<br />'.&mt('Stored modified parameter for').' '.
2264: &Apache::loncommon::plainname($tuname,$tudom));
2265: } else {
2266: $r->print('<h2><font color="red">'.
2267: &mt('Error storing parameters').'</font></h2>');
2268: }
2269: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2270: } else {
2271: $newdata{$thiskey}=$data;
2272: $newdata{$thiskey.'.type'}=$typeof;
2273: }
2274: }
2275: } elsif ($cmd eq 'del') {
2276: if ($tuname) {
2277: if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
2278: $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
2279: } else {
2280: $r->print('<h2><font color="red">'.
2281: &mt('Error deleting parameters').'</font></h2>');
2282: }
2283: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2284: } else {
2285: push (@deldata,$thiskey);
2286: }
2287: } elsif ($cmd eq 'datepointer') {
2288: my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
2289: my $typeof=$env{'form.typeof_'.$thiskey};
2290: if (defined($data) and $$olddata{$thiskey} ne $data) {
2291: if ($tuname) {
2292: if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
2293: $tkey.'.type' => $typeof},
2294: $tudom,$tuname) eq 'ok') {
2295: $r->print('<br />'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
2296: } else {
2297: $r->print('<h2><font color="red">'.
2298: &mt('Error storing parameters').'</font></h2>');
2299: }
2300: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2301: } else {
2302: $newdata{$thiskey}=$data;
2303: $newdata{$thiskey.'.type'}=$typeof;
2304: }
2305: }
2306: }
2307: }
2308: }
2309: # Store all course level
2310: my $delentries=$#deldata+1;
2311: my @newdatakeys=keys %newdata;
2312: my $putentries=$#newdatakeys+1;
2313: if ($delentries) {
2314: if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
2315: $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
2316: } else {
2317: $r->print('<h2><font color="red">'.
2318: &mt('Error deleting parameters').'</font></h2>');
2319: }
2320: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
2321: }
2322: if ($putentries) {
2323: if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
2324: $r->print('<h3>'.&mt('Stored [_1] parameter(s)',$putentries/2).'</h3>');
2325: } else {
2326: $r->print('<h2><font color="red">'.
2327: &mt('Error storing parameters').'</font></h2>');
2328: }
2329: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
2330: }
2331: }
2332:
2333: sub extractuser {
2334: my $key=shift;
2335: return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./);
2336: }
2337:
2338: sub listdata {
2339: my ($r,$resourcedata,$listdata,$sortorder)=@_;
2340: # Start list output
2341:
2342: my $oldsection='';
2343: my $oldrealm='';
2344: my $oldpart='';
2345: my $pointer=0;
2346: $tableopen=0;
2347: my $foundkeys=0;
2348: my %keyorder=&standardkeyorder();
2349: foreach my $thiskey (sort {
2350: if ($sortorder eq 'realmstudent') {
2351: my ($astudent,$arealm)=($a=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/);
2352: my ($bstudent,$brealm)=($b=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/);
2353: if (!defined($astudent)) {
2354: ($arealm)=($a=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
2355: }
2356: if (!defined($bstudent)) {
2357: ($brealm)=($b=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
2358: }
2359: $arealm=~s/\.type//;
2360: my ($ares, $aparm) = ($arealm=~/^(.*)\.(.*)$/);
2361: $aparm=$keyorder{'parameter_0_'.$aparm};
2362: $brealm=~s/\.type//;
2363: my ($bres, $bparm) = ($brealm=~/^(.*)\.(.*)$/);
2364: $bparm=$keyorder{'parameter_0_'.$bparm};
2365: if ($ares eq $bres) {
2366: if (defined($aparm) && defined($bparm)) {
2367: ($aparm <=> $bparm);
2368: } elsif (defined($aparm)) {
2369: -1;
2370: } elsif (defined($bparm)) {
2371: 1;
2372: } else {
2373: ($arealm cmp $brealm) || ($astudent cmp $bstudent);
2374: }
2375: } else {
2376: ($arealm cmp $brealm) || ($astudent cmp $bstudent);
2377: }
2378: } else {
2379: $a cmp $b;
2380: }
2381: } keys %{$listdata}) {
2382:
2383: if ($$listdata{$thiskey.'.type'}) {
2384: my $thistype=$$listdata{$thiskey.'.type'};
2385: if ($$resourcedata{$thiskey.'.type'}) {
2386: $thistype=$$resourcedata{$thiskey.'.type'};
2387: }
2388: my ($middle,$part,$name)=
2389: ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
2390: my $section=&mt('All Students');
2391: if ($middle=~/^\[(.*)\]/) {
2392: my $issection=$1;
2393: if ($issection=~/^useropt\:(\w+)\:(\w+)/) {
2394: $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
2395: } else {
2396: $section=&mt('Group/Section').': '.$issection;
2397: }
2398: $middle=~s/^\[(.*)\]//;
2399: }
2400: $middle=~s/\.+$//;
2401: $middle=~s/^\.+//;
2402: my $realm='<font color="red">'.&mt('All Resources').'</font>';
2403: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
2404: $realm='<font color="green">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><font color="#aaaaaa" size="-2">('.$1.')</font></font>';
2405: } elsif ($middle) {
2406: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
2407: $realm='<font color="orange">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><font color="#aaaaaa" size="-2">('.$url.' in '.$map.' id: '.$id.')</font></font>';
2408: }
2409: if ($sortorder eq 'realmstudent') {
2410: if ($realm ne $oldrealm) {
2411: $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
2412: $oldrealm=$realm;
2413: $oldsection='';
2414: }
2415: if ($section ne $oldsection) {
2416: $r->print(&tableend()."\n<h2>$section</h2>");
2417: $oldsection=$section;
2418: $oldpart='';
2419: }
2420: } else {
2421: if ($section ne $oldsection) {
2422: $r->print(&tableend()."\n<hr /><h1>$section</h1>");
2423: $oldsection=$section;
2424: $oldrealm='';
2425: }
2426: if ($realm ne $oldrealm) {
2427: $r->print(&tableend()."\n<h2>$realm</h2>");
2428: $oldrealm=$realm;
2429: $oldpart='';
2430: }
2431: }
2432: if ($part ne $oldpart) {
2433: $r->print(&tableend().
2434: "\n<font color='blue'>".&mt('Part').": $part</font>");
2435: $oldpart=$part;
2436: }
2437: #
2438: # Preset defaults?
2439: #
2440: my ($hour,$min,$sec,$val)=('','','','');
2441: unless ($$resourcedata{$thiskey}) {
2442: my ($parmname)=($thiskey=~/\.(\w+)$/);
2443: ($hour,$min,$sec,$val)=&preset_defaults($parmname);
2444: }
2445:
2446: #
2447: # Ready to print
2448: #
2449: $r->print(&tablestart().'<tr><td><b>'.$name.
2450: ':</b></td><td><input type="checkbox" name="del_'.
2451: $thiskey.'" /></td><td>');
2452: $foundkeys++;
2453: if (&isdateparm($thistype)) {
2454: my $jskey='key_'.$pointer;
2455: $pointer++;
2456: $r->print(
2457: &Apache::lonhtmlcommon::date_setter('parmform',
2458: $jskey,
2459: $$resourcedata{$thiskey},
2460: '',1,'','',$hour,$min,$sec).
2461: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'
2462: );
2463: } elsif ($thistype eq 'string_yesno') {
2464: my $showval;
2465: if (defined($$resourcedata{$thiskey})) {
2466: $showval=$$resourcedata{$thiskey};
2467: } else {
2468: $showval=$val;
2469: }
2470: $r->print('<label><input type="radio" name="set_'.$thiskey.
2471: '" value="yes"');
2472: if ($showval eq 'yes') {
2473: $r->print(' checked="checked"');
2474: }
2475: $r->print(' />'.&mt('Yes').'</label> ');
2476: $r->print('<label><input type="radio" name="set_'.$thiskey.
2477: '" value="no"');
2478: if ($showval eq 'no') {
2479: $r->print(' checked="checked"');
2480: }
2481: $r->print(' />'.&mt('No').'</label>');
2482: } else {
2483: my $showval;
2484: if (defined($$resourcedata{$thiskey})) {
2485: $showval=$$resourcedata{$thiskey};
2486: } else {
2487: $showval=$val;
2488: }
2489: $r->print('<input type="text" name="set_'.$thiskey.'" value="'.
2490: $showval.'">');
2491: }
2492: $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
2493: $thistype.'">');
2494: $r->print('</td></tr>');
2495: }
2496: }
2497: return $foundkeys;
2498: }
2499:
2500: sub newoverview {
2501: my $r=shift;
2502: my $bodytag=&Apache::loncommon::bodytag('Set Parameters');
2503: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2504: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2505: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
2506: my $html=&Apache::lonxml::xmlbegin();
2507: $r->print(<<ENDOVER);
2508: $html
2509: <head>
2510: <title>LON-CAPA Parameters</title>
2511: </head>
2512: $bodytag
2513: $breadcrumbs
2514: <form method="post" action="/adm/parmset?action=newoverview" name="parmform">
2515: ENDOVER
2516: my @ids=();
2517: my %typep=();
2518: my %keyp=();
2519: my %allparms=();
2520: my %allparts=();
2521: my %allmaps=();
2522: my %mapp=();
2523: my %symbp=();
2524: my %maptitles=();
2525: my %uris=();
2526: my %keyorder=&standardkeyorder();
2527: my %defkeytype=();
2528:
2529: my %alllevs=();
2530: $alllevs{'Resource Level'}='full';
2531: $alllevs{'Map/Folder Level'}='map';
2532: $alllevs{'Course Level'}='general';
2533:
2534: my $csec=$env{'form.csec'};
2535: my $cgroup=$env{'form.cgroup'};
2536:
2537: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
2538: my $pschp=$env{'form.pschp'};
2539: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
2540: if (!@psprt) { $psprt[0]='0'; }
2541:
2542: my @selected_sections =
2543: &Apache::loncommon::get_env_multiple('form.Section');
2544: @selected_sections = ('all') if (! @selected_sections);
2545: foreach (@selected_sections) {
2546: if ($_ eq 'all') {
2547: @selected_sections = ('all');
2548: }
2549: }
2550: my @selected_groups =
2551: &Apache::loncommon::get_env_multiple('form.Group');
2552:
2553: my $pssymb='';
2554: my $parmlev='';
2555:
2556: unless ($env{'form.parmlev'}) {
2557: $parmlev = 'map';
2558: } else {
2559: $parmlev = $env{'form.parmlev'};
2560: }
2561:
2562: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
2563: \%mapp, \%symbp,\%maptitles,\%uris,
2564: \%keyorder,\%defkeytype);
2565:
2566: # Menu to select levels, etc
2567:
2568: $r->print('<table border="1"><tr><td>');
2569: &levelmenu($r,\%alllevs,$parmlev);
2570: if ($parmlev ne 'general') {
2571: $r->print('<td>');
2572: &mapmenu($r,\%allmaps,$pschp,\%maptitles);
2573: $r->print('</td>');
2574: }
2575: $r->print('</td></tr></table>');
2576:
2577: $r->print('<table border="1"><tr><td>');
2578: &parmmenu($r,\%allparms,\@pscat,\%keyorder);
2579: $r->print('</td><td><table border="0" cellspacing="0" cellpadding="0">'.
2580: '<tr><td>'.&mt('Parts').'</td><td></td><td>'.&mt('Section(s)').
2581: '</td><td></td><td>'.&mt('Group(s)').'</td></tr><tr><td>');
2582: &partmenu($r,\%allparts,\@psprt);
2583: $r->print('</td><td> </td><td>');
2584: §ionmenu($r,\@selected_sections);
2585: $r->print('</td><td> </td><td>');
2586: &groupmenu($r,\@selected_groups);
2587: $r->print('</td></tr></table>');
2588: $r->print('</td></tr></table>');
2589:
2590: my $sortorder=$env{'form.sortorder'};
2591: unless ($sortorder) { $sortorder='realmstudent'; }
2592: &sortmenu($r,$sortorder);
2593:
2594: $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
2595:
2596: # Build the list data hash from the specified parms
2597:
2598: my $listdata;
2599: %{$listdata}=();
2600:
2601: foreach my $cat (@pscat) {
2602: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_sections,\%defkeytype,\%allmaps,\@ids,\%symbp);
2603: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_groups,\%defkeytype,\%allmaps,\@ids,\%symbp);
2604: }
2605:
2606: if (($env{'form.store'}) || ($env{'form.dis'})) {
2607:
2608: if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
2609:
2610: # Read modified data
2611:
2612: my $resourcedata=&readdata($crs,$dom);
2613:
2614: # List data
2615:
2616: &listdata($r,$resourcedata,$listdata,$sortorder);
2617: }
2618: $r->print(&tableend().
2619: ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Store').'" /></p>':'').
2620: '</form></body></html>');
2621: }
2622:
2623: sub secgroup_lister {
2624: my ($cat,$pschp,$parmlev,$listdata,$psprt,$selections,$defkeytype,$allmaps,$ids,$symbp) = @_;
2625: foreach my $item (@{$selections}) {
2626: foreach my $part (@{$psprt}) {
2627: my $rootparmkey=$env{'request.course.id'};
2628: if (($item ne 'all') && ($item ne 'none') && ($item)) {
2629: $rootparmkey.='.['.$item.']';
2630: }
2631: if ($parmlev eq 'general') {
2632: # course-level parameter
2633: my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
2634: $$listdata{$newparmkey}=1;
2635: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
2636: } elsif ($parmlev eq 'map') {
2637: # map-level parameter
2638: foreach my $mapid (keys %{$allmaps}) {
2639: if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
2640: my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
2641: $$listdata{$newparmkey}=1;
2642: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
2643: }
2644: } else {
2645: # resource-level parameter
2646: foreach my $rid (@{$ids}) {
2647: my ($map,$resid,$url)=&Apache::lonnet::decode_symb($$symbp{$rid});
2648: if (($pschp ne 'all') && ($$allmaps{$pschp} ne $map)) { next; }
2649: my $newparmkey=$rootparmkey.'.'.$$symbp{$rid}.'.'.$part.'.'.$cat;
2650: $$listdata{$newparmkey}=1;
2651: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
2652: }
2653: }
2654: }
2655: }
2656: }
2657:
2658: sub overview {
2659: my $r=shift;
2660: my $bodytag=&Apache::loncommon::bodytag('Modify Parameters');
2661: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2662: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2663: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
2664: my $html=&Apache::lonxml::xmlbegin();
2665: $r->print(<<ENDOVER);
2666: $html
2667: <head>
2668: <title>LON-CAPA Parameters</title>
2669: </head>
2670: $bodytag
2671: $breadcrumbs
2672: <form method="post" action="/adm/parmset?action=setoverview" name="parmform">
2673: ENDOVER
2674: # Store modified
2675:
2676: &storedata($r,$crs,$dom);
2677:
2678: # Read modified data
2679:
2680: my $resourcedata=&readdata($crs,$dom);
2681:
2682:
2683: my $sortorder=$env{'form.sortorder'};
2684: unless ($sortorder) { $sortorder='realmstudent'; }
2685: &sortmenu($r,$sortorder);
2686:
2687: # List data
2688:
2689: my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder);
2690:
2691: $r->print(&tableend().'<p>'.
2692: ($foundkeys?'<input type="submit" value="'.&mt('Modify Parameters').'" />':&mt('There are no parameters.')).'</p></form></body></html>');
2693: }
2694:
2695: ##################################################
2696: ##################################################
2697:
2698: =pod
2699:
2700: =item check_cloners
2701:
2702: Checks if new users included in list of allowed cloners
2703: are valid users. Replaces supplied list with
2704: cleaned list containing only users with valid usernames
2705: and domains.
2706:
2707: Inputs: $clonelist, $oldcloner
2708: where $clonelist is ref to array of requested cloners,
2709: and $oldcloner is ref to array of currently allowed
2710: cloners.
2711:
2712: Returns: string - comma separated list of requested
2713: cloners (username:domain) who do not exist in system.
2714:
2715: =item change_clone
2716:
2717: Modifies the list of courses a user can clone (stored
2718: in the user's environment.db file), called when a
2719: change is made to the list of users allowed to clone
2720: a course.
2721:
2722: Inputs: $action,$cloner
2723: where $action is add or drop, and $cloner is identity of
2724: user for whom cloning ability is to be changed in course.
2725:
2726: =cut
2727:
2728: ##################################################
2729: ##################################################
2730:
2731: sub extract_cloners {
2732: my ($clonelist,$allowclone) = @_;
2733: if ($clonelist =~ /,/) {
2734: @{$allowclone} = split/,/,$clonelist;
2735: } else {
2736: $$allowclone[0] = $clonelist;
2737: }
2738: }
2739:
2740:
2741: sub check_cloners {
2742: my ($clonelist,$oldcloner) = @_;
2743: my ($clean_clonelist,$disallowed);
2744: my @allowclone = ();
2745: &extract_cloners($$clonelist,\@allowclone);
2746: foreach my $currclone (@allowclone) {
2747: if (!grep/^$currclone$/,@$oldcloner) {
2748: my ($uname,$udom) = split/:/,$currclone;
2749: if ($uname && $udom) {
2750: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
2751: $disallowed .= $currclone.',';
2752: } else {
2753: $clean_clonelist .= $currclone.',';
2754: }
2755: }
2756: } else {
2757: $clean_clonelist .= $currclone.',';
2758: }
2759: }
2760: if ($disallowed) {
2761: $disallowed =~ s/,$//;
2762: }
2763: if ($clean_clonelist) {
2764: $clean_clonelist =~ s/,$//;
2765: }
2766: $$clonelist = $clean_clonelist;
2767: return $disallowed;
2768: }
2769:
2770: sub change_clone {
2771: my ($clonelist,$oldcloner) = @_;
2772: my ($uname,$udom);
2773: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2774: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2775: my $clone_crs = $cnum.':'.$cdom;
2776:
2777: if ($cnum && $cdom) {
2778: my @allowclone;
2779: &extract_cloners($clonelist,\@allowclone);
2780: foreach my $currclone (@allowclone) {
2781: if (!grep/^$currclone$/,@$oldcloner) {
2782: ($uname,$udom) = split/:/,$currclone;
2783: if ($uname && $udom) {
2784: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
2785: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
2786: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
2787: if ($currclonecrs{'cloneable'} eq '') {
2788: $currclonecrs{'cloneable'} = $clone_crs;
2789: } else {
2790: $currclonecrs{'cloneable'} .= ','.$clone_crs;
2791: }
2792: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
2793: }
2794: }
2795: }
2796: }
2797: }
2798: foreach my $oldclone (@$oldcloner) {
2799: if (!grep/^$oldclone$/,@allowclone) {
2800: ($uname,$udom) = split/:/,$oldclone;
2801: if ($uname && $udom) {
2802: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
2803: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
2804: my %newclonecrs = ();
2805: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
2806: if ($currclonecrs{'cloneable'} =~ /,/) {
2807: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
2808: foreach (@currclonecrs) {
2809: unless ($_ eq $clone_crs) {
2810: $newclonecrs{'cloneable'} .= $_.',';
2811: }
2812: }
2813: $newclonecrs{'cloneable'} =~ s/,$//;
2814: } else {
2815: $newclonecrs{'cloneable'} = '';
2816: }
2817: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
2818: }
2819: }
2820: }
2821: }
2822: }
2823: }
2824: }
2825:
2826:
2827: ##################################################
2828: ##################################################
2829:
2830: =pod
2831:
2832: =item * header
2833:
2834: Output html header for page
2835:
2836: =cut
2837:
2838: ##################################################
2839: ##################################################
2840: sub header {
2841: my $html=&Apache::lonxml::xmlbegin();
2842: my $bodytag=&Apache::loncommon::bodytag('Parameter Manager');
2843: my $title = &mt('LON-CAPA Parameter Manager');
2844: return(<<ENDHEAD);
2845: $html
2846: <head>
2847: <title>$title</title>
2848: </head>
2849: $bodytag
2850: ENDHEAD
2851: }
2852: ##################################################
2853: ##################################################
2854: sub print_main_menu {
2855: my ($r,$parm_permission)=@_;
2856: #
2857: $r->print(<<ENDMAINFORMHEAD);
2858: <form method="post" enctype="multipart/form-data"
2859: action="/adm/parmset" name="studentform">
2860: ENDMAINFORMHEAD
2861: #
2862: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2863: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2864: my $vgr = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
2865:
2866: my @menu =
2867: (
2868: { text => 'Set Course Environment Parameters',
2869: action => 'crsenv',
2870: permission => $parm_permission,
2871: },
2872: { text => 'Set Portfolio Metadata',
2873: action => 'setrestrictmeta',
2874: permission => $parm_permission,
2875: },
2876: { text => 'Manage Course Slots',
2877: url => '/adm/slotrequest?command=showslots',
2878: permission => $vgr,
2879: },
2880: { divider => 1,
2881: },
2882: { text => 'Set/Modify Resource Parameters - Helper Mode',
2883: url => '/adm/helper/parameter.helper',
2884: permission => $parm_permission,
2885: },
2886: { text => 'Modify Resource Parameters - Overview Mode',
2887: action => 'setoverview',
2888: permission => $parm_permission,
2889: },
2890: { text => 'Set Resource Parameters - Overview Mode',
2891: action => 'newoverview',
2892: permission => $parm_permission,
2893: },
2894: { text => 'Set/Modify Resource Parameters - Table Mode',
2895: action => 'settable',
2896: permission => $parm_permission,
2897: help => 'Cascading_Parameters',
2898: },
2899: { text => 'Set Parameter Setting Default Actions',
2900: action => 'setdefaults',
2901: permission => $parm_permission,
2902: },
2903: );
2904: my $menu_html = '';
2905: foreach my $menu_item (@menu) {
2906: if ($menu_item->{'divider'}) {
2907: $menu_html .= '<hr />';
2908: next;
2909: }
2910: next if (! $menu_item->{'permission'});
2911: $menu_html.='<p>';
2912: $menu_html.='<font size="+1">';
2913: if (exists($menu_item->{'url'})) {
2914: $menu_html.=qq{<a href="$menu_item->{'url'}">};
2915: } else {
2916: $menu_html.=
2917: qq{<a href="/adm/parmset?action=$menu_item->{'action'}">};
2918: }
2919: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
2920: if (exists($menu_item->{'help'})) {
2921: $menu_html.=
2922: &Apache::loncommon::help_open_topic($menu_item->{'help'});
2923: }
2924: $menu_html.='</p>'.$/;
2925: }
2926: $r->print($menu_html);
2927: return;
2928: }
2929: ### Set portfolio metadata
2930: sub output_row {
2931: my ($r, $field_name, $field_text) = @_;
2932: my $output;
2933: my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
2934: my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
2935: unless (defined($options)) {
2936: $options = 'active,stuadd';
2937: $values = '';
2938: }
2939: $output.='<strong>'.$field_text.':</strong>';
2940: $output.='<input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /><br />';
2941:
2942: my @options= ( ['active', 'Show to student'],
2943: ['onlyone','Student may select only one choice'],
2944: ['stuadd', 'Student may type choices']);
2945: foreach my $opt (@options) {
2946: my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
2947: $output.=(' 'x5).'<label><input type="checkbox" name="'.
2948: $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.
2949: &mt($opt->[1]).'</label> <br />';
2950: }
2951: return ($output);
2952: }
2953:
2954: sub setrestrictmeta {
2955: my ($r)=@_;
2956: my $next_meta;
2957: my $output;
2958: my $item_num;
2959: my $put_result;
2960: $r->print(&Apache::lonxml::xmlbegin());
2961: $r->print('<head>
2962: <title>LON-CAPA Restrict Metadata</title>
2963: </head>');
2964: $r->print(&Apache::loncommon::bodytag('Restrict Metadata'));
2965: $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
2966: 'Restrict Metadata'));
2967: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2968: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2969: my $key_base = $env{'course.'.$env{'request.course.id'}.'.'};
2970: my $save_field = '';
2971: if ($env{'form.restrictmeta'}) {
2972: foreach my $field (sort(keys(%env))) {
2973: if ($field=~m/^form.(.+)_(.+)$/) {
2974: my $options;
2975: my $meta_field = $1;
2976: my $meta_key = $2;
2977: if ($save_field ne $meta_field) {
2978: $save_field = $meta_field;
2979: if ($env{'form.'.$meta_field.'_stuadd'}) {
2980: $options.='stuadd,';
2981: }
2982: if ($env{'form.'.$meta_field.'_onlyone'}) {
2983: $options.='onlyone,';
2984: }
2985: if ($env{'form.'.$meta_field.'_active'}) {
2986: $options.='active,';
2987: }
2988: my $name = $save_field;
2989: $put_result = &Apache::lonnet::put('environment',
2990: {'metadata.'.$meta_field.'.options'=>$options,
2991: 'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
2992: },$dom,$crs);
2993: }
2994: }
2995: }
2996: }
2997: &Apache::lonnet::coursedescription($env{'request.course.id'});
2998: my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
2999: foreach my $field (sort(keys(%metadata_fields))) {
3000: &Apache::lonnet::logthis ($field);
3001: if ($field ne 'courserestricted') {
3002: $output.= &output_row($r, $field, $metadata_fields{$field});
3003: }
3004: }
3005: $r->print(<<ENDenv);
3006: <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
3007: <p>
3008: $output
3009: <input type="submit" name="restrictmeta" value="Update Metadata Restrictions">
3010: </form>
3011: ENDenv
3012: $r->print('</body>
3013: </html>');
3014: return 'ok';
3015: }
3016: ##################################################
3017:
3018: sub defaultsetter {
3019: my $r=shift;
3020: my $bodytag=&Apache::loncommon::bodytag('Parameter Setting Default Actions');
3021: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3022: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3023: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Defaults');
3024: my $html=&Apache::lonxml::xmlbegin();
3025: $r->print(<<ENDDEFHEAD);
3026: $html
3027: <head>
3028: <title>LON-CAPA Parameters</title>
3029: </head>
3030: $bodytag
3031: $breadcrumbs
3032: <form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">
3033: ENDDEFHEAD
3034: my @ids=();
3035: my %typep=();
3036: my %keyp=();
3037: my %allparms=();
3038: my %allparts=();
3039: my %allmaps=();
3040: my %mapp=();
3041: my %symbp=();
3042: my %maptitles=();
3043: my %uris=();
3044: my %keyorder=&standardkeyorder();
3045: my %defkeytype=();
3046:
3047: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
3048: \%mapp, \%symbp,\%maptitles,\%uris,
3049: \%keyorder,\%defkeytype);
3050: if ($env{'form.storerules'}) {
3051: my %newrules=();
3052: my @delrules=();
3053: my %triggers=();
3054: foreach my $key (keys(%env)) {
3055: if ($key=~/^form\.(\w+)\_action$/) {
3056: my $tempkey=$1;
3057: my $action=$env{$key};
3058: if ($action) {
3059: $newrules{$tempkey.'_action'}=$action;
3060: if ($action ne 'default') {
3061: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
3062: $triggers{$whichparm}.=$tempkey.':';
3063: }
3064: $newrules{$tempkey.'_type'}=$defkeytype{$tempkey};
3065: if (&isdateparm($defkeytype{$tempkey})) {
3066: $newrules{$tempkey.'_days'}=$env{'form.'.$tempkey.'_days'};
3067: $newrules{$tempkey.'_hours'}=$env{'form.'.$tempkey.'_hours'};
3068: $newrules{$tempkey.'_min'}=$env{'form.'.$tempkey.'_min'};
3069: $newrules{$tempkey.'_sec'}=$env{'form.'.$tempkey.'_sec'};
3070: } else {
3071: $newrules{$tempkey.'_value'}=$env{'form.'.$tempkey.'_value'};
3072: $newrules{$tempkey.'_triggervalue'}=$env{'form.'.$tempkey.'_triggervalue'};
3073: }
3074: } else {
3075: push(@delrules,$tempkey.'_action');
3076: push(@delrules,$tempkey.'_type');
3077: push(@delrules,$tempkey.'_hours');
3078: push(@delrules,$tempkey.'_min');
3079: push(@delrules,$tempkey.'_sec');
3080: push(@delrules,$tempkey.'_value');
3081: }
3082: }
3083: }
3084: foreach my $key (keys %allparms) {
3085: $newrules{$key.'_triggers'}=$triggers{$key};
3086: }
3087: &Apache::lonnet::put('parmdefactions',\%newrules,$dom,$crs);
3088: &Apache::lonnet::del('parmdefactions',\@delrules,$dom,$crs);
3089: &resetrulescache();
3090: }
3091: my %lt=&Apache::lonlocal::texthash('days' => 'Days',
3092: 'hours' => 'Hours',
3093: 'min' => 'Minutes',
3094: 'sec' => 'Seconds',
3095: 'yes' => 'Yes',
3096: 'no' => 'No');
3097: my @standardoptions=('','default');
3098: my @standarddisplay=('',&mt('Default value when manually setting'));
3099: my @dateoptions=('','default');
3100: my @datedisplay=('',&mt('Default value when manually setting'));
3101: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
3102: unless ($tempkey) { next; }
3103: push @standardoptions,'when_setting_'.$tempkey;
3104: push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
3105: if (&isdateparm($defkeytype{$tempkey})) {
3106: push @dateoptions,'later_than_'.$tempkey;
3107: push @datedisplay,&mt('Automatically set later than ').$tempkey;
3108: push @dateoptions,'earlier_than_'.$tempkey;
3109: push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
3110: }
3111: }
3112: $r->print(&mt('Manual setting rules apply to all interfaces.').'<br />'.
3113: &mt('Automatic setting rules apply to table mode interfaces only.'));
3114: $r->print("\n<table border='1'><tr><th>".&mt('Rule for parameter').'</th><th>'.
3115: &mt('Action').'</th><th>'.&mt('Value').'</th></tr>');
3116: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
3117: unless ($tempkey) { next; }
3118: $r->print("\n<tr><td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
3119: my $action=&rulescache($tempkey.'_action');
3120: $r->print('<select name="'.$tempkey.'_action">');
3121: if (&isdateparm($defkeytype{$tempkey})) {
3122: for (my $i=0;$i<=$#dateoptions;$i++) {
3123: if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
3124: $r->print("\n<option value='$dateoptions[$i]'".
3125: ($dateoptions[$i] eq $action?' selected="selected"':'').
3126: ">$datedisplay[$i]</option>");
3127: }
3128: } else {
3129: for (my $i=0;$i<=$#standardoptions;$i++) {
3130: if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
3131: $r->print("\n<option value='$standardoptions[$i]'".
3132: ($standardoptions[$i] eq $action?' selected="selected"':'').
3133: ">$standarddisplay[$i]</option>");
3134: }
3135: }
3136: $r->print('</select>');
3137: unless (&isdateparm($defkeytype{$tempkey})) {
3138: $r->print("\n<br />".&mt('Triggering value(s) of other parameter (optional, comma-separated):').
3139: '<input type="text" size="20" name="'.$tempkey.'_triggervalue" value="'.&rulescache($tempkey.'_triggervalue').'" />');
3140: }
3141: $r->print("\n</td><td>\n");
3142:
3143: if (&isdateparm($defkeytype{$tempkey})) {
3144: my $days=&rulescache($tempkey.'_days');
3145: my $hours=&rulescache($tempkey.'_hours');
3146: my $min=&rulescache($tempkey.'_min');
3147: my $sec=&rulescache($tempkey.'_sec');
3148: $r->print(<<ENDINPUTDATE);
3149: <input name="$tempkey\_days" type="text" size="4" value="$days" />$lt{'days'}<br />
3150: <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
3151: <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
3152: <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
3153: ENDINPUTDATE
3154: } elsif ($defkeytype{$tempkey} eq 'string_yesno') {
3155: my $yeschecked='';
3156: my $nochecked='';
3157: if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked='checked="checked"'; }
3158: if (&rulescache($tempkey.'_value') eq 'no') { $nochecked='checked="checked"'; }
3159:
3160: $r->print(<<ENDYESNO);
3161: <label><input type="radio" name="$tempkey\_value" value="yes" $yeschecked /> $lt{'yes'}</label><br />
3162: <label><input type="radio" name="$tempkey\_value" value="no" $nochecked /> $lt{'no'}</label>
3163: ENDYESNO
3164: } else {
3165: $r->print('<input type="text" size="20" name="'.$tempkey.'_value" value="'.&rulescache($tempkey.'_value').'" />');
3166: }
3167: $r->print('</td></tr>');
3168: }
3169: $r->print("</table>\n<input type='submit' name='storerules' value='".
3170: &mt('Store Rules')."' /></form>\n</body>\n</html>");
3171: return;
3172: }
3173:
3174: ##################################################
3175: ##################################################
3176:
3177: =pod
3178:
3179: =item * handler
3180:
3181: Main handler. Calls &assessparms and &crsenv subroutines.
3182:
3183: =cut
3184: ##################################################
3185: ##################################################
3186: # use Data::Dumper;
3187:
3188:
3189: sub handler {
3190: my $r=shift;
3191:
3192: if ($r->header_only) {
3193: &Apache::loncommon::content_type($r,'text/html');
3194: $r->send_http_header;
3195: return OK;
3196: }
3197: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3198: ['action','state',
3199: 'pres_marker',
3200: 'pres_value',
3201: 'pres_type',
3202: 'udom','uname','symb','serial']);
3203:
3204:
3205: &Apache::lonhtmlcommon::clear_breadcrumbs();
3206: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
3207: text=>"Parameter Manager",
3208: faq=>10,
3209: bug=>'Instructor Interface'});
3210:
3211: # ----------------------------------------------------- Needs to be in a course
3212: my $parm_permission =
3213: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
3214: &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
3215: $env{'request.course.sec'}));
3216: if ($env{'request.course.id'} && $parm_permission) {
3217:
3218: # Start Page
3219: &Apache::loncommon::content_type($r,'text/html');
3220: $r->send_http_header;
3221:
3222:
3223: # id numbers can change on re-ordering of folders
3224:
3225: &resetsymbcache();
3226:
3227: #
3228: # Main switch on form.action and form.state, as appropriate
3229: #
3230: # Check first if coming from someone else headed directly for
3231: # the table mode
3232: if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
3233: && (!$env{'form.dis'})) || ($env{'form.symb'})) {
3234: &assessparms($r);
3235:
3236: } elsif (! exists($env{'form.action'})) {
3237: $r->print(&header());
3238: $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
3239: 'Parameter Manager'));
3240: &print_main_menu($r,$parm_permission);
3241: } elsif ($env{'form.action'} eq 'crsenv' && $parm_permission) {
3242: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=crsenv',
3243: text=>"Course Environment"});
3244: &crsenv($r);
3245: } elsif ($env{'form.action'} eq 'setoverview' && $parm_permission) {
3246: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
3247: text=>"Overview Mode"});
3248: &overview($r);
3249: } elsif ($env{'form.action'} eq 'setrestrictmeta' && $parm_permission) {
3250: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
3251: text=>"Restrict Metadata"});
3252: &setrestrictmeta($r);
3253: } elsif ($env{'form.action'} eq 'newoverview' && $parm_permission) {
3254: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
3255: text=>"Overview Mode"});
3256: &newoverview($r);
3257: } elsif ($env{'form.action'} eq 'setdefaults' && $parm_permission) {
3258: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
3259: text=>"Set Defaults"});
3260: &defaultsetter($r);
3261: } elsif ($env{'form.action'} eq 'settable' && $parm_permission) {
3262: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
3263: text=>"Table Mode",
3264: help => 'Course_Setting_Parameters'});
3265: &assessparms($r);
3266: }
3267:
3268: } else {
3269: # ----------------------------- Not in a course, or not allowed to modify parms
3270: $env{'user.error.msg'}=
3271: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
3272: return HTTP_NOT_ACCEPTABLE;
3273: }
3274: return OK;
3275: }
3276:
3277: 1;
3278: __END__
3279:
3280: =pod
3281:
3282: =back
3283:
3284: =cut
3285:
3286:
3287:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>