Annotation of loncom/interface/lonparmset.pm, revision 1.87
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
1.87 ! www 4: # $Id: lonparmset.pm,v 1.86 2003/04/04 20:38:36 bowersj2 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.82 www 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.82 www 101: 8 - Map or Folder level in course
1.71 albertel 102: 7 - resource level in course
103: 6 - General for section
1.82 www 104: 5 - Map or Folder level for section
1.71 albertel 105: 4 - resource level in section
106: 3 - General for specific student
1.82 www 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)=@_;
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;
1.82 www 552: my $maptitles=shift;
1.63 bowersj2 553:
554: foreach (keys %$bighash) {
555: if ($_=~/^src\_(\d+)\.(\d+)$/) {
556: my $mapid=$1;
557: my $resid=$2;
558: my $id=$mapid.'.'.$resid;
559: my $srcf=$$bighash{$_};
560: if ($srcf=~/\.(problem|exam|quiz|assess|survey|form)$/) {
561: $$ids[$#$ids+1]=$id;
562: $$typep{$id}=$1;
563: $$keyp{$id}='';
1.65 albertel 564: foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
1.63 bowersj2 565: if ($_=~/^parameter\_(.*)/) {
566: my $key=$_;
567: my $allkey=$1;
568: $allkey=~s/\_/\./g;
569: my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
570: my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
571: my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
572: my $parmdis = $display;
573: $parmdis =~ s|(\[Part.*$)||g;
574: my $partkey = $part;
575: $partkey =~ tr|_|.|;
576: $$allparms{$name} = $parmdis;
577: $$allparts{$part} = "[Part $part]";
578: $$allkeys{$allkey}=$display;
579: if ($allkey eq $fcat) {
580: $$defp{$id}= &Apache::lonnet::metadata($srcf,$key);
581: }
582: if ($$keyp{$id}) {
583: $$keyp{$id}.=','.$key;
584: } else {
585: $$keyp{$id}=$key;
586: }
587: }
588: }
589: $$mapp{$id}=
590: &Apache::lonnet::declutter($$bighash{'map_id_'.$mapid});
591: $$mapp{$mapid}=$$mapp{$id};
592: $$allmaps{$mapid}=$$mapp{$id};
1.82 www 593: $$maptitles{$mapid}=
594: $$bighash{'title_'.$$bighash{'ids_'.&Apache::lonnet::clutter($$mapp{$id})}};
595: $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
1.63 bowersj2 596: $$symbp{$id}=$$mapp{$id}.
597: '___'.$resid.'___'.
598: &Apache::lonnet::declutter($srcf);
599: $$symbp{$mapid}=$$mapp{$id}.'___(all)';
600: }
601: }
602: }
603: }
604:
1.59 matthew 605: ##################################################
606: ##################################################
607:
608: =pod
609:
610: =item assessparms
611:
612: Show assessment data and parameters. This is a large routine that should
613: be simplified and shortened... someday.
614:
615: Inputs: $r
616:
617: Returns: nothing
618:
1.63 bowersj2 619: Variables used (guessed by Jeremy):
620:
621: =over 4
622:
623: =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.
624:
625: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
626:
627: =item B<allmaps>:
628:
629: =back
630:
1.59 matthew 631: =cut
632:
633: ##################################################
634: ##################################################
1.30 www 635: sub assessparms {
1.1 www 636:
1.43 albertel 637: my $r=shift;
1.2 www 638: # -------------------------------------------------------- Variable declaration
1.43 albertel 639: my %allkeys;
640: my %allmaps;
1.57 albertel 641: my %alllevs;
642:
643: $alllevs{'Resource Level'}='full';
644: # $alllevs{'Resource Level [BRIEF]'}='brief';
645: $alllevs{'Map Level'}='map';
646: $alllevs{'Course Level'}='general';
647:
648: my %allparms;
649: my %allparts;
650:
1.43 albertel 651: my %defp;
652: %courseopt=();
653: %useropt=();
1.44 albertel 654: my %bighash=();
1.43 albertel 655:
656: @ids=();
657: %symbp=();
658: %typep=();
659:
660: my $message='';
661:
662: $csec=$ENV{'form.csec'};
663: $udom=$ENV{'form.udom'};
664: unless ($udom) { $udom=$r->dir_config('lonDefDomain'); }
665:
1.57 albertel 666: my @pscat=&get_env_multiple('form.pscat');
1.43 albertel 667: my $pschp=$ENV{'form.pschp'};
1.57 albertel 668: my @psprt=&get_env_multiple('form.psprt');
1.76 www 669: if (!@psprt) { $psprt[0]='0'; }
1.57 albertel 670: my $showoptions=$ENV{'form.showoptions'};
671:
1.43 albertel 672: my $pssymb='';
1.57 albertel 673: my $parmlev='';
674: my $prevvisit=$ENV{'form.prevvisit'};
675:
676: # unless ($parmlev==$ENV{'form.parmlev'}) {
677: # $parmlev = 'full';
678: # }
679:
680: unless ($ENV{'form.parmlev'}) {
681: $parmlev = 'map';
682: } else {
683: $parmlev = $ENV{'form.parmlev'};
684: }
1.26 www 685:
1.29 www 686: # ----------------------------------------------- Was this started from grades?
687:
1.43 albertel 688: if (($ENV{'form.command'} eq 'set') && ($ENV{'form.url'})
689: && (!$ENV{'form.dis'})) {
690: my $url=$ENV{'form.url'};
691: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
692: $pssymb=&Apache::lonnet::symbread($url);
1.57 albertel 693: @pscat='all';
1.43 albertel 694: $pschp='';
1.57 albertel 695: $parmlev = 'full';
1.43 albertel 696: } elsif ($ENV{'form.symb'}) {
697: $pssymb=$ENV{'form.symb'};
1.57 albertel 698: @pscat='all';
1.43 albertel 699: $pschp='';
1.57 albertel 700: $parmlev = 'full';
1.43 albertel 701: } else {
702: $ENV{'form.url'}='';
703: }
704:
705: my $id=$ENV{'form.id'};
706: if (($id) && ($udom)) {
707: $uname=(&Apache::lonnet::idget($udom,$id))[1];
708: if ($uname) {
709: $id='';
710: } else {
711: $message=
712: "<font color=red>Unknown ID '$id' at domain '$udom'</font>";
713: }
714: } else {
715: $uname=$ENV{'form.uname'};
716: }
717: unless ($udom) { $uname=''; }
718: $uhome='';
719: if ($uname) {
720: $uhome=&Apache::lonnet::homeserver($uname,$udom);
721: if ($uhome eq 'no_host') {
722: $message=
723: "<font color=red>Unknown user '$uname' at domain '$udom'</font>";
724: $uname='';
1.12 www 725: } else {
1.43 albertel 726: $csec=&Apache::lonnet::usection($udom,$uname,
727: $ENV{'request.course.id'});
728: if ($csec eq '-1') {
729: $message="<font color=red>".
1.45 matthew 730: "User '$uname' at domain '$udom' not ".
731: "in this course</font>";
1.43 albertel 732: $uname='';
733: $csec=$ENV{'form.csec'};
734: } else {
735: my %name=&Apache::lonnet::userenvironment($udom,$uname,
736: ('firstname','middlename','lastname','generation','id'));
737: $message="\n<p>\nFull Name: ".
738: $name{'firstname'}.' '.$name{'middlename'}.' '
739: .$name{'lastname'}.' '.$name{'generation'}.
740: "<br>\nID: ".$name{'id'}.'<p>';
741: }
1.12 www 742: }
1.43 albertel 743: }
1.2 www 744:
1.43 albertel 745: unless ($csec) { $csec=''; }
1.12 www 746:
1.44 albertel 747: my $fcat=$ENV{'form.fcat'};
1.43 albertel 748: unless ($fcat) { $fcat=''; }
1.2 www 749:
750: # ------------------------------------------------------------------- Tie hashs
1.44 albertel 751: if (!(tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
1.58 albertel 752: &GDBM_READER(),0640))) {
1.44 albertel 753: $r->print("Unable to access course data. (File $ENV{'request.course.fn'}.db not tieable)");
754: return ;
755: }
756: if (!(tie(%parmhash,'GDBM_File',
1.58 albertel 757: $ENV{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640))) {
1.44 albertel 758: $r->print("Unable to access parameter data. (File $ENV{'request.course.fn'}_parms.db not tieable)");
759: return ;
760: }
1.63 bowersj2 761:
1.14 www 762: # --------------------------------------------------------- Get all assessments
1.82 www 763: extractResourceInformation(\%bighash, \@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allkeys, \%allmaps, $fcat, \%defp, \%mapp, \%symbp,\%maptitles);
1.63 bowersj2 764:
1.57 albertel 765: $mapp{'0.0'} = '';
766: $symbp{'0.0'} = '';
1.14 www 767: # ---------------------------------------------------------- Anything to store?
1.44 albertel 768: if ($ENV{'form.pres_marker'}) {
769: my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
770: $spnam=~s/\_([^\_]+)$/\.$1/;
1.15 www 771: # ---------------------------------------------------------- Construct prefixes
1.14 www 772:
1.44 albertel 773: my $symbparm=$symbp{$sresid}.'.'.$spnam;
774: my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
775:
776: my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$spnam;
777: my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
778: my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
779:
780: my $courselevel=$ENV{'request.course.id'}.'.'.$spnam;
781: my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
782: my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
783:
784: my $storeunder='';
785: if (($snum==9) || ($snum==3)) { $storeunder=$courselevel; }
786: if (($snum==8) || ($snum==2)) { $storeunder=$courselevelm; }
787: if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
788: if ($snum==6) { $storeunder=$seclevel; }
789: if ($snum==5) { $storeunder=$seclevelm; }
790: if ($snum==4) { $storeunder=$seclevelr; }
791:
1.79 albertel 792: my $delete;
793: if ($ENV{'form.pres_value'} eq '') { $delete=1;}
1.66 www 794: my %storecontent = ($storeunder => $ENV{'form.pres_value'},
795: $storeunder.'.type' => $ENV{'form.pres_type'});
1.44 albertel 796: my $reply='';
797: if ($snum>3) {
1.14 www 798: # ---------------------------------------------------------------- Store Course
1.24 www 799: #
800: # Expire sheets
1.44 albertel 801: &Apache::lonnet::expirespread('','','studentcalc');
802: if (($snum==7) || ($snum==4)) {
803: &Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
804: } elsif (($snum==8) || ($snum==5)) {
805: &Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
806: } else {
807: &Apache::lonnet::expirespread('','','assesscalc');
808: }
1.24 www 809: # Store parameter
1.79 albertel 810: if ($delete) {
811: $reply=&Apache::lonnet::del
812: ('resourcedata',[keys(%storecontent)],
813: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
814: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
815: } else {
816: $reply=&Apache::lonnet::cput
817: ('resourcedata',\%storecontent,
818: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
819: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
820: }
1.44 albertel 821: } else {
1.14 www 822: # ------------------------------------------------------------------ Store User
1.24 www 823: #
824: # Expire sheets
1.44 albertel 825: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
826: if ($snum==1) {
827: &Apache::lonnet::expirespread
828: ($uname,$udom,'assesscalc',$symbp{$sresid});
829: } elsif ($snum==2) {
830: &Apache::lonnet::expirespread
831: ($uname,$udom,'assesscalc',$mapp{$sresid});
832: } else {
833: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
834: }
1.24 www 835: # Store parameter
1.79 albertel 836: if ($delete) {
837: $reply=&Apache::lonnet::del
838: ('resourcedata',[keys(%storecontent)],$udom,$uname);
839: } else {
840: $reply=&Apache::lonnet::cput
841: ('resourcedata',\%storecontent,$udom,$uname);
842: }
1.44 albertel 843: }
1.15 www 844:
1.44 albertel 845: if ($reply=~/^error\:(.*)/) {
846: $message.="<font color=red>Write Error: $1</font>";
847: }
1.68 www 848: # ---------------------------------------------------------------- Done storing
1.80 www 849: $message.='<h3>Changes can take up to 10 minutes before being active for all students</h3>';
1.68 www 850: }
1.67 www 851: # --------------------------------------------- Devalidate cache for this child
852: &Apache::lonnet::devalidatecourseresdata(
853: $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
854: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'});
1.2 www 855: # -------------------------------------------------------------- Get coursedata
1.45 matthew 856: %courseopt = &Apache::lonnet::dump
857: ('resourcedata',
858: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
859: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.44 albertel 860: # --------------------------------------------------- Get userdata (if present)
861: if ($uname) {
1.45 matthew 862: %useropt=&Apache::lonnet::dump('resourcedata',$udom,$uname);
1.44 albertel 863: }
1.14 www 864:
1.2 www 865: # ------------------------------------------------------------------- Sort this
1.17 www 866:
1.44 albertel 867: @ids=sort {
868: if ($fcat eq '') {
869: $a<=>$b;
870: } else {
871: my ($result,@outpar)=&parmval($fcat,$a,$defp{$a});
872: my $aparm=$outpar[$result];
873: ($result,@outpar)=&parmval($fcat,$b,$defp{$b});
874: my $bparm=$outpar[$result];
875: 1*$aparm<=>1*$bparm;
876: }
877: } @ids;
1.57 albertel 878: #----------------------------------------------- if all selected, fill in array
879: if ($pscat[0] eq "all" || !@pscat) {@pscat = (keys %allparms);}
880: if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
1.2 www 881: # ------------------------------------------------------------------ Start page
1.63 bowersj2 882:
1.44 albertel 883: &startpage($r,$id,$udom,$csec,$uname);
884: # if ($ENV{'form.url'}) {
885: # $r->print('<input type="hidden" value="'.$ENV{'form.url'}.
886: # '" name="url"><input type="hidden" name="command" value="set">');
887: # }
1.57 albertel 888: $r->print('<input type="hidden" value="true" name="prevvisit">');
889:
1.44 albertel 890: foreach ('tolerance','date_default','date_start','date_end',
891: 'date_interval','int','float','string') {
892: $r->print('<input type="hidden" value="'.
893: $ENV{'form.recent_'.$_}.'" name="recent_'.$_.'">');
894: }
895:
1.57 albertel 896: $r->print('<h2>'.$message.'</h2><table>');
897:
898: $r->print('<tr><td><hr /></td></tr>');
899:
900: my $submitmessage;
901: if (($prevvisit) || ($pschp) || ($pssymb)) {
902: $submitmessage = "Update Display";
903: } else {
904: $submitmessage = "Display";
1.13 www 905: }
1.44 albertel 906: if (!$pssymb) {
1.57 albertel 907: $r->print('<tr><td>Select Parameter Level</td><td>');
908: $r->print('<select name="parmlev">');
909: foreach (reverse sort keys %alllevs) {
910: $r->print('<option value="'.$alllevs{$_}.'"');
911: if ($parmlev eq $alllevs{$_}) {
912: $r->print(' selected');
913: }
914: $r->print('>'.$_.'</option>');
915: }
916: $r->print("</select></td>\n");
917:
918: $r->print('<td><input type="submit" name="dis" value="'.$submitmessage.'"></td>');
919:
920: $r->print('</tr><tr><td><hr /></td>');
921:
1.82 www 922: $r->print('<tr><td>Select Enclosing Map or Folder</td>');
1.57 albertel 923: $r->print('<td colspan="2"><select name="pschp">');
1.82 www 924: $r->print('<option value="all">All Maps or Folders</option>');
1.57 albertel 925: foreach (sort {$allmaps{$a} cmp $allmaps{$b}} keys %allmaps) {
926: $r->print('<option value="'.$_.'"');
927: if (($pschp eq $_)) { $r->print(' selected'); }
1.82 www 928: $r->print('>'.$maptitles{$_}.($allmaps{$_}!~/^uploaded/?' ['.$allmaps{$_}.']':'').'</option>');
1.57 albertel 929: }
930: $r->print("</select></td></tr>\n");
1.44 albertel 931: } else {
1.57 albertel 932: my ($map,$id,$resource)=split(/___/,$pssymb);
933: $r->print("<tr><td>Specific Resource</td><td>$resource</td>");
934: $r->print('<td><input type="submit" name="dis" value="'.$submitmessage.'"></td>');
935: $r->print('</tr>');
936: $r->print('<input type="hidden" value="'.$pssymb.'" name="symb">');
937: }
938:
939: $r->print('<tr><td colspan="3"><hr /><input type="checkbox"');
940: if ($showoptions eq 'show') {$r->print(" checked ");}
941: $r->print(' name="showoptions" value="show" onclick="form.submit();">Show More Options<hr /></td></tr>');
942: # $r->print("<tr><td>Show: $showoptions</td></tr>");
943: # $r->print("<tr><td>pscat: @pscat</td></tr>");
944: # $r->print("<tr><td>psprt: @psprt</td></tr>");
945: # $r->print("<tr><td>fcat: $fcat</td></tr>");
946:
947: if ($showoptions eq 'show') {
948: my $tempkey;
949:
950: $r->print('<tr><td colspan="3" align="center">Select Parameters to View</td></tr>');
951:
952: $r->print('<tr><td colspan="2"><table>');
953: $r->print('<tr><td><input type="checkbox" name="pscat" value="all"');
954: $r->print(' checked') unless (@pscat);
955: $r->print('>All Parameters</td>');
956:
957: my $cnt=0;
958: foreach $tempkey (sort { $allparms{$a} cmp $allparms{$b} }
959: keys %allparms ) {
960: ++$cnt;
961: $r->print('</tr><tr>') unless ($cnt%2);
962: $r->print('<td><input type="checkbox" name="pscat" ');
963: $r->print('value="'.$tempkey.'"');
964: if ($pscat[0] eq "all" || grep $_ eq $tempkey, @pscat) {
965: $r->print(' checked');
966: }
967: $r->print('>'.$allparms{$tempkey}.'</td>');
968: }
969: $r->print('</tr></table>');
970:
971: # $r->print('<tr><td>Select Parts</td><td>');
972: $r->print('<td><select multiple name="psprt" size="5">');
973: $r->print('<option value="all"');
974: $r->print(' selected') unless (@psprt);
975: $r->print('>All Parts</option>');
1.76 www 976: my %temphash=();
977: foreach (@psprt) { $temphash{$_}=1; }
1.57 albertel 978: foreach $tempkey (sort keys %allparts) {
979: unless ($tempkey =~ /\./) {
980: $r->print('<option value="'.$tempkey.'"');
1.76 www 981: if ($psprt[0] eq "all" || $temphash{$tempkey}) {
1.57 albertel 982: $r->print(' selected');
983: }
984: $r->print('>'.$allparts{$tempkey}.'</option>');
985: }
986: }
987: $r->print('</select></td></tr><tr><td colspan="3"><hr /></td></tr>');
988:
989: $r->print('<tr><td>Sort list by</td><td>');
990: $r->print('<select name="fcat">');
1.82 www 991: $r->print('<option value="">Enclosing Map or Folder</option>');
1.57 albertel 992: foreach (sort keys %allkeys) {
993: $r->print('<option value="'.$_.'"');
994: if ($fcat eq $_) { $r->print(' selected'); }
995: $r->print('>'.$allkeys{$_}.'</option>');
996: }
997: $r->print('</select></td>');
998:
999: $r->print('</tr><tr><td colspan="3"><hr /></td></tr>');
1000:
1001: } else { # hide options - include any necessary extras here
1002:
1003: $r->print('<input type="hidden" name="fcat" value="'.$fcat.'">'."\n");
1004:
1005: unless (@pscat) {
1006: foreach (keys %allparms ) {
1007: $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
1008: }
1009: } else {
1010: foreach (@pscat) {
1011: $r->print('<input type="hidden" name="pscat" value="'.$_.'">'."\n");
1012: }
1013: }
1014:
1015: unless (@psprt) {
1016: foreach (keys %allparts ) {
1017: $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
1018: }
1019: } else {
1020: foreach (@psprt) {
1021: $r->print('<input type="hidden" name="psprt" value="'.$_.'">'."\n");
1022: }
1023: }
1024:
1.44 albertel 1025: }
1.57 albertel 1026: $r->print('</table>');
1027:
1.76 www 1028: # my @temp_psprt;
1029: # foreach my $t (@psprt) {
1030: # push(@temp_psprt, grep {eval (/^$t\./ || ($_ == $t))} (keys %allparts));
1031: # }
1.57 albertel 1032:
1.76 www 1033: # @psprt = @temp_psprt;
1.57 albertel 1034:
1035: my @temp_pscat;
1036: map {
1037: my $cat = $_;
1038: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
1039: } @pscat;
1040:
1041: @pscat = @temp_pscat;
1042:
1043: if (($prevvisit) || ($pschp) || ($pssymb)) {
1.10 www 1044: # ----------------------------------------------------------------- Start Table
1.57 albertel 1045: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
1046: my $csuname=$ENV{'user.name'};
1047: my $csudom=$ENV{'user.domain'};
1048:
1049:
1050: if ($parmlev eq 'full' || $parmlev eq 'brief') {
1051:
1052: my $coursespan=$csec?8:5;
1053: $r->print('<p><table border=2>');
1054: $r->print('<tr><td colspan=5></td>');
1055: $r->print('<th colspan='.($coursespan).'>Any User</th>');
1056: if ($uname) {
1057: $r->print("<th colspan=3 rowspan=2>");
1058: $r->print("User $uname at Domain $udom</th>");
1059: }
1060: $r->print(<<ENDTABLETWO);
1.33 www 1061: <th rowspan=3>Parameter in Effect</th>
1062: <th rowspan=3>Current Session Value<br>($csuname at $csudom)</th>
1.57 albertel 1063: </tr><tr><td colspan=5></td><th colspan=2>Resource Level</th>
1.10 www 1064: <th colspan=3>in Course</th>
1065: ENDTABLETWO
1.57 albertel 1066: if ($csec) {
1067: $r->print("<th colspan=3>in Section/Group $csec</th>");
1068: }
1069: $r->print(<<ENDTABLEHEADFOUR);
1.11 www 1070: </tr><tr><th>Assessment URL and Title</th><th>Type</th>
1.82 www 1071: <th>Enclosing Map or Folder</th><th>Part No.</th><th>Parameter Name</th>
1072: <th>default</th><th>from Enclosing Map or Folder</th>
1073: <th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>
1.10 www 1074: ENDTABLEHEADFOUR
1.57 albertel 1075:
1076: if ($csec) {
1.82 www 1077: $r->print('<th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>');
1.57 albertel 1078: }
1079:
1080: if ($uname) {
1.82 www 1081: $r->print('<th>general</th><th>for Enclosing Map or Folder</th><th>for Resource</th>');
1.57 albertel 1082: }
1083:
1084: $r->print('</tr>');
1085:
1086: my $defbgone='';
1087: my $defbgtwo='';
1088:
1089: foreach (@ids) {
1090:
1091: my $rid=$_;
1092: my ($inmapid)=($rid=~/\.(\d+)$/);
1093:
1094: if (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid}) ||
1095: ($pssymb eq $symbp{$rid})) {
1.4 www 1096: # ------------------------------------------------------ Entry for one resource
1.57 albertel 1097: if ($defbgone eq '"E0E099"') {
1098: $defbgone='"E0E0DD"';
1099: } else {
1100: $defbgone='"E0E099"';
1101: }
1102: if ($defbgtwo eq '"FFFF99"') {
1103: $defbgtwo='"FFFFDD"';
1104: } else {
1105: $defbgtwo='"FFFF99"';
1106: }
1107: my $thistitle='';
1108: my %name= ();
1109: undef %name;
1110: my %part= ();
1111: my %display=();
1112: my %type= ();
1113: my %default=();
1114: my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
1115:
1116: foreach (split(/\,/,$keyp{$rid})) {
1117: my $tempkeyp = $_;
1118: if (grep $_ eq $tempkeyp, @catmarker) {
1119: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
1120: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
1121: $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
1122: unless ($display{$_}) { $display{$_}=''; }
1123: $display{$_}.=' ('.$name{$_}.')';
1124: $default{$_}=&Apache::lonnet::metadata($uri,$_);
1125: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
1126: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
1127: }
1128: }
1129: my $totalparms=scalar keys %name;
1130: if ($totalparms>0) {
1131: my $firstrow=1;
1132:
1133: $r->print('<tr><td bgcolor='.$defbgone.
1134: ' rowspan='.$totalparms.
1135: '><tt><font size=-1>'.
1136: join(' / ',split(/\//,$uri)).
1137: '</font></tt><p><b>'.
1138: "<a href=\"javascript:openWindow('/res/".$uri.
1139: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
1140: " TARGET=_self>$bighash{'title_'.$rid}");
1141:
1142: if ($thistitle) {
1143: $r->print(' ('.$thistitle.')');
1144: }
1145: $r->print('</a></b></td>');
1146: $r->print('<td bgcolor='.$defbgtwo.
1147: ' rowspan='.$totalparms.'>'.$typep{$rid}.
1148: '</td>');
1149:
1150: $r->print('<td bgcolor='.$defbgone.
1151: ' rowspan='.$totalparms.
1152: '><tt><font size=-1>');
1153:
1154: $r->print(' / res / ');
1155: $r->print(join(' / ', split(/\//,$mapp{$rid})));
1156:
1157: $r->print('</font></tt></td>');
1158:
1159: foreach (sort keys %name) {
1160: unless ($firstrow) {
1161: $r->print('<tr>');
1162: } else {
1163: undef $firstrow;
1164: }
1165:
1166: &print_row($r,$_,\%part,\%name,$rid,\%default,
1167: \%type,\%display,$defbgone,$defbgtwo,
1168: $parmlev);
1169: }
1170: }
1171: }
1172: } # end foreach ids
1.43 albertel 1173: # -------------------------------------------------- End entry for one resource
1.57 albertel 1174: $r->print('</table>');
1175: } # end of brief/full
1176: #--------------------------------------------------- Entry for parm level map
1177: if ($parmlev eq 'map') {
1178: my $defbgone = '"E0E099"';
1179: my $defbgtwo = '"FFFF99"';
1180:
1181: my %maplist;
1182:
1183: if ($pschp eq 'all') {
1184: %maplist = %allmaps;
1185: } else {
1186: %maplist = ($pschp => $mapp{$pschp});
1187: }
1188:
1189: #-------------------------------------------- for each map, gather information
1190: my $mapid;
1.60 albertel 1191: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
1192: my $maptitle = $maplist{$mapid};
1.57 albertel 1193:
1194: #----------------------- loop through ids and get all parameter types for map
1195: #----------------------------------------- and associated information
1196: my %name = ();
1197: my %part = ();
1198: my %display = ();
1199: my %type = ();
1200: my %default = ();
1201: my $map = 0;
1202:
1203: # $r->print("Catmarker: @catmarker<br />\n");
1204:
1205: foreach (@ids) {
1206: ($map)=(/([\d]*?)\./);
1207: my $rid = $_;
1208:
1209: # $r->print("$mapid:$map: $rid <br /> \n");
1210:
1211: if ($map eq $mapid) {
1212: my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
1213: # $r->print("Keys: $keyp{$rid} <br />\n");
1214:
1215: #--------------------------------------------------------------------
1216: # @catmarker contains list of all possible parameters including part #s
1217: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1218: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1219: # When storing information, store as part 0
1220: # When requesting information, request from full part
1221: #-------------------------------------------------------------------
1222: foreach (split(/\,/,$keyp{$rid})) {
1223: my $tempkeyp = $_;
1224: my $fullkeyp = $tempkeyp;
1.73 albertel 1225: $tempkeyp =~ s/_\w+_/_0_/;
1.57 albertel 1226:
1227: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1228: $part{$tempkeyp}="0";
1229: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1230: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1231: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1232: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1.73 albertel 1233: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1.57 albertel 1234: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1235: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1236: }
1237: } # end loop through keys
1238: }
1239: } # end loop through ids
1240:
1241: #---------------------------------------------------- print header information
1.82 www 1242: my $foldermap=($maptitle=~/^uploaded/?'Folder':'Map');
1243: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
1.57 albertel 1244: $r->print(<<ENDMAPONE);
1245: <center><h4>
1.82 www 1246: <font color="red">Set Defaults for All Resources in $foldermap<br />
1247: <i>$showtitle</i><br />
1.57 albertel 1248: Specifically for
1249: ENDMAPONE
1250: if ($uname) {
1251: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1252: ('firstname','middlename','lastname','generation', 'id'));
1253: my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
1254: .$name{'lastname'}.' '.$name{'generation'};
1255: $r->print("User <i>$uname \($person\) </i> in \n");
1256: } else {
1257: $r->print("<i>all</i> users in \n");
1258: }
1259:
1260: if ($csec) {$r->print("Section <i>$csec</i> of \n")};
1261:
1262: $r->print("<i>$coursename</i><br />");
1263: $r->print("</font></h4>\n");
1264: #---------------------------------------------------------------- print table
1265: $r->print('<p><table border="2">');
1266: $r->print('<tr><th>Parameter Name</th>');
1267: $r->print('<th>Default Value</th>');
1268: $r->print('<th>Parameter in Effect</th></tr>');
1269:
1270: foreach (sort keys %name) {
1271: &print_row($r,$_,\%part,\%name,$mapid,\%default,
1272: \%type,\%display,$defbgone,$defbgtwo,
1273: $parmlev);
1274: # $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
1275: }
1276: $r->print("</table></center>");
1277: } # end each map
1278: } # end of $parmlev eq map
1279: #--------------------------------- Entry for parm level general (Course level)
1280: if ($parmlev eq 'general') {
1281: my $defbgone = '"E0E099"';
1282: my $defbgtwo = '"FFFF99"';
1283:
1284: #-------------------------------------------- for each map, gather information
1285: my $mapid="0.0";
1286: #----------------------- loop through ids and get all parameter types for map
1287: #----------------------------------------- and associated information
1288: my %name = ();
1289: my %part = ();
1290: my %display = ();
1291: my %type = ();
1292: my %default = ();
1293:
1294: foreach (@ids) {
1295: my $rid = $_;
1296:
1297: my $uri=&Apache::lonnet::declutter($bighash{'src_'.$rid});
1298:
1299: #--------------------------------------------------------------------
1300: # @catmarker contains list of all possible parameters including part #s
1301: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1302: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1303: # When storing information, store as part 0
1304: # When requesting information, request from full part
1305: #-------------------------------------------------------------------
1306: foreach (split(/\,/,$keyp{$rid})) {
1307: my $tempkeyp = $_;
1308: my $fullkeyp = $tempkeyp;
1.73 albertel 1309: $tempkeyp =~ s/_\w+_/_0_/;
1.57 albertel 1310: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1311: $part{$tempkeyp}="0";
1312: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1313: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1314: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1315: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1.73 albertel 1316: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1.57 albertel 1317: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1318: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1319: }
1320: } # end loop through keys
1321: } # end loop through ids
1322:
1323: #---------------------------------------------------- print header information
1324: $r->print(<<ENDMAPONE);
1325: <center><h4>
1326: <font color="red">Set Defaults for All Resources in Course
1327: <i>$coursename</i><br />
1328: ENDMAPONE
1329: if ($uname) {
1330: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1331: ('firstname','middlename','lastname','generation', 'id'));
1332: my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
1333: .$name{'lastname'}.' '.$name{'generation'};
1334: $r->print(" User <i>$uname \($person\) </i> \n");
1335: } else {
1336: $r->print("<i>ALL</i> USERS \n");
1337: }
1338:
1339: if ($csec) {$r->print("Section <i>$csec</i>\n")};
1340: $r->print("</font></h4>\n");
1341: #---------------------------------------------------------------- print table
1342: $r->print('<p><table border="2">');
1343: $r->print('<tr><th>Parameter Name</th>');
1344: $r->print('<th>Default Value</th>');
1345: $r->print('<th>Parameter in Effect</th></tr>');
1346:
1347: foreach (sort keys %name) {
1348: &print_row($r,$_,\%part,\%name,$mapid,\%default,
1349: \%type,\%display,$defbgone,$defbgtwo,$parmlev);
1350: # $r->print("<tr><td>resource.$part{$_}.$name{$_},$symbp{$mapid}</td></tr>\n");
1351: }
1352: $r->print("</table></center>");
1353: } # end of $parmlev eq general
1.43 albertel 1354: }
1.44 albertel 1355: $r->print('</form></body></html>');
1356: untie(%bighash);
1357: untie(%parmhash);
1.57 albertel 1358: } # end sub assessparms
1.30 www 1359:
1.59 matthew 1360:
1361: ##################################################
1362: ##################################################
1363:
1364: =pod
1365:
1366: =item crsenv
1367:
1368: Show course data and parameters. This is a large routine that should
1369: be simplified and shortened... someday.
1370:
1371: Inputs: $r
1372:
1373: Returns: nothing
1374:
1375: =cut
1376:
1377: ##################################################
1378: ##################################################
1.30 www 1379: sub crsenv {
1380: my $r=shift;
1381: my $setoutput='';
1.64 www 1382: my $bodytag=&Apache::loncommon::bodytag(
1383: 'Set Course Environment Parameters');
1.45 matthew 1384: my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1385: my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1.30 www 1386: # -------------------------------------------------- Go through list of changes
1.38 harris41 1387: foreach (keys %ENV) {
1.30 www 1388: if ($_=~/^form\.(.+)\_setparmval$/) {
1389: my $name=$1;
1390: my $value=$ENV{'form.'.$name.'_value'};
1391: if ($name eq 'newp') {
1392: $name=$ENV{'form.newp_name'};
1393: }
1394: if ($name eq 'url') {
1395: $value=~s/^\/res\///;
1.62 www 1396: my $bkuptime=time;
1.45 matthew 1397: my @tmp = &Apache::lonnet::get
1398: ('environment',['url'],$dom,$crs);
1.30 www 1399: $setoutput.='Backing up previous URL: '.
1.45 matthew 1400: &Apache::lonnet::put
1401: ('environment',
1.62 www 1402: {'top level map backup '.$bkuptime => $tmp[1] },
1.45 matthew 1403: $dom,$crs).
1404: '<br>';
1.30 www 1405: }
1.77 matthew 1406: if ($name =~ /^spreadsheet_default_(classcalc|
1407: studentcalc|
1408: assesscalc)$/x) {
1.78 matthew 1409: my $sheettype = $1;
1.77 matthew 1410: if ($sheettype eq 'classcalc') {
1411: # no need to do anything since viewing the sheet will
1.78 matthew 1412: # cause it to be updated.
1.77 matthew 1413: } elsif ($sheettype eq 'studentcalc') {
1414: # expire all the student spreadsheets
1415: &Apache::lonnet::expirespread('','','studentcalc');
1416: } else {
1417: # expire all the default assessment spreadsheets
1418: }
1419: }
1420:
1.30 www 1421: if ($name) {
1.45 matthew 1422: $setoutput.='Setting <tt>'.$name.'</tt> to <tt>'.
1423: $value.'</tt>: '.
1424: &Apache::lonnet::put
1425: ('environment',{$name=>$value},$dom,$crs).
1426: '<br>';
1.30 www 1427: }
1428: }
1.38 harris41 1429: }
1.30 www 1430: # -------------------------------------------------------- Get parameters again
1.45 matthew 1431:
1432: my %values=&Apache::lonnet::dump('environment',$dom,$crs);
1.30 www 1433: my $output='';
1.45 matthew 1434: if (! exists($values{'con_lost'})) {
1.30 www 1435: my %descriptions=
1.47 matthew 1436: ('url' => '<b>Top Level Map</b> '.
1.46 matthew 1437: '<a href="javascript:openbrowser'.
1.47 matthew 1438: "('envform','url','sequence')\">".
1.75 albertel 1439: 'Browse</a><br /><font color=red> '.
1.45 matthew 1440: 'Modification may make assessment data '.
1441: 'inaccessible</font>',
1442: 'description' => '<b>Course Description</b>',
1.75 albertel 1443: 'courseid' => '<b>Course ID or number</b><br />'.
1.45 matthew 1444: '(internal, optional)',
1.52 www 1445: 'default_xml_style' => '<b>Default XML Style File</b> '.
1446: '<a href="javascript:openbrowser'.
1447: "('envform','default_xml_style'".
1448: ",'sty')\">Browse</a><br>",
1.74 www 1449: 'question.email' => '<b>Feedback Addresses for Resource Content '.
1.75 albertel 1450: 'Questions</b><br />(<tt>user:domain,'.
1.74 www 1451: 'user:domain(section;section;...;*;...),...</tt>)',
1.75 albertel 1452: 'comment.email' => '<b>Feedback Addresses for Course Content Comments</b><br />'.
1.74 www 1453: '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1.45 matthew 1454: 'policy.email' => '<b>Feedback Addresses for Course Policy</b>'.
1.75 albertel 1455: '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1456: 'hideemptyrows' => '<b>Hide Empty Rows in Spreadsheets</b><br />'.
1.45 matthew 1457: '("<tt>yes</tt>" for default hiding)',
1.75 albertel 1458: 'pageseparators' => '<b>Visibly Separate Items on Pages</b><br />'.
1.54 www 1459: '("<tt>yes</tt>" for visible separation)',
1.45 matthew 1460: 'pch.roles.denied'=> '<b>Disallow Resource Discussion for '.
1.75 albertel 1461: 'Roles</b><br />"<tt>st</tt>": '.
1.61 albertel 1462: 'student, "<tt>ta</tt>": '.
1463: 'TA, "<tt>in</tt>": '.
1.75 albertel 1464: 'instructor;<br /><tt>role,role,...</tt>) '.
1.61 albertel 1465: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
1.53 www 1466: 'pch.users.denied' =>
1.75 albertel 1467: '<b>Disallow Resource Discussion for Users</b><br />'.
1.53 www 1468: '(<tt>user:domain,user:domain,...</tt>)',
1.49 matthew 1469: 'spreadsheet_default_classcalc'
1.52 www 1470: => '<b>Default Course Spreadsheet</b> '.
1.50 matthew 1471: '<a href="javascript:openbrowser'.
1472: "('envform','spreadsheet_default_classcalc'".
1.75 albertel 1473: ",'spreadsheet')\">Browse</a><br />",
1.49 matthew 1474: 'spreadsheet_default_studentcalc'
1.52 www 1475: => '<b>Default Student Spreadsheet</b> '.
1.50 matthew 1476: '<a href="javascript:openbrowser'.
1477: "('envform','spreadsheet_default_calc'".
1.75 albertel 1478: ",'spreadsheet')\">Browse</a><br />",
1.49 matthew 1479: 'spreadsheet_default_assesscalc'
1.52 www 1480: => '<b>Default Assessment Spreadsheet</b> '.
1.50 matthew 1481: '<a href="javascript:openbrowser'.
1482: "('envform','spreadsheet_default_assesscalc'".
1.75 albertel 1483: ",'spreadsheet')\">Browse</a><br />",
1484: 'allow_limited_html_in_feedback'
1485: => '<b>Allow limited HTML in discussion posts</b><br />'.
1486: '(Set value to yes to allow)'
1.45 matthew 1487: );
1488: foreach (keys(%values)) {
1489: unless ($descriptions{$_}) {
1490: $descriptions{$_}=$_;
1.43 albertel 1491: }
1492: }
1493: foreach (sort keys %descriptions) {
1.51 matthew 1494: # onchange is javascript to automatically check the 'Set' button.
1.69 www 1495: my $onchange = 'onFocus="javascript:window.document.forms'.
1.51 matthew 1496: '[\'envform\'].elements[\''.$_.'_setparmval\']'.
1497: '.checked=true;"';
1498: $output.='<tr><td>'.$descriptions{$_}.'</td>'.
1499: '<td><input name="'.$_.'_value" size=40 '.
1500: 'value="'.$values{$_}.'" '.$onchange.' /></td>'.
1501: '<td><input type=checkbox name="'.$_.'_setparmval"></td>'.
1502: '</tr>'."\n";
1503: }
1.69 www 1504: my $onchange = 'onFocus="javascript:window.document.forms'.
1.51 matthew 1505: '[\'envform\'].elements[\'newp_setparmval\']'.
1506: '.checked=true;"';
1507: $output.='<tr><td><i>Create New Environment Variable</i><br />'.
1508: '<input type="text" size=40 name="newp_name" '.
1509: $onchange.' /></td><td>'.
1510: '<input type="text" size=40 name="newp_value" '.
1511: $onchange.' /></td><td>'.
1512: '<input type="checkbox" name="newp_setparmval" /></td></tr>';
1.43 albertel 1513: }
1.30 www 1514: $r->print(<<ENDENV);
1515: <html>
1.46 matthew 1516: <script type="text/javascript" language="Javascript" >
1517: var editbrowser;
1.47 matthew 1518: function openbrowser(formname,elementname,only,omit) {
1.46 matthew 1519: var url = '/res/?';
1520: if (editbrowser == null) {
1521: url += 'launch=1&';
1522: }
1523: url += 'catalogmode=interactive&';
1524: url += 'mode=parmset&';
1525: url += 'form=' + formname + '&';
1.47 matthew 1526: if (only != null) {
1527: url += 'only=' + only + '&';
1528: }
1529: if (omit != null) {
1530: url += 'omit=' + omit + '&';
1531: }
1.46 matthew 1532: url += 'element=' + elementname + '';
1533: var title = 'Browser';
1534: var options = 'scrollbars=1,resizable=1,menubar=0';
1535: options += ',width=700,height=600';
1536: editbrowser = open(url,title,options,'1');
1537: editbrowser.focus();
1538: }
1539: </script>
1.30 www 1540: <head>
1541: <title>LON-CAPA Course Environment</title>
1542: </head>
1.64 www 1543: $bodytag
1.30 www 1544: <form method="post" action="/adm/parmset" name="envform">
1545: $setoutput
1546: <p>
1547: <table border=2>
1548: <tr><th>Parameter</th><th>Value</th><th>Set?</th></tr>
1549: $output
1550: </table>
1551: <input type="submit" name="crsenv" value="Set Course Environment">
1552: </form>
1553: </body>
1554: </html>
1555: ENDENV
1556: }
1557:
1.59 matthew 1558: ##################################################
1559: ##################################################
1.30 www 1560:
1.59 matthew 1561: =pod
1562:
1.83 bowersj2 1563: =item * handler
1.59 matthew 1564:
1565: Main handler. Calls &assessparms and &crsenv subroutines.
1566:
1567: =cut
1568:
1569: ##################################################
1570: ##################################################
1.85 bowersj2 1571: use Data::Dumper;
1.30 www 1572: sub handler {
1.43 albertel 1573: my $r=shift;
1.30 www 1574:
1.43 albertel 1575: if ($r->header_only) {
1576: $r->content_type('text/html');
1577: $r->send_http_header;
1578: return OK;
1579: }
1580: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.83 bowersj2 1581:
1.85 bowersj2 1582: $r->content_type('text/html');
1583: $r->send_http_header;
1.86 bowersj2 1584:
1.30 www 1585: # ----------------------------------------------------- Needs to be in a course
1586:
1.43 albertel 1587: if (($ENV{'request.course.id'}) &&
1588: (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'}))) {
1.57 albertel 1589:
1590: $coursename=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.30 www 1591:
1.43 albertel 1592: unless (($ENV{'form.crsenv'}) || (!$ENV{'request.course.fn'})) {
1.30 www 1593: # --------------------------------------------------------- Bring up assessment
1.43 albertel 1594: &assessparms($r);
1.30 www 1595: # ---------------------------------------------- This is for course environment
1.43 albertel 1596: } else {
1597: &crsenv($r);
1598: }
1599: } else {
1.1 www 1600: # ----------------------------- Not in a course, or not allowed to modify parms
1.43 albertel 1601: $ENV{'user.error.msg'}=
1602: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
1603: return HTTP_NOT_ACCEPTABLE;
1604: }
1605: return OK;
1.1 www 1606: }
1607:
1608: 1;
1609: __END__
1610:
1.59 matthew 1611: =pod
1.38 harris41 1612:
1613: =back
1614:
1615: =cut
1.1 www 1616:
1617:
1618:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>