File:
[LON-CAPA] /
loncom /
interface /
lonparmset.pm
Revision
1.118:
download - view:
text,
annotated -
select for diffs
Thu Jul 24 17:53:59 2003 UTC (21 years ago) by
matthew
Branches:
MAIN
CVS tags:
HEAD
Bug 679: Need to be able to disable chatroom.
Added plc (permission for live chat).
lonchat.pm and lonchatfetch.pm now both call &lonnet::allowed('plc',...)
lonparmset.pm, loncreatecourse.pm, and course.initialization.helper
now all allow setting $ENV{'course.'.$courseid.'.plc.roles.deny'}
lonparmset.pm also allows the user to set
$ENV{'course.'.$courseid.'.plc.users.deny'}
lonmenu.pm was modified to allow us to require the user both be in
a course AND have permissions.
mydesk.tab, roles.tab, and rolesplain.tab were modified to include the
new role.
1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
4: # $Id: lonparmset.pm,v 1.118 2003/07/24 17:53:59 matthew 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:
65:
66: my %courseopt;
67: my %useropt;
68: my %parmhash;
69:
70: my @ids;
71: my %symbp;
72: my %mapp;
73: my %typep;
74: my %keyp;
75:
76: my %maptitles;
77:
78: my $uname;
79: my $udom;
80: my $uhome;
81: my $csec;
82: my $coursename;
83:
84: ##################################################
85: ##################################################
86:
87: =pod
88:
89: =item parmval
90:
91: Figure out a cascading parameter.
92:
93: Inputs: $what - a parameter spec (incluse part info and name I.E. 0.weight)
94: $id - a bighash Id number
95: $def - the resource's default value 'stupid emacs
96:
97: 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
98:
99: 11- resource default
100: 10- map default
101: 9 - General Course
102: 8 - Map or Folder level in course
103: 7 - resource level in course
104: 6 - General for section
105: 5 - Map or Folder level for section
106: 4 - resource level in section
107: 3 - General for specific student
108: 2 - Map or Folder level for specific student
109: 1 - resource level for specific student
110:
111: =cut
112:
113: ##################################################
114: ##################################################
115: sub parmval {
116: my ($what,$id,$def)=@_;
117: my $result='';
118: my @outpar=();
119: # ----------------------------------------------------- Cascading lookup scheme
120:
121: my $symbparm=$symbp{$id}.'.'.$what;
122: my $mapparm=$mapp{$id}.'___(all).'.$what;
123:
124: my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$what;
125: my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
126: my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
127:
128: my $courselevel=$ENV{'request.course.id'}.'.'.$what;
129: my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
130: my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
131:
132: # -------------------------------------------------------- first, check default
133:
134: if ($def) { $outpar[11]=$def; $result=11; }
135:
136: # ----------------------------------------------------- second, check map parms
137:
138: my $thisparm=$parmhash{$symbparm};
139: if ($thisparm) { $outpar[10]=$thisparm; $result=10; }
140:
141: # --------------------------------------------------------- third, check course
142:
143: if (defined($courseopt{$courselevel})) {
144: $outpar[9]=$courseopt{$courselevel};
145: $result=9;
146: }
147:
148: if (defined($courseopt{$courselevelm})) {
149: $outpar[8]=$courseopt{$courselevelm};
150: $result=8;
151: }
152:
153: if (defined($courseopt{$courselevelr})) {
154: $outpar[7]=$courseopt{$courselevelr};
155: $result=7;
156: }
157:
158: if (defined($csec)) {
159: if (defined($courseopt{$seclevel})) {
160: $outpar[6]=$courseopt{$seclevel};
161: $result=6;
162: }
163: if (defined($courseopt{$seclevelm})) {
164: $outpar[5]=$courseopt{$seclevelm};
165: $result=5;
166: }
167:
168: if (defined($courseopt{$seclevelr})) {
169: $outpar[4]=$courseopt{$seclevelr};
170: $result=4;
171: }
172: }
173:
174: # ---------------------------------------------------------- fourth, check user
175:
176: if (defined($uname)) {
177: if (defined($useropt{$courselevel})) {
178: $outpar[3]=$useropt{$courselevel};
179: $result=3;
180: }
181:
182: if (defined($useropt{$courselevelm})) {
183: $outpar[2]=$useropt{$courselevelm};
184: $result=2;
185: }
186:
187: if (defined($useropt{$courselevelr})) {
188: $outpar[1]=$useropt{$courselevelr};
189: $result=1;
190: }
191: }
192: return ($result,@outpar);
193: }
194:
195: ##################################################
196: ##################################################
197:
198: =pod
199:
200: =item valout
201:
202: Format a value for output.
203:
204: Inputs: $value, $type
205:
206: Returns: $value, formatted for output. If $type indicates it is a date,
207: localtime($value) is returned.
208:
209: =cut
210:
211: ##################################################
212: ##################################################
213: sub valout {
214: my ($value,$type)=@_;
215: my $result = '';
216: # Values of zero are valid.
217: if (! $value && $value ne '0') {
218: $result = ' ';
219: } else {
220: if ($type eq 'date_interval') {
221: my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
222: $year=$year-70;
223: $mday--;
224: if ($year) {
225: $result.=$year.' yrs ';
226: }
227: if ($mon) {
228: $result.=$mon.' mths ';
229: }
230: if ($mday) {
231: $result.=$mday.' days ';
232: }
233: if ($hour) {
234: $result.=$hour.' hrs ';
235: }
236: if ($min) {
237: $result.=$min.' mins ';
238: }
239: if ($sec) {
240: $result.=$sec.' secs ';
241: }
242: $result=~s/\s+$//;
243: } elsif ($type=~/^date/) {
244: $result = localtime($value);
245: } else {
246: $result = $value;
247: }
248: }
249: return $result;
250: }
251:
252: ##################################################
253: ##################################################
254:
255: =pod
256:
257: =item plink
258:
259: Produces a link anchor.
260:
261: Inputs: $type,$dis,$value,$marker,$return,$call
262:
263: Returns: scalar with html code for a link which will envoke the
264: javascript function 'pjump'.
265:
266: =cut
267:
268: ##################################################
269: ##################################################
270: sub plink {
271: my ($type,$dis,$value,$marker,$return,$call)=@_;
272: my $winvalue=$value;
273: unless ($winvalue) {
274: if ($type=~/^date/) {
275: $winvalue=$ENV{'form.recent_'.$type};
276: } else {
277: $winvalue=$ENV{'form.recent_'.(split(/\_/,$type))[0]};
278: }
279: }
280: return
281: '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
282: .$marker."','".$return."','".$call."'".');">'.
283: &valout($value,$type).'</a><a name="'.$marker.'"></a>';
284: }
285:
286:
287: sub startpage {
288: my ($r,$id,$udom,$csec,$uname,$have_assesments)=@_;
289:
290: my $bodytag=&Apache::loncommon::bodytag('Set Course Parameters','',
291: 'onUnload="pclose()"');
292: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
293: &Apache::loncommon::selectstudent_link('parmform','uname','udom');
294: my $selscript=&Apache::loncommon::studentbrowser_javascript();
295: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
296: $r->print(<<ENDHEAD);
297: <html>
298: <head>
299: <title>LON-CAPA Course Parameters</title>
300: <script>
301:
302: function pclose() {
303: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
304: "height=350,width=350,scrollbars=no,menubar=no");
305: parmwin.close();
306: }
307:
308: $pjump_def
309:
310: function psub() {
311: pclose();
312: if (document.parmform.pres_marker.value!='') {
313: document.parmform.action+='#'+document.parmform.pres_marker.value;
314: var typedef=new Array();
315: typedef=document.parmform.pres_type.value.split('_');
316: if (document.parmform.pres_type.value!='') {
317: if (typedef[0]=='date') {
318: eval('document.parmform.recent_'+
319: document.parmform.pres_type.value+
320: '.value=document.parmform.pres_value.value;');
321: } else {
322: eval('document.parmform.recent_'+typedef[0]+
323: '.value=document.parmform.pres_value.value;');
324: }
325: }
326: document.parmform.submit();
327: } else {
328: document.parmform.pres_value.value='';
329: document.parmform.pres_marker.value='';
330: }
331: }
332:
333: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
334: var options = "width=" + w + ",height=" + h + ",";
335: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
336: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
337: var newWin = window.open(url, wdwName, options);
338: newWin.focus();
339: }
340: </script>
341: $selscript
342: </head>
343: $bodytag
344:
345: <form method="post" action="/adm/parmset" name="envform">
346: <h3>Course Environment</h3>
347: <input type="submit" name="crsenv" value="Set Course Environment">
348: </form>
349: <hr />
350: <form method="post" action="/adm/parmset" name="parmform">
351: <h3>Course Assessments</h3>
352:
353: <a href="/adm/helper/parameter.helper">Use Assignment Parameter Helper</a>, a
354: simpler interface to set open, due, or answer open dates for problems or
355: sequences.<br /> <br />
356: ENDHEAD
357:
358: if (!$have_assesments) {
359: $r->print('<font color="red">There are no assesment parameters in this course to set.</font><br />');
360: } else {
361: $r->print(<<ENDHEAD);
362: <b>
363: Section/Group:
364: <input type="text" value="$csec" size="6" name="csec">
365: <br>
366: For User
367: <input type="text" value="$uname" size="12" name="uname">
368: or ID
369: <input type="text" value="$id" size="12" name="id">
370: at Domain
371: $chooseopt
372: </b>
373: <input type="hidden" value='' name="pres_value">
374: <input type="hidden" value='' name="pres_type">
375: <input type="hidden" value='' name="pres_marker">
376: ENDHEAD
377: }
378: }
379:
380: sub print_row {
381: my ($r,$which,$part,$name,$rid,$default,$defaulttype,$display,$defbgone,
382: $defbgtwo,$parmlev)=@_;
383: # get the values for the parameter in cascading order
384: # empty levels will remain empty
385: my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
386: $rid,$$default{$which});
387: # get the type for the parameters
388: # problem: these may not be set for all levels
389: my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
390: $$name{$which}.'.type',
391: $rid,$$defaulttype{$which});
392: # cascade down manually
393: my $cascadetype=$defaulttype;
394: for (my $i=$#typeoutpar;$i>0;$i--) {
395: if ($typeoutpar[$i]) {
396: $cascadetype=$typeoutpar[$i];
397: } else {
398: $typeoutpar[$i]=$cascadetype;
399: }
400: }
401:
402: my $parm=$$display{$which};
403:
404: if ($parmlev eq 'full' || $parmlev eq 'brief') {
405: $r->print('<td bgcolor='.$defbgtwo.' align="center">'
406: .$$part{$which}.'</td>');
407: } else {
408: $parm=~s|\[.*\]\s||g;
409: }
410:
411: $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
412:
413: my $thismarker=$which;
414: $thismarker=~s/^parameter\_//;
415: my $mprefix=$rid.'&'.$thismarker.'&';
416:
417: if ($parmlev eq 'general') {
418:
419: if ($uname) {
420: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
421: } elsif ($csec) {
422: &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
423: } else {
424: &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
425: }
426: } elsif ($parmlev eq 'map') {
427:
428: if ($uname) {
429: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
430: } elsif ($csec) {
431: &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
432: } else {
433: &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
434: }
435: } else {
436:
437: &print_td($r,11,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
438:
439: if ($parmlev eq 'brief') {
440:
441: &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
442:
443: if ($csec) {
444: &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
445: }
446: if ($uname) {
447: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
448: }
449: } else {
450:
451: &print_td($r,10,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
452: &print_td($r,9,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
453: &print_td($r,8,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
454: &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
455:
456: if ($csec) {
457: &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
458: &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
459: &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
460: }
461: if ($uname) {
462: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
463: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
464: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
465: }
466: } # end of $brief if/else
467: } # end of $parmlev if/else
468:
469: if ($parmlev eq 'full' || $parmlev eq 'brief') {
470: $r->print('<td bgcolor=#CCCCFF align="center">'.
471: &valout($outpar[$result],$typeoutpar[$result]).'</td>');
472: }
473: my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
474: '.'.$$name{$which},$symbp{$rid});
475: # this doesn't seem to work, and I don't think is correct
476: # my $sessionvaltype=&Apache::lonnet::EXT('resource.'.$$part{$which}.
477: # '.'.$$name{$which}.'.type',$symbp{$rid});
478: # this seems to work
479: my $sessionvaltype=$typeoutpar[$result];
480: if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
481: $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
482: &valout($sessionval,$sessionvaltype).' '.
483: '</font></td>');
484: $r->print('</tr>');
485: $r->print("\n");
486: }
487:
488: sub print_td {
489: my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
490: $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
491: ' align="center">');
492: if ($which<10) {
493: $r->print(&plink($$typeoutpar[$which],
494: $$display{$value},$$outpar[$which],
495: $mprefix."$which",'parmform.pres','psub'));
496: } else {
497: $r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
498: }
499: $r->print('</td>'."\n");
500: }
501:
502: sub get_env_multiple {
503: my ($name) = @_;
504: my @values;
505: if (defined($ENV{$name})) {
506: # exists is it an array
507: if (ref($ENV{$name})) {
508: @values=@{ $ENV{$name} };
509: } else {
510: $values[0]=$ENV{$name};
511: }
512: }
513: return(@values);
514: }
515:
516: =pod
517:
518: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
519:
520: Input: See list below:
521:
522: =over 4
523:
524: =item B<ids>: An array that will contain all of the ids in the course.
525:
526: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
527:
528: =item B<keyp>: hash, id->key list, will contain a comma seperated list of the meta-data keys available for the given id
529:
530: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
531:
532: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
533:
534: =item B<allkeys>: hash, full key to part->display value (what's display value?)
535:
536: =item B<allmaps>: hash, ???
537:
538: =item B<fcat>: ???
539:
540: =item B<defp>: hash, ???
541:
542: =item B<mapp>: ??
543:
544: =item B<symbp>: hash, id->full sym?
545:
546: =back
547:
548: =cut
549:
550: sub extractResourceInformation {
551: my $bighash = shift;
552: my $ids = shift;
553: my $typep = shift;
554: my $keyp = shift;
555: my $allparms = shift;
556: my $allparts = shift;
557: my $allkeys = shift;
558: my $allmaps = shift;
559: my $fcat = shift;
560: my $defp = shift;
561: my $mapp = shift;
562: my $symbp = shift;
563: my $maptitles=shift;
564:
565: foreach (keys %$bighash) {
566: if ($_=~/^src\_(\d+)\.(\d+)$/) {
567: my $mapid=$1;
568: my $resid=$2;
569: my $id=$mapid.'.'.$resid;
570: my $srcf=$$bighash{$_};
571: if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) {
572: $$ids[$#$ids+1]=$id;
573: $$typep{$id}=$1;
574: $$keyp{$id}='';
575: foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
576: if ($_=~/^parameter\_(.*)/) {
577: my $key=$_;
578: my $allkey=$1;
579: $allkey=~s/\_/\./g;
580: my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
581: my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
582: my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
583: my $parmdis = $display;
584: $parmdis =~ s|(\[Part.*$)||g;
585: my $partkey = $part;
586: $partkey =~ tr|_|.|;
587: $$allparms{$name} = $parmdis;
588: $$allparts{$part} = "[Part $part]";
589: $$allkeys{$allkey}=$display;
590: if ($allkey eq $fcat) {
591: $$defp{$id}= &Apache::lonnet::metadata($srcf,$key);
592: }
593: if ($$keyp{$id}) {
594: $$keyp{$id}.=','.$key;
595: } else {
596: $$keyp{$id}=$key;
597: }
598: }
599: }
600: $$mapp{$id}=
601: &Apache::lonnet::declutter($$bighash{'map_id_'.$mapid});
602: $$mapp{$mapid}=$$mapp{$id};
603: $$allmaps{$mapid}=$$mapp{$id};
604: $$maptitles{$mapid}=
605: $$bighash{'title_'.$$bighash{'ids_'.&Apache::lonnet::clutter($$mapp{$id})}};
606: $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
607: $$symbp{$id}=$$mapp{$id}.
608: '___'.$resid.'___'.
609: &Apache::lonnet::declutter($srcf);
610: $$symbp{$mapid}=$$mapp{$id}.'___(all)';
611: }
612: }
613: }
614: }
615:
616: ##################################################
617: ##################################################
618:
619: =pod
620:
621: =item assessparms
622:
623: Show assessment data and parameters. This is a large routine that should
624: be simplified and shortened... someday.
625:
626: Inputs: $r
627:
628: Returns: nothing
629:
630: Variables used (guessed by Jeremy):
631:
632: =over 4
633:
634: =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.
635:
636: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
637:
638: =item B<allmaps>:
639:
640: =back
641:
642: =cut
643:
644: ##################################################
645: ##################################################
646: sub assessparms {
647:
648: my $r=shift;
649: # -------------------------------------------------------- Variable declaration
650: my %allkeys;
651: my %allmaps;
652: my %alllevs;
653:
654: $alllevs{'Resource Level'}='full';
655: # $alllevs{'Resource Level [BRIEF]'}='brief';
656: $alllevs{'Map Level'}='map';
657: $alllevs{'Course Level'}='general';
658:
659: my %allparms;
660: my %allparts;
661:
662: my %defp;
663: %courseopt=();
664: %useropt=();
665: my %bighash=();
666:
667: @ids=();
668: %symbp=();
669: %typep=();
670:
671: my $message='';
672:
673: $csec=$ENV{'form.csec'};
674: $udom=$ENV{'form.udom'};
675: unless ($udom) { $udom=$r->dir_config('lonDefDomain'); }
676:
677: my @pscat=&get_env_multiple('form.pscat');
678: my $pschp=$ENV{'form.pschp'};
679: my @psprt=&get_env_multiple('form.psprt');
680: if (!@psprt) { $psprt[0]='0'; }
681: my $showoptions=$ENV{'form.showoptions'};
682:
683: my $pssymb='';
684: my $parmlev='';
685: my $prevvisit=$ENV{'form.prevvisit'};
686:
687: # unless ($parmlev==$ENV{'form.parmlev'}) {
688: # $parmlev = 'full';
689: # }
690:
691: unless ($ENV{'form.parmlev'}) {
692: $parmlev = 'map';
693: } else {
694: $parmlev = $ENV{'form.parmlev'};
695: }
696:
697: # ----------------------------------------------- Was this started from grades?
698:
699: if (($ENV{'form.command'} eq 'set') && ($ENV{'form.url'})
700: && (!$ENV{'form.dis'})) {
701: my $url=$ENV{'form.url'};
702: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
703: $pssymb=&Apache::lonnet::symbread($url);
704: if (!@pscat) { @pscat=('all'); }
705: $pschp='';
706: $parmlev = 'full';
707: } elsif ($ENV{'form.symb'}) {
708: $pssymb=$ENV{'form.symb'};
709: if (!@pscat) { @pscat=('all'); }
710: $pschp='';
711: $parmlev = 'full';
712: } else {
713: $ENV{'form.url'}='';
714: }
715:
716: my $id=$ENV{'form.id'};
717: if (($id) && ($udom)) {
718: $uname=(&Apache::lonnet::idget($udom,$id))[1];
719: if ($uname) {
720: $id='';
721: } else {
722: $message=
723: "<font color=red>Unknown ID '$id' at domain '$udom'</font>";
724: }
725: } else {
726: $uname=$ENV{'form.uname'};
727: }
728: unless ($udom) { $uname=''; }
729: $uhome='';
730: if ($uname) {
731: $uhome=&Apache::lonnet::homeserver($uname,$udom);
732: if ($uhome eq 'no_host') {
733: $message=
734: "<font color=red>Unknown user '$uname' at domain '$udom'</font>";
735: $uname='';
736: } else {
737: $csec=&Apache::lonnet::getsection($udom,$uname,
738: $ENV{'request.course.id'});
739: if ($csec eq '-1') {
740: $message="<font color=red>".
741: "User '$uname' at domain '$udom' not ".
742: "in this course</font>";
743: $uname='';
744: $csec=$ENV{'form.csec'};
745: } else {
746: my %name=&Apache::lonnet::userenvironment($udom,$uname,
747: ('firstname','middlename','lastname','generation','id'));
748: $message="\n<p>\nFull Name: ".
749: $name{'firstname'}.' '.$name{'middlename'}.' '
750: .$name{'lastname'}.' '.$name{'generation'}.
751: "<br>\nID: ".$name{'id'}.'<p>';
752: }
753: }
754: }
755:
756: unless ($csec) { $csec=''; }
757:
758: my $fcat=$ENV{'form.fcat'};
759: unless ($fcat) { $fcat=''; }
760:
761: # ------------------------------------------------------------------- Tie hashs
762: if (!(tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
763: &GDBM_READER(),0640))) {
764: $r->print("Unable to access course data. (File $ENV{'request.course.fn'}.db not tieable)");
765: return ;
766: }
767: if (!(tie(%parmhash,'GDBM_File',
768: $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640))) {
769: $r->print("Unable to access parameter data. (File $ENV{'request.course.fn'}_parms.db not tieable)");
770: return ;
771: }
772:
773: # --------------------------------------------------------- Get all assessments
774: extractResourceInformation(\%bighash, \@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles);
775:
776: $mapp{'0.0'} = '';
777: $symbp{'0.0'} = '';
778:
779: # ---------------------------------------------------------- Anything to store?
780: if ($ENV{'form.pres_marker'}) {
781: my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
782: $spnam=~s/\_([^\_]+)$/\.$1/;
783: # ---------------------------------------------------------- Construct prefixes
784:
785: my $symbparm=$symbp{$sresid}.'.'.$spnam;
786: my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
787:
788: my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$spnam;
789: my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
790: my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
791:
792: my $courselevel=$ENV{'request.course.id'}.'.'.$spnam;
793: my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
794: my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
795:
796: my $storeunder='';
797: if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
798: if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
799: if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
800: if ($snum==6) { $storeunder=$seclevel; }
801: if ($snum==5) { $storeunder=$seclevelm; }
802: if ($snum==4) { $storeunder=$seclevelr; }
803:
804: my $delete;
805: if ($ENV{'form.pres_value'} eq '') { $delete=1;}
806: my %storecontent = ($storeunder => $ENV{'form.pres_value'},
807: $storeunder.'.type' => $ENV{'form.pres_type'});
808: my $reply='';
809: if ($snum>3) {
810: # ---------------------------------------------------------------- Store Course
811: #
812: # Expire sheets
813: &Apache::lonnet::expirespread('','','studentcalc');
814: if (($snum==7) || ($snum==4)) {
815: &Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
816: } elsif (($snum==8) || ($snum==5)) {
817: &Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
818: } else {
819: &Apache::lonnet::expirespread('','','assesscalc');
820: }
821: # Store parameter
822: if ($delete) {
823: $reply=&Apache::lonnet::del
824: ('resourcedata',[keys(%storecontent)],
825: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
826: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
827: } else {
828: $reply=&Apache::lonnet::cput
829: ('resourcedata',\%storecontent,
830: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
831: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
832: }
833: } else {
834: # ------------------------------------------------------------------ Store User
835: #
836: # Expire sheets
837: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
838: if ($snum==1) {
839: &Apache::lonnet::expirespread
840: ($uname,$udom,'assesscalc',$symbp{$sresid});
841: } elsif ($snum==2) {
842: &Apache::lonnet::expirespread
843: ($uname,$udom,'assesscalc',$mapp{$sresid});
844: } else {
845: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
846: }
847: # Store parameter
848: if ($delete) {
849: $reply=&Apache::lonnet::del
850: ('resourcedata',[keys(%storecontent)],$udom,$uname);
851: } else {
852: $reply=&Apache::lonnet::cput
853: ('resourcedata',\%storecontent,$udom,$uname);
854: }
855: }
856:
857: if ($reply=~/^error\:(.*)/) {
858: $message.="<font color=red>Write Error: $1</font>";
859: }
860: # ---------------------------------------------------------------- Done storing
861: $message.='<h3>Changes can take up to 10 minutes before being active for all students.'.&Apache::loncommon::help_open_topic('Caching').'</h3>';
862: }
863: # --------------------------------------------- Devalidate cache for this child
864: &Apache::lonnet::devalidatecourseresdata(
865: $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
866: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'});
867: &Apache::lonnet::clear_EXT_cache_status();
868: # -------------------------------------------------------------- Get coursedata
869: %courseopt = &Apache::lonnet::dump
870: ('resourcedata',
871: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
872: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
873: # --------------------------------------------------- Get userdata (if present)
874: if ($uname) {
875: %useropt=&Apache::lonnet::dump('resourcedata',$udom,$uname);
876: }
877:
878: # ------------------------------------------------------------------- Sort this
879:
880: @ids=sort {
881: if ($fcat eq '') {
882: $a<=>$b;
883: } else {
884: my ($result,@outpar)=&parmval($fcat,$a,$defp{$a});
885: my $aparm=$outpar[$result];
886: ($result,@outpar)=&parmval($fcat,$b,$defp{$b});
887: my $bparm=$outpar[$result];
888: 1*$aparm<=>1*$bparm;
889: }
890: } @ids;
891: #----------------------------------------------- if all selected, fill in array
892: if ($pscat[0] eq "all" || !@pscat) {@pscat = (keys %allparms);}
893: if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
894: # ------------------------------------------------------------------ Start page
895:
896: my $have_assesments=1;
897: if (scalar(keys(%allkeys)) eq 0) { $have_assesments=0; }
898:
899: &startpage($r,$id,$udom,$csec,$uname,$have_assesments);
900:
901: if (!$have_assesments) {
902: untie(%bighash);
903: untie(%parmhash);
904: return '';
905: }
906: # if ($ENV{'form.url'}) {
907: # $r->print('<input type="hidden" value="'.$ENV{'form.url'}.
908: # '" name="url"><input type="hidden" name="command" value="set">');
909: # }
910: $r->print('<input type="hidden" value="true" name="prevvisit">');
911:
912: foreach ('tolerance','date_default','date_start','date_end',
913: 'date_interval','int','float','string') {
914: $r->print('<input type="hidden" value="'.
915: $ENV{'form.recent_'.$_}.'" name="recent_'.$_.'">');
916: }
917:
918: $r->print('<h2>'.$message.'</h2><table>');
919:
920: my $submitmessage;
921: if (!$pssymb) {
922: $r->print('<tr><td>Select Parameter Level</td><td colspan="2">');
923: $r->print('<select name="parmlev">');
924: foreach (reverse sort keys %alllevs) {
925: $r->print('<option value="'.$alllevs{$_}.'"');
926: if ($parmlev eq $alllevs{$_}) {
927: $r->print(' selected');
928: }
929: $r->print('>'.$_.'</option>');
930: }
931: $r->print("</select></td>\n");
932:
933: $r->print('</tr>');
934:
935: $r->print('<tr><td>Select Enclosing Map or Folder</td>');
936: $r->print('<td colspan="2"><select name="pschp">');
937: $r->print('<option value="all">All Maps or Folders</option>');
938: foreach (sort {$allmaps{$a} cmp $allmaps{$b}} keys %allmaps) {
939: $r->print('<option value="'.$_.'"');
940: if (($pschp eq $_)) { $r->print(' selected'); }
941: $r->print('>'.$maptitles{$_}.($allmaps{$_}!~/^uploaded/?' ['.$allmaps{$_}.']':'').'</option>');
942: }
943: $r->print("</select></td></tr>\n");
944: } else {
945: my ($map,$id,$resource)=split(/___/,$pssymb);
946: $r->print("<tr><td>Specific Resource</td><td>$resource</td>");
947: $r->print('<td><input type="submit" name="dis" value="'.$submitmessage.'"></td>');
948: $r->print('</tr>');
949: $r->print('<input type="hidden" value="'.$pssymb.'" name="symb">');
950: }
951:
952: $r->print('<tr><td colspan="3"><hr /><input type="checkbox"');
953: if ($showoptions eq 'show') {$r->print(" checked ");}
954: $r->print(' name="showoptions" value="show">Show More Options<hr /></td></tr>');
955: # $r->print("<tr><td>Show: $showoptions</td></tr>");
956: # $r->print("<tr><td>pscat: @pscat</td></tr>");
957: # $r->print("<tr><td>psprt: @psprt</td></tr>");
958: # $r->print("<tr><td>fcat: $fcat</td></tr>");
959:
960: if ($showoptions eq 'show') {
961: my $tempkey;
962:
963: $r->print('<tr><td colspan="3" align="center">Select Parameters to View</td></tr>');
964:
965: $r->print('<tr><td colspan="2"><table>');
966: $r->print('<tr><td><input type="checkbox" name="pscat" value="all"');
967: $r->print(' checked') unless (@pscat);
968: $r->print('>All Parameters</td>');
969:
970: my $cnt=0;
971: foreach $tempkey (sort { $allparms{$a} cmp $allparms{$b} }
972: keys %allparms ) {
973: ++$cnt;
974: $r->print('</tr><tr>') unless ($cnt%2);
975: $r->print('<td><input type="checkbox" name="pscat" ');
976: $r->print('value="'.$tempkey.'"');
977: if ($pscat[0] eq "all" || grep $_ eq $tempkey, @pscat) {
978: $r->print(' checked');
979: }
980: $r->print('>'.$allparms{$tempkey}.'</td>');
981: }
982: $r->print('</tr></table>');
983:
984: # $r->print('<tr><td>Select Parts</td><td>');
985: $r->print('<td><select multiple name="psprt" size="5">');
986: $r->print('<option value="all"');
987: $r->print(' selected') unless (@psprt);
988: $r->print('>All Parts</option>');
989: my %temphash=();
990: foreach (@psprt) { $temphash{$_}=1; }
991: foreach $tempkey (sort keys %allparts) {
992: unless ($tempkey =~ /\./) {
993: $r->print('<option value="'.$tempkey.'"');
994: if ($psprt[0] eq "all" || $temphash{$tempkey}) {
995: $r->print(' selected');
996: }
997: $r->print('>'.$allparts{$tempkey}.'</option>');
998: }
999: }
1000: $r->print('</select></td></tr><tr><td colspan="3"><hr /></td></tr>');
1001:
1002: $r->print('<tr><td>Sort list by</td><td>');
1003: $r->print('<select name="fcat">');
1004: $r->print('<option value="">Enclosing Map or Folder</option>');
1005: foreach (sort keys %allkeys) {
1006: $r->print('<option value="'.$_.'"');
1007: if ($fcat eq $_) { $r->print(' selected'); }
1008: $r->print('>'.$allkeys{$_}.'</option>');
1009: }
1010: $r->print('</select></td>');
1011:
1012: $r->print('</tr><tr><td colspan="3"><hr /></td></tr>');
1013:
1014: } else { # hide options - include any necessary extras here
1015:
1016: $r->print('<input type="hidden" name="fcat" value="'.$fcat.'">'."\n");
1017:
1018: unless (@pscat) {
1019: foreach (keys %allparms ) {
1020: $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
1021: }
1022: } else {
1023: foreach (@pscat) {
1024: $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
1025: }
1026: }
1027:
1028: unless (@psprt) {
1029: foreach (keys %allparts ) {
1030: $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
1031: }
1032: } else {
1033: foreach (@psprt) {
1034: $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
1035: }
1036: }
1037:
1038: }
1039: $r->print('</table><br />');
1040: if (($prevvisit) || ($pschp) || ($pssymb)) {
1041: $submitmessage = "Update Course Assessment Parameter Display";
1042: } else {
1043: $submitmessage = "Set Course Assessment Parameters";
1044: }
1045: $r->print('<input type="submit" name="dis" value="'.$submitmessage.'">');
1046:
1047: # my @temp_psprt;
1048: # foreach my $t (@psprt) {
1049: # push(@temp_psprt, grep {eval (/^$t\./ || ($_ == $t))} (keys %allparts));
1050: # }
1051:
1052: # @psprt = @temp_psprt;
1053:
1054: my @temp_pscat;
1055: map {
1056: my $cat = $_;
1057: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
1058: } @pscat;
1059:
1060: @pscat = @temp_pscat;
1061:
1062: if (($prevvisit) || ($pschp) || ($pssymb)) {
1063: # ----------------------------------------------------------------- Start Table
1064: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
1065: my $csuname=$ENV{'user.name'};
1066: my $csudom=$ENV{'user.domain'};
1067:
1068: if ($parmlev eq 'full' || $parmlev eq 'brief') {
1069: my $coursespan=$csec?8:5;
1070: $r->print('<p><table border=2>');
1071: $r->print('<tr><td colspan=5></td>');
1072: $r->print('<th colspan='.($coursespan).'>Any User</th>');
1073: if ($uname) {
1074: $r->print("<th colspan=3 rowspan=2>");
1075: $r->print("User $uname at Domain $udom</th>");
1076: }
1077: $r->print(<<ENDTABLETWO);
1078: <th rowspan=3>Parameter in Effect</th>
1079: <th rowspan=3>Current Session Value<br>($csuname at $csudom)</th>
1080: </tr><tr><td colspan=5></td><th colspan=2>Resource Level</th>
1081: <th colspan=3>in Course</th>
1082: ENDTABLETWO
1083: if ($csec) {
1084: $r->print("<th colspan=3>in Section/Group $csec</th>");
1085: }
1086: $r->print(<<ENDTABLEHEADFOUR);
1087: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1088: <th>Enclosing Map or Folder</th><th>Part</th><th>Parameter Name</th>
1089: <th>default</th><th>from Enclosing Map or Folder</th>
1090: <th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>
1091: ENDTABLEHEADFOUR
1092:
1093: if ($csec) {
1094: $r->print('<th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>');
1095: }
1096:
1097: if ($uname) {
1098: $r->print('<th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>');
1099: }
1100:
1101: $r->print('</tr>');
1102:
1103: my $defbgone='';
1104: my $defbgtwo='';
1105:
1106: foreach (@ids) {
1107:
1108: my $rid=$_;
1109: my ($inmapid)=($rid=~/\.(\d+)$/);
1110:
1111: if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
1112: ($pssymb eq $symbp{$rid})) {
1113: # ------------------------------------------------------ Entry for one resource
1114: if ($defbgone eq '"E0E099"') {
1115: $defbgone='"E0E0DD"';
1116: } else {
1117: $defbgone='"E0E099"';
1118: }
1119: if ($defbgtwo eq '"FFFF99"') {
1120: $defbgtwo='"FFFFDD"';
1121: } else {
1122: $defbgtwo='"FFFF99"';
1123: }
1124: my $thistitle='';
1125: my %name= ();
1126: undef %name;
1127: my %part= ();
1128: my %display=();
1129: my %type= ();
1130: my %default=();
1131: my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
1132:
1133: foreach (split(/\,/,$keyp{$rid})) {
1134: my $tempkeyp = $_;
1135: if (grep $_ eq $tempkeyp, @catmarker) {
1136: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
1137: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
1138: $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
1139: unless ($display{$_}) { $display{$_}=''; }
1140: $display{$_}.=' ('.$name{$_}.')';
1141: $default{$_}=&Apache::lonnet::metadata($uri,$_);
1142: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
1143: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
1144: }
1145: }
1146: my $totalparms=scalar keys %name;
1147: if ($totalparms>0) {
1148: my $firstrow=1;
1149:
1150: $r->print('<tr><td bgcolor='.$defbgone.
1151: ' rowspan='.$totalparms.
1152: '><tt><font size=-1>'.
1153: join(' / ',split(/\//,$uri)).
1154: '</font></tt><p><b>'.
1155: "<a href=\"javascript:openWindow('/res/".$uri.
1156: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
1157: " TARGET=_self>$bighash{'title_'.$rid}");
1158:
1159: if ($thistitle) {
1160: $r->print(' ('.$thistitle.')');
1161: }
1162: $r->print('</a></b></td>');
1163: $r->print('<td bgcolor='.$defbgtwo.
1164: ' rowspan='.$totalparms.'>'.$typep{$rid}.
1165: '</td>');
1166:
1167: $r->print('<td bgcolor='.$defbgone.
1168: ' rowspan='.$totalparms.
1169: '><tt><font size=-1>');
1170:
1171: $r->print(' / res / ');
1172: $r->print(join(' / ', split(/\//,$mapp{$rid})));
1173:
1174: $r->print('</font></tt></td>');
1175:
1176: foreach (sort keys %name) {
1177: unless ($firstrow) {
1178: $r->print('<tr>');
1179: } else {
1180: undef $firstrow;
1181: }
1182:
1183: &print_row($r,$_,\%part,\%name,$rid,\%default,
1184: \%type,\%display,$defbgone,$defbgtwo,
1185: $parmlev);
1186: }
1187: }
1188: }
1189: } # end foreach ids
1190: # -------------------------------------------------- End entry for one resource
1191: $r->print('</table>');
1192: } # end of brief/full
1193: #--------------------------------------------------- Entry for parm level map
1194: if ($parmlev eq 'map') {
1195: my $defbgone = '"E0E099"';
1196: my $defbgtwo = '"FFFF99"';
1197:
1198: my %maplist;
1199:
1200: if ($pschp eq 'all') {
1201: %maplist = %allmaps;
1202: } else {
1203: %maplist = ($pschp => $mapp{$pschp});
1204: }
1205:
1206: #-------------------------------------------- for each map, gather information
1207: my $mapid;
1208: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
1209: my $maptitle = $maplist{$mapid};
1210:
1211: #----------------------- loop through ids and get all parameter types for map
1212: #----------------------------------------- and associated information
1213: my %name = ();
1214: my %part = ();
1215: my %display = ();
1216: my %type = ();
1217: my %default = ();
1218: my $map = 0;
1219:
1220: # $r->print("Catmarker: @catmarker<br />\n");
1221:
1222: foreach (@ids) {
1223: ($map)=(/([\d]*?)\./);
1224: my $rid = $_;
1225:
1226: # $r->print("$mapid:$map: $rid <br /> \n");
1227:
1228: if ($map eq $mapid) {
1229: my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
1230: # $r->print("Keys: $keyp{$rid} <br />\n");
1231:
1232: #--------------------------------------------------------------------
1233: # @catmarker contains list of all possible parameters including part #s
1234: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1235: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1236: # When storing information, store as part 0
1237: # When requesting information, request from full part
1238: #-------------------------------------------------------------------
1239: foreach (split(/\,/,$keyp{$rid})) {
1240: my $tempkeyp = $_;
1241: my $fullkeyp = $tempkeyp;
1242: $tempkeyp =~ s/_\w+_/_0_/;
1243:
1244: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1245: $part{$tempkeyp}="0";
1246: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1247: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1248: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1249: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1250: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1251: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1252: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1253: }
1254: } # end loop through keys
1255: }
1256: } # end loop through ids
1257:
1258: #---------------------------------------------------- print header information
1259: my $foldermap=($maptitle=~/^uploaded/?'Folder':'Map');
1260: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
1261: $r->print(<<ENDMAPONE);
1262: <center><h4>
1263: <font color="red">Set Defaults for All Resources in $foldermap<br />
1264: <i>$showtitle</i><br />
1265: Specifically for
1266: ENDMAPONE
1267: if ($uname) {
1268: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1269: ('firstname','middlename','lastname','generation', 'id'));
1270: my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
1271: .$name{'lastname'}.' '.$name{'generation'};
1272: $r->print("User <i>$uname \($person\) </i> in \n");
1273: } else {
1274: $r->print("<i>all</i> users in \n");
1275: }
1276:
1277: if ($csec) {$r->print("Section <i>$csec</i> of \n")};
1278:
1279: $r->print("<i>$coursename</i><br />");
1280: $r->print("</font></h4>\n");
1281: #---------------------------------------------------------------- print table
1282: $r->print('<p><table border="2">');
1283: $r->print('<tr><th>Parameter Name</th>');
1284: $r->print('<th>Default Value</th>');
1285: $r->print('<th>Parameter in Effect</th></tr>');
1286:
1287: foreach (sort keys %name) {
1288: &print_row($r,$_,\%part,\%name,$mapid,\%default,
1289: \%type,\%display,$defbgone,$defbgtwo,
1290: $parmlev);
1291: # $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
1292: }
1293: $r->print("</table></center>");
1294: } # end each map
1295: } # end of $parmlev eq map
1296: #--------------------------------- Entry for parm level general (Course level)
1297: if ($parmlev eq 'general') {
1298: my $defbgone = '"E0E099"';
1299: my $defbgtwo = '"FFFF99"';
1300:
1301: #-------------------------------------------- for each map, gather information
1302: my $mapid="0.0";
1303: #----------------------- loop through ids and get all parameter types for map
1304: #----------------------------------------- and associated information
1305: my %name = ();
1306: my %part = ();
1307: my %display = ();
1308: my %type = ();
1309: my %default = ();
1310:
1311: foreach (@ids) {
1312: my $rid = $_;
1313:
1314: my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
1315:
1316: #--------------------------------------------------------------------
1317: # @catmarker contains list of all possible parameters including part #s
1318: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1319: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1320: # When storing information, store as part 0
1321: # When requesting information, request from full part
1322: #-------------------------------------------------------------------
1323: foreach (split(/\,/,$keyp{$rid})) {
1324: my $tempkeyp = $_;
1325: my $fullkeyp = $tempkeyp;
1326: $tempkeyp =~ s/_\w+_/_0_/;
1327: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1328: $part{$tempkeyp}="0";
1329: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1330: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1331: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1332: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1333: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1334: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1335: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1336: }
1337: } # end loop through keys
1338: } # end loop through ids
1339:
1340: #---------------------------------------------------- print header information
1341: $r->print(<<ENDMAPONE);
1342: <center><h4>
1343: <font color="red">Set Defaults for All Resources in Course
1344: <i>$coursename</i><br />
1345: ENDMAPONE
1346: if ($uname) {
1347: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1348: ('firstname','middlename','lastname','generation', 'id'));
1349: my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
1350: .$name{'lastname'}.' '.$name{'generation'};
1351: $r->print(" User <i>$uname \($person\) </i> \n");
1352: } else {
1353: $r->print("<i>ALL</i> USERS \n");
1354: }
1355:
1356: if ($csec) {$r->print("Section <i>$csec</i>\n")};
1357: $r->print("</font></h4>\n");
1358: #---------------------------------------------------------------- print table
1359: $r->print('<p><table border="2">');
1360: $r->print('<tr><th>Parameter Name</th>');
1361: $r->print('<th>Default Value</th>');
1362: $r->print('<th>Parameter in Effect</th></tr>');
1363:
1364: foreach (sort keys %name) {
1365: &print_row($r,$_,\%part,\%name,$mapid,\%default,
1366: \%type,\%display,$defbgone,$defbgtwo,$parmlev);
1367: # $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
1368: }
1369: $r->print("</table></center>");
1370: } # end of $parmlev eq general
1371: }
1372: $r->print('</form></body></html>');
1373: untie(%bighash);
1374: untie(%parmhash);
1375: } # end sub assessparms
1376:
1377:
1378: ##################################################
1379: ##################################################
1380:
1381: =pod
1382:
1383: =item crsenv
1384:
1385: Show and set course data and parameters. This is a large routine that should
1386: be simplified and shortened... someday.
1387:
1388: Inputs: $r
1389:
1390: Returns: nothing
1391:
1392: =cut
1393:
1394: ##################################################
1395: ##################################################
1396: sub crsenv {
1397: my $r=shift;
1398: my $setoutput='';
1399: my $bodytag=&Apache::loncommon::bodytag(
1400: 'Set Course Environment Parameters');
1401: my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1402: my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1403:
1404: #
1405: # Go through list of changes
1406: foreach (keys %ENV) {
1407: next if ($_!~/^form\.(.+)\_setparmval$/);
1408: my $name = $1;
1409: my $value = $ENV{'form.'.$name.'_value'};
1410: if ($name eq 'newp') {
1411: $name = $ENV{'form.newp_name'};
1412: }
1413: if ($name eq 'url') {
1414: $value=~s/^\/res\///;
1415: my $bkuptime=time;
1416: my @tmp = &Apache::lonnet::get
1417: ('environment',['url'],$dom,$crs);
1418: $setoutput.='Backing up previous URL: '.
1419: &Apache::lonnet::put
1420: ('environment',
1421: {'top level map backup '.$bkuptime => $tmp[1] },
1422: $dom,$crs).
1423: '<br>';
1424: }
1425: #
1426: # Deal with modified default spreadsheets
1427: if ($name =~ /^spreadsheet_default_(classcalc|
1428: studentcalc|
1429: assesscalc)$/x) {
1430: my $sheettype = $1;
1431: if ($sheettype eq 'classcalc') {
1432: # no need to do anything since viewing the sheet will
1433: # cause it to be updated.
1434: } elsif ($sheettype eq 'studentcalc') {
1435: # expire all the student spreadsheets
1436: &Apache::lonnet::expirespread('','','studentcalc');
1437: } else {
1438: # expire all the assessment spreadsheets
1439: # this includes non-default spreadsheets, but better to
1440: # be safe than sorry.
1441: &Apache::lonnet::expirespread('','','assesscalc');
1442: # expire all the student spreadsheets
1443: &Apache::lonnet::expirespread('','','studentcalc');
1444: }
1445: }
1446: #
1447: # Deal with the enrollment dates
1448: if ($name =~ /^default_enrollment_(start|end)_date$/) {
1449: $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
1450: }
1451: #
1452: # Let the user know we made the changes
1453: if ($name) {
1454: my $put_result = &Apache::lonnet::put('environment',
1455: {$name=>$value},$dom,$crs);
1456: if ($put_result eq 'ok') {
1457: $setoutput.='Set <b>'.$name.'</b> to <b>'.$value.'</b>.<br />';
1458: } else {
1459: $setoutput.='Unable to set <b>'.$name.'</b> to '.
1460: '<b>'.$value.'</b> due to '.$put_result.'.<br />';
1461: }
1462: }
1463: }
1464: # ------------------------- Re-init course environment entries for this session
1465:
1466: &Apache::lonnet::coursedescription($ENV{'request.course.id'});
1467:
1468: # -------------------------------------------------------- Get parameters again
1469:
1470: my %values=&Apache::lonnet::dump('environment',$dom,$crs);
1471: my $output='';
1472: if (! exists($values{'con_lost'})) {
1473: my %descriptions=
1474: ('url' => '<b>Top Level Map</b> '.
1475: '<a href="javascript:openbrowser'.
1476: "('envform','url','sequence')\">".
1477: 'Select Map</a><br /><font color=red> '.
1478: 'Modification may make assessment data '.
1479: 'inaccessible</font>',
1480: 'description' => '<b>Course Description</b>',
1481: 'courseid' => '<b>Course ID or number</b><br />'.
1482: '(internal, optional)',
1483: 'grading' => '<b>Grading</b>'.
1484: '"standard" or any other value. '.
1485: 'Default for new courses is "standard".',
1486:
1487: 'default_xml_style' => '<b>Default XML Style File</b> '.
1488: '<a href="javascript:openbrowser'.
1489: "('envform','default_xml_style'".
1490: ",'sty')\">Select Style File</a><br>",
1491: 'question.email' => '<b>Feedback Addresses for Resource Content '.
1492: 'Questions</b><br />(<tt>user:domain,'.
1493: 'user:domain(section;section;...;*;...),...</tt>)',
1494: 'comment.email' => '<b>Feedback Addresses for Course Content Comments</b><br />'.
1495: '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1496: 'policy.email' => '<b>Feedback Addresses for Course Policy</b>'.
1497: '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1498: 'hideemptyrows' => '<b>Hide Empty Rows in Spreadsheets</b><br />'.
1499: '("<tt>yes</tt>" for default hiding)',
1500: 'pageseparators' => '<b>Visibly Separate Items on Pages</b><br />'.
1501: '("<tt>yes</tt>" for visible separation, '.
1502: 'changes will not show until next login)',
1503:
1504: 'plc.roles.denied'=> '<b>Disallow live chatroom use for '.
1505: 'Roles</b><br />"<tt>st</tt>": '.
1506: 'student, "<tt>ta</tt>": '.
1507: 'TA, "<tt>in</tt>": '.
1508: 'instructor;<br /><tt>role,role,...</tt>) '.
1509: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
1510: 'plc.users.denied' =>
1511: '<b>Disallow live chatroom use for Users</b><br />'.
1512: '(<tt>user:domain,user:domain,...</tt>)',
1513:
1514: 'pch.roles.denied'=> '<b>Disallow Resource Discussion for '.
1515: 'Roles</b><br />"<tt>st</tt>": '.
1516: 'student, "<tt>ta</tt>": '.
1517: 'TA, "<tt>in</tt>": '.
1518: 'instructor;<br /><tt>role,role,...</tt>) '.
1519: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
1520: 'pch.users.denied' =>
1521: '<b>Disallow Resource Discussion for Users</b><br />'.
1522: '(<tt>user:domain,user:domain,...</tt>)',
1523: 'spreadsheet_default_classcalc'
1524: => '<b>Default Course Spreadsheet</b> '.
1525: '<a href="javascript:openbrowser'.
1526: "('envform','spreadsheet_default_classcalc'".
1527: ",'spreadsheet')\">Select Spreadsheet File</a><br />",
1528: 'spreadsheet_default_studentcalc'
1529: => '<b>Default Student Spreadsheet</b> '.
1530: '<a href="javascript:openbrowser'.
1531: "('envform','spreadsheet_default_calc'".
1532: ",'spreadsheet')\">Select Spreadsheet File</a><br />",
1533: 'spreadsheet_default_assesscalc'
1534: => '<b>Default Assessment Spreadsheet</b> '.
1535: '<a href="javascript:openbrowser'.
1536: "('envform','spreadsheet_default_assesscalc'".
1537: ",'spreadsheet')\">Select Spreadsheet File</a><br />",
1538: 'allow_limited_html_in_feedback'
1539: => '<b>Allow limited HTML in discussion posts</b><br />'.
1540: '(Set value to "<tt>yes</tt>" to allow)',
1541: 'rndseed'
1542: => '<b>Randomization algorithm used</b> <br />'.
1543: '<font color="red">Modifying this will make problems '.
1544: 'have different numbers and answers</font>',
1545: 'problem_stream_switch'
1546: => '<b>Allow problems to be split over pages</b><br />'.
1547: ' ("<tt>yes</tt>" if allowed, anything else if not)',
1548: 'anonymous_quiz'
1549: => '<b>Anonimous quiz/exam</b><br />'.
1550: ' (<tt><b>yes</b> to avoid print students names </tt>)',
1551: 'default_enrollment_start_date' => '<b>Default beginning date '.
1552: 'when enrolling students</b>',
1553: 'default_enrollment_end_date' => '<b>Default ending date '.
1554: 'when enrolling students</b>',
1555: 'languages' => '<b>Languages used</b>',
1556: 'disable_receipt_display'
1557: => '<b>Disable display of problem receipts</b><br />'.
1558: ' ("<tt>yes</tt>" to disable, anything else if not)'
1559: );
1560: my @Display_Order = ('url','description','courseid','grading',
1561: 'default_xml_style','pageseparators',
1562: 'question.email','comment.email','policy.email',
1563: 'plc.roles.denied','plc.users.denied',
1564: 'pch.roles.denied','pch.users.denied',
1565: 'allow_limited_html_in_feedback',
1566: 'languages',
1567: 'rndseed',
1568: 'problem_stream_switch',
1569: 'disable_receipt_display',
1570: 'spreadsheet_default_classcalc',
1571: 'spreadsheet_default_studentcalc',
1572: 'spreadsheet_default_assesscalc',
1573: 'hideemptyrows',
1574: 'default_enrollment_start_date',
1575: 'default_enrollment_end_date',
1576: );
1577: foreach my $parameter (sort(keys(%values))) {
1578: if (! $descriptions{$parameter}) {
1579: $descriptions{$parameter}=$parameter;
1580: push(@Display_Order,$parameter);
1581: }
1582: }
1583: foreach my $parameter (@Display_Order) {
1584: my $description = $descriptions{$parameter};
1585: # onchange is javascript to automatically check the 'Set' button.
1586: my $onchange = 'onFocus="javascript:window.document.forms'.
1587: "['envform'].elements['".$parameter."_setparmval']".
1588: '.checked=true;"';
1589: $output .= '<tr><td>'.$description.'</td>';
1590: if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
1591: $output .= '<td>'.
1592: &Apache::lonhtmlcommon::date_setter('envform',
1593: $parameter.'_value',
1594: $values{$parameter},
1595: $onchange).
1596: '</td>';
1597: } else {
1598: $output .= '<td>'.
1599: &Apache::lonhtmlcommon::textbox($parameter.'_value',
1600: $values{$parameter},
1601: 40,$onchange).'</td>';
1602: }
1603: $output .= '<td>'.
1604: &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
1605: '</td>';
1606: $output .= "</tr>\n";
1607: }
1608: my $onchange = 'onFocus="javascript:window.document.forms'.
1609: '[\'envform\'].elements[\'newp_setparmval\']'.
1610: '.checked=true;"';
1611: $output.='<tr><td><i>Create New Environment Variable</i><br />'.
1612: '<input type="text" size=40 name="newp_name" '.
1613: $onchange.' /></td><td>'.
1614: '<input type="text" size=40 name="newp_value" '.
1615: $onchange.' /></td><td>'.
1616: '<input type="checkbox" name="newp_setparmval" /></td></tr>';
1617: }
1618: $r->print(<<ENDENV);
1619: <html>
1620: <script type="text/javascript" language="Javascript" >
1621: var editbrowser;
1622: function openbrowser(formname,elementname,only,omit) {
1623: var url = '/res/?';
1624: if (editbrowser == null) {
1625: url += 'launch=1&';
1626: }
1627: url += 'catalogmode=interactive&';
1628: url += 'mode=parmset&';
1629: url += 'form=' + formname + '&';
1630: if (only != null) {
1631: url += 'only=' + only + '&';
1632: }
1633: if (omit != null) {
1634: url += 'omit=' + omit + '&';
1635: }
1636: url += 'element=' + elementname + '';
1637: var title = 'Browser';
1638: var options = 'scrollbars=1,resizable=1,menubar=0';
1639: options += ',width=700,height=600';
1640: editbrowser = open(url,title,options,'1');
1641: editbrowser.focus();
1642: }
1643: </script>
1644: <head>
1645: <title>LON-CAPA Course Environment</title>
1646: </head>
1647: $bodytag
1648: <form method="post" action="/adm/parmset" name="envform">
1649: $setoutput
1650: <p>
1651: <table border=2>
1652: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
1653: $output
1654: </table>
1655: <input type="submit" name="crsenv" value="Set Course Environment">
1656: </form>
1657: </body>
1658: </html>
1659: ENDENV
1660: }
1661:
1662: ##################################################
1663: ##################################################
1664:
1665: =pod
1666:
1667: =item * handler
1668:
1669: Main handler. Calls &assessparms and &crsenv subroutines.
1670:
1671: =cut
1672:
1673: ##################################################
1674: ##################################################
1675: use Data::Dumper;
1676: sub handler {
1677: my $r=shift;
1678:
1679: if ($r->header_only) {
1680: $r->content_type('text/html');
1681: $r->send_http_header;
1682: return OK;
1683: }
1684: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1685:
1686: # ----------------------------------------------------- Needs to be in a course
1687:
1688: if (($ENV{'request.course.id'}) &&
1689: (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
1690:
1691: $r->content_type('text/html');
1692: $r->send_http_header;
1693:
1694: $coursename=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1695:
1696: unless (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) {
1697: # --------------------------------------------------------- Bring up assessment
1698: &assessparms($r);
1699: # ---------------------------------------------- This is for course environment
1700: } else {
1701: &crsenv($r);
1702: }
1703: } else {
1704: # ----------------------------- Not in a course, or not allowed to modify parms
1705: $ENV{'user.error.msg'}=
1706: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
1707: return HTTP_NOT_ACCEPTABLE;
1708: }
1709: return OK;
1710: }
1711:
1712: 1;
1713: __END__
1714:
1715: =pod
1716:
1717: =back
1718:
1719: =cut
1720:
1721:
1722:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>