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