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