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