Annotation of loncom/interface/lonparmset.pm, revision 1.229
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
1.229 ! www 4: # $Id: lonparmset.pm,v 1.228 2005/06/18 14:39:24 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.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.130 www 64: use Apache::lonlocal;
1.197 www 65: use Apache::lonnavmaps;
1.1 www 66:
1.198 www 67: # --- Caches local to lonparmset
1.2 www 68:
1.199 www 69: my $parmhashid;
70: my %parmhash;
1.201 www 71: my $symbsid;
72: my %symbs;
1.221 www 73: my $rulesid;
74: my %rules;
1.198 www 75:
76: # --- end local caches
77:
1.59 matthew 78: ##################################################
79: ##################################################
80:
81: =pod
82:
83: =item parmval
84:
85: Figure out a cascading parameter.
86:
1.71 albertel 87: Inputs: $what - a parameter spec (incluse part info and name I.E. 0.weight)
1.162 albertel 88: $id - a bighash Id number
1.71 albertel 89: $def - the resource's default value 'stupid emacs
90:
91: 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
92:
1.182 albertel 93: 11 - General Course
94: 10 - Map or Folder level in course
95: 9- resource default
96: 8- map default
1.71 albertel 97: 7 - resource level in course
98: 6 - General for section
1.82 www 99: 5 - Map or Folder level for section
1.71 albertel 100: 4 - resource level in section
101: 3 - General for specific student
1.82 www 102: 2 - Map or Folder level for specific student
1.71 albertel 103: 1 - resource level for specific student
1.2 www 104:
1.59 matthew 105: =cut
106:
107: ##################################################
1.2 www 108: sub parmval {
1.187 www 109: my ($what,$id,$def,$uname,$udom,$csec)=@_;
1.201 www 110: return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec);
111: }
112:
113: sub parmval_by_symb {
114: my ($what,$symb,$def,$uname,$udom,$csec)=@_;
1.198 www 115: # load caches
1.200 www 116:
1.198 www 117: &cacheparmhash();
1.200 www 118:
119: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
120: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
121: my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
122: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
123:
1.198 www 124:
1.8 www 125: my $result='';
1.44 albertel 126: my @outpar=();
1.2 www 127: # ----------------------------------------------------- Cascading lookup scheme
1.201 www 128: my $map=(&Apache::lonnet::decode_symb($symb))[0];
1.10 www 129:
1.201 www 130: my $symbparm=$symb.'.'.$what;
131: my $mapparm=$map.'___(all).'.$what;
1.10 www 132:
1.190 albertel 133: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
134: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
135: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
136:
137: my $courselevel=$env{'request.course.id'}.'.'.$what;
138: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
139: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
1.2 www 140:
1.11 www 141:
142:
1.182 albertel 143: # --------------------------------------------------------- first, check course
1.11 www 144:
1.200 www 145: if (defined($$courseopt{$courselevel})) {
146: $outpar[11]=$$courseopt{$courselevel};
1.182 albertel 147: $result=11;
1.43 albertel 148: }
1.11 www 149:
1.200 www 150: if (defined($$courseopt{$courselevelm})) {
151: $outpar[10]=$$courseopt{$courselevelm};
1.182 albertel 152: $result=10;
1.43 albertel 153: }
1.11 www 154:
1.182 albertel 155: # ------------------------------------------------------- second, check default
156:
157: if (defined($def)) { $outpar[9]=$def; $result=9; }
158:
159: # ------------------------------------------------------ third, check map parms
160:
161: my $thisparm=$parmhash{$symbparm};
162: if (defined($thisparm)) { $outpar[8]=$thisparm; $result=8; }
163:
1.200 www 164: if (defined($$courseopt{$courselevelr})) {
165: $outpar[7]=$$courseopt{$courselevelr};
1.43 albertel 166: $result=7;
167: }
1.11 www 168:
1.182 albertel 169: # ------------------------------------------------------ fourth, back to course
1.71 albertel 170: if (defined($csec)) {
1.200 www 171: if (defined($$courseopt{$seclevel})) {
172: $outpar[6]=$$courseopt{$seclevel};
1.43 albertel 173: $result=6;
174: }
1.200 www 175: if (defined($$courseopt{$seclevelm})) {
176: $outpar[5]=$$courseopt{$seclevelm};
1.43 albertel 177: $result=5;
178: }
179:
1.200 www 180: if (defined($$courseopt{$seclevelr})) {
1.201 www 181: $outpar[4]=$$courseopt{$seclevelr};
1.43 albertel 182: $result=4;
183: }
184: }
1.11 www 185:
1.182 albertel 186: # ---------------------------------------------------------- fifth, check user
1.11 www 187:
1.71 albertel 188: if (defined($uname)) {
1.200 www 189: if (defined($$useropt{$courselevel})) {
190: $outpar[3]=$$useropt{$courselevel};
1.43 albertel 191: $result=3;
192: }
1.10 www 193:
1.200 www 194: if (defined($$useropt{$courselevelm})) {
195: $outpar[2]=$$useropt{$courselevelm};
1.43 albertel 196: $result=2;
197: }
1.2 www 198:
1.200 www 199: if (defined($$useropt{$courselevelr})) {
200: $outpar[1]=$$useropt{$courselevelr};
1.43 albertel 201: $result=1;
202: }
203: }
1.44 albertel 204: return ($result,@outpar);
1.2 www 205: }
206:
1.198 www 207: sub resetparmhash {
208: $parmhashid='';
209: }
210:
211: sub cacheparmhash {
212: if ($parmhashid eq $env{'request.course.fn'}) { return; }
213: my %parmhashfile;
214: if (tie(%parmhashfile,'GDBM_File',
215: $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
216: %parmhash=%parmhashfile;
217: untie %parmhashfile;
218: $parmhashid=$env{'request.course.fn'};
219: }
220: }
221:
1.203 www 222: sub resetsymbcache {
223: $symbsid='';
224: }
225:
1.201 www 226: sub symbcache {
227: my $id=shift;
228: if ($symbsid ne $env{'request.course.id'}) {
229: %symbs=();
230: }
231: unless ($symbs{$id}) {
232: my $navmap = Apache::lonnavmaps::navmap->new();
233: if ($id=~/\./) {
234: my $resource=$navmap->getById($id);
235: $symbs{$id}=$resource->symb();
236: } else {
237: my $resource=$navmap->getByMapPc($id);
238: $symbs{$id}=&Apache::lonnet::declutter($resource->src());
239: }
240: $symbsid=$env{'request.course.id'};
241: }
242: return $symbs{$id};
243: }
244:
1.221 www 245: sub resetrulescache {
246: $rulesid='';
247: }
248:
249: sub rulescache {
250: my $id=shift;
251: if ($rulesid ne $env{'request.course.id'}) {
252: %rules=();
253: }
1.224 www 254: unless (defined($rules{$id})) {
1.221 www 255: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
256: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.224 www 257: %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
1.221 www 258: $rulesid=$env{'request.course.id'};
259: }
260: return $rules{$id};
261: }
262:
1.229 ! www 263: sub preset_defaults {
! 264: my $type=shift;
! 265: if (&rulescache($type.'_action') eq 'default') {
! 266: # yes, there is something
! 267: return (&rulescache($type.'_hours'),
! 268: &rulescache($type.'_min'),
! 269: &rulescache($type.'_sec'),
! 270: &rulescache($type.'_value'));
! 271: } else {
! 272: # nothing there or something else
! 273: return ('','','','','');
! 274: }
! 275: }
! 276:
1.186 www 277: ##################################################
278: ##################################################
279: #
1.197 www 280: # Store a parameter by ID
1.186 www 281: #
282: # Takes
283: # - resource id
284: # - name of parameter
285: # - level
286: # - new value
287: # - new type
1.187 www 288: # - username
289: # - userdomain
290:
1.186 www 291: sub storeparm {
1.187 www 292: my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
1.201 www 293: &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
1.197 www 294: }
295:
296: #
297: # Store a parameter by symb
298: #
299: # Takes
300: # - symb
301: # - name of parameter
302: # - level
303: # - new value
304: # - new type
305: # - username
306: # - userdomain
307:
1.226 www 308: my %recstack;
1.197 www 309: sub storeparm_by_symb {
1.226 www 310: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag)=@_;
311: unless ($recflag) {
312: # first time call
313: %recstack=();
314: $recflag=1;
315: }
316: # store parameter
317: &storeparm_by_symb_inner
318: ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec);
319: my ($prefix,$parm)=($spnam=~/^(.*[\_\.])([^\_\.]+)$/);
320: # remember that this was set
321: $recstack{$parm}=1;
322: # what does this trigger?
323: foreach my $triggered (split(/\:/,&rulescache($parm.'_triggers'))) {
324: # don't backfire
325: unless ((!$triggered) || ($recstack{$triggered})) {
326: my $action=&rulescache($triggered.'_action');
327: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
328: # set triggered parameter on same level
329: my $newspnam=$prefix.$triggered;
1.227 www 330: my $newvalue='';
1.228 www 331: my $active=1;
332: if ($action=~/^when\_setting/) {
333: # are there restrictions?
334: if (&rulescache($triggered.'_triggervalue')=~/\w/) {
335: $active=0;
336: foreach my $possiblevalue (split(/\s*\,\s*/,&rulescache($triggered.'_triggervalue'))) {
337: if (lc($possiblevalue) eq lc($nval)) { $active=1; }
338: }
339: }
340: $newvalue=&rulescache($triggered.'_value');
1.227 www 341: } else {
342: my $totalsecs=((&rulescache($triggered.'_days')*24+&rulescache($triggered.'_hours'))*60+&rulescache($triggered.'_min'))*60+&rulescache($triggered.'_sec');
1.228 www 343: if ($action=~/^later\_than/) {
344: $newvalue=$nval+$totalsecs;
345: } else {
346: $newvalue=$nval-$totalsecs;
347: }
348: }
349: if ($active) {
350: &storeparm_by_symb($symb,$newspnam,$snum,$newvalue,&rulescache($triggered.'_type'),
351: $uname,$udom,$csec,$recflag);
1.227 www 352: }
1.226 www 353: }
354: }
355: return '';
356: }
357:
358: sub storeparm_by_symb_inner {
1.197 www 359: # ---------------------------------------------------------- Get symb, map, etc
360: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec)=@_;
361: # ---------------------------------------------------------- Construct prefixes
1.186 www 362: $spnam=~s/\_([^\_]+)$/\.$1/;
1.197 www 363: my $map=(&Apache::lonnet::decode_symb($symb))[0];
364: my $symbparm=$symb.'.'.$spnam;
365: my $mapparm=$map.'___(all).'.$spnam;
366:
1.190 albertel 367: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
368: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
369: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
1.186 www 370:
1.190 albertel 371: my $courselevel=$env{'request.course.id'}.'.'.$spnam;
372: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
373: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
1.186 www 374:
375: my $storeunder='';
376: if (($snum==11) || ($snum==3)) { $storeunder=$courselevel; }
377: if (($snum==10) || ($snum==2)) { $storeunder=$courselevelm; }
378: if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
379: if ($snum==6) { $storeunder=$seclevel; }
380: if ($snum==5) { $storeunder=$seclevelm; }
381: if ($snum==4) { $storeunder=$seclevelr; }
382:
383: my $delete;
384: if ($nval eq '') { $delete=1;}
385: my %storecontent = ($storeunder => $nval,
386: $storeunder.'.type' => $ntype);
387: my $reply='';
388: if ($snum>3) {
389: # ---------------------------------------------------------------- Store Course
390: #
1.200 www 391: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
392: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.186 www 393: # Expire sheets
394: &Apache::lonnet::expirespread('','','studentcalc');
395: if (($snum==7) || ($snum==4)) {
1.197 www 396: &Apache::lonnet::expirespread('','','assesscalc',$symb);
1.186 www 397: } elsif (($snum==8) || ($snum==5)) {
1.197 www 398: &Apache::lonnet::expirespread('','','assesscalc',$map);
1.186 www 399: } else {
400: &Apache::lonnet::expirespread('','','assesscalc');
401: }
402: # Store parameter
403: if ($delete) {
404: $reply=&Apache::lonnet::del
1.200 www 405: ('resourcedata',[keys(%storecontent)],$cdom,$cnum);
1.186 www 406: } else {
407: $reply=&Apache::lonnet::cput
1.200 www 408: ('resourcedata',\%storecontent,$cdom,$cnum);
1.186 www 409: }
1.200 www 410: &Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
1.186 www 411: } else {
412: # ------------------------------------------------------------------ Store User
413: #
414: # Expire sheets
415: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
416: if ($snum==1) {
417: &Apache::lonnet::expirespread
1.197 www 418: ($uname,$udom,'assesscalc',$symb);
1.186 www 419: } elsif ($snum==2) {
420: &Apache::lonnet::expirespread
1.197 www 421: ($uname,$udom,'assesscalc',$map);
1.186 www 422: } else {
423: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
424: }
425: # Store parameter
426: if ($delete) {
427: $reply=&Apache::lonnet::del
428: ('resourcedata',[keys(%storecontent)],$udom,$uname);
429: } else {
430: $reply=&Apache::lonnet::cput
431: ('resourcedata',\%storecontent,$udom,$uname);
432: }
1.191 albertel 433: &Apache::lonnet::devalidateuserresdata($uname,$udom);
1.186 www 434: }
435:
436: if ($reply=~/^error\:(.*)/) {
437: return "<font color=red>Write Error: $1</font>";
438: }
439: return '';
440: }
441:
1.59 matthew 442: ##################################################
443: ##################################################
444:
445: =pod
446:
447: =item valout
448:
449: Format a value for output.
450:
451: Inputs: $value, $type
452:
453: Returns: $value, formatted for output. If $type indicates it is a date,
454: localtime($value) is returned.
1.9 www 455:
1.59 matthew 456: =cut
457:
458: ##################################################
459: ##################################################
1.9 www 460: sub valout {
461: my ($value,$type)=@_;
1.59 matthew 462: my $result = '';
463: # Values of zero are valid.
464: if (! $value && $value ne '0') {
1.71 albertel 465: $result = ' ';
1.59 matthew 466: } else {
1.66 www 467: if ($type eq 'date_interval') {
468: my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value);
469: $year=$year-70;
470: $mday--;
471: if ($year) {
472: $result.=$year.' yrs ';
473: }
474: if ($mon) {
475: $result.=$mon.' mths ';
476: }
477: if ($mday) {
478: $result.=$mday.' days ';
479: }
480: if ($hour) {
481: $result.=$hour.' hrs ';
482: }
483: if ($min) {
484: $result.=$min.' mins ';
485: }
486: if ($sec) {
487: $result.=$sec.' secs ';
488: }
489: $result=~s/\s+$//;
1.213 www 490: } elsif (&isdateparm($type)) {
1.59 matthew 491: $result = localtime($value);
492: } else {
493: $result = $value;
494: }
495: }
496: return $result;
1.9 www 497: }
498:
1.59 matthew 499: ##################################################
500: ##################################################
501:
502: =pod
1.5 www 503:
1.59 matthew 504: =item plink
505:
506: Produces a link anchor.
507:
508: Inputs: $type,$dis,$value,$marker,$return,$call
509:
510: Returns: scalar with html code for a link which will envoke the
511: javascript function 'pjump'.
512:
513: =cut
514:
515: ##################################################
516: ##################################################
1.5 www 517: sub plink {
518: my ($type,$dis,$value,$marker,$return,$call)=@_;
1.23 www 519: my $winvalue=$value;
520: unless ($winvalue) {
1.213 www 521: if (&isdateparm($type)) {
1.190 albertel 522: $winvalue=$env{'form.recent_'.$type};
1.23 www 523: } else {
1.190 albertel 524: $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
1.23 www 525: }
526: }
1.229 ! www 527: my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/);
! 528: &Apache::lonnet::logthis($marker.'-'.$parmname);
! 529: my ($hour,$min,$sec,$val)=&preset_defaults($parmname);
! 530: unless (defined($winvalue)) { $winvalue=$val; }
1.23 www 531: return
1.43 albertel 532: '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
1.229 ! www 533: .$marker."','".$return."','".$call."','".$hour."','".$min."','".$sec."'".');">'.
1.43 albertel 534: &valout($value,$type).'</a><a name="'.$marker.'"></a>';
1.5 www 535: }
536:
1.44 albertel 537: sub startpage {
1.209 www 538: my $r=shift;
1.99 albertel 539:
1.120 www 540: my $bodytag=&Apache::loncommon::bodytag('Set/Modify Course Parameters','',
1.98 www 541: 'onUnload="pclose()"');
1.204 www 542: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Table Mode Parameter Setting');
1.81 www 543: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1.88 matthew 544: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.183 albertel 545: my $html=&Apache::lonxml::xmlbegin();
1.44 albertel 546: $r->print(<<ENDHEAD);
1.183 albertel 547: $html
1.44 albertel 548: <head>
549: <title>LON-CAPA Course Parameters</title>
550: <script>
551:
552: function pclose() {
553: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
554: "height=350,width=350,scrollbars=no,menubar=no");
555: parmwin.close();
556: }
557:
1.88 matthew 558: $pjump_def
1.44 albertel 559:
560: function psub() {
561: pclose();
562: if (document.parmform.pres_marker.value!='') {
563: document.parmform.action+='#'+document.parmform.pres_marker.value;
564: var typedef=new Array();
565: typedef=document.parmform.pres_type.value.split('_');
566: if (document.parmform.pres_type.value!='') {
567: if (typedef[0]=='date') {
568: eval('document.parmform.recent_'+
569: document.parmform.pres_type.value+
570: '.value=document.parmform.pres_value.value;');
571: } else {
572: eval('document.parmform.recent_'+typedef[0]+
573: '.value=document.parmform.pres_value.value;');
574: }
575: }
576: document.parmform.submit();
577: } else {
578: document.parmform.pres_value.value='';
579: document.parmform.pres_marker.value='';
580: }
581: }
582:
1.57 albertel 583: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
584: var options = "width=" + w + ",height=" + h + ",";
585: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
586: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
587: var newWin = window.open(url, wdwName, options);
588: newWin.focus();
589: }
1.44 albertel 590: </script>
1.81 www 591: $selscript
1.44 albertel 592: </head>
1.64 www 593: $bodytag
1.193 albertel 594: $breadcrumbs
595: <form method="post" action="/adm/parmset?action=settable" name="parmform">
1.44 albertel 596: <input type="hidden" value='' name="pres_value">
597: <input type="hidden" value='' name="pres_type">
598: <input type="hidden" value='' name="pres_marker">
1.209 www 599: <input type="hidden" value='1' name="prevvisit">
1.44 albertel 600: ENDHEAD
601: }
602:
1.209 www 603:
1.44 albertel 604: sub print_row {
1.201 www 605: my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
1.187 www 606: $defbgtwo,$parmlev,$uname,$udom,$csec)=@_;
1.66 www 607: # get the values for the parameter in cascading order
608: # empty levels will remain empty
1.44 albertel 609: my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
1.187 www 610: $rid,$$default{$which},$uname,$udom,$csec);
1.66 www 611: # get the type for the parameters
612: # problem: these may not be set for all levels
613: my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
614: $$name{$which}.'.type',
1.187 www 615: $rid,$$defaulttype{$which},$uname,$udom,$csec);
1.66 www 616: # cascade down manually
1.182 albertel 617: my $cascadetype=$$defaulttype{$which};
618: for (my $i=11;$i>0;$i--) {
1.66 www 619: if ($typeoutpar[$i]) {
620: $cascadetype=$typeoutpar[$i];
621: } else {
622: $typeoutpar[$i]=$cascadetype;
623: }
624: }
1.57 albertel 625: my $parm=$$display{$which};
626:
1.203 www 627: if ($parmlev eq 'full') {
1.57 albertel 628: $r->print('<td bgcolor='.$defbgtwo.' align="center">'
629: .$$part{$which}.'</td>');
630: } else {
631: $parm=~s|\[.*\]\s||g;
632: }
633:
1.159 albertel 634: $r->print('<td bgcolor='.$defbgone.'>'.$parm.'</td>');
1.57 albertel 635:
1.44 albertel 636: my $thismarker=$which;
637: $thismarker=~s/^parameter\_//;
638: my $mprefix=$rid.'&'.$thismarker.'&';
639:
1.57 albertel 640: if ($parmlev eq 'general') {
641:
642: if ($uname) {
1.66 www 643: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 644: } elsif ($csec) {
1.66 www 645: &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 646: } else {
1.182 albertel 647: &print_td($r,11,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 648: }
649: } elsif ($parmlev eq 'map') {
650:
651: if ($uname) {
1.66 www 652: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 653: } elsif ($csec) {
1.66 www 654: &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 655: } else {
1.182 albertel 656: &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 657: }
658: } else {
659:
1.182 albertel 660: &print_td($r,11,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
1.57 albertel 661:
1.203 www 662: &print_td($r,10,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
663: &print_td($r,9,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
664: &print_td($r,8,'#FFDDDD',$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
665: &print_td($r,7,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
666:
667: if ($csec) {
668: &print_td($r,6,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
669: &print_td($r,5,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
670: &print_td($r,4,$defbgtwo,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
671: }
672: if ($uname) {
673: &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
674: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
675: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display);
676: }
1.57 albertel 677:
678: } # end of $parmlev if/else
679:
1.136 albertel 680: $r->print('<td bgcolor=#CCCCFF align="center">'.
681: &valout($outpar[$result],$typeoutpar[$result]).'</td>');
682:
1.203 www 683: if ($parmlev eq 'full') {
1.136 albertel 684: my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
1.201 www 685: '.'.$$name{$which},$$symbp{$rid});
1.136 albertel 686: my $sessionvaltype=$typeoutpar[$result];
687: if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; }
688: $r->print('<td bgcolor=#999999 align="center"><font color=#FFFFFF>'.
1.66 www 689: &valout($sessionval,$sessionvaltype).' '.
1.57 albertel 690: '</font></td>');
1.136 albertel 691: }
1.44 albertel 692: $r->print('</tr>');
1.57 albertel 693: $r->print("\n");
1.44 albertel 694: }
1.59 matthew 695:
1.44 albertel 696: sub print_td {
1.66 www 697: my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_;
1.57 albertel 698: $r->print('<td bgcolor='.(($result==$which)?'"#AAFFAA"':$defbg).
1.114 www 699: ' align="center">');
1.182 albertel 700: if ($which<8 || $which > 9) {
1.114 www 701: $r->print(&plink($$typeoutpar[$which],
702: $$display{$value},$$outpar[$which],
703: $mprefix."$which",'parmform.pres','psub'));
704: } else {
705: $r->print(&valout($$outpar[$which],$$typeoutpar[$which]));
706: }
707: $r->print('</td>'."\n");
1.57 albertel 708: }
709:
1.201 www 710:
1.63 bowersj2 711: =pod
712:
713: =item B<extractResourceInformation>: Given the course data hash, extractResourceInformation extracts lots of information about the course's resources into a variety of hashes.
714:
715: Input: See list below:
716:
717: =over 4
718:
719: =item B<ids>: An array that will contain all of the ids in the course.
720:
721: =item B<typep>: hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
722:
1.171 www 723: =item B<keyp>: hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
1.63 bowersj2 724:
725: =item B<allparms>: hash, name of parameter->display value (what is the display value?)
726:
727: =item B<allparts>: hash, part identification->text representation of part, where the text representation is "[Part $part]"
728:
729: =item B<allkeys>: hash, full key to part->display value (what's display value?)
730:
731: =item B<allmaps>: hash, ???
732:
733: =item B<fcat>: ???
734:
735: =item B<defp>: hash, ???
736:
737: =item B<mapp>: ??
738:
739: =item B<symbp>: hash, id->full sym?
740:
741: =back
742:
743: =cut
744:
745: sub extractResourceInformation {
746: my $ids = shift;
747: my $typep = shift;
748: my $keyp = shift;
749: my $allparms = shift;
750: my $allparts = shift;
751: my $allmaps = shift;
752: my $mapp = shift;
753: my $symbp = shift;
1.82 www 754: my $maptitles=shift;
1.196 www 755: my $uris=shift;
1.210 www 756: my $keyorder=shift;
1.211 www 757: my $defkeytype=shift;
1.196 www 758:
1.210 www 759: my $keyordercnt=100;
1.63 bowersj2 760:
1.196 www 761: my $navmap = Apache::lonnavmaps::navmap->new();
762: my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
763: foreach my $resource (@allres) {
764: my $id=$resource->id();
765: my ($mapid,$resid)=split(/\./,$id);
766: if ($mapid eq '0') { next; }
767: $$ids[$#$ids+1]=$id;
768: my $srcf=$resource->src();
769: $srcf=~/\.(\w+)$/;
770: $$typep{$id}=$1;
771: $$keyp{$id}='';
772: $$uris{$id}=$srcf;
773: foreach (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys'))) {
774: if ($_=~/^parameter\_(.*)/) {
775: my $key=$_;
1.209 www 776: # Hidden parameters
777: if (&Apache::lonnet::metadata($srcf,$key.'.hidden') eq 'parm') {
778: next;
1.63 bowersj2 779: }
1.196 www 780: my $display= &Apache::lonnet::metadata($srcf,$key.'.display');
781: my $name=&Apache::lonnet::metadata($srcf,$key.'.name');
782: my $part= &Apache::lonnet::metadata($srcf,$key.'.part');
1.209 www 783: #
784: # allparms is a hash of parameter names
785: #
1.196 www 786: my $parmdis = $display;
1.209 www 787: $parmdis =~ s/\[Part.*$//g;
788: $$allparms{$name}=$parmdis;
1.211 www 789: $$defkeytype{$name}=&Apache::lonnet::metadata($srcf,$key.'.type');
1.209 www 790: #
791: # allparts is a hash of all parts
792: #
793: $$allparts{$part} = "Part: $part";
794: #
795: # Remember all keys going with this resource
796: #
1.196 www 797: if ($$keyp{$id}) {
798: $$keyp{$id}.=','.$key;
1.175 albertel 799: } else {
1.196 www 800: $$keyp{$id}=$key;
1.175 albertel 801: }
1.210 www 802: #
803: # Put in order
804: #
805: unless ($$keyorder{$key}) {
806: $$keyorder{$key}=$keyordercnt;
807: $keyordercnt++;
808: }
809:
1.63 bowersj2 810: }
811: }
1.196 www 812: $$mapp{$id}=
813: &Apache::lonnet::declutter($resource->enclosing_map_src());
814: $$mapp{$mapid}=$$mapp{$id};
815: $$allmaps{$mapid}=$$mapp{$id};
816: if ($mapid eq '1') {
817: $$maptitles{$mapid}='Main Course Documents';
818: } else {
819: $$maptitles{$mapid}=&Apache::lonnet::gettitle(&Apache::lonnet::clutter($$mapp{$id}));
820: }
821: $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
822: $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
823: $$symbp{$mapid}=$$mapp{$id}.'___(all)';
1.63 bowersj2 824: }
825: }
826:
1.208 www 827:
828: ##################################################
829: ##################################################
830:
1.213 www 831: sub isdateparm {
832: my $type=shift;
833: return (($type=~/^date/) && (!($type eq 'date_interval')));
834: }
835:
1.208 www 836: sub parmmenu {
1.211 www 837: my ($r,$allparms,$pscat,$keyorder)=@_;
1.208 www 838: my $tempkey;
839: $r->print(<<ENDSCRIPT);
840: <script type="text/javascript">
841: function checkall(value, checkName) {
842: for (i=0; i<document.forms.parmform.elements.length; i++) {
843: ele = document.forms.parmform.elements[i];
844: if (ele.name == checkName) {
845: document.forms.parmform.elements[i].checked=value;
846: }
847: }
848: }
1.210 www 849:
850: function checkthis(thisvalue, checkName) {
851: for (i=0; i<document.forms.parmform.elements.length; i++) {
852: ele = document.forms.parmform.elements[i];
853: if (ele.name == checkName) {
854: if (ele.value == thisvalue) {
855: document.forms.parmform.elements[i].checked=true;
856: }
857: }
858: }
859: }
860:
861: function checkdates() {
862: checkthis('duedate','pscat');
863: checkthis('opendate','pscat');
864: checkthis('answerdate','pscat');
1.218 www 865: }
866:
867: function checkdisset() {
868: checkthis('discussend','pscat');
869: checkthis('discusshide','pscat');
870: }
871:
872: function checkcontdates() {
873: checkthis('contentopen','pscat');
874: checkthis('contentclose','pscat');
875: }
876:
1.210 www 877:
878: function checkvisi() {
879: checkthis('hiddenresource','pscat');
880: checkthis('encrypturl','pscat');
881: checkthis('problemstatus','pscat');
882: checkthis('contentopen','pscat');
883: checkthis('opendate','pscat');
884: }
885:
886: function checkparts() {
887: checkthis('hiddenparts','pscat');
888: checkthis('display','pscat');
889: checkthis('ordered','pscat');
890: }
891:
892: function checkstandard() {
893: checkall(false,'pscat');
894: checkdates();
895: checkthis('weight','pscat');
896: checkthis('maxtries','pscat');
897: }
898:
1.208 www 899: </script>
900: ENDSCRIPT
1.209 www 901: $r->print();
1.208 www 902: $r->print("\n<table><tr>");
903: my $cnt=0;
1.211 www 904: foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) {
1.209 www 905: $r->print("\n<td><font size='-1'><input type='checkbox' name='pscat' ");
1.208 www 906: $r->print('value="'.$tempkey.'"');
907: if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
908: $r->print(' checked');
909: }
1.209 www 910: $r->print('>'.$$allparms{$tempkey}.'</font></td>');
911: $cnt++;
912: if ($cnt==3) {
913: $r->print("</tr>\n<tr>");
914: $cnt=0;
915: }
1.208 www 916: }
917: $r->print('
918: </tr><tr><td>
1.218 www 919: <a href="javascript:checkall(true, \'pscat\')">Select All</a><br />
920: <a href="javascript:checkstandard()">Select Common Only</a>
1.210 www 921: </td><td>
1.218 www 922: <a href="javascript:checkdates()">Add Problem Dates</a>
923: <a href="javascript:checkcontdates()">Add Content Dates</a><br />
924: <a href="javascript:checkdisset()">Add Discussion Settings</a>
925: <a href="javascript:checkvisi()">Add Visibilities</a><br />
926: <a href="javascript:checkparts()">Add Part Parameters</a>
1.210 www 927: </td><td>
928: <a href="javascript:checkall(false, \'pscat\')">Unselect All</a>
1.208 www 929: </td>
930: ');
931: $r->print('</tr></table>');
932: }
933:
1.209 www 934: sub partmenu {
935: my ($r,$allparts,$psprt)=@_;
1.211 www 936: $r->print('<select multiple name="psprt" size="8">');
1.208 www 937: $r->print('<option value="all"');
938: $r->print(' selected') unless (@{$psprt});
939: $r->print('>'.&mt('All Parts').'</option>');
940: my %temphash=();
941: foreach (@{$psprt}) { $temphash{$_}=1; }
1.209 www 942: foreach my $tempkey (sort keys %{$allparts}) {
1.208 www 943: unless ($tempkey =~ /\./) {
944: $r->print('<option value="'.$tempkey.'"');
945: if ($$psprt[0] eq "all" || $temphash{$tempkey}) {
946: $r->print(' selected');
947: }
948: $r->print('>'.$$allparts{$tempkey}.'</option>');
949: }
950: }
1.209 www 951: $r->print('</select>');
952: }
953:
954: sub usermenu {
955: my ($r,$uname,$id,$udom,$csec)=@_;
956: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
957: &Apache::loncommon::selectstudent_link('parmform','uname','udom');
958: my $selscript=&Apache::loncommon::studentbrowser_javascript();
959: my %lt=&Apache::lonlocal::texthash(
960: 'sg' => "Section/Group",
961: 'fu' => "For User",
962: 'oi' => "or ID",
963: 'ad' => "at Domain"
964: );
965: my %sectionhash=();
966: my $sections='';
967: if (&Apache::loncommon::get_sections(
968: $env{'course.'.$env{'request.course.id'}.'.domain'},
969: $env{'course.'.$env{'request.course.id'}.'.num'},
970: \%sectionhash)) {
971: $sections=$lt{'sg'}.': <select name="csec">';
972: foreach ('',sort keys %sectionhash) {
973: $sections.='<option value="'.$_.'"'.
974: ($_ eq $csec?'selected="selected"':'').'>'.$_.'</option>';
975: }
976: $sections.='</select>';
977: }
978: $r->print(<<ENDMENU);
979: <b>
980: $sections
981: <br />
982: $lt{'fu'}
983: <input type="text" value="$uname" size="12" name="uname" />
984: $lt{'oi'}
985: <input type="text" value="$id" size="12" name="id" />
986: $lt{'ad'}
987: $chooseopt
988: </b>
989: ENDMENU
990: }
991:
992: sub displaymenu {
1.211 www 993: my ($r,$allparms,$allparts,$pscat,$psprt,$keyorder)=@_;
1.209 www 994: $r->print('<table border="1"><tr><th>'.&mt('Select Parameters to View').'</th><th>'.
995: &mt('Select Parts to View').'</th></tr><tr><td>');
1.211 www 996: &parmmenu($r,$allparms,$pscat,$keyorder);
1.209 www 997: $r->print('</td><td>');
998: &partmenu($r,$allparts,$psprt);
999: $r->print('</td></tr></table>');
1000: }
1001:
1002: sub mapmenu {
1003: my ($r,$allmaps,$pschp,$maptitles)=@_;
1004: $r->print(&mt('Select Enclosing Map or Folder').' ');
1005: $r->print('<select name="pschp">');
1006: $r->print('<option value="all">'.&mt('All Maps or Folders').'</option>');
1007: foreach (sort {$$allmaps{$a} cmp $$allmaps{$b}} keys %{$allmaps}) {
1.208 www 1008: $r->print('<option value="'.$_.'"');
1.209 www 1009: if (($pschp eq $_)) { $r->print(' selected'); }
1010: $r->print('>'.$$maptitles{$_}.($$allmaps{$_}!~/^uploaded/?' ['.$$allmaps{$_}.']':'').'</option>');
1011: }
1012: $r->print("</select>");
1013: }
1014:
1015: sub levelmenu {
1016: my ($r,$alllevs,$parmlev)=@_;
1017: $r->print(&mt('Select Parameter Level').
1018: &Apache::loncommon::help_open_topic('Course_Parameter_Levels').' ');
1019: $r->print('<select name="parmlev">');
1020: foreach (reverse sort keys %{$alllevs}) {
1021: $r->print('<option value="'.$$alllevs{$_}.'"');
1022: if ($parmlev eq $$alllevs{$_}) {
1023: $r->print(' selected');
1024: }
1025: $r->print('>'.$_.'</option>');
1.208 www 1026: }
1.209 www 1027: $r->print("</select>");
1.208 www 1028: }
1029:
1.211 www 1030:
1031: sub sectionmenu {
1032: my ($r,$selectedsections)=@_;
1.212 www 1033: my %sectionhash=();
1.211 www 1034:
1.212 www 1035: if (&Apache::loncommon::get_sections(
1036: $env{'course.'.$env{'request.course.id'}.'.domain'},
1037: $env{'course.'.$env{'request.course.id'}.'.num'},
1038: \%sectionhash)) {
1039: $r->print('<select name="Section" multiple="true" size="8" >');
1040: foreach my $s ('all',sort keys %sectionhash) {
1041: $r->print(' <option value="'.$s.'"');
1042: foreach (@{$selectedsections}) {
1043: if ($s eq $_) {
1044: $r->print(' selected');
1045: last;
1046: }
1047: }
1048: $r->print('>'.$s."</option>\n");
1049: }
1050: $r->print("</select>\n");
1.211 www 1051: }
1052: }
1053:
1.210 www 1054: sub keysplit {
1055: my $keyp=shift;
1056: return (split(/\,/,$keyp));
1057: }
1058:
1059: sub keysinorder {
1060: my ($name,$keyorder)=@_;
1061: return sort {
1062: $$keyorder{$a} <=> $$keyorder{$b};
1063: } (keys %{$name});
1064: }
1065:
1.211 www 1066: sub keysindisplayorder {
1067: my ($name,$keyorder)=@_;
1068: return sort {
1069: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
1070: } (keys %{$name});
1071: }
1072:
1.214 www 1073: sub sortmenu {
1074: my ($r,$sortorder)=@_;
1075: $r->print('<br /><input type="radio" name="sortorder" value="realmstudent"');
1076: if ($sortorder eq 'realmstudent') {
1077: $r->print(' checked="on"');
1078: }
1079: $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
1080: $r->print('<br /><input type="radio" name="sortorder" value="studentrealm"');
1081: if ($sortorder eq 'studentrealm') {
1082: $r->print(' checked="on"');
1083: }
1084: $r->print(' />'.&mt('Sort by student (group/section) first, then realm'));
1085: }
1086:
1.211 www 1087: sub standardkeyorder {
1088: return ('parameter_0_opendate' => 1,
1089: 'parameter_0_duedate' => 2,
1090: 'parameter_0_answerdate' => 3,
1091: 'parameter_0_interval' => 4,
1092: 'parameter_0_weight' => 5,
1093: 'parameter_0_maxtries' => 6,
1094: 'parameter_0_hinttries' => 7,
1095: 'parameter_0_contentopen' => 8,
1096: 'parameter_0_contentclose' => 9,
1097: 'parameter_0_type' => 10,
1098: 'parameter_0_problemstatus' => 11,
1099: 'parameter_0_hiddenresource' => 12,
1100: 'parameter_0_hiddenparts' => 13,
1101: 'parameter_0_display' => 14,
1102: 'parameter_0_ordered' => 15,
1103: 'parameter_0_tol' => 16,
1104: 'parameter_0_sig' => 17,
1.218 www 1105: 'parameter_0_turnoffunit' => 18,
1106: 'parameter_0_discussend' => 19,
1107: 'parameter_0_discusshide' => 20);
1.211 www 1108: }
1109:
1.59 matthew 1110: ##################################################
1111: ##################################################
1112:
1113: =pod
1114:
1115: =item assessparms
1116:
1117: Show assessment data and parameters. This is a large routine that should
1118: be simplified and shortened... someday.
1119:
1120: Inputs: $r
1121:
1122: Returns: nothing
1123:
1.63 bowersj2 1124: Variables used (guessed by Jeremy):
1125:
1126: =over 4
1127:
1128: =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.
1129:
1130: =item B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
1131:
1132: =item B<allmaps>:
1133:
1134: =back
1135:
1.59 matthew 1136: =cut
1137:
1138: ##################################################
1139: ##################################################
1.30 www 1140: sub assessparms {
1.1 www 1141:
1.43 albertel 1142: my $r=shift;
1.201 www 1143:
1144: my @ids=();
1145: my %symbp=();
1146: my %mapp=();
1147: my %typep=();
1148: my %keyp=();
1149: my %uris=();
1150: my %maptitles=();
1151:
1.2 www 1152: # -------------------------------------------------------- Variable declaration
1.209 www 1153:
1.129 www 1154: my %allmaps=();
1155: my %alllevs=();
1.57 albertel 1156:
1.187 www 1157: my $uname;
1158: my $udom;
1159: my $uhome;
1160: my $csec;
1161:
1.190 albertel 1162: my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
1.187 www 1163:
1.57 albertel 1164: $alllevs{'Resource Level'}='full';
1.215 www 1165: $alllevs{'Map/Folder Level'}='map';
1.57 albertel 1166: $alllevs{'Course Level'}='general';
1167:
1168: my %allparms;
1169: my %allparts;
1.210 www 1170: #
1171: # Order in which these parameters will be displayed
1172: #
1.211 www 1173: my %keyorder=&standardkeyorder();
1174:
1.43 albertel 1175: @ids=();
1176: %symbp=();
1177: %typep=();
1178:
1179: my $message='';
1180:
1.190 albertel 1181: $csec=$env{'form.csec'};
1.188 www 1182:
1.190 albertel 1183: if ($udom=$env{'form.udom'}) {
1184: } elsif ($udom=$env{'request.role.domain'}) {
1185: } elsif ($udom=$env{'user.domain'}) {
1.172 albertel 1186: } else {
1187: $udom=$r->dir_config('lonDefDomain');
1188: }
1.43 albertel 1189:
1.134 albertel 1190: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
1.190 albertel 1191: my $pschp=$env{'form.pschp'};
1.134 albertel 1192: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
1.76 www 1193: if (!@psprt) { $psprt[0]='0'; }
1.57 albertel 1194:
1.43 albertel 1195: my $pssymb='';
1.57 albertel 1196: my $parmlev='';
1197:
1.190 albertel 1198: unless ($env{'form.parmlev'}) {
1.57 albertel 1199: $parmlev = 'map';
1200: } else {
1.190 albertel 1201: $parmlev = $env{'form.parmlev'};
1.57 albertel 1202: }
1.26 www 1203:
1.29 www 1204: # ----------------------------------------------- Was this started from grades?
1205:
1.190 albertel 1206: if (($env{'form.command'} eq 'set') && ($env{'form.url'})
1207: && (!$env{'form.dis'})) {
1208: my $url=$env{'form.url'};
1.194 albertel 1209: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.43 albertel 1210: $pssymb=&Apache::lonnet::symbread($url);
1.92 albertel 1211: if (!@pscat) { @pscat=('all'); }
1.43 albertel 1212: $pschp='';
1.57 albertel 1213: $parmlev = 'full';
1.190 albertel 1214: } elsif ($env{'form.symb'}) {
1215: $pssymb=$env{'form.symb'};
1.92 albertel 1216: if (!@pscat) { @pscat=('all'); }
1.43 albertel 1217: $pschp='';
1.57 albertel 1218: $parmlev = 'full';
1.43 albertel 1219: } else {
1.190 albertel 1220: $env{'form.url'}='';
1.43 albertel 1221: }
1222:
1.190 albertel 1223: my $id=$env{'form.id'};
1.43 albertel 1224: if (($id) && ($udom)) {
1225: $uname=(&Apache::lonnet::idget($udom,$id))[1];
1226: if ($uname) {
1227: $id='';
1228: } else {
1229: $message=
1.133 www 1230: "<font color=red>".&mt("Unknown ID")." '$id' ".
1231: &mt('at domain')." '$udom'</font>";
1.43 albertel 1232: }
1233: } else {
1.190 albertel 1234: $uname=$env{'form.uname'};
1.43 albertel 1235: }
1236: unless ($udom) { $uname=''; }
1237: $uhome='';
1238: if ($uname) {
1239: $uhome=&Apache::lonnet::homeserver($uname,$udom);
1240: if ($uhome eq 'no_host') {
1241: $message=
1.133 www 1242: "<font color=red>".&mt("Unknown user")." '$uname' ".
1243: &mt("at domain")." '$udom'</font>";
1.43 albertel 1244: $uname='';
1.12 www 1245: } else {
1.103 albertel 1246: $csec=&Apache::lonnet::getsection($udom,$uname,
1.190 albertel 1247: $env{'request.course.id'});
1.43 albertel 1248: if ($csec eq '-1') {
1249: $message="<font color=red>".
1.133 www 1250: &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
1251: &mt("not in this course")."</font>";
1.43 albertel 1252: $uname='';
1.190 albertel 1253: $csec=$env{'form.csec'};
1.43 albertel 1254: } else {
1255: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1256: ('firstname','middlename','lastname','generation','id'));
1.133 www 1257: $message="\n<p>\n".&mt("Full Name").": ".
1.43 albertel 1258: $name{'firstname'}.' '.$name{'middlename'}.' '
1259: .$name{'lastname'}.' '.$name{'generation'}.
1.133 www 1260: "<br>\n".&mt('ID').": ".$name{'id'}.'<p>';
1.43 albertel 1261: }
1.12 www 1262: }
1.43 albertel 1263: }
1.2 www 1264:
1.43 albertel 1265: unless ($csec) { $csec=''; }
1.12 www 1266:
1.14 www 1267: # --------------------------------------------------------- Get all assessments
1.210 www 1268: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
1269: \%mapp, \%symbp,\%maptitles,\%uris,
1270: \%keyorder);
1.63 bowersj2 1271:
1.57 albertel 1272: $mapp{'0.0'} = '';
1273: $symbp{'0.0'} = '';
1.99 albertel 1274:
1.14 www 1275: # ---------------------------------------------------------- Anything to store?
1.190 albertel 1276: if ($env{'form.pres_marker'}) {
1.205 www 1277: my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
1278: my @values=split(/\&\&\&/,$env{'form.pres_value'});
1279: my @types=split(/\&\&\&/,$env{'form.pres_type'});
1280: for (my $i=0;$i<=$#markers;$i++) {
1281: $message.=&storeparm(split(/\&/,$markers[$i]),
1282: $values[$i],
1283: $types[$i],
1284: $uname,$udom,$csec);
1285: }
1.68 www 1286: # ---------------------------------------------------------------- Done storing
1.130 www 1287: $message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
1.68 www 1288: }
1.57 albertel 1289: #----------------------------------------------- if all selected, fill in array
1.209 www 1290: if ($pscat[0] eq "all") {@pscat = (keys %allparms);}
1291: if (!@pscat) { @pscat=('duedate','opendate','answerdate','weight','maxtries') };
1.57 albertel 1292: if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
1.2 www 1293: # ------------------------------------------------------------------ Start page
1.63 bowersj2 1294:
1.209 www 1295: &startpage($r);
1.57 albertel 1296:
1.44 albertel 1297: foreach ('tolerance','date_default','date_start','date_end',
1298: 'date_interval','int','float','string') {
1299: $r->print('<input type="hidden" value="'.
1.190 albertel 1300: $env{'form.recent_'.$_}.'" name="recent_'.$_.'">');
1.44 albertel 1301: }
1.57 albertel 1302:
1.44 albertel 1303: if (!$pssymb) {
1.209 www 1304: $r->print('<table border="1"><tr><td>');
1305: &levelmenu($r,\%alllevs,$parmlev);
1.128 albertel 1306: if ($parmlev ne 'general') {
1.209 www 1307: $r->print('<td>');
1308: &mapmenu($r,\%allmaps,$pschp,\%maptitles);
1309: $r->print('</td>');
1.128 albertel 1310: }
1.209 www 1311: $r->print('</td></tr></table>');
1.211 www 1312: &displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder);
1.44 albertel 1313: } else {
1.125 www 1314: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
1.209 www 1315: $r->print(&mt('Specific Resource').": ".$resource.
1.212 www 1316: '<input type="hidden" value="'.$pssymb.'" name="symb"><br />');
1.57 albertel 1317: }
1.209 www 1318: &usermenu($r,$uname,$id,$udom,$csec);
1.57 albertel 1319:
1.210 www 1320: $r->print('<p>'.$message.'</p>');
1321:
1.209 www 1322: $r->print('<br /><input type="submit" name="dis" value="'.&mt("Update Parameter Display").'" />');
1.57 albertel 1323:
1324: my @temp_pscat;
1325: map {
1326: my $cat = $_;
1327: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
1328: } @pscat;
1329:
1330: @pscat = @temp_pscat;
1331:
1.209 www 1332: if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
1.10 www 1333: # ----------------------------------------------------------------- Start Table
1.57 albertel 1334: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
1.190 albertel 1335: my $csuname=$env{'user.name'};
1336: my $csudom=$env{'user.domain'};
1.57 albertel 1337:
1.203 www 1338: if ($parmlev eq 'full') {
1.57 albertel 1339: my $coursespan=$csec?8:5;
1340: $r->print('<p><table border=2>');
1341: $r->print('<tr><td colspan=5></td>');
1.130 www 1342: $r->print('<th colspan='.($coursespan).'>'.&mt('Any User').'</th>');
1.57 albertel 1343: if ($uname) {
1344: $r->print("<th colspan=3 rowspan=2>");
1.130 www 1345: $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
1.57 albertel 1346: }
1.133 www 1347: my %lt=&Apache::lonlocal::texthash(
1348: 'pie' => "Parameter in Effect",
1349: 'csv' => "Current Session Value",
1350: 'at' => 'at',
1351: 'rl' => "Resource Level",
1352: 'ic' => 'in Course',
1353: 'aut' => "Assessment URL and Title",
1.143 albertel 1354: 'type' => 'Type',
1.133 www 1355: 'emof' => "Enclosing Map or Folder",
1.143 albertel 1356: 'part' => 'Part',
1.133 www 1357: 'pn' => 'Parameter Name',
1358: 'def' => 'default',
1359: 'femof' => 'from Enclosing Map or Folder',
1360: 'gen' => 'general',
1361: 'foremf' => 'for Enclosing Map or Folder',
1362: 'fr' => 'for Resource'
1363: );
1.57 albertel 1364: $r->print(<<ENDTABLETWO);
1.133 www 1365: <th rowspan=3>$lt{'pie'}</th>
1366: <th rowspan=3>$lt{'csv'}<br>($csuname $lt{'at'} $csudom)</th>
1.182 albertel 1367: </tr><tr><td colspan=5></td><th colspan=2>$lt{'ic'}</th><th colspan=2>$lt{'rl'}</th>
1368: <th colspan=1>$lt{'ic'}</th>
1369:
1.10 www 1370: ENDTABLETWO
1.57 albertel 1371: if ($csec) {
1.133 www 1372: $r->print("<th colspan=3>".
1373: &mt("in Section/Group")." $csec</th>");
1.57 albertel 1374: }
1375: $r->print(<<ENDTABLEHEADFOUR);
1.133 www 1376: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
1377: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
1.192 albertel 1378: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
1379: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
1.10 www 1380: ENDTABLEHEADFOUR
1.57 albertel 1381:
1382: if ($csec) {
1.130 www 1383: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1.57 albertel 1384: }
1385:
1386: if ($uname) {
1.130 www 1387: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
1.57 albertel 1388: }
1389:
1390: $r->print('</tr>');
1391:
1392: my $defbgone='';
1393: my $defbgtwo='';
1394:
1395: foreach (@ids) {
1396:
1397: my $rid=$_;
1398: my ($inmapid)=($rid=~/\.(\d+)$/);
1399:
1.152 albertel 1400: if ((!$pssymb &&
1401: (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
1402: ||
1403: ($pssymb && $pssymb eq $symbp{$rid})) {
1.4 www 1404: # ------------------------------------------------------ Entry for one resource
1.184 albertel 1405: if ($defbgone eq '"#E0E099"') {
1406: $defbgone='"#E0E0DD"';
1.57 albertel 1407: } else {
1.184 albertel 1408: $defbgone='"#E0E099"';
1.57 albertel 1409: }
1.184 albertel 1410: if ($defbgtwo eq '"#FFFF99"') {
1411: $defbgtwo='"#FFFFDD"';
1.57 albertel 1412: } else {
1.184 albertel 1413: $defbgtwo='"#FFFF99"';
1.57 albertel 1414: }
1415: my $thistitle='';
1416: my %name= ();
1417: undef %name;
1418: my %part= ();
1419: my %display=();
1420: my %type= ();
1421: my %default=();
1.196 www 1422: my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57 albertel 1423:
1.210 www 1424: foreach (&keysplit($keyp{$rid})) {
1.57 albertel 1425: my $tempkeyp = $_;
1426: if (grep $_ eq $tempkeyp, @catmarker) {
1427: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
1428: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
1429: $display{$_}=&Apache::lonnet::metadata($uri,$_.'.display');
1430: unless ($display{$_}) { $display{$_}=''; }
1431: $display{$_}.=' ('.$name{$_}.')';
1432: $default{$_}=&Apache::lonnet::metadata($uri,$_);
1433: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
1434: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
1435: }
1436: }
1437: my $totalparms=scalar keys %name;
1438: if ($totalparms>0) {
1439: my $firstrow=1;
1.180 albertel 1440: my $title=&Apache::lonnet::gettitle($uri);
1.57 albertel 1441: $r->print('<tr><td bgcolor='.$defbgone.
1442: ' rowspan='.$totalparms.
1443: '><tt><font size=-1>'.
1444: join(' / ',split(/\//,$uri)).
1445: '</font></tt><p><b>'.
1.154 albertel 1446: "<a href=\"javascript:openWindow('".
1447: &Apache::lonnet::clutter($uri).
1.57 albertel 1448: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
1.127 albertel 1449: " TARGET=_self>$title");
1.57 albertel 1450:
1451: if ($thistitle) {
1452: $r->print(' ('.$thistitle.')');
1453: }
1454: $r->print('</a></b></td>');
1455: $r->print('<td bgcolor='.$defbgtwo.
1456: ' rowspan='.$totalparms.'>'.$typep{$rid}.
1457: '</td>');
1458:
1459: $r->print('<td bgcolor='.$defbgone.
1460: ' rowspan='.$totalparms.
1461: '><tt><font size=-1>');
1462:
1463: $r->print(' / res / ');
1464: $r->print(join(' / ', split(/\//,$mapp{$rid})));
1465:
1466: $r->print('</font></tt></td>');
1467:
1.210 www 1468: foreach (&keysinorder(\%name,\%keyorder)) {
1.57 albertel 1469: unless ($firstrow) {
1470: $r->print('<tr>');
1471: } else {
1472: undef $firstrow;
1473: }
1474:
1.201 www 1475: &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
1.57 albertel 1476: \%type,\%display,$defbgone,$defbgtwo,
1.187 www 1477: $parmlev,$uname,$udom,$csec);
1.57 albertel 1478: }
1479: }
1480: }
1481: } # end foreach ids
1.43 albertel 1482: # -------------------------------------------------- End entry for one resource
1.57 albertel 1483: $r->print('</table>');
1.203 www 1484: } # end of full
1.57 albertel 1485: #--------------------------------------------------- Entry for parm level map
1486: if ($parmlev eq 'map') {
1487: my $defbgone = '"E0E099"';
1488: my $defbgtwo = '"FFFF99"';
1489:
1490: my %maplist;
1491:
1492: if ($pschp eq 'all') {
1493: %maplist = %allmaps;
1494: } else {
1495: %maplist = ($pschp => $mapp{$pschp});
1496: }
1497:
1498: #-------------------------------------------- for each map, gather information
1499: my $mapid;
1.60 albertel 1500: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
1501: my $maptitle = $maplist{$mapid};
1.57 albertel 1502:
1503: #----------------------- loop through ids and get all parameter types for map
1504: #----------------------------------------- and associated information
1505: my %name = ();
1506: my %part = ();
1507: my %display = ();
1508: my %type = ();
1509: my %default = ();
1510: my $map = 0;
1511:
1512: # $r->print("Catmarker: @catmarker<br />\n");
1513:
1514: foreach (@ids) {
1515: ($map)=(/([\d]*?)\./);
1516: my $rid = $_;
1517:
1518: # $r->print("$mapid:$map: $rid <br /> \n");
1519:
1520: if ($map eq $mapid) {
1.196 www 1521: my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57 albertel 1522: # $r->print("Keys: $keyp{$rid} <br />\n");
1523:
1524: #--------------------------------------------------------------------
1525: # @catmarker contains list of all possible parameters including part #s
1526: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1527: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1528: # When storing information, store as part 0
1529: # When requesting information, request from full part
1530: #-------------------------------------------------------------------
1.210 www 1531: foreach (&keysplit($keyp{$rid})) {
1.57 albertel 1532: my $tempkeyp = $_;
1533: my $fullkeyp = $tempkeyp;
1.73 albertel 1534: $tempkeyp =~ s/_\w+_/_0_/;
1.57 albertel 1535:
1536: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1537: $part{$tempkeyp}="0";
1538: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1539: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1540: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1541: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1.73 albertel 1542: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1.57 albertel 1543: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1544: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1545: }
1546: } # end loop through keys
1547: }
1548: } # end loop through ids
1549:
1550: #---------------------------------------------------- print header information
1.133 www 1551: my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
1.82 www 1552: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
1.57 albertel 1553: $r->print(<<ENDMAPONE);
1554: <center><h4>
1.135 albertel 1555: Set Defaults for All Resources in $foldermap<br />
1556: <font color="red"><i>$showtitle</i></font><br />
1.57 albertel 1557: Specifically for
1558: ENDMAPONE
1559: if ($uname) {
1560: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1561: ('firstname','middlename','lastname','generation', 'id'));
1562: my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
1563: .$name{'lastname'}.' '.$name{'generation'};
1.135 albertel 1564: $r->print(&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
1.130 www 1565: &mt('in')." \n");
1.57 albertel 1566: } else {
1.135 albertel 1567: $r->print("<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n");
1.57 albertel 1568: }
1569:
1.135 albertel 1570: if ($csec) {$r->print(&mt("Section")." <font color=\"red\"><i>$csec</i></font> ".
1.130 www 1571: &mt('of')." \n")};
1.57 albertel 1572:
1.135 albertel 1573: $r->print("<font color=\"red\"><i>$coursename</i></font><br />");
1574: $r->print("</h4>\n");
1.57 albertel 1575: #---------------------------------------------------------------- print table
1576: $r->print('<p><table border="2">');
1.130 www 1577: $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
1578: $r->print('<th>'.&mt('Default Value').'</th>');
1579: $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1.57 albertel 1580:
1.210 www 1581: foreach (&keysinorder(\%name,\%keyorder)) {
1.168 matthew 1582: $r->print('<tr>');
1.201 www 1583: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1.57 albertel 1584: \%type,\%display,$defbgone,$defbgtwo,
1.187 www 1585: $parmlev,$uname,$udom,$csec);
1.57 albertel 1586: }
1587: $r->print("</table></center>");
1588: } # end each map
1589: } # end of $parmlev eq map
1590: #--------------------------------- Entry for parm level general (Course level)
1591: if ($parmlev eq 'general') {
1592: my $defbgone = '"E0E099"';
1593: my $defbgtwo = '"FFFF99"';
1594:
1595: #-------------------------------------------- for each map, gather information
1596: my $mapid="0.0";
1597: #----------------------- loop through ids and get all parameter types for map
1598: #----------------------------------------- and associated information
1599: my %name = ();
1600: my %part = ();
1601: my %display = ();
1602: my %type = ();
1603: my %default = ();
1604:
1605: foreach (@ids) {
1606: my $rid = $_;
1607:
1.196 www 1608: my $uri=&Apache::lonnet::declutter($uris{$rid});
1.57 albertel 1609:
1610: #--------------------------------------------------------------------
1611: # @catmarker contains list of all possible parameters including part #s
1612: # $fullkeyp contains the full part/id # for the extraction of proper parameters
1613: # $tempkeyp contains part 0 only (no ids - ie, subparts)
1614: # When storing information, store as part 0
1615: # When requesting information, request from full part
1616: #-------------------------------------------------------------------
1.210 www 1617: foreach (&keysplit($keyp{$rid})) {
1.57 albertel 1618: my $tempkeyp = $_;
1619: my $fullkeyp = $tempkeyp;
1.73 albertel 1620: $tempkeyp =~ s/_\w+_/_0_/;
1.57 albertel 1621: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
1622: $part{$tempkeyp}="0";
1623: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
1624: $display{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
1625: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
1626: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
1.73 albertel 1627: $display{$tempkeyp} =~ s/_\w+_/_0_/;
1.57 albertel 1628: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
1629: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
1630: }
1631: } # end loop through keys
1632: } # end loop through ids
1633:
1634: #---------------------------------------------------- print header information
1.133 www 1635: my $setdef=&mt("Set Defaults for All Resources in Course");
1.57 albertel 1636: $r->print(<<ENDMAPONE);
1.133 www 1637: <center><h4>$setdef
1.135 albertel 1638: <font color="red"><i>$coursename</i></font><br />
1.57 albertel 1639: ENDMAPONE
1640: if ($uname) {
1641: my %name=&Apache::lonnet::userenvironment($udom,$uname,
1642: ('firstname','middlename','lastname','generation', 'id'));
1643: my $person=$name{'firstname'}.' '.$name{'middlename'}.' '
1644: .$name{'lastname'}.' '.$name{'generation'};
1.135 albertel 1645: $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
1.57 albertel 1646: } else {
1.135 albertel 1647: $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
1.57 albertel 1648: }
1649:
1.135 albertel 1650: if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
1651: $r->print("</h4>\n");
1.57 albertel 1652: #---------------------------------------------------------------- print table
1653: $r->print('<p><table border="2">');
1.130 www 1654: $r->print('<tr><th>'.&mt('Parameter Name').'</th>');
1655: $r->print('<th>'.&mt('Default Value').'</th>');
1656: $r->print('<th>'.&mt('Parameter in Effect').'</th></tr>');
1.57 albertel 1657:
1.210 www 1658: foreach (&keysinorder(\%name,\%keyorder)) {
1.168 matthew 1659: $r->print('<tr>');
1.201 www 1660: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
1.187 www 1661: \%type,\%display,$defbgone,$defbgtwo,$parmlev,$uname,$udom,$csec);
1.57 albertel 1662: }
1663: $r->print("</table></center>");
1664: } # end of $parmlev eq general
1.43 albertel 1665: }
1.44 albertel 1666: $r->print('</form></body></html>');
1.57 albertel 1667: } # end sub assessparms
1.30 www 1668:
1.59 matthew 1669:
1670: ##################################################
1671: ##################################################
1672:
1673: =pod
1674:
1675: =item crsenv
1676:
1.105 matthew 1677: Show and set course data and parameters. This is a large routine that should
1.59 matthew 1678: be simplified and shortened... someday.
1679:
1680: Inputs: $r
1681:
1682: Returns: nothing
1683:
1684: =cut
1685:
1686: ##################################################
1687: ##################################################
1.30 www 1688: sub crsenv {
1689: my $r=shift;
1690: my $setoutput='';
1.64 www 1691: my $bodytag=&Apache::loncommon::bodytag(
1692: 'Set Course Environment Parameters');
1.194 albertel 1693: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,
1694: 'Edit Course Environment');
1.190 albertel 1695: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1696: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.105 matthew 1697:
1698: #
1699: # Go through list of changes
1.190 albertel 1700: foreach (keys %env) {
1.105 matthew 1701: next if ($_!~/^form\.(.+)\_setparmval$/);
1702: my $name = $1;
1.190 albertel 1703: my $value = $env{'form.'.$name.'_value'};
1.105 matthew 1704: if ($name eq 'newp') {
1.190 albertel 1705: $name = $env{'form.newp_name'};
1.105 matthew 1706: }
1707: if ($name eq 'url') {
1708: $value=~s/^\/res\///;
1709: my $bkuptime=time;
1710: my @tmp = &Apache::lonnet::get
1711: ('environment',['url'],$dom,$crs);
1.130 www 1712: $setoutput.=&mt('Backing up previous URL').': '.
1.105 matthew 1713: &Apache::lonnet::put
1714: ('environment',
1715: {'top level map backup '.$bkuptime => $tmp[1] },
1716: $dom,$crs).
1717: '<br>';
1718: }
1719: #
1720: # Deal with modified default spreadsheets
1721: if ($name =~ /^spreadsheet_default_(classcalc|
1722: studentcalc|
1723: assesscalc)$/x) {
1724: my $sheettype = $1;
1725: if ($sheettype eq 'classcalc') {
1726: # no need to do anything since viewing the sheet will
1727: # cause it to be updated.
1728: } elsif ($sheettype eq 'studentcalc') {
1729: # expire all the student spreadsheets
1730: &Apache::lonnet::expirespread('','','studentcalc');
1731: } else {
1732: # expire all the assessment spreadsheets
1733: # this includes non-default spreadsheets, but better to
1734: # be safe than sorry.
1735: &Apache::lonnet::expirespread('','','assesscalc');
1736: # expire all the student spreadsheets
1737: &Apache::lonnet::expirespread('','','studentcalc');
1.30 www 1738: }
1.105 matthew 1739: }
1740: #
1.107 matthew 1741: # Deal with the enrollment dates
1742: if ($name =~ /^default_enrollment_(start|end)_date$/) {
1743: $value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
1744: }
1.178 raeburn 1745: # Get existing cloners
1746: my @oldcloner = ();
1747: if ($name eq 'cloners') {
1748: my %clonenames=&Apache::lonnet::dump('environment',$dom,$crs,'cloners');
1749: if ($clonenames{'cloners'} =~ /,/) {
1750: @oldcloner = split/,/,$clonenames{'cloners'};
1751: } else {
1752: $oldcloner[0] = $clonenames{'cloners'};
1753: }
1754: }
1.107 matthew 1755: #
1.105 matthew 1756: # Let the user know we made the changes
1.153 albertel 1757: if ($name && defined($value)) {
1.178 raeburn 1758: if ($name eq 'cloners') {
1759: $value =~ s/^,//;
1760: $value =~ s/,$//;
1761: }
1.105 matthew 1762: my $put_result = &Apache::lonnet::put('environment',
1763: {$name=>$value},$dom,$crs);
1764: if ($put_result eq 'ok') {
1.130 www 1765: $setoutput.=&mt('Set').' <b>'.$name.'</b> '.&mt('to').' <b>'.$value.'</b>.<br />';
1.178 raeburn 1766: if ($name eq 'cloners') {
1767: &change_clone($value,\@oldcloner);
1768: }
1.179 raeburn 1769: # Flush the course logs so course description is immediately updated
1770: if ($name eq 'description' && defined($value)) {
1771: &Apache::lonnet::flushcourselogs();
1772: }
1.105 matthew 1773: } else {
1.130 www 1774: $setoutput.=&mt('Unable to set').' <b>'.$name.'</b> '.&mt('to').
1775: ' <b>'.$value.'</b> '.&mt('due to').' '.$put_result.'.<br />';
1.30 www 1776: }
1777: }
1.38 harris41 1778: }
1.108 www 1779: # ------------------------- Re-init course environment entries for this session
1780:
1.190 albertel 1781: &Apache::lonnet::coursedescription($env{'request.course.id'});
1.105 matthew 1782:
1.30 www 1783: # -------------------------------------------------------- Get parameters again
1.45 matthew 1784:
1785: my %values=&Apache::lonnet::dump('environment',$dom,$crs);
1.140 sakharuk 1786: my $SelectStyleFile=&mt('Select Style File');
1.141 sakharuk 1787: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
1.30 www 1788: my $output='';
1.45 matthew 1789: if (! exists($values{'con_lost'})) {
1.30 www 1790: my %descriptions=
1.140 sakharuk 1791: ('url' => '<b>'.&mt('Top Level Map').'</b> '.
1.46 matthew 1792: '<a href="javascript:openbrowser'.
1.47 matthew 1793: "('envform','url','sequence')\">".
1.140 sakharuk 1794: &mt('Select Map').'</a><br /><font color=red> '.
1795: &mt('Modification may make assessment data inaccessible').
1796: '</font>',
1797: 'description' => '<b>'.&mt('Course Description').'</b>',
1.158 sakharuk 1798: 'courseid' => '<b>'.&mt('Course ID or number').
1.140 sakharuk 1799: '</b><br />'.
1800: '('.&mt('internal').', '.&mt('optional').')',
1.177 raeburn 1801: 'cloners' => '<b>'.&mt('Users allowed to clone course').'</b><br /><tt>(user:domain,user:domain)</tt><br />'.&mt('Users with active Course Coordinator role in the course automatically have the right to clone it, and can be omitted from list.'),
1.150 www 1802: 'grading' => '<b>'.&mt('Grading').'</b><br />'.
1803: '<tt>"standard", "external", or "spreadsheet"</tt> '.&Apache::loncommon::help_open_topic('GradingOptions'),
1.140 sakharuk 1804: 'default_xml_style' => '<b>'.&mt('Default XML Style File').'</b> '.
1.52 www 1805: '<a href="javascript:openbrowser'.
1806: "('envform','default_xml_style'".
1.140 sakharuk 1807: ",'sty')\">$SelectStyleFile</a><br>",
1.141 sakharuk 1808: 'question.email' => '<b>'.&mt('Feedback Addresses for Resource Content Question').
1809: '</b><br />(<tt>user:domain,'.
1.74 www 1810: 'user:domain(section;section;...;*;...),...</tt>)',
1.141 sakharuk 1811: 'comment.email' => '<b>'.&mt('Feedback Addresses for Course Content Comments').'</b><br />'.
1.74 www 1812: '(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1.141 sakharuk 1813: 'policy.email' => '<b>'.&mt('Feedback Addresses for Course Policy').'</b>'.
1.75 albertel 1814: '<br />(<tt>user:domain,user:domain(section;section;...;*;...),...</tt>)',
1.141 sakharuk 1815: 'hideemptyrows' => '<b>'.&mt('Hide Empty Rows in Spreadsheets').'</b><br />'.
1.158 sakharuk 1816: '('.&mt('"[_1]" for default hiding','<tt>yes</tt>').')',
1.141 sakharuk 1817: 'pageseparators' => '<b>'.&mt('Visibly Separate Items on Pages').'</b><br />'.
1.158 sakharuk 1818: '('.&mt('"[_1]" for visible separation','<tt>yes</tt>').', '.
1.141 sakharuk 1819: &mt('changes will not show until next login').')',
1.169 matthew 1820: 'student_classlist_view' => '<b>'.&mt('Allow students to view classlist.').'</b>'.&mt('("all":students can view all sections,"section":students can only view their own section.blank or "disabled" prevents student view.'),
1.118 matthew 1821:
1.141 sakharuk 1822: 'plc.roles.denied'=> '<b>'.&mt('Disallow live chatroom use for Roles').
1823: '</b><br />"<tt>st</tt>": '.
1.158 sakharuk 1824: &mt('student').', "<tt>ta</tt>": '.
1.118 matthew 1825: 'TA, "<tt>in</tt>": '.
1.158 sakharuk 1826: &mt('instructor').';<br /><tt>'.&mt('role,role,...').'</tt>) '.
1.118 matthew 1827: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
1828: 'plc.users.denied' =>
1.141 sakharuk 1829: '<b>'.&mt('Disallow live chatroom use for Users').'</b><br />'.
1.118 matthew 1830: '(<tt>user:domain,user:domain,...</tt>)',
1831:
1.141 sakharuk 1832: 'pch.roles.denied'=> '<b>'.&mt('Disallow Resource Discussion for Roles').
1833: '</b><br />"<tt>st</tt>": '.
1.61 albertel 1834: 'student, "<tt>ta</tt>": '.
1835: 'TA, "<tt>in</tt>": '.
1.75 albertel 1836: 'instructor;<br /><tt>role,role,...</tt>) '.
1.61 albertel 1837: Apache::loncommon::help_open_topic("Course_Disable_Discussion"),
1.53 www 1838: 'pch.users.denied' =>
1.141 sakharuk 1839: '<b>'.&mt('Disallow Resource Discussion for Users').'</b><br />'.
1.53 www 1840: '(<tt>user:domain,user:domain,...</tt>)',
1.49 matthew 1841: 'spreadsheet_default_classcalc'
1.141 sakharuk 1842: => '<b>'.&mt('Default Course Spreadsheet').'</b> '.
1.50 matthew 1843: '<a href="javascript:openbrowser'.
1844: "('envform','spreadsheet_default_classcalc'".
1.141 sakharuk 1845: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1.49 matthew 1846: 'spreadsheet_default_studentcalc'
1.141 sakharuk 1847: => '<b>'.&mt('Default Student Spreadsheet').'</b> '.
1.50 matthew 1848: '<a href="javascript:openbrowser'.
1849: "('envform','spreadsheet_default_calc'".
1.141 sakharuk 1850: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1.49 matthew 1851: 'spreadsheet_default_assesscalc'
1.141 sakharuk 1852: => '<b>'.&mt('Default Assessment Spreadsheet').'</b> '.
1.50 matthew 1853: '<a href="javascript:openbrowser'.
1854: "('envform','spreadsheet_default_assesscalc'".
1.141 sakharuk 1855: ",'spreadsheet')\">$SelectSpreadsheetFile</a><br />",
1.75 albertel 1856: 'allow_limited_html_in_feedback'
1.141 sakharuk 1857: => '<b>'.&mt('Allow limited HTML in discussion posts').'</b><br />'.
1.158 sakharuk 1858: '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
1.170 raeburn 1859: 'allow_discussion_post_editing'
1860: => '<b>'.&mt('Allow users to edit/delete their own discussion posts').'</b><br />'.
1861: '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
1.89 albertel 1862: 'rndseed'
1.140 sakharuk 1863: => '<b>'.&mt('Randomization algorithm used').'</b> <br />'.
1864: '<font color="red">'.&mt('Modifying this will make problems').' '.
1865: &mt('have different numbers and answers').'</font>',
1.151 albertel 1866: 'receiptalg'
1867: => '<b>'.&mt('Receipt algorithm used').'</b> <br />'.
1868: &mt('This controls how receipt numbers are generated.'),
1.164 sakharuk 1869: 'suppress_tries'
1870: => '<b>'.&mt('Suppress number of tries in printing').'</b>('.
1871: &mt('yes if supress').')',
1.113 sakharuk 1872: 'problem_stream_switch'
1.141 sakharuk 1873: => '<b>'.&mt('Allow problems to be split over pages').'</b><br />'.
1.158 sakharuk 1874: ' ('.&mt('"[_1]" if allowed, anything else if not','<tt>yes</tt>').')',
1.161 sakharuk 1875: 'default_paper_size'
1876: => '<b>'.&mt('Default paper type').'</b><br />'.
1877: ' ('.&mt('supported types').': Letter [8 1/2x11 in], Legal [8 1/2x14 in],'.
1878: ' Tabloid [11x17 in], Executive [7 1/2x10 in], A2 [420x594 mm],'.
1879: ' A3 [297x420 mm], A4 [210x297 mm], A5 [148x210 mm], A6 [105x148 mm])',
1.111 sakharuk 1880: 'anonymous_quiz'
1.150 www 1881: => '<b>'.&mt('Anonymous quiz/exam').'</b><br />'.
1.141 sakharuk 1882: ' (<tt><b>'.&mt('yes').'</b> '.&mt('to avoid print students names').' </tt>)',
1.217 albertel 1883: 'default_enrollment_start_date' => '<b>'.&mt('Default beginning date for student access.').'</b>',
1884: 'default_enrollment_end_date' => '<b>'.&mt('Default ending date for student access.').'</b>',
1.150 www 1885: 'nothideprivileged' => '<b>'.&mt('Privileged users that should not be hidden on staff listings').'</b>'.
1886: '<br />(<tt>user:domain,user:domain,...</tt>)',
1.140 sakharuk 1887: 'languages' => '<b>'.&mt('Languages used').'</b>',
1.115 www 1888: 'disable_receipt_display'
1.141 sakharuk 1889: => '<b>'.&mt('Disable display of problem receipts').'</b><br />'.
1.158 sakharuk 1890: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
1.163 albertel 1891: 'disablesigfigs'
1892: => '<b>'.&mt('Disable checking of Significant Figures').'</b><br />'.
1893: ' ('.&mt('"[_1]" to disable, anything else if not','<tt>yes</tt>').')',
1.149 albertel 1894: 'tthoptions'
1895: => '<b>'.&mt('Default set of options to pass to tth/m when converting tex').'</b>'
1.107 matthew 1896: );
1.177 raeburn 1897: my @Display_Order = ('url','description','courseid','cloners','grading',
1.107 matthew 1898: 'default_xml_style','pageseparators',
1899: 'question.email','comment.email','policy.email',
1.169 matthew 1900: 'student_classlist_view',
1.118 matthew 1901: 'plc.roles.denied','plc.users.denied',
1.107 matthew 1902: 'pch.roles.denied','pch.users.denied',
1903: 'allow_limited_html_in_feedback',
1.170 raeburn 1904: 'allow_discussion_post_editing',
1.108 www 1905: 'languages',
1.150 www 1906: 'nothideprivileged',
1.107 matthew 1907: 'rndseed',
1.151 albertel 1908: 'receiptalg',
1.107 matthew 1909: 'problem_stream_switch',
1.164 sakharuk 1910: 'suppress_tries',
1.161 sakharuk 1911: 'default_paper_size',
1.115 www 1912: 'disable_receipt_display',
1.107 matthew 1913: 'spreadsheet_default_classcalc',
1914: 'spreadsheet_default_studentcalc',
1915: 'spreadsheet_default_assesscalc',
1916: 'hideemptyrows',
1917: 'default_enrollment_start_date',
1918: 'default_enrollment_end_date',
1.163 albertel 1919: 'tthoptions',
1920: 'disablesigfigs'
1.107 matthew 1921: );
1922: foreach my $parameter (sort(keys(%values))) {
1.142 raeburn 1923: unless ($parameter =~ m/^internal\./) {
1924: if (! $descriptions{$parameter}) {
1925: $descriptions{$parameter}=$parameter;
1926: push(@Display_Order,$parameter);
1927: }
1928: }
1.43 albertel 1929: }
1.107 matthew 1930: foreach my $parameter (@Display_Order) {
1931: my $description = $descriptions{$parameter};
1.51 matthew 1932: # onchange is javascript to automatically check the 'Set' button.
1.69 www 1933: my $onchange = 'onFocus="javascript:window.document.forms'.
1.107 matthew 1934: "['envform'].elements['".$parameter."_setparmval']".
1.51 matthew 1935: '.checked=true;"';
1.107 matthew 1936: $output .= '<tr><td>'.$description.'</td>';
1937: if ($parameter =~ /^default_enrollment_(start|end)_date$/) {
1938: $output .= '<td>'.
1939: &Apache::lonhtmlcommon::date_setter('envform',
1940: $parameter.'_value',
1941: $values{$parameter},
1942: $onchange).
1943: '</td>';
1944: } else {
1945: $output .= '<td>'.
1946: &Apache::lonhtmlcommon::textbox($parameter.'_value',
1947: $values{$parameter},
1948: 40,$onchange).'</td>';
1949: }
1950: $output .= '<td>'.
1951: &Apache::lonhtmlcommon::checkbox($parameter.'_setparmval').
1952: '</td>';
1953: $output .= "</tr>\n";
1.51 matthew 1954: }
1.69 www 1955: my $onchange = 'onFocus="javascript:window.document.forms'.
1.51 matthew 1956: '[\'envform\'].elements[\'newp_setparmval\']'.
1957: '.checked=true;"';
1.130 www 1958: $output.='<tr><td><i>'.&mt('Create New Environment Variable').'</i><br />'.
1.51 matthew 1959: '<input type="text" size=40 name="newp_name" '.
1960: $onchange.' /></td><td>'.
1961: '<input type="text" size=40 name="newp_value" '.
1962: $onchange.' /></td><td>'.
1963: '<input type="checkbox" name="newp_setparmval" /></td></tr>';
1.43 albertel 1964: }
1.157 sakharuk 1965: my %lt=&Apache::lonlocal::texthash(
1966: 'par' => 'Parameter',
1967: 'val' => 'Value',
1968: 'set' => 'Set',
1969: 'sce' => 'Set Course Environment'
1970: );
1971:
1.140 sakharuk 1972: my $Parameter=&mt('Parameter');
1973: my $Value=&mt('Value');
1.141 sakharuk 1974: my $Set=&mt('Set');
1.167 albertel 1975: my $browse_js=&Apache::loncommon::browser_and_searcher_javascript('parmset');
1.183 albertel 1976: my $html=&Apache::lonxml::xmlbegin();
1.190 albertel 1977: $r->print(<<ENDenv);
1.183 albertel 1978: $html
1979: <head>
1.46 matthew 1980: <script type="text/javascript" language="Javascript" >
1.155 albertel 1981: $browse_js
1.46 matthew 1982: </script>
1.30 www 1983: <title>LON-CAPA Course Environment</title>
1984: </head>
1.64 www 1985: $bodytag
1.193 albertel 1986: $breadcrumbs
1987: <form method="post" action="/adm/parmset?action=crsenv" name="envform">
1.30 www 1988: $setoutput
1989: <p>
1990: <table border=2>
1.157 sakharuk 1991: <tr><th>$lt{'par'}</th><th>$lt{'val'}</th><th>$lt{'set'}?</th></tr>
1.30 www 1992: $output
1993: </table>
1.157 sakharuk 1994: <input type="submit" name="crsenv" value="$lt{'sce'}">
1.30 www 1995: </form>
1996: </body>
1997: </html>
1.190 albertel 1998: ENDenv
1.30 www 1999: }
1.120 www 2000: ##################################################
1.207 www 2001: # Overview mode
2002: ##################################################
1.124 www 2003: my $tableopen;
2004:
2005: sub tablestart {
2006: if ($tableopen) {
2007: return '';
2008: } else {
2009: $tableopen=1;
1.130 www 2010: return '<table border="2"><tr><th>'.&mt('Parameter').'</th><th>'.
2011: &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
1.124 www 2012: }
2013: }
2014:
2015: sub tableend {
2016: if ($tableopen) {
2017: $tableopen=0;
2018: return '</table>';
2019: } else {
2020: return'';
2021: }
2022: }
2023:
1.207 www 2024: sub readdata {
2025: my ($crs,$dom)=@_;
2026: # Read coursedata
2027: my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
2028: # Read userdata
2029:
2030: my $classlist=&Apache::loncoursedata::get_classlist();
2031: foreach (keys %$classlist) {
2032: # the following undefs are for 'domain', and 'username' respectively.
2033: if ($_=~/^(\w+)\:(\w+)$/) {
2034: my ($tuname,$tudom)=($1,$2);
2035: my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
2036: foreach my $userkey (keys %{$useropt}) {
2037: if ($userkey=~/^$env{'request.course.id'}/) {
2038: my $newkey=$userkey;
2039: $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
2040: $$resourcedata{$newkey}=$$useropt{$userkey};
2041: }
2042: }
2043: }
2044: }
2045: return $resourcedata;
2046: }
2047:
2048:
1.124 www 2049: # Setting
1.208 www 2050:
2051: sub storedata {
2052: my ($r,$crs,$dom)=@_;
1.207 www 2053: # Set userlevel immediately
2054: # Do an intermediate store of course level
2055: my $olddata=&readdata($crs,$dom);
1.124 www 2056: my %newdata=();
2057: undef %newdata;
2058: my @deldata=();
2059: undef @deldata;
1.190 albertel 2060: foreach (keys %env) {
1.124 www 2061: if ($_=~/^form\.([a-z]+)\_(.+)$/) {
2062: my $cmd=$1;
2063: my $thiskey=$2;
1.207 www 2064: my ($tuname,$tudom)=&extractuser($thiskey);
2065: my $tkey=$thiskey;
2066: if ($tuname) {
2067: $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
2068: }
1.124 www 2069: if ($cmd eq 'set') {
1.190 albertel 2070: my $data=$env{$_};
1.212 www 2071: my $typeof=$env{'form.typeof_'.$thiskey};
2072: if ($$olddata{$thiskey} ne $data) {
1.207 www 2073: if ($tuname) {
1.212 www 2074: if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
2075: $tkey.'.type' => $typeof},
2076: $tudom,$tuname) eq 'ok') {
1.207 www 2077: $r->print('<br />'.&mt('Stored modified parameter for').' '.
2078: &Apache::loncommon::plainname($tuname,$tudom));
2079: } else {
2080: $r->print('<h2><font color="red">'.
2081: &mt('Error storing parameters').'</font></h2>');
2082: }
2083: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2084: } else {
2085: $newdata{$thiskey}=$data;
1.212 www 2086: $newdata{$thiskey.'.type'}=$typeof;
2087: }
1.207 www 2088: }
1.124 www 2089: } elsif ($cmd eq 'del') {
1.207 www 2090: if ($tuname) {
2091: if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
2092: $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
2093: } else {
2094: $r->print('<h2><font color="red">'.
2095: &mt('Error deleting parameters').'</font></h2>');
2096: }
2097: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2098: } else {
2099: push (@deldata,$thiskey);
2100: }
1.124 www 2101: } elsif ($cmd eq 'datepointer') {
1.190 albertel 2102: my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
1.212 www 2103: my $typeof=$env{'form.typeof_'.$thiskey};
1.207 www 2104: if (defined($data) and $$olddata{$thiskey} ne $data) {
2105: if ($tuname) {
1.212 www 2106: if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
2107: $tkey.'.type' => $typeof},
2108: $tudom,$tuname) eq 'ok') {
1.207 www 2109: $r->print('<br />'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
2110: } else {
2111: $r->print('<h2><font color="red">'.
2112: &mt('Error storing parameters').'</font></h2>');
2113: }
2114: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2115: } else {
1.212 www 2116: $newdata{$thiskey}=$data;
2117: $newdata{$thiskey.'.type'}=$typeof;
1.207 www 2118: }
2119: }
1.124 www 2120: }
2121: }
2122: }
1.207 www 2123: # Store all course level
1.144 www 2124: my $delentries=$#deldata+1;
2125: my @newdatakeys=keys %newdata;
2126: my $putentries=$#newdatakeys+1;
2127: if ($delentries) {
2128: if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
2129: $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
2130: } else {
2131: $r->print('<h2><font color="red">'.
2132: &mt('Error deleting parameters').'</font></h2>');
2133: }
1.205 www 2134: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
1.144 www 2135: }
2136: if ($putentries) {
2137: if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
1.212 www 2138: $r->print('<h3>'.&mt('Stored [_1] parameter(s)',$putentries/2).'</h3>');
1.144 www 2139: } else {
2140: $r->print('<h2><font color="red">'.
2141: &mt('Error storing parameters').'</font></h2>');
2142: }
1.205 www 2143: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
1.144 www 2144: }
1.208 www 2145: }
1.207 www 2146:
1.208 www 2147: sub extractuser {
2148: my $key=shift;
2149: return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./);
2150: }
1.206 www 2151:
1.208 www 2152: sub listdata {
1.214 www 2153: my ($r,$resourcedata,$listdata,$sortorder)=@_;
1.207 www 2154: # Start list output
1.206 www 2155:
1.122 www 2156: my $oldsection='';
2157: my $oldrealm='';
2158: my $oldpart='';
1.123 www 2159: my $pointer=0;
1.124 www 2160: $tableopen=0;
1.145 www 2161: my $foundkeys=0;
1.214 www 2162: foreach my $thiskey (sort {
2163: if ($sortorder eq 'realmstudent') {
2164: my ($astudent,$arealm)=($a=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/);
2165: my ($bstudent,$brealm)=($b=~/^$env{'request.course.id'}\.([^\.]+)\.(.+)\.[^\.]+$/);
2166: ($arealm cmp $brealm) || ($astudent cmp $bstudent);
2167: } else {
2168: $a cmp $b;
2169: }
2170: } keys %{$listdata}) {
1.211 www 2171: if ($$listdata{$thiskey.'.type'}) {
2172: my $thistype=$$listdata{$thiskey.'.type'};
2173: if ($$resourcedata{$thiskey.'.type'}) {
2174: $thistype=$$resourcedata{$thiskey.'.type'};
2175: }
1.207 www 2176: my ($middle,$part,$name)=
2177: ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
1.130 www 2178: my $section=&mt('All Students');
1.207 www 2179: if ($middle=~/^\[(.*)\]/) {
1.206 www 2180: my $issection=$1;
2181: if ($issection=~/^useropt\:(\w+)\:(\w+)/) {
2182: $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
2183: } else {
2184: $section=&mt('Group/Section').': '.$issection;
2185: }
1.207 www 2186: $middle=~s/^\[(.*)\]//;
1.122 www 2187: }
1.207 www 2188: $middle=~s/\.+$//;
2189: $middle=~s/^\.+//;
1.130 www 2190: my $realm='<font color="red">'.&mt('All Resources').'</font>';
1.122 www 2191: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
1.174 albertel 2192: $realm='<font color="green">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><font color="#aaaaaa" size="-2">('.$1.')</font></font>';
1.122 www 2193: } elsif ($middle) {
1.174 albertel 2194: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
2195: $realm='<font color="orange">'.&mt('Resource').': '.&Apache::lonnet::gettitle($middle).' <br /><font color="#aaaaaa" size="-2">('.$url.' in '.$map.' id: '.$id.')</font></font>';
1.122 www 2196: }
1.214 www 2197: if ($sortorder eq 'realmstudent') {
2198: if ($realm ne $oldrealm) {
2199: $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
2200: $oldrealm=$realm;
2201: $oldsection='';
2202: }
2203: if ($section ne $oldsection) {
2204: $r->print(&tableend()."\n<h2>$section</h2>");
2205: $oldsection=$section;
2206: $oldpart='';
2207: }
2208: } else {
2209: if ($section ne $oldsection) {
2210: $r->print(&tableend()."\n<hr /><h1>$section</h1>");
2211: $oldsection=$section;
2212: $oldrealm='';
2213: }
2214: if ($realm ne $oldrealm) {
2215: $r->print(&tableend()."\n<h2>$realm</h2>");
2216: $oldrealm=$realm;
2217: $oldpart='';
2218: }
1.122 www 2219: }
2220: if ($part ne $oldpart) {
1.124 www 2221: $r->print(&tableend().
1.214 www 2222: "\n<font color='blue'>".&mt('Part').": $part</font>");
1.122 www 2223: $oldpart=$part;
2224: }
1.123 www 2225: #
2226: # Ready to print
2227: #
1.124 www 2228: $r->print(&tablestart().'<tr><td><b>'.$name.
2229: ':</b></td><td><input type="checkbox" name="del_'.
2230: $thiskey.'" /></td><td>');
1.145 www 2231: $foundkeys++;
1.213 www 2232: if (&isdateparm($thistype)) {
1.123 www 2233: my $jskey='key_'.$pointer;
2234: $pointer++;
2235: $r->print(
2236: &Apache::lonhtmlcommon::date_setter('overviewform',
2237: $jskey,
1.219 www 2238: $$resourcedata{$thiskey},
2239: '',1).
1.123 www 2240: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'
2241: );
1.219 www 2242: } elsif ($thistype eq 'string_yesno') {
2243: $r->print('<label><input type="radio" name="set_'.$thiskey.
2244: '" value="yes"');
2245: if ($$resourcedata{$thiskey} eq 'yes') {
2246: $r->print(' checked="checked"');
2247: }
2248: $r->print(' />'.&mt('Yes').'</label> ');
2249: $r->print('<label><input type="radio" name="set_'.$thiskey.
2250: '" value="no"');
2251: if ($$resourcedata{$thiskey} eq 'no') {
2252: $r->print(' checked="checked"');
2253: }
2254: $r->print(' />'.&mt('No').'</label>');
1.123 www 2255: } else {
1.211 www 2256: $r->print('<input type="text" name="set_'.$thiskey.'" value="'.
1.206 www 2257: $$resourcedata{$thiskey}.'">');
1.123 www 2258: }
1.211 www 2259: $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
2260: $thistype.'">');
1.124 www 2261: $r->print('</td></tr>');
1.122 www 2262: }
1.121 www 2263: }
1.208 www 2264: return $foundkeys;
2265: }
2266:
2267: sub newoverview {
2268: my $r=shift;
1.216 www 2269: my $bodytag=&Apache::loncommon::bodytag('Set Parameters');
1.208 www 2270: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2271: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2272: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
2273: my $html=&Apache::lonxml::xmlbegin();
2274: $r->print(<<ENDOVER);
2275: $html
2276: <head>
2277: <title>LON-CAPA Parameters</title>
2278: </head>
2279: $bodytag
2280: $breadcrumbs
1.211 www 2281: <form method="post" action="/adm/parmset?action=newoverview" name="parmform">
1.208 www 2282: ENDOVER
1.211 www 2283: my @ids=();
2284: my %typep=();
2285: my %keyp=();
2286: my %allparms=();
2287: my %allparts=();
2288: my %allmaps=();
2289: my %mapp=();
2290: my %symbp=();
2291: my %maptitles=();
2292: my %uris=();
2293: my %keyorder=&standardkeyorder();
2294: my %defkeytype=();
2295:
2296: my %alllevs=();
2297: $alllevs{'Resource Level'}='full';
1.215 www 2298: $alllevs{'Map/Folder Level'}='map';
1.211 www 2299: $alllevs{'Course Level'}='general';
2300:
2301: my $csec=$env{'form.csec'};
2302:
2303: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
2304: my $pschp=$env{'form.pschp'};
2305: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
2306: if (!@psprt) { $psprt[0]='0'; }
2307:
2308: my @selected_sections =
2309: &Apache::loncommon::get_env_multiple('form.Section');
2310: @selected_sections = ('all') if (! @selected_sections);
2311: foreach (@selected_sections) {
2312: if ($_ eq 'all') {
2313: @selected_sections = ('all');
2314: }
2315: }
2316:
2317: my $pssymb='';
2318: my $parmlev='';
2319:
2320: unless ($env{'form.parmlev'}) {
2321: $parmlev = 'map';
2322: } else {
2323: $parmlev = $env{'form.parmlev'};
2324: }
2325:
2326: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
2327: \%mapp, \%symbp,\%maptitles,\%uris,
2328: \%keyorder,\%defkeytype);
2329:
2330: # Menu to select levels, etc
2331:
2332: $r->print('<table border="1"><tr><td>');
2333: &levelmenu($r,\%alllevs,$parmlev);
2334: if ($parmlev ne 'general') {
2335: $r->print('<td>');
2336: &mapmenu($r,\%allmaps,$pschp,\%maptitles);
2337: $r->print('</td>');
2338: }
2339: $r->print('</td></tr></table>');
2340:
2341: $r->print('<table border="1"><tr><td>');
2342: &parmmenu($r,\%allparms,\@pscat,\%keyorder);
2343: $r->print('</td><td>');
2344: &partmenu($r,\%allparts,\@psprt);
2345: $r->print('</td><td>');
2346: §ionmenu($r,\@selected_sections);
1.214 www 2347:
2348: $r->print('</td></tr></table>');
2349:
2350: my $sortorder=$env{'form.sortorder'};
2351: unless ($sortorder) { $sortorder='realmstudent'; }
2352: &sortmenu($r,$sortorder);
2353:
2354: $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
1.211 www 2355:
2356: # Build the list data hash from the specified parms
2357:
2358: my $listdata;
2359: %{$listdata}=();
2360:
2361: foreach my $cat (@pscat) {
2362: foreach my $section (@selected_sections) {
2363: foreach my $part (@psprt) {
1.212 www 2364: my $rootparmkey=$env{'request.course.id'};
1.211 www 2365: if (($section ne 'all') && ($section ne 'none') && ($section)) {
1.212 www 2366: $rootparmkey.='.['.$section.']';
1.211 www 2367: }
2368: if ($parmlev eq 'general') {
2369: # course-level parameter
1.212 www 2370: my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
2371: $$listdata{$newparmkey}=1;
2372: $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
1.211 www 2373: } elsif ($parmlev eq 'map') {
1.212 www 2374: # map-level parameter
2375: foreach my $mapid (keys %allmaps) {
2376: if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
2377: my $newparmkey=$rootparmkey.'.'.$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
1.211 www 2378: $$listdata{$newparmkey}=1;
2379: $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
2380: }
2381: } else {
2382: # resource-level parameter
1.212 www 2383: foreach my $rid (@ids) {
2384: my ($map,$resid,$url)=&Apache::lonnet::decode_symb($symbp{$rid});
2385: if (($pschp ne 'all') && ($allmaps{$pschp} ne $map)) { next; }
2386: my $newparmkey=$rootparmkey.'.'.$symbp{$rid}.'.'.$part.'.'.$cat;
2387: $$listdata{$newparmkey}=1;
2388: $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
2389: }
1.211 www 2390: }
2391: }
2392: }
2393: }
2394:
1.212 www 2395: if (($env{'form.store'}) || ($env{'form.dis'})) {
1.211 www 2396:
1.212 www 2397: if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
1.211 www 2398:
2399: # Read modified data
2400:
2401: my $resourcedata=&readdata($crs,$dom);
2402:
2403: # List data
2404:
1.214 www 2405: &listdata($r,$resourcedata,$listdata,$sortorder);
1.211 www 2406: }
2407: $r->print(&tableend().
1.212 www 2408: ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Store').'" /></p>':'').
2409: '</form></body></html>');
1.208 www 2410: }
2411:
2412: sub overview {
2413: my $r=shift;
1.216 www 2414: my $bodytag=&Apache::loncommon::bodytag('Modify Parameters');
1.208 www 2415: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2416: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2417: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Overview');
2418: my $html=&Apache::lonxml::xmlbegin();
2419: $r->print(<<ENDOVER);
2420: $html
2421: <head>
2422: <title>LON-CAPA Parameters</title>
2423: </head>
2424: $bodytag
2425: $breadcrumbs
2426: <form method="post" action="/adm/parmset?action=setoverview" name="overviewform">
2427: ENDOVER
2428: # Store modified
2429:
2430: &storedata($r,$crs,$dom);
2431:
2432: # Read modified data
2433:
2434: my $resourcedata=&readdata($crs,$dom);
2435:
1.214 www 2436:
2437: my $sortorder=$env{'form.sortorder'};
2438: unless ($sortorder) { $sortorder='realmstudent'; }
2439: &sortmenu($r,$sortorder);
2440:
1.208 www 2441: # List data
2442:
1.214 www 2443: my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder);
1.208 www 2444:
1.145 www 2445: $r->print(&tableend().'<p>'.
1.208 www 2446: ($foundkeys?'<input type="submit" value="'.&mt('Modify Parameters').'" />':&mt('There are no parameters.')).'</p></form></body></html>');
1.120 www 2447: }
1.121 www 2448:
1.59 matthew 2449: ##################################################
2450: ##################################################
1.178 raeburn 2451:
2452: =pod
2453:
2454: =item change clone
2455:
2456: Modifies the list of courses a user can clone (stored
2457: in the user's environemnt.db file), called when a
2458: change is made to the list of users allowed to clone
2459: a course.
2460:
2461: Inputs: $action,$cloner
2462: where $action is add or drop, and $cloner is identity of
2463: user for whom cloning ability is to be changed in course.
2464:
2465: Returns:
2466:
2467: =cut
2468:
2469: ##################################################
2470: ##################################################
2471:
2472:
2473: sub change_clone {
2474: my ($clonelist,$oldcloner) = @_;
2475: my ($uname,$udom);
1.190 albertel 2476: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2477: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.178 raeburn 2478: my $clone_crs = $cnum.':'.$cdom;
2479:
2480: if ($cnum && $cdom) {
2481: my @allowclone = ();
2482: if ($clonelist =~ /,/) {
2483: @allowclone = split/,/,$clonelist;
2484: } else {
2485: $allowclone[0] = $clonelist;
2486: }
2487: foreach my $currclone (@allowclone) {
2488: if (!grep/^$currclone$/,@$oldcloner) {
2489: ($uname,$udom) = split/:/,$currclone;
2490: if ($uname && $udom) {
2491: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
2492: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
2493: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
2494: if ($currclonecrs{'cloneable'} eq '') {
2495: $currclonecrs{'cloneable'} = $clone_crs;
2496: } else {
2497: $currclonecrs{'cloneable'} .= ','.$clone_crs;
2498: }
2499: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
2500: }
2501: }
2502: }
2503: }
2504: }
2505: foreach my $oldclone (@$oldcloner) {
2506: if (!grep/^$oldclone$/,@allowclone) {
2507: ($uname,$udom) = split/:/,$oldclone;
2508: if ($uname && $udom) {
2509: unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
2510: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
2511: my %newclonecrs = ();
2512: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
2513: if ($currclonecrs{'cloneable'} =~ /,/) {
2514: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
2515: foreach (@currclonecrs) {
2516: unless ($_ eq $clone_crs) {
2517: $newclonecrs{'cloneable'} .= $_.',';
2518: }
2519: }
2520: $newclonecrs{'cloneable'} =~ s/,$//;
2521: } else {
2522: $newclonecrs{'cloneable'} = '';
2523: }
2524: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
2525: }
2526: }
2527: }
2528: }
2529: }
2530: }
2531: }
2532:
1.193 albertel 2533:
2534: ##################################################
2535: ##################################################
2536:
2537: =pod
2538:
2539: =item * header
2540:
2541: Output html header for page
2542:
2543: =cut
2544:
2545: ##################################################
2546: ##################################################
2547: sub header {
2548: my $html=&Apache::lonxml::xmlbegin();
2549: my $bodytag=&Apache::loncommon::bodytag('Parameter Manager');
2550: my $title = &mt('LON-CAPA Parameter Manager');
2551: return(<<ENDHEAD);
2552: $html
2553: <head>
2554: <title>$title</title>
2555: </head>
2556: $bodytag
2557: ENDHEAD
2558: }
2559: ##################################################
2560: ##################################################
2561: sub print_main_menu {
2562: my ($r,$parm_permission)=@_;
2563: #
2564: $r->print(<<ENDMAINFORMHEAD);
2565: <form method="post" enctype="multipart/form-data"
2566: action="/adm/parmset" name="studentform">
2567: ENDMAINFORMHEAD
2568: #
1.195 albertel 2569: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2570: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.193 albertel 2571: my @menu =
2572: (
2573: { text => 'Set Course Environment Parameters',
1.204 www 2574: action => 'crsenv',
1.193 albertel 2575: permission => $parm_permission,
2576: },
1.216 www 2577: { text => 'Set/Modify Resource Parameters - Helper Mode',
1.193 albertel 2578: url => '/adm/helper/parameter.helper',
2579: permission => $parm_permission,
2580: },
1.216 www 2581: { text => 'Modify Resource Parameters - Overview Mode',
1.193 albertel 2582: action => 'setoverview',
2583: permission => $parm_permission,
1.208 www 2584: },
1.216 www 2585: { text => 'Set Resource Parameters - Overview Mode',
1.208 www 2586: action => 'newoverview',
2587: permission => $parm_permission,
1.193 albertel 2588: },
1.216 www 2589: { text => 'Set/Modify Resource Parameters - Table Mode',
1.193 albertel 2590: action => 'settable',
2591: permission => $parm_permission,
1.204 www 2592: help => 'Cascading_Parameters',
1.193 albertel 2593: },
1.220 www 2594: { text => 'Set Parameter Setting Default Actions',
2595: action => 'setdefaults',
2596: permission => $parm_permission,
2597: },
1.193 albertel 2598: );
2599: my $menu_html = '';
2600: foreach my $menu_item (@menu) {
2601: next if (! $menu_item->{'permission'});
2602: $menu_html.='<p>';
2603: $menu_html.='<font size="+1">';
2604: if (exists($menu_item->{'url'})) {
2605: $menu_html.=qq{<a href="$menu_item->{'url'}">};
2606: } else {
2607: $menu_html.=
2608: qq{<a href="/adm/parmset?action=$menu_item->{'action'}">};
2609: }
2610: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
2611: if (exists($menu_item->{'help'})) {
2612: $menu_html.=
2613: &Apache::loncommon::help_open_topic($menu_item->{'help'});
2614: }
2615: $menu_html.='</p>'.$/;
2616: }
2617: $r->print($menu_html);
2618: return;
2619: }
2620:
2621:
1.220 www 2622: ##################################################
1.193 albertel 2623:
1.220 www 2624: sub defaultsetter {
2625: my $r=shift;
2626: my $bodytag=&Apache::loncommon::bodytag('Parameter Setting Default Actions');
2627: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2628: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
2629: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs(undef,'Defaults');
2630: my $html=&Apache::lonxml::xmlbegin();
2631: $r->print(<<ENDDEFHEAD);
2632: $html
2633: <head>
2634: <title>LON-CAPA Parameters</title>
2635: </head>
2636: $bodytag
2637: $breadcrumbs
2638: <form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">
2639: ENDDEFHEAD
1.221 www 2640: my @ids=();
2641: my %typep=();
2642: my %keyp=();
2643: my %allparms=();
2644: my %allparts=();
2645: my %allmaps=();
2646: my %mapp=();
2647: my %symbp=();
2648: my %maptitles=();
2649: my %uris=();
2650: my %keyorder=&standardkeyorder();
2651: my %defkeytype=();
2652:
2653: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
2654: \%mapp, \%symbp,\%maptitles,\%uris,
2655: \%keyorder,\%defkeytype);
1.224 www 2656: if ($env{'form.storerules'}) {
2657: my %newrules=();
2658: my @delrules=();
1.226 www 2659: my %triggers=();
1.225 albertel 2660: foreach my $key (keys(%env)) {
2661: if ($key=~/^form\.(\w+)\_action$/) {
1.224 www 2662: my $tempkey=$1;
1.226 www 2663: my $action=$env{$key};
2664: if ($action) {
2665: $newrules{$tempkey.'_action'}=$action;
2666: if ($action ne 'default') {
2667: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
2668: $triggers{$whichparm}.=$tempkey.':';
2669: }
2670: $newrules{$tempkey.'_type'}=$defkeytype{$tempkey};
1.224 www 2671: if (&isdateparm($defkeytype{$tempkey})) {
1.227 www 2672: $newrules{$tempkey.'_days'}=$env{'form.'.$tempkey.'_days'};
1.224 www 2673: $newrules{$tempkey.'_hours'}=$env{'form.'.$tempkey.'_hours'};
2674: $newrules{$tempkey.'_min'}=$env{'form.'.$tempkey.'_min'};
2675: $newrules{$tempkey.'_sec'}=$env{'form.'.$tempkey.'_sec'};
2676: } else {
2677: $newrules{$tempkey.'_value'}=$env{'form.'.$tempkey.'_value'};
1.227 www 2678: $newrules{$tempkey.'_triggervalue'}=$env{'form.'.$tempkey.'_triggervalue'};
1.224 www 2679: }
2680: } else {
1.225 albertel 2681: push(@delrules,$tempkey.'_action');
1.226 www 2682: push(@delrules,$tempkey.'_type');
1.225 albertel 2683: push(@delrules,$tempkey.'_hours');
2684: push(@delrules,$tempkey.'_min');
2685: push(@delrules,$tempkey.'_sec');
2686: push(@delrules,$tempkey.'_value');
1.224 www 2687: }
2688: }
2689: }
1.226 www 2690: foreach my $key (keys %allparms) {
2691: $newrules{$key.'_triggers'}=$triggers{$key};
2692: }
1.224 www 2693: &Apache::lonnet::put('parmdefactions',\%newrules,$dom,$crs);
2694: &Apache::lonnet::del('parmdefactions',\@delrules,$dom,$crs);
2695: &resetrulescache();
2696: }
1.227 www 2697: my %lt=&Apache::lonlocal::texthash('days' => 'Days',
2698: 'hours' => 'Hours',
1.221 www 2699: 'min' => 'Minutes',
2700: 'sec' => 'Seconds',
2701: 'yes' => 'Yes',
2702: 'no' => 'No');
1.222 www 2703: my @standardoptions=('','default');
2704: my @standarddisplay=('',&mt('Default value when manually setting'));
2705: my @dateoptions=('','default');
2706: my @datedisplay=('',&mt('Default value when manually setting'));
2707: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
2708: unless ($tempkey) { next; }
2709: push @standardoptions,'when_setting_'.$tempkey;
2710: push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
2711: if (&isdateparm($defkeytype{$tempkey})) {
2712: push @dateoptions,'later_than_'.$tempkey;
2713: push @datedisplay,&mt('Automatically set later than ').$tempkey;
2714: push @dateoptions,'earlier_than_'.$tempkey;
2715: push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
2716: }
2717: }
1.221 www 2718: $r->print("\n<table border='1'><tr><th>".&mt('Rule for parameter').'</th><th>'.
1.222 www 2719: &mt('Action').'</th><th>'.&mt('Value').'</th></tr>');
1.221 www 2720: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
1.222 www 2721: unless ($tempkey) { next; }
1.221 www 2722: $r->print("\n<tr><td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
1.222 www 2723: my $action=&rulescache($tempkey.'_action');
2724: $r->print('<select name="'.$tempkey.'_action">');
2725: if (&isdateparm($defkeytype{$tempkey})) {
2726: for (my $i=0;$i<=$#dateoptions;$i++) {
2727: if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
2728: $r->print("\n<option value='$dateoptions[$i]'".
2729: ($dateoptions[$i] eq $action?' selected="selected"':'').
2730: ">$datedisplay[$i]</option>");
2731: }
2732: } else {
2733: for (my $i=0;$i<=$#standardoptions;$i++) {
2734: if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
2735: $r->print("\n<option value='$standardoptions[$i]'".
2736: ($standardoptions[$i] eq $action?' selected="selected"':'').
2737: ">$standarddisplay[$i]</option>");
2738: }
2739: }
2740: $r->print('</select>');
1.227 www 2741: unless (&isdateparm($defkeytype{$tempkey})) {
2742: $r->print("\n<br />".&mt('Triggering value(s) of other parameter (optional, comma-separated):').
2743: '<input type="text" size="20" name="'.$tempkey.'_triggervalue" value="'.&rulescache($tempkey.'_triggervalue').'" />');
2744: }
1.222 www 2745: $r->print("\n</td><td>\n");
2746:
1.221 www 2747: if (&isdateparm($defkeytype{$tempkey})) {
1.227 www 2748: my $days=&rulescache($tempkey.'_days');
1.222 www 2749: my $hours=&rulescache($tempkey.'_hours');
2750: my $min=&rulescache($tempkey.'_min');
2751: my $sec=&rulescache($tempkey.'_sec');
1.221 www 2752: $r->print(<<ENDINPUTDATE);
1.227 www 2753: <input name="$tempkey\_days" type="text" size="4" value="$days" />$lt{'days'}<br />
1.222 www 2754: <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
2755: <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
2756: <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
1.221 www 2757: ENDINPUTDATE
2758: } elsif ($defkeytype{$tempkey} eq 'string_yesno') {
1.222 www 2759: my $yeschecked='';
2760: my $nochecked='';
2761: if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked='checked="checked"'; }
2762: if (&rulescache($tempkey.'_value') eq 'no') { $nochecked='checked="checked"'; }
2763:
1.221 www 2764: $r->print(<<ENDYESNO);
1.224 www 2765: <label><input type="radio" name="$tempkey\_value" value="yes" $yeschecked /> $lt{'yes'}</label><br />
2766: <label><input type="radio" name="$tempkey\_value" value="no" $nochecked /> $lt{'no'}</label>
1.221 www 2767: ENDYESNO
2768: } else {
1.224 www 2769: $r->print('<input type="text" size="20" name="'.$tempkey.'_value" value="'.&rulescache($tempkey.'_value').'" />');
1.221 www 2770: }
2771: $r->print('</td></tr>');
2772: }
1.224 www 2773: $r->print("</table>\n<input type='submit' name='storerules' value='".
2774: &mt('Store Rules')."' /></form>\n</body>\n</html>");
1.220 www 2775: return;
2776: }
1.193 albertel 2777:
1.178 raeburn 2778: ##################################################
2779: ##################################################
1.30 www 2780:
1.59 matthew 2781: =pod
2782:
1.83 bowersj2 2783: =item * handler
1.59 matthew 2784:
2785: Main handler. Calls &assessparms and &crsenv subroutines.
2786:
2787: =cut
2788: ##################################################
2789: ##################################################
1.220 www 2790: # use Data::Dumper;
2791:
1.30 www 2792: sub handler {
1.43 albertel 2793: my $r=shift;
1.30 www 2794:
1.43 albertel 2795: if ($r->header_only) {
1.126 www 2796: &Apache::loncommon::content_type($r,'text/html');
1.43 albertel 2797: $r->send_http_header;
2798: return OK;
2799: }
1.193 albertel 2800: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.205 www 2801: ['action','state',
2802: 'pres_marker',
2803: 'pres_value',
1.206 www 2804: 'pres_type',
1.215 www 2805: 'udom','uname','symb']);
1.131 www 2806:
1.83 bowersj2 2807:
1.193 albertel 2808: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.194 albertel 2809: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
2810: text=>"Parameter Manager",
1.204 www 2811: faq=>10,
1.194 albertel 2812: bug=>'Instructor Interface'});
1.203 www 2813:
1.30 www 2814: # ----------------------------------------------------- Needs to be in a course
1.194 albertel 2815: my $parm_permission =
2816: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
1.190 albertel 2817: &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
1.193 albertel 2818: $env{'request.course.sec'}));
1.194 albertel 2819: if ($env{'request.course.id'} && $parm_permission) {
1.193 albertel 2820:
2821: # Start Page
1.126 www 2822: &Apache::loncommon::content_type($r,'text/html');
1.106 www 2823: $r->send_http_header;
1.30 www 2824:
1.203 www 2825:
2826: # id numbers can change on re-ordering of folders
2827:
2828: &resetsymbcache();
2829:
1.193 albertel 2830: #
2831: # Main switch on form.action and form.state, as appropriate
2832: #
2833: # Check first if coming from someone else headed directly for
2834: # the table mode
2835: if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
2836: && (!$env{'form.dis'})) || ($env{'form.symb'})) {
2837: &assessparms($r);
2838:
2839: } elsif (! exists($env{'form.action'})) {
2840: $r->print(&header());
1.194 albertel 2841: $r->print(&Apache::lonhtmlcommon::breadcrumbs(undef,
2842: 'Parameter Manager'));
1.193 albertel 2843: &print_main_menu($r,$parm_permission);
2844: } elsif ($env{'form.action'} eq 'crsenv' && $parm_permission) {
1.194 albertel 2845: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=crsenv',
2846: text=>"Course Environment"});
1.193 albertel 2847: &crsenv($r);
2848: } elsif ($env{'form.action'} eq 'setoverview' && $parm_permission) {
1.194 albertel 2849: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
2850: text=>"Overview Mode"});
1.121 www 2851: &overview($r);
1.208 www 2852: } elsif ($env{'form.action'} eq 'newoverview' && $parm_permission) {
2853: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
2854: text=>"Overview Mode"});
2855: &newoverview($r);
1.220 www 2856: } elsif ($env{'form.action'} eq 'setdefaults' && $parm_permission) {
2857: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
2858: text=>"Set Defaults"});
2859: &defaultsetter($r);
2860: } elsif ($env{'form.action'} eq 'settable' && $parm_permission) {
1.194 albertel 2861: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
1.204 www 2862: text=>"Table Mode",
2863: help => 'Course_Setting_Parameters'});
1.121 www 2864: &assessparms($r);
1.193 albertel 2865: }
2866:
1.43 albertel 2867: } else {
1.1 www 2868: # ----------------------------- Not in a course, or not allowed to modify parms
1.190 albertel 2869: $env{'user.error.msg'}=
1.43 albertel 2870: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
2871: return HTTP_NOT_ACCEPTABLE;
2872: }
2873: return OK;
1.1 www 2874: }
2875:
2876: 1;
2877: __END__
2878:
1.59 matthew 2879: =pod
1.38 harris41 2880:
2881: =back
2882:
2883: =cut
1.1 www 2884:
2885:
2886:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>