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