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