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