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