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