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