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