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