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