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