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