File:
[LON-CAPA] /
loncom /
interface /
lonparmset.pm
Revision
1.372:
download - view:
text,
annotated -
select for diffs
Fri Jul 20 00:15:06 2007 UTC (17 years, 1 month ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Student-viewable classlist can now be set to only display students who have agreed to be listed, and can also be set to indicate whether there are viewable portfolio files.
- new options set in Course Parameters
- students set option to appear in roster in roster page itself.
1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
4: # $Id: lonparmset.pm,v 1.372 2007/07/20 00:15:06 raeburn 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: use Apache::longroup;
67: use Apache::lonrss;
68: use LONCAPA qw(:DEFAULT :match);
69:
70: # --- Caches local to lonparmset
71:
72: my $parmhashid;
73: my %parmhash;
74: my $symbsid;
75: my %symbs;
76: my $rulesid;
77: my %rules;
78:
79: # --- end local caches
80:
81: ##################################################
82: ##################################################
83:
84: =pod
85:
86: =item parmval
87:
88: Figure out a cascading parameter.
89:
90: Inputs: $what - a parameter spec (incluse part info and name I.E. 0.weight)
91: $id - a bighash Id number
92: $def - the resource's default value 'stupid emacs
93:
94: 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
95:
96: 14- General Course
97: 13- Map or Folder level in course
98: 12- resource default
99: 11- map default
100: 10- resource level in course
101: 9 - General for section
102: 8 - Map or Folder level for section
103: 7 - resource level in section
104: 6 - General for group
105: 5 - Map or Folder level for group
106: 4 - resource level in group
107: 3 - General for specific student
108: 2 - Map or Folder level for specific student
109: 1 - resource level for specific student
110:
111: =cut
112:
113: ##################################################
114: sub parmval {
115: my ($what,$id,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
116: return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec,
117: $cgroup,$courseopt);
118: }
119:
120: sub parmval_by_symb {
121: my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
122: # load caches
123: &cacheparmhash();
124:
125: my $useropt;
126: if ($uname ne '' && $udom ne '') {
127: $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
128: }
129:
130: my $result='';
131: my @outpar=();
132: # ----------------------------------------------------- Cascading lookup scheme
133: my $map=(&Apache::lonnet::decode_symb($symb))[0];
134: $map = &Apache::lonnet::deversion($map);
135:
136: my $symbparm=$symb.'.'.$what;
137: my $mapparm=$map.'___(all).'.$what;
138:
139: my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$what;
140: my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
141: my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
142:
143: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
144: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
145: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
146:
147: my $courselevel=$env{'request.course.id'}.'.'.$what;
148: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
149: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
150:
151:
152: # --------------------------------------------------------- first, check course
153:
154: if (defined($$courseopt{$courselevel})) {
155: $outpar[14]=$$courseopt{$courselevel};
156: $result=14;
157: }
158:
159: if (defined($$courseopt{$courselevelm})) {
160: $outpar[13]=$$courseopt{$courselevelm};
161: $result=13;
162: }
163:
164: # ------------------------------------------------------- second, check default
165:
166: if (defined($def)) { $outpar[12]=$def; $result=12; }
167:
168: # ------------------------------------------------------ third, check map parms
169:
170: my $thisparm=$parmhash{$symbparm};
171: if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }
172:
173: if (defined($$courseopt{$courselevelr})) {
174: $outpar[10]=$$courseopt{$courselevelr};
175: $result=10;
176: }
177:
178: # ------------------------------------------------------ fourth, back to course
179: if ($csec ne '') {
180: if (defined($$courseopt{$seclevel})) {
181: $outpar[9]=$$courseopt{$seclevel};
182: $result=9;
183: }
184: if (defined($$courseopt{$seclevelm})) {
185: $outpar[8]=$$courseopt{$seclevelm};
186: $result=8;
187: }
188:
189: if (defined($$courseopt{$seclevelr})) {
190: $outpar[7]=$$courseopt{$seclevelr};
191: $result=7;
192: }
193: }
194: # ------------------------------------------------------ fifth, check course group
195: if ($cgroup ne '') {
196: if (defined($$courseopt{$grplevel})) {
197: $outpar[6]=$$courseopt{$grplevel};
198: $result=6;
199: }
200: if (defined($$courseopt{$grplevelm})) {
201: $outpar[5]=$$courseopt{$grplevelm};
202: $result=5;
203: }
204: if (defined($$courseopt{$grplevelr})) {
205: $outpar[4]=$$courseopt{$grplevelr};
206: $result=4;
207: }
208: }
209:
210: # ---------------------------------------------------------- fifth, check user
211:
212: if ($uname ne '') {
213: if (defined($$useropt{$courselevel})) {
214: $outpar[3]=$$useropt{$courselevel};
215: $result=3;
216: }
217:
218: if (defined($$useropt{$courselevelm})) {
219: $outpar[2]=$$useropt{$courselevelm};
220: $result=2;
221: }
222:
223: if (defined($$useropt{$courselevelr})) {
224: $outpar[1]=$$useropt{$courselevelr};
225: $result=1;
226: }
227: }
228: return ($result,@outpar);
229: }
230:
231: sub resetparmhash {
232: $parmhashid='';
233: }
234:
235: sub cacheparmhash {
236: if ($parmhashid eq $env{'request.course.fn'}) { return; }
237: my %parmhashfile;
238: if (tie(%parmhashfile,'GDBM_File',
239: $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
240: %parmhash=%parmhashfile;
241: untie %parmhashfile;
242: $parmhashid=$env{'request.course.fn'};
243: }
244: }
245:
246: sub resetsymbcache {
247: $symbsid='';
248: }
249:
250: sub symbcache {
251: my $id=shift;
252: if ($symbsid ne $env{'request.course.id'}) {
253: %symbs=();
254: }
255: unless ($symbs{$id}) {
256: my $navmap = Apache::lonnavmaps::navmap->new();
257: if ($id=~/\./) {
258: my $resource=$navmap->getById($id);
259: $symbs{$id}=$resource->symb();
260: } else {
261: my $resource=$navmap->getByMapPc($id);
262: $symbs{$id}=&Apache::lonnet::declutter($resource->src());
263: }
264: $symbsid=$env{'request.course.id'};
265: }
266: return $symbs{$id};
267: }
268:
269: sub resetrulescache {
270: $rulesid='';
271: }
272:
273: sub rulescache {
274: my $id=shift;
275: if ($rulesid ne $env{'request.course.id'}
276: && !defined($rules{$id})) {
277: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
278: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
279: %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
280: $rulesid=$env{'request.course.id'};
281: }
282: return $rules{$id};
283: }
284:
285: sub preset_defaults {
286: my $type=shift;
287: if (&rulescache($type.'_action') eq 'default') {
288: # yes, there is something
289: return (&rulescache($type.'_hours'),
290: &rulescache($type.'_min'),
291: &rulescache($type.'_sec'),
292: &rulescache($type.'_value'));
293: } else {
294: # nothing there or something else
295: return ('','','','','');
296: }
297: }
298:
299: ##################################################
300:
301: sub date_sanity_info {
302: my $checkdate=shift;
303: unless ($checkdate) { return ''; }
304: my $result='';
305: my $crsprefix='course.'.$env{'request.course.id'}.'.';
306: if ($env{$crsprefix.'default_enrollment_end_date'}) {
307: if ($checkdate>$env{$crsprefix.'default_enrollment_end_date'}) {
308: $result.='<br />'.&mt('After course enrollment end!');
309: }
310: }
311: if ($env{$crsprefix.'default_enrollment_start_date'}) {
312: if ($checkdate<$env{$crsprefix.'default_enrollment_start_date'}) {
313: $result.='<br />'.&mt('Before course enrollment start!');
314: }
315: }
316: return $result;
317: }
318: ##################################################
319: ##################################################
320: #
321: # Store a parameter by ID
322: #
323: # Takes
324: # - resource id
325: # - name of parameter
326: # - level
327: # - new value
328: # - new type
329: # - username
330: # - userdomain
331:
332: sub storeparm {
333: my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
334: &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,'',$cgroup);
335: }
336:
337: #
338: # Store a parameter by symb
339: #
340: # Takes
341: # - symb
342: # - name of parameter
343: # - level
344: # - new value
345: # - new type
346: # - username
347: # - userdomain
348:
349: my %recstack;
350: sub storeparm_by_symb {
351: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
352: unless ($recflag) {
353: # first time call
354: %recstack=();
355: $recflag=1;
356: }
357: # store parameter
358: &storeparm_by_symb_inner
359: ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup);
360: # don't do anything if parameter was reset
361: unless ($nval) { return; }
362: my ($prefix,$parm)=($spnam=~/^(.*[\_\.])([^\_\.]+)$/);
363: # remember that this was set
364: $recstack{$parm}=1;
365: # what does this trigger?
366: foreach my $triggered (split(/\:/,&rulescache($parm.'_triggers'))) {
367: # don't backfire
368: unless ((!$triggered) || ($recstack{$triggered})) {
369: my $action=&rulescache($triggered.'_action');
370: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
371: # set triggered parameter on same level
372: my $newspnam=$prefix.$triggered;
373: my $newvalue='';
374: my $active=1;
375: if ($action=~/^when\_setting/) {
376: # are there restrictions?
377: if (&rulescache($triggered.'_triggervalue')=~/\w/) {
378: $active=0;
379: foreach my $possiblevalue (split(/\s*\,\s*/,&rulescache($triggered.'_triggervalue'))) {
380: if (lc($possiblevalue) eq lc($nval)) { $active=1; }
381: }
382: }
383: $newvalue=&rulescache($triggered.'_value');
384: } else {
385: my $totalsecs=((&rulescache($triggered.'_days')*24+&rulescache($triggered.'_hours'))*60+&rulescache($triggered.'_min'))*60+&rulescache($triggered.'_sec');
386: if ($action=~/^later\_than/) {
387: $newvalue=$nval+$totalsecs;
388: } else {
389: $newvalue=$nval-$totalsecs;
390: }
391: }
392: if ($active) {
393: &storeparm_by_symb($symb,$newspnam,$snum,$newvalue,&rulescache($triggered.'_type'),
394: $uname,$udom,$csec,$recflag,$cgroup);
395: }
396: }
397: }
398: return '';
399: }
400:
401: sub log_parmset {
402: return &Apache::lonnet::instructor_log('parameterlog',@_);
403: }
404:
405: sub storeparm_by_symb_inner {
406: # ---------------------------------------------------------- Get symb, map, etc
407: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
408: # ---------------------------------------------------------- Construct prefixes
409: $spnam=~s/\_([^\_]+)$/\.$1/;
410: my $map=(&Apache::lonnet::decode_symb($symb))[0];
411: $map = &Apache::lonnet::deversion($map);
412:
413: my $symbparm=$symb.'.'.$spnam;
414: my $mapparm=$map.'___(all).'.$spnam;
415:
416: my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$spnam;
417: my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
418: my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
419:
420: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
421: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
422: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
423:
424: my $courselevel=$env{'request.course.id'}.'.'.$spnam;
425: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
426: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
427:
428: my $storeunder='';
429: if (($snum==14) || ($snum==3)) { $storeunder=$courselevel; }
430: if (($snum==13) || ($snum==2)) { $storeunder=$courselevelm; }
431: if (($snum==10) || ($snum==1)) { $storeunder=$courselevelr; }
432: if ($snum==9) { $storeunder=$seclevel; }
433: if ($snum==8) { $storeunder=$seclevelm; }
434: if ($snum==7) { $storeunder=$seclevelr; }
435: if ($snum==6) { $storeunder=$grplevel; }
436: if ($snum==5) { $storeunder=$grplevelm; }
437: if ($snum==4) { $storeunder=$grplevelr; }
438:
439:
440: my $delete;
441: if ($nval eq '') { $delete=1;}
442: my %storecontent = ($storeunder => $nval,
443: $storeunder.'.type' => $ntype);
444: my $reply='';
445: if ($snum>3) {
446: # ---------------------------------------------------------------- Store Course
447: #
448: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
449: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
450: # Expire sheets
451: &Apache::lonnet::expirespread('','','studentcalc');
452: if (($snum==10) || ($snum==7) || ($snum==4)) {
453: &Apache::lonnet::expirespread('','','assesscalc',$symb);
454: } elsif (($snum==11) || ($snum==8) || ($snum==5)) {
455: &Apache::lonnet::expirespread('','','assesscalc',$map);
456: } else {
457: &Apache::lonnet::expirespread('','','assesscalc');
458: }
459: # Store parameter
460: if ($delete) {
461: $reply=&Apache::lonnet::del
462: ('resourcedata',[keys(%storecontent)],$cdom,$cnum);
463: &log_parmset(\%storecontent,1);
464: } else {
465: $reply=&Apache::lonnet::cput
466: ('resourcedata',\%storecontent,$cdom,$cnum);
467: &log_parmset(\%storecontent);
468: }
469: &Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
470: } else {
471: # ------------------------------------------------------------------ Store User
472: #
473: # Expire sheets
474: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
475: if ($snum==1) {
476: &Apache::lonnet::expirespread
477: ($uname,$udom,'assesscalc',$symb);
478: } elsif ($snum==2) {
479: &Apache::lonnet::expirespread
480: ($uname,$udom,'assesscalc',$map);
481: } else {
482: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
483: }
484: # Store parameter
485: if ($delete) {
486: $reply=&Apache::lonnet::del
487: ('resourcedata',[keys(%storecontent)],$udom,$uname);
488: &log_parmset(\%storecontent,1,$uname,$udom);
489: } else {
490: $reply=&Apache::lonnet::cput
491: ('resourcedata',\%storecontent,$udom,$uname);
492: &log_parmset(\%storecontent,0,$uname,$udom);
493: }
494: &Apache::lonnet::devalidateuserresdata($uname,$udom);
495: }
496:
497: if ($reply=~/^error\:(.*)/) {
498: return "<span class=\"LC_error\">Write Error: $1</span>";
499: }
500: return '';
501: }
502:
503: ##################################################
504: ##################################################
505:
506: =pod
507:
508: =item valout
509:
510: Format a value for output.
511:
512: Inputs: $value, $type, $editable
513:
514: Returns: $value, formatted for output. If $type indicates it is a date,
515: localtime($value) is returned.
516: $editable will return an icon to click on
517:
518: =cut
519:
520: ##################################################
521: ##################################################
522: sub valout {
523: my ($value,$type,$editable)=@_;
524: my $result = '';
525: # Values of zero are valid.
526: if (! $value && $value ne '0') {
527: if ($editable) {
528: $result = '<span class="LC_clickhere">*</span>';
529: } else {
530: $result=' ';
531: }
532: } else {
533: if ($type eq 'date_interval') {
534: my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
535: $year=$year-70;
536: $mday--;
537: if ($year) {
538: $result.=$year.' yrs ';
539: }
540: if ($mon) {
541: $result.=$mon.' mths ';
542: }
543: if ($mday) {
544: $result.=$mday.' days ';
545: }
546: if ($hour) {
547: $result.=$hour.' hrs ';
548: }
549: if ($min) {
550: $result.=$min.' mins ';
551: }
552: if ($sec) {
553: $result.=$sec.' secs ';
554: }
555: $result=~s/\s+$//;
556: } elsif (&isdateparm($type)) {
557: $result = &Apache::lonlocal::locallocaltime($value).
558: &date_sanity_info($value);
559: } else {
560: $result = $value;
561: }
562: }
563: return $result;
564: }
565:
566: ##################################################
567: ##################################################
568:
569: =pod
570:
571: =item plink
572:
573: Produces a link anchor.
574:
575: Inputs: $type,$dis,$value,$marker,$return,$call
576:
577: Returns: scalar with html code for a link which will envoke the
578: javascript function 'pjump'.
579:
580: =cut
581:
582: ##################################################
583: ##################################################
584: sub plink {
585: my ($type,$dis,$value,$marker,$return,$call)=@_;
586: my $winvalue=$value;
587: unless ($winvalue) {
588: if (&isdateparm($type)) {
589: $winvalue=$env{'form.recent_'.$type};
590: } else {
591: $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
592: }
593: }
594: my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/);
595: my ($hour,$min,$sec,$val)=&preset_defaults($parmname);
596: unless (defined($winvalue)) { $winvalue=$val; }
597: return '<table width="100%"><tr valign="top" align="right"><td><a name="'.$marker.'" /></td></tr><tr><td align="center">'.
598: '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
599: .$marker."','".$return."','".$call."','".$hour."','".$min."','".$sec."'".');">'.
600: &valout($value,$type,1).'</a></td></tr></table>';
601: }
602:
603: sub page_js {
604:
605: my $selscript=&Apache::loncommon::studentbrowser_javascript();
606: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
607:
608: return(<<ENDJS);
609: <script type="text/javascript">
610:
611: function pclose() {
612: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
613: "height=350,width=350,scrollbars=no,menubar=no");
614: parmwin.close();
615: }
616:
617: $pjump_def
618:
619: function psub() {
620: pclose();
621: if (document.parmform.pres_marker.value!='') {
622: document.parmform.action+='#'+document.parmform.pres_marker.value;
623: var typedef=new Array();
624: typedef=document.parmform.pres_type.value.split('_');
625: if (document.parmform.pres_type.value!='') {
626: if (typedef[0]=='date') {
627: eval('document.parmform.recent_'+
628: document.parmform.pres_type.value+
629: '.value=document.parmform.pres_value.value;');
630: } else {
631: eval('document.parmform.recent_'+typedef[0]+
632: '.value=document.parmform.pres_value.value;');
633: }
634: }
635: document.parmform.submit();
636: } else {
637: document.parmform.pres_value.value='';
638: document.parmform.pres_marker.value='';
639: }
640: }
641:
642: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
643: var options = "width=" + w + ",height=" + h + ",";
644: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
645: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
646: var newWin = window.open(url, wdwName, options);
647: newWin.focus();
648: }
649: </script>
650: $selscript
651: ENDJS
652:
653: }
654: sub startpage {
655: my ($r) = @_;
656:
657: my %loaditems = ('onunload' => "pclose()",
658: 'onload' => "group_or_section('cgroup')",);
659:
660: my $start_page =
661: &Apache::loncommon::start_page('Set/Modify Course Parameters',
662: &page_js(),
663: {'add_entries' => \%loaditems,});
664: my $breadcrumbs =
665: &Apache::lonhtmlcommon::breadcrumbs('Table Mode Parameter Setting','Table_Mode');
666: $r->print(<<ENDHEAD);
667: $start_page
668: $breadcrumbs
669: <form method="post" action="/adm/parmset?action=settable" name="parmform">
670: <input type="hidden" value='' name="pres_value" />
671: <input type="hidden" value='' name="pres_type" />
672: <input type="hidden" value='' name="pres_marker" />
673: <input type="hidden" value='1' name="prevvisit" />
674: ENDHEAD
675: }
676:
677:
678: sub print_row {
679: my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
680: $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups)=@_;
681: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
682: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
683: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
684: # get the values for the parameter in cascading order
685: # empty levels will remain empty
686: my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
687: $rid,$$default{$which},$uname,$udom,$csec,$cgroup,$courseopt);
688: # get the type for the parameters
689: # problem: these may not be set for all levels
690: my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
691: $$name{$which}.'.type',$rid,
692: $$defaulttype{$which},$uname,$udom,$csec,$cgroup,$courseopt);
693: # cascade down manually
694: my $cascadetype=$$defaulttype{$which};
695: for (my $i=14;$i>0;$i--) {
696: if ($typeoutpar[$i]) {
697: $cascadetype=$typeoutpar[$i];
698: } else {
699: $typeoutpar[$i]=$cascadetype;
700: }
701: }
702: my $parm=$$display{$which};
703:
704: if ($parmlev eq 'full') {
705: $r->print('<td bgcolor='.$defbgtwo.' align="center">'
706: .$$part{$which}.'</td>');
707: } else {
708: $parm=~s|\[.*\]\s||g;
709: }
710: my $automatic=&rulescache(($which=~/\_([^\_]+)$/)[0].'_triggers');
711: if ($automatic) {
712: $parm.='<span class="LC_warning"><br />'.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).'</span>';
713: }
714: $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
715:
716: my $thismarker=$which;
717: $thismarker=~s/^parameter\_//;
718: my $mprefix=$rid.'&'.$thismarker.'&';
719: my $effective_parm = &valout($outpar[$result],$typeoutpar[$result]);
720: my ($othergrp,$grp_parm,$controlgrp);
721:
722: if ($parmlev eq 'general') {
723:
724: if ($uname) {
725: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
726: } elsif ($cgroup) {
727: &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
728: } elsif ($csec) {
729: &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
730: } else {
731: &print_td($r,14,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
732: }
733: } elsif ($parmlev eq 'map') {
734:
735: if ($uname) {
736: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
737: } elsif ($cgroup) {
738: &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
739: } elsif ($csec) {
740: &print_td($r,8,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
741: } else {
742: &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
743: }
744: } else {
745: if ($uname) {
746: if (@{$usersgroups} > 1) {
747: my ($coursereply,$grp_parm,$controlgrp);
748: ($coursereply,$othergrp,$grp_parm,$controlgrp) =
749: &print_usergroups($r,$$part{$which}.'.'.$$name{$which},
750: $rid,$cgroup,$defbgone,$usersgroups,$result,$courseopt);
751: if ($coursereply && $result > 3) {
752: if (defined($controlgrp)) {
753: if ($cgroup ne $controlgrp) {
754: $effective_parm = $grp_parm;
755: $result = 0;
756: }
757: }
758: }
759: }
760: }
761:
762: &print_td($r,14,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
763:
764: &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
765: &print_td($r,12,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
766: &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
767: &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
768:
769: if ($csec) {
770: &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
771: &print_td($r,8,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
772: &print_td($r,7,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
773: }
774:
775: if ($cgroup) {
776: &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
777: &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
778: &print_td($r,4,$defbgthree,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
779: }
780:
781: if ($uname) {
782: if ($othergrp) {
783: $r->print($othergrp);
784: }
785: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
786: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
787: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
788: }
789:
790: } # end of $parmlev if/else
791: $r->print('<td bgcolor="#CCCCFF" align="center">'.$effective_parm.'</td>');
792:
793: if ($parmlev eq 'full') {
794: my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
795: '.'.$$name{$which},$$symbp{$rid});
796: my $sessionvaltype=$typeoutpar[$result];
797: if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
798: $r->print('<td bgcolor="#999999" align="center"><font color="#FFFFFF">'.
799: &valout($sessionval,$sessionvaltype).' '.
800: '</font></td>');
801: }
802: $r->print('</tr>');
803: $r->print("\n");
804: }
805:
806: sub print_td {
807: my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
808: $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
809: ' align="center">');
810: if ($which<11 || $which > 12) {
811: $r->print(&plink($$typeoutpar[$which],
812: $$display{$value},$$outpar[$which],
813: $mprefix."$which",'parmform.pres','psub'));
814: } else {
815: $r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
816: }
817: $r->print('</td>'."\n");
818: }
819:
820: sub print_usergroups {
821: my ($r,$what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
822: my $courseid = $env{'request.course.id'};
823: my $output;
824: my $symb = &symbcache($rid);
825: my $symbparm=$symb.'.'.$what;
826: my $map=(&Apache::lonnet::decode_symb($symb))[0];
827: my $mapparm=$map.'___(all).'.$what;
828: my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype) =
829: &parm_control_group($courseid,$usersgroups,$symbparm,$mapparm,$what,
830: $courseopt);
831: my $bgcolor = $defbg;
832: my $grp_parm;
833: if (($coursereply) && ($cgroup ne $resultgroup)) {
834: if ($result > 3) {
835: $bgcolor = '"#AAFFAA"';
836: $grp_parm = &valout($coursereply,$resulttype);
837: }
838: $grp_parm = &valout($coursereply,$resulttype);
839: $output = '<td bgcolor='.$bgcolor.' align="center">';
840: if ($resultgroup && $resultlevel) {
841: $output .= '<small><b>'.$resultgroup.'</b> ('.$resultlevel.'): </small>'.$grp_parm;
842: } else {
843: $output .= ' ';
844: }
845: $output .= '</td>';
846: } else {
847: $output .= '<td bgcolor='.$bgcolor.'> </td>';
848: }
849: return ($coursereply,$output,$grp_parm,$resultgroup);
850: }
851:
852: sub parm_control_group {
853: my ($courseid,$usersgroups,$symbparm,$mapparm,$what,$courseopt) = @_;
854: my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
855: my $grpfound = 0;
856: my @levels = ($symbparm,$mapparm,$what);
857: my @levelnames = ('resource','map/folder','general');
858: foreach my $group (@{$usersgroups}) {
859: if ($grpfound) { last; }
860: for (my $i=0; $i<@levels; $i++) {
861: my $item = $courseid.'.['.$group.'].'.$levels[$i];
862: if (defined($$courseopt{$item})) {
863: $coursereply = $$courseopt{$item};
864: $resultitem = $item;
865: $resultgroup = $group;
866: $resultlevel = $levelnames[$i];
867: $resulttype = $$courseopt{$item.'.type'};
868: $grpfound = 1;
869: last;
870: }
871: }
872: }
873: return($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
874: }
875:
876: =pod
877:
878: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
879:
880: Input: See list below:
881:
882: =over 4
883:
884: =item B<ids>: An array that will contain all of the ids in the course.
885:
886: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
887:
888: =item B<keyp>: hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
889:
890: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
891:
892: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
893:
894: =item B<allkeys>: hash, full key to part->display value (what's display value?)
895:
896: =item B<allmaps>: hash, ???
897:
898: =item B<fcat>: ???
899:
900: =item B<defp>: hash, ???
901:
902: =item B<mapp>: ??
903:
904: =item B<symbp>: hash, id->full sym?
905:
906: =back
907:
908: =cut
909:
910: sub extractResourceInformation {
911: my $ids = shift;
912: my $typep = shift;
913: my $keyp = shift;
914: my $allparms = shift;
915: my $allparts = shift;
916: my $allmaps = shift;
917: my $mapp = shift;
918: my $symbp = shift;
919: my $maptitles=shift;
920: my $uris=shift;
921: my $keyorder=shift;
922: my $defkeytype=shift;
923:
924: my $keyordercnt=100;
925:
926: my $navmap = Apache::lonnavmaps::navmap->new();
927: my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
928: foreach my $resource (@allres) {
929: my $id=$resource->id();
930: my ($mapid,$resid)=split(/\./,$id);
931: if ($mapid eq '0') { next; }
932: $$ids[$#$ids+1]=$id;
933: my $srcf=$resource->src();
934: $srcf=~/\.(\w+)$/;
935: $$typep{$id}=$1;
936: $$keyp{$id}='';
937: $$uris{$id}=$srcf;
938: foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
939: next if ($key!~/^parameter_/);
940:
941: # Hidden parameters
942: next if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm');
943: #
944: # allparms is a hash of parameter names
945: #
946: my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
947: if (!exists($$allparms{$name})) {
948: my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
949: my $parmdis = $display;
950: $parmdis =~ s/\[Part.*$//g;
951: $$allparms{$name}=$parmdis;
952: if (ref($defkeytype)) {
953: $$defkeytype{$name}=
954: &Apache::lonnet::metadata($srcf,$key.'.type');
955: }
956: }
957:
958: #
959: # allparts is a hash of all parts
960: #
961: my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
962: $$allparts{$part} = "Part: $part";
963: #
964: # Remember all keys going with this resource
965: #
966: if ($$keyp{$id}) {
967: $$keyp{$id}.=','.$key;
968: } else {
969: $$keyp{$id}=$key;
970: }
971: #
972: # Put in order
973: #
974: unless ($$keyorder{$key}) {
975: $$keyorder{$key}=$keyordercnt;
976: $keyordercnt++;
977: }
978: }
979:
980:
981: if (!exists($$mapp{$mapid})) {
982: $$mapp{$id}=
983: &Apache::lonnet::declutter($resource->enclosing_map_src());
984: $$mapp{$mapid}=$$mapp{$id};
985: $$allmaps{$mapid}=$$mapp{$id};
986: if ($mapid eq '1') {
987: $$maptitles{$mapid}='Main Course Documents';
988: } else {
989: $$maptitles{$mapid}=
990: &Apache::lonnet::gettitle($$mapp{$id});
991: }
992: $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
993: $$symbp{$mapid}=$$mapp{$id}.'___(all)';
994: } else {
995: $$mapp{$id} = $$mapp{$mapid};
996: }
997: $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
998: }
999: }
1000:
1001:
1002: ##################################################
1003: ##################################################
1004:
1005: sub isdateparm {
1006: my $type=shift;
1007: return (($type=~/^date/) && (!($type eq 'date_interval')));
1008: }
1009:
1010: sub parmmenu {
1011: my ($r,$allparms,$pscat,$keyorder)=@_;
1012: my $tempkey;
1013: $r->print(<<ENDSCRIPT);
1014: <script type="text/javascript">
1015: function checkall(value, checkName) {
1016: for (i=0; i<document.forms.parmform.elements.length; i++) {
1017: ele = document.forms.parmform.elements[i];
1018: if (ele.name == checkName) {
1019: document.forms.parmform.elements[i].checked=value;
1020: }
1021: }
1022: }
1023:
1024: function checkthis(thisvalue, checkName) {
1025: for (i=0; i<document.forms.parmform.elements.length; i++) {
1026: ele = document.forms.parmform.elements[i];
1027: if (ele.name == checkName) {
1028: if (ele.value == thisvalue) {
1029: document.forms.parmform.elements[i].checked=true;
1030: }
1031: }
1032: }
1033: }
1034:
1035: function checkdates() {
1036: checkthis('duedate','pscat');
1037: checkthis('opendate','pscat');
1038: checkthis('answerdate','pscat');
1039: }
1040:
1041: function checkdisset() {
1042: checkthis('discussend','pscat');
1043: checkthis('discusshide','pscat');
1044: }
1045:
1046: function checkcontdates() {
1047: checkthis('contentopen','pscat');
1048: checkthis('contentclose','pscat');
1049: }
1050:
1051:
1052: function checkvisi() {
1053: checkthis('hiddenresource','pscat');
1054: checkthis('encrypturl','pscat');
1055: checkthis('problemstatus','pscat');
1056: checkthis('contentopen','pscat');
1057: checkthis('opendate','pscat');
1058: }
1059:
1060: function checkparts() {
1061: checkthis('hiddenparts','pscat');
1062: checkthis('display','pscat');
1063: checkthis('ordered','pscat');
1064: }
1065:
1066: function checkstandard() {
1067: checkall(false,'pscat');
1068: checkdates();
1069: checkthis('weight','pscat');
1070: checkthis('maxtries','pscat');
1071: }
1072:
1073: </script>
1074: ENDSCRIPT
1075: $r->print();
1076: $r->print("\n<table id=\"LC_parm_overview_parm_menu\"><tr>");
1077: my $cnt=0;
1078: foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) {
1079: $r->print("\n<td><label><input type='checkbox' name='pscat' ");
1080: $r->print('value="'.$tempkey.'"');
1081: if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
1082: $r->print(' checked');
1083: }
1084: $r->print('>'.$$allparms{$tempkey}.'</label></td>');
1085: $cnt++;
1086: if ($cnt==3) {
1087: $r->print("</tr>\n<tr>");
1088: $cnt=0;
1089: }
1090: }
1091: $r->print('
1092: </tr><tr id=\"LC_parm_overview_parm_menu_selectors\"><td>
1093: <a href="javascript:checkall(true, \'pscat\')">Select All</a><br />
1094: <a href="javascript:checkstandard()">Select Common Only</a>
1095: </td><td>
1096: <a href="javascript:checkdates()">Add Problem Dates</a>
1097: <a href="javascript:checkcontdates()">Add Content Dates</a><br />
1098: <a href="javascript:checkdisset()">Add Discussion Settings</a>
1099: <a href="javascript:checkvisi()">Add Visibilities</a><br />
1100: <a href="javascript:checkparts()">Add Part Parameters</a>
1101: </td><td>
1102: <a href="javascript:checkall(false, \'pscat\')">Unselect All</a>
1103: </td>
1104: ');
1105: $r->print('</tr></table>');
1106: }
1107:
1108: sub partmenu {
1109: my ($r,$allparts,$psprt)=@_;
1110: $r->print('<select multiple name="psprt" size="8">');
1111: $r->print('<option value="all"');
1112: $r->print(' selected') unless (@{$psprt});
1113: $r->print('>'.&mt('All Parts').'</option>');
1114: my %temphash=();
1115: foreach (@{$psprt}) { $temphash{$_}=1; }
1116: foreach my $tempkey (sort {
1117: if ($a==$b) { return ($a cmp $b) } else { return ($a <=> $b); }
1118: } keys(%{$allparts})) {
1119: unless ($tempkey =~ /\./) {
1120: $r->print('<option value="'.$tempkey.'"');
1121: if ($$psprt[0] eq "all" || $temphash{$tempkey}) {
1122: $r->print(' selected');
1123: }
1124: $r->print('>'.$$allparts{$tempkey}.'</option>');
1125: }
1126: }
1127: $r->print('</select>');
1128: }
1129:
1130: sub usermenu {
1131: my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups)=@_;
1132: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
1133: &Apache::loncommon::selectstudent_link('parmform','uname','udom');
1134: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1135: my %lt=&Apache::lonlocal::texthash(
1136: 'se' => "Section",
1137: 'gr' => "Group",
1138: 'fu' => "For User",
1139: 'oi' => "or ID",
1140: 'ad' => "at Domain"
1141: );
1142: my $sections='';
1143: my %sectionhash = &Apache::loncommon::get_sections();
1144:
1145: my $groups;
1146: my %grouphash = &Apache::longroup::coursegroups();
1147:
1148: if (%sectionhash) {
1149: $sections=$lt{'se'}.': <select name="csec"';
1150: if (%grouphash && $parmlev ne 'full') {
1151: $sections .= qq| onchange="group_or_section('csec')" |;
1152: }
1153: $sections .= '>';
1154: foreach my $section ('',sort keys %sectionhash) {
1155: $sections.='<option value="'.$section.'" '.
1156: ($section eq $csec?'selected="selected"':'').'>'.$section.
1157: '</option>';
1158: }
1159: $sections.='</select>';
1160: }
1161: if (%sectionhash && %grouphash && $parmlev ne 'full') {
1162: $sections .= ' or ';
1163: $sections .= qq|
1164: <script type="text/javascript">
1165: function group_or_section(caller) {
1166: if (caller == "cgroup") {
1167: if (document.parmform.cgroup.selectedIndex != 0) {
1168: document.parmform.csec.selectedIndex = 0;
1169: }
1170: } else {
1171: if (document.parmform.csec.selectedIndex != 0) {
1172: document.parmform.cgroup.selectedIndex = 0;
1173: }
1174: }
1175: }
1176: </script>
1177: |;
1178: } else {
1179: $sections .= qq|
1180: <script type="text/javascript">
1181: function group_or_section(caller) {
1182: return;
1183: }
1184: </script>
1185: |;
1186: }
1187:
1188: if (%grouphash) {
1189: $groups=$lt{'gr'}.': <select name="cgroup"';
1190: if (%sectionhash && $env{'form.action'} eq 'settable') {
1191: $groups .= qq| onchange="group_or_section('cgroup')" |;
1192: }
1193: $groups .= '>';
1194: foreach my $grp ('',sort keys %grouphash) {
1195: $groups.='<option value="'.$grp.'" ';
1196: if ($grp eq $cgroup) {
1197: unless ((defined($uname)) && ($grp eq '')) {
1198: $groups .= 'selected="selected" ';
1199: }
1200: } elsif (!defined($cgroup)) {
1201: if (@{$usersgroups} == 1) {
1202: if ($grp eq $$usersgroups[0]) {
1203: $groups .= 'selected="selected" ';
1204: }
1205: }
1206: }
1207: $groups .= '>'.$grp.'</option>';
1208: }
1209: $groups.='</select>';
1210: }
1211: $r->print(<<ENDMENU);
1212: <b>
1213: $sections
1214: $groups
1215: <br />
1216: $lt{'fu'}
1217: <input type="text" value="$uname" size="12" name="uname" />
1218: $lt{'oi'}
1219: <input type="text" value="$id" size="12" name="id" />
1220: $lt{'ad'}
1221: $chooseopt
1222: </b>
1223: ENDMENU
1224: }
1225:
1226: sub displaymenu {
1227: my ($r,$allparms,$allparts,$pscat,$psprt,$keyorder)=@_;
1228: $r->print('<table border="1"><tr><th>'.&mt('Select Parameters to View').'</th><th>'.
1229: &mt('Select Parts to View').'</th></tr><tr><td>');
1230: &parmmenu($r,$allparms,$pscat,$keyorder);
1231: $r->print('</td><td>');
1232: &partmenu($r,$allparts,$psprt);
1233: $r->print('</td></tr></table>');
1234: }
1235:
1236: sub mapmenu {
1237: my ($r,$allmaps,$pschp,$maptitles)=@_;
1238: $r->print('<b>'.&mt('Select Enclosing Map or Folder').'</b> ');
1239: $r->print('<select name="pschp">');
1240: $r->print('<option value="all">'.&mt('All Maps or Folders').'</option>');
1241: foreach (sort {$$allmaps{$a} cmp $$allmaps{$b}} keys %{$allmaps}) {
1242: $r->print('<option value="'.$_.'"');
1243: if (($pschp eq $_)) { $r->print(' selected'); }
1244: $r->print('>'.$$maptitles{$_}.($$allmaps{$_}!~/^uploaded/?' ['.$$allmaps{$_}.']':'').'</option>');
1245: }
1246: $r->print("</select>");
1247: }
1248:
1249: sub levelmenu {
1250: my ($r,$alllevs,$parmlev)=@_;
1251: $r->print('<b>'.&mt('Select Parameter Level').
1252: &Apache::loncommon::help_open_topic('Course_Parameter_Levels').'</b> ');
1253: $r->print('<select name="parmlev">');
1254: foreach (reverse sort keys %{$alllevs}) {
1255: $r->print('<option value="'.$$alllevs{$_}.'"');
1256: if ($parmlev eq $$alllevs{$_}) {
1257: $r->print(' selected');
1258: }
1259: $r->print('>'.$_.'</option>');
1260: }
1261: $r->print("</select>");
1262: }
1263:
1264:
1265: sub sectionmenu {
1266: my ($r,$selectedsections)=@_;
1267: my %sectionhash = &Apache::loncommon::get_sections();
1268: return if (!%sectionhash);
1269:
1270: $r->print('<select name="Section" multiple="true" size="8" >');
1271: foreach my $s ('all',sort keys %sectionhash) {
1272: $r->print(' <option value="'.$s.'"');
1273: foreach (@{$selectedsections}) {
1274: if ($s eq $_) {
1275: $r->print(' selected');
1276: last;
1277: }
1278: }
1279: $r->print('>'.$s."</option>\n");
1280: }
1281: $r->print("</select>\n");
1282: }
1283:
1284: sub groupmenu {
1285: my ($r,$selectedgroups)=@_;
1286: my %grouphash = &Apache::longroup::coursegroups();
1287: return if (!%grouphash);
1288:
1289: $r->print('<select name="Group" multiple="true" size="8" >');
1290: foreach my $group (sort(keys(%grouphash))) {
1291: $r->print(' <option value="'.$group.'"');
1292: foreach (@{$selectedgroups}) {
1293: if ($group eq $_) {
1294: $r->print(' selected');
1295: last;
1296: }
1297: }
1298: $r->print('>'.$group."</option>\n");
1299: }
1300: $r->print("</select>\n");
1301: }
1302:
1303:
1304: sub keysplit {
1305: my $keyp=shift;
1306: return (split(/\,/,$keyp));
1307: }
1308:
1309: sub keysinorder {
1310: my ($name,$keyorder)=@_;
1311: return sort {
1312: $$keyorder{$a} <=> $$keyorder{$b};
1313: } (keys %{$name});
1314: }
1315:
1316: sub keysinorder_bytype {
1317: my ($name,$keyorder)=@_;
1318: return sort {
1319: my $ta=(split('_',$a))[-1];
1320: my $tb=(split('_',$b))[-1];
1321: if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) {
1322: return ($a cmp $b);
1323: }
1324: $$keyorder{'parameter_0_'.$ta} <=> $$keyorder{'parameter_0_'.$tb};
1325: } (keys %{$name});
1326: }
1327:
1328: sub keysindisplayorder {
1329: my ($name,$keyorder)=@_;
1330: return sort {
1331: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
1332: } (keys %{$name});
1333: }
1334:
1335: sub sortmenu {
1336: my ($r,$sortorder)=@_;
1337: $r->print('<br /><label><input type="radio" name="sortorder" value="realmstudent"');
1338: if ($sortorder eq 'realmstudent') {
1339: $r->print(' checked="on"');
1340: }
1341: $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
1342: $r->print('</label><br /><label><input type="radio" name="sortorder" value="studentrealm"');
1343: if ($sortorder eq 'studentrealm') {
1344: $r->print(' checked="on"');
1345: }
1346: $r->print(' />'.&mt('Sort by student (group/section) first, then realm').
1347: '</label>');
1348: }
1349:
1350: sub standardkeyorder {
1351: return ('parameter_0_opendate' => 1,
1352: 'parameter_0_duedate' => 2,
1353: 'parameter_0_answerdate' => 3,
1354: 'parameter_0_interval' => 4,
1355: 'parameter_0_weight' => 5,
1356: 'parameter_0_maxtries' => 6,
1357: 'parameter_0_hinttries' => 7,
1358: 'parameter_0_contentopen' => 8,
1359: 'parameter_0_contentclose' => 9,
1360: 'parameter_0_type' => 10,
1361: 'parameter_0_problemstatus' => 11,
1362: 'parameter_0_hiddenresource' => 12,
1363: 'parameter_0_hiddenparts' => 13,
1364: 'parameter_0_display' => 14,
1365: 'parameter_0_ordered' => 15,
1366: 'parameter_0_tol' => 16,
1367: 'parameter_0_sig' => 17,
1368: 'parameter_0_turnoffunit' => 18,
1369: 'parameter_0_discussend' => 19,
1370: 'parameter_0_discusshide' => 20);
1371: }
1372:
1373: ##################################################
1374: ##################################################
1375:
1376: =pod
1377:
1378: =item assessparms
1379:
1380: Show assessment data and parameters. This is a large routine that should
1381: be simplified and shortened... someday.
1382:
1383: Inputs: $r
1384:
1385: Returns: nothing
1386:
1387: Variables used (guessed by Jeremy):
1388:
1389: =over 4
1390:
1391: =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.
1392:
1393: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
1394:
1395: =item B<allmaps>:
1396:
1397: =back
1398:
1399: =cut
1400:
1401: ##################################################
1402: ##################################################
1403: sub assessparms {
1404:
1405: my $r=shift;
1406:
1407: my @ids=();
1408: my %symbp=();
1409: my %mapp=();
1410: my %typep=();
1411: my %keyp=();
1412: my %uris=();
1413: my %maptitles=();
1414:
1415: # -------------------------------------------------------- Variable declaration
1416:
1417: my %allmaps=();
1418: my %alllevs=();
1419:
1420: my $uname;
1421: my $udom;
1422: my $uhome;
1423: my $csec;
1424: my $cgroup;
1425: my @usersgroups = ();
1426:
1427: my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
1428:
1429: $alllevs{'Resource Level'}='full';
1430: $alllevs{'Map/Folder Level'}='map';
1431: $alllevs{'Course Level'}='general';
1432:
1433: my %allparms;
1434: my %allparts;
1435: #
1436: # Order in which these parameters will be displayed
1437: #
1438: my %keyorder=&standardkeyorder();
1439:
1440: @ids=();
1441: %symbp=();
1442: %typep=();
1443:
1444: my $message='';
1445:
1446: $csec=$env{'form.csec'};
1447: $cgroup=$env{'form.cgroup'};
1448:
1449: if ($udom=$env{'form.udom'}) {
1450: } elsif ($udom=$env{'request.role.domain'}) {
1451: } elsif ($udom=$env{'user.domain'}) {
1452: } else {
1453: $udom=$r->dir_config('lonDefDomain');
1454: }
1455:
1456: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
1457: my $pschp=$env{'form.pschp'};
1458: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
1459: if (!@psprt) { $psprt[0]='0'; }
1460:
1461: my $pssymb='';
1462: my $parmlev='';
1463:
1464: unless ($env{'form.parmlev'}) {
1465: $parmlev = 'map';
1466: } else {
1467: $parmlev = $env{'form.parmlev'};
1468: }
1469:
1470: # ----------------------------------------------- Was this started from grades?
1471:
1472: if (($env{'form.command'} eq 'set') && ($env{'form.url'})
1473: && (!$env{'form.dis'})) {
1474: my $url=$env{'form.url'};
1475: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1476: $pssymb=&Apache::lonnet::symbread($url);
1477: if (!@pscat) { @pscat=('all'); }
1478: $pschp='';
1479: $parmlev = 'full';
1480: } elsif ($env{'form.symb'}) {
1481: $pssymb=$env{'form.symb'};
1482: if (!@pscat) { @pscat=('all'); }
1483: $pschp='';
1484: $parmlev = 'full';
1485: } else {
1486: $env{'form.url'}='';
1487: }
1488:
1489: my $id=$env{'form.id'};
1490: if (($id) && ($udom)) {
1491: $uname=(&Apache::lonnet::idget($udom,$id))[1];
1492: if ($uname) {
1493: $id='';
1494: } else {
1495: $message=
1496: '<span class="LC_error">'.&mt("Unknown ID")." '$id' ".
1497: &mt('at domain')." '$udom'</span>";
1498: }
1499: } else {
1500: $uname=$env{'form.uname'};
1501: }
1502: unless ($udom) { $uname=''; }
1503: $uhome='';
1504: if ($uname) {
1505: $uhome=&Apache::lonnet::homeserver($uname,$udom);
1506: if ($uhome eq 'no_host') {
1507: $message=
1508: '<span class="LC_error">'.&mt("Unknown user")." '$uname' ".
1509: &mt("at domain")." '$udom'</span>";
1510: $uname='';
1511: } else {
1512: $csec=&Apache::lonnet::getsection($udom,$uname,
1513: $env{'request.course.id'});
1514:
1515: if ($csec eq '-1') {
1516: $message='<span class="LC_error">'.
1517: &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
1518: &mt("not in this course")."</span>";
1519: $uname='';
1520: $csec=$env{'form.csec'};
1521: $cgroup=$env{'form.cgroup'};
1522: } else {
1523: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1524: ('firstname','middlename','lastname','generation','id'));
1525: $message="\n<p>\n".&mt("Full Name").": ".
1526: $name{'firstname'}.' '.$name{'middlename'}.' '
1527: .$name{'lastname'}.' '.$name{'generation'}.
1528: "<br />\n".&mt('ID').": ".$name{'id'}.'<p>';
1529: }
1530: @usersgroups = &Apache::lonnet::get_users_groups(
1531: $udom,$uname,$env{'request.course.id'});
1532: if (@usersgroups > 0) {
1533: unless (grep(/^\Q$cgroup\E$/,@usersgroups)) {
1534: $cgroup = $usersgroups[0];
1535: }
1536: }
1537: }
1538: }
1539:
1540: unless ($csec) { $csec=''; }
1541: unless ($cgroup) { $cgroup=''; }
1542:
1543: # --------------------------------------------------------- Get all assessments
1544: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
1545: \%mapp, \%symbp,\%maptitles,\%uris,
1546: \%keyorder);
1547:
1548: $mapp{'0.0'} = '';
1549: $symbp{'0.0'} = '';
1550:
1551: # ---------------------------------------------------------- Anything to store?
1552: if ($env{'form.pres_marker'}) {
1553: my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
1554: my @values=split(/\&\&\&/,$env{'form.pres_value'});
1555: my @types=split(/\&\&\&/,$env{'form.pres_type'});
1556: for (my $i=0;$i<=$#markers;$i++) {
1557: $message.=&storeparm(split(/\&/,$markers[$i]),
1558: $values[$i],
1559: $types[$i],
1560: $uname,$udom,$csec,$cgroup);
1561: }
1562: # ---------------------------------------------------------------- Done storing
1563: $message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
1564: }
1565: #----------------------------------------------- if all selected, fill in array
1566: if ($pscat[0] eq "all") {@pscat = (keys %allparms);}
1567: if (!@pscat) { @pscat=('duedate','opendate','answerdate','weight','maxtries') };
1568: if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
1569: # ------------------------------------------------------------------ Start page
1570:
1571: &startpage($r);
1572:
1573: foreach ('tolerance','date_default','date_start','date_end',
1574: 'date_interval','int','float','string') {
1575: $r->print('<input type="hidden" value="'.
1576: $env{'form.recent_'.$_}.'" name="recent_'.$_.'" />');
1577: }
1578:
1579: if (!$pssymb) {
1580: $r->print('<table border="1"><tr><td>');
1581: &levelmenu($r,\%alllevs,$parmlev);
1582: if ($parmlev ne 'general') {
1583: $r->print('<td>');
1584: &mapmenu($r,\%allmaps,$pschp,\%maptitles);
1585: $r->print('</td>');
1586: }
1587: $r->print('</td></tr></table>');
1588: &displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder);
1589: } else {
1590: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
1591: my $title = &Apache::lonnet::gettitle($pssymb);
1592: $r->print(&mt('Specific Resource: [_1] ([_2])',$title,$resource).
1593: '<input type="hidden" value="'.$pssymb.'" name="symb" />'.
1594: '<br /><label><b>'.&mt('Show all parts').': <input type="checkbox" name="psprt" value="all"'.
1595: ($env{'form.psprt'}?' checked="checked"':'').' /></b></label><br />');
1596: }
1597: &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups);
1598:
1599: $r->print('<p>'.$message.'</p>');
1600:
1601: $r->print('<br /><input type="submit" name="dis" value="'.&mt("Update Parameter Display").'" />');
1602:
1603: my @temp_pscat;
1604: map {
1605: my $cat = $_;
1606: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
1607: } @pscat;
1608:
1609: @pscat = @temp_pscat;
1610:
1611: if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
1612: # ----------------------------------------------------------------- Start Table
1613: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
1614: my $csuname=$env{'user.name'};
1615: my $csudom=$env{'user.domain'};
1616:
1617: if ($parmlev eq 'full') {
1618: my $coursespan=$csec?8:5;
1619: my $userspan=3;
1620: if ($cgroup ne '') {
1621: $coursespan += 3;
1622: }
1623:
1624: $r->print('<p><table border=2>');
1625: $r->print('<tr><td colspan=5></td>');
1626: $r->print('<th colspan='.($coursespan).'>'.&mt('Any User').'</th>');
1627: if ($uname) {
1628: if (@usersgroups > 1) {
1629: $userspan ++;
1630: }
1631: $r->print('<th colspan="'.$userspan.'" rowspan="2">');
1632: $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
1633: }
1634: my %lt=&Apache::lonlocal::texthash(
1635: 'pie' => "Parameter in Effect",
1636: 'csv' => "Current Session Value",
1637: 'at' => 'at',
1638: 'rl' => "Resource Level",
1639: 'ic' => 'in Course',
1640: 'aut' => "Assessment URL and Title",
1641: 'type' => 'Type',
1642: 'emof' => "Enclosing Map or Folder",
1643: 'part' => 'Part',
1644: 'pn' => 'Parameter Name',
1645: 'def' => 'default',
1646: 'femof' => 'from Enclosing Map or Folder',
1647: 'gen' => 'general',
1648: 'foremf' => 'for Enclosing Map or Folder',
1649: 'fr' => 'for Resource'
1650: );
1651: $r->print(<<ENDTABLETWO);
1652: <th rowspan=3>$lt{'pie'}</th>
1653: <th rowspan=3>$lt{'csv'}<br />($csuname $lt{'at'} $csudom)</th>
1654: </tr><tr><td colspan=5></td><th colspan=2>$lt{'ic'}</th><th colspan=2>$lt{'rl'}</th>
1655: <th colspan=1>$lt{'ic'}</th>
1656:
1657: ENDTABLETWO
1658: if ($csec) {
1659: $r->print("<th colspan=3>".
1660: &mt("in Section")." $csec</th>");
1661: }
1662: if ($cgroup) {
1663: $r->print("<th colspan=3>".
1664: &mt("in Group")." $cgroup</th>");
1665: }
1666: $r->print(<<ENDTABLEHEADFOUR);
1667: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
1668: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
1669: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
1670: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
1671: ENDTABLEHEADFOUR
1672:
1673: if ($csec) {
1674: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1675: }
1676:
1677: if ($cgroup) {
1678: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1679: }
1680:
1681: if ($uname) {
1682: if (@usersgroups > 1) {
1683: $r->print('<th>'.&mt('Control by other group?').'</th>');
1684: }
1685: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1686: }
1687:
1688: $r->print('</tr>');
1689:
1690: my $defbgone='';
1691: my $defbgtwo='';
1692: my $defbgthree = '';
1693:
1694: foreach (@ids) {
1695:
1696: my $rid=$_;
1697: my ($inmapid)=($rid=~/\.(\d+)$/);
1698:
1699: if ((!$pssymb &&
1700: (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
1701: ||
1702: ($pssymb && $pssymb eq $symbp{$rid})) {
1703: # ------------------------------------------------------ Entry for one resource
1704: if ($defbgone eq '"#E0E099"') {
1705: $defbgone='"#E0E0DD"';
1706: } else {
1707: $defbgone='"#E0E099"';
1708: }
1709: if ($defbgtwo eq '"#FFFF99"') {
1710: $defbgtwo='"#FFFFDD"';
1711: } else {
1712: $defbgtwo='"#FFFF99"';
1713: }
1714: if ($defbgthree eq '"#FFBB99"') {
1715: $defbgthree='"#FFBBDD"';
1716: } else {
1717: $defbgthree='"#FFBB99"';
1718: }
1719:
1720: my $thistitle='';
1721: my %name= ();
1722: undef %name;
1723: my %part= ();
1724: my %display=();
1725: my %type= ();
1726: my %default=();
1727: my $uri=&Apache::lonnet::declutter($uris{$rid});
1728:
1729: foreach (&keysplit($keyp{$rid})) {
1730: my $tempkeyp = $_;
1731: if (grep $_ eq $tempkeyp, @catmarker) {
1732: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
1733: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
1734: $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
1735: unless ($display{$_}) { $display{$_}=''; }
1736: $display{$_}.=' ('.$name{$_}.')';
1737: $default{$_}=&Apache::lonnet::metadata($uri,$_);
1738: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
1739: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
1740: }
1741: }
1742: my $totalparms=scalar keys %name;
1743: if ($totalparms>0) {
1744: my $firstrow=1;
1745: my $title=&Apache::lonnet::gettitle($symbp{$rid});
1746: $r->print('<tr><td bgcolor='.$defbgone.
1747: ' rowspan='.$totalparms.
1748: '><tt><font size=-1>'.
1749: join(' / ',split(/\//,$uri)).
1750: '</font></tt><p><b>'.
1751: "<a href=\"javascript:openWindow('".
1752: &Apache::lonnet::clutter($uri).'?symb='.
1753: &escape($symbp{$rid}).
1754: "', 'metadatafile', '450', '500', 'no', 'yes');\"".
1755: " target=\"_self\">$title");
1756:
1757: if ($thistitle) {
1758: $r->print(' ('.$thistitle.')');
1759: }
1760: $r->print('</a></b></td>');
1761: $r->print('<td bgcolor='.$defbgtwo.
1762: ' rowspan='.$totalparms.'>'.$typep{$rid}.
1763: '</td>');
1764:
1765: $r->print('<td bgcolor='.$defbgone.
1766: ' rowspan='.$totalparms.
1767: '>'.$maptitles{$mapp{$rid}}.'</td>');
1768:
1769: foreach (&keysinorder_bytype(\%name,\%keyorder)) {
1770: unless ($firstrow) {
1771: $r->print('<tr>');
1772: } else {
1773: undef $firstrow;
1774: }
1775: &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
1776: \%type,\%display,$defbgone,$defbgtwo,
1777: $defbgthree,$parmlev,$uname,$udom,$csec,
1778: $cgroup,\@usersgroups);
1779: }
1780: }
1781: }
1782: } # end foreach ids
1783: # -------------------------------------------------- End entry for one resource
1784: $r->print('</table>');
1785: } # end of full
1786: #--------------------------------------------------- Entry for parm level map
1787: if ($parmlev eq 'map') {
1788: my $defbgone = '"E0E099"';
1789: my $defbgtwo = '"FFFF99"';
1790: my $defbgthree = '"FFBB99"';
1791:
1792: my %maplist;
1793:
1794: if ($pschp eq 'all') {
1795: %maplist = %allmaps;
1796: } else {
1797: %maplist = ($pschp => $mapp{$pschp});
1798: }
1799:
1800: #-------------------------------------------- for each map, gather information
1801: my $mapid;
1802: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
1803: my $maptitle = $maplist{$mapid};
1804:
1805: #----------------------- loop through ids and get all parameter types for map
1806: #----------------------------------------- and associated information
1807: my %name = ();
1808: my %part = ();
1809: my %display = ();
1810: my %type = ();
1811: my %default = ();
1812: my $map = 0;
1813:
1814: # $r->print("Catmarker: @catmarker<br />\n");
1815:
1816: foreach (@ids) {
1817: ($map)=(/([\d]*?)\./);
1818: my $rid = $_;
1819:
1820: # $r->print("$mapid:$map: $rid <br /> \n");
1821:
1822: if ($map eq $mapid) {
1823: my $uri=&Apache::lonnet::declutter($uris{$rid});
1824: # $r->print("Keys: $keyp{$rid} <br />\n");
1825:
1826: #--------------------------------------------------------------------
1827: # @catmarker contains list of all possible parameters including part #s
1828: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1829: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1830: # When storing information, store as part 0
1831: # When requesting information, request from full part
1832: #-------------------------------------------------------------------
1833: foreach (&keysplit($keyp{$rid})) {
1834: my $tempkeyp = $_;
1835: my $fullkeyp = $tempkeyp;
1836: $tempkeyp =~ s/_\w+_/_0_/;
1837:
1838: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1839: $part{$tempkeyp}="0";
1840: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1841: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1842: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1843: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1844: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1845: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1846: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1847: }
1848: } # end loop through keys
1849: }
1850: } # end loop through ids
1851:
1852: #---------------------------------------------------- print header information
1853: my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
1854: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
1855: $r->print(<<ENDMAPONE);
1856: <center><h4>
1857: Set Defaults for All Resources in $foldermap<br />
1858: <font color="red"><i>$showtitle</i></font><br />
1859: Specifically for
1860: ENDMAPONE
1861: if ($uname) {
1862: my $person=&Apache::loncommon::plainname($uname,$udom);
1863: $r->print(&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
1864: &mt('in')." \n");
1865: } else {
1866: $r->print("<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n");
1867: }
1868: if ($cgroup) {
1869: $r->print(&mt("Group")." <font color=\"red\"><i>$cgroup".
1870: "</i></font> ".&mt('of')." \n");
1871: $csec = '';
1872: } elsif ($csec) {
1873: $r->print(&mt("Section")." <font color=\"red\"><i>$csec".
1874: "</i></font> ".&mt('of')." \n");
1875: }
1876: $r->print("<font color=\"red\"><i>$coursename</i></font><br />");
1877: $r->print("</h4>\n");
1878: #---------------------------------------------------------------- print table
1879: $r->print('<p><table border="2">');
1880: $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
1881: $r->print('<th>'.&mt('Default Value').'</th>');
1882: $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1883:
1884: foreach (&keysinorder(\%name,\%keyorder)) {
1885: $r->print('<tr>');
1886: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1887: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
1888: $parmlev,$uname,$udom,$csec,$cgroup);
1889: }
1890: $r->print("</table></center>");
1891: } # end each map
1892: } # end of $parmlev eq map
1893: #--------------------------------- Entry for parm level general (Course level)
1894: if ($parmlev eq 'general') {
1895: my $defbgone = '"E0E099"';
1896: my $defbgtwo = '"FFFF99"';
1897: my $defbgthree = '"FFBB99"';
1898:
1899: #-------------------------------------------- for each map, gather information
1900: my $mapid="0.0";
1901: #----------------------- loop through ids and get all parameter types for map
1902: #----------------------------------------- and associated information
1903: my %name = ();
1904: my %part = ();
1905: my %display = ();
1906: my %type = ();
1907: my %default = ();
1908:
1909: foreach (@ids) {
1910: my $rid = $_;
1911:
1912: my $uri=&Apache::lonnet::declutter($uris{$rid});
1913:
1914: #--------------------------------------------------------------------
1915: # @catmarker contains list of all possible parameters including part #s
1916: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1917: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1918: # When storing information, store as part 0
1919: # When requesting information, request from full part
1920: #-------------------------------------------------------------------
1921: foreach (&keysplit($keyp{$rid})) {
1922: my $tempkeyp = $_;
1923: my $fullkeyp = $tempkeyp;
1924: $tempkeyp =~ s/_\w+_/_0_/;
1925: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1926: $part{$tempkeyp}="0";
1927: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1928: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1929: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1930: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1931: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1932: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1933: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1934: }
1935: } # end loop through keys
1936: } # end loop through ids
1937:
1938: #---------------------------------------------------- print header information
1939: my $setdef=&mt("Set Defaults for All Resources in Course");
1940: $r->print(<<ENDMAPONE);
1941: <center><h4>$setdef
1942: <font color="red"><i>$coursename</i></font><br />
1943: ENDMAPONE
1944: if ($uname) {
1945: my $person=&Apache::loncommon::plainname($uname,$udom);
1946: $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
1947: } else {
1948: $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
1949: }
1950:
1951: if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
1952: if ($cgroup) {$r->print(&mt("Group")."<font color=\"red\"> <i>$cgroup</i></font>\n")};
1953: $r->print("</h4>\n");
1954: #---------------------------------------------------------------- print table
1955: $r->print('<p><table border="2">');
1956: $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
1957: $r->print('<th>'.&mt('Default Value').'</th>');
1958: $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1959:
1960: foreach (&keysinorder(\%name,\%keyorder)) {
1961: $r->print('<tr>');
1962: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1963: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
1964: $parmlev,$uname,$udom,$csec,$cgroup);
1965: }
1966: $r->print("</table></center>");
1967: } # end of $parmlev eq general
1968: }
1969: $r->print('</form>'.&Apache::loncommon::end_page());
1970: } # end sub assessparms
1971:
1972:
1973: ##################################################
1974: ##################################################
1975:
1976: =pod
1977:
1978: =item crsenv
1979:
1980: Show and set course data and parameters. This is a large routine that should
1981: be simplified and shortened... someday.
1982:
1983: Inputs: $r
1984:
1985: Returns: nothing
1986:
1987: =cut
1988:
1989: ##################################################
1990: ##################################################
1991: sub crsenv {
1992: my $r=shift;
1993: my $setoutput='';
1994:
1995: my $breadcrumbs =
1996: &Apache::lonhtmlcommon::breadcrumbs('Edit Course Environment');
1997: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1998: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1999:
2000: #
2001: # Go through list of changes
2002: foreach (keys %env) {
2003: next if ($_!~/^form\.(.+)\_setparmval$/);
2004: my $name = $1;
2005: my $value = $env{'form.'.$name.'_value'};
2006: if ($name eq 'newp') {
2007: $name = $env{'form.newp_name'};
2008: }
2009: if ($name eq 'url') {
2010: $value=~s/^\/res\///;
2011: my $bkuptime=time;
2012: my @tmp = &Apache::lonnet::get
2013: ('environment',['url'],$dom,$crs);
2014: $setoutput.=&mt('Backing up previous URL').': '.
2015: &Apache::lonnet::put
2016: ('environment',
2017: {'top level map backup '.$bkuptime => $tmp[1] },
2018: $dom,$crs).
2019: '<br />';
2020: }
2021: #
2022: # Deal with modified default spreadsheets
2023: if ($name =~ /^spreadsheet_default_(classcalc|
2024: studentcalc|
2025: assesscalc)$/x) {
2026: my $sheettype = $1;
2027: if ($sheettype eq 'classcalc') {
2028: # no need to do anything since viewing the sheet will
2029: # cause it to be updated.
2030: } elsif ($sheettype eq 'studentcalc') {
2031: # expire all the student spreadsheets
2032: &Apache::lonnet::expirespread('','','studentcalc');
2033: } else {
2034: # expire all the assessment spreadsheets
2035: # this includes non-default spreadsheets, but better to
2036: # be safe than sorry.
2037: &Apache::lonnet::expirespread('','','assesscalc');
2038: # expire all the student spreadsheets
2039: &Apache::lonnet::expirespread('','','studentcalc');
2040: }
2041: }
2042: #
2043: # Deal with the enrollment dates
2044: if ($name =~ /^default_enrollment_(start|end)_date$/) {
2045: $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
2046: }
2047: #
2048: # Deal with the emails
2049: if ($name =~ /\.email$/) {
2050: foreach my $specifier (split(',',$value)) {
2051: my ($user,$sections_or_groups)=
2052: ($specifier=~/^([^\(]+)\(([^\)]+)\)/);
2053: if (!$sections_or_groups) {
2054: $user = $specifier;
2055: }
2056: my ($name,$domain) = split(':',$user);
2057: if (!defined($user) || !defined($domain)) {
2058: $setoutput.= '<br /> <span class="LC_error">'.
2059: &mt("Invalid email address specified, address must be of the form username:domain what was specified was ([_1])",$user).
2060: '</span>';
2061: undef($value);
2062: } elsif (&Apache::lonnet::homeserver($user,$domain) eq 'no_host') {
2063: $setoutput.= '<br /> <span class="LC_error">'.
2064: &mt("Invalid email address specified, user [_1] is unknown.",$name).
2065: '</span>';
2066: undef($value);
2067: }
2068: }
2069: }
2070: # Get existing cloners
2071: my @oldcloner = ();
2072: if ($name eq 'cloners') {
2073: my %clonenames=&Apache::lonnet::dump('environment',$dom,$crs,'cloners');
2074: if ($clonenames{'cloners'} =~ /,/) {
2075: @oldcloner = split/,/,$clonenames{'cloners'};
2076: } else {
2077: $oldcloner[0] = $clonenames{'cloners'};
2078: }
2079: }
2080: #
2081: # Let the user know we made the changes
2082: if ($name && defined($value)) {
2083: my $failed_cloners;
2084: if ($name eq 'cloners') {
2085: $value =~ s/\s//g;
2086: $value =~ s/^,//;
2087: $value =~ s/,$//;
2088: # check requested clones are valid users.
2089: $failed_cloners = &check_cloners(\$value,\@oldcloner);
2090: }
2091: my $put_result = &Apache::lonnet::put('environment',
2092: {$name=>$value},$dom,$crs);
2093: if ($put_result eq 'ok') {
2094: $setoutput.=&mt('Set').' <b>'.$name.'</b> '.&mt('to').' <b>'.$value.'</b>.<br />';
2095: if ($name eq 'cloners') {
2096: &change_clone($value,\@oldcloner);
2097: }
2098: # Flush the course logs so course description is immediately updated
2099: if ($name eq 'description' && defined($value)) {
2100: &Apache::lonnet::flushcourselogs();
2101: }
2102: } else {
2103: $setoutput.=&mt('Unable to set').' <b>'.$name.'</b> '.&mt('to').
2104: ' <b>'.$value.'</b> '.&mt('due to').' '.$put_result.'.<br />';
2105: }
2106: if (($name eq 'cloners') && ($failed_cloners)) {
2107: $setoutput.= &mt('Unable to include').' - <b>'.$failed_cloners.'</b>, '.
2108: &mt('reason').' - '.&mt('LON-CAPA user(s) do(es) not exist').
2109: '.<br />'.&mt('Please ').
2110: ' <a href="/adm/createuser">'.
2111: &mt('add the user(s)').'</a>, '.
2112: &mt('and then return to the ').
2113: '<a href="/admparmset?action=crsenv">'.
2114: &mt('Course Parameters page').'</a> '.
2115: &mt('to add the new user(s) to the list of possible cloners').
2116: '.<br />';
2117: }
2118: }
2119: }
2120:
2121: my $start_table =&Apache::loncommon::start_data_table();
2122: my $start_header_row=&Apache::loncommon::start_data_table_header_row();
2123: my $end_header_row =&Apache::loncommon::end_data_table_header_row();
2124: # ------------------------- Re-init course environment entries for this session
2125:
2126: &Apache::lonnet::coursedescription($env{'request.course.id'},
2127: {'freshen_cache' => 1});
2128:
2129: # -------------------------------------------------------- Get parameters again
2130:
2131: my %values=&Apache::lonnet::dump('environment',$dom,$crs);
2132: my $SelectStyleFile=&mt('Select Style File');
2133: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
2134: my $output='';
2135: if (! exists($values{'con_lost'})) {
2136: my %descriptions=
2137: ('url' => '<b>'.&mt('Top Level Map').'</b> '.
2138: '<a href="javascript:openbrowser'.
2139: "('envform','url','sequence')\">".
2140: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
2141: &mt('Modification may make assessment data inaccessible').
2142: '</span>',
2143: 'description' => '<b>'.&mt('Course Description').'</b>',
2144: 'courseid' => '<b>'.&mt('Course ID or number').
2145: '</b><br />'.
2146: '('.&mt('internal').', '.&mt('optional').')',
2147: '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.'),
2148: 'grading' => '<b>'.&mt('Grading').'</b><br />'.
2149: '<tt>"standard", "external", or "spreadsheet"</tt> '.&Apache::loncommon::help_open_topic('GradingOptions'),
2150: 'default_xml_style' => '<b>'.&mt('Default XML Style File').'</b> '.
2151: '<a href="javascript:openbrowser'.
2152: "('envform','default_xml_style'".
2153: ",'sty')\">$SelectStyleFile</a><br />",
2154: 'question.email' => '<b>'.&mt('Feedback Addresses for Resource Content Question').
2155: '</b><br />(<tt>user:domain,'.
2156: 'user:domain(section;section;...;*;...),...</tt>)',
2157: 'question.email.text' => '<b>'.&mt('Custom Text for Resource Content Question Option in Feedback').
2158: '</b>',
2159: 'comment.email' => '<b>'.&mt('Feedback Addresses for Course Content Comments').'</b><br />'.
2160: '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
2161: 'comment.email.text' => '<b>'.&mt('Custom Text for Course Content Option in Feedback').
2162: '</b>',
2163: 'policy.email' => '<b>'.&mt('Feedback Addresses for Course Policy').'</b>'.
2164: '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
2165: 'policy.email.text' => '<b>'.&mt('Custom Text for Course Policy Option in Feedback').
2166: '</b>',
2167: 'hideemptyrows' => '<b>'.&mt('Hide Empty Rows in Spreadsheets').'</b><br />'.
2168: '('.&mt('"[_1]" for default hiding','<tt>yes</tt>').')',
2169: 'pageseparators' => '<b>'.&mt('Visibly Separate Items on Pages').'</b><br />'.
2170: '('.&mt('"[_1]" for visible separation','<tt>yes</tt>').', '.
2171: &mt('changes will not show until next login').')',
2172: '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.'),
2173: 'student_classlist_portfiles' => '<b>'.&mt('Include link to accessible portfolio files').'</b><br />'.&mt('"[_1]" for link to each a listing of each student\'s files.','<tt>yes</tt>'),
2174: 'student_classlist_opt_in' => '<b>'.&mt("Student's agreement needed for listing in student-viewable roster").'</b><br />'.&mt('"[_1]" to require students to opt-in to listing in the roster (on the roster page).','<tt>yes</tt>'),
2175: 'plc.roles.denied'=> '<b>'.&mt('Disallow live chatroom use for Roles').
2176: '</b><br />"<tt>st</tt>": '.
2177: &mt('student').', "<tt>ta</tt>": '.
2178: 'TA, "<tt>in</tt>": '.
2179: &mt('instructor').';<br /><tt>'.&mt('role,role,...').'</tt>) '.
2180: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
2181: 'plc.users.denied' =>
2182: '<b>'.&mt('Disallow live chatroom use for Users').'</b><br />'.
2183: '(<tt>user:domain,user:domain,...</tt>)',
2184:
2185: 'pch.roles.denied'=> '<b>'.&mt('Disallow Resource Discussion for Roles').
2186: '</b><br />"<tt>st</tt>": '.
2187: 'student, "<tt>ta</tt>": '.
2188: 'TA, "<tt>in</tt>": '.
2189: 'instructor;<br /><tt>role,role,...</tt>) '.
2190: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
2191: 'pch.users.denied' =>
2192: '<b>'.&mt('Disallow Resource Discussion for Users').'</b><br />'.
2193: '(<tt>user:domain,user:domain,...</tt>)',
2194: 'spreadsheet_default_classcalc'
2195: => '<b>'.&mt('Default Course Spreadsheet').'</b> '.
2196: '<a href="javascript:openbrowser'.
2197: "('envform','spreadsheet_default_classcalc'".
2198: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
2199: 'spreadsheet_default_studentcalc'
2200: => '<b>'.&mt('Default Student Spreadsheet').'</b> '.
2201: '<a href="javascript:openbrowser'.
2202: "('envform','spreadsheet_default_calc'".
2203: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
2204: 'spreadsheet_default_assesscalc'
2205: => '<b>'.&mt('Default Assessment Spreadsheet').'</b> '.
2206: '<a href="javascript:openbrowser'.
2207: "('envform','spreadsheet_default_assesscalc'".
2208: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
2209: 'allow_limited_html_in_feedback'
2210: => '<b>'.&mt('Allow limited HTML in discussion posts').'</b><br />'.
2211: '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
2212: 'allow_discussion_post_editing'
2213: => '<b>'.&mt('Allow users with specified roles to edit/delete their own discussion posts').'</b><br />"<tt>st</tt>": '.
2214: &mt('student').', "<tt>ta</tt>": '.
2215: 'TA, "<tt>in</tt>": '.
2216: &mt('instructor').'; (<tt>'.&mt('role:section,role:section,..., e.g., st:001,st:002,in,cc would permit students in sections 001 and 002 and instructors in any section, and course coordinators to edit their own posts.').'</tt>)<br />'.
2217: '('.&mt('or set value to "[_1]" to allow all roles',"<tt>yes</tt>").')',
2218: 'rndseed'
2219: => '<b>'.&mt('Randomization algorithm used').'</b> <br />'.
2220: '<span class="LC_error">'.&mt('Modifying this will make problems').' '.
2221: &mt('have different numbers and answers').'</span>',
2222: 'receiptalg'
2223: => '<b>'.&mt('Receipt algorithm used').'</b> <br />'.
2224: &mt('This controls how receipt numbers are generated.'),
2225: 'suppress_tries'
2226: => '<b>'.&mt('Suppress number of tries in printing').'</b><br />'.
2227: ' ('.&mt('"[_1]" to suppress, anything else to not suppress','<tt>yes</tt>').')',
2228: 'problem_stream_switch'
2229: => '<b>'.&mt('Allow problems to be split over pages').'</b><br />'.
2230: ' ('.&mt('"[_1]" if allowed, anything else if not','<tt>yes</tt>').')',
2231: 'default_paper_size'
2232: => '<b>'.&mt('Default paper type').'</b><br />'.
2233: ' ('.&mt('supported types').': Letter [8 1/2x11 in], Legal [8 1/2x14 in],'.
2234: ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'.
2235: ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])',
2236: 'print_header_format'
2237: => &mtn('<b> Print header format; substitutions </b>: %n student name %c course id %a assignment note, numbers after the % limit the field size.').'</b>',
2238: 'default_enrollment_start_date' => '<b>'.&mt('Default beginning date for student access.').'</b>',
2239: 'default_enrollment_end_date' => '<b>'.&mt('Default ending date for student access.').'</b>',
2240: 'nothideprivileged' => '<b>'.&mt('Privileged users that should not be hidden on staff listings').'</b>'.
2241: '<br />(<tt>user:domain,user:domain,...</tt>)',
2242: 'languages' => '<b>'.&mt('Languages used').'</b>',
2243: 'disable_receipt_display'
2244: => '<b>'.&mt('Disable display of problem receipts').'</b><br />'.
2245: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
2246: 'task_messages'
2247: => '<b>'.&mt('Send message to student when clicking Done on Tasks').'</b><br /> ('.&mt('[_1] to send a message only to student, [_2] to send message to student and add record to user information page for instructors. Leave blank to disable.','<tt>only_student</tt>','<tt>student_and_user_notes_screen</tt>').')',
2248: 'disablesigfigs'
2249: => '<b>'.&mt('Disable checking of Significant Figures').'</b><br />'.
2250: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
2251: 'disableexampointprint'
2252: => '<b>'.&mt('Disable automatically printing point values onto exams.').'</b><br />'.
2253: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
2254: 'externalsyllabus'
2255: => '<b>'.&mt('URL of Syllabus (not using internal handler)').'</b>',
2256: 'tthoptions'
2257: => '<b>'.&mt('Default set of options to pass to tth/m when converting tex').'</b>',
2258:
2259: 'texengine'
2260: => '<b>'.&mt('Force all students in the course to use a specific math rendering engine.').'</b><br />'.&mt('(Valid options are [_1].)','"tth", "jsMath", "mimetex"').'</b>',
2261: );
2262: my @Display_Order = ('url','description','courseid','cloners','grading',
2263: 'externalsyllabus',
2264: 'default_xml_style','pageseparators',
2265: 'question.email','question.email.text','comment.email','comment.email.text','policy.email','policy.email.text',
2266: 'student_classlist_view',
2267: 'student_classlist_opt_in',
2268: 'student_classlist_portfiles',
2269: 'plc.roles.denied','plc.users.denied',
2270: 'pch.roles.denied','pch.users.denied',
2271: 'allow_limited_html_in_feedback',
2272: 'allow_discussion_post_editing',
2273: 'languages',
2274: 'nothideprivileged',
2275: 'rndseed',
2276: 'receiptalg',
2277: 'problem_stream_switch',
2278: 'suppress_tries',
2279: 'default_paper_size',
2280: 'print_header_format',
2281: 'disable_receipt_display',
2282: 'spreadsheet_default_classcalc',
2283: 'spreadsheet_default_studentcalc',
2284: 'spreadsheet_default_assesscalc',
2285: 'hideemptyrows',
2286: 'default_enrollment_start_date',
2287: 'default_enrollment_end_date',
2288: 'tthoptions',
2289: 'texengine',
2290: 'disablesigfigs',
2291: 'disableexampointprint',
2292: 'task_messages'
2293: );
2294: foreach my $parameter (sort(keys(%values))) {
2295: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./)) {
2296: if (! $descriptions{$parameter}) {
2297: $descriptions{$parameter}=$parameter;
2298: push(@Display_Order,$parameter);
2299: }
2300: }
2301: }
2302:
2303: foreach my $parameter (@Display_Order) {
2304: my $description = $descriptions{$parameter};
2305: # onchange is javascript to automatically check the 'Set' button.
2306: my $onchange = 'onFocus="javascript:window.document.forms'.
2307: "['envform'].elements['".$parameter."_setparmval']".
2308: '.checked=true;"';
2309: $output .= &Apache::loncommon::start_data_table_row().
2310: '<td>'.$description.'</td>';
2311: if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
2312: $output .= '<td>'.
2313: &Apache::lonhtmlcommon::date_setter('envform',
2314: $parameter.'_value',
2315: $values{$parameter},
2316: $onchange).
2317: '</td>';
2318: } else {
2319: $output .= '<td>'.
2320: &Apache::lonhtmlcommon::textbox($parameter.'_value',
2321: $values{$parameter},
2322: 40,$onchange).'</td>';
2323: }
2324: $output .= '<td>'.
2325: &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
2326: '</td>';
2327: $output .= &Apache::loncommon::end_data_table_row()."\n";
2328: }
2329: my $onchange = 'onFocus="javascript:window.document.forms'.
2330: '[\'envform\'].elements[\'newp_setparmval\']'.
2331: '.checked=true;"';
2332: $output.=&Apache::loncommon::start_data_table_row().
2333: '<td><i>'.&mt('Create New Environment Variable').'</i><br />'.
2334: '<input type="text" size=40 name="newp_name" '.
2335: $onchange.' /></td><td>'.
2336: '<input type="text" size=40 name="newp_value" '.
2337: $onchange.' /></td><td>'.
2338: '<input type="checkbox" name="newp_setparmval" /></td>'.
2339: &Apache::loncommon::end_data_table_row()."\n";
2340: }
2341: my %lt=&Apache::lonlocal::texthash(
2342: 'par' => 'Parameter',
2343: 'val' => 'Value',
2344: 'set' => 'Set',
2345: 'sce' => 'Set Course Environment'
2346: );
2347:
2348: my $Parameter=&mt('Parameter');
2349: my $Value=&mt('Value');
2350: my $Set=&mt('Set');
2351: my $browse_js=
2352: '<script type="text/javascript" language="Javascript">'.
2353: &Apache::loncommon::browser_and_searcher_javascript('parmset').
2354: '</script>';
2355:
2356: my $start_page =
2357: &Apache::loncommon::start_page('Set Course Environment',
2358: $browse_js);
2359: my $end_page =
2360: &Apache::loncommon::end_page();
2361: my $end_table=&Apache::loncommon::end_data_table();
2362: $r->print(<<ENDENV);
2363: $start_page
2364: $breadcrumbs
2365: <form method="post" action="/adm/parmset?action=crsenv" name="envform">
2366: $setoutput
2367: $start_table
2368: $start_header_row
2369: <th>$lt{'par'}</th><th>$lt{'val'}</th><th>$lt{'set'}?</th>
2370: $end_header_row
2371: $output
2372: $end_table
2373: <input type="submit" name="crsenv" value="$lt{'sce'}" />
2374: </form>
2375: $end_page
2376: ENDENV
2377: }
2378: ##################################################
2379: # Overview mode
2380: ##################################################
2381: my $tableopen;
2382:
2383: sub tablestart {
2384: if ($tableopen) {
2385: return '';
2386: } else {
2387: $tableopen=1;
2388: return &Apache::loncommon::start_data_table().'<tr><th>'.&mt('Parameter').'</th><th>'.
2389: &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
2390: }
2391: }
2392:
2393: sub tableend {
2394: if ($tableopen) {
2395: $tableopen=0;
2396: return &Apache::loncommon::end_data_table();
2397: } else {
2398: return'';
2399: }
2400: }
2401:
2402: sub readdata {
2403: my ($crs,$dom)=@_;
2404: # Read coursedata
2405: my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
2406: # Read userdata
2407:
2408: my $classlist=&Apache::loncoursedata::get_classlist();
2409: foreach (keys %$classlist) {
2410: if ($_=~/^($match_username)\:($match_domain)$/) {
2411: my ($tuname,$tudom)=($1,$2);
2412: my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
2413: foreach my $userkey (keys %{$useropt}) {
2414: if ($userkey=~/^$env{'request.course.id'}/) {
2415: my $newkey=$userkey;
2416: $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
2417: $$resourcedata{$newkey}=$$useropt{$userkey};
2418: }
2419: }
2420: }
2421: }
2422: return $resourcedata;
2423: }
2424:
2425:
2426: # Setting
2427:
2428: sub storedata {
2429: my ($r,$crs,$dom)=@_;
2430: # Set userlevel immediately
2431: # Do an intermediate store of course level
2432: my $olddata=&readdata($crs,$dom);
2433: my %newdata=();
2434: undef %newdata;
2435: my @deldata=();
2436: undef @deldata;
2437: foreach (keys %env) {
2438: if ($_=~/^form\.([a-z]+)\_(.+)$/) {
2439: my $cmd=$1;
2440: my $thiskey=$2;
2441: my ($tuname,$tudom)=&extractuser($thiskey);
2442: my $tkey=$thiskey;
2443: if ($tuname) {
2444: $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
2445: }
2446: if ($cmd eq 'set') {
2447: my $data=$env{$_};
2448: my $typeof=$env{'form.typeof_'.$thiskey};
2449: if ($$olddata{$thiskey} ne $data) {
2450: if ($tuname) {
2451: if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
2452: $tkey.'.type' => $typeof},
2453: $tudom,$tuname) eq 'ok') {
2454: &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
2455: $r->print('<br />'.&mt('Saved modified parameter for').' '.
2456: &Apache::loncommon::plainname($tuname,$tudom));
2457: } else {
2458: $r->print('<div class="LC_error">'.
2459: &mt('Error saving parameters').'</div>');
2460: }
2461: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2462: } else {
2463: $newdata{$thiskey}=$data;
2464: $newdata{$thiskey.'.type'}=$typeof;
2465: }
2466: }
2467: } elsif ($cmd eq 'del') {
2468: if ($tuname) {
2469: if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
2470: &log_parmset({$tkey=>''},1,$tuname,$tudom);
2471: $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
2472: } else {
2473: $r->print('<div class="LC_error">'.
2474: &mt('Error deleting parameters').'</div>');
2475: }
2476: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2477: } else {
2478: push (@deldata,$thiskey,$thiskey.'.type');
2479: }
2480: } elsif ($cmd eq 'datepointer') {
2481: my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
2482: my $typeof=$env{'form.typeof_'.$thiskey};
2483: if (defined($data) and $$olddata{$thiskey} ne $data) {
2484: if ($tuname) {
2485: if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
2486: $tkey.'.type' => $typeof},
2487: $tudom,$tuname) eq 'ok') {
2488: &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
2489: $r->print('<br />'.&mt('Saved modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
2490: } else {
2491: $r->print('<div class="LC_error">'.
2492: &mt('Error saving parameters').'</div>');
2493: }
2494: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2495: } else {
2496: $newdata{$thiskey}=$data;
2497: $newdata{$thiskey.'.type'}=$typeof;
2498: }
2499: }
2500: }
2501: }
2502: }
2503: # Store all course level
2504: my $delentries=$#deldata+1;
2505: my @newdatakeys=keys %newdata;
2506: my $putentries=$#newdatakeys+1;
2507: if ($delentries) {
2508: if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
2509: my %loghash=map { $_ => '' } @deldata;
2510: &log_parmset(\%loghash,1);
2511: $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
2512: } else {
2513: $r->print('<div class="LC_error">'.
2514: &mt('Error deleting parameters').'</div>');
2515: }
2516: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
2517: }
2518: if ($putentries) {
2519: if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
2520: &log_parmset(\%newdata,0);
2521: $r->print('<h3>'.&mt('Saved [_1] parameter(s)',$putentries/2).'</h3>');
2522: } else {
2523: $r->print('<div class="LC_error">'.
2524: &mt('Error saving parameters').'</div>');
2525: }
2526: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
2527: }
2528: }
2529:
2530: sub extractuser {
2531: my $key=shift;
2532: return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./);
2533: }
2534:
2535: sub listdata {
2536: my ($r,$resourcedata,$listdata,$sortorder)=@_;
2537: # Start list output
2538:
2539: my $oldsection='';
2540: my $oldrealm='';
2541: my $oldpart='';
2542: my $pointer=0;
2543: $tableopen=0;
2544: my $foundkeys=0;
2545: my %keyorder=&standardkeyorder();
2546: foreach my $thiskey (sort {
2547: if ($sortorder eq 'realmstudent') {
2548: my ($astudent,$arealm)=($a=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/);
2549: my ($bstudent,$brealm)=($b=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)\.[^\.]+$/);
2550: if (!defined($astudent)) {
2551: ($arealm)=($a=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
2552: }
2553: if (!defined($bstudent)) {
2554: ($brealm)=($b=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
2555: }
2556: $arealm=~s/\.type//;
2557: my ($ares, $aparm) = ($arealm=~/^(.*)\.(.*)$/);
2558: $aparm=$keyorder{'parameter_0_'.$aparm};
2559: $brealm=~s/\.type//;
2560: my ($bres, $bparm) = ($brealm=~/^(.*)\.(.*)$/);
2561: $bparm=$keyorder{'parameter_0_'.$bparm};
2562: if ($ares eq $bres) {
2563: if (defined($aparm) && defined($bparm)) {
2564: ($aparm <=> $bparm);
2565: } elsif (defined($aparm)) {
2566: -1;
2567: } elsif (defined($bparm)) {
2568: 1;
2569: } else {
2570: ($arealm cmp $brealm) || ($astudent cmp $bstudent);
2571: }
2572: } else {
2573: ($arealm cmp $brealm) || ($astudent cmp $bstudent);
2574: }
2575: } else {
2576: $a cmp $b;
2577: }
2578: } keys %{$listdata}) {
2579:
2580: if ($$listdata{$thiskey.'.type'}) {
2581: my $thistype=$$listdata{$thiskey.'.type'};
2582: if ($$resourcedata{$thiskey.'.type'}) {
2583: $thistype=$$resourcedata{$thiskey.'.type'};
2584: }
2585: my ($middle,$part,$name)=
2586: ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
2587: my $section=&mt('All Students');
2588: if ($middle=~/^\[(.*)\]/) {
2589: my $issection=$1;
2590: if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
2591: $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
2592: } else {
2593: $section=&mt('Group/Section').': '.$issection;
2594: }
2595: $middle=~s/^\[(.*)\]//;
2596: }
2597: $middle=~s/\.+$//;
2598: $middle=~s/^\.+//;
2599: my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
2600: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
2601: $realm='<span class="LC_parm_scope_folder">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><span class="LC_parm_folder">('.$1.')</span></span>';
2602: } elsif ($middle) {
2603: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
2604: $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><span class="LC_parm_symb">('.$url.' in '.$map.' id: '.$id.')</span></span>';
2605: }
2606: if ($sortorder eq 'realmstudent') {
2607: if ($realm ne $oldrealm) {
2608: $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
2609: $oldrealm=$realm;
2610: $oldsection='';
2611: }
2612: if ($section ne $oldsection) {
2613: $r->print(&tableend()."\n<h2>$section</h2>");
2614: $oldsection=$section;
2615: $oldpart='';
2616: }
2617: } else {
2618: if ($section ne $oldsection) {
2619: $r->print(&tableend()."\n<hr /><h1>$section</h1>");
2620: $oldsection=$section;
2621: $oldrealm='';
2622: }
2623: if ($realm ne $oldrealm) {
2624: $r->print(&tableend()."\n<h2>$realm</h2>");
2625: $oldrealm=$realm;
2626: $oldpart='';
2627: }
2628: }
2629: if ($part ne $oldpart) {
2630: $r->print(&tableend().
2631: "\n<span class=\"LC_parm_part\">".&mt('Part').": $part</span>");
2632: $oldpart=$part;
2633: }
2634: #
2635: # Ready to print
2636: #
2637: $r->print(&tablestart().
2638: &Apache::loncommon::start_data_table_row().
2639: '<td><b>'.&standard_parameter_names($name).
2640: '</b></td><td><input type="checkbox" name="del_'.
2641: $thiskey.'" /></td><td>');
2642: $foundkeys++;
2643: if (&isdateparm($thistype)) {
2644: my $jskey='key_'.$pointer;
2645: $pointer++;
2646: $r->print(
2647: &Apache::lonhtmlcommon::date_setter('parmform',
2648: $jskey,
2649: $$resourcedata{$thiskey},
2650: '',1,'','').
2651: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'.
2652: &date_sanity_info($$resourcedata{$thiskey})
2653: );
2654: } elsif ($thistype eq 'string_yesno') {
2655: my $showval;
2656: if (defined($$resourcedata{$thiskey})) {
2657: $showval=$$resourcedata{$thiskey};
2658: }
2659: $r->print('<label><input type="radio" name="set_'.$thiskey.
2660: '" value="yes"');
2661: if ($showval eq 'yes') {
2662: $r->print(' checked="checked"');
2663: }
2664: $r->print(' />'.&mt('Yes').'</label> ');
2665: $r->print('<label><input type="radio" name="set_'.$thiskey.
2666: '" value="no"');
2667: if ($showval eq 'no') {
2668: $r->print(' checked="checked"');
2669: }
2670: $r->print(' />'.&mt('No').'</label>');
2671: } else {
2672: my $showval;
2673: if (defined($$resourcedata{$thiskey})) {
2674: $showval=$$resourcedata{$thiskey};
2675: }
2676: $r->print('<input type="text" name="set_'.$thiskey.'" value="'.
2677: $showval.'">');
2678: }
2679: $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
2680: $thistype.'">');
2681: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
2682: }
2683: }
2684: return $foundkeys;
2685: }
2686:
2687: sub newoverview {
2688: my ($r) = @_;
2689:
2690: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2691: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2692: my $start_page = &Apache::loncommon::start_page('Set Parameters');
2693: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
2694: $r->print(<<ENDOVER);
2695: $start_page
2696: $breadcrumbs
2697: <form method="post" action="/adm/parmset?action=newoverview" name="parmform">
2698: ENDOVER
2699: my @ids=();
2700: my %typep=();
2701: my %keyp=();
2702: my %allparms=();
2703: my %allparts=();
2704: my %allmaps=();
2705: my %mapp=();
2706: my %symbp=();
2707: my %maptitles=();
2708: my %uris=();
2709: my %keyorder=&standardkeyorder();
2710: my %defkeytype=();
2711:
2712: my %alllevs=();
2713: $alllevs{'Resource Level'}='full';
2714: $alllevs{'Map/Folder Level'}='map';
2715: $alllevs{'Course Level'}='general';
2716:
2717: my $csec=$env{'form.csec'};
2718: my $cgroup=$env{'form.cgroup'};
2719:
2720: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
2721: my $pschp=$env{'form.pschp'};
2722: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
2723: if (!@psprt) { $psprt[0]='0'; }
2724:
2725: my @selected_sections =
2726: &Apache::loncommon::get_env_multiple('form.Section');
2727: @selected_sections = ('all') if (! @selected_sections);
2728: foreach (@selected_sections) {
2729: if ($_ eq 'all') {
2730: @selected_sections = ('all');
2731: }
2732: }
2733: my @selected_groups =
2734: &Apache::loncommon::get_env_multiple('form.Group');
2735:
2736: my $pssymb='';
2737: my $parmlev='';
2738:
2739: unless ($env{'form.parmlev'}) {
2740: $parmlev = 'map';
2741: } else {
2742: $parmlev = $env{'form.parmlev'};
2743: }
2744:
2745: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
2746: \%mapp, \%symbp,\%maptitles,\%uris,
2747: \%keyorder,\%defkeytype);
2748:
2749: # Menu to select levels, etc
2750:
2751: $r->print('<table id="LC_parm_overview_scope">
2752: <tr><td class="LC_parm_overview_level_menu">');
2753: &levelmenu($r,\%alllevs,$parmlev);
2754: if ($parmlev ne 'general') {
2755: $r->print('<td class="LC_parm_overview_map_menu">');
2756: &mapmenu($r,\%allmaps,$pschp,\%maptitles);
2757: $r->print('</td>');
2758: }
2759: $r->print('</td></tr></table>');
2760:
2761: $r->print('<table id="LC_parm_overview_controls">
2762: <tr><td class="LC_parm_overview_parm_selectors">');
2763: &parmmenu($r,\%allparms,\@pscat,\%keyorder);
2764: $r->print('</td><td class="LC_parm_overview_restrictions">
2765: <table class="LC_parm_overview_restrictions">'.
2766: '<tr><th>'.&mt('Parts').'</th><th>'.&mt('Section(s)').
2767: '</th><th>'.&mt('Group(s)').'</th></tr><tr><td>');
2768: &partmenu($r,\%allparts,\@psprt);
2769: $r->print('</td><td>');
2770: §ionmenu($r,\@selected_sections);
2771: $r->print('</td><td>');
2772: &groupmenu($r,\@selected_groups);
2773: $r->print('</td></tr></table>');
2774: $r->print('</td></tr></table>');
2775:
2776: my $sortorder=$env{'form.sortorder'};
2777: unless ($sortorder) { $sortorder='realmstudent'; }
2778: &sortmenu($r,$sortorder);
2779:
2780: $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
2781:
2782: # Build the list data hash from the specified parms
2783:
2784: my $listdata;
2785: %{$listdata}=();
2786:
2787: foreach my $cat (@pscat) {
2788: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_sections,\%defkeytype,\%allmaps,\@ids,\%symbp);
2789: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_groups,\%defkeytype,\%allmaps,\@ids,\%symbp);
2790: }
2791:
2792: if (($env{'form.store'}) || ($env{'form.dis'})) {
2793:
2794: if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
2795:
2796: # Read modified data
2797:
2798: my $resourcedata=&readdata($crs,$dom);
2799:
2800: # List data
2801:
2802: &listdata($r,$resourcedata,$listdata,$sortorder);
2803: }
2804: $r->print(&tableend().
2805: ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Save').'" /></p>':'').
2806: '</form>'.&Apache::loncommon::end_page());
2807: }
2808:
2809: sub secgroup_lister {
2810: my ($cat,$pschp,$parmlev,$listdata,$psprt,$selections,$defkeytype,$allmaps,$ids,$symbp) = @_;
2811: foreach my $item (@{$selections}) {
2812: foreach my $part (@{$psprt}) {
2813: my $rootparmkey=$env{'request.course.id'};
2814: if (($item ne 'all') && ($item ne 'none') && ($item)) {
2815: $rootparmkey.='.['.$item.']';
2816: }
2817: if ($parmlev eq 'general') {
2818: # course-level parameter
2819: my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
2820: $$listdata{$newparmkey}=1;
2821: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
2822: } elsif ($parmlev eq 'map') {
2823: # map-level parameter
2824: foreach my $mapid (keys %{$allmaps}) {
2825: if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
2826: my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
2827: $$listdata{$newparmkey}=1;
2828: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
2829: }
2830: } else {
2831: # resource-level parameter
2832: foreach my $rid (@{$ids}) {
2833: my ($map,$resid,$url)=&Apache::lonnet::decode_symb($$symbp{$rid});
2834: if (($pschp ne 'all') && ($$allmaps{$pschp} ne $map)) { next; }
2835: my $newparmkey=$rootparmkey.'.'.$$symbp{$rid}.'.'.$part.'.'.$cat;
2836: $$listdata{$newparmkey}=1;
2837: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
2838: }
2839: }
2840: }
2841: }
2842: }
2843:
2844: sub overview {
2845: my ($r) = @_;
2846: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2847: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2848:
2849: my $start_page=&Apache::loncommon::start_page('Modify Parameters');
2850: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
2851: $r->print(<<ENDOVER);
2852: $start_page
2853: $breadcrumbs
2854: <form method="post" action="/adm/parmset?action=setoverview" name="parmform">
2855: ENDOVER
2856: # Store modified
2857:
2858: &storedata($r,$crs,$dom);
2859:
2860: # Read modified data
2861:
2862: my $resourcedata=&readdata($crs,$dom);
2863:
2864:
2865: my $sortorder=$env{'form.sortorder'};
2866: unless ($sortorder) { $sortorder='realmstudent'; }
2867: &sortmenu($r,$sortorder);
2868:
2869: # List data
2870:
2871: my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder);
2872:
2873: $r->print(&tableend().'<p>'.
2874: ($foundkeys?'<input type="submit" value="'.&mt('Modify Parameters').'" />':&mt('There are no parameters.')).'</p></form>'.
2875: &Apache::loncommon::end_page());
2876: }
2877:
2878: sub clean_parameters {
2879: my ($r) = @_;
2880: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2881: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2882:
2883: my $start_page=&Apache::loncommon::start_page('Clean Parameters');
2884: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Clean');
2885: $r->print(<<ENDOVER);
2886: $start_page
2887: $breadcrumbs
2888: <form method="post" action="/adm/parmset?action=cleanparameters" name="parmform">
2889: ENDOVER
2890: # Store modified
2891:
2892: &storedata($r,$crs,$dom);
2893:
2894: # Read modified data
2895:
2896: my $resourcedata=&readdata($crs,$dom);
2897:
2898: # List data
2899:
2900: $r->print('<h3>'.
2901: &mt('These parameters refer to resources that do not exist.').
2902: '</h3>'.
2903: '<input type="submit" value="'.&mt('Delete Checked Parameters').'" />'.'<br />'.
2904: '<br />');
2905: $r->print(&Apache::loncommon::start_data_table().
2906: '<tr>'.
2907: '<th>'.&mt('Delete').'</th>'.
2908: '<th>'.&mt('Parameter').'</th>'.
2909: '</tr>');
2910: foreach my $thiskey (sort(keys(%{$resourcedata}))) {
2911: next if (!exists($resourcedata->{$thiskey.'.type'})
2912: && $thiskey=~/\.type$/);
2913: my %data = &parse_key($thiskey);
2914: if (exists($data{'realm_exists'})
2915: && !$data{'realm_exists'}) {
2916: $r->print(&Apache::loncommon::start_data_table_row().
2917: '<tr>'.
2918: '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>' );
2919:
2920: $r->print('<td>');
2921: my $display_value = $resourcedata->{$thiskey};
2922: if (&isdateparm($resourcedata->{$thiskey.'.type'})) {
2923: $display_value =
2924: &Apache::lonlocal::locallocaltime($display_value);
2925: }
2926: $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
2927: &standard_parameter_names($data{'parameter_name'}),
2928: $resourcedata->{$thiskey}));
2929: $r->print('<br />');
2930: if ($data{'scope_type'} eq 'all') {
2931: $r->print(&mt('All users'));
2932: } elsif ($data{'scope_type'} eq 'user') {
2933: $r->print(&mt('User: [_1]',join(':',@{$data{'scope'}})));
2934: } elsif ($data{'scope_type'} eq 'section') {
2935: $r->print(&mt('Section: [_1]',$data{'scope'}));
2936: } elsif ($data{'scope_type'} eq 'group') {
2937: $r->print(&mt('Group: [_1]',$data{'scope'}));
2938: }
2939: $r->print('<br />');
2940: if ($data{'realm_type'} eq 'all') {
2941: $r->print(&mt('All Resources'));
2942: } elsif ($data{'realm_type'} eq 'folder') {
2943: $r->print(&mt('Folder: [_1]'),$data{'realm'});
2944: } elsif ($data{'realm_type'} eq 'symb') {
2945: my ($map,$resid,$url) =
2946: &Apache::lonnet::decode_symb($data{'realm'});
2947: $r->print(&mt('Resource: [_1] <br /> with ID: [_2] <br /> in folder [_3]',
2948: $url,$resid,$map));
2949: }
2950: $r->print(' <br /> '.&mt('Part: [_1]',$data{'parameter_part'}));
2951: $r->print('</td></tr>');
2952:
2953: }
2954: }
2955: $r->print(&Apache::loncommon::end_data_table().'<p>'.
2956: '<input type="submit" value="'.&mt('Delete Checked Parameters').'" />'.
2957: '</p></form>'.
2958: &Apache::loncommon::end_page());
2959: }
2960:
2961: sub parse_key {
2962: my ($key) = @_;
2963: my %data;
2964: my ($middle,$part,$name)=
2965: ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
2966: $data{'scope_type'} = 'all';
2967: if ($middle=~/^\[(.*)\]/) {
2968: $data{'scope'} = $1;
2969: if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) {
2970: $data{'scope_type'} = 'user';
2971: $data{'scope'} = [$1,$2];
2972: } else {
2973: #FIXME check for group scope
2974: $data{'scope_type'} = 'section';
2975: }
2976: $middle=~s/^\[(.*)\]//;
2977: }
2978: $middle=~s/\.+$//;
2979: $middle=~s/^\.+//;
2980: $data{'realm_type'}='all';
2981: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
2982: $data{'realm'} = $1;
2983: $data{'realm_type'} = 'folder';
2984: $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
2985: ($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
2986: &Apache::lonnet::logthis($1." siad ". $data{'realm_exists'} );
2987: } elsif ($middle) {
2988: $data{'realm'} = $middle;
2989: $data{'realm_type'} = 'symb';
2990: $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
2991: my ($map,$resid,$url) = &Apache::lonnet::decode_symb($data{'realm'});
2992: $data{'realm_exists'} = &Apache::lonnet::symbverify($data{'realm'},$url);
2993: }
2994:
2995: $data{'parameter_part'} = $part;
2996: $data{'parameter_name'} = $name;
2997:
2998: return %data;
2999: }
3000:
3001: ##################################################
3002: ##################################################
3003:
3004: =pod
3005:
3006: =item check_cloners
3007:
3008: Checks if new users included in list of allowed cloners
3009: are valid users. Replaces supplied list with
3010: cleaned list containing only users with valid usernames
3011: and domains.
3012:
3013: Inputs: $clonelist, $oldcloner
3014: where $clonelist is ref to array of requested cloners,
3015: and $oldcloner is ref to array of currently allowed
3016: cloners.
3017:
3018: Returns: string - comma separated list of requested
3019: cloners (username:domain) who do not exist in system.
3020:
3021: =item change_clone
3022:
3023: Modifies the list of courses a user can clone (stored
3024: in the user's environment.db file), called when a
3025: change is made to the list of users allowed to clone
3026: a course.
3027:
3028: Inputs: $action,$cloner
3029: where $action is add or drop, and $cloner is identity of
3030: user for whom cloning ability is to be changed in course.
3031:
3032: =cut
3033:
3034: ##################################################
3035: ##################################################
3036:
3037: sub extract_cloners {
3038: my ($clonelist,$allowclone) = @_;
3039: if ($clonelist =~ /,/) {
3040: @{$allowclone} = split/,/,$clonelist;
3041: } else {
3042: $$allowclone[0] = $clonelist;
3043: }
3044: }
3045:
3046:
3047: sub check_cloners {
3048: my ($clonelist,$oldcloner) = @_;
3049: my ($clean_clonelist,$disallowed);
3050: my @allowclone = ();
3051: &extract_cloners($$clonelist,\@allowclone);
3052: foreach my $currclone (@allowclone) {
3053: if (!grep/^$currclone$/,@$oldcloner) {
3054: my ($uname,$udom) = split/:/,$currclone;
3055: if ($uname && $udom) {
3056: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
3057: $disallowed .= $currclone.',';
3058: } else {
3059: $clean_clonelist .= $currclone.',';
3060: }
3061: }
3062: } else {
3063: $clean_clonelist .= $currclone.',';
3064: }
3065: }
3066: if ($disallowed) {
3067: $disallowed =~ s/,$//;
3068: }
3069: if ($clean_clonelist) {
3070: $clean_clonelist =~ s/,$//;
3071: }
3072: $$clonelist = $clean_clonelist;
3073: return $disallowed;
3074: }
3075:
3076: sub change_clone {
3077: my ($clonelist,$oldcloner) = @_;
3078: my ($uname,$udom);
3079: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3080: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3081: my $clone_crs = $cnum.':'.$cdom;
3082:
3083: if ($cnum && $cdom) {
3084: my @allowclone;
3085: &extract_cloners($clonelist,\@allowclone);
3086: foreach my $currclone (@allowclone) {
3087: if (!grep/^$currclone$/,@$oldcloner) {
3088: ($uname,$udom) = split/:/,$currclone;
3089: if ($uname && $udom) {
3090: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
3091: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
3092: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
3093: if ($currclonecrs{'cloneable'} eq '') {
3094: $currclonecrs{'cloneable'} = $clone_crs;
3095: } else {
3096: $currclonecrs{'cloneable'} .= ','.$clone_crs;
3097: }
3098: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
3099: }
3100: }
3101: }
3102: }
3103: }
3104: foreach my $oldclone (@$oldcloner) {
3105: if (!grep/^$oldclone$/,@allowclone) {
3106: ($uname,$udom) = split/:/,$oldclone;
3107: if ($uname && $udom) {
3108: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
3109: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
3110: my %newclonecrs = ();
3111: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
3112: if ($currclonecrs{'cloneable'} =~ /,/) {
3113: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
3114: foreach (@currclonecrs) {
3115: unless ($_ eq $clone_crs) {
3116: $newclonecrs{'cloneable'} .= $_.',';
3117: }
3118: }
3119: $newclonecrs{'cloneable'} =~ s/,$//;
3120: } else {
3121: $newclonecrs{'cloneable'} = '';
3122: }
3123: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
3124: }
3125: }
3126: }
3127: }
3128: }
3129: }
3130: }
3131:
3132:
3133: ##################################################
3134: ##################################################
3135:
3136: =pod
3137:
3138: =item * header
3139:
3140: Output html header for page
3141:
3142: =cut
3143:
3144: ##################################################
3145: ##################################################
3146: sub header {
3147: return &Apache::loncommon::start_page('Parameter Manager');
3148: }
3149: ##################################################
3150: ##################################################
3151: sub print_main_menu {
3152: my ($r,$parm_permission)=@_;
3153: #
3154: $r->print(<<ENDMAINFORMHEAD);
3155: <form method="post" enctype="multipart/form-data"
3156: action="/adm/parmset" name="studentform">
3157: ENDMAINFORMHEAD
3158: #
3159: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3160: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3161: my $vgr = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
3162: my $mgr = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
3163:
3164: my @menu =
3165: ( { divider=>'Settings for Your Course',
3166: },
3167: { text => 'Set Course Environment',
3168: action => 'crsenv',
3169: permission => $parm_permission,
3170: help => 'Course_Environment',
3171: },
3172: { text => 'Set Portfolio Metadata',
3173: action => 'setrestrictmeta',
3174: permission => $parm_permission,
3175: },
3176: { text => 'Manage Course Slots',
3177: url => '/adm/slotrequest?command=showslots',
3178: permission => $vgr,
3179: },
3180: { text => 'Reset Student Access Times',
3181: url => '/adm/helper/resettimes.helper',
3182: permission => $mgr,
3183: },
3184:
3185: { text => 'Set Parameter Setting Default Actions',
3186: action => 'setdefaults',
3187: permission => $parm_permission,
3188: },
3189: { divider => 'New and Existing Parameter Settings for Your Resources',
3190: },
3191: { text => 'Set/Modify Resource Parameters - Helper Mode',
3192: url => '/adm/helper/parameter.helper',
3193: permission => $parm_permission,
3194: help => 'Parameter_Helper',
3195: },
3196: { text => 'Set/Modify Resource Parameters - Overview Mode',
3197: action => 'newoverview',
3198: permission => $parm_permission,
3199: help => 'Parameter_Overview',
3200: },
3201: { text => 'Set/Modify Resource Parameters - Table Mode',
3202: action => 'settable',
3203: permission => $parm_permission,
3204: help => 'Table_Mode',
3205: },
3206: { divider => 'Existing Parameter Settings for Your Resources',
3207: },
3208: { text => 'Modify Resource Parameters - Overview Mode',
3209: action => 'setoverview',
3210: permission => $parm_permission,
3211: help => 'Parameter_Overview',
3212: },
3213: { text => 'Parameter Change Log and Course Blog Posting/User Notification',
3214: action => 'parameterchangelog',
3215: permission => $parm_permission,
3216: },
3217: );
3218: my $menu_html = '';
3219: foreach my $menu_item (@menu) {
3220: if ($menu_item->{'divider'}) {
3221: $menu_html .= '<h3>'.&mt($menu_item->{'divider'}).'</h3>';
3222: next;
3223: }
3224: next if (! $menu_item->{'permission'});
3225: $menu_html.='<p>';
3226: $menu_html.='<span class="LC_parm_menu_item">';
3227: if (exists($menu_item->{'url'})) {
3228: $menu_html.=qq{<a href="$menu_item->{'url'}">};
3229: } else {
3230: $menu_html.=
3231: qq{<a href="/adm/parmset?action=$menu_item->{'action'}">};
3232: }
3233: $menu_html.= &mt($menu_item->{'text'}).'</a></span>';
3234: if (exists($menu_item->{'help'})) {
3235: $menu_html.=
3236: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3237: }
3238: $menu_html.='</p>'.$/;
3239: }
3240: $r->print($menu_html);
3241: return;
3242: }
3243: ### Set portfolio metadata
3244: sub output_row {
3245: my ($r, $field_name, $field_text, $added_flag) = @_;
3246: my $output;
3247: my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
3248: my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
3249: if (!defined($options)) {
3250: $options = 'active,stuadd';
3251: $values = '';
3252: }
3253: if (!($options =~ /deleted/)) {
3254: my @options= ( ['active', 'Show to student'],
3255: ['stuadd', 'Provide text area for students to type catalog information'],
3256: ['choices','Provide choices for students to select from']);
3257: # ['onlyone','Student may select only one choice']);
3258: if ($added_flag) {
3259: push @options,['deleted', 'Delete Metadata Field'];
3260: }
3261: $output = &Apache::loncommon::start_data_table_row();
3262: $output .= '<td><span class="LC_metadata"><strong>'.$field_text.':</strong></span></td>';
3263: $output .= &Apache::loncommon::end_data_table_row();
3264: foreach my $opt (@options) {
3265: my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
3266: $output .= &Apache::loncommon::continue_data_table_row();
3267: $output .= '<td>'.(' ' x 5).'<span class="LC_metadata"><label>
3268: <input type="checkbox" name="'.
3269: $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.
3270: &mt($opt->[1]).'</label></span> </td>';
3271: $output .= &Apache::loncommon::end_data_table_row();
3272: }
3273: $output .= &Apache::loncommon::continue_data_table_row();
3274: $output .= '<td>'.(' ' x 10).'<span class="LC_metadata"><input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /></span></td>';
3275: $output .= &Apache::loncommon::end_data_table_row();
3276: my $multiple_checked;
3277: my $single_checked;
3278: if ($options =~ m/onlyone/) {
3279: $multiple_checked = "";
3280: $single_checked = " CHECKED ";
3281: } else {
3282: $multiple_checked = " CHECKED ";
3283: $single_checked = "";
3284: }
3285: $output .= &Apache::loncommon::continue_data_table_row();
3286: $output .= '<td>'.(' ' x 10).'<span class="LC_metadata">
3287: <input type="radio" name="'.$field_name.'_onlyone" value="multiple" '.$multiple_checked .'/>
3288: Student may select multiple choices from list</span></td>';
3289: $output .= &Apache::loncommon::end_data_table_row();
3290: $output .= &Apache::loncommon::continue_data_table_row();
3291: $output .= '<td>'.(' ' x 10).'<span class="LC_metadata">
3292: <input type="radio" name="'.$field_name.'_onlyone" value="single" '.$single_checked.'/>
3293: Student may select only one choice from list</span></td>';
3294: $output .= &Apache::loncommon::end_data_table_row();
3295: }
3296: return ($output);
3297: }
3298: sub order_meta_fields {
3299: my ($r)=@_;
3300: my $idx = 1;
3301: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3302: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3303: $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));
3304: &Apache::lonhtmlcommon::add_breadcrumb
3305: ({href=>"/adm/parmset?action=setrestrictmeta",
3306: text=>"Restrict Metadata"},
3307: {text=>"Order Metadata"});
3308: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata'));
3309: if ($env{'form.storeorder'}) {
3310: my $newpos = $env{'form.newpos'} - 1;
3311: my $currentpos = $env{'form.currentpos'} - 1;
3312: my @neworder = ();
3313: my @oldorder = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
3314: my $i;
3315: if ($newpos > $currentpos) {
3316: # moving stuff up
3317: for ($i=0;$i<$currentpos;$i++) {
3318: $neworder[$i]=$oldorder[$i];
3319: }
3320: for ($i=$currentpos;$i<$newpos;$i++) {
3321: $neworder[$i]=$oldorder[$i+1];
3322: }
3323: $neworder[$newpos]=$oldorder[$currentpos];
3324: for ($i=$newpos+1;$i<=$#oldorder;$i++) {
3325: $neworder[$i]=$oldorder[$i];
3326: }
3327: } else {
3328: # moving stuff down
3329: for ($i=0;$i<$newpos;$i++) {
3330: $neworder[$i]=$oldorder[$i];
3331: }
3332: $neworder[$newpos]=$oldorder[$currentpos];
3333: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
3334: $neworder[$i]=$oldorder[$i-1];
3335: }
3336: for ($i=$currentpos+1;$i<=$#oldorder;$i++) {
3337: $neworder[$i]=$oldorder[$i];
3338: }
3339: }
3340: my $ordered_fields = join ",", @neworder;
3341: my $put_result = &Apache::lonnet::put('environment',
3342: {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
3343: &Apache::lonnet::appenv('course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields);
3344: }
3345: my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
3346: my $ordered_fields;
3347: my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
3348: if (!@fields_in_order) {
3349: # no order found, pick sorted order then create metadata.addedorder key.
3350: foreach my $key (sort keys %$fields) {
3351: push @fields_in_order, $key;
3352: $ordered_fields = join ",", @fields_in_order;
3353: }
3354: my $put_result = &Apache::lonnet::put('environment',
3355: {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
3356: }
3357: $r->print('<table>');
3358: my $num_fields = scalar(@fields_in_order);
3359: foreach my $key (@fields_in_order) {
3360: $r->print('<tr><td>');
3361: $r->print('<form method="post" action="">');
3362: $r->print('<select name="newpos" onChange="this.form.submit()">');
3363: for (my $i = 1;$i le $num_fields;$i ++) {
3364: if ($i eq $idx) {
3365: $r->print('<option value="'.$i.'" SELECTED>('.$i.')</option>');
3366: } else {
3367: $r->print('<option value="'.$i.'">'.$i.'</option>');
3368: }
3369: }
3370: $r->print('</select></td><td>');
3371: $r->print('<input type="hidden" name="currentpos" value="'.$idx.'" />');
3372: $r->print('<input type="hidden" name="storeorder" value="true" />');
3373: $r->print('</form>');
3374: $r->print($$fields{$key}.'</td></tr>');
3375: $idx ++;
3376: }
3377: $r->print('</table>');
3378: return 'ok';
3379: }
3380: sub continue {
3381: my $output;
3382: $output .= '<form action="" method="post">';
3383: $output .= '<input type="hidden" name="action" value="setrestrictmeta" />';
3384: $output .= '<input type="submit" value="Continue" />';
3385: return ($output);
3386: }
3387: sub addmetafield {
3388: my ($r)=@_;
3389: $r->print(&Apache::loncommon::start_page('Add Metadata Field'));
3390: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
3391: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3392: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3393: if (exists($env{'form.undelete'})) {
3394: my @meta_fields = &Apache::loncommon::get_env_multiple('form.undeletefield');
3395: foreach my $meta_field(@meta_fields) {
3396: my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};
3397: $options =~ s/deleted//;
3398: $options =~ s/,,/,/;
3399: my $put_result = &Apache::lonnet::put('environment',
3400: {'metadata.'.$meta_field.'.options'=>$options},$dom,$crs);
3401:
3402: $r->print('Undeleted Metadata Field <strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}."</strong> with result ".$put_result.'<br />');
3403: }
3404: $r->print(&continue());
3405: } elsif (exists($env{'form.fieldname'})) {
3406: my $meta_field = $env{'form.fieldname'};
3407: my $display_field = $env{'form.fieldname'};
3408: $meta_field =~ s/\W/_/g;
3409: $meta_field =~ tr/A-Z/a-z/;
3410: my $put_result = &Apache::lonnet::put('environment',
3411: {'metadata.'.$meta_field.'.values'=>"",
3412: 'metadata.'.$meta_field.'.added'=>"$display_field",
3413: 'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
3414: $r->print('Added new Metadata Field <strong>'.$env{'form.fieldname'}."</strong> with result ".$put_result.'<br />');
3415: $r->print(&continue());
3416: } else {
3417: my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'});
3418: if ($fields) {
3419: $r->print('You may undelete previously deleted fields.<br />Check those you wish to undelete and click Undelete.<br />');
3420: $r->print('<form method="post" action="">');
3421: foreach my $key(keys(%$fields)) {
3422: $r->print('<input type="checkbox" name="undeletefield" value="'.$key.'" />'.$$fields{$key}.'<br /');
3423: }
3424: $r->print('<input type="submit" name="undelete" value="Undelete" />');
3425: $r->print('</form>');
3426: }
3427: $r->print('<hr /><strong>Or</strong> you may enter a new metadata field name.<form method="post" action="/adm/parmset?action=addmetadata"');
3428: $r->print('<input type="text" name="fieldname" /><br />');
3429: $r->print('<input type="submit" value="Add Metadata Field" />');
3430: }
3431: $r->print('</form>');
3432: }
3433: sub setrestrictmeta {
3434: my ($r)=@_;
3435: my $next_meta;
3436: my $output;
3437: my $item_num;
3438: my $put_result;
3439: $r->print(&Apache::loncommon::start_page('Restrict Metadata'));
3440: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Restrict Metadata'));
3441: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3442: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3443: my $key_base = $env{'course.'.$env{'request.course.id'}.'.'};
3444: my $save_field = '';
3445: if ($env{'form.restrictmeta'}) {
3446: foreach my $field (sort(keys(%env))) {
3447: if ($field=~m/^form.(.+)_(.+)$/) {
3448: my $options;
3449: my $meta_field = $1;
3450: my $meta_key = $2;
3451: if ($save_field ne $meta_field) {
3452: $save_field = $meta_field;
3453: if ($env{'form.'.$meta_field.'_stuadd'}) {
3454: $options.='stuadd,';
3455: }
3456: if ($env{'form.'.$meta_field.'_choices'}) {
3457: $options.='choices,';
3458: }
3459: if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') {
3460: $options.='onlyone,';
3461: }
3462: if ($env{'form.'.$meta_field.'_active'}) {
3463: $options.='active,';
3464: }
3465: if ($env{'form.'.$meta_field.'_deleted'}) {
3466: $options.='deleted,';
3467: }
3468: my $name = $save_field;
3469: $put_result = &Apache::lonnet::put('environment',
3470: {'metadata.'.$meta_field.'.options'=>$options,
3471: 'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
3472: },$dom,$crs);
3473: }
3474: }
3475: }
3476: }
3477: &Apache::lonnet::coursedescription($env{'request.course.id'},
3478: {'freshen_cache' => 1});
3479: # Get the default metadata fields
3480: my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
3481: # Now get possible added metadata fields
3482: my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
3483: my $row_alt = 1;
3484: $output .= &Apache::loncommon::start_data_table();
3485: foreach my $field (sort(keys(%metadata_fields))) {
3486: if ($field ne 'courserestricted') {
3487: $row_alt = $row_alt ? 0 : 1;
3488: $output.= &output_row($r, $field, $metadata_fields{$field});
3489: }
3490: }
3491: my $buttons = (<<ENDButtons);
3492: <input type="submit" name="restrictmeta" value="Save" />
3493: </form><br />
3494: <form method="post" action="/adm/parmset?action=addmetadata" name="form1">
3495: <input type="submit" name="restrictmeta" value="Add a Metadata Field" />
3496: </form>
3497: <br />
3498: <form method="post" action="/adm/parmset?action=ordermetadata" name="form2">
3499: <input type="submit" name="restrictmeta" value="Order Metadata Fields" />
3500: ENDButtons
3501: my $added_flag = 1;
3502: foreach my $field (sort(keys(%$added_metadata_fields))) {
3503: $row_alt = $row_alt ? 0 : 1;
3504: $output.= &output_row($r, $field, $$added_metadata_fields{$field},$added_flag, $row_alt);
3505: }
3506: $output .= &Apache::loncommon::end_data_table();
3507: $r->print(<<ENDenv);
3508: <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
3509: $output
3510: $buttons
3511: </form>
3512: ENDenv
3513: $r->print(&Apache::loncommon::end_page());
3514: return 'ok';
3515: }
3516: ##################################################
3517: sub get_added_meta_fieldnames {
3518: my ($cid) = @_;
3519: my %fields;
3520: foreach my $key(%env) {
3521: if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
3522: my $field_name = $1;
3523: my ($display_field_name) = $env{$key};
3524: $fields{$field_name} = $display_field_name;
3525: }
3526: }
3527: return \%fields;
3528: }
3529: sub get_deleted_meta_fieldnames {
3530: my ($cid) = @_;
3531: my %fields;
3532: foreach my $key(%env) {
3533: if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
3534: my $field_name = $1;
3535: if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
3536: my ($display_field_name) = $env{$key};
3537: $fields{$field_name} = $display_field_name;
3538: }
3539: }
3540: }
3541: return \%fields;
3542: }
3543: sub defaultsetter {
3544: my ($r) = @_;
3545:
3546: my $start_page =
3547: &Apache::loncommon::start_page('Parameter Setting Default Actions');
3548: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Defaults');
3549: $r->print(<<ENDDEFHEAD);
3550: $start_page
3551: $breadcrumbs
3552: <form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">
3553: ENDDEFHEAD
3554:
3555: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3556: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3557: my @ids=();
3558: my %typep=();
3559: my %keyp=();
3560: my %allparms=();
3561: my %allparts=();
3562: my %allmaps=();
3563: my %mapp=();
3564: my %symbp=();
3565: my %maptitles=();
3566: my %uris=();
3567: my %keyorder=&standardkeyorder();
3568: my %defkeytype=();
3569:
3570: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
3571: \%mapp, \%symbp,\%maptitles,\%uris,
3572: \%keyorder,\%defkeytype);
3573: if ($env{'form.storerules'}) {
3574: my %newrules=();
3575: my @delrules=();
3576: my %triggers=();
3577: foreach my $key (keys(%env)) {
3578: if ($key=~/^form\.(\w+)\_action$/) {
3579: my $tempkey=$1;
3580: my $action=$env{$key};
3581: if ($action) {
3582: $newrules{$tempkey.'_action'}=$action;
3583: if ($action ne 'default') {
3584: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
3585: $triggers{$whichparm}.=$tempkey.':';
3586: }
3587: $newrules{$tempkey.'_type'}=$defkeytype{$tempkey};
3588: if (&isdateparm($defkeytype{$tempkey})) {
3589: $newrules{$tempkey.'_days'}=$env{'form.'.$tempkey.'_days'};
3590: $newrules{$tempkey.'_hours'}=$env{'form.'.$tempkey.'_hours'};
3591: $newrules{$tempkey.'_min'}=$env{'form.'.$tempkey.'_min'};
3592: $newrules{$tempkey.'_sec'}=$env{'form.'.$tempkey.'_sec'};
3593: } else {
3594: $newrules{$tempkey.'_value'}=$env{'form.'.$tempkey.'_value'};
3595: $newrules{$tempkey.'_triggervalue'}=$env{'form.'.$tempkey.'_triggervalue'};
3596: }
3597: } else {
3598: push(@delrules,$tempkey.'_action');
3599: push(@delrules,$tempkey.'_type');
3600: push(@delrules,$tempkey.'_hours');
3601: push(@delrules,$tempkey.'_min');
3602: push(@delrules,$tempkey.'_sec');
3603: push(@delrules,$tempkey.'_value');
3604: }
3605: }
3606: }
3607: foreach my $key (keys %allparms) {
3608: $newrules{$key.'_triggers'}=$triggers{$key};
3609: }
3610: &Apache::lonnet::put('parmdefactions',\%newrules,$dom,$crs);
3611: &Apache::lonnet::del('parmdefactions',\@delrules,$dom,$crs);
3612: &resetrulescache();
3613: }
3614: my %lt=&Apache::lonlocal::texthash('days' => 'Days',
3615: 'hours' => 'Hours',
3616: 'min' => 'Minutes',
3617: 'sec' => 'Seconds',
3618: 'yes' => 'Yes',
3619: 'no' => 'No');
3620: my @standardoptions=('','default');
3621: my @standarddisplay=('',&mt('Default value when manually setting'));
3622: my @dateoptions=('','default');
3623: my @datedisplay=('',&mt('Default value when manually setting'));
3624: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
3625: unless ($tempkey) { next; }
3626: push @standardoptions,'when_setting_'.$tempkey;
3627: push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
3628: if (&isdateparm($defkeytype{$tempkey})) {
3629: push @dateoptions,'later_than_'.$tempkey;
3630: push @datedisplay,&mt('Automatically set later than ').$tempkey;
3631: push @dateoptions,'earlier_than_'.$tempkey;
3632: push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
3633: }
3634: }
3635: $r->print(&mt('Manual setting rules apply to all interfaces.').'<br />'.
3636: &mt('Automatic setting rules apply to table mode interfaces only.'));
3637: $r->print("\n".&Apache::loncommon::start_data_table().
3638: &Apache::loncommon::start_data_table_header_row().
3639: "<th>".&mt('Rule for parameter').'</th><th>'.
3640: &mt('Action').'</th><th>'.&mt('Value').'</th>'.
3641: &Apache::loncommon::end_data_table_header_row());
3642: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
3643: unless ($tempkey) { next; }
3644: $r->print("\n".&Apache::loncommon::start_data_table_row().
3645: "<td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
3646: my $action=&rulescache($tempkey.'_action');
3647: $r->print('<select name="'.$tempkey.'_action">');
3648: if (&isdateparm($defkeytype{$tempkey})) {
3649: for (my $i=0;$i<=$#dateoptions;$i++) {
3650: if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
3651: $r->print("\n<option value='$dateoptions[$i]'".
3652: ($dateoptions[$i] eq $action?' selected="selected"':'').
3653: ">$datedisplay[$i]</option>");
3654: }
3655: } else {
3656: for (my $i=0;$i<=$#standardoptions;$i++) {
3657: if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
3658: $r->print("\n<option value='$standardoptions[$i]'".
3659: ($standardoptions[$i] eq $action?' selected="selected"':'').
3660: ">$standarddisplay[$i]</option>");
3661: }
3662: }
3663: $r->print('</select>');
3664: unless (&isdateparm($defkeytype{$tempkey})) {
3665: $r->print("\n<br />".&mt('Triggering value(s) of other parameter (optional, comma-separated):').
3666: '<input type="text" size="20" name="'.$tempkey.'_triggervalue" value="'.&rulescache($tempkey.'_triggervalue').'" />');
3667: }
3668: $r->print("\n</td><td>\n");
3669:
3670: if (&isdateparm($defkeytype{$tempkey})) {
3671: my $days=&rulescache($tempkey.'_days');
3672: my $hours=&rulescache($tempkey.'_hours');
3673: my $min=&rulescache($tempkey.'_min');
3674: my $sec=&rulescache($tempkey.'_sec');
3675: $r->print(<<ENDINPUTDATE);
3676: <input name="$tempkey\_days" type="text" size="4" value="$days" />$lt{'days'}<br />
3677: <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
3678: <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
3679: <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
3680: ENDINPUTDATE
3681: } elsif ($defkeytype{$tempkey} eq 'string_yesno') {
3682: my $yeschecked='';
3683: my $nochecked='';
3684: if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked='checked="checked"'; }
3685: if (&rulescache($tempkey.'_value') eq 'no') { $nochecked='checked="checked"'; }
3686:
3687: $r->print(<<ENDYESNO);
3688: <label><input type="radio" name="$tempkey\_value" value="yes" $yeschecked /> $lt{'yes'}</label><br />
3689: <label><input type="radio" name="$tempkey\_value" value="no" $nochecked /> $lt{'no'}</label>
3690: ENDYESNO
3691: } else {
3692: $r->print('<input type="text" size="20" name="'.$tempkey.'_value" value="'.&rulescache($tempkey.'_value').'" />');
3693: }
3694: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
3695: }
3696: $r->print(&Apache::loncommon::end_data_table().
3697: "\n<input type='submit' name='storerules' value='".
3698: &mt('Save Rules')."' /></form>\n".
3699: &Apache::loncommon::end_page());
3700: return;
3701: }
3702:
3703: sub components {
3704: my ($key,$uname,$udom,$exeuser,$exedomain,$typeflag)=@_;
3705:
3706: if ($typeflag) {
3707: $key=~s/\.type$//;
3708: }
3709:
3710: my ($middle,$part,$name)=
3711: ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
3712: my $issection;
3713:
3714: my $section=&mt('All Students');
3715: if ($middle=~/^\[(.*)\]/) {
3716: $issection=$1;
3717: $section=&mt('Group/Section').': '.$issection;
3718: $middle=~s/^\[(.*)\]//;
3719: }
3720: $middle=~s/\.+$//;
3721: $middle=~s/^\.+//;
3722: if ($uname) {
3723: $section=&mt('User').": ".&Apache::loncommon::plainname($uname,$udom);
3724: $issection='';
3725: }
3726: my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
3727: my $realmdescription=&mt('all resources');
3728: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
3729: $realm='<span class="LC_parm_scope_folder">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <span class="LC_parm_folder"><br />('.$1.')</span></span>';
3730: $realmdescription=&mt('folder').' '.&Apache::lonnet::gettitle($1);
3731: } elsif ($middle) {
3732: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
3733: $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><span class="LC_parm_symb">('.$url.' in '.$map.' id: '.$id.')</span></span>';
3734: $realmdescription=&mt('resource').' '.&Apache::lonnet::gettitle($middle);
3735: }
3736: my $what=$part.'.'.$name;
3737: return ($realm,$section,$name,$part,
3738: $what,$middle,$uname,$udom,$issection,$realmdescription);
3739: }
3740:
3741: my %standard_parms;
3742: sub load_parameter_names {
3743: open(my $config,"<$Apache::lonnet::perlvar{'lonTabDir'}/packages.tab");
3744: while (my $configline=<$config>) {
3745: if ($configline !~ /\S/ || $configline=~/^\#/) { next; }
3746: chomp($configline);
3747: my ($short,$plain)=split(/:/,$configline);
3748: my (undef,$name,$type)=split(/\&/,$short,3);
3749: if ($type eq 'display') {
3750: $standard_parms{$name} = $plain;
3751: }
3752: }
3753: close($config);
3754: $standard_parms{'int_pos'} = 'Positive Integer';
3755: $standard_parms{'int_zero_pos'} = 'Positive Integer or Zero';
3756: %standard_parms=&Apache::lonlocal::texthash(%standard_parms);
3757: }
3758:
3759: sub standard_parameter_names {
3760: my ($name)=@_;
3761: if (!%standard_parms) {
3762: &load_parameter_names();
3763: }
3764: if ($standard_parms{$name}) {
3765: return $standard_parms{$name};
3766: } else {
3767: return $name;
3768: }
3769: }
3770:
3771: #
3772: # Parameter Change Log
3773: #
3774:
3775:
3776: sub parm_change_log {
3777: my ($r)=@_;
3778: $r->print(&Apache::loncommon::start_page('Parameter Change Log'));
3779: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Change Log'));
3780:
3781: my %parmlog=&Apache::lonnet::dump('nohist_parameterlog',
3782: $env{'course.'.$env{'request.course.id'}.'.domain'},
3783: $env{'course.'.$env{'request.course.id'}.'.num'});
3784:
3785: if ((keys(%parmlog))[0]=~/^error\:/) { undef(%parmlog); }
3786:
3787: $r->print('<form action="/adm/parmset?action=parameterchangelog"
3788: method="post" name="parameterlog">');
3789:
3790: my %saveable_parameters = ('show' => 'scalar',);
3791: &Apache::loncommon::store_course_settings('parameter_log',
3792: \%saveable_parameters);
3793: &Apache::loncommon::restore_course_settings('parameter_log',
3794: \%saveable_parameters);
3795: $r->print(&Apache::loncommon::display_filter().
3796: '<label>'.&Apache::lonhtmlcommon::checkbox('includetypes',$env{'form.includetypes'},'1').
3797: ' '.&mt('Include parameter types').'</label>'.
3798: '<input type="submit" value="'.&mt('Display').'" /></form>');
3799:
3800: my $courseopt=&Apache::lonnet::get_courseresdata($env{'course.'.$env{'request.course.id'}.'.num'},
3801: $env{'course.'.$env{'request.course.id'}.'.domain'});
3802: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
3803: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Extent').'</th><th>'.&mt('Users').'</th><th>'.
3804: &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th><th>'.&mt('Announce').'</th>'.
3805: &Apache::loncommon::end_data_table_header_row());
3806: my $shown=0;
3807: my $folder='';
3808: if ($env{'form.displayfilter'} eq 'currentfolder') {
3809: my $last='';
3810: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
3811: &GDBM_READER(),0640)) {
3812: $last=$hash{'last_known'};
3813: untie(%hash);
3814: }
3815: if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
3816: }
3817: foreach my $id (sort
3818: {
3819: if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
3820: return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'}
3821: }
3822: my $aid = (split('00000',$a))[-1];
3823: my $bid = (split('00000',$b))[-1];
3824: return $bid<=>$aid;
3825: } (keys(%parmlog))) {
3826: my @changes=keys(%{$parmlog{$id}{'logentry'}});
3827: my $count = 0;
3828: my $time =
3829: &Apache::lonlocal::locallocaltime($parmlog{$id}{'exe_time'});
3830: my $plainname =
3831: &Apache::loncommon::plainname($parmlog{$id}{'exe_uname'},
3832: $parmlog{$id}{'exe_udom'});
3833: my $about_me_link =
3834: &Apache::loncommon::aboutmewrapper($plainname,
3835: $parmlog{$id}{'exe_uname'},
3836: $parmlog{$id}{'exe_udom'});
3837: my $send_msg_link='';
3838: if ((($parmlog{$id}{'exe_uname'} ne $env{'user.name'})
3839: || ($parmlog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
3840: $send_msg_link ='<br />'.
3841: &Apache::loncommon::messagewrapper(&mt('Send message'),
3842: $parmlog{$id}{'exe_uname'},
3843: $parmlog{$id}{'exe_udom'});
3844: }
3845: my $row_start=&Apache::loncommon::start_data_table_row();
3846: my $makenewrow=0;
3847: my %istype=();
3848: my $output;
3849: foreach my $changed (reverse(sort(@changes))) {
3850: my $value=$parmlog{$id}{'logentry'}{$changed};
3851: my $typeflag = ($changed =~/\.type$/ &&
3852: !exists($parmlog{$id}{'logentry'}{$changed.'.type'}));
3853: my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
3854: &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag);
3855: if ($env{'form.displayfilter'} eq 'currentfolder') {
3856: if ($folder) {
3857: if ($middle!~/^\Q$folder\E/) { next; }
3858: }
3859: }
3860: if ($typeflag) {
3861: $istype{$parmname}=$value;
3862: if (!$env{'form.includetypes'}) { next; }
3863: }
3864: $count++;
3865: if ($makenewrow) {
3866: $output .= $row_start;
3867: } else {
3868: $makenewrow=1;
3869: }
3870: $output .='<td>'.$realm.'</td><td>'.$section.'</td><td>'.
3871: &standard_parameter_names($parmname).'</td><td>'.
3872: ($part?&mt('Part: [_1]',$part):&mt('All Parts')).'</td><td>';
3873: my $stillactive=0;
3874: if ($parmlog{$id}{'delflag'}) {
3875: $output .= &mt('Deleted');
3876: } else {
3877: if ($typeflag) {
3878: $output .= &mt('Type: [_1]',&standard_parameter_names($value));
3879: } else {
3880: my ($level,@all)=&parmval_by_symb($what,$middle,&Apache::lonnet::metadata($middle,$what),
3881: $uname,$udom,$issection,$issection,$courseopt);
3882: if (&isdateparm($istype{$parmname})) {
3883: $output .= &Apache::lonlocal::locallocaltime($value);
3884: } else {
3885: $output .= $value;
3886: }
3887: if ($value ne $all[$level]) {
3888: $output .= '<br /><span class="LC_warning">'.&mt('Not active anymore').'</span>';
3889: } else {
3890: $stillactive=1;
3891: }
3892: }
3893: }
3894: $output .= '</td><td>';
3895: if ($stillactive) {
3896: my $title=&mt('Changed [_1]',&standard_parameter_names($parmname));
3897: my $description=&mt('Changed [_1] for [_2] to [_3]',&standard_parameter_names($parmname),$realmdescription,
3898: (&isdateparm($istype{$parmname})?&Apache::lonlocal::locallocaltime($value):$value));
3899: if (($uname) && ($udom)) {
3900: $output .=
3901: &Apache::loncommon::messagewrapper('Notify User',
3902: $uname,$udom,$title,
3903: $description);
3904: } else {
3905: $output .=
3906: &Apache::lonrss::course_blog_link($id,$title,
3907: $description);
3908: }
3909: }
3910: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
3911: }
3912: if ($env{'form.displayfilter'} eq 'containing') {
3913: my $wholeentry=$about_me_link.':'.
3914: $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'.
3915: $output;
3916: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
3917: }
3918: if ($count) {
3919: $r->print($row_start.'<td rowspan="'.$count.'">'.$time.'</td>
3920: <td rowspan="'.$count.'">'.$about_me_link.
3921: '<br /><tt>'.$parmlog{$id}{'exe_uname'}.
3922: ':'.$parmlog{$id}{'exe_udom'}.'</tt>'.
3923: $send_msg_link.'</td>'.$output);
3924: $shown++;
3925: }
3926: if (!($env{'form.show'} eq &mt('all')
3927: || $shown<=$env{'form.show'})) { last; }
3928: }
3929: $r->print(&Apache::loncommon::end_data_table());
3930: $r->print(&Apache::loncommon::end_page());
3931: }
3932:
3933: sub check_for_course_info {
3934: my $navmap = Apache::lonnavmaps::navmap->new();
3935: return 1 if ($navmap);
3936: return 0;
3937: }
3938:
3939: ##################################################
3940: ##################################################
3941:
3942: =pod
3943:
3944: =item * handler
3945:
3946: Main handler. Calls &assessparms and &crsenv subroutines.
3947:
3948: =cut
3949: ##################################################
3950: ##################################################
3951: # use Data::Dumper;
3952:
3953:
3954: sub handler {
3955: my $r=shift;
3956:
3957: if ($r->header_only) {
3958: &Apache::loncommon::content_type($r,'text/html');
3959: $r->send_http_header;
3960: return OK;
3961: }
3962: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3963: ['action','state',
3964: 'pres_marker',
3965: 'pres_value',
3966: 'pres_type',
3967: 'udom','uname','symb','serial']);
3968:
3969:
3970: &Apache::lonhtmlcommon::clear_breadcrumbs();
3971: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
3972: text=>"Parameter Manager",
3973: faq=>10,
3974: bug=>'Instructor Interface',
3975: help => 'Parameter_Manager'});
3976:
3977: # ----------------------------------------------------- Needs to be in a course
3978: my $parm_permission =
3979: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
3980: &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
3981: $env{'request.course.sec'}));
3982: my $exists = &check_for_course_info();
3983:
3984: if ($env{'request.course.id'} && $parm_permission && $exists) {
3985:
3986: # Start Page
3987: &Apache::loncommon::content_type($r,'text/html');
3988: $r->send_http_header;
3989:
3990:
3991: # id numbers can change on re-ordering of folders
3992:
3993: &resetsymbcache();
3994:
3995: #
3996: # Main switch on form.action and form.state, as appropriate
3997: #
3998: # Check first if coming from someone else headed directly for
3999: # the table mode
4000: if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
4001: && (!$env{'form.dis'})) || ($env{'form.symb'})) {
4002: &Apache::lonhtmlcommon::add_breadcrumb({help=>'Problem_Parameters',
4003: text=>"Problem Parameters"});
4004: &assessparms($r);
4005:
4006: } elsif (! exists($env{'form.action'})) {
4007: $r->print(&header());
4008: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Manager'));
4009: &print_main_menu($r,$parm_permission);
4010: } elsif ($env{'form.action'} eq 'crsenv' && $parm_permission) {
4011: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=crsenv',
4012: text=>"Course Environment"});
4013: &crsenv($r);
4014: } elsif ($env{'form.action'} eq 'setoverview' && $parm_permission) {
4015: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
4016: text=>"Overview Mode"});
4017: &overview($r);
4018: } elsif ($env{'form.action'} eq 'addmetadata' && $parm_permission) {
4019: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
4020: text=>"Add Metadata Field"});
4021: &addmetafield($r);
4022: } elsif ($env{'form.action'} eq 'ordermetadata' && $parm_permission) {
4023: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
4024: text=>"Add Metadata Field"});
4025: &order_meta_fields($r);
4026: } elsif ($env{'form.action'} eq 'setrestrictmeta' && $parm_permission) {
4027: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
4028: text=>"Restrict Metadata"});
4029: &setrestrictmeta($r);
4030: } elsif ($env{'form.action'} eq 'newoverview' && $parm_permission) {
4031: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
4032: text=>"Overview Mode"});
4033: &newoverview($r);
4034: } elsif ($env{'form.action'} eq 'setdefaults' && $parm_permission) {
4035: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
4036: text=>"Set Defaults"});
4037: &defaultsetter($r);
4038: } elsif ($env{'form.action'} eq 'settable' && $parm_permission) {
4039: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
4040: text=>"Table Mode",
4041: help => 'Course_Setting_Parameters'});
4042: &assessparms($r);
4043: } elsif ($env{'form.action'} eq 'parameterchangelog' && $parm_permission) {
4044: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
4045: text=>"Parameter Change Log"});
4046: &parm_change_log($r);
4047: } elsif ($env{'form.action'} eq 'cleanparameters' && $parm_permission) {
4048: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
4049: text=>"Clean Parameters"});
4050: &clean_parameters($r);
4051: }
4052: } else {
4053: # ----------------------------- Not in a course, or not allowed to modify parms
4054: if ($exists) {
4055: $env{'user.error.msg'}=
4056: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
4057: } else {
4058: $env{'user.error.msg'}=
4059: "/adm/parmset::0:1:Course environment gone, reinitialize the course";
4060: }
4061: return HTTP_NOT_ACCEPTABLE;
4062: }
4063: return OK;
4064: }
4065:
4066: 1;
4067: __END__
4068:
4069: =pod
4070:
4071: =back
4072:
4073: =cut
4074:
4075:
4076:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>