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