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