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