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