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