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