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