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