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