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