File:
[LON-CAPA] /
loncom /
interface /
lonparmset.pm
Revision
1.469:
download - view:
text,
annotated -
select for diffs
Sat Aug 29 03:06:09 2009 UTC (14 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 5988.
- Log entries resulting from global date shifts do not include parmname.type,
so values were being displayed as Unix times instead of human times.
- Use type from packages.tab in cases where no type is logged to determine if
value is a time which should be converted for display.
1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
4: # $Id: lonparmset.pm,v 1.469 2009/08/29 03:06:09 raeburn 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: #
1248: # This function prints a list of parameters, which were selected. It also display a link from which you can
1249: # hide or show the complete parameter list, from which you can choose your parameters.
1250: #
1251: sub parmmenu {
1252: my ($r,$allparms,$pscat,$keyorder)=@_;
1253: my $tempkey;
1254: $r->print(<<ENDSCRIPT);
1255: <script type="text/javascript">
1256: // <![CDATA[
1257: function checkall(value, checkName) {
1258:
1259: var li = "_li";
1260: var displayOverview = "";
1261:
1262: if (value == false) {
1263: displayOverview = "none"
1264: }
1265:
1266: for (i=0; i<document.forms.parmform.elements.length; i++) {
1267: ele = document.forms.parmform.elements[i];
1268: if (ele.name == checkName) {
1269: document.forms.parmform.elements[i].checked=value;
1270: document.getElementById(document.forms.parmform.elements[i].value.concat(li)).style.display = displayOverview;
1271: }
1272: }
1273: }
1274:
1275: function checkthis(thisvalue, checkName) {
1276:
1277: document.getElementById(thisvalue.concat("_li")).style.display = "";
1278:
1279: for (i=0; i<document.forms.parmform.elements.length; i++) {
1280: ele = document.forms.parmform.elements[i];
1281: if (ele.name == checkName) {
1282: if (ele.value == thisvalue) {
1283: document.forms.parmform.elements[i].checked=true;
1284: }
1285: }
1286: }
1287: }
1288:
1289: function checkdates() {
1290: checkthis('duedate','pscat');
1291: checkthis('opendate','pscat');
1292: checkthis('answerdate','pscat');
1293: }
1294:
1295: function checkdisset() {
1296: checkthis('discussend','pscat');
1297: checkthis('discusshide','pscat');
1298: }
1299:
1300: function checkcontdates() {
1301: checkthis('contentopen','pscat');
1302: checkthis('contentclose','pscat');
1303: }
1304:
1305: function checkvisi() {
1306: checkthis('hiddenresource','pscat');
1307: checkthis('encrypturl','pscat');
1308: checkthis('problemstatus','pscat');
1309: checkthis('contentopen','pscat');
1310: checkthis('opendate','pscat');
1311: }
1312:
1313: function checkparts() {
1314: checkthis('hiddenparts','pscat');
1315: checkthis('display','pscat');
1316: checkthis('ordered','pscat');
1317: }
1318:
1319: function checkstandard() {
1320: checkall(false,'pscat');
1321: checkdates();
1322: checkthis('weight','pscat');
1323: checkthis('maxtries','pscat');
1324: }
1325:
1326: function hideParms() {
1327: document.getElementById('LC_parm_overview_parm_menu').style.display = "none";
1328: }
1329:
1330: function showParms() {
1331: document.getElementById('LC_parm_overview_parm_menu').style.display = "";
1332: }
1333:
1334: function checkboxChecked(id) {
1335: var li = "_li";
1336: var id_li = id.concat(li);
1337: if (document.getElementById(id_li).style.display == "none") {
1338: document.getElementById(id_li).style.display = "";
1339: }
1340: else {
1341: document.getElementById(id_li).style.display = "none";
1342: }
1343: }
1344: // ]]>
1345: </script>
1346: ENDSCRIPT
1347: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameters to View')));
1348:
1349: #part to print selected parms overview
1350: $r->print(&mt('Selected Parameters:').'<br />');
1351:
1352: #print out all possible parms and hide them by default
1353: $r->print('<ul>');
1354: foreach $tempkey (&keysindisplayorder($allparms,$keyorder)) {
1355: $r->print('<li id="'.$tempkey.'_li" value="'.$tempkey.'_li" name="pscat_li"');
1356: if (!($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat})) {
1357: $r->print(' style="display:none"');
1358: }
1359: $r->print('>'
1360: .($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey} : $tempkey)
1361: .'</li>'
1362: );
1363: }
1364: $r->print('</ul>'
1365: .'<p><a href="javascript:showParms()">'
1366: .&mt('Show detailed Parameter Selection')
1367: .'</a></p>'
1368: );
1369:
1370: &shortCuts($r,$allparms,$pscat,$keyorder);
1371:
1372: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1373: }
1374: # return a hash
1375: sub categories {
1376: return ('time_settings' => 'Time Settings',
1377: 'grading' => 'Grading',
1378: 'tries' => 'Tries',
1379: 'problem_appearance' => 'Problem Appearance',
1380: 'behaviour_of_input_fields' => 'Behaviour of Input Fields',
1381: 'hiding' => 'Hiding',
1382: 'high_level_randomization' => 'High Level Randomization',
1383: 'slots' => 'Slots',
1384: 'file_submission' => 'File Submission',
1385: 'misc' => 'Miscellaneous' );
1386: }
1387:
1388: # return a hash. Like a look-up table
1389: sub lookUpTableParameter {
1390:
1391: return (
1392: 'opendate' => 'time_settings',
1393: 'duedate' => 'time_settings',
1394: 'answerdate' => 'time_settings',
1395: 'interval' => 'time_settings',
1396: 'contentopen' => 'time_settings',
1397: 'contentclose' => 'time_settings',
1398: 'discussend' => 'time_settings',
1399: 'weight' => 'grading',
1400: 'handgrade' => 'grading',
1401: 'maxtries' => 'tries',
1402: 'hinttries' => 'tries',
1403: 'type' => 'problem_appearance',
1404: 'problemstatus' => 'problem_appearance',
1405: 'display' => 'problem_appearance',
1406: 'ordered' => 'problem_appearance',
1407: 'numbubbles' => 'problem_appearance',
1408: 'tol' => 'behaviour_of_input_fields',
1409: 'sig' => 'behaviour_of_input_fields',
1410: 'turnoffunit' => 'behaviour_of_input_fields',
1411: 'hiddenresource' => 'hiding',
1412: 'hiddenparts' => 'hiding',
1413: 'discusshide' => 'hiding',
1414: 'buttonshide' => 'hiding',
1415: 'turnoffeditor' => 'hiding',
1416: 'encrypturl' => 'hiding',
1417: 'randomorder' => 'high_level_randomization',
1418: 'randompick' => 'high_level_randomization',
1419: 'available' => 'slots',
1420: 'useslots' => 'slots',
1421: 'availablestudent' => 'slots',
1422: 'uploadedfiletypes' => 'file_submission',
1423: 'maxfilesize' => 'file_submission',
1424: 'cssfile' => 'misc',
1425: 'mapalias' => 'misc',
1426: 'acc' => 'misc',
1427: 'maxcollaborators' => 'misc',
1428: 'scoreformat' => 'misc',
1429:
1430: );
1431: }
1432:
1433: sub whatIsMyCategory {
1434: my $name = shift;
1435: my $catList = shift;
1436: my @list;
1437: my %lookUpList = &lookUpTableParameter; #Initilize the lookupList
1438: my $cat = $lookUpList{$name};
1439: if (defined($cat)) {
1440: if (!defined($$catList{$cat})){
1441: push @list, ($name);
1442: $$catList{$cat} = \@list;
1443: } else {
1444: push @{${$catList}{$cat}}, ($name);
1445: }
1446: } else {
1447: if (!defined($$catList{'misc'})){
1448: push @list, ($name);
1449: $$catList{'misc'} = \@list;
1450: } else {
1451: push @{${$catList}{'misc'}}, ($name);
1452: }
1453: }
1454: }
1455:
1456: sub keysindisplayorderCategory {
1457: my ($name,$keyorder)=@_;
1458: return sort {
1459: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
1460: } ( @{$name});
1461: }
1462:
1463: sub category_order {
1464: return (
1465: 'time_settings' => 1,
1466: 'grading' => 2,
1467: 'tries' => 3,
1468: 'problem_appearance' => 4,
1469: 'hiding' => 5,
1470: 'behaviour_of_input_fields' => 6,
1471: 'high_level_randomization' => 7,
1472: 'slots' => 8,
1473: 'file_submission' => 9,
1474: 'misc' => 10
1475: );
1476:
1477: }
1478:
1479: sub parmboxes {
1480: my ($r,$allparms,$pscat,$keyorder)=@_;
1481: my $tempkey;
1482: my $tempparameter;
1483: my %categories = &categories;
1484: my %category_order = &category_order();
1485: my %categoryList = (
1486: 'time_settings' => [],
1487: 'grading' => [],
1488: 'tries' => [],
1489: 'problem_appearance' => [],
1490: 'behaviour_of_input_fields' => [],
1491: 'hiding' => [],
1492: 'high_level_randomization' => [],
1493: 'slots' => [],
1494: 'file_submission' => [],
1495: 'misc' => [],
1496: );
1497: foreach $tempparameter (keys %$allparms) {
1498: &whatIsMyCategory($tempparameter, \%categoryList);
1499: }
1500: #part to print the parm-list
1501: $r->print('<fieldset id="LC_parm_overview_parm_menu" style="display:none">'
1502: .'<legend>'.&mt('Parameter').'</legend>'."\n"
1503: );
1504:
1505: #Print parameters
1506: for my $key (sort { $category_order{$a} <=> $category_order{$b} } keys %categoryList) {
1507: if(@{$categoryList{$key}} == 0) {
1508: next;
1509: } else {
1510: $r->print('<fieldset>'
1511: .'<legend>'
1512: .&mt($categories{$key})
1513: .'</legend>'."\n");
1514: foreach $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) {
1515: $r->print('<span class="LC_nobreak">'
1516: .'<label><input type="checkbox" name="pscat" ');
1517: $r->print('value="'.$tempkey.'" ');
1518: $r->print('onclick="checkboxChecked(\''.$tempkey.'\')"');
1519: if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
1520: $r->print(' checked="checked"');
1521: }
1522: $r->print(' />'.($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey}
1523: : $tempkey)
1524: .'</label></span> ');
1525: }
1526: $r->print('</fieldset>');
1527: }
1528: }
1529: $r->print('<hr />'
1530: .'<a href="javascript:hideParms()">'
1531: .&mt('Hide')
1532: .'</a>'
1533: );
1534:
1535: #&shortCuts($r,$allparms,$pscat,$keyorder);
1536: $r->print('</fieldset>');
1537: }
1538: #
1539: # This function offers some links on the parameter section to get with one click a group a parameters
1540: #
1541: sub shortCuts {
1542: my ($r,$allparms,$pscat,$keyorder)=@_;
1543:
1544: #part to print out the shortcuts for parmselection
1545: $r->print('<table><tr id="LC_parm_overview_parm_menu_selectors">'
1546: .'<td valign="top">'
1547: .'<fieldset><legend>'.&mt('Parameter Selection').'</legend>'
1548: .'<span class="LC_nobreak">'
1549: .'• <a href="javascript:checkall(true, \'pscat\')">'.&mt('Select All').'</a>'
1550: .'</span>'
1551: .'<br />'
1552: .'<span class="LC_nobreak">'
1553: .'• <a href="javascript:checkstandard()">'.&mt('Select Common Only').'</a>'
1554: .'</span>'
1555: .'<br />'
1556: .'<span class="LC_nobreak">'
1557: .'• <a href="javascript:checkall(false, \'pscat\')">'.&mt('Unselect All').'</a>'
1558: .'</span>'
1559: .'</fieldset>'
1560: .'</td>'
1561: .'<td colspan="2" valign="top">'
1562: .'<fieldset><legend>'.&mt('Add Selection for...').'</legend>'
1563: .'<span class="LC_nobreak">'
1564: .'• <a href="javascript:checkdates()">'.&mt('Problem Dates').'</a>'
1565: .'</span>'
1566: .'<span class="LC_nobreak">'
1567: .' • <a href="javascript:checkcontdates()">'.&mt('Content Dates').'</a>'
1568: .'</span>'
1569: # .'<br />'
1570: .'<span class="LC_nobreak">'
1571: .' • <a href="javascript:checkdisset()">'.&mt('Discussion Settings').'</a>'
1572: .'</span>'
1573: .'<span class="LC_nobreak">'
1574: .' • <a href="javascript:checkvisi()">'.&mt('Visibilities').'</a>'
1575: .'</span>'
1576: # .'<br />'
1577: .'<span class="LC_nobreak">'
1578: .' • <a href="javascript:checkparts()">'.&mt('Part Parameters').'</a>'
1579: .'</span>'
1580: .'</fieldset>'
1581: .'</td>'
1582: .'</tr></table>');
1583: }
1584:
1585: sub partmenu {
1586: my ($r,$allparts,$psprt)=@_;
1587:
1588: $r->print('<select multiple="multiple" name="psprt" size="8">');
1589: $r->print('<option value="all"');
1590: $r->print(' selected="selected"') unless (@{$psprt});
1591: $r->print('>'.&mt('All Parts').'</option>');
1592: my %temphash=();
1593: foreach (@{$psprt}) { $temphash{$_}=1; }
1594: foreach my $tempkey (sort {
1595: if ($a==$b) { return ($a cmp $b) } else { return ($a <=> $b); }
1596: } keys(%{$allparts})) {
1597: unless ($tempkey =~ /\./) {
1598: $r->print('<option value="'.$tempkey.'"');
1599: if ($$psprt[0] eq "all" || $temphash{$tempkey}) {
1600: $r->print(' selected="selected"');
1601: }
1602: $r->print('>'.$$allparts{$tempkey}.'</option>');
1603: }
1604: }
1605: $r->print('</select>');
1606: }
1607:
1608: sub usermenu {
1609: my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups)=@_;
1610: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
1611: &Apache::loncommon::selectstudent_link('parmform','uname','udom');
1612: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1613:
1614: my $sections='';
1615: my %sectionhash = &Apache::loncommon::get_sections();
1616:
1617: my $groups;
1618: my %grouphash = &Apache::longroup::coursegroups();
1619:
1620: my $g_s_header='';
1621: my $g_s_footer='';
1622:
1623: if (%sectionhash) {
1624: $sections=&mt('Section:').' <select name="csec"';
1625: if (%grouphash && $parmlev ne 'full') {
1626: $sections .= qq| onchange="group_or_section('csec')" |;
1627: }
1628: $sections .= '>';
1629: foreach my $section ('',sort keys %sectionhash) {
1630: $sections.='<option value="'.$section.'" '.
1631: ($section eq $csec?'selected="selected"':'').'>'.$section.
1632: '</option>';
1633: }
1634: $sections.='</select>';
1635: }
1636:
1637: if (%sectionhash && %grouphash && $parmlev ne 'full') {
1638: $sections .= ' '.&mt('or').' ';
1639: $sections .= qq|
1640: <script type="text/javascript">
1641: // <![CDATA[
1642: function group_or_section(caller) {
1643: if (caller == "cgroup") {
1644: if (document.parmform.cgroup.selectedIndex != 0) {
1645: document.parmform.csec.selectedIndex = 0;
1646: }
1647: } else {
1648: if (document.parmform.csec.selectedIndex != 0) {
1649: document.parmform.cgroup.selectedIndex = 0;
1650: }
1651: }
1652: }
1653: // ]]>
1654: </script>
1655: |;
1656: } else {
1657: $sections .= qq|
1658: <script type="text/javascript">
1659: // <![CDATA[
1660: function group_or_section(caller) {
1661: return;
1662: }
1663: // ]]>
1664: </script>
1665: |;
1666: }
1667:
1668: if (%grouphash) {
1669: $groups=&mt('Group:').' <select name="cgroup"';
1670: if (%sectionhash && $env{'form.action'} eq 'settable') {
1671: $groups .= qq| onchange="group_or_section('cgroup')" |;
1672: }
1673: $groups .= '>';
1674: foreach my $grp ('',sort keys %grouphash) {
1675: $groups.='<option value="'.$grp.'" ';
1676: if ($grp eq $cgroup) {
1677: unless ((defined($uname)) && ($grp eq '')) {
1678: $groups .= 'selected="selected" ';
1679: }
1680: } elsif (!defined($cgroup)) {
1681: if (@{$usersgroups} == 1) {
1682: if ($grp eq $$usersgroups[0]) {
1683: $groups .= 'selected="selected" ';
1684: }
1685: }
1686: }
1687: $groups .= '>'.$grp.'</option>';
1688: }
1689: $groups.='</select>';
1690: }
1691:
1692: if (%sectionhash || %grouphash) {
1693: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group/Section')));
1694: $r->print($sections.$groups);
1695: $r->print(&Apache::lonhtmlcommon::row_closure());
1696: }
1697:
1698: $r->print(&Apache::lonhtmlcommon::row_title(&mt('User')));
1699: $r->print(&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]'
1700: ,'<input type="text" value="'.$uname.'" size="12" name="uname" />'
1701: ,'<input type="text" value="'.$id.'" size="12" name="id" /> '
1702: ,$chooseopt));
1703: }
1704:
1705: #
1706: # This function shows on table Mode the available Parameters for the selected Resources
1707: #
1708: sub displaymenu {
1709: my ($r,$allparms,$allparts,$pscat,$psprt,$keyorder)=@_;
1710: $r->print(&Apache::lonhtmlcommon::topic_bar (2,&mt('Select Parameters')));
1711: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1712: &parmmenu($r,$allparms,$pscat,$keyorder);
1713: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1714: &parmboxes($r,$allparms,$pscat,$keyorder);
1715: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1716: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
1717: &partmenu($r,$allparts,$psprt);
1718: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1719: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1720: }
1721:
1722: sub mapmenu {
1723: my ($r,$allmaps,$pschp,$maptitles, $symbp)=@_;
1724: my %allmaps_inverted = reverse %$allmaps;
1725: my $navmap = Apache::lonnavmaps::navmap->new();
1726: my $tree=[];
1727: my $treeinfo={};
1728: if (defined($navmap)) {
1729: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
1730: my $curRes;
1731: my $depth = 0;
1732: my %parent = ();
1733: my $startcount = 5;
1734: my $lastcontainer = $startcount;
1735: # preparing what is to show ...
1736: while ($curRes = $it->next()) {
1737: if ($curRes == $it->BEGIN_MAP()) {
1738: $depth++;
1739: $parent{$depth}= $lastcontainer;
1740: }
1741: if ($curRes == $it->END_MAP()) {
1742: $depth--;
1743: $lastcontainer = $parent{$depth};
1744: }
1745: if (ref($curRes)) {
1746: my $symb = $curRes->symb();
1747: my $ressymb = $symb;
1748: if (($curRes->is_sequence()) || ($curRes->is_page())) {
1749: my $type = 'sequence';
1750: if ($curRes->is_page()) {
1751: $type = 'page';
1752: }
1753: my $id= $curRes->id();
1754: my $srcf = $curRes->src();
1755: my $resource_name = &Apache::lonnet::gettitle($srcf);
1756: if(!exists($treeinfo->{$id})) {
1757: push(@$tree,$id);
1758: my $enclosing_map_folder = &Apache::lonnet::declutter($curRes->enclosing_map_src());
1759: $treeinfo->{$id} = {
1760: depth => $depth,
1761: type => $type,
1762: name => $resource_name,
1763: enclosing_map_folder => $enclosing_map_folder,
1764: };
1765: }
1766: }
1767: }
1768: }
1769: }
1770: # Show it ...
1771: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Enclosing Map or Folder')));
1772: if ((ref($tree) eq 'ARRAY') && (ref($treeinfo) eq 'HASH')) {
1773: my $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
1774: $r->print(&Apache::loncommon::start_data_table()
1775: .&Apache::loncommon::start_data_table_row()
1776: .'<td>'.$icon
1777: .'<label> '
1778: .'<input type="radio" name="pschp" checked="checked" value="all" />'
1779: .&mt('All Maps or Folders')
1780: .'</label></td>'
1781: .&Apache::loncommon::end_data_table_row()
1782: );
1783: my $whitespace = '<img src="'
1784: .&Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif")
1785: .'" alt="" />';
1786: if (exists($$allmaps{1})) {
1787: $r->print(&Apache::loncommon::start_data_table_row()
1788: .'<td>'.$icon
1789: .'<label> '
1790: .'<input type="radio" name="pschp" value="1"'
1791: );
1792: if ($pschp eq 1) {
1793: $r->print(' checked="checked"');
1794: }
1795: $r->print('/>'
1796: .$$maptitles{1}
1797: .($$allmaps{1} !~/^uploaded/?' ['.$$allmaps{1}.']':'')
1798: .'</label>'
1799: .'</td>'
1800: .&Apache::loncommon::end_data_table_row()
1801: );
1802: }
1803: foreach my $id (@{$tree}) {
1804: my ($mapid,$resid)=split(/\./,$id);
1805: # Indentation
1806: my $depth = $treeinfo->{$id}->{'depth'};
1807: my $indent;
1808: for (my $i = 0; $i < $depth; $i++) {
1809: $indent.= $whitespace;
1810: }
1811: $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
1812: if ($treeinfo->{$id}->{'type'} eq 'page') {
1813: $icon = '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />';
1814: }
1815: my $symb_name = $$symbp{$id};
1816: my ($front, $tail) = split (/___${resid}___/, $symb_name);
1817: $symb_name = $tail;
1818: $r->print(&Apache::loncommon::start_data_table_row()
1819: .'<td>'.$indent.$icon
1820: .'<label> '
1821: .'<input type ="radio" name="pschp" value="'.$allmaps_inverted{$symb_name}.'"'
1822: );
1823: if ($pschp eq $allmaps_inverted{$symb_name}) {
1824: $r->print(' checked="checked"');
1825: }
1826: $r->print('/>'
1827: .$treeinfo->{$id}->{name}
1828: .($$allmaps{$mapid}!~/^uploaded/?' ['.$$allmaps{$mapid}.']':'')
1829: .'</label>'
1830: .'</td>'
1831: .&Apache::loncommon::end_data_table_row()
1832: );
1833: }
1834: $r->print(&Apache::loncommon::end_data_table());
1835: }
1836: }
1837:
1838: sub levelmenu {
1839: my ($r,$alllevs,$parmlev)=@_;
1840:
1841: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameter Level').&Apache::loncommon::help_open_topic('Course_Parameter_Levels')));
1842: $r->print('<select name="parmlev">');
1843: foreach (reverse sort keys %{$alllevs}) {
1844: $r->print('<option value="'.$$alllevs{$_}.'"');
1845: if ($parmlev eq $$alllevs{$_}) {
1846: $r->print(' selected="selected"');
1847: }
1848: $r->print('>'.&mt($_).'</option>');
1849: }
1850: $r->print("</select>");
1851: }
1852:
1853:
1854: sub sectionmenu {
1855: my ($r,$selectedsections)=@_;
1856: my %sectionhash = &Apache::loncommon::get_sections();
1857: return if (!%sectionhash);
1858:
1859: $r->print('<select name="Section" multiple="multiple" size="8">');
1860: foreach my $s ('all',sort keys %sectionhash) {
1861: $r->print(' <option value="'.$s.'"');
1862: foreach (@{$selectedsections}) {
1863: if ($s eq $_) {
1864: $r->print(' selected="selected"');
1865: last;
1866: }
1867: }
1868: $r->print('>'.$s."</option>\n");
1869: }
1870: $r->print("</select>\n");
1871: }
1872:
1873: sub groupmenu {
1874: my ($r,$selectedgroups)=@_;
1875: my %grouphash = &Apache::longroup::coursegroups();
1876: return if (!%grouphash);
1877:
1878: $r->print('<select name="Group" multiple="multiple" size="8">');
1879: foreach my $group (sort(keys(%grouphash))) {
1880: $r->print(' <option value="'.$group.'"');
1881: foreach (@{$selectedgroups}) {
1882: if ($group eq $_) {
1883: $r->print(' selected="selected"');
1884: last;
1885: }
1886: }
1887: $r->print('>'.$group."</option>\n");
1888: }
1889: $r->print("</select>\n");
1890: }
1891:
1892:
1893: sub keysplit {
1894: my $keyp=shift;
1895: return (split(/\,/,$keyp));
1896: }
1897:
1898: sub keysinorder {
1899: my ($name,$keyorder)=@_;
1900: return sort {
1901: $$keyorder{$a} <=> $$keyorder{$b};
1902: } (keys %{$name});
1903: }
1904:
1905: sub keysinorder_bytype {
1906: my ($name,$keyorder)=@_;
1907: return sort {
1908: my $ta=(split('_',$a))[-1];
1909: my $tb=(split('_',$b))[-1];
1910: if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) {
1911: return ($a cmp $b);
1912: }
1913: $$keyorder{'parameter_0_'.$ta} <=> $$keyorder{'parameter_0_'.$tb};
1914: } (keys %{$name});
1915: }
1916:
1917: sub keysindisplayorder {
1918: my ($name,$keyorder)=@_;
1919: return sort {
1920: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
1921: } (keys %{$name});
1922: }
1923:
1924: sub sortmenu {
1925: my ($r,$sortorder)=@_;
1926: $r->print('<br /><label><input type="radio" name="sortorder" value="realmstudent"');
1927: if ($sortorder eq 'realmstudent') {
1928: $r->print(' checked="checked"');
1929: }
1930: $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
1931: $r->print('</label><br /><label><input type="radio" name="sortorder" value="studentrealm"');
1932: if ($sortorder eq 'studentrealm') {
1933: $r->print(' checked="checked"');
1934: }
1935: $r->print(' />'.&mt('Sort by student (group/section) first, then realm').
1936: '</label>');
1937: }
1938:
1939: sub standardkeyorder {
1940: return ('parameter_0_opendate' => 1,
1941: 'parameter_0_duedate' => 2,
1942: 'parameter_0_answerdate' => 3,
1943: 'parameter_0_interval' => 4,
1944: 'parameter_0_weight' => 5,
1945: 'parameter_0_maxtries' => 6,
1946: 'parameter_0_hinttries' => 7,
1947: 'parameter_0_contentopen' => 8,
1948: 'parameter_0_contentclose' => 9,
1949: 'parameter_0_type' => 10,
1950: 'parameter_0_problemstatus' => 11,
1951: 'parameter_0_hiddenresource' => 12,
1952: 'parameter_0_hiddenparts' => 13,
1953: 'parameter_0_display' => 14,
1954: 'parameter_0_ordered' => 15,
1955: 'parameter_0_tol' => 16,
1956: 'parameter_0_sig' => 17,
1957: 'parameter_0_turnoffunit' => 18,
1958: 'parameter_0_discussend' => 19,
1959: 'parameter_0_discusshide' => 20);
1960: }
1961:
1962:
1963: sub assessparms {
1964:
1965: my $r=shift;
1966:
1967: my @ids=();
1968: my %symbp=();
1969: my %mapp=();
1970: my %typep=();
1971: my %keyp=();
1972: my %uris=();
1973: my %maptitles=();
1974:
1975: # -------------------------------------------------------- Variable declaration
1976:
1977: my %allmaps=();
1978: my %alllevs=();
1979:
1980: my $uname;
1981: my $udom;
1982: my $uhome;
1983: my $csec;
1984: my $cgroup;
1985: my @usersgroups = ();
1986:
1987: my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
1988:
1989: $alllevs{'Resource Level'}='full';
1990: $alllevs{'Map/Folder Level'}='map';
1991: $alllevs{'Course Level'}='general';
1992:
1993: my %allparms;
1994: my %allparts;
1995: #
1996: # Order in which these parameters will be displayed
1997: #
1998: my %keyorder=&standardkeyorder();
1999:
2000: @ids=();
2001: %symbp=();
2002: %typep=();
2003:
2004: my $message='';
2005:
2006: $csec=$env{'form.csec'};
2007: $cgroup=$env{'form.cgroup'};
2008:
2009: if ($udom=$env{'form.udom'}) {
2010: } elsif ($udom=$env{'request.role.domain'}) {
2011: } elsif ($udom=$env{'user.domain'}) {
2012: } else {
2013: $udom=$r->dir_config('lonDefDomain');
2014: }
2015:
2016:
2017: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
2018: my $pschp=$env{'form.pschp'};
2019: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
2020: if (!@psprt) { $psprt[0]='0'; }
2021:
2022: my $pssymb='';
2023: my $parmlev='';
2024:
2025: unless ($env{'form.parmlev'}) {
2026: $parmlev = 'map';
2027: } else {
2028: $parmlev = $env{'form.parmlev'};
2029: }
2030:
2031: # ----------------------------------------------- Was this started from grades?
2032:
2033: if (($env{'form.command'} eq 'set') && ($env{'form.url'})
2034: && (!$env{'form.dis'})) {
2035: my $url=$env{'form.url'};
2036: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
2037: $pssymb=&Apache::lonnet::symbread($url);
2038: if (!@pscat) { @pscat=('all'); }
2039: $pschp='';
2040: $parmlev = 'full';
2041: } elsif ($env{'form.symb'}) {
2042: $pssymb=$env{'form.symb'};
2043: if (!@pscat) { @pscat=('all'); }
2044: $pschp='';
2045: $parmlev = 'full';
2046: } else {
2047: $env{'form.url'}='';
2048: }
2049:
2050: my $id=$env{'form.id'};
2051: if (($id) && ($udom)) {
2052: $uname=(&Apache::lonnet::idget($udom,$id))[1];
2053: if ($uname) {
2054: $id='';
2055: } else {
2056: $message=
2057: '<span class="LC_error">'.&mt("Unknown ID")." '$id' ".
2058: &mt('at domain')." '$udom'</span>";
2059: }
2060: } else {
2061: $uname=$env{'form.uname'};
2062: }
2063: unless ($udom) { $uname=''; }
2064: $uhome='';
2065: if ($uname) {
2066: $uhome=&Apache::lonnet::homeserver($uname,$udom);
2067: if ($uhome eq 'no_host') {
2068: $message=
2069: '<span class="LC_error">'.&mt("Unknown user")." '$uname' ".
2070: &mt("at domain")." '$udom'</span>";
2071: $uname='';
2072: } else {
2073: $csec=&Apache::lonnet::getsection($udom,$uname,
2074: $env{'request.course.id'});
2075:
2076: if ($csec eq '-1') {
2077: $message='<span class="LC_error">'.
2078: &mt("User")." '$uname' ".&mt("at domain")." '$udom' ".
2079: &mt("not in this course")."</span>";
2080: $uname='';
2081: $csec=$env{'form.csec'};
2082: $cgroup=$env{'form.cgroup'};
2083: } else {
2084: my %name=&Apache::lonnet::userenvironment($udom,$uname,
2085: ('firstname','middlename','lastname','generation','id'));
2086: $message="\n<p>\n".&mt("Full Name").": ".
2087: $name{'firstname'}.' '.$name{'middlename'}.' '
2088: .$name{'lastname'}.' '.$name{'generation'}.
2089: "<br />\n".&mt('ID').": ".$name{'id'}.'<p>';
2090: }
2091: @usersgroups = &Apache::lonnet::get_users_groups(
2092: $udom,$uname,$env{'request.course.id'});
2093: if (@usersgroups > 0) {
2094: unless (grep(/^\Q$cgroup\E$/,@usersgroups)) {
2095: $cgroup = $usersgroups[0];
2096: }
2097: }
2098: }
2099: }
2100:
2101: unless ($csec) { $csec=''; }
2102: unless ($cgroup) { $cgroup=''; }
2103:
2104: # --------------------------------------------------------- Get all assessments
2105: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
2106: \%mapp, \%symbp,\%maptitles,\%uris,
2107: \%keyorder);
2108:
2109: $mapp{'0.0'} = '';
2110: $symbp{'0.0'} = '';
2111:
2112: # ---------------------------------------------------------- Anything to store?
2113: if ($env{'form.pres_marker'}) {
2114: my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
2115: my @values=split(/\&\&\&/,$env{'form.pres_value'});
2116: my @types=split(/\&\&\&/,$env{'form.pres_type'});
2117: for (my $i=0;$i<=$#markers;$i++) {
2118: if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3)$/) {
2119: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2120: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2121: my (@ok_slots,@fail_slots,@del_slots);
2122: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
2123: my ($level,@all) =
2124: &parmval_by_symb('0.availablestudent',$pssymb,'',$uname,$udom,
2125: $csec,$cgroup,$courseopt);
2126: foreach my $slot_name (split(/:/,$values[$i])) {
2127: next if ($slot_name eq '');
2128: if (&update_slots($slot_name,$cdom,$cnum,$pssymb,$uname,$udom) eq 'ok') {
2129: push(@ok_slots,$slot_name);
2130:
2131: } else {
2132: push(@fail_slots,$slot_name);
2133: }
2134: }
2135: if (@ok_slots) {
2136: $values[$i] = join(':',@ok_slots);
2137: } else {
2138: $values[$i] = '';
2139: }
2140: if ($all[$level] ne '') {
2141: my @existing = split(/:/,$all[$level]);
2142: foreach my $slot_name (@existing) {
2143: if (!grep(/^\Q$slot_name\E$/,split(/:/,$values[$i]))) {
2144: if (&delete_slots($slot_name,$cdom,$cnum,$uname,$udom,$pssymb) eq 'ok') {
2145: push(@del_slots,$slot_name);
2146: }
2147: }
2148: }
2149: }
2150: }
2151: $message.=&storeparm(split(/\&/,$markers[$i]),
2152: $values[$i],
2153: $types[$i],
2154: $uname,$udom,$csec,$cgroup);
2155: }
2156: # ---------------------------------------------------------------- Done storing
2157: $message.='<p class="LC_warning">'
2158: .&mt('Changes can take up to 10 minutes before being active for all students.')
2159: .&Apache::loncommon::help_open_topic('Caching')
2160: .'</p>';
2161: }
2162: #----------------------------------------------- if all selected, fill in array
2163: if ($pscat[0] eq "all") {@pscat = (keys %allparms);}
2164: if (!@pscat) { @pscat=('duedate','opendate','answerdate','weight','maxtries') };
2165: if ($psprt[0] eq "all" || !@psprt) {@psprt = (keys %allparts);}
2166: # ------------------------------------------------------------------ Start page
2167:
2168: &startpage($r);
2169:
2170: foreach ('tolerance','date_default','date_start','date_end',
2171: 'date_interval','int','float','string') {
2172: $r->print('<input type="hidden" value="'.
2173: &HTML::Entities::encode($env{'form.recent_'.$_},'"&<>').
2174: '" name="recent_'.$_.'" />');
2175: }
2176:
2177: # ----- Start Parameter Selection
2178:
2179: # Hide parm selection?
2180: $r->print(<<ENDPARMSELSCRIPT);
2181: <script type="text/javascript">
2182: // <![CDATA[
2183: function parmsel_show() {
2184: document.getElementById('parmsel').style.display = "";
2185: document.getElementById('parmsellink').style.display = "none";
2186: }
2187: // ]]>
2188: </script>
2189: ENDPARMSELSCRIPT
2190: my $parmselhiddenstyle=' style="display:none"';
2191: if($env{'form.hideparmsel'} eq 'hidden') {
2192: $r->print('<div id="parmsel"'.$parmselhiddenstyle.'>');
2193: } else {
2194: $r->print('<div id="parmsel">');
2195: }
2196:
2197: # Display Unit 1 "General Parameters"
2198: if (!$pssymb) {
2199: $r->print(&Apache::lonhtmlcommon::topic_bar (1,&mt('General Parameters')));
2200: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2201:
2202: &levelmenu($r,\%alllevs,$parmlev);
2203:
2204: if ($parmlev ne 'general') {
2205: $r->print(&Apache::lonhtmlcommon::row_closure());
2206: &mapmenu($r,\%allmaps,$pschp,\%maptitles, \%symbp);
2207: }
2208:
2209: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2210: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2211: #Display Unit 2 "Select Parameter"
2212: &displaymenu($r,\%allparms,\%allparts,\@pscat,\@psprt,\%keyorder);
2213: } else {
2214: my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
2215: my $title = &Apache::lonnet::gettitle($pssymb);
2216: $r->print(&mt('Specific Resource: [_1] ([_2])',$title,$resource).
2217: '<input type="hidden" value="'.$pssymb.'" name="symb" />'.
2218: '<br /><label><b>'.&mt('Show all parts').': <input type="checkbox" name="psprt" value="all"'.
2219: ($env{'form.psprt'}?' checked="checked"':'').' /></b></label><br />');
2220: }
2221: $r->print(&Apache::lonhtmlcommon::topic_bar (3,&mt('User Selection')));
2222: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2223: &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups);
2224: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2225: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2226:
2227: # parm selection is shown: display parm update button
2228: $r->print('<p>'
2229: .'<input type="submit" name="dis"'
2230: .' value="'.&mt('Update Parameter Display').'" />'
2231: .'<input type="hidden" name="hideparmsel" value="hidden" />'
2232: .'</p>'
2233: );
2234:
2235: $r->print('</div>');
2236: # ----- End Parameter Selection
2237:
2238: # Offer link to display parameter selection again
2239: $r->print('<p id="parmsellink"');
2240: if($env{'form.hideparmsel'} ne 'hidden') {
2241: $r->print($parmselhiddenstyle);
2242: }
2243: $r->print('>'
2244: .'<a href="javascript:parmsel_show()">'
2245: .&mt('Change Parameter Selection')
2246: .'</a>'
2247: .'</p>');
2248:
2249: # Display Messages
2250: $r->print('<div>'.$message.'</div>');
2251:
2252:
2253: my @temp_pscat;
2254: map {
2255: my $cat = $_;
2256: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
2257: } @pscat;
2258:
2259: @pscat = @temp_pscat;
2260:
2261: if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
2262: # ----------------------------------------------------------------- Start Table
2263: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
2264: my $csuname=$env{'user.name'};
2265: my $csudom=$env{'user.domain'};
2266:
2267: if ($parmlev eq 'full') {
2268: my $coursespan=$csec?8:5;
2269: my $userspan=3;
2270: if ($cgroup ne '') {
2271: $coursespan += 3;
2272: }
2273:
2274: $r->print('<p><table border="2">');
2275: $r->print('<tr><td colspan="5"></td>');
2276: $r->print('<th colspan="'.($coursespan).'">'.&mt('Any User').'</th>');
2277: if ($uname) {
2278: if (@usersgroups > 1) {
2279: $userspan ++;
2280: }
2281: $r->print('<th colspan="'.$userspan.'" rowspan="2">');
2282: $r->print(&mt("User")." $uname ".&mt('at Domain')." $udom</th>");
2283: }
2284: my %lt=&Apache::lonlocal::texthash(
2285: 'pie' => "Parameter in Effect",
2286: 'csv' => "Current Session Value",
2287: 'at' => 'at',
2288: 'rl' => "Resource Level",
2289: 'ic' => 'in Course',
2290: 'aut' => "Assessment URL and Title",
2291: 'type' => 'Type',
2292: 'emof' => "Enclosing Map or Folder",
2293: 'part' => 'Part',
2294: 'pn' => 'Parameter Name',
2295: 'def' => 'default',
2296: 'femof' => 'from Enclosing Map or Folder',
2297: 'gen' => 'general',
2298: 'foremf' => 'for Enclosing Map or Folder',
2299: 'fr' => 'for Resource'
2300: );
2301: $r->print(<<ENDTABLETWO);
2302: <th rowspan="3">$lt{'pie'}</th>
2303: <th rowspan="3">$lt{'csv'}<br />($csuname $lt{'at'} $csudom)</th>
2304: </tr><tr><td colspan="5"></td><th colspan="2">$lt{'ic'}</th><th colspan="2">$lt{'rl'}</th>
2305: <th colspan="1">$lt{'ic'}</th>
2306:
2307: ENDTABLETWO
2308: if ($csec) {
2309: $r->print('<th colspan="3">'.
2310: &mt("in Section")." $csec</th>");
2311: }
2312: if ($cgroup) {
2313: $r->print('<th colspan="3">'.
2314: &mt("in Group")." $cgroup</th>");
2315: }
2316: $r->print(<<ENDTABLEHEADFOUR);
2317: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
2318: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
2319: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
2320: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
2321: ENDTABLEHEADFOUR
2322:
2323: if ($csec) {
2324: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
2325: }
2326:
2327: if ($cgroup) {
2328: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
2329: }
2330:
2331: if ($uname) {
2332: if (@usersgroups > 1) {
2333: $r->print('<th>'.&mt('Control by other group?').'</th>');
2334: }
2335: $r->print('<th>'.&mt('general').'</th><th>'.&mt('for Enclosing Map or Folder').'</th><th>'.&mt('for Resource').'</th>');
2336: }
2337:
2338: $r->print('</tr>');
2339:
2340: my $defbgone='';
2341: my $defbgtwo='';
2342: my $defbgthree = '';
2343:
2344: foreach (@ids) {
2345:
2346: my $rid=$_;
2347: my ($inmapid)=($rid=~/\.(\d+)$/);
2348:
2349: if ((!$pssymb &&
2350: (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
2351: ||
2352: ($pssymb && $pssymb eq $symbp{$rid})) {
2353: # ------------------------------------------------------ Entry for one resource
2354: if ($defbgone eq '#E0E099') {
2355: $defbgone='#E0E0DD';
2356: } else {
2357: $defbgone='#E0E099';
2358: }
2359: if ($defbgtwo eq '#FFFF99') {
2360: $defbgtwo='#FFFFDD';
2361: } else {
2362: $defbgtwo='#FFFF99';
2363: }
2364: if ($defbgthree eq '#FFBB99') {
2365: $defbgthree='#FFBBDD';
2366: } else {
2367: $defbgthree='#FFBB99';
2368: }
2369:
2370: my $thistitle='';
2371: my %name= ();
2372: undef %name;
2373: my %part= ();
2374: my %display=();
2375: my %type= ();
2376: my %default=();
2377: my $uri=&Apache::lonnet::declutter($uris{$rid});
2378:
2379: foreach (&keysplit($keyp{$rid})) {
2380: my $tempkeyp = $_;
2381: if (grep $_ eq $tempkeyp, @catmarker) {
2382: $part{$_}=&Apache::lonnet::metadata($uri,$_.'.part');
2383: $name{$_}=&Apache::lonnet::metadata($uri,$_.'.name');
2384: my $parmdis=&Apache::lonnet::metadata($uri,$_.'.display');
2385: if ($allparms{$name{$_}} ne '') {
2386: my $identifier;
2387: if ($parmdis =~ /(\s*\[Part.*)$/) {
2388: $identifier = $1;
2389: }
2390: $display{$_} = $allparms{$name{$_}}.$identifier;
2391: } else {
2392: $display{$_} = $parmdis;
2393: }
2394: unless ($display{$_}) { $display{$_}=''; }
2395: $display{$_}.=' ('.$name{$_}.')';
2396: $default{$_}=&Apache::lonnet::metadata($uri,$_);
2397: $type{$_}=&Apache::lonnet::metadata($uri,$_.'.type');
2398: $thistitle=&Apache::lonnet::metadata($uri,$_.'.title');
2399: }
2400: }
2401: my $totalparms=scalar keys %name;
2402: if ($totalparms>0) {
2403: my $firstrow=1;
2404: my $title=&Apache::lonnet::gettitle($symbp{$rid});
2405: $r->print('<tr><td style="background-color:'.$defbgone.';"'.
2406: ' rowspan='.$totalparms.
2407: '><tt><font size="-1">'.
2408: join(' / ',split(/\//,$uri)).
2409: '</font></tt><p><b>'.
2410: "<a href=\"javascript:openWindow('".
2411: &Apache::lonnet::clutter($uri).'?symb='.
2412: &escape($symbp{$rid}).
2413: "', 'metadatafile', '450', '500', 'no', 'yes');\"".
2414: " target=\"_self\">$title");
2415:
2416: if ($thistitle) {
2417: $r->print(' ('.$thistitle.')');
2418: }
2419: $r->print('</a></b></td>');
2420: $r->print('<td style="background-color:'.$defbgtwo.';"'.
2421: ' rowspan='.$totalparms.'>'.$typep{$rid}.
2422: '</td>');
2423:
2424: $r->print('<td style="background-color:'.$defbgone.';"'.
2425: ' rowspan='.$totalparms.
2426: '>'.$maptitles{$mapp{$rid}}.'</td>');
2427:
2428: foreach (&keysinorder_bytype(\%name,\%keyorder)) {
2429: unless ($firstrow) {
2430: $r->print('<tr>');
2431: } else {
2432: undef $firstrow;
2433: }
2434: &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default,
2435: \%type,\%display,$defbgone,$defbgtwo,
2436: $defbgthree,$parmlev,$uname,$udom,$csec,
2437: $cgroup,\@usersgroups);
2438: }
2439: }
2440: }
2441: } # end foreach ids
2442: # -------------------------------------------------- End entry for one resource
2443: $r->print('</table>');
2444: } # end of full
2445: #--------------------------------------------------- Entry for parm level map
2446: if ($parmlev eq 'map') {
2447: my $defbgone = '#E0E099';
2448: my $defbgtwo = '#FFFF99';
2449: my $defbgthree = '#FFBB99';
2450:
2451: my %maplist;
2452:
2453: if ($pschp eq 'all') {
2454: %maplist = %allmaps;
2455: } else {
2456: %maplist = ($pschp => $mapp{$pschp});
2457: }
2458:
2459: #-------------------------------------------- for each map, gather information
2460: my $mapid;
2461: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys %maplist) {
2462: my $maptitle = $maplist{$mapid};
2463:
2464: #----------------------- loop through ids and get all parameter types for map
2465: #----------------------------------------- and associated information
2466: my %name = ();
2467: my %part = ();
2468: my %display = ();
2469: my %type = ();
2470: my %default = ();
2471: my $map = 0;
2472:
2473: # $r->print("Catmarker: @catmarker<br />\n");
2474:
2475: foreach (@ids) {
2476: ($map)=(/([\d]*?)\./);
2477: my $rid = $_;
2478:
2479: # $r->print("$mapid:$map: $rid <br /> \n");
2480:
2481: if ($map eq $mapid) {
2482: my $uri=&Apache::lonnet::declutter($uris{$rid});
2483: # $r->print("Keys: $keyp{$rid} <br />\n");
2484:
2485: #--------------------------------------------------------------------
2486: # @catmarker contains list of all possible parameters including part #s
2487: # $fullkeyp contains the full part/id # for the extraction of proper parameters
2488: # $tempkeyp contains part 0 only (no ids - ie, subparts)
2489: # When storing information, store as part 0
2490: # When requesting information, request from full part
2491: #-------------------------------------------------------------------
2492: foreach (&keysplit($keyp{$rid})) {
2493: my $tempkeyp = $_;
2494: my $fullkeyp = $tempkeyp;
2495: $tempkeyp =~ s/_\w+_/_0_/;
2496:
2497: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
2498: $part{$tempkeyp}="0";
2499: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
2500: my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
2501: if ($allparms{$name{$tempkeyp}} ne '') {
2502: my $identifier;
2503: if ($parmdis =~ /(\s*\[Part.*)$/) {
2504: $identifier = $1;
2505: }
2506: $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
2507: } else {
2508: $display{$tempkeyp} = $parmdis;
2509: }
2510: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
2511: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
2512: $display{$tempkeyp} =~ s/_\w+_/_0_/;
2513: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
2514: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
2515: }
2516: } # end loop through keys
2517: }
2518: } # end loop through ids
2519:
2520: #---------------------------------------------------- print header information
2521: my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
2522: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
2523: my $tmp="";
2524: if ($uname) {
2525: my $person=&Apache::loncommon::plainname($uname,$udom);
2526: $tmp.=&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
2527: &mt('in')." \n";
2528: } else {
2529: $tmp.="<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n";
2530: }
2531: if ($cgroup) {
2532: $tmp.=&mt("Group")." <font color=\"red\"><i>$cgroup".
2533: "</i></font> ".&mt('of')." \n";
2534: $csec = '';
2535: } elsif ($csec) {
2536: $tmp.=&mt("Section")." <font color=\"red\"><i>$csec".
2537: "</i></font> ".&mt('of')." \n";
2538: }
2539: $r->print('<div align="center"><h4>'
2540: .&mt('Set Defaults for All Resources in [_1]Specifically for [_2][_3]'
2541: ,$foldermap.'<br /><font color="red"><i>'.$showtitle.'</i></font><br />'
2542: ,$tmp
2543: ,'<font color="red"><i>'.$coursename.'</i></font>'
2544: )
2545: ."<br /></h4>\n"
2546: );
2547: #---------------------------------------------------------------- print table
2548: $r->print('<p>'.&Apache::loncommon::start_data_table()
2549: .&Apache::loncommon::start_data_table_header_row()
2550: .'<th>'.&mt('Parameter Name').'</th>'
2551: .'<th>'.&mt('Default Value').'</th>'
2552: .'<th>'.&mt('Parameter in Effect').'</th>'
2553: .&Apache::loncommon::end_data_table_header_row()
2554: );
2555:
2556: foreach (&keysinorder(\%name,\%keyorder)) {
2557: $r->print(&Apache::loncommon::start_data_table_row());
2558: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
2559: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
2560: $parmlev,$uname,$udom,$csec,$cgroup);
2561: }
2562: $r->print(&Apache::loncommon::end_data_table().'</p>'
2563: .'</div>'
2564: );
2565: } # end each map
2566: } # end of $parmlev eq map
2567: #--------------------------------- Entry for parm level general (Course level)
2568: if ($parmlev eq 'general') {
2569: my $defbgone = '#E0E099';
2570: my $defbgtwo = '#FFFF99';
2571: my $defbgthree = '#FFBB99';
2572:
2573: #-------------------------------------------- for each map, gather information
2574: my $mapid="0.0";
2575: #----------------------- loop through ids and get all parameter types for map
2576: #----------------------------------------- and associated information
2577: my %name = ();
2578: my %part = ();
2579: my %display = ();
2580: my %type = ();
2581: my %default = ();
2582:
2583: foreach (@ids) {
2584: my $rid = $_;
2585:
2586: my $uri=&Apache::lonnet::declutter($uris{$rid});
2587:
2588: #--------------------------------------------------------------------
2589: # @catmarker contains list of all possible parameters including part #s
2590: # $fullkeyp contains the full part/id # for the extraction of proper parameters
2591: # $tempkeyp contains part 0 only (no ids - ie, subparts)
2592: # When storing information, store as part 0
2593: # When requesting information, request from full part
2594: #-------------------------------------------------------------------
2595: foreach (&keysplit($keyp{$rid})) {
2596: my $tempkeyp = $_;
2597: my $fullkeyp = $tempkeyp;
2598: $tempkeyp =~ s/_\w+_/_0_/;
2599: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
2600: $part{$tempkeyp}="0";
2601: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name');
2602: my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display');
2603: if ($allparms{$name{$tempkeyp}} ne '') {
2604: my $identifier;
2605: if ($parmdis =~ /(\s*\[Part.*)$/) {
2606: $identifier = $1;
2607: }
2608: $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
2609: } else {
2610: $display{$tempkeyp} = $parmdis;
2611: }
2612: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
2613: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
2614: $display{$tempkeyp} =~ s/_\w+_/_0_/;
2615: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp);
2616: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type');
2617: }
2618: } # end loop through keys
2619: } # end loop through ids
2620:
2621: #---------------------------------------------------- print header information
2622: my $setdef=&mt("Set Defaults for All Resources in Course");
2623: $r->print(<<ENDMAPONE);
2624: <center>
2625: <h4>$setdef
2626: <font color="red"><i>$coursename</i></font><br />
2627: ENDMAPONE
2628: if ($uname) {
2629: my $person=&Apache::loncommon::plainname($uname,$udom);
2630: $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
2631: } else {
2632: $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
2633: }
2634:
2635: if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
2636: if ($cgroup) {$r->print(&mt("Group")."<font color=\"red\"> <i>$cgroup</i></font>\n")};
2637: $r->print("</h4>\n");
2638: #---------------------------------------------------------------- print table
2639: $r->print('<p>'.&Apache::loncommon::start_data_table()
2640: .&Apache::loncommon::start_data_table_header_row()
2641: .'<th>'.&mt('Parameter Name').'</th>'
2642: .'<th>'.&mt('Default Value').'</th>'
2643: .'<th>'.&mt('Parameter in Effect').'</th>'
2644: .&Apache::loncommon::end_data_table_header_row()
2645: );
2646:
2647: foreach (&keysinorder(\%name,\%keyorder)) {
2648: $r->print(&Apache::loncommon::start_data_table_row());
2649: &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default,
2650: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
2651: $parmlev,$uname,$udom,$csec,$cgroup);
2652: }
2653: $r->print(&Apache::loncommon::end_data_table()
2654: .'</p>'
2655: .'</center>'
2656: );
2657: } # end of $parmlev eq general
2658: }
2659: $r->print('</form>'.&Apache::loncommon::end_page());
2660: } # end sub assessparms
2661:
2662: ##################################################
2663: # Overview mode
2664: ##################################################
2665: my $tableopen;
2666:
2667: sub tablestart {
2668: if ($tableopen) {
2669: return '';
2670: } else {
2671: $tableopen=1;
2672: return &Apache::loncommon::start_data_table().'<tr><th>'.&mt('Parameter').'</th><th>'.
2673: &mt('Delete').'</th><th>'.&mt('Set to ...').'</th></tr>';
2674: }
2675: }
2676:
2677: sub tableend {
2678: if ($tableopen) {
2679: $tableopen=0;
2680: return &Apache::loncommon::end_data_table();
2681: } else {
2682: return'';
2683: }
2684: }
2685:
2686: sub readdata {
2687: my ($crs,$dom)=@_;
2688: # Read coursedata
2689: my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
2690: # Read userdata
2691:
2692: my $classlist=&Apache::loncoursedata::get_classlist();
2693: foreach (keys %$classlist) {
2694: if ($_=~/^($match_username)\:($match_domain)$/) {
2695: my ($tuname,$tudom)=($1,$2);
2696: my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
2697: foreach my $userkey (keys %{$useropt}) {
2698: if ($userkey=~/^$env{'request.course.id'}/) {
2699: my $newkey=$userkey;
2700: $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
2701: $$resourcedata{$newkey}=$$useropt{$userkey};
2702: }
2703: }
2704: }
2705: }
2706: return $resourcedata;
2707: }
2708:
2709:
2710: # Setting
2711:
2712: sub storedata {
2713: my ($r,$crs,$dom)=@_;
2714: # Set userlevel immediately
2715: # Do an intermediate store of course level
2716: my $olddata=&readdata($crs,$dom);
2717: my %newdata=();
2718: undef %newdata;
2719: my @deldata=();
2720: undef @deldata;
2721: foreach (keys %env) {
2722: if ($_=~/^form\.([a-z]+)\_(.+)$/) {
2723: my $cmd=$1;
2724: my $thiskey=$2;
2725: my ($tuname,$tudom)=&extractuser($thiskey);
2726: my $tkey=$thiskey;
2727: if ($tuname) {
2728: $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
2729: }
2730: if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
2731: my ($data, $typeof, $text);
2732: if ($cmd eq 'set') {
2733: $data=$env{$_};
2734: $typeof=$env{'form.typeof_'.$thiskey};
2735: $text = &mt('Saved modified parameter for');
2736: } elsif ($cmd eq 'datepointer') {
2737: $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
2738: $typeof=$env{'form.typeof_'.$thiskey};
2739: $text = &mt('Saved modified date for');
2740: } elsif ($cmd eq 'dateinterval') {
2741: $data=&get_date_interval_from_form($thiskey);
2742: $typeof=$env{'form.typeof_'.$thiskey};
2743: $text = &mt('Saved modified date for');
2744: }
2745: if (defined($data) and $$olddata{$thiskey} ne $data) {
2746: if ($tuname) {
2747: if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
2748: $tkey.'.type' => $typeof},
2749: $tudom,$tuname) eq 'ok') {
2750: &log_parmset({$tkey=>$data,$tkey.'.type' => $typeof},0,$tuname,$tudom);
2751: $r->print('<br />'.$text.' '.
2752: &Apache::loncommon::plainname($tuname,$tudom));
2753: } else {
2754: $r->print('<div class="LC_error">'.
2755: &mt('Error saving parameters').'</div>');
2756: }
2757: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2758: } else {
2759: $newdata{$thiskey}=$data;
2760: $newdata{$thiskey.'.type'}=$typeof;
2761: }
2762: }
2763: } elsif ($cmd eq 'del') {
2764: if ($tuname) {
2765: if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
2766: &log_parmset({$tkey=>''},1,$tuname,$tudom);
2767: $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
2768: } else {
2769: $r->print('<div class="LC_error">'.
2770: &mt('Error deleting parameters').'</div>');
2771: }
2772: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
2773: } else {
2774: push (@deldata,$thiskey,$thiskey.'.type');
2775: }
2776: }
2777: }
2778: }
2779: # Store all course level
2780: my $delentries=$#deldata+1;
2781: my @newdatakeys=keys %newdata;
2782: my $putentries=$#newdatakeys+1;
2783: if ($delentries) {
2784: if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') {
2785: my %loghash=map { $_ => '' } @deldata;
2786: &log_parmset(\%loghash,1);
2787: $r->print('<h2>'.&mt('Deleted [_1] parameter(s)</h2>',$delentries));
2788: } else {
2789: $r->print('<div class="LC_error">'.
2790: &mt('Error deleting parameters').'</div>');
2791: }
2792: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
2793: }
2794: if ($putentries) {
2795: if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
2796: &log_parmset(\%newdata,0);
2797: $r->print('<h3>'.&mt('Saved [_1] parameter(s)',$putentries/2).'</h3>');
2798: } else {
2799: $r->print('<div class="LC_error">'.
2800: &mt('Error saving parameters').'</div>');
2801: }
2802: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
2803: }
2804: }
2805:
2806: sub extractuser {
2807: my $key=shift;
2808: return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./);
2809: }
2810:
2811: sub parse_listdata_key {
2812: my ($key,$listdata) = @_;
2813: # split into student/section affected, and
2814: # the realm (folder/resource part and parameter
2815: my ($student,$realm) =
2816: ($key=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)$/);
2817: # if course wide student would be undefined
2818: if (!defined($student)) {
2819: ($realm)=($key=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
2820: }
2821: # strip off the .type if it's not the Question type parameter
2822: if ($realm=~/\.type$/ && !exists($listdata->{$key.'.type'})) {
2823: $realm=~s/\.type//;
2824: }
2825: # split into resource+part and parameter name
2826: my ($res, $parm) = ($realm=~/^(.*)\.(.*)$/);
2827: ($res, my $part) = ($res =~/^(.*)\.(.*)$/);
2828: return ($student,$res,$part,$parm);
2829: }
2830:
2831: sub listdata {
2832: my ($r,$resourcedata,$listdata,$sortorder)=@_;
2833: # Start list output
2834:
2835: my $oldsection='';
2836: my $oldrealm='';
2837: my $oldpart='';
2838: my $pointer=0;
2839: $tableopen=0;
2840: my $foundkeys=0;
2841: my %keyorder=&standardkeyorder();
2842:
2843: foreach my $thiskey (sort {
2844: my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata);
2845: my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata);
2846:
2847: # get the numerical order for the param
2848: $aparm=$keyorder{'parameter_0_'.$aparm};
2849: $bparm=$keyorder{'parameter_0_'.$bparm};
2850:
2851: my $result=0;
2852:
2853: if ($sortorder eq 'realmstudent') {
2854: if ($ares ne $bres ) {
2855: $result = ($ares cmp $bres);
2856: } elsif ($astudent ne $bstudent) {
2857: $result = ($astudent cmp $bstudent);
2858: } elsif ($apart ne $bpart ) {
2859: $result = ($apart cmp $bpart);
2860: }
2861: } else {
2862: if ($astudent ne $bstudent) {
2863: $result = ($astudent cmp $bstudent);
2864: } elsif ($ares ne $bres ) {
2865: $result = ($ares cmp $bres);
2866: } elsif ($apart ne $bpart ) {
2867: $result = ($apart cmp $bpart);
2868: }
2869: }
2870:
2871: if (!$result) {
2872: if (defined($aparm) && defined($bparm)) {
2873: $result = ($aparm <=> $bparm);
2874: } elsif (defined($aparm)) {
2875: $result = -1;
2876: } elsif (defined($bparm)) {
2877: $result = 1;
2878: }
2879: }
2880:
2881: $result;
2882: } keys %{$listdata}) {
2883:
2884: if ($$listdata{$thiskey.'.type'}) {
2885: my $thistype=$$listdata{$thiskey.'.type'};
2886: if ($$resourcedata{$thiskey.'.type'}) {
2887: $thistype=$$resourcedata{$thiskey.'.type'};
2888: }
2889: my ($middle,$part,$name)=
2890: ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
2891: my $section=&mt('All Students');
2892: if ($middle=~/^\[(.*)\]/) {
2893: my $issection=$1;
2894: if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
2895: $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
2896: } else {
2897: $section=&mt('Group/Section').': '.$issection;
2898: }
2899: $middle=~s/^\[(.*)\]//;
2900: }
2901: $middle=~s/\.+$//;
2902: $middle=~s/^\.+//;
2903: my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
2904: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
2905: $realm='<span class="LC_parm_scope_folder">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><span class="LC_parm_folder">('.$1.')</span></span>';
2906: } elsif ($middle) {
2907: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
2908: $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>';
2909: }
2910: if ($sortorder eq 'realmstudent') {
2911: if ($realm ne $oldrealm) {
2912: $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
2913: $oldrealm=$realm;
2914: $oldsection='';
2915: }
2916: if ($section ne $oldsection) {
2917: $r->print(&tableend()."\n<h2>$section</h2>");
2918: $oldsection=$section;
2919: $oldpart='';
2920: }
2921: } else {
2922: if ($section ne $oldsection) {
2923: $r->print(&tableend()."\n<hr /><h1>$section</h1>");
2924: $oldsection=$section;
2925: $oldrealm='';
2926: }
2927: if ($realm ne $oldrealm) {
2928: $r->print(&tableend()."\n<h2>$realm</h2>");
2929: $oldrealm=$realm;
2930: $oldpart='';
2931: }
2932: }
2933: if ($part ne $oldpart) {
2934: $r->print(&tableend().
2935: "\n".'<span class="LC_parm_part">'.&mt('Part').": $part</span>");
2936: $oldpart=$part;
2937: }
2938: #
2939: # Ready to print
2940: #
2941: $r->print(&tablestart().
2942: &Apache::loncommon::start_data_table_row().
2943: '<td><b>'.&standard_parameter_names($name).
2944: '</b></td><td><input type="checkbox" name="del_'.
2945: $thiskey.'" /></td><td>');
2946: $foundkeys++;
2947: if (&isdateparm($thistype)) {
2948: my $jskey='key_'.$pointer;
2949: $pointer++;
2950: $r->print(
2951: &Apache::lonhtmlcommon::date_setter('parmform',
2952: $jskey,
2953: $$resourcedata{$thiskey},
2954: '',1,'','').
2955: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'.
2956: (($$resourcedata{$thiskey}!=0)?'<span class="LC_nobreak"><a href="/adm/parmset?&action=dateshift1&timebase='.$$resourcedata{$thiskey}.'">'.
2957: &mt('Shift all dates based on this date').'</a></span>':'').
2958: &date_sanity_info($$resourcedata{$thiskey})
2959: );
2960: } elsif ($thistype eq 'date_interval') {
2961: $r->print(&date_interval_selector($thiskey,
2962: $$resourcedata{$thiskey}));
2963: } elsif ($thistype =~ m/^string/) {
2964: $r->print(&string_selector($thistype,$thiskey,
2965: $$resourcedata{$thiskey}));
2966: } else {
2967: $r->print(&default_selector($thiskey,$$resourcedata{$thiskey}));
2968: }
2969: $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
2970: $thistype.'" />');
2971: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
2972: }
2973: }
2974: return $foundkeys;
2975: }
2976:
2977:
2978: sub date_interval_selector {
2979: my ($thiskey, $showval) = @_;
2980: my $result;
2981: foreach my $which (['days', 86400, 31],
2982: ['hours', 3600, 23],
2983: ['minutes', 60, 59],
2984: ['seconds', 1, 59]) {
2985: my ($name, $factor, $max) = @{ $which };
2986: my $amount = int($showval/$factor);
2987: $showval %= $factor;
2988: my %select = ((map {$_ => $_} (0..$max)),
2989: 'select_form_order' => [0..$max]);
2990: $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey,
2991: %select);
2992: $result .= ' '.&mt($name);
2993: }
2994: $result .= '<input type="hidden" name="dateinterval_'.$thiskey.'" />';
2995: return $result;
2996:
2997: }
2998:
2999: sub get_date_interval_from_form {
3000: my ($key) = @_;
3001: my $seconds = 0;
3002: foreach my $which (['days', 86400],
3003: ['hours', 3600],
3004: ['minutes', 60],
3005: ['seconds', 1]) {
3006: my ($name, $factor) = @{ $which };
3007: if (defined($env{'form.'.$name.'_'.$key})) {
3008: $seconds += $env{'form.'.$name.'_'.$key} * $factor;
3009: }
3010: }
3011: return $seconds;
3012: }
3013:
3014:
3015: sub default_selector {
3016: my ($thiskey, $showval) = @_;
3017: return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'" />';
3018: }
3019:
3020: my %strings =
3021: (
3022: 'string_yesno'
3023: => [[ 'yes', 'Yes' ],
3024: [ 'no', 'No' ]],
3025: 'string_problemstatus'
3026: => [[ 'yes', 'Yes' ],
3027: [ 'answer', 'Yes, and show correct answer if they exceed the maximum number of tries.' ],
3028: [ 'no', 'No, don\'t show correct/incorrect feedback.' ],
3029: [ 'no_feedback_ever', 'No, show no feedback at all.' ]],
3030: );
3031:
3032:
3033: sub string_selector {
3034: my ($thistype, $thiskey, $showval) = @_;
3035:
3036: if (!exists($strings{$thistype})) {
3037: return &default_selector($thiskey,$showval);
3038: }
3039:
3040: my $result;
3041: foreach my $possibilities (@{ $strings{$thistype} }) {
3042: my ($name, $description) = @{ $possibilities };
3043: $result .= '<label><input type="radio" name="set_'.$thiskey.
3044: '" value="'.$name.'"';
3045: if ($showval eq $name) {
3046: $result .= ' checked="checked"';
3047: }
3048: $result .= ' />'.&mt($description).'</label> ';
3049: }
3050: return $result;
3051: }
3052:
3053: #
3054: # Shift all start and end dates by $shift
3055: #
3056:
3057: sub dateshift {
3058: my ($shift)=@_;
3059: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3060: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3061: my %data=&Apache::lonnet::dump('resourcedata',$dom,$crs);
3062: # ugly retro fix for broken version of types
3063: foreach my $key (keys %data) {
3064: if ($key=~/\wtype$/) {
3065: my $newkey=$key;
3066: $newkey=~s/type$/\.type/;
3067: $data{$newkey}=$data{$key};
3068: delete $data{$key};
3069: }
3070: }
3071: my %storecontent=();
3072: # go through all parameters and look for dates
3073: foreach my $key (keys %data) {
3074: if ($data{$key.'.type'}=~/^date_(start|end)$/) {
3075: my $newdate=$data{$key}+$shift;
3076: $storecontent{$key}=$newdate;
3077: }
3078: }
3079: my $reply=&Apache::lonnet::cput
3080: ('resourcedata',\%storecontent,$dom,$crs);
3081: if ($reply eq 'ok') {
3082: &log_parmset(\%storecontent);
3083: }
3084: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
3085: return $reply;
3086: }
3087:
3088: sub newoverview {
3089: my ($r) = @_;
3090:
3091: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3092: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3093: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
3094: text=>"Overview Mode"});
3095: my $start_page = &Apache::loncommon::start_page('Set Parameters');
3096: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
3097: $r->print(<<ENDOVER);
3098: $start_page
3099: $breadcrumbs
3100: <form method="post" action="/adm/parmset?action=newoverview" name="parmform">
3101: ENDOVER
3102: my @ids=();
3103: my %typep=();
3104: my %keyp=();
3105: my %allparms=();
3106: my %allparts=();
3107: my %allmaps=();
3108: my %mapp=();
3109: my %symbp=();
3110: my %maptitles=();
3111: my %uris=();
3112: my %keyorder=&standardkeyorder();
3113: my %defkeytype=();
3114:
3115: my %alllevs=();
3116: $alllevs{'Resource Level'}='full';
3117: $alllevs{'Map/Folder Level'}='map';
3118: $alllevs{'Course Level'}='general';
3119:
3120: my $csec=$env{'form.csec'};
3121: my $cgroup=$env{'form.cgroup'};
3122:
3123: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
3124: my $pschp=$env{'form.pschp'};
3125: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
3126: if (!@psprt) { $psprt[0]='0'; }
3127:
3128: my @selected_sections =
3129: &Apache::loncommon::get_env_multiple('form.Section');
3130: @selected_sections = ('all') if (! @selected_sections);
3131: foreach my $sec (@selected_sections) {
3132: if ($sec eq 'all') {
3133: @selected_sections = ('all');
3134: }
3135: }
3136: my @selected_groups =
3137: &Apache::loncommon::get_env_multiple('form.Group');
3138:
3139: my $pssymb='';
3140: my $parmlev='';
3141:
3142: unless ($env{'form.parmlev'}) {
3143: $parmlev = 'map';
3144: } else {
3145: $parmlev = $env{'form.parmlev'};
3146: }
3147:
3148: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
3149: \%mapp, \%symbp,\%maptitles,\%uris,
3150: \%keyorder,\%defkeytype);
3151:
3152: if (grep {$_ eq 'all'} (@psprt)) {
3153: @psprt = keys(%allparts);
3154: }
3155: # Menu to select levels, etc
3156:
3157: #$r->print('<table id="LC_parm_overview_scope">
3158: # <tr><td class="LC_parm_overview_level_menu">');
3159: $r->print('<div class="LC_Box">');
3160: #$r->print('<h2 class="LC_hcell">Step 1</h2>');
3161: $r->print('<div>');
3162: $r->print(&Apache::lonhtmlcommon::start_pick_box());
3163: &levelmenu($r,\%alllevs,$parmlev);
3164: if ($parmlev ne 'general') {
3165: #$r->print('<td class="LC_parm_overview_map_menu">');
3166: $r->print(&Apache::lonhtmlcommon::row_closure());
3167: &mapmenu($r,\%allmaps,$pschp,\%maptitles);
3168: #$r->print('</td>');
3169: }
3170: $r->print(&Apache::lonhtmlcommon::row_closure(1));
3171: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3172: $r->print('</div></div>');
3173: #$r->print('</td></tr></table>');
3174:
3175: #$r->print('<table id="LC_parm_overview_controls">
3176: # <tr><td class="LC_parm_overview_parm_selectors">');
3177: $r->print('<div class="LC_Box">');
3178: $r->print('<div>');
3179: $r->print(&Apache::lonhtmlcommon::start_pick_box());
3180: &parmmenu($r,\%allparms,\@pscat,\%keyorder);
3181: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3182: &parmboxes($r,\%allparms,\@pscat,\%keyorder);
3183: $r->print(&Apache::lonhtmlcommon::start_pick_box());
3184: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
3185: #$r->print('</td><td class="LC_parm_overview_restrictions">'.
3186: $r->print('<table>'.
3187: '<tr><th>'.&mt('Parts').'</th><th>'.&mt('Section(s)').
3188: '</th><th>'.&mt('Group(s)').'</th></tr><tr><td>');
3189: &partmenu($r,\%allparts,\@psprt);
3190: $r->print('</td><td>');
3191: §ionmenu($r,\@selected_sections);
3192: $r->print('</td><td>');
3193: &groupmenu($r,\@selected_groups);
3194: $r->print('</td></tr></table>');
3195: #$r->print('</td></tr></table>');
3196: $r->print(&Apache::lonhtmlcommon::row_closure(1));
3197: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3198: $r->print('</div></div>');
3199:
3200: $r->print('<div class="LC_Box">');
3201: $r->print('<div>');
3202: my $sortorder=$env{'form.sortorder'};
3203: unless ($sortorder) { $sortorder='realmstudent'; }
3204: &sortmenu($r,$sortorder);
3205: $r->print('</div></div>');
3206:
3207: $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
3208:
3209: # Build the list data hash from the specified parms
3210:
3211: my $listdata;
3212: %{$listdata}=();
3213:
3214: foreach my $cat (@pscat) {
3215: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_sections,\%defkeytype,\%allmaps,\@ids,\%symbp);
3216: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_groups,\%defkeytype,\%allmaps,\@ids,\%symbp);
3217: }
3218:
3219: if (($env{'form.store'}) || ($env{'form.dis'})) {
3220:
3221: if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
3222:
3223: # Read modified data
3224:
3225: my $resourcedata=&readdata($crs,$dom);
3226:
3227: # List data
3228:
3229: &listdata($r,$resourcedata,$listdata,$sortorder);
3230: }
3231: $r->print(&tableend().
3232: ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Save').'" /></p>':'').
3233: '</form>'.&Apache::loncommon::end_page());
3234: }
3235:
3236: sub secgroup_lister {
3237: my ($cat,$pschp,$parmlev,$listdata,$psprt,$selections,$defkeytype,$allmaps,$ids,$symbp) = @_;
3238: foreach my $item (@{$selections}) {
3239: foreach my $part (@{$psprt}) {
3240: my $rootparmkey=$env{'request.course.id'};
3241: if (($item ne 'all') && ($item ne 'none') && ($item)) {
3242: $rootparmkey.='.['.$item.']';
3243: }
3244: if ($parmlev eq 'general') {
3245: # course-level parameter
3246: my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
3247: $$listdata{$newparmkey}=1;
3248: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
3249: } elsif ($parmlev eq 'map') {
3250: # map-level parameter
3251: foreach my $mapid (keys %{$allmaps}) {
3252: if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
3253: my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
3254: $$listdata{$newparmkey}=1;
3255: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
3256: }
3257: } else {
3258: # resource-level parameter
3259: foreach my $rid (@{$ids}) {
3260: my ($map,$resid,$url)=&Apache::lonnet::decode_symb($$symbp{$rid});
3261: if (($pschp ne 'all') && ($$allmaps{$pschp} ne $map)) { next; }
3262: my $newparmkey=$rootparmkey.'.'.$$symbp{$rid}.'.'.$part.'.'.$cat;
3263: $$listdata{$newparmkey}=1;
3264: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
3265: }
3266: }
3267: }
3268: }
3269: }
3270:
3271: sub overview {
3272: my ($r) = @_;
3273: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3274: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3275:
3276: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
3277: text=>"Overview Mode"});
3278: my $start_page=&Apache::loncommon::start_page('Modify Parameters');
3279: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
3280: $r->print(<<ENDOVER);
3281: $start_page
3282: $breadcrumbs
3283: <form method="post" action="/adm/parmset?action=setoverview" name="parmform">
3284: ENDOVER
3285: # Store modified
3286:
3287: &storedata($r,$crs,$dom);
3288:
3289: # Read modified data
3290:
3291: my $resourcedata=&readdata($crs,$dom);
3292:
3293:
3294: my $sortorder=$env{'form.sortorder'};
3295: unless ($sortorder) { $sortorder='realmstudent'; }
3296: &sortmenu($r,$sortorder);
3297:
3298: # List data
3299:
3300: my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder);
3301:
3302: $r->print(&tableend().'<p>'.
3303: ($foundkeys?'<input type="submit" value="'.&mt('Save').'" />':&mt('There are no parameters.')).'</p></form>'.
3304: &Apache::loncommon::end_page());
3305: }
3306:
3307: sub clean_parameters {
3308: my ($r) = @_;
3309: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3310: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3311:
3312: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
3313: text=>"Clean Parameters"});
3314: my $start_page=&Apache::loncommon::start_page('Clean Parameters');
3315: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Clean');
3316: $r->print(<<ENDOVER);
3317: $start_page
3318: $breadcrumbs
3319: <form method="post" action="/adm/parmset?action=cleanparameters" name="parmform">
3320: ENDOVER
3321: # Store modified
3322:
3323: &storedata($r,$crs,$dom);
3324:
3325: # Read modified data
3326:
3327: my $resourcedata=&readdata($crs,$dom);
3328:
3329: # List data
3330:
3331: $r->print('<h3>'.
3332: &mt('These parameters refer to resources that do not exist.').
3333: '</h3>'.
3334: '<input type="submit" value="'.&mt('Delete Selected').'" />'.'<br />'.
3335: '<br />');
3336: $r->print(&Apache::loncommon::start_data_table().
3337: '<tr>'.
3338: '<th>'.&mt('Delete').'</th>'.
3339: '<th>'.&mt('Parameter').'</th>'.
3340: '</tr>');
3341: foreach my $thiskey (sort(keys(%{$resourcedata}))) {
3342: next if (!exists($resourcedata->{$thiskey.'.type'})
3343: && $thiskey=~/\.type$/);
3344: my %data = &parse_key($thiskey);
3345: if (1) { #exists($data{'realm_exists'})
3346: #&& !$data{'realm_exists'}) {
3347: $r->print(&Apache::loncommon::start_data_table_row().
3348: '<tr>'.
3349: '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>' );
3350:
3351: $r->print('<td>');
3352: my $display_value = $resourcedata->{$thiskey};
3353: if (&isdateparm($resourcedata->{$thiskey.'.type'})) {
3354: $display_value =
3355: &Apache::lonlocal::locallocaltime($display_value);
3356: }
3357: $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
3358: &standard_parameter_names($data{'parameter_name'}),
3359: $resourcedata->{$thiskey}));
3360: $r->print('<br />');
3361: if ($data{'scope_type'} eq 'all') {
3362: $r->print(&mt('All users'));
3363: } elsif ($data{'scope_type'} eq 'user') {
3364: $r->print(&mt('User: [_1]',join(':',@{$data{'scope'}})));
3365: } elsif ($data{'scope_type'} eq 'section') {
3366: $r->print(&mt('Section: [_1]',$data{'scope'}));
3367: } elsif ($data{'scope_type'} eq 'group') {
3368: $r->print(&mt('Group: [_1]',$data{'scope'}));
3369: }
3370: $r->print('<br />');
3371: if ($data{'realm_type'} eq 'all') {
3372: $r->print(&mt('All Resources'));
3373: } elsif ($data{'realm_type'} eq 'folder') {
3374: $r->print(&mt('Folder: [_1]'),$data{'realm'});
3375: } elsif ($data{'realm_type'} eq 'symb') {
3376: my ($map,$resid,$url) =
3377: &Apache::lonnet::decode_symb($data{'realm'});
3378: $r->print(&mt('Resource: [_1] <br /> with ID: [_2] <br /> in folder [_3]',
3379: $url,$resid,$map));
3380: }
3381: $r->print(' <br /> '.&mt('Part: [_1]',$data{'parameter_part'}));
3382: $r->print('</td></tr>');
3383:
3384: }
3385: }
3386: $r->print(&Apache::loncommon::end_data_table().'<p>'.
3387: '<input type="submit" value="'.&mt('Delete Selected').'" />'.
3388: '</p></form>'.
3389: &Apache::loncommon::end_page());
3390: }
3391:
3392: sub date_shift_one {
3393: my ($r) = @_;
3394: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3395: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3396:
3397: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
3398: text=>"Shifting Dates"});
3399: my $start_page=&Apache::loncommon::start_page('Shift Dates');
3400: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
3401: $r->print(<<ENDOVER);
3402: $start_page
3403: $breadcrumbs
3404: ENDOVER
3405: $r->print('<form name="shiftform" method="post">'.
3406: '<table><tr><td>'.&mt('Currently set date:').'</td><td>'.
3407: &Apache::lonlocal::locallocaltime($env{'form.timebase'}).'</td></tr>'.
3408: '<tr><td>'.&mt('Shifted date:').'</td><td>'.
3409: &Apache::lonhtmlcommon::date_setter('shiftform',
3410: 'timeshifted',
3411: $env{'form.timebase'},,
3412: '').
3413: '</td></tr></table>'.
3414: '<input type="hidden" name="action" value="dateshift2" />'.
3415: '<input type="hidden" name="timebase" value="'.$env{'form.timebase'}.'" />'.
3416: '<input type="submit" value="'.&mt('Shift all dates accordingly').'" /></form>');
3417: $r->print(&Apache::loncommon::end_page());
3418: }
3419:
3420: sub date_shift_two {
3421: my ($r) = @_;
3422: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3423: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3424: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
3425: text=>"Shifting Dates"});
3426: my $start_page=&Apache::loncommon::start_page('Shift Dates');
3427: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
3428: $r->print(<<ENDOVER);
3429: $start_page
3430: $breadcrumbs
3431: ENDOVER
3432: my $timeshifted=&Apache::lonhtmlcommon::get_date_from_form('timeshifted');
3433: $r->print(&mt('Shifting all dates such that [_1] becomes [_2]',
3434: &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
3435: &Apache::lonlocal::locallocaltime($timeshifted)));
3436: my $delta=$timeshifted-$env{'form.timebase'};
3437: &dateshift($delta);
3438: $r->print(&Apache::loncommon::end_page());
3439: }
3440:
3441: sub parse_key {
3442: my ($key) = @_;
3443: my %data;
3444: my ($middle,$part,$name)=
3445: ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
3446: $data{'scope_type'} = 'all';
3447: if ($middle=~/^\[(.*)\]/) {
3448: $data{'scope'} = $1;
3449: if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) {
3450: $data{'scope_type'} = 'user';
3451: $data{'scope'} = [$1,$2];
3452: } else {
3453: #FIXME check for group scope
3454: $data{'scope_type'} = 'section';
3455: }
3456: $middle=~s/^\[(.*)\]//;
3457: }
3458: $middle=~s/\.+$//;
3459: $middle=~s/^\.+//;
3460: $data{'realm_type'}='all';
3461: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
3462: $data{'realm'} = $1;
3463: $data{'realm_type'} = 'folder';
3464: $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
3465: ($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
3466: } elsif ($middle) {
3467: $data{'realm'} = $middle;
3468: $data{'realm_type'} = 'symb';
3469: $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
3470: my ($map,$resid,$url) = &Apache::lonnet::decode_symb($data{'realm'});
3471: $data{'realm_exists'} = &Apache::lonnet::symbverify($data{'realm'},$url);
3472: }
3473:
3474: $data{'parameter_part'} = $part;
3475: $data{'parameter_name'} = $name;
3476:
3477: return %data;
3478: }
3479:
3480:
3481:
3482: sub extract_cloners {
3483: my ($clonelist,$allowclone) = @_;
3484: if ($clonelist =~ /,/) {
3485: @{$allowclone} = split(/,/,$clonelist);
3486: } else {
3487: $$allowclone[0] = $clonelist;
3488: }
3489: }
3490:
3491: sub check_cloners {
3492: my ($clonelist,$oldcloner) = @_;
3493: my ($clean_clonelist,%disallowed);
3494: my @allowclone = ();
3495: &extract_cloners($$clonelist,\@allowclone);
3496: foreach my $currclone (@allowclone) {
3497: if (!grep(/^\Q$currclone\E$/,@$oldcloner)) {
3498: if ($currclone eq '*') {
3499: $clean_clonelist .= $currclone.',';
3500: } else {
3501: my ($uname,$udom) = split(/:/,$currclone);
3502: if ($uname eq '*') {
3503: if ($udom =~ /^$match_domain$/) {
3504: if (!&Apache::lonnet::domain($udom)) {
3505: $disallowed{'domain'} .= $currclone.',';
3506: } else {
3507: $clean_clonelist .= $currclone.',';
3508: }
3509: } else {
3510: $disallowed{'format'} .= $currclone.',';
3511: }
3512: } elsif ($currclone !~/^($match_username)\:($match_domain)$/) {
3513: $disallowed{'format'} .= $currclone.',';
3514: } else {
3515: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
3516: $disallowed{'newuser'} .= $currclone.',';
3517: } else {
3518: $clean_clonelist .= $currclone.',';
3519: }
3520: }
3521: }
3522: } else {
3523: $clean_clonelist .= $currclone.',';
3524: }
3525: }
3526: foreach my $key (keys(%disallowed)) {
3527: $disallowed{$key} =~ s/,$//;
3528: }
3529: if ($clean_clonelist) {
3530: $clean_clonelist =~ s/,$//;
3531: }
3532: $$clonelist = $clean_clonelist;
3533: return %disallowed;
3534: }
3535:
3536: sub change_clone {
3537: my ($clonelist,$oldcloner) = @_;
3538: my ($uname,$udom);
3539: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3540: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3541: my $clone_crs = $cnum.':'.$cdom;
3542:
3543: if ($cnum && $cdom) {
3544: my @allowclone;
3545: &extract_cloners($clonelist,\@allowclone);
3546: foreach my $currclone (@allowclone) {
3547: if (!grep(/^$currclone$/,@$oldcloner)) {
3548: if ($currclone ne '*') {
3549: ($uname,$udom) = split(/:/,$currclone);
3550: if ($uname && $udom && $uname ne '*') {
3551: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
3552: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
3553: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
3554: if ($currclonecrs{'cloneable'} eq '') {
3555: $currclonecrs{'cloneable'} = $clone_crs;
3556: } else {
3557: $currclonecrs{'cloneable'} .= ','.$clone_crs;
3558: }
3559: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
3560: }
3561: }
3562: }
3563: }
3564: }
3565: }
3566: foreach my $oldclone (@$oldcloner) {
3567: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
3568: if ($oldclone ne '*') {
3569: ($uname,$udom) = split(/:/,$oldclone);
3570: if ($uname && $udom && $uname ne '*' ) {
3571: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
3572: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
3573: my %newclonecrs = ();
3574: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
3575: if ($currclonecrs{'cloneable'} =~ /,/) {
3576: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
3577: foreach my $crs (@currclonecrs) {
3578: if ($crs ne $clone_crs) {
3579: $newclonecrs{'cloneable'} .= $crs.',';
3580: }
3581: }
3582: $newclonecrs{'cloneable'} =~ s/,$//;
3583: } else {
3584: $newclonecrs{'cloneable'} = '';
3585: }
3586: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
3587: }
3588: }
3589: }
3590: }
3591: }
3592: }
3593: }
3594: }
3595:
3596:
3597:
3598: sub header {
3599: return &Apache::loncommon::start_page('Parameter Manager');
3600: }
3601:
3602:
3603:
3604: sub print_main_menu {
3605: my ($r,$parm_permission)=@_;
3606: #
3607: $r->print(&header());
3608: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Manager'));
3609: $r->print(<<ENDMAINFORMHEAD);
3610: <form method="post" enctype="multipart/form-data"
3611: action="/adm/parmset" name="studentform">
3612: ENDMAINFORMHEAD
3613: #
3614: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3615: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3616: my $vgr = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
3617: my $mgr = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
3618:
3619:
3620: my @menu =
3621: ( { categorytitle=>'Settings for this Course',
3622: items => [
3623: { linktext => 'Course Configuration',
3624: url => '/adm/courseprefs?origin=params',
3625: permission => $parm_permission,
3626: linktitle =>'Edit course configuration.' ,
3627: icon => 'preferences-desktop-remote-desktop.png' ,
3628: #help => 'Course_Environment',
3629: },
3630: { linktext => 'Portfolio Metadata',
3631: url => '/adm/parmset?action=setrestrictmeta',
3632: permission => $parm_permission,
3633: linktitle => 'Restrict metadata for this course.' ,
3634: icon =>'contact-new.png' ,
3635: },
3636: { linktext => 'Manage Course Slots',
3637: url => '/adm/slotrequest?command=showslots',
3638: permission => $vgr,
3639: linktitle =>'Manage slots for this course.' ,
3640: icon => 'format-justify-fill.png' ,
3641: },
3642: { linktext => 'Reset Student Access Times',
3643: url => '/adm/helper/resettimes.helper',
3644: permission => $mgr,
3645: linktitle =>'Reset access times for folders/maps, resources or the course.' ,
3646: icon => 'start-here.png' ,
3647: },
3648:
3649: { linktext => 'Set Parameter Setting Default Actions',
3650: url => '/adm/parmset?action=setdefaults',
3651: permission => $parm_permission,
3652: linktitle =>'Set default actions for parameters.' ,
3653: icon => 'folder-new.png' ,
3654: }]},
3655: { categorytitle => 'New and Existing Parameter Settings for Resources',
3656: items => [
3657: { linktext => 'Edit Resource Parameters - Helper Mode',
3658: url => '/adm/helper/parameter.helper',
3659: permission => $parm_permission,
3660: linktitle =>'Set/Modify resource parameters in helper mode.' ,
3661: icon => 'dialog-information.png' ,
3662: #help => 'Parameter_Helper',
3663: },
3664: { linktext => 'Edit Resource Parameters - Overview Mode',
3665: url => '/adm/parmset?action=newoverview',
3666: permission => $parm_permission,
3667: linktitle =>'Set/Modify resource parameters in overview mode.' ,
3668: icon => 'edit-find.png' ,
3669: #help => 'Parameter_Overview',
3670: },
3671: { linktext => 'Edit Resource Parameters - Table Mode',
3672: url => '/adm/parmset?action=settable',
3673: permission => $parm_permission,
3674: linktitle =>'Set/Modify resource parameters in table mode.' ,
3675: icon => 'edit-copy.png' ,
3676: #help => 'Table_Mode',
3677: }]},
3678: { categorytitle => 'Existing Parameter Settings for Resources',
3679: items => [
3680: { linktext => 'Modify Resource Parameters - Overview Mode',
3681: url => '/adm/parmset?action=setoverview',
3682: permission => $parm_permission,
3683: linktitle =>'Set/Modify existing resource parameters in overview mode.' ,
3684: icon => 'preferences-desktop-wallpaper.png' ,
3685: #help => 'Parameter_Overview',
3686: },
3687: { linktext => 'Change Log',
3688: url => '/adm/parmset?action=parameterchangelog',
3689: permission => $parm_permission,
3690: linktitle =>'View parameter and course blog posting/user notification change log.' ,
3691: icon => 'emblem-system.png' ,
3692: }]}
3693: );
3694: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
3695: return;
3696: }
3697:
3698:
3699:
3700: sub output_row {
3701: my ($r, $field_name, $field_text, $added_flag) = @_;
3702: my $output;
3703: my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
3704: my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
3705: if (!defined($options)) {
3706: $options = 'active,stuadd';
3707: $values = '';
3708: }
3709: if (!($options =~ /deleted/)) {
3710: my @options= ( ['active', 'Show to student'],
3711: ['stuadd', 'Provide text area for students to type metadata'],
3712: ['choices','Provide choices for students to select from']);
3713: # ['onlyone','Student may select only one choice']);
3714: if ($added_flag) {
3715: push @options,['deleted', 'Delete Metadata Field'];
3716: }
3717: $output = &Apache::loncommon::start_data_table_row();
3718: $output .= '<td><strong>'.$field_text.':</strong></td>';
3719: $output .= &Apache::loncommon::end_data_table_row();
3720: foreach my $opt (@options) {
3721: my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
3722: $output .= &Apache::loncommon::continue_data_table_row();
3723: $output .= '<td>'.(' ' x 5).'<label>
3724: <input type="checkbox" name="'.
3725: $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.
3726: &mt($opt->[1]).'</label></td>';
3727: $output .= &Apache::loncommon::end_data_table_row();
3728: }
3729: $output .= &Apache::loncommon::continue_data_table_row();
3730: $output .= '<td>'.(' ' x 10).'<input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /></td>';
3731: $output .= &Apache::loncommon::end_data_table_row();
3732: my $multiple_checked;
3733: my $single_checked;
3734: if ($options =~ m/onlyone/) {
3735: $multiple_checked = '';
3736: $single_checked = ' checked="checked"';
3737: } else {
3738: $multiple_checked = ' checked="checked"';
3739: $single_checked = '';
3740: }
3741: $output .= &Apache::loncommon::continue_data_table_row();
3742: $output .= '<td>'.(' ' x 10).'
3743: <input type="radio" name="'.$field_name.'_onlyone" value="multiple"'.$multiple_checked .' />
3744: '.&mt('Student may select multiple choices from list').'</td>';
3745: $output .= &Apache::loncommon::end_data_table_row();
3746: $output .= &Apache::loncommon::continue_data_table_row();
3747: $output .= '<td>'.(' ' x 10).'
3748: <input type="radio" name="'.$field_name.'_onlyone" value="single"'.$single_checked.' />
3749: '.&mt('Student may select only one choice from list').'</td>';
3750: $output .= &Apache::loncommon::end_data_table_row();
3751: }
3752: return ($output);
3753: }
3754:
3755:
3756:
3757: sub order_meta_fields {
3758: my ($r)=@_;
3759: my $idx = 1;
3760: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3761: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3762: $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));
3763: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
3764: text=>"Add Metadata Field"});
3765: &Apache::lonhtmlcommon::add_breadcrumb
3766: ({href=>"/adm/parmset?action=setrestrictmeta",
3767: text=>"Restrict Metadata"},
3768: {text=>"Order Metadata"});
3769: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata'));
3770: if ($env{'form.storeorder'}) {
3771: my $newpos = $env{'form.newpos'} - 1;
3772: my $currentpos = $env{'form.currentpos'} - 1;
3773: my @neworder = ();
3774: my @oldorder = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
3775: my $i;
3776: if ($newpos > $currentpos) {
3777: # moving stuff up
3778: for ($i=0;$i<$currentpos;$i++) {
3779: $neworder[$i]=$oldorder[$i];
3780: }
3781: for ($i=$currentpos;$i<$newpos;$i++) {
3782: $neworder[$i]=$oldorder[$i+1];
3783: }
3784: $neworder[$newpos]=$oldorder[$currentpos];
3785: for ($i=$newpos+1;$i<=$#oldorder;$i++) {
3786: $neworder[$i]=$oldorder[$i];
3787: }
3788: } else {
3789: # moving stuff down
3790: for ($i=0;$i<$newpos;$i++) {
3791: $neworder[$i]=$oldorder[$i];
3792: }
3793: $neworder[$newpos]=$oldorder[$currentpos];
3794: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
3795: $neworder[$i]=$oldorder[$i-1];
3796: }
3797: for ($i=$currentpos+1;$i<=$#oldorder;$i++) {
3798: $neworder[$i]=$oldorder[$i];
3799: }
3800: }
3801: my $ordered_fields = join ",", @neworder;
3802: my $put_result = &Apache::lonnet::put('environment',
3803: {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
3804: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields});
3805: }
3806: my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
3807: my $ordered_fields;
3808: my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
3809: if (!@fields_in_order) {
3810: # no order found, pick sorted order then create metadata.addedorder key.
3811: foreach my $key (sort keys %$fields) {
3812: push @fields_in_order, $key;
3813: $ordered_fields = join ",", @fields_in_order;
3814: }
3815: my $put_result = &Apache::lonnet::put('environment',
3816: {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
3817: }
3818: $r->print('<table>');
3819: my $num_fields = scalar(@fields_in_order);
3820: foreach my $key (@fields_in_order) {
3821: $r->print('<tr><td>');
3822: $r->print('<form method="post" action="">');
3823: $r->print('<select name="newpos" onChange="this.form.submit()">');
3824: for (my $i = 1;$i le $num_fields;$i ++) {
3825: if ($i eq $idx) {
3826: $r->print('<option value="'.$i.'" SELECTED>('.$i.')</option>');
3827: } else {
3828: $r->print('<option value="'.$i.'">'.$i.'</option>');
3829: }
3830: }
3831: $r->print('</select></td><td>');
3832: $r->print('<input type="hidden" name="currentpos" value="'.$idx.'" />');
3833: $r->print('<input type="hidden" name="storeorder" value="true" />');
3834: $r->print('</form>');
3835: $r->print($$fields{$key}.'</td></tr>');
3836: $idx ++;
3837: }
3838: $r->print('</table>');
3839: return 'ok';
3840: }
3841:
3842:
3843: sub continue {
3844: my $output;
3845: $output .= '<form action="" method="post">';
3846: $output .= '<input type="hidden" name="action" value="setrestrictmeta" />';
3847: $output .= '<input type="submit" value="Continue" />';
3848: return ($output);
3849: }
3850:
3851:
3852: sub addmetafield {
3853: my ($r)=@_;
3854: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
3855: text=>"Add Metadata Field"});
3856: $r->print(&Apache::loncommon::start_page('Add Metadata Field'));
3857: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
3858: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3859: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3860: if (exists($env{'form.undelete'})) {
3861: my @meta_fields = &Apache::loncommon::get_env_multiple('form.undeletefield');
3862: foreach my $meta_field(@meta_fields) {
3863: my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};
3864: $options =~ s/deleted//;
3865: $options =~ s/,,/,/;
3866: my $put_result = &Apache::lonnet::put('environment',
3867: {'metadata.'.$meta_field.'.options'=>$options},$dom,$crs);
3868:
3869: $r->print('Undeleted Metadata Field <strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}."</strong> with result ".$put_result.'<br />');
3870: }
3871: $r->print(&continue());
3872: } elsif (exists($env{'form.fieldname'})) {
3873: my $meta_field = $env{'form.fieldname'};
3874: my $display_field = $env{'form.fieldname'};
3875: $meta_field =~ s/\W/_/g;
3876: $meta_field =~ tr/A-Z/a-z/;
3877: my $put_result = &Apache::lonnet::put('environment',
3878: {'metadata.'.$meta_field.'.values'=>"",
3879: 'metadata.'.$meta_field.'.added'=>"$display_field",
3880: 'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
3881: $r->print('Added new Metadata Field <strong>'.$env{'form.fieldname'}."</strong> with result ".$put_result.'<br />');
3882: $r->print(&continue());
3883: } else {
3884: my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'});
3885: if ($fields) {
3886: $r->print('You may undelete previously deleted fields.<br />Check those you wish to undelete and click Undelete.<br />');
3887: $r->print('<form method="post" action="">');
3888: foreach my $key(keys(%$fields)) {
3889: $r->print('<input type="checkbox" name="undeletefield" value="'.$key.'" />'.$$fields{$key}.'<br /');
3890: }
3891: $r->print('<input type="submit" name="undelete" value="Undelete" />');
3892: $r->print('</form>');
3893: }
3894: $r->print('<hr /><strong>Or</strong> you may enter a new metadata field name.<form method="post" action="/adm/parmset?action=addmetadata"');
3895: $r->print('<input type="text" name="fieldname" /><br />');
3896: $r->print('<input type="submit" value="Add Metadata Field" />');
3897: }
3898: $r->print('</form>');
3899: }
3900:
3901:
3902:
3903: sub setrestrictmeta {
3904: my ($r)=@_;
3905: my $next_meta;
3906: my $output;
3907: my $item_num;
3908: my $put_result;
3909: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
3910: text=>"Restrict Metadata"});
3911: $r->print(&Apache::loncommon::start_page('Restrict Metadata'));
3912: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Restrict Metadata'));
3913: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3914: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
3915: my $key_base = $env{'course.'.$env{'request.course.id'}.'.'};
3916: my $save_field = '';
3917: if ($env{'form.restrictmeta'}) {
3918: foreach my $field (sort(keys(%env))) {
3919: if ($field=~m/^form.(.+)_(.+)$/) {
3920: my $options;
3921: my $meta_field = $1;
3922: my $meta_key = $2;
3923: if ($save_field ne $meta_field) {
3924: $save_field = $meta_field;
3925: if ($env{'form.'.$meta_field.'_stuadd'}) {
3926: $options.='stuadd,';
3927: }
3928: if ($env{'form.'.$meta_field.'_choices'}) {
3929: $options.='choices,';
3930: }
3931: if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') {
3932: $options.='onlyone,';
3933: }
3934: if ($env{'form.'.$meta_field.'_active'}) {
3935: $options.='active,';
3936: }
3937: if ($env{'form.'.$meta_field.'_deleted'}) {
3938: $options.='deleted,';
3939: }
3940: my $name = $save_field;
3941: $put_result = &Apache::lonnet::put('environment',
3942: {'metadata.'.$meta_field.'.options'=>$options,
3943: 'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
3944: },$dom,$crs);
3945: }
3946: }
3947: }
3948: }
3949: &Apache::lonnet::coursedescription($env{'request.course.id'},
3950: {'freshen_cache' => 1});
3951: # Get the default metadata fields
3952: my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
3953: # Now get possible added metadata fields
3954: my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
3955: my $row_alt = 1;
3956: $output .= &Apache::loncommon::start_data_table();
3957: foreach my $field (sort(keys(%metadata_fields))) {
3958: if ($field ne 'courserestricted') {
3959: $row_alt = $row_alt ? 0 : 1;
3960: $output.= &output_row($r, $field, $metadata_fields{$field});
3961: }
3962: }
3963: my $buttons = (<<ENDButtons);
3964: <input type="submit" name="restrictmeta" value="Save" />
3965: </form><br />
3966: <form method="post" action="/adm/parmset?action=addmetadata" name="form1">
3967: <input type="submit" name="restrictmeta" value="Add a Metadata Field" />
3968: </form>
3969: <br />
3970: <form method="post" action="/adm/parmset?action=ordermetadata" name="form2">
3971: <input type="submit" name="restrictmeta" value="Order Metadata Fields" />
3972: ENDButtons
3973: my $added_flag = 1;
3974: foreach my $field (sort(keys(%$added_metadata_fields))) {
3975: $row_alt = $row_alt ? 0 : 1;
3976: $output.= &output_row($r, $field, $$added_metadata_fields{$field},$added_flag, $row_alt);
3977: }
3978: $output .= &Apache::loncommon::end_data_table();
3979: $r->print(<<ENDenv);
3980: <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
3981: $output
3982: $buttons
3983: </form>
3984: ENDenv
3985: $r->print(&Apache::loncommon::end_page());
3986: return 'ok';
3987: }
3988:
3989:
3990:
3991: sub get_added_meta_fieldnames {
3992: my ($cid) = @_;
3993: my %fields;
3994: foreach my $key(%env) {
3995: if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
3996: my $field_name = $1;
3997: my ($display_field_name) = $env{$key};
3998: $fields{$field_name} = $display_field_name;
3999: }
4000: }
4001: return \%fields;
4002: }
4003:
4004:
4005:
4006: sub get_deleted_meta_fieldnames {
4007: my ($cid) = @_;
4008: my %fields;
4009: foreach my $key(%env) {
4010: if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
4011: my $field_name = $1;
4012: if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
4013: my ($display_field_name) = $env{$key};
4014: $fields{$field_name} = $display_field_name;
4015: }
4016: }
4017: }
4018: return \%fields;
4019: }
4020: sub defaultsetter {
4021: my ($r) = @_;
4022:
4023: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
4024: text=>"Set Defaults"});
4025: my $start_page =
4026: &Apache::loncommon::start_page('Parameter Setting Default Actions');
4027: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Defaults');
4028: $r->print(<<ENDDEFHEAD);
4029: $start_page
4030: $breadcrumbs
4031: <form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">
4032: ENDDEFHEAD
4033:
4034: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4035: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
4036: my @ids=();
4037: my %typep=();
4038: my %keyp=();
4039: my %allparms=();
4040: my %allparts=();
4041: my %allmaps=();
4042: my %mapp=();
4043: my %symbp=();
4044: my %maptitles=();
4045: my %uris=();
4046: my %keyorder=&standardkeyorder();
4047: my %defkeytype=();
4048:
4049: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
4050: \%mapp, \%symbp,\%maptitles,\%uris,
4051: \%keyorder,\%defkeytype);
4052: if ($env{'form.storerules'}) {
4053: my %newrules=();
4054: my @delrules=();
4055: my %triggers=();
4056: foreach my $key (keys(%env)) {
4057: if ($key=~/^form\.(\w+)\_action$/) {
4058: my $tempkey=$1;
4059: my $action=$env{$key};
4060: if ($action) {
4061: $newrules{$tempkey.'_action'}=$action;
4062: if ($action ne 'default') {
4063: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
4064: $triggers{$whichparm}.=$tempkey.':';
4065: }
4066: $newrules{$tempkey.'_type'}=$defkeytype{$tempkey};
4067: if (&isdateparm($defkeytype{$tempkey})) {
4068: $newrules{$tempkey.'_days'}=$env{'form.'.$tempkey.'_days'};
4069: $newrules{$tempkey.'_hours'}=$env{'form.'.$tempkey.'_hours'};
4070: $newrules{$tempkey.'_min'}=$env{'form.'.$tempkey.'_min'};
4071: $newrules{$tempkey.'_sec'}=$env{'form.'.$tempkey.'_sec'};
4072: } else {
4073: $newrules{$tempkey.'_value'}=$env{'form.'.$tempkey.'_value'};
4074: $newrules{$tempkey.'_triggervalue'}=$env{'form.'.$tempkey.'_triggervalue'};
4075: }
4076: } else {
4077: push(@delrules,$tempkey.'_action');
4078: push(@delrules,$tempkey.'_type');
4079: push(@delrules,$tempkey.'_hours');
4080: push(@delrules,$tempkey.'_min');
4081: push(@delrules,$tempkey.'_sec');
4082: push(@delrules,$tempkey.'_value');
4083: }
4084: }
4085: }
4086: foreach my $key (keys %allparms) {
4087: $newrules{$key.'_triggers'}=$triggers{$key};
4088: }
4089: &Apache::lonnet::put('parmdefactions',\%newrules,$dom,$crs);
4090: &Apache::lonnet::del('parmdefactions',\@delrules,$dom,$crs);
4091: &resetrulescache();
4092: }
4093: my %lt=&Apache::lonlocal::texthash('days' => 'Days',
4094: 'hours' => 'Hours',
4095: 'min' => 'Minutes',
4096: 'sec' => 'Seconds',
4097: 'yes' => 'Yes',
4098: 'no' => 'No');
4099: my @standardoptions=('','default');
4100: my @standarddisplay=('',&mt('Default value when manually setting'));
4101: my @dateoptions=('','default');
4102: my @datedisplay=('',&mt('Default value when manually setting'));
4103: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
4104: unless ($tempkey) { next; }
4105: push @standardoptions,'when_setting_'.$tempkey;
4106: push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
4107: if (&isdateparm($defkeytype{$tempkey})) {
4108: push @dateoptions,'later_than_'.$tempkey;
4109: push @datedisplay,&mt('Automatically set later than ').$tempkey;
4110: push @dateoptions,'earlier_than_'.$tempkey;
4111: push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
4112: }
4113: }
4114: $r->print(&mt('Manual setting rules apply to all interfaces.').'<br />'.
4115: &mt('Automatic setting rules apply to table mode interfaces only.'));
4116: $r->print("\n".&Apache::loncommon::start_data_table().
4117: &Apache::loncommon::start_data_table_header_row().
4118: "<th>".&mt('Rule for parameter').'</th><th>'.
4119: &mt('Action').'</th><th>'.&mt('Value').'</th>'.
4120: &Apache::loncommon::end_data_table_header_row());
4121: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
4122: unless ($tempkey) { next; }
4123: $r->print("\n".&Apache::loncommon::start_data_table_row().
4124: "<td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
4125: my $action=&rulescache($tempkey.'_action');
4126: $r->print('<select name="'.$tempkey.'_action">');
4127: if (&isdateparm($defkeytype{$tempkey})) {
4128: for (my $i=0;$i<=$#dateoptions;$i++) {
4129: if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
4130: $r->print("\n<option value='$dateoptions[$i]'".
4131: ($dateoptions[$i] eq $action?' selected="selected"':'').
4132: ">$datedisplay[$i]</option>");
4133: }
4134: } else {
4135: for (my $i=0;$i<=$#standardoptions;$i++) {
4136: if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
4137: $r->print("\n<option value='$standardoptions[$i]'".
4138: ($standardoptions[$i] eq $action?' selected="selected"':'').
4139: ">$standarddisplay[$i]</option>");
4140: }
4141: }
4142: $r->print('</select>');
4143: unless (&isdateparm($defkeytype{$tempkey})) {
4144: $r->print("\n<br />".&mt('Triggering value(s) of other parameter (optional, comma-separated):').
4145: '<input type="text" size="20" name="'.$tempkey.'_triggervalue" value="'.&rulescache($tempkey.'_triggervalue').'" />');
4146: }
4147: $r->print("\n</td><td>\n");
4148:
4149: if (&isdateparm($defkeytype{$tempkey})) {
4150: my $days=&rulescache($tempkey.'_days');
4151: my $hours=&rulescache($tempkey.'_hours');
4152: my $min=&rulescache($tempkey.'_min');
4153: my $sec=&rulescache($tempkey.'_sec');
4154: $r->print(<<ENDINPUTDATE);
4155: <input name="$tempkey\_days" type="text" size="4" value="$days" />$lt{'days'}<br />
4156: <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
4157: <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
4158: <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
4159: ENDINPUTDATE
4160: } elsif ($defkeytype{$tempkey} eq 'string_yesno') {
4161: my $yeschecked='';
4162: my $nochecked='';
4163: if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked=' checked="checked"'; }
4164: if (&rulescache($tempkey.'_value') eq 'no') { $nochecked=' checked="checked"'; }
4165:
4166: $r->print(<<ENDYESNO);
4167: <label><input type="radio" name="$tempkey\_value" value="yes"$yeschecked /> $lt{'yes'}</label><br />
4168: <label><input type="radio" name="$tempkey\_value" value="no"$nochecked /> $lt{'no'}</label>
4169: ENDYESNO
4170: } else {
4171: $r->print('<input type="text" size="20" name="'.$tempkey.'_value" value="'.&rulescache($tempkey.'_value').'" />');
4172: }
4173: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
4174: }
4175: $r->print(&Apache::loncommon::end_data_table().
4176: "\n".'<input type="submit" name="storerules" value="'.
4177: &mt('Save').'" /></form>'."\n".
4178: &Apache::loncommon::end_page());
4179: return;
4180: }
4181:
4182: sub components {
4183: my ($key,$uname,$udom,$exeuser,$exedomain,$typeflag)=@_;
4184:
4185: if ($typeflag) {
4186: $key=~s/\.type$//;
4187: }
4188:
4189: my ($middle,$part,$name)=
4190: ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
4191: my $issection;
4192:
4193: my $section=&mt('All Students');
4194: if ($middle=~/^\[(.*)\]/) {
4195: $issection=$1;
4196: $section=&mt('Group/Section').': '.$issection;
4197: $middle=~s/^\[(.*)\]//;
4198: }
4199: $middle=~s/\.+$//;
4200: $middle=~s/^\.+//;
4201: if ($uname) {
4202: $section=&mt('User').": ".&Apache::loncommon::plainname($uname,$udom);
4203: $issection='';
4204: }
4205: my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
4206: my $realmdescription=&mt('all resources');
4207: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
4208: $realm='<span class="LC_parm_scope_folder">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <span class="LC_parm_folder"><br />('.$1.')</span></span>';
4209: $realmdescription=&mt('folder').' '.&Apache::lonnet::gettitle($1);
4210: } elsif ($middle) {
4211: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
4212: $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>';
4213: $realmdescription=&mt('resource').' '.&Apache::lonnet::gettitle($middle);
4214: }
4215: my $what=$part.'.'.$name;
4216: return ($realm,$section,$name,$part,
4217: $what,$middle,$uname,$udom,$issection,$realmdescription);
4218: }
4219:
4220: my %standard_parms;
4221: my %standard_parms_types;
4222:
4223: sub load_parameter_names {
4224: open(my $config,"<$Apache::lonnet::perlvar{'lonTabDir'}/packages.tab");
4225: while (my $configline=<$config>) {
4226: if ($configline !~ /\S/ || $configline=~/^\#/) { next; }
4227: chomp($configline);
4228: my ($short,$plain)=split(/:/,$configline);
4229: my (undef,$name,$type)=split(/\&/,$short,3);
4230: if ($type eq 'display') {
4231: $standard_parms{$name} = $plain;
4232: } elsif ($type eq 'type') {
4233: $standard_parms_types{$name} = $plain;
4234: }
4235: }
4236: close($config);
4237: $standard_parms{'int_pos'} = 'Positive Integer';
4238: $standard_parms{'int_zero_pos'} = 'Positive Integer or Zero';
4239: %standard_parms=&Apache::lonlocal::texthash(%standard_parms);
4240: }
4241:
4242: sub standard_parameter_names {
4243: my ($name)=@_;
4244: if (!%standard_parms) {
4245: &load_parameter_names();
4246: }
4247: if ($standard_parms{$name}) {
4248: return $standard_parms{$name};
4249: } else {
4250: return $name;
4251: }
4252: }
4253:
4254: sub standard_parameter_types {
4255: my ($name)=@_;
4256: if (!%standard_parms_types) {
4257: &load_parameter_names();
4258: }
4259: if ($standard_parms_types{$name}) {
4260: return $standard_parms_types{$name};
4261: }
4262: return;
4263: }
4264:
4265: sub parm_change_log {
4266: my ($r)=@_;
4267: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
4268: text=>"Parameter Change Log"});
4269: $r->print(&Apache::loncommon::start_page('Parameter Change Log'));
4270: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Change Log'));
4271:
4272: my %parmlog=&Apache::lonnet::dump('nohist_parameterlog',
4273: $env{'course.'.$env{'request.course.id'}.'.domain'},
4274: $env{'course.'.$env{'request.course.id'}.'.num'});
4275:
4276: if ((keys(%parmlog))[0]=~/^error\:/) { undef(%parmlog); }
4277:
4278: $r->print('<form action="/adm/parmset?action=parameterchangelog"
4279: method="post" name="parameterlog">');
4280:
4281: my %saveable_parameters = ('show' => 'scalar',);
4282: &Apache::loncommon::store_course_settings('parameter_log',
4283: \%saveable_parameters);
4284: &Apache::loncommon::restore_course_settings('parameter_log',
4285: \%saveable_parameters);
4286: $r->print(&Apache::loncommon::display_filter().
4287: '<label>'.&Apache::lonhtmlcommon::checkbox('includetypes',$env{'form.includetypes'},'1').
4288: ' '.&mt('Include parameter types').'</label>'.
4289: '<input type="submit" value="'.&mt('Display').'" /></form>');
4290:
4291: my $courseopt=&Apache::lonnet::get_courseresdata($env{'course.'.$env{'request.course.id'}.'.num'},
4292: $env{'course.'.$env{'request.course.id'}.'.domain'});
4293: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
4294: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Extent').'</th><th>'.&mt('Users').'</th><th>'.
4295: &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th><th>'.&mt('Announce').'</th>'.
4296: &Apache::loncommon::end_data_table_header_row());
4297: my $shown=0;
4298: my $folder='';
4299: if ($env{'form.displayfilter'} eq 'currentfolder') {
4300: my $last='';
4301: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
4302: &GDBM_READER(),0640)) {
4303: $last=$hash{'last_known'};
4304: untie(%hash);
4305: }
4306: if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
4307: }
4308: foreach my $id (sort
4309: {
4310: if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
4311: return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'}
4312: }
4313: my $aid = (split('00000',$a))[-1];
4314: my $bid = (split('00000',$b))[-1];
4315: return $bid<=>$aid;
4316: } (keys(%parmlog))) {
4317: my @changes=keys(%{$parmlog{$id}{'logentry'}});
4318: my $count = 0;
4319: my $time =
4320: &Apache::lonlocal::locallocaltime($parmlog{$id}{'exe_time'});
4321: my $plainname =
4322: &Apache::loncommon::plainname($parmlog{$id}{'exe_uname'},
4323: $parmlog{$id}{'exe_udom'});
4324: my $about_me_link =
4325: &Apache::loncommon::aboutmewrapper($plainname,
4326: $parmlog{$id}{'exe_uname'},
4327: $parmlog{$id}{'exe_udom'});
4328: my $send_msg_link='';
4329: if ((($parmlog{$id}{'exe_uname'} ne $env{'user.name'})
4330: || ($parmlog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
4331: $send_msg_link ='<br />'.
4332: &Apache::loncommon::messagewrapper(&mt('Send message'),
4333: $parmlog{$id}{'exe_uname'},
4334: $parmlog{$id}{'exe_udom'});
4335: }
4336: my $row_start=&Apache::loncommon::start_data_table_row();
4337: my $makenewrow=0;
4338: my %istype=();
4339: my $output;
4340: foreach my $changed (reverse(sort(@changes))) {
4341: my $value=$parmlog{$id}{'logentry'}{$changed};
4342: my $typeflag = ($changed =~/\.type$/ &&
4343: !exists($parmlog{$id}{'logentry'}{$changed.'.type'}));
4344: my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
4345: &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag);
4346: if ($env{'form.displayfilter'} eq 'currentfolder') {
4347: if ($folder) {
4348: if ($middle!~/^\Q$folder\E/) { next; }
4349: }
4350: }
4351: if ($typeflag) {
4352: $istype{$parmname}=$value;
4353: if (!$env{'form.includetypes'}) { next; }
4354: }
4355: $count++;
4356: if ($makenewrow) {
4357: $output .= $row_start;
4358: } else {
4359: $makenewrow=1;
4360: }
4361: $output .='<td>'.$realm.'</td><td>'.$section.'</td><td>'.
4362: &standard_parameter_names($parmname).'</td><td>'.
4363: ($part?&mt('Part: [_1]',$part):&mt('All Parts')).'</td><td>';
4364: my $stillactive=0;
4365: if ($parmlog{$id}{'delflag'}) {
4366: $output .= &mt('Deleted');
4367: } else {
4368: if ($typeflag) {
4369: $output .= &mt('Type: [_1]',&standard_parameter_names($value));
4370: } else {
4371: my ($level,@all)=&parmval_by_symb($what,$middle,&Apache::lonnet::metadata($middle,$what),
4372: $uname,$udom,$issection,$issection,$courseopt);
4373: my $showvalue = $value;
4374: if ($istype{$parmname} eq '') {
4375: my $type = &standard_parameter_types($parmname);
4376: if ($type ne '') {
4377: if (&isdateparm($type)) {
4378: $showvalue =
4379: &Apache::lonlocal::locallocaltime($value);
4380: }
4381: }
4382: } else {
4383: if (&isdateparm($istype{$parmname})) {
4384: $showvalue =
4385: &Apache::lonlocal::locallocaltime($value);
4386: }
4387: }
4388: $output .= $showvalue;
4389: if ($value ne $all[$level]) {
4390: $output .= '<br /><span class="LC_warning">'.&mt('Not active anymore').'</span>';
4391: } else {
4392: $stillactive=1;
4393: }
4394: }
4395: }
4396: $output .= '</td><td>';
4397: if ($stillactive) {
4398: my $title=&mt('Changed [_1]',&standard_parameter_names($parmname));
4399: my $description=&mt('Changed [_1] for [_2] to [_3]',&standard_parameter_names($parmname),$realmdescription,
4400: (&isdateparm($istype{$parmname})?&Apache::lonlocal::locallocaltime($value):$value));
4401: if (($uname) && ($udom)) {
4402: $output .=
4403: &Apache::loncommon::messagewrapper('Notify User',
4404: $uname,$udom,$title,
4405: $description);
4406: } else {
4407: $output .=
4408: &Apache::lonrss::course_blog_link($id,$title,
4409: $description);
4410: }
4411: }
4412: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4413: }
4414: if ($env{'form.displayfilter'} eq 'containing') {
4415: my $wholeentry=$about_me_link.':'.
4416: $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'.
4417: $output;
4418: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
4419: }
4420: if ($count) {
4421: $r->print($row_start.'<td rowspan="'.$count.'">'.$time.'</td>
4422: <td rowspan="'.$count.'">'.$about_me_link.
4423: '<br /><tt>'.$parmlog{$id}{'exe_uname'}.
4424: ':'.$parmlog{$id}{'exe_udom'}.'</tt>'.
4425: $send_msg_link.'</td>'.$output);
4426: $shown++;
4427: }
4428: if (!($env{'form.show'} eq &mt('all')
4429: || $shown<=$env{'form.show'})) { last; }
4430: }
4431: $r->print(&Apache::loncommon::end_data_table());
4432: $r->print(&Apache::loncommon::end_page());
4433: }
4434:
4435: sub update_slots {
4436: my ($slot_name,$cdom,$cnum,$symb,$uname,$udom) = @_;
4437: my %slot=&Apache::lonnet::get_slot($slot_name);
4438: if (!keys(%slot)) {
4439: return 'error: slot does not exist';
4440: }
4441: my $max=$slot{'maxspace'};
4442: if (!defined($max)) { $max=99999; }
4443:
4444: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
4445: "^$slot_name\0");
4446: my ($tmp)=%consumed;
4447: if ($tmp=~/^error: 2 / ) {
4448: return 'error: unable to determine current slot status';
4449: }
4450: my $last=0;
4451: foreach my $key (keys(%consumed)) {
4452: my $num=(split('\0',$key))[1];
4453: if ($num > $last) { $last=$num; }
4454: if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
4455: return 'ok';
4456: }
4457: }
4458:
4459: if (scalar(keys(%consumed)) >= $max) {
4460: return 'error: no space left in slot';
4461: }
4462: my $wanted=$last+1;
4463:
4464: my %reservation=('name' => $uname.':'.$udom,
4465: 'timestamp' => time,
4466: 'symb' => $symb);
4467:
4468: my $success=&Apache::lonnet::newput('slot_reservations',
4469: {"$slot_name\0$wanted" =>
4470: \%reservation},
4471: $cdom, $cnum);
4472: if ($success eq 'ok') {
4473: my %storehash = (
4474: symb => $symb,
4475: slot => $slot_name,
4476: action => 'reserve',
4477: context => 'parameter',
4478: );
4479: &Apache::lonnet::instructor_log('slotreservationslog',\%storehash,
4480: '',$uname,$udom,$cnum,$cdom);
4481:
4482: &Apache::lonnet::instructor_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
4483: '',$uname,$udom,$uname,$udom);
4484: }
4485: return $success;
4486: }
4487:
4488: sub delete_slots {
4489: my ($slot_name,$cdom,$cnum,$uname,$udom,$symb) = @_;
4490: my $delresult;
4491: my %consumed = &Apache::lonnet::dump('slot_reservations',$cdom,
4492: $cnum, "^$slot_name\0");
4493: if (&Apache::lonnet::error(%consumed)) {
4494: return 'error: unable to determine current slot status';
4495: }
4496: my ($tmp)=%consumed;
4497: if ($tmp=~/^error: 2 /) {
4498: return 'error: unable to determine current slot status';
4499: }
4500: foreach my $key (keys(%consumed)) {
4501: if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
4502: my $num=(split('\0',$key))[1];
4503: my $entry = $slot_name.'\0'.$num;
4504: $delresult = &Apache::lonnet::del('slot_reservations',[$entry],
4505: $cdom,$cnum);
4506: if ($delresult eq 'ok') {
4507: my %storehash = (
4508: symb => $symb,
4509: slot => $slot_name,
4510: action => 'release',
4511: context => 'parameter',
4512: );
4513: &Apache::lonnet::instructor_log('slotreservationslog',\%storehash,
4514: 1,$uname,$udom,$cnum,$cdom);
4515: &Apache::lonnet::instructor_log($cdom.'_'.$cnum.'_slotlog',\%storehash,
4516: 1,$uname,$udom,$uname,$udom);
4517: }
4518: }
4519: }
4520: return $delresult;
4521: }
4522:
4523: sub check_for_course_info {
4524: my $navmap = Apache::lonnavmaps::navmap->new();
4525: return 1 if ($navmap);
4526: return 0;
4527: }
4528:
4529:
4530: sub handler {
4531: my $r=shift;
4532:
4533: &reset_caches();
4534:
4535: &Apache::loncommon::content_type($r,'text/html');
4536: $r->send_http_header;
4537: return OK if $r->header_only;
4538:
4539: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
4540: ['action','state',
4541: 'pres_marker',
4542: 'pres_value',
4543: 'pres_type',
4544: 'udom','uname','symb','serial','timebase']);
4545:
4546:
4547: &Apache::lonhtmlcommon::clear_breadcrumbs();
4548: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
4549: text=>"Parameter Manager",
4550: faq=>10,
4551: bug=>'Instructor Interface',
4552: help =>
4553: 'Parameter_Manager,Course_Environment,Parameter_Helper,Parameter_Overview,Table_Mode'});
4554:
4555: # ----------------------------------------------------- Needs to be in a course
4556: my $parm_permission =
4557: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
4558: &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
4559: $env{'request.course.sec'}));
4560: my $exists = &check_for_course_info();
4561:
4562: if ($env{'request.course.id'} && $parm_permission && $exists) {
4563: #
4564: # Main switch on form.action and form.state, as appropriate
4565: #
4566: # Check first if coming from someone else headed directly for
4567: # the table mode
4568: if ((($env{'form.command'} eq 'set') && ($env{'form.url'})
4569: && (!$env{'form.dis'})) || ($env{'form.symb'})) {
4570: &assessparms($r);
4571: } elsif (! exists($env{'form.action'})) {
4572: &print_main_menu($r,$parm_permission);
4573: } elsif ($env{'form.action'} eq 'setoverview') {
4574: &overview($r);
4575: } elsif ($env{'form.action'} eq 'addmetadata') {
4576: &addmetafield($r);
4577: } elsif ($env{'form.action'} eq 'ordermetadata') {
4578: &order_meta_fields($r);
4579: } elsif ($env{'form.action'} eq 'setrestrictmeta') {
4580: &setrestrictmeta($r);
4581: } elsif ($env{'form.action'} eq 'newoverview') {
4582: &newoverview($r);
4583: } elsif ($env{'form.action'} eq 'setdefaults') {
4584: &defaultsetter($r);
4585: } elsif ($env{'form.action'} eq 'settable') {
4586: &assessparms($r);
4587: } elsif ($env{'form.action'} eq 'parameterchangelog') {
4588: &parm_change_log($r);
4589: } elsif ($env{'form.action'} eq 'cleanparameters') {
4590: &clean_parameters($r);
4591: } elsif ($env{'form.action'} eq 'dateshift1') {
4592: &date_shift_one($r);
4593: } elsif ($env{'form.action'} eq 'dateshift2') {
4594: &date_shift_two($r);
4595: } elsif ($env{'form.action'} eq 'categorizecourse') {
4596: &assign_course_categories($r);
4597: }
4598: } else {
4599: # ----------------------------- Not in a course, or not allowed to modify parms
4600: if ($exists) {
4601: $env{'user.error.msg'}=
4602: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
4603: } else {
4604: $env{'user.error.msg'}=
4605: "/adm/parmset::0:1:Course environment gone, reinitialize the course";
4606: }
4607: return HTTP_NOT_ACCEPTABLE;
4608: }
4609: &reset_caches();
4610:
4611: return OK;
4612: }
4613:
4614: 1;
4615: __END__
4616:
4617:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>