File:
[LON-CAPA] /
loncom /
interface /
lonparmset.pm
Revision
1.594:
download - view:
text,
annotated -
select for diffs
Mon Feb 10 02:11:46 2020 UTC (4 years, 6 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 5349: Parameter management by users with a section-specific role ...
- No setting user-specific parameter if student not in current section
- In overview mode, input elements enabled for current section
- Date shift only applies to date parameters for current section
1: # The LearningOnline Network with CAPA
2: # Handler to set parameters for assessments
3: #
4: # $Id: lonparmset.pm,v 1.594 2020/02/10 02:11:46 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 content parameters in a
40: course.
41:
42: It contains all the code for the "Content and Problem Settings" UI, except
43: for the helpers parameter.helper and resettimes.helper, and lonhelper.pm,
44: and lonblockingmenu.pm.
45:
46: =head1 DESCRIPTION
47:
48: This module sets coursewide and assessment parameters.
49:
50: =head1 INTERNAL SUBROUTINES
51:
52: =over
53:
54: =item parmval()
55:
56: Figure out a cascading parameter.
57:
58: Inputs: $what - a parameter spec (incluse part info and name I.E. 0.weight)
59: $id - a bighash Id number
60: $def - the resource's default value 'stupid emacs
61:
62: Returns: A list, the first item is the index into the remaining list of items of parm values that is the active one, the list consists of parm values at the 18 possible levels
63:
64: 18 - General Course
65: 17 - Map or Folder level in course (recursive)
66: 16 - Map or Folder level in course (non-recursive)
67: 15 - resource default
68: 14 - map default
69: 13 - resource level in course
70: 12 - General for section
71: 11 - Map or Folder level for section (recursive)
72: 10 - Map or Folder level for section (non-recursive)
73: 9 - resource level in section
74: 8 - General for group
75: 7 - Map or Folder level for group (recursive)
76: 6 - Map or Folder level for group (non-recursive)
77: 5 - resource level in group
78: 4 - General for specific student
79: 3 - Map or Folder level for specific student (recursive)
80: 2 - Map or Folder level for specific student (non-recursive)
81: 1 - resource level for specific student
82:
83: =item parmval_by_symb()
84:
85: =item reset_caches()
86:
87: =item cacheparmhash()
88:
89: =item parmhash()
90:
91: =item symbcache()
92:
93: =item preset_defaults()
94:
95: =item date_sanity_info()
96:
97: =item storeparm()
98:
99: Store a parameter by symb
100:
101: Takes
102: - symb
103: - name of parameter
104: - level
105: - new value
106: - new type
107: - username
108: - userdomain
109:
110: =item log_parmset()
111:
112: =item storeparm_by_symb_inner()
113:
114: =item valout()
115:
116: Format a value for output.
117:
118: Inputs: $value, $type, $editable
119:
120: Returns: $value, formatted for output. If $type indicates it is a date,
121: localtime($value) is returned.
122: $editable will return an icon to click on
123:
124: =item plink()
125:
126: Produces a link anchor.
127:
128: Inputs: $type,$dis,$value,$marker,$return,$call
129:
130: Returns: scalar with html code for a link which will envoke the
131: javascript function 'pjump'.
132:
133: =item page_js()
134:
135: =item startpage()
136:
137: =item print_row()
138:
139: =item print_td()
140:
141: =item check_other_groups()
142:
143: =item parm_control_group()
144:
145: =item extractResourceInformation() :
146:
147: extractResourceInformation extracts lots of information about all of the the course's resources into a variety of hashes.
148:
149: Input: See list below
150:
151: =over 4
152:
153: =item * B<env{'user.name'}> : Current username
154:
155: =item * B<env{'user.domain'}> : Domain of current user.
156:
157: =item * B<env{"request.course.fn"}> : Course
158:
159: =back
160:
161: Outputs: See list below:
162:
163: =over 4
164:
165: =item * B<ids> (out) : An array that will contain all of the ids in the course.
166:
167: =item * B<typep>(out) : hash, id->type, where "type" contains the extension of the file, thus, I<problem exam quiz assess survey form>.
168:
169: =item * B<keyp> (out) : hash, id->key list, will contain a comma separated list of the meta-data keys available for the given id
170:
171: =item * B<allparms> (out) : hash, name of parameter->display value (what is the display value?)
172:
173: =item * B<allparts> (out) : hash, part identification->text representation of part, where the text representation is "[Part $part]"
174:
175: =item * B<allmaps> (out) : hash, ???
176:
177: =item * B<mapp> : ??
178:
179: =item * B<symbp> : hash, id->full sym?
180:
181: =item * B<maptitles>
182:
183: =item * B<uris>
184:
185: =item * B<keyorder>
186:
187: =item * B<defkeytype>
188:
189: =back
190:
191: =item isdateparm()
192:
193: =item parmmenu()
194:
195: =item partmenu()
196:
197: =item usermenu()
198:
199: =item displaymenu()
200:
201: =item mapmenu()
202:
203: =item levelmenu()
204:
205: =item sectionmenu()
206:
207: =item keysplit()
208:
209: =item keysinorder()
210:
211: =item keysinorder_bytype()
212:
213: =item keysindisplayorder()
214:
215: =item standardkeyorder()
216:
217: =item assessparms() :
218:
219: Show assessment data and parameters. This is a large routine that should
220: be simplified and shortened... someday.
221:
222: Inputs: $r - the Apache request object.
223:
224: Returns: nothing
225:
226: Variables used (guessed by Jeremy):
227:
228: =over
229:
230: =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.
231:
232: =item * B<psprt>: ParameterS PaRTs? a list of the parts of a problem that we are displaying? Used to display only selected parts?
233:
234: =item * B<@catmarker> contains list of all possible parameters including part #s
235:
236: =item * B<$fullkeyp> contains the full part/id # for the extraction of proper parameters
237:
238: =item * B<$tempkeyp> contains part 0 only (no ids - ie, subparts)
239: When storing information, store as part 0
240: When requesting information, request from full part
241:
242: =back
243:
244: =item tablestart()
245:
246: =item tableend()
247:
248: =item extractuser()
249:
250: =item parse_listdata_key()
251:
252: =item listdata()
253:
254: =item date_interval_selector()
255:
256: =item get_date_interval_from_form()
257:
258: =item default_selector()
259:
260: =item string_selector()
261:
262: =item dateshift()
263:
264: =item newoverview()
265:
266: =item secgroup_lister()
267:
268: =item overview()
269:
270: =item clean_parameters()
271:
272: =item date_shift_one()
273:
274: =item date_shift_two()
275:
276: =item parse_key()
277:
278: =item header()
279:
280: Output html header for page
281:
282: =item print_main_menu()
283:
284: =item output_row()
285:
286: Set portfolio metadata
287:
288: =item order_meta_fields()
289:
290: =item addmetafield()
291:
292: =item setrestrictmeta()
293:
294: =item get_added_meta_fieldnames()
295:
296: =item get_deleted_meta_fieldnames()
297:
298: =item defaultsetter()
299:
300: =item components()
301:
302: =item load_parameter_names()
303:
304: =item parm_change_log()
305:
306: =item handler() :
307:
308: Main handler. Calls &assessparms subroutine.
309:
310: =back
311:
312: =cut
313:
314: ###################################################################
315: ###################################################################
316:
317: package Apache::lonparmset;
318:
319: use strict;
320: use Apache::lonnet;
321: use Apache::Constants qw(:common :http REDIRECT);
322: use Apache::lonhtmlcommon();
323: use Apache::loncommon;
324: use GDBM_File;
325: use Apache::lonhomework;
326: use Apache::lonxml;
327: use Apache::lonlocal;
328: use Apache::lonnavmaps;
329: use Apache::longroup;
330: use Apache::lonrss;
331: use HTML::Entities;
332: use LONCAPA qw(:DEFAULT :match);
333:
334:
335: ##################################################
336: # CONTENT AND PROBLEM SETTINGS HTML PAGE HEADER/FOOTER
337: ##################################################
338:
339: # Page header
340: #
341: # @param {Apache2::RequestRec} $r - Apache request object
342: # @param {string} $mode - selected tab, 'parmset' for course and problem settings, or 'coursepref' for course settings
343: # @param {string} $crstype - course type ('Community' for community settings)
344: sub startSettingsScreen {
345: my ($r,$mode,$crstype)=@_;
346:
347: my $tabtext = &mt('Course Settings');
348: if ($crstype eq 'Community') {
349: $tabtext = &mt('Community Settings');
350: }
351: $r->print("\n".'<ul class="LC_TabContentBigger" id="main">');
352: $r->print("\n".'<li'.($mode eq 'coursepref'?' class="active"':'').'><a href="/adm/courseprefs"><b> '.
353: $tabtext.
354: ' </b></a></li>');
355:
356: $r->print("\n".'<li'.($mode eq 'parmset'?' class="active"':'').' id="tabbededitor"><a href="/adm/parmset"><b>'.
357: &mt('Content and Problem Settings').'</b></a></li>');
358: $r->print("\n".'</ul>'."\n");
359: $r->print('<div class="LC_Box" style="clear:both;margin:0;" id="parameditor"><div id="maincoursedoc" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
360: }
361:
362: # Page footer
363: sub endSettingsScreen {
364: my ($r)=@_;
365: $r->print('</div></div></div>');
366: }
367:
368:
369:
370: ##################################################
371: # (mostly) TABLE MODE
372: # (parmval is also used for the log of parameter changes)
373: ##################################################
374:
375: # Calls parmval_by_symb, getting the symb from $id with &symbcache.
376: #
377: # @param {string} $what - part info and parameter name separated by a dot, e.g. '0.weight'
378: # @param {string} $id - resource id or map pc
379: # @param {string} $def - the resource's default value for this parameter
380: # @param {string} $uname - user name
381: # @param {string} $udom - user domain
382: # @param {string} $csec - section name
383: # @param {string} $cgroup - group name
384: # @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
385: # @returns {Array}
386: sub parmval {
387: my ($what,$id,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
388: return &parmval_by_symb($what,&symbcache($id),$def,$uname,$udom,$csec,
389: $cgroup,$courseopt);
390: }
391:
392: # Returns an array containing
393: # - the most specific level that is defined for that parameter (integer)
394: # - an array with the level as index and the parameter value as value (when defined)
395: # (level 1 is the most specific and will have precedence)
396: #
397: # @param {string} $what - part info and parameter name separated by a dot, e.g. '0.weight'
398: # @param {string} $symb - resource symb or map src
399: # @param {string} $def - the resource's default value for this parameter
400: # @param {string} $uname - user name
401: # @param {string} $udom - user domain
402: # @param {string} $csec - section name
403: # @param {string} $cgroup - group name
404: # @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
405: # @returns {Array}
406: sub parmval_by_symb {
407: my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
408:
409: my $useropt;
410: if ($uname ne '' && $udom ne '') {
411: $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
412: }
413:
414: my $result='';
415: my @outpar=();
416: # ----------------------------------------------------- Cascading lookup scheme
417: my $map=(&Apache::lonnet::decode_symb($symb))[0];
418: $map = &Apache::lonnet::deversion($map);
419:
420: # NOTE: some of that code looks redondant with code in lonnavmaps::parmval_real,
421: # any change should be reflected there.
422:
423: my $symbparm=$symb.'.'.$what;
424: my $recurseparm=$map.'___(rec).'.$what;
425: my $mapparm=$map.'___(all).'.$what;
426:
427: my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$what;
428: my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
429: my $grpleveli=$env{'request.course.id'}.'.['.$cgroup.'].'.$recurseparm;
430: my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
431:
432: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$what;
433: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
434: my $secleveli=$env{'request.course.id'}.'.['.$csec.'].'.$recurseparm;
435: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
436:
437: my $courselevel=$env{'request.course.id'}.'.'.$what;
438: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
439: my $courseleveli=$env{'request.course.id'}.'.'.$recurseparm;
440: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
441:
442:
443: # --------------------------------------------------------- first, check course
444:
445: # 18 - General Course
446: if (defined($$courseopt{$courselevel})) {
447: $outpar[18]=$$courseopt{$courselevel};
448: $result=18;
449: }
450:
451: # 17 - Map or Folder level in course (recursive)
452: if (defined($$courseopt{$courseleveli})) {
453: $outpar[17]=$$courseopt{$courseleveli};
454: $result=17;
455: }
456:
457: # 16 - Map or Folder level in course (non-recursive)
458: if (defined($$courseopt{$courselevelm})) {
459: $outpar[16]=$$courseopt{$courselevelm};
460: $result=16;
461: }
462:
463: # ------------------------------------------------------- second, check default
464:
465: # 15 - resource default
466: if (defined($def)) { $outpar[15]=$def; $result=15; }
467:
468: # ------------------------------------------------------ third, check map parms
469:
470:
471: # 14 - map default
472: my $thisparm=&parmhash($symbparm);
473: if (defined($thisparm)) { $outpar[14]=$thisparm; $result=14; }
474:
475: # 13 - resource level in course
476: if (defined($$courseopt{$courselevelr})) {
477: $outpar[13]=$$courseopt{$courselevelr};
478: $result=13;
479: }
480:
481: # ------------------------------------------------------ fourth, back to course
482: if ($csec ne '') {
483: # 12 - General for section
484: if (defined($$courseopt{$seclevel})) {
485: $outpar[12]=$$courseopt{$seclevel};
486: $result=12;
487: }
488: # 11 - Map or Folder level for section (recursive)
489: if (defined($$courseopt{$secleveli})) {
490: $outpar[11]=$$courseopt{$secleveli};
491: $result=11;
492: }
493: # 10 - Map or Folder level for section (non-recursive)
494: if (defined($$courseopt{$seclevelm})) {
495: $outpar[10]=$$courseopt{$seclevelm};
496: $result=10;
497: }
498: # 9 - resource level in section
499: if (defined($$courseopt{$seclevelr})) {
500: $outpar[9]=$$courseopt{$seclevelr};
501: $result=9;
502: }
503: }
504: # ------------------------------------------------------ fifth, check course group
505: if ($cgroup ne '') {
506: # 8 - General for group
507: if (defined($$courseopt{$grplevel})) {
508: $outpar[8]=$$courseopt{$grplevel};
509: $result=8;
510: }
511: # 7 - Map or Folder level for group (recursive)
512: if (defined($$courseopt{$grpleveli})) {
513: $outpar[7]=$$courseopt{$grpleveli};
514: $result=7;
515: }
516: # 6 - Map or Folder level for group (non-recursive)
517: if (defined($$courseopt{$grplevelm})) {
518: $outpar[6]=$$courseopt{$grplevelm};
519: $result=6;
520: }
521: # 5 - resource level in group
522: if (defined($$courseopt{$grplevelr})) {
523: $outpar[5]=$$courseopt{$grplevelr};
524: $result=5;
525: }
526: }
527:
528: # ---------------------------------------------------------- sixth, check user
529:
530: if ($uname ne '') {
531: # 4 - General for specific student
532: if (defined($$useropt{$courselevel})) {
533: $outpar[4]=$$useropt{$courselevel};
534: $result=4;
535: }
536:
537: # 3 - Map or Folder level for specific student (recursive)
538: if (defined($$useropt{$courseleveli})) {
539: $outpar[3]=$$useropt{$courseleveli};
540: $result=3;
541: }
542:
543: # 2 - Map or Folder level for specific student (non-recursive)
544: if (defined($$useropt{$courselevelm})) {
545: $outpar[2]=$$useropt{$courselevelm};
546: $result=2;
547: }
548:
549: # 1 - resource level for specific student
550: if (defined($$useropt{$courselevelr})) {
551: $outpar[1]=$$useropt{$courselevelr};
552: $result=1;
553: }
554: }
555: return ($result,@outpar);
556: }
557:
558:
559:
560: # --- Caches local to lonparmset
561:
562:
563: # Reset lonparmset caches (called at the beginning and end of the handler).
564: sub reset_caches {
565: &resetparmhash();
566: &resetsymbcache();
567: &resetrulescache();
568: }
569:
570: # cache for map parameters, stored temporarily in $env{'request.course.fn'}_parms.db
571: # (these parameters come from param elements in .sequence files created with the advanced RAT)
572: {
573: my $parmhashid; # course identifier, to initialize the cache only once for a course
574: my %parmhash; # the parameter cache
575: # reset map parameter hash
576: sub resetparmhash {
577: undef($parmhashid);
578: undef(%parmhash);
579: }
580:
581: # dump the _parms.db database into %parmhash
582: sub cacheparmhash {
583: if ($parmhashid eq $env{'request.course.fn'}) { return; }
584: my %parmhashfile;
585: if (tie(%parmhashfile,'GDBM_File',
586: $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
587: %parmhash=%parmhashfile;
588: untie(%parmhashfile);
589: $parmhashid=$env{'request.course.fn'};
590: }
591: }
592:
593: # returns a parameter value for an identifier symb.parts.parameter, using the map parameter cache
594: sub parmhash {
595: my ($id) = @_;
596: &cacheparmhash();
597: return $parmhash{$id};
598: }
599: }
600:
601: # cache resource id or map pc -> resource symb or map src, using lonnavmaps to find association
602: {
603: my $symbsid; # course identifier, to initialize the cache only once for a course
604: my %symbs; # hash id->symb
605: # reset the id->symb cache
606: sub resetsymbcache {
607: undef($symbsid);
608: undef(%symbs);
609: }
610:
611: # returns the resource symb or map src corresponding to a resource id or map pc
612: # (using lonnavmaps and a cache)
613: sub symbcache {
614: my $id=shift;
615: if ($symbsid ne $env{'request.course.id'}) {
616: undef(%symbs);
617: }
618: if (!$symbs{$id}) {
619: my $navmap = Apache::lonnavmaps::navmap->new();
620: if ($id=~/\./) {
621: my $resource=$navmap->getById($id);
622: $symbs{$id}=$resource->symb();
623: } else {
624: my $resource=$navmap->getByMapPc($id);
625: $symbs{$id}=&Apache::lonnet::declutter($resource->src());
626: }
627: $symbsid=$env{'request.course.id'};
628: }
629: return $symbs{$id};
630: }
631: }
632:
633: # cache for parameter default actions (stored in parmdefactions.db)
634: {
635: my $rulesid; # course identifier, to initialize the cache only once for a course
636: my %rules; # parameter default actions hash
637: sub resetrulescache {
638: undef($rulesid);
639: undef(%rules);
640: }
641:
642: # returns the value for a given key in the parameter default action hash
643: sub rulescache {
644: my $id=shift;
645: if ($rulesid ne $env{'request.course.id'}
646: && !defined($rules{$id})) {
647: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
648: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
649: %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
650: $rulesid=$env{'request.course.id'};
651: }
652: return $rules{$id};
653: }
654: }
655:
656:
657: # Returns the values of the parameter type default action
658: # "default value when manually setting".
659: # If none is defined, ('','','','','') is returned.
660: #
661: # @param {string} $type - parameter type
662: # @returns {Array<string>} - (hours, min, sec, value)
663: sub preset_defaults {
664: my $type=shift;
665: if (&rulescache($type.'_action') eq 'default') {
666: # yes, there is something
667: return (&rulescache($type.'_hours'),
668: &rulescache($type.'_min'),
669: &rulescache($type.'_sec'),
670: &rulescache($type.'_value'));
671: } else {
672: # nothing there or something else
673: return ('','','','','');
674: }
675: }
676:
677:
678: # Checks that a date is after enrollment start date and before
679: # enrollment end date.
680: # Returns HTML with a warning if it is not, or the empty string otherwise.
681: # This is used by both overview and table modes.
682: #
683: # @param {integer} $checkdate - the date to check.
684: # @returns {string} - HTML possibly containing a localized warning message.
685: sub date_sanity_info {
686: my $checkdate=shift;
687: unless ($checkdate) { return ''; }
688: my $result='';
689: my $crsprefix='course.'.$env{'request.course.id'}.'.';
690: if ($env{$crsprefix.'default_enrollment_end_date'}) {
691: if ($checkdate>$env{$crsprefix.'default_enrollment_end_date'}) {
692: $result.='<div class="LC_warning">'
693: .&mt('After course enrollment end!')
694: .'</div>';
695: }
696: }
697: if ($env{$crsprefix.'default_enrollment_start_date'}) {
698: if ($checkdate<$env{$crsprefix.'default_enrollment_start_date'}) {
699: $result.='<div class="LC_warning">'
700: .&mt('Before course enrollment start!')
701: .'</div>';
702: }
703: }
704: # Preparation for additional warnings about dates in the past/future.
705: # An improved, more context sensitive version is recommended,
706: # e.g. warn for due and answer dates which are defined before the corresponding open date, etc.
707: # if ($checkdate<time) {
708: # $result.='<div class="LC_info">'
709: # .'('.&mt('in the past').')'
710: # .'</div>';
711: # }
712: # if ($checkdate>time) {
713: # $result.='<div class="LC_info">'
714: # .'('.&mt('in the future').')'
715: # .'</div>';
716: # }
717: return $result;
718: }
719:
720:
721: # Store a parameter value and type by ID, also triggering more parameter changes based on parameter default actions.
722: #
723: # @param {string} $sresid - resource id or map pc
724: # @param {string} $spnam - part info and parameter name separated by a dot or underscore, e.g. '0.weight'
725: # @param {integer} $snum - level
726: # @param {string} $nval - new value
727: # @param {string} $ntype - new type
728: # @param {string} $uname - username
729: # @param {string} $udom - userdomain
730: # @param {string} $csec - section name
731: # @param {string} $cgroup - group name
732: sub storeparm {
733: my ($sresid,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
734: &storeparm_by_symb(&symbcache($sresid),$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,'',$cgroup);
735: }
736:
737: my %recstack; # hash parameter name -> 1 when a parameter was used before in a recursive call to storeparm_by_symb
738:
739: # Store a parameter value and type by symb, also triggering more parameter changes based on parameter default actions.
740: # Uses storeparm_by_symb_inner to actually store the parameter, ignoring any returned error.
741: #
742: # @param {string} $symb - resource symb or map src
743: # @param {string} $spnam - part info and parameter name separated by a dot or underscore, e.g. '0.weight'
744: # @param {integer} $snum - level
745: # @param {string} $nval - new value
746: # @param {string} $ntype - new type
747: # @param {string} $uname - username
748: # @param {string} $udom - userdomain
749: # @param {string} $csec - section name
750: # @param {boolean} $recflag - should be true for recursive calls to storeparm_by_symb, false otherwise
751: # @param {string} $cgroup - group name
752: sub storeparm_by_symb {
753: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
754: unless ($recflag) {
755: # first time call
756: %recstack=();
757: $recflag=1;
758: }
759: # store parameter
760: &storeparm_by_symb_inner
761: ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup);
762: # don't do anything if parameter was reset
763: unless ($nval) { return; }
764: my ($prefix,$parm)=($spnam=~/^(.*[\_\.])([^\_\.]+)$/);
765: # remember that this was set
766: $recstack{$parm}=1;
767: # what does this trigger?
768: foreach my $triggered (split(/\:/,&rulescache($parm.'_triggers'))) {
769: # don't backfire
770: unless ((!$triggered) || ($recstack{$triggered})) {
771: my $action=&rulescache($triggered.'_action');
772: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
773: # set triggered parameter on same level
774: my $newspnam=$prefix.$triggered;
775: my $newvalue='';
776: my $active=1;
777: if ($action=~/^when\_setting/) {
778: # are there restrictions?
779: if (&rulescache($triggered.'_triggervalue')=~/\w/) {
780: $active=0;
781: foreach my $possiblevalue (split(/\s*\,\s*/,&rulescache($triggered.'_triggervalue'))) {
782: if (lc($possiblevalue) eq lc($nval)) { $active=1; }
783: }
784: }
785: $newvalue=&rulescache($triggered.'_value');
786: } else {
787: my $totalsecs=((&rulescache($triggered.'_days')*24+&rulescache($triggered.'_hours'))*60+&rulescache($triggered.'_min'))*60+&rulescache($triggered.'_sec');
788: if ($action=~/^later\_than/) {
789: $newvalue=$nval+$totalsecs;
790: } else {
791: $newvalue=$nval-$totalsecs;
792: }
793: }
794: if ($active) {
795: &storeparm_by_symb($symb,$newspnam,$snum,$newvalue,&rulescache($triggered.'_type'),
796: $uname,$udom,$csec,$recflag,$cgroup);
797: }
798: }
799: }
800: return '';
801: }
802:
803: # Adds all given arguments to the course parameter log.
804: # @returns {string} - the answer to the lonnet query.
805: sub log_parmset {
806: return &Apache::lonnet::write_log('course','parameterlog',@_);
807: }
808:
809: # Store a parameter value and type by symb, without using the parameter default actions.
810: # Expire related sheets.
811: #
812: # @param {string} $symb - resource symb or map src
813: # @param {string} $spnam - part info and parameter name separated by a dot, e.g. '0.weight'
814: # @param {integer} $snum - level
815: # @param {string} $nval - new value
816: # @param {string} $ntype - new type
817: # @param {string} $uname - username
818: # @param {string} $udom - userdomain
819: # @param {string} $csec - section name
820: # @param {string} $cgroup - group name
821: # @returns {string} - HTML code with an error message if the parameter could not be stored.
822: sub storeparm_by_symb_inner {
823: # ---------------------------------------------------------- Get symb, map, etc
824: my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$cgroup)=@_;
825: # ---------------------------------------------------------- Construct prefixes
826: $spnam=~s/\_([^\_]+)$/\.$1/;
827: my $map=(&Apache::lonnet::decode_symb($symb))[0];
828: $map = &Apache::lonnet::deversion($map);
829:
830: my $symbparm=$symb.'.'.$spnam;
831: my $recurseparm=$map.'___(rec).'.$spnam;
832: my $mapparm=$map.'___(all).'.$spnam;
833:
834: my $grplevel=$env{'request.course.id'}.'.['.$cgroup.'].'.$spnam;
835: my $grplevelr=$env{'request.course.id'}.'.['.$cgroup.'].'.$symbparm;
836: my $grpleveli=$env{'request.course.id'}.'.['.$cgroup.'].'.$recurseparm;
837: my $grplevelm=$env{'request.course.id'}.'.['.$cgroup.'].'.$mapparm;
838:
839: my $seclevel=$env{'request.course.id'}.'.['.$csec.'].'.$spnam;
840: my $seclevelr=$env{'request.course.id'}.'.['.$csec.'].'.$symbparm;
841: my $secleveli=$env{'request.course.id'}.'.['.$csec.'].'.$recurseparm;
842: my $seclevelm=$env{'request.course.id'}.'.['.$csec.'].'.$mapparm;
843:
844: my $courselevel=$env{'request.course.id'}.'.'.$spnam;
845: my $courselevelr=$env{'request.course.id'}.'.'.$symbparm;
846: my $courseleveli=$env{'request.course.id'}.'.'.$recurseparm;
847: my $courselevelm=$env{'request.course.id'}.'.'.$mapparm;
848:
849: my $storeunder='';
850: my $possreplace='';
851: if (($snum==18) || ($snum==4)) { $storeunder=$courselevel; }
852: if (($snum==17) || ($snum==3)) {
853: $storeunder=$courseleveli;
854: $possreplace=$courselevelm;
855: }
856: if (($snum==16) || ($snum==2)) {
857: $storeunder=$courselevelm;
858: $possreplace=$courseleveli;
859: }
860: if (($snum==13) || ($snum==1)) { $storeunder=$courselevelr; }
861: if ($snum==12) { $storeunder=$seclevel; }
862: if ($snum==11) {
863: $storeunder=$secleveli;
864: $possreplace=$seclevelm;
865: }
866: if ($snum==10) {
867: $storeunder=$seclevelm;
868: $possreplace=$secleveli;
869: }
870: if ($snum==9) { $storeunder=$seclevelr; }
871: if ($snum==8) { $storeunder=$grplevel; }
872: if ($snum==7) {
873: $storeunder=$grpleveli;
874: $possreplace=$grplevelm;
875: }
876: if ($snum==6) {
877: $storeunder=$grplevelm;
878: $possreplace=$grpleveli;
879: }
880: if ($snum==5) { $storeunder=$grplevelr; }
881:
882:
883: my $delete;
884: if ($nval eq '') { $delete=1;}
885: my %storecontent = ($storeunder => $nval,
886: $storeunder.'.type' => $ntype);
887: my $reply='';
888:
889: if ($snum>4) {
890: # ---------------------------------------------------------------- Store Course
891: #
892: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
893: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
894: # Expire sheets
895: &Apache::lonnet::expirespread('','','studentcalc');
896: if (($snum==13) || ($snum==9) || ($snum==5)) {
897: &Apache::lonnet::expirespread('','','assesscalc',$symb);
898: } elsif (($snum==17) || ($snum==16) || ($snum==11) || ($snum==10) || ($snum==7) || ($snum==6)) {
899: &Apache::lonnet::expirespread('','','assesscalc',$map);
900: } else {
901: &Apache::lonnet::expirespread('','','assesscalc');
902: }
903: # Store parameter
904: if ($delete) {
905: $reply=&Apache::lonnet::del
906: ('resourcedata',[keys(%storecontent)],$cdom,$cnum);
907: &log_parmset(\%storecontent,1);
908: } else {
909: $reply=&Apache::lonnet::cput
910: ('resourcedata',\%storecontent,$cdom,$cnum);
911: &log_parmset(\%storecontent);
912: if ($possreplace) {
913: my $resdata = &Apache::lonnet::get_courseresdata($cnum,$cdom);
914: if (ref($resdata) eq 'HASH') {
915: if (exists($resdata->{$possreplace})) {
916: if (&Apache::lonnet::del
917: ('resourcedata',[$possreplace,$possreplace.'.type'],$cdom,$cnum) eq 'ok') {
918: &log_parmset({$possreplace => '', $possreplace.'.type' => $ntype},1);
919: }
920: }
921: }
922: }
923: }
924: &Apache::lonnet::devalidatecourseresdata($cnum,$cdom);
925: } else {
926: # ------------------------------------------------------------------ Store User
927: #
928: # Expire sheets
929: &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
930: if ($snum==1) {
931: &Apache::lonnet::expirespread
932: ($uname,$udom,'assesscalc',$symb);
933: } elsif (($snum==2) || ($snum==3)) {
934: &Apache::lonnet::expirespread
935: ($uname,$udom,'assesscalc',$map);
936: } else {
937: &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
938: }
939: # Store parameter
940: if ($delete) {
941: $reply=&Apache::lonnet::del
942: ('resourcedata',[keys(%storecontent)],$udom,$uname);
943: &log_parmset(\%storecontent,1,$uname,$udom);
944: } else {
945: $reply=&Apache::lonnet::cput
946: ('resourcedata',\%storecontent,$udom,$uname);
947: &log_parmset(\%storecontent,0,$uname,$udom);
948: if ($possreplace) {
949: my $resdata = &Apache::lonnet::get_userresdata($uname,$udom);
950: if (ref($resdata) eq 'HASH') {
951: if (exists($resdata->{$possreplace})) {
952: if (&Apache::lonnet::del
953: ('resourcedata',[$possreplace,$possreplace.'.type'],$udom,$uname) eq 'ok') {
954: &log_parmset({$possreplace => '',$possreplace.'.type' => $ntype},1,
955: $uname,$udom);
956: }
957: }
958: }
959: }
960: }
961: &Apache::lonnet::devalidateuserresdata($uname,$udom);
962: }
963:
964: if ($reply=~/^error\:(.*)/) {
965: return "<span class=\"LC_error\">Write Error: $1</span>";
966: }
967: return '';
968: }
969:
970:
971: # Returns HTML with the value of the given parameter,
972: # using a readable format for dates, and
973: # a warning if there is a problem with a date.
974: # Used by table mode.
975: # Returns HTML for the editmap.png image if no value is defined and $editable is true.
976: #
977: # @param {string} $value - the parameter value
978: # @param {string} $type - the parameter type
979: # @param {boolean} $editable - Set to true to get an icon when no value is defined.
980: sub valout {
981: my ($value,$type,$name,$editable)=@_;
982: my $result = '';
983: # Values of zero are valid.
984: if (! $value && $value ne '0') {
985: if ($editable) {
986: $result =
987: '<img src="/res/adm/pages/editmap.png"'
988: .' alt="'.&mt('Change').'"'
989: .' title="'.&mt('Change').'" style="border:0;" />';
990: } else {
991: $result=' ';
992: }
993: } else {
994: if ($type eq 'date_interval') {
995: my ($totalsecs,$donesuffix) = split(/_/,$value,2);
996: my ($usesdone,$donebuttontext,$proctor,$secretkey);
997: if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
998: $donebuttontext = $1;
999: (undef,$proctor,$secretkey) = split(/_/,$2);
1000: $usesdone = 'done';
1001: } elsif ($donesuffix =~ /^done(|_.+)$/) {
1002: $donebuttontext = &mt('Done');
1003: ($usesdone,$proctor,$secretkey) = split(/_/,$donesuffix);
1004: }
1005: my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($totalsecs);
1006: my @timer;
1007: $year=$year-70;
1008: $mday--;
1009: if ($year) {
1010: # $result.=&mt('[quant,_1,yr]',$year).' ';
1011: push(@timer,&mt('[quant,_1,yr]',$year));
1012: }
1013: if ($mon) {
1014: # $result.=&mt('[quant,_1,mth]',$mon).' ';
1015: push(@timer,&mt('[quant,_1,mth]',$mon));
1016: }
1017: if ($mday) {
1018: # $result.=&mt('[quant,_1,day]',$mday).' ';
1019: push(@timer,&mt('[quant,_1,day]',$mday));
1020: }
1021: if ($hour) {
1022: # $result.=&mt('[quant,_1,hr]',$hour).' ';
1023: push(@timer,&mt('[quant,_1,hr]',$hour));
1024: }
1025: if ($min) {
1026: # $result.=&mt('[quant,_1,min]',$min).' ';
1027: push(@timer,&mt('[quant,_1,min]',$min));
1028: }
1029: if ($sec) {
1030: # $result.=&mt('[quant,_1,sec]',$sec).' ';
1031: push(@timer,&mt('[quant,_1,sec]',$sec));
1032: }
1033: # $result=~s/\s+$//;
1034: if (!@timer) { # Special case: all entries 0 -> display "0 secs" intead of empty field to keep this field editable
1035: push(@timer,&mt('[quant,_1,sec]',0));
1036: }
1037: $result.=join(", ",@timer);
1038: if ($usesdone eq 'done') {
1039: if ($secretkey) {
1040: $result .= ' '.&mt('+ "[_1]" with proctor key: [_2]',$donebuttontext,$secretkey);
1041: } else {
1042: $result .= ' + "'.$donebuttontext.'"';
1043: }
1044: }
1045: } elsif (&isdateparm($type)) {
1046: $result = &Apache::lonlocal::locallocaltime($value).
1047: &date_sanity_info($value);
1048: } else {
1049: $result = $value;
1050: $result=~s/\,/\, /gs;
1051: $result = &HTML::Entities::encode($result,'"<>&');
1052: }
1053: }
1054: return $result;
1055: }
1056:
1057:
1058: # Returns HTML containing a link on a parameter value, for table mode.
1059: # The link uses the javascript function 'pjump'.
1060: #
1061: # @param {string} $type - parameter type
1062: # @param {string} $dis - dialog title for editing the parameter value and type
1063: # @param {string} $value - parameter value
1064: # @param {string} $marker - identifier for the parameter, "resource id&part_parameter name&level", will be passed as pres_marker when the user submits a change.
1065: # @param {string} $return - prefix for the name of the form and field names that will be used to submit the form ('parmform.pres')
1066: # @param {string} $call - javascript function to call to submit the form ('psub')
1067: # @param {boolean} $recursive - true if link is for a map/folder where parameter is currently set to be recursive.
1068: # @param {string} $extra - optional additional information to send as tenth arg in call to javascript pjump function.
1069: sub plink {
1070: my ($type,$dis,$value,$marker,$return,$call,$recursive,$extra)=@_;
1071: my $winvalue=$value;
1072: unless ($winvalue) {
1073: if (&isdateparm($type) || (&is_specialstring($type))) {
1074: $winvalue=$env{'form.recent_'.$type};
1075: } elsif ($type eq 'string_yesno') {
1076: if ($env{'form.recent_string'} =~ /^(yes|no)$/i) {
1077: $winvalue=$env{'form.recent_string'};
1078: }
1079: } else {
1080: $winvalue=$env{'form.recent_'.(split(/\_/,$type))[0]};
1081: }
1082: }
1083: my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/);
1084: my ($hour,$min,$sec,$val)=&preset_defaults($parmname);
1085: unless (defined($winvalue)) { $winvalue=$val; }
1086: my $valout = &valout($value,$type,1);
1087: my $unencmarker = $marker;
1088: foreach my $item (\$type, \$dis, \$winvalue, \$marker, \$return, \$call,
1089: \$hour, \$min, \$sec, \$extra) {
1090: $$item = &HTML::Entities::encode($$item,'"<>&');
1091: $$item =~ s/\'/\\\'/g;
1092: }
1093: return '<table width="100%"><tr valign="top" align="right"><td><a name="'.$unencmarker.'" /></td></tr><tr><td align="center">'.
1094: '<a href="javascript:pjump('."'".$type."','".$dis."','".$winvalue."','"
1095: .$marker."','".$return."','".$call."','".$hour."','".$min."','".$sec."','".$extra."'".');">'.
1096: $valout.'</a></td></tr>'.($recursive?'<tr><td align="center" class="LC_parm_recursive">'.
1097: &mt('recursive').'</td></tr>' : '').'</table>';
1098:
1099: }
1100:
1101: # Javascript for table mode.
1102: sub page_js {
1103:
1104: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1105: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1106:
1107: return(<<ENDJS);
1108: <script type="text/javascript">
1109: // <![CDATA[
1110:
1111: $pjump_def
1112:
1113: function psub() {
1114: var specstring = /^string_!(yesno|any)/i;
1115: if (document.parmform.pres_marker.value!='') {
1116: document.parmform.action+='#'+document.parmform.pres_marker.value;
1117: var typedef=new Array();
1118: typedef=document.parmform.pres_type.value.split('_');
1119: if (document.parmform.pres_type.value!='') {
1120: if ((typedef[0]=='date') ||
1121: (specstring.test(document.parmform.pres_type.value))) {
1122: eval('document.parmform.recent_'+
1123: document.parmform.pres_type.value+
1124: '.value=document.parmform.pres_value.value;');
1125: } else {
1126: eval('document.parmform.recent_'+typedef[0]+
1127: '.value=document.parmform.pres_value.value;');
1128: }
1129: }
1130: document.parmform.submit();
1131: } else {
1132: document.parmform.pres_value.value='';
1133: document.parmform.pres_marker.value='';
1134: }
1135: }
1136:
1137: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
1138: var options = "width=" + w + ",height=" + h + ",";
1139: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
1140: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
1141: var newWin = window.open(url, wdwName, options);
1142: newWin.focus();
1143: }
1144:
1145: // ]]>
1146:
1147: </script>
1148: $selscript
1149: ENDJS
1150:
1151: }
1152:
1153: # Javascript to show or hide the map selection (function showHide_courseContent),
1154: # for table and overview modes.
1155: sub showhide_js {
1156: return <<"COURSECONTENTSCRIPT";
1157:
1158: function showHide_courseContent() {
1159: var parmlevValue=document.getElementById("parmlev").value;
1160: if (parmlevValue == 'general') {
1161: document.getElementById('mapmenu').style.display="none";
1162: } else {
1163: if ((parmlevValue == "full") || (parmlevValue == "map")) {
1164: document.getElementById('mapmenu').style.display ="";
1165: } else {
1166: document.getElementById('mapmenu').style.display="none";
1167: }
1168: }
1169: return;
1170: }
1171:
1172: COURSECONTENTSCRIPT
1173: }
1174:
1175: # Javascript functions showHideLenient and toggleParmTextbox, for overview mode
1176: sub toggleparmtextbox_js {
1177: return <<"ENDSCRIPT";
1178:
1179: if (!document.getElementsByClassName) {
1180: function getElementsByClassName(node, classname) {
1181: var a = [];
1182: var re = new RegExp('(^| )'+classname+'( |$)');
1183: var els = node.getElementsByTagName("*");
1184: for(var i=0,j=els.length; i<j; i++)
1185: if(re.test(els[i].className))a.push(els[i]);
1186: return a;
1187: }
1188: }
1189:
1190: function showHideLenient() {
1191: var lenients;
1192: var setRegExp = /^set_/;
1193: if (document.getElementsByClassName) {
1194: lenients = document.getElementsByClassName('LC_lenient_radio');
1195: } else {
1196: lenients = getElementsByClassName(document.body,'LC_lenient_radio');
1197: }
1198: if (lenients != 'undefined') {
1199: for (var i=0; i<lenients.length; i++) {
1200: if (lenients[i].checked) {
1201: if (lenients[i].value == 'weighted') {
1202: if (setRegExp.test(lenients[i].name)) {
1203: var identifier = lenients[i].name.replace(setRegExp,'');
1204: toggleParmTextbox(document.parmform,identifier);
1205: }
1206: }
1207: }
1208: }
1209: }
1210: return;
1211: }
1212:
1213: function toggleParmTextbox(form,key) {
1214: var divfortext = document.getElementById('LC_parmtext_'+key);
1215: if (divfortext) {
1216: var caller = form.elements['set_'+key];
1217: if (caller.length) {
1218: for (i=0; i<caller.length; i++) {
1219: if (caller[i].checked) {
1220: if (caller[i].value == 'weighted') {
1221: divfortext.style.display = 'inline';
1222: } else {
1223: divfortext.style.display = 'none';
1224: }
1225: }
1226: }
1227: }
1228: }
1229: return;
1230: }
1231:
1232: ENDSCRIPT
1233: }
1234:
1235: # Javascript function validateParms, for overview mode
1236: sub validateparms_js {
1237: return <<'ENDSCRIPT';
1238:
1239: function validateParms() {
1240: var textRegExp = /^settext_/;
1241: var tailLenient = /\.lenient$/;
1242: var patternRelWeight = /^\-?[\d.]+$/;
1243: var patternLenientStd = /^(yes|no|default)$/;
1244: var ipallowRegExp = /^setipallow_/;
1245: var ipdenyRegExp = /^setipdeny_/;
1246: var deeplinkRegExp = /^deeplink_(listing|scope)_/;
1247: var deeplinkUrlsRegExp = /^deeplink_urls_/;
1248: var deeplinkltiRegExp = /^deeplink_lti_/;
1249: var deeplinkkeyRegExp = /^deeplink_key_/;
1250: var patternIP = /[\[\]\*\.a-zA-Z\d\-]+/;
1251: if ((document.parmform.elements.length != 'undefined') && (document.parmform.elements.length) != 'null') {
1252: if (document.parmform.elements.length) {
1253: for (i=0; i<document.parmform.elements.length; i++) {
1254: var name=document.parmform.elements[i].name;
1255: if (textRegExp.test(name)) {
1256: var identifier = name.replace(textRegExp,'');
1257: if (tailLenient.test(identifier)) {
1258: if (document.parmform.elements['set_'+identifier].length) {
1259: for (var j=0; j<document.parmform.elements['set_'+identifier].length; j++) {
1260: if (document.parmform.elements['set_'+identifier][j].checked) {
1261: if (!(patternLenientStd.test(document.parmform.elements['set_'+identifier][j].value))) {
1262: var relweight = document.parmform.elements[i].value;
1263: relweight = relweight.replace(/^\s+|\s+$/g,'');
1264: if (!patternRelWeight.test(relweight)) {
1265: relweight = '0.0';
1266: }
1267: if (document.parmform.elements['set_'+identifier][j].value == 'weighted') {
1268: document.parmform.elements['set_'+identifier][j].value = relweight;
1269: } else {
1270: document.parmform.elements['set_'+identifier][j].value += ','+relweight;
1271: }
1272: }
1273: break;
1274: }
1275: }
1276: }
1277: }
1278: } else if (ipallowRegExp.test(name)) {
1279: var identifier = name.replace(ipallowRegExp,'');
1280: var possallow = document.parmform.elements[i].value;
1281: possallow = possallow.replace(/^\s+|\s+$/g,'');
1282: if (patternIP.test(possallow)) {
1283: if (document.parmform.elements['set_'+identifier].value) {
1284: possallow = ','+possallow;
1285: }
1286: document.parmform.elements['set_'+identifier].value += possallow;
1287: }
1288: } else if (ipdenyRegExp.test(name)) {
1289: var identifier = name.replace(ipdenyRegExp,'');
1290: var possdeny = document.parmform.elements[i].value;
1291: possdeny = possdeny.replace(/^\s+|\s+$/g,'');
1292: if (patternIP.test(possdeny)) {
1293: possdeny = '!'+possdeny;
1294: if (document.parmform.elements['set_'+identifier].value) {
1295: possdeny = ','+possdeny;
1296: }
1297: document.parmform.elements['set_'+identifier].value += possdeny;
1298: }
1299: } else if (deeplinkRegExp.test(name)) {
1300: var identifier = name.replace(deeplinkRegExp,'');
1301: var possdeeplink = document.parmform.elements[i].value;
1302: possdeeplink = possdeeplink.replace(/^\s+|\s+$/g,'');
1303: if (document.parmform.elements['set_'+identifier].value) {
1304: possdeeplink = ','+possdeeplink;
1305: }
1306: document.parmform.elements['set_'+identifier].value += possdeeplink;
1307: } else if (deeplinkUrlsRegExp.test(name)) {
1308: if (document.parmform.elements[i].checked) {
1309: var identifier = name.replace(deeplinkUrlsRegExp,'');
1310: var posslinkurl = document.parmform.elements[i].value;
1311: posslinkurl = posslinkurl.replace(/^\s+|\s+$/g,'');
1312: if (document.parmform.elements['set_'+identifier].value) {
1313: posslinkurl = ','+posslinkurl;
1314: }
1315: document.parmform.elements['set_'+identifier].value += posslinkurl;
1316: }
1317: } else if (deeplinkltiRegExp.test(name)) {
1318: var identifier = name.replace(deeplinkltiRegExp,'');
1319: var posslti = document.parmform.elements[i].value;
1320: posslti = posslti.replace(/\D+/g,'');
1321: if (document.parmform.elements['set_'+identifier].value) {
1322: posslti = ':'+posslti;
1323: }
1324: document.parmform.elements['set_'+identifier].value += posslti;
1325: } else if (deeplinkkeyRegExp.test(name)) {
1326: var identifier = name.replace(deeplinkkeyRegExp,'');
1327: var posskey = document.parmform.elements[i].value;
1328: posskey = posskey.replace(/\W+/g,'');
1329: if (document.parmform.elements['set_'+identifier].value) {
1330: posslti = ':'+posskey;
1331: }
1332: document.parmform.elements['set_'+identifier].value += posskey;
1333: }
1334: }
1335: }
1336: }
1337: return true;
1338: }
1339:
1340: ENDSCRIPT
1341: }
1342:
1343: # Javascript initialization, for overview mode
1344: sub ipacc_boxes_js {
1345: my $remove = &mt('Remove');
1346: return <<"END";
1347: \$(document).ready(function() {
1348: var wrapper = \$(".LC_string_ipacc_wrap");
1349: var add_button = \$(".LC_add_ipacc_button");
1350: var ipaccRegExp = /^LC_string_ipacc_/;
1351:
1352: \$(add_button).click(function(e){
1353: e.preventDefault();
1354: var identifier = \$(this).closest("div").attr("id");
1355: identifier = identifier.replace(ipaccRegExp,'');
1356: \$(this).closest('div').find('.LC_string_ipacc_inner').append('<div><input type="text" name="setip'+identifier+'" /><a href="#" class="LC_remove_ipacc">$remove</a></div>');
1357: });
1358:
1359: \$(wrapper).delegate(".LC_remove_ipacc","click", function(e){
1360: e.preventDefault(); \$(this).closest("div").remove();
1361: })
1362: });
1363:
1364:
1365: END
1366: }
1367:
1368: # Javascript function toggleSecret, for overview mode.
1369: sub done_proctor_js {
1370: return <<"END";
1371: function toggleSecret(form,radio,key) {
1372: var radios = form[radio+key];
1373: if (radios.length) {
1374: for (var i=0; i<radios.length; i++) {
1375: if (radios[i].checked) {
1376: if (radios[i].value == '_done_proctor') {
1377: if (document.getElementById('done_'+key+'_proctorkey')) {
1378: document.getElementById('done_'+key+'_proctorkey').type='text';
1379: }
1380: } else {
1381: if (document.getElementById('done_'+key+'_proctorkey')) {
1382: document.getElementById('done_'+key+'_proctorkey').type='hidden';
1383: document.getElementById('done_'+key+'_proctorkey').value='';
1384: }
1385: }
1386: }
1387: }
1388: }
1389: }
1390: END
1391:
1392: }
1393:
1394: # Javascript function toggle
1395: sub deeplink_js {
1396: return <<"END";
1397: function toggleDeepLink(form,item,key) {
1398: var radios = form['deeplink_'+item+'_'+key];
1399: if (radios.length) {
1400: var keybox;
1401: if (document.getElementById('deeplink_key_'+item+'_'+key)) {
1402: keybox = document.getElementById('deeplink_key_'+item+'_'+key);
1403: }
1404: var ltidiv;
1405: if (document.getElementById('deeplinkdiv_lti_'+item+'_'+key)) {
1406: ltidiv = document.getElementById('deeplinkdiv_lti_'+item+'_'+key);
1407: }
1408: for (var i=0; i<radios.length; i++) {
1409: if (radios[i].checked) {
1410: if (radios[i].value == 'lti') {
1411: ltidiv.style.display = 'inline-block';
1412: keybox.type = 'hidden';
1413: keybox.value = '';
1414: } else {
1415: if (ltidiv != '') {
1416: ltidiv.style.display = 'none';
1417: form['deeplink_lti_'+key].selectedIndex = 0;
1418: }
1419: if (radios[i].value == 'key') {
1420: keybox.type = 'text';
1421: } else {
1422: keybox.type = 'hidden';
1423: }
1424: }
1425: }
1426: }
1427: }
1428: }
1429: END
1430:
1431: }
1432:
1433: # Prints HTML page start for table mode.
1434: # @param {Apache2::RequestRec} $r - the Apache request
1435: # @param {string} $psymb - resource symb
1436: # @param {string} $crstype - course type (Community / Course / Placement Test)
1437: sub startpage {
1438: my ($r,$psymb,$crstype) = @_;
1439:
1440: my %loaditems = (
1441: 'onload' => "group_or_section('cgroup')",
1442: );
1443: if (!$psymb) {
1444: $loaditems{'onload'} = "showHide_courseContent(); group_or_section('cgroup'); resize_scrollbox('mapmenuscroll','1','1');";
1445: }
1446:
1447: if ((($env{'form.command'} eq 'set') && ($env{'form.url'}) &&
1448: (!$env{'form.dis'})) || ($env{'form.symb'})) {
1449: &Apache::lonhtmlcommon::add_breadcrumb({help=>'Problem_Parameters',
1450: text=>"Problem Parameters"});
1451: } else {
1452: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
1453: text=>"Table Mode",
1454: help => 'Course_Setting_Parameters'});
1455: }
1456: my $js = &page_js().'
1457: <script type="text/javascript">
1458: // <![CDATA[
1459: '.
1460: &Apache::lonhtmlcommon::resize_scrollbox_js('params').'
1461: // ]]>
1462: </script>
1463: ';
1464: my $start_page =
1465: &Apache::loncommon::start_page('Set/Modify Course Parameters',$js,
1466: {'add_entries' => \%loaditems,});
1467: my $breadcrumbs =
1468: &Apache::lonhtmlcommon::breadcrumbs('Table Mode Parameter Setting','Table_Mode');
1469: my $escfilter=&Apache::lonhtmlcommon::entity_encode($env{'form.filter'});
1470: my $escpart=&Apache::lonhtmlcommon::entity_encode($env{'form.part'});
1471: $r->print($start_page.$breadcrumbs);
1472: &startSettingsScreen($r,'parmset',$crstype);
1473: $r->print(<<ENDHEAD);
1474: <form method="post" action="/adm/parmset?action=settable" name="parmform">
1475: <input type="hidden" value="" name="pres_value" />
1476: <input type="hidden" value="" name="pres_type" />
1477: <input type="hidden" value="" name="pres_marker" />
1478: <input type="hidden" value="1" name="prevvisit" />
1479: <input type="hidden" value="$escfilter" name="filter" />
1480: <input type="hidden" value="$escpart" name="part" />
1481: ENDHEAD
1482: }
1483:
1484:
1485: # Prints a row for table mode (except for the tr start).
1486: # Every time a hash reference is passed, a single entry is used, so print_row
1487: # could just use these values, but why make it simple when it can be complicated ?
1488: #
1489: # @param {Apache2::RequestRec} $r - the Apache request
1490: # @param {string} $which - parameter key ('parameter_'.part.'_'.name)
1491: # @param {hash reference} $part - parameter key -> parameter part (can be problem part.'_'.response id for response parameters)
1492: # @param {hash reference} $name - parameter key -> parameter name
1493: # @param {hash reference} $symbp - map pc or resource/map id -> map src.'___(all)' or resource symb
1494: # @param {string} $rid - resource id
1495: # @param {hash reference} $default - parameter key -> resource parameter default value
1496: # @param {hash reference} $defaulttype - parameter key -> resource parameter default type
1497: # @param {hash reference} $display - parameter key -> full title for the parameter
1498: # @param {string} $defbgone - user level and other levels background color
1499: # @param {string} $defbgtwo - section level background color, also used for part number
1500: # @param {string} $defbgthree - group level background color
1501: # @param {string} $parmlev - parameter level (Resource:'full', Map:'map', Course:'general')
1502: # @param {string} $uname - user name
1503: # @param {string} $udom - user domain
1504: # @param {string} $csec - section name
1505: # @param {string} $cgroup - group name
1506: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
1507: # @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
1508: # @param {boolean} $readonly - true if no editing allowed.
1509: # @param {array reference} - $recurseup - list of maps containing current one, ending at top-level.
1510: # @param {hash reference} - $maptitles - - hash map id or src -> map title
1511: # @param {hash reference} - $allmaps_inverted - hash map src -> map pc
1512: # @param {scalar reference} - $reclinks - number of "parameter in effect" cells with link to map where recursive param was set
1513: sub print_row {
1514: my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone,
1515: $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups,$noeditgrp,
1516: $readonly,$recurseup,$maptitles,$allmaps_inverted,$reclinks)=@_;
1517: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1518: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1519: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
1520: my $numlinks = 0;
1521:
1522: # get the values for the parameter in cascading order
1523: # empty levels will remain empty
1524: my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which},
1525: $rid,$$default{$which},$uname,$udom,$csec,$cgroup,$courseopt);
1526: # get the type for the parameters
1527: # problem: these may not be set for all levels
1528: my ($typeresult,@typeoutpar)=&parmval($$part{$which}.'.'.
1529: $$name{$which}.'.type',$rid,
1530: $$defaulttype{$which},$uname,$udom,$csec,$cgroup,$courseopt);
1531: # cascade down manually
1532: my $cascadetype=$$defaulttype{$which};
1533: for (my $i=18;$i>0;$i--) {
1534: if ($typeoutpar[$i]) {
1535: $cascadetype=$typeoutpar[$i];
1536: } else {
1537: $typeoutpar[$i]=$cascadetype;
1538: }
1539: }
1540: my $parm=$$display{$which};
1541:
1542: if ($parmlev eq 'full') {
1543: $r->print('<td style="background-color:'.$defbgtwo.';" align="center">'
1544: .($$part{$which} eq '0'?'0 ('.&mt('default').')':$$part{$which}).'</td>');
1545: } else {
1546: $parm=~s|\[.*\]\s||g;
1547: }
1548: my $automatic=&rulescache(($which=~/\_([^\_]+)$/)[0].'_triggers');
1549: if ($automatic) {
1550: $parm.='<span class="LC_warning"><br />'.&mt('Automatically sets').' '.join(', ',split(/\:/,$automatic)).'</span>';
1551: }
1552: $r->print('<td>'.$parm.'</td>');
1553:
1554: my $thismarker=$which;
1555: $thismarker=~s/^parameter\_//;
1556: my $mprefix=$rid.'&'.$thismarker.'&';
1557: my ($parmname)=($thismarker=~/\_([^\_]+)$/);
1558: my ($othergrp,$grp_parm,$controlgrp,$effective_parm,$effparm_rec,$effparm_level,
1559: $eff_groupparm,$recurse_check,$recursinfo,$extra);
1560: if ((ref($recurseup) eq 'ARRAY') && (@{$recurseup} > 0)) {
1561: if ($result eq '') {
1562: $recurse_check = 1;
1563: } elsif (($uname ne '') && ($result > 3)) {
1564: $recurse_check = 1;
1565: } elsif (($cgroup ne '') && ($result > 7)) {
1566: $recurse_check = 1;
1567: } elsif (($csec ne '') && ($result > 11)) {
1568: $recurse_check = 1;
1569: } elsif ($result > 17) {
1570: $recurse_check = 1;
1571: }
1572: if ($recurse_check) {
1573: my $what = $$part{$which}.'.'.$$name{$which};
1574: my $prefix;
1575: if (($uname ne '') && ($udom ne '')) {
1576: my $useropt = &Apache::lonnet::get_userresdata($uname,$udom);
1577: $prefix = $env{'request.course.id'};
1578: $recursinfo = &get_recursive($recurseup,$useropt,$what,$prefix);
1579: if (ref($recursinfo) eq 'ARRAY') {
1580: $effparm_rec = 1;
1581: $effparm_level = &mt('user: [_1]',$uname);
1582: }
1583: }
1584: if (($cgroup ne '') && (!$effparm_rec)) {
1585: $prefix = $env{'request.course.id'}.'.['.$cgroup.']';
1586: $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
1587: if (ref($recursinfo) eq 'ARRAY') {
1588: $effparm_rec = 1;
1589: $effparm_level = &mt('group: [_1]',$cgroup);
1590: }
1591: }
1592: if (($csec ne '') && (!$effparm_rec)) {
1593: $prefix = $env{'request.course.id'}.'.['.$csec.']';
1594: $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
1595: if (ref($recursinfo) eq 'ARRAY') {
1596: $effparm_rec = 1;
1597: $effparm_level = &mt('section: [_1]',$csec);
1598: }
1599: }
1600: if (!$effparm_rec) {
1601: $prefix = $env{'request.course.id'};
1602: $recursinfo = &get_recursive($recurseup,$courseopt,$what,$prefix);
1603: if (ref($recursinfo) eq 'ARRAY') {
1604: $effparm_rec = 1;
1605: }
1606: }
1607: }
1608: }
1609: if ((!$effparm_rec) && ($result == 17 || $result == 11 || $result == 7 || $result == 3)) {
1610: $effparm_rec = 1;
1611: }
1612: if ((!$effparm_rec) &&
1613: (($$name{$which} eq 'encrypturl') || ($$name{$which} eq 'hiddenresource')) &&
1614: ($result == 16 || $result == 10 || $result == 6 || $result == 2)) {
1615: $effparm_rec = 1;
1616: }
1617: if ($parmname eq 'deeplink') {
1618: my %posslti;
1619: my %lti =
1620: &Apache::lonnet::get_domain_lti($env{'course.'.$env{'request.course.id'}.'.domain'},
1621: 'provider');
1622: foreach my $item (keys(%lti)) {
1623: if (ref($lti{$item}) eq 'HASH') {
1624: unless ($lti{$item}{'requser'}) {
1625: $posslti{$item} = $lti{$item}{'consumer'};
1626: }
1627: }
1628: }
1629: if (keys(%posslti)) {
1630: $extra = 'lti_';
1631: foreach my $lti (sort { $a <=> $b } keys(%posslti)) {
1632: $extra .= $lti.':'.&js_escape($posslti{$lti}).',';
1633: }
1634: $extra =~ s/,$//;
1635: }
1636: }
1637: if ($parmlev eq 'general') {
1638: if ($uname) {
1639: &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1640: } elsif ($cgroup) {
1641: &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,'',$extra);
1642: } elsif ($csec) {
1643: &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1644: } else {
1645: &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1646: }
1647: } elsif ($parmlev eq 'map') {
1648: if ($uname) {
1649: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
1650: } elsif ($cgroup) {
1651: &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra);
1652: } elsif ($csec) {
1653: &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
1654: } else {
1655: &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
1656: }
1657: } else {
1658: if ($uname) {
1659: if (@{$usersgroups} > 1) {
1660: (my $coursereply,$othergrp,$grp_parm,$controlgrp,my $grp_is_rec) =
1661: &check_other_groups($$part{$which}.'.'.$$name{$which},
1662: $rid,$cgroup,$defbgone,$usersgroups,$result,$courseopt);
1663: if (($coursereply) && ($result > 4)) {
1664: if (defined($controlgrp)) {
1665: if ($cgroup ne $controlgrp) {
1666: $eff_groupparm = $grp_parm;
1667: undef($result);
1668: undef($effparm_rec);
1669: if ($grp_is_rec) {
1670: $effparm_rec = 1;
1671: }
1672: }
1673: }
1674: }
1675: }
1676: }
1677:
1678: &print_td($r,18,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1679: &print_td($r,16,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
1680: &print_td($r,15,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1681: &print_td($r,14,'#FFDDDD',$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1682: &print_td($r,13,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1683:
1684: if ($csec) {
1685: &print_td($r,12,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1686: &print_td($r,10,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
1687: &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1688: }
1689:
1690: if ($cgroup) {
1691: &print_td($r,8,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,'',$extra);
1692: &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp,$readonly,1,$extra);
1693: &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp.$readonly,'',$extra);
1694: }
1695:
1696: if ($uname) {
1697: if ($othergrp) {
1698: $r->print($othergrp);
1699: }
1700: &print_td($r,4,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1701: &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,1,$extra);
1702: &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,'',$readonly,'',$extra);
1703: }
1704: } # end of $parmlev if/else
1705: if (ref($recursinfo) eq 'ARRAY') {
1706: my $rectitle = &mt('recursive');
1707: if ((ref($maptitles) eq 'HASH') && (exists($maptitles->{$recursinfo->[2]}))) {
1708: if ((ref($allmaps_inverted) eq 'HASH') && (exists($allmaps_inverted->{$recursinfo->[2]}))) {
1709: $rectitle = &mt('set in: [_1]','"'.
1710: '<a href="javascript:pjumprec('."'".$allmaps_inverted->{$recursinfo->[2]}."',".
1711: "'$parmname','$$part{$which}'".');">'.
1712: $maptitles->{$recursinfo->[2]}.'</a>"');
1713:
1714: $numlinks ++;
1715: }
1716: }
1717: my ($parmname)=($thismarker=~/\_([^\_]+)$/);
1718: $effective_parm = &valout($recursinfo->[0],$recursinfo->[1]);
1719: $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
1720: '<br /><span class="LC_parm_recursive">'.$rectitle.' '.
1721: $effparm_level.'</span></td>');
1722: } else {
1723: if ($result) {
1724: $effective_parm = &valout($outpar[$result],$typeoutpar[$result]);
1725: }
1726: if ($eff_groupparm) {
1727: $effective_parm = $eff_groupparm;
1728: }
1729: $r->print('<td style="background-color:#CCCCFF;" align="center">'.$effective_parm.
1730: ($effparm_rec?'<br /><span class="LC_parm_recursive">'.&mt('recursive').
1731: '</span>':'').'</td>');
1732: }
1733: if ($parmlev eq 'full') {
1734: my $sessionval=&Apache::lonnet::EXT('resource.'.$$part{$which}.
1735: '.'.$$name{$which},$$symbp{$rid});
1736: my $sessionvaltype=$typeoutpar[$result];
1737: if (!defined($sessionvaltype)) {
1738: $sessionvaltype=$$defaulttype{$which};
1739: }
1740: $r->print('<td style="background-color:#999999;" align="center"><font color="#FFFFFF">'.
1741: &valout($sessionval,$sessionvaltype).' '.
1742: '</font></td>');
1743: }
1744: $r->print('</tr>');
1745: $r->print("\n");
1746: if (($numlinks) && (ref($reclinks))) {
1747: $$reclinks = $numlinks;
1748: }
1749: }
1750:
1751: # Prints a cell for table mode.
1752: #
1753: # FIXME: some of these parameter names are uninspired ($which and $value)
1754: # Also, it would make more sense to pass the display for this cell rather
1755: # than the full display hash and the key to use.
1756: #
1757: # @param {Apache2::RequestRec} $r - the Apache request
1758: # @param {integer} $which - level
1759: # @param {string} $defbg - cell background color
1760: # @param {integer} $result - the most specific level that is defined for that parameter
1761: # @param {array reference} $outpar - array level -> parameter value (when defined)
1762: # @param {string} $mprefix - resource id.'&'.part.'_'.parameter name.'&'
1763: # @param {string} $value - parameter key ('parameter_'.part.'_'.name)
1764: # @param {array reference} $typeoutpar - array level -> parameter type (when defined)
1765: # @param {hash reference} $display - parameter key -> full title for the parameter
1766: # @param {boolean} $noeditgrp - true if no edit is allowed for group level parameters
1767: # @param {boolean} $readonly -true if editing not allowed.
1768: # @param {boolean} $ismaplevel - true if level is for a map.
1769: # @param {strring} $extra - extra informatio to pass to plink.
1770: sub print_td {
1771: my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display,
1772: $noeditgrp,$readonly,$ismaplevel,$extra)=@_;
1773: my ($ineffect,$recursive,$currval,$currtype,$currlevel);
1774: $ineffect = 0;
1775: $currval = $$outpar[$which];
1776: $currtype = $$typeoutpar[$which];
1777: $currlevel = $which;
1778: if (($result) && ($result == $which)) {
1779: $ineffect = 1;
1780: }
1781: if ($ismaplevel) {
1782: if ($mprefix =~ /(hiddenresource|encrypturl)\&/) {
1783: if (($result) && ($result == $which)) {
1784: $recursive = 1;
1785: }
1786: } elsif ($$outpar[$which+1] ne '') {
1787: $recursive = 1;
1788: $currlevel = $which+1;
1789: $currval = $$outpar[$currlevel];
1790: $currtype = $$typeoutpar[$currlevel];
1791: if (($result) && ($result == $currlevel)) {
1792: $ineffect = 1;
1793: }
1794: }
1795: }
1796: $r->print('<td style="background-color:'.($ineffect?'#AAFFAA':$defbg).
1797: ';" align="center">');
1798: my $nolink = 0;
1799: if ($readonly) {
1800: $nolink = 1;
1801: } else {
1802: if ($which == 14 || $which == 15 || $mprefix =~ /mapalias\&$/) {
1803: $nolink = 1;
1804: } elsif (($env{'request.course.sec'} ne '') && ($which > 12)) {
1805: $nolink = 1;
1806: } elsif ($which == 5 || $which == 6 || $which == 7 || $which == 8) {
1807: if ($noeditgrp) {
1808: $nolink = 1;
1809: }
1810: } elsif ($mprefix =~ /availablestudent\&$/) {
1811: if ($which > 4) {
1812: $nolink = 1;
1813: }
1814: } elsif ($mprefix =~ /examcode\&$/) {
1815: unless ($which == 2) {
1816: $nolink = 1;
1817: }
1818: }
1819: }
1820: if ($nolink) {
1821: my ($parmname)=((split(/\&/,$mprefix))[1]=~/\_([^\_]+)$/);
1822: $r->print(&valout($currval,$currtype));
1823: } else {
1824: $r->print(&plink($currtype,
1825: $$display{$value},$currval,
1826: $mprefix.$currlevel,'parmform.pres','psub',$recursive,
1827: $extra));
1828: }
1829: $r->print('</td>'."\n");
1830: }
1831:
1832: # Returns HTML and other info for the cell added when a user is selected
1833: # and that user is in several groups. This is the cell with the title "Control by other group".
1834: #
1835: # @param {string} $what - parameter part.'.'.parameter name
1836: # @param {string} $rid - resource id
1837: # @param {string} $cgroup - group name
1838: # @param {string} $defbg - cell background color
1839: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
1840: # @param {integer} $result - level
1841: # @param {hash reference} $courseopt - course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db)
1842: # @returns {Array} - array (parameter value for the other group, HTML for the cell, HTML with the value, name of the other group, true if recursive)
1843: sub check_other_groups {
1844: my ($what,$rid,$cgroup,$defbg,$usersgroups,$result,$courseopt) = @_;
1845: my $courseid = $env{'request.course.id'};
1846: my $output;
1847: my $symb = &symbcache($rid);
1848: my $symbparm=$symb.'.'.$what;
1849: my $map=(&Apache::lonnet::decode_symb($symb))[0];
1850: my $recurseparm=$map.'___(rec).'.$what;
1851: my $mapparm=$map.'___(all).'.$what;
1852: my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype) =
1853: &parm_control_group($courseid,$usersgroups,$symbparm,$mapparm,
1854: $recurseparm,$what,$courseopt);
1855: my $bgcolor = $defbg;
1856: my ($grp_parm,$grp_is_rec);
1857: if (($coursereply) && ($cgroup ne $resultgroup)) {
1858: my ($parmname) = ($what =~ /\.([^.]+)$/);
1859: if ($result > 3) {
1860: $bgcolor = '#AAFFAA';
1861: }
1862: $grp_parm = &valout($coursereply,$resulttype);
1863: $output = '<td style="background-color:'.$bgcolor.';" align="center">';
1864: if ($resultgroup && $resultlevel) {
1865: if ($resultlevel eq 'recursive') {
1866: $resultlevel = 'map/folder';
1867: $grp_is_rec = 1;
1868: }
1869: $output .= '<small><b>'.$resultgroup.'</b> ('.$resultlevel.'): </small>'.$grp_parm.
1870: ($grp_is_rec?'<span class="LC_parm_recursive">'.&mt('recursive').'</span>':'');
1871:
1872: } else {
1873: $output .= ' ';
1874: }
1875: $output .= '</td>';
1876: } else {
1877: $output .= '<td style="background-color:'.$bgcolor.';"> </td>';
1878: }
1879: return ($coursereply,$output,$grp_parm,$resultgroup,$grp_is_rec);
1880: }
1881:
1882: # Looks for a group with a defined parameter for given user and parameter.
1883: # Used by check_other_groups.
1884: #
1885: # @param {string} $courseid - the course id
1886: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
1887: # @param {string} $symbparm - end of the course parameter hash key for the group resource level
1888: # @param {string} $mapparm - end of the course parameter hash key for the group map/folder level
1889: # @param {string} $recurseparm - end of the course parameter hash key for the group recursive level
1890: # @param {string} $what - parameter part.'.'.parameter name
1891: # @param {hash reference} $courseopt - course parameters hash
1892: # @returns {Array} - (parameter value for the group, course parameter hash key for the parameter, name of the group, level name, parameter type)
1893: sub parm_control_group {
1894: my ($courseid,$usersgroups,$symbparm,$mapparm,$recurseparm,$what,$courseopt) = @_;
1895: my ($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
1896: my $grpfound = 0;
1897: my @levels = ($symbparm,$mapparm,$recurseparm,$what);
1898: my @levelnames = ('resource','map/folder','recursive','general');
1899: foreach my $group (@{$usersgroups}) {
1900: if ($grpfound) { last; }
1901: for (my $i=0; $i<@levels; $i++) {
1902: my $item = $courseid.'.['.$group.'].'.$levels[$i];
1903: if (defined($$courseopt{$item})) {
1904: $coursereply = $$courseopt{$item};
1905: $resultitem = $item;
1906: $resultgroup = $group;
1907: $resultlevel = $levelnames[$i];
1908: $resulttype = $$courseopt{$item.'.type'};
1909: $grpfound = 1;
1910: last;
1911: }
1912: }
1913: }
1914: return($coursereply,$resultitem,$resultgroup,$resultlevel,$resulttype);
1915: }
1916:
1917:
1918:
1919: # Extracts lots of information about all of the the course's resources into a variety of hashes, using lonnavmaps and lonnet::metadata.
1920: # All the parameters are references and are filled by the sub.
1921: #
1922: # @param {array reference} $ids - resource and map ids
1923: # @param {hash reference} $typep - hash resource/map id -> resource type (file extension)
1924: # @param {hash reference} $keyp - hash resource/map id -> comma-separated list of parameter keys from lonnet::metadata
1925: # @param {hash reference} $allparms - hash parameter name -> parameter title
1926: # @param {hash reference} $allparts - hash parameter part -> part title (a parameter part can be problem part.'_'.response id for response parameters)
1927: # @param {hash reference} $allmaps - hash map pc -> map src
1928: # @param {hash reference} $mapp - hash map pc or resource/map id -> enclosing map src
1929: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' for a map or resource symb for a resource
1930: # @param {hash reference} $maptitles - hash map pc or src -> map title (this should really be two separate hashes)
1931: # @param {hash reference} $uris - hash resource/map id -> resource src
1932: # @param {hash reference} $keyorder - hash parameter key -> appearance rank for this parameter when looking through every resource and every parameter, starting at 100 (integer)
1933: # @param {hash reference} $defkeytype - hash parameter name -> parameter type
1934: sub extractResourceInformation {
1935: my $ids = shift;
1936: my $typep = shift;
1937: my $keyp = shift;
1938: my $allparms = shift;
1939: my $allparts = shift;
1940: my $allmaps = shift;
1941: my $mapp = shift;
1942: my $symbp = shift;
1943: my $maptitles=shift;
1944: my $uris=shift;
1945: my $keyorder=shift;
1946: my $defkeytype=shift;
1947:
1948: my $keyordercnt=100;
1949:
1950: my $navmap = Apache::lonnavmaps::navmap->new();
1951: my @allres=$navmap->retrieveResources(undef,undef,1,undef,1);
1952: foreach my $resource (@allres) {
1953: my $id=$resource->id();
1954: my ($mapid,$resid)=split(/\./,$id);
1955: if ($mapid eq '0') { next; }
1956: $$ids[$#$ids+1]=$id;
1957: my $srcf=$resource->src();
1958: $srcf=~/\.(\w+)$/;
1959: $$typep{$id}=$1;
1960: my $toolsymb;
1961: if ($srcf =~ /ext\.tool$/) {
1962: $toolsymb = $resource->symb();
1963: }
1964: $$keyp{$id}='';
1965: $$uris{$id}=$srcf;
1966:
1967: foreach my $key (split(/\,/,&Apache::lonnet::metadata($srcf,'allpossiblekeys',$toolsymb))) {
1968: next if ($key!~/^parameter_/);
1969:
1970: # Hidden parameters
1971: next if (&Apache::lonnet::metadata($srcf,$key.'.hidden',$toolsymb) eq 'parm');
1972: #
1973: # allparms is a hash of parameter names
1974: #
1975: my $name=&Apache::lonnet::metadata($srcf,$key.'.name',$toolsymb);
1976: if (!exists($$allparms{$name}) || $$allparms{$name} =~ m/^\s*$/ ) {
1977: my ($display,$parmdis);
1978: $display = &standard_parameter_names($name);
1979: if ($display eq '') {
1980: $display= &Apache::lonnet::metadata($srcf,$key.'.display',$toolsymb);
1981: $parmdis = $display;
1982: $parmdis =~ s/\s*\[Part.*$//g;
1983: } else {
1984: $parmdis = &mt($display);
1985: }
1986: $$allparms{$name}=$parmdis;
1987: if (ref($defkeytype)) {
1988: $$defkeytype{$name}=
1989: &Apache::lonnet::metadata($srcf,$key.'.type',$toolsymb);
1990: }
1991: }
1992:
1993: #
1994: # allparts is a hash of all parts
1995: #
1996: my $part= &Apache::lonnet::metadata($srcf,$key.'.part',$toolsymb);
1997: $$allparts{$part} = &mt('Part: [_1]',$part);
1998: #
1999: # Remember all keys going with this resource
2000: #
2001: if ($$keyp{$id}) {
2002: $$keyp{$id}.=','.$key;
2003: } else {
2004: $$keyp{$id}=$key;
2005: }
2006: #
2007: # Put in order
2008: #
2009: unless ($$keyorder{$key}) {
2010: $$keyorder{$key}=$keyordercnt;
2011: $keyordercnt++;
2012: }
2013: }
2014:
2015:
2016: if (!exists($$mapp{$mapid})) {
2017: $$mapp{$id}=
2018: &Apache::lonnet::declutter($resource->enclosing_map_src());
2019: $$mapp{$mapid}=$$mapp{$id};
2020: $$allmaps{$mapid}=$$mapp{$id};
2021: if ($mapid eq '1') {
2022: $$maptitles{$mapid}=&mt('Main Content');
2023: } else {
2024: $$maptitles{$mapid}=&Apache::lonnet::gettitle($$mapp{$id});
2025: }
2026: $$maptitles{$$mapp{$id}}=$$maptitles{$mapid};
2027: $$symbp{$mapid}=$$mapp{$id}.'___(all)'; # Added in rev. 1.57, but seems not to be used.
2028: # Lines 1038 and 1114 which use $symbp{$mapid}
2029: # are commented out in rev. 1.57
2030: } else {
2031: $$mapp{$id} = $$mapp{$mapid};
2032: }
2033: $$symbp{$id}=&Apache::lonnet::encode_symb($$mapp{$id},$resid,$srcf);
2034: }
2035: }
2036:
2037: sub get_recursive {
2038: my ($recurseup,$resdata,$what,$prefix) = @_;
2039: if ((ref($resdata) eq 'HASH') && (ref($recurseup) eq 'ARRAY')) {
2040: foreach my $item (@{$recurseup}) {
2041: my $norecursechk=$prefix.'.'.$item.'___(all).'.$what;
2042: if (defined($resdata->{$norecursechk})) {
2043: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
2044: my $type = $resdata->{$norecursechk.'.type'};
2045: return [$resdata->{$norecursechk},$type,$item];
2046: } else {
2047: last;
2048: }
2049: }
2050: my $recursechk=$prefix.'.'.$item.'___(rec).'.$what;
2051: if (defined($resdata->{$recursechk})) {
2052: my $type = $resdata->{$recursechk.'.type'};
2053: return [$resdata->{$recursechk},$type,$item];
2054: }
2055: }
2056: }
2057: return;
2058: }
2059:
2060:
2061: # Tells if a parameter type is a date.
2062: #
2063: # @param {string} type - parameter type
2064: # @returns{boolean} - true if it is a date
2065: sub isdateparm {
2066: my $type=shift;
2067: return (($type=~/^date/) && (!($type eq 'date_interval')));
2068: }
2069:
2070: # Determine if parameter type is specialized string type (i.e.,
2071: # not just string or string_yesno.
2072:
2073: sub is_specialstring {
2074: my $type=shift;
2075: return (($type=~/^string_/) && (($type ne 'string_yesno')));
2076: }
2077:
2078: # Prints the HTML and Javascript to select parameters, with various shortcuts.
2079: #
2080: # @param {Apache2::RequestRec} $r - the Apache request
2081: sub parmmenu {
2082: my ($r)=@_;
2083: $r->print(<<ENDSCRIPT);
2084: <script type="text/javascript">
2085: // <![CDATA[
2086: function checkall(value, checkName) {
2087:
2088: var li = "_li";
2089: var displayOverview = "";
2090:
2091: if (value == false) {
2092: displayOverview = "none"
2093: }
2094:
2095: for (i=0; i<document.forms.parmform.elements.length; i++) {
2096: ele = document.forms.parmform.elements[i];
2097: if (ele.name == checkName) {
2098: document.forms.parmform.elements[i].checked=value;
2099: }
2100: }
2101: }
2102:
2103: function checkthis(thisvalue, checkName) {
2104: for (i=0; i<document.forms.parmform.elements.length; i++) {
2105: ele = document.forms.parmform.elements[i];
2106: if (ele.name == checkName) {
2107: if (ele.value == thisvalue) {
2108: document.forms.parmform.elements[i].checked=true;
2109: }
2110: }
2111: }
2112: }
2113:
2114: function checkdates() {
2115: checkthis('duedate','pscat');
2116: checkthis('opendate','pscat');
2117: checkthis('answerdate','pscat');
2118: }
2119:
2120: function checkdisset() {
2121: checkthis('discussend','pscat');
2122: checkthis('discusshide','pscat');
2123: checkthis('discussvote','pscat');
2124: }
2125:
2126: function checkcontdates() {
2127: checkthis('contentopen','pscat');
2128: checkthis('contentclose','pscat');
2129: }
2130:
2131: function checkvisi() {
2132: checkthis('hiddenresource','pscat');
2133: checkthis('encrypturl','pscat');
2134: checkthis('problemstatus','pscat');
2135: checkthis('contentopen','pscat');
2136: checkthis('opendate','pscat');
2137: }
2138:
2139: function checkparts() {
2140: checkthis('hiddenparts','pscat');
2141: checkthis('display','pscat');
2142: checkthis('ordered','pscat');
2143: }
2144:
2145: function checkstandard() {
2146: checkall(false,'pscat');
2147: checkdates();
2148: checkthis('weight','pscat');
2149: checkthis('maxtries','pscat');
2150: checkthis('type','pscat');
2151: checkthis('problemstatus','pscat');
2152: }
2153:
2154: // ]]>
2155: </script>
2156: ENDSCRIPT
2157:
2158: $r->print('<hr />');
2159: &shortCuts($r);
2160: $r->print('<hr />');
2161: }
2162:
2163: # Returns parameter categories.
2164: #
2165: # @returns {hash} - category name -> title in English
2166: sub categories {
2167: return ('time_settings' => 'Time Settings',
2168: 'grading' => 'Grading',
2169: 'tries' => 'Tries',
2170: 'problem_appearance' => 'Problem Appearance',
2171: 'behaviour_of_input_fields' => 'Behaviour of Input Fields',
2172: 'hiding' => 'Hiding',
2173: 'high_level_randomization' => 'High Level Randomization',
2174: 'slots' => 'Slots',
2175: 'file_submission' => 'File Submission',
2176: 'misc' => 'Miscellaneous' );
2177: }
2178:
2179: # Returns the category for each parameter.
2180: #
2181: # @returns {hash} - parameter name -> category name
2182: sub lookUpTableParameter {
2183:
2184: return (
2185: 'opendate' => 'time_settings',
2186: 'duedate' => 'time_settings',
2187: 'answerdate' => 'time_settings',
2188: 'interval' => 'time_settings',
2189: 'contentopen' => 'time_settings',
2190: 'contentclose' => 'time_settings',
2191: 'discussend' => 'time_settings',
2192: 'printstartdate' => 'time_settings',
2193: 'printenddate' => 'time_settings',
2194: 'weight' => 'grading',
2195: 'handgrade' => 'grading',
2196: 'maxtries' => 'tries',
2197: 'hinttries' => 'tries',
2198: 'randomizeontries' => 'tries',
2199: 'type' => 'problem_appearance',
2200: 'problemstatus' => 'problem_appearance',
2201: 'display' => 'problem_appearance',
2202: 'ordered' => 'problem_appearance',
2203: 'numbubbles' => 'problem_appearance',
2204: 'tol' => 'behaviour_of_input_fields',
2205: 'sig' => 'behaviour_of_input_fields',
2206: 'turnoffunit' => 'behaviour_of_input_fields',
2207: 'hiddenresource' => 'hiding',
2208: 'hiddenparts' => 'hiding',
2209: 'discusshide' => 'hiding',
2210: 'buttonshide' => 'hiding',
2211: 'turnoffeditor' => 'hiding',
2212: 'encrypturl' => 'hiding',
2213: 'deeplink' => 'hiding',
2214: 'randomorder' => 'high_level_randomization',
2215: 'randompick' => 'high_level_randomization',
2216: 'available' => 'slots',
2217: 'useslots' => 'slots',
2218: 'availablestudent' => 'slots',
2219: 'uploadedfiletypes' => 'file_submission',
2220: 'maxfilesize' => 'file_submission',
2221: 'cssfile' => 'misc',
2222: 'mapalias' => 'misc',
2223: 'acc' => 'misc',
2224: 'maxcollaborators' => 'misc',
2225: 'scoreformat' => 'misc',
2226: 'lenient' => 'grading',
2227: 'retrypartial' => 'tries',
2228: 'discussvote' => 'misc',
2229: 'examcode' => 'high_level_randomization',
2230: );
2231: }
2232:
2233: # Adds the given parameter name to an array of arrays listing all parameters for each category.
2234: #
2235: # @param {string} $name - parameter name
2236: # @param {array reference} $catList - array reference category name -> array reference of parameter names
2237: sub whatIsMyCategory {
2238: my $name = shift;
2239: my $catList = shift;
2240: my @list;
2241: my %lookUpList = &lookUpTableParameter; #Initilize the lookupList
2242: my $cat = $lookUpList{$name};
2243: if (defined($cat)) {
2244: if (!defined($$catList{$cat})){
2245: push @list, ($name);
2246: $$catList{$cat} = \@list;
2247: } else {
2248: push @{${$catList}{$cat}}, ($name);
2249: }
2250: } else {
2251: if (!defined($$catList{'misc'})){
2252: push @list, ($name);
2253: $$catList{'misc'} = \@list;
2254: } else {
2255: push @{${$catList}{'misc'}}, ($name);
2256: }
2257: }
2258: }
2259:
2260: # Sorts parameter names based on appearance order.
2261: #
2262: # @param {array reference} name - array reference of parameter names
2263: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
2264: # @returns {Array} - array of parameter names
2265: sub keysindisplayorderCategory {
2266: my ($name,$keyorder)=@_;
2267: return sort {
2268: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
2269: } ( @{$name});
2270: }
2271:
2272: # Returns a hash category name -> order, starting at 1 (integer)
2273: #
2274: # @returns {hash}
2275: sub category_order {
2276: return (
2277: 'time_settings' => 1,
2278: 'grading' => 2,
2279: 'tries' => 3,
2280: 'problem_appearance' => 4,
2281: 'hiding' => 5,
2282: 'behaviour_of_input_fields' => 6,
2283: 'high_level_randomization' => 7,
2284: 'slots' => 8,
2285: 'file_submission' => 9,
2286: 'misc' => 10
2287: );
2288:
2289: }
2290:
2291: # Prints HTML to let the user select parameters, from a list of all parameters organized by category.
2292: #
2293: # @param {Apache2::RequestRec} $r - the Apache request
2294: # @param {hash reference} $allparms - hash parameter name -> parameter title
2295: # @param {array reference} $pscat - list of selected parameter names
2296: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
2297: sub parmboxes {
2298: my ($r,$allparms,$pscat,$keyorder)=@_;
2299: my %categories = &categories();
2300: my %category_order = &category_order();
2301: my %categoryList = (
2302: 'time_settings' => [],
2303: 'grading' => [],
2304: 'tries' => [],
2305: 'problem_appearance' => [],
2306: 'behaviour_of_input_fields' => [],
2307: 'hiding' => [],
2308: 'high_level_randomization' => [],
2309: 'slots' => [],
2310: 'file_submission' => [],
2311: 'misc' => [],
2312: );
2313:
2314: foreach my $tempparameter (keys(%$allparms)) {
2315: &whatIsMyCategory($tempparameter, \%categoryList);
2316: }
2317: #part to print the parm-list
2318: foreach my $key (sort { $category_order{$a} <=> $category_order{$b} } keys(%categoryList)) {
2319: next if (@{$categoryList{$key}} == 0);
2320: next if ($key eq '');
2321: $r->print('<div class="LC_Box LC_400Box">'
2322: .'<h4 class="LC_hcell">'.&mt($categories{$key}).'</h4>'."\n");
2323: foreach my $tempkey (&keysindisplayorderCategory($categoryList{$key},$keyorder)) {
2324: next if ($tempkey eq '');
2325: $r->print('<span class="LC_nobreak">'
2326: .'<label><input type="checkbox" name="pscat" '
2327: .'value="'.$tempkey.'" ');
2328: if ($$pscat[0] eq "all" || grep $_ eq $tempkey, @{$pscat}) {
2329: $r->print( ' checked="checked"');
2330: }
2331: $r->print(' />'.($$allparms{$tempkey}=~/\S/ ? $$allparms{$tempkey}
2332: : $tempkey)
2333: .'</label></span><br />'."\n");
2334: }
2335: $r->print('</div>');
2336: }
2337: $r->print("\n");
2338: }
2339:
2340: # Prints HTML with shortcuts to select groups of parameters in one click, or deselect all.
2341: #
2342: # @param {Apache2::RequestRec} $r - the Apache request
2343: sub shortCuts {
2344: my ($r)=@_;
2345:
2346: # Parameter Selection
2347: $r->print(
2348: &Apache::lonhtmlcommon::start_funclist(&mt('Parameter Selection'))
2349: .&Apache::lonhtmlcommon::add_item_funclist(
2350: '<a href="javascript:checkall(true, \'pscat\')">'.&mt('Select All').'</a>')
2351: .&Apache::lonhtmlcommon::add_item_funclist(
2352: '<a href="javascript:checkstandard()">'.&mt('Select Common Only').'</a>')
2353: .&Apache::lonhtmlcommon::add_item_funclist(
2354: '<a href="javascript:checkall(false, \'pscat\')">'.&mt('Unselect All').'</a>')
2355: .&Apache::lonhtmlcommon::end_funclist()
2356: );
2357:
2358: # Add Selection for...
2359: $r->print(
2360: &Apache::lonhtmlcommon::start_funclist(&mt('Add Selection for...'))
2361: .&Apache::lonhtmlcommon::add_item_funclist(
2362: '<a href="javascript:checkdates()">'.&mt('Problem Dates').'</a>')
2363: .&Apache::lonhtmlcommon::add_item_funclist(
2364: '<a href="javascript:checkcontdates()">'.&mt('Content Dates').'</a>')
2365: .&Apache::lonhtmlcommon::add_item_funclist(
2366: '<a href="javascript:checkdisset()">'.&mt('Discussion Settings').'</a>')
2367: .&Apache::lonhtmlcommon::add_item_funclist(
2368: '<a href="javascript:checkvisi()">'.&mt('Visibilities').'</a>')
2369: .&Apache::lonhtmlcommon::add_item_funclist(
2370: '<a href="javascript:checkparts()">'.&mt('Part Parameters').'</a>')
2371: .&Apache::lonhtmlcommon::end_funclist()
2372: );
2373: }
2374:
2375: # Prints HTML to select parts to view (except for the title).
2376: # Used by table and overview modes.
2377: #
2378: # @param {Apache2::RequestRec} $r - the Apache request
2379: # @param {hash reference} $allparts - hash parameter part -> part title
2380: # @param {array reference} $psprt - list of selected parameter parts
2381: sub partmenu {
2382: my ($r,$allparts,$psprt)=@_;
2383: my $selsize = 1+scalar(keys(%{$allparts}));
2384: if ($selsize > 8) {
2385: $selsize = 8;
2386: }
2387:
2388: $r->print('<select multiple="multiple" name="psprt" size="'.$selsize.'">');
2389: $r->print('<option value="all"');
2390: $r->print(' selected="selected"') unless (@{$psprt}); # useless, the array is never empty
2391: $r->print('>'.&mt('All Parts').'</option>');
2392: my %temphash=();
2393: foreach (@{$psprt}) { $temphash{$_}=1; }
2394: foreach my $tempkey (sort {
2395: if ($a==$b) { return ($a cmp $b) } else { return ($a <=> $b); }
2396: } keys(%{$allparts})) {
2397: unless ($tempkey =~ /\./) {
2398: $r->print('<option value="'.$tempkey.'"');
2399: if ($$psprt[0] eq "all" || $temphash{$tempkey}) {
2400: $r->print(' selected="selected"');
2401: }
2402: $r->print('>'.$$allparts{$tempkey}.'</option>');
2403: }
2404: }
2405: $r->print('</select>');
2406: }
2407:
2408: # Prints HTML to select a user and/or a group.
2409: # Used by table mode.
2410: #
2411: # @param {Apache2::RequestRec} $r - the Apache request
2412: # @param {string} $uname - selected user name
2413: # @param {string} $id - selected Student/Employee ID
2414: # @param {string} $udom - selected user domain
2415: # @param {string} $csec - selected section name
2416: # @param {string} $cgroup - selected group name
2417: # @param {string} $parmlev - parameter level (Resource:'full', Map:'map', Course:'general')
2418: # @param {array reference} $usersgroups - list of groups the user belongs to, if any
2419: # @param {string} $pssymb - resource symb (when a single resource is selected)
2420: sub usermenu {
2421: my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups,$pssymb)=@_;
2422: my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '.
2423: &Apache::loncommon::selectstudent_link('parmform','uname','udom');
2424: my $selscript=&Apache::loncommon::studentbrowser_javascript();
2425:
2426: my $sections='';
2427: my %sectionhash = &Apache::loncommon::get_sections();
2428:
2429: my $groups;
2430: my %grouphash;
2431: if (($pssymb) || &Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
2432: %grouphash = &Apache::longroup::coursegroups();
2433: } elsif ($env{'request.course.groups'} ne '') {
2434: map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
2435: }
2436:
2437: my $g_s_header='';
2438: my $g_s_footer='';
2439:
2440: my $currsec = $env{'request.course.sec'};
2441: if ($currsec) {
2442: $sections=&mt('Section:').' '.$currsec;
2443: if (%grouphash) {
2444: $sections .= ';'.(' ' x2);
2445: }
2446: } elsif (%sectionhash && $currsec eq '') {
2447: $sections=&mt('Section:').' <select name="csec"';
2448: if (%grouphash && $parmlev ne 'full') {
2449: $sections .= qq| onchange="group_or_section('csec')" |;
2450: }
2451: $sections .= '>';
2452: foreach my $section ('',sort(keys(%sectionhash))) {
2453: $sections.='<option value="'.$section.'" '.
2454: ($section eq $csec?'selected="selected"':'').'>'.$section.
2455: '</option>';
2456: }
2457: $sections.='</select>';
2458: }
2459:
2460: if (%sectionhash && %grouphash && $parmlev ne 'full' && $currsec eq '') {
2461: $sections .= ' '.&mt('or').' ';
2462: $sections .= qq|
2463: <script type="text/javascript">
2464: // <![CDATA[
2465: function group_or_section(caller) {
2466: if (caller == "cgroup") {
2467: if (document.parmform.cgroup.selectedIndex != 0) {
2468: document.parmform.csec.selectedIndex = 0;
2469: }
2470: } else {
2471: if (document.parmform.csec.selectedIndex != 0) {
2472: document.parmform.cgroup.selectedIndex = 0;
2473: }
2474: }
2475: }
2476: // ]]>
2477: </script>
2478: |;
2479: } else {
2480: $sections .= qq|
2481: <script type="text/javascript">
2482: // <![CDATA[
2483: function group_or_section(caller) {
2484: return;
2485: }
2486: // ]]>
2487: </script>
2488: |;
2489: }
2490:
2491: if (%grouphash) {
2492: $groups=&mt('Group:').' <select name="cgroup"';
2493: if (%sectionhash && $env{'form.action'} eq 'settable' && $currsec eq '') {
2494: $groups .= qq| onchange="group_or_section('cgroup')" |;
2495: }
2496: $groups .= '>';
2497: foreach my $grp ('',sort(keys(%grouphash))) {
2498: $groups.='<option value="'.$grp.'" ';
2499: if ($grp eq $cgroup) {
2500: unless ((defined($uname)) && ($grp eq '')) {
2501: $groups .= 'selected="selected" ';
2502: }
2503: } elsif (!defined($cgroup)) {
2504: if (@{$usersgroups} == 1) {
2505: if ($grp eq $$usersgroups[0]) {
2506: $groups .= 'selected="selected" ';
2507: }
2508: }
2509: }
2510: $groups .= '>'.$grp.'</option>';
2511: }
2512: $groups.='</select>';
2513: }
2514:
2515: if (%sectionhash || %grouphash) {
2516: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Group/Section')));
2517: $r->print($sections.$groups);
2518: $r->print(&Apache::lonhtmlcommon::row_closure());
2519: } else {
2520: $r->print($sections);
2521: }
2522:
2523: $r->print(&Apache::lonhtmlcommon::row_title(&mt('User')));
2524: $r->print(&mt('For User [_1] or Student/Employee ID [_2] at Domain [_3]'
2525: ,'<input type="text" value="'.$uname.'" size="12" name="uname" />'
2526: ,'<input type="text" value="'.$id.'" size="12" name="id" /> '
2527: ,$chooseopt));
2528: }
2529:
2530: # Prints HTML to select parameters from a list of all parameters.
2531: # Uses parmmenu and parmboxes.
2532: # Used by table and overview modes.
2533: #
2534: # @param {Apache2::RequestRec} $r - the Apache request
2535: # @param {hash reference} $allparms - hash parameter name -> parameter title
2536: # @param {array reference} $pscat - list of selected parameter names
2537: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
2538: # @param {string} [$divid] - name used to give an id to the HTML element for the scroll box
2539: sub displaymenu {
2540: my ($r,$allparms,$pscat,$keyorder,$divid)=@_;
2541:
2542: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2543: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameters to View')));
2544:
2545: &parmmenu($r);
2546: $r->print(&Apache::loncommon::start_scrollbox('480px','440px','200px',$divid));
2547: &parmboxes($r,$allparms,$pscat,$keyorder);
2548: $r->print(&Apache::loncommon::end_scrollbox());
2549:
2550: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2551: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2552:
2553: }
2554:
2555: # Prints HTML to select a map.
2556: # Used by table mode and overview mode.
2557: #
2558: # @param {Apache2::RequestRec} $r - the Apache request
2559: # @param {hash reference} $allmaps - hash map pc -> map src
2560: # @param {string} $pschp - selected map pc, or 'all'
2561: # @param {hash reference} $maptitles - hash map id or src -> map title
2562: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' or resource symb
2563: sub mapmenu {
2564: my ($r,$allmaps,$pschp,$maptitles,$symbp)=@_;
2565: my %allmaps_inverted = reverse %$allmaps;
2566: my $navmap = Apache::lonnavmaps::navmap->new();
2567: my $tree=[];
2568: my $treeinfo={};
2569: if (defined($navmap)) {
2570: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
2571: my $curRes;
2572: my $depth = 0;
2573: my %parent = ();
2574: my $startcount = 5;
2575: my $lastcontainer = $startcount;
2576: # preparing what is to show ...
2577: while ($curRes = $it->next()) {
2578: if ($curRes == $it->BEGIN_MAP()) {
2579: $depth++;
2580: $parent{$depth}= $lastcontainer;
2581: }
2582: if ($curRes == $it->END_MAP()) {
2583: $depth--;
2584: $lastcontainer = $parent{$depth};
2585: }
2586: if (ref($curRes)) {
2587: my $symb = $curRes->symb();
2588: my $ressymb = $symb;
2589: if (($curRes->is_sequence()) || ($curRes->is_page())) {
2590: my $type = 'sequence';
2591: if ($curRes->is_page()) {
2592: $type = 'page';
2593: }
2594: my $id= $curRes->id();
2595: my $srcf = $curRes->src();
2596: my $resource_name = &Apache::lonnet::gettitle($srcf);
2597: if(!exists($treeinfo->{$id})) {
2598: push(@$tree,$id);
2599: my $enclosing_map_folder = &Apache::lonnet::declutter($curRes->enclosing_map_src());
2600: $treeinfo->{$id} = {
2601: depth => $depth,
2602: type => $type,
2603: name => $resource_name,
2604: enclosing_map_folder => $enclosing_map_folder,
2605: };
2606: }
2607: }
2608: }
2609: }
2610: }
2611: # Show it ...
2612: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Enclosing Map or Folder'),'','',' id="mapmenu"'));
2613: if ((ref($tree) eq 'ARRAY') && (ref($treeinfo) eq 'HASH')) {
2614: my $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
2615: my $whitespace =
2616: '<img src="'
2617: .&Apache::loncommon::lonhttpdurl('/adm/lonIcons/whitespace_21.gif')
2618: .'" alt="" />';
2619:
2620: # Info about selectable folders/maps
2621: $r->print(
2622: '<div class="LC_info">'
2623: .&mt('You can only select maps and folders which have modifiable settings.')
2624: .' '.&Apache::loncommon::help_open_topic('Parameter_Set_Folder')
2625: .'</div>'
2626: );
2627:
2628: $r->print(&Apache::loncommon::start_scrollbox('700px','680px','400px','mapmenuscroll'));
2629: $r->print(&Apache::loncommon::start_data_table(undef,'mapmenuinner'));
2630:
2631: # Display row: "All Maps or Folders"
2632: $r->print(
2633: &Apache::loncommon::start_data_table_row(undef,'picklevel')
2634: .'<td>'
2635: .'<label>'
2636: .'<input type="radio" name="pschp"'
2637: );
2638: $r->print(' checked="checked"') if ($pschp eq 'all' || !$pschp);
2639: $r->print(
2640: ' value="all" /> '.$icon.' '
2641: .&mt('All Maps or Folders')
2642: .'</label>'
2643: .'<hr /></td>'
2644: .&Apache::loncommon::end_data_table_row()
2645: );
2646:
2647: # Display row: "Main Content"
2648: if (exists($$allmaps{1})) {
2649: $r->print(
2650: &Apache::loncommon::start_data_table_row()
2651: .'<td>'
2652: .'<label>'
2653: .'<input type="radio" name="pschp" value="1"'
2654: );
2655: $r->print(' checked="checked"') if ($pschp eq '1');
2656: $r->print(
2657: '/> '.$icon.' '
2658: .$$maptitles{1}
2659: .($$allmaps{1} !~/^uploaded/?' ['.$$allmaps{1}.']':'')
2660: .'</label>'
2661: .'</td>'
2662: .&Apache::loncommon::end_data_table_row()
2663: );
2664: }
2665:
2666: # Display rows for all course maps and folders
2667: foreach my $id (@{$tree}) {
2668: my ($mapid,$resid)=split(/\./,$id);
2669: # Indentation
2670: my $depth = $treeinfo->{$id}->{'depth'};
2671: my $indent;
2672: for (my $i = 0; $i < $depth; $i++) {
2673: $indent.= $whitespace;
2674: }
2675: $icon = '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />';
2676: if ($treeinfo->{$id}->{'type'} eq 'page') {
2677: $icon = '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" />';
2678: }
2679: my $symb_name = $$symbp{$id};
2680: my ($front, $tail) = split (/___${resid}___/, $symb_name);
2681: $symb_name = $tail;
2682: $r->print(
2683: &Apache::loncommon::start_data_table_row()
2684: .'<td>'
2685: .'<label>'
2686: );
2687: # Only offer radio button for folders/maps which can be parameterized
2688: if ($allmaps_inverted{$symb_name}) {
2689: $r->print(
2690: '<input type ="radio" name="pschp"'
2691: .' value="'.$allmaps_inverted{$symb_name}.'"'
2692: );
2693: $r->print(' checked="checked"') if ($allmaps_inverted{$symb_name} eq $pschp);
2694: $r->print('/>');
2695: } else {
2696: $r->print($whitespace);
2697: }
2698: $r->print(
2699: $indent.$icon.' '
2700: .$treeinfo->{$id}->{name}
2701: .($$allmaps{$mapid}!~/^uploaded/?' ['.$$allmaps{$mapid}.']':'')
2702: .'</label>'
2703: .'</td>'
2704: .&Apache::loncommon::end_data_table_row()
2705: );
2706: }
2707:
2708: $r->print(&Apache::loncommon::end_data_table().
2709: '<br style="line-height:2px;" />'.
2710: &Apache::loncommon::end_scrollbox());
2711: }
2712: }
2713:
2714: # Prints HTML to select the parameter level (resource, map/folder or course).
2715: # Used by table and overview modes.
2716: #
2717: # @param {Apache2::RequestRec} $r - the Apache request
2718: # @param {hash reference} $alllevs - all parameter levels, hash English title -> value
2719: # @param {string} $parmlev - selected level value (full|map|general), or ''
2720: sub levelmenu {
2721: my ($r,$alllevs,$parmlev)=@_;
2722:
2723: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parameter Level').
2724: &Apache::loncommon::help_open_topic('Course_Parameter_Levels')));
2725: $r->print('<select id="parmlev" name="parmlev" onchange="showHide_courseContent()">');
2726: foreach my $lev (reverse(sort(keys(%{$alllevs})))) {
2727: $r->print('<option value="'.$$alllevs{$lev}.'"');
2728: if ($parmlev eq $$alllevs{$lev}) {
2729: $r->print(' selected="selected"');
2730: }
2731: $r->print('>'.&mt($lev).'</option>');
2732: }
2733: $r->print("</select>");
2734: }
2735:
2736:
2737: # Returns HTML to select a section (with a select HTML element).
2738: # Used by overview mode.
2739: #
2740: # @param {array reference} $selectedsections - list of selected section ids
2741: # @returns {string}
2742: sub sectionmenu {
2743: my ($selectedsections)=@_;
2744: my %sectionhash = &Apache::loncommon::get_sections();
2745: return '' if (!%sectionhash);
2746:
2747: my (@possibles,$disabled);
2748: if ($env{'request.course.sec'} ne '') {
2749: @possibles = ($env{'request.course.sec'});
2750: $selectedsections = [$env{'request.course.sec'}];
2751: $disabled = ' disabled="disabled"';
2752: } else {
2753: @possibles = ('all',sort(keys(%sectionhash)));
2754: }
2755: my $output = '<select name="Section" multiple="multiple" size="8"'.$disabled.'>';
2756: foreach my $s (@possibles) {
2757: $output .= ' <option value="'.$s.'"';
2758: if ((@{$selectedsections}) && (grep(/^\Q$s\E$/,@{$selectedsections}))) {
2759: $output .= ' selected="selected"';
2760: }
2761: $output .= '>'."$s</option>\n";
2762: }
2763: $output .= "</select>\n";
2764: return $output;
2765: }
2766:
2767: # Returns HTML to select a group (with a select HTML element).
2768: # Used by overview mode.
2769: #
2770: # @param {array reference} $selectedgroups - list of selected group names
2771: # @returns {string}
2772: sub groupmenu {
2773: my ($selectedgroups)=@_;
2774: my %grouphash;
2775: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
2776: %grouphash = &Apache::longroup::coursegroups();
2777: } elsif ($env{'request.course.groups'} ne '') {
2778: map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
2779: }
2780: return '' if (!%grouphash);
2781:
2782: my $output = '<select name="Group" multiple="multiple" size="8">';
2783: foreach my $group (sort(keys(%grouphash))) {
2784: $output .= ' <option value="'.$group.'"';
2785: if ((@{$selectedgroups}) && (grep(/^\Q$group\E$/,\@{$selectedgroups}))) {
2786: $output .= ' selected="selected"';
2787: }
2788: $output .= '>'."$group</option>\n";
2789: }
2790: $output .= "</select>\n";
2791: return $output;
2792: }
2793:
2794: # Returns an array with the given parameter split by comma.
2795: # Used by assessparms (table mode).
2796: #
2797: # @param {string} $keyp - the string to split
2798: # @returns {Array<string>}
2799: sub keysplit {
2800: my $keyp=shift;
2801: return (split(/\,/,$keyp));
2802: }
2803:
2804: # Returns the keys in $name, sorted using $keyorder.
2805: # Parameters are sorted by key, which means they are sorted by part first, then by name.
2806: # Used by assessparms (table mode) for resource level.
2807: #
2808: # @param {hash reference} $name - parameter key -> parameter name
2809: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
2810: # @returns {Array<string>}
2811: sub keysinorder {
2812: my ($name,$keyorder)=@_;
2813: return sort {
2814: $$keyorder{$a} <=> $$keyorder{$b};
2815: } (keys(%{$name}));
2816: }
2817:
2818: # Returns the keys in $name, sorted using $keyorder to sort parameters by name first, then by part.
2819: # Used by assessparms (table mode) for map and general levels.
2820: #
2821: # @param {hash reference} $name - parameter key -> parameter name
2822: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
2823: # @returns {Array<string>}
2824: sub keysinorder_bytype {
2825: my ($name,$keyorder)=@_;
2826: return sort {
2827: my $ta=(split('_',$a))[-1]; # parameter name
2828: my $tb=(split('_',$b))[-1];
2829: if ($$keyorder{'parameter_0_'.$ta} == $$keyorder{'parameter_0_'.$tb}) {
2830: return ($a cmp $b);
2831: }
2832: $$keyorder{'parameter_0_'.$ta} <=> $$keyorder{'parameter_0_'.$tb};
2833: } (keys(%{$name}));
2834: }
2835:
2836: # Returns the keys in $name, sorted using $keyorder to sort parameters by name.
2837: # Used by defaultsetter (parameter settings default actions).
2838: #
2839: # @param {hash reference} $name - hash parameter name -> parameter title
2840: # @param {hash reference} $keyorder - hash parameter key -> appearance rank
2841: # @returns {Array<string>}
2842: sub keysindisplayorder {
2843: my ($name,$keyorder)=@_;
2844: return sort {
2845: $$keyorder{'parameter_0_'.$a} <=> $$keyorder{'parameter_0_'.$b};
2846: } (keys(%{$name}));
2847: }
2848:
2849: # Prints HTML with a choice to sort results by realm or student first.
2850: # Used by overview mode.
2851: #
2852: # @param {Apache2::RequestRec} $r - the Apache request
2853: # @param {string} $sortorder - realmstudent|studentrealm
2854: sub sortmenu {
2855: my ($r,$sortorder)=@_;
2856: $r->print('<br /><label><input type="radio" name="sortorder" value="realmstudent"');
2857: if ($sortorder eq 'realmstudent') {
2858: $r->print(' checked="checked"');
2859: }
2860: $r->print(' />'.&mt('Sort by realm first, then student (group/section)'));
2861: $r->print('</label><br /><label><input type="radio" name="sortorder" value="studentrealm"');
2862: if ($sortorder eq 'studentrealm') {
2863: $r->print(' checked="checked"');
2864: }
2865: $r->print(' />'.&mt('Sort by student (group/section) first, then realm').
2866: '</label>');
2867: }
2868:
2869: # Returns a hash parameter key -> order (integer) giving the order for some parameters.
2870: #
2871: # @returns {hash}
2872: sub standardkeyorder {
2873: return ('parameter_0_opendate' => 1,
2874: 'parameter_0_duedate' => 2,
2875: 'parameter_0_answerdate' => 3,
2876: 'parameter_0_interval' => 4,
2877: 'parameter_0_weight' => 5,
2878: 'parameter_0_maxtries' => 6,
2879: 'parameter_0_hinttries' => 7,
2880: 'parameter_0_contentopen' => 8,
2881: 'parameter_0_contentclose' => 9,
2882: 'parameter_0_type' => 10,
2883: 'parameter_0_problemstatus' => 11,
2884: 'parameter_0_hiddenresource' => 12,
2885: 'parameter_0_hiddenparts' => 13,
2886: 'parameter_0_display' => 14,
2887: 'parameter_0_ordered' => 15,
2888: 'parameter_0_tol' => 16,
2889: 'parameter_0_sig' => 17,
2890: 'parameter_0_turnoffunit' => 18,
2891: 'parameter_0_discussend' => 19,
2892: 'parameter_0_discusshide' => 20,
2893: 'parameter_0_discussvote' => 21,
2894: 'parameter_0_printstartdate' => 22,
2895: 'parameter_0_printenddate' => 23);
2896: }
2897:
2898:
2899: # Table mode UI.
2900: # If nothing is selected, prints HTML forms to select resources, parts, parameters, user, group and section.
2901: # Otherwise, prints the parameter table, with a link to change the selection unless a single resource is selected.
2902: #
2903: # Parameters used from the request:
2904: # action - handler action (see handler), usermenu is checking for value 'settable'
2905: # cgroup - selected group
2906: # command - 'set': direct access to table mode for a resource
2907: # csec - selected section
2908: # dis - set when the "Update Display" button was used, used only to discard command 'set'
2909: # hideparmsel - can be 'hidden' to hide the parameter selection div initially and display the "Change Parameter Selection" link instead (which displays the div)
2910: # id - student/employee ID
2911: # parmlev - selected level (full|map|general)
2912: # part - selected part (unused ?)
2913: # pres_marker - &&&-separated parameter identifiers, "resource id&part_parameter name&level"
2914: # pres_type - &&&-separated parameter types
2915: # pres_value - &&&-separated parameter values
2916: # prevvisit - '1' if the user has submitted the form before
2917: # pscat (multiple values) - selected parameter names
2918: # pschp - selected map pc, or 'all'
2919: # psprt (multiple values) - list of selected parameter parts
2920: # filter - part of or whole parameter name, to be filtered out when parameters are displayed (unused ?)
2921: # recent_* (* = parameter type) - recent values entered by the user for parameter types
2922: # symb - resource symb (when a single resource is selected)
2923: # udom - selected user domain
2924: # uname - selected user name
2925: # url - used only with command 'set', the resource url
2926: #
2927: # @param {Apache2::RequestRec} $r - the Apache request
2928: # @param $parm_permission - ref to hash of permissions
2929: # if $parm_permission->{'edit'} is true, editing is allowed.
2930: sub assessparms {
2931:
2932: my ($r,$parm_permission) = @_;
2933:
2934:
2935: # -------------------------------------------------------- Variable declaration
2936: my @ids=(); # resource and map ids
2937: my %symbp=(); # hash map pc or resource/map id -> map src.'___(all)' or resource symb
2938: my %mapp=(); # hash map pc or resource/map id -> enclosing map src
2939: my %typep=(); # hash resource/map id -> resource type (file extension)
2940: my %keyp=(); # hash resource/map id -> comma-separated list of parameter keys
2941: my %uris=(); # hash resource/map id -> resource src
2942: my %maptitles=(); # hash map pc or src -> map title
2943: my %allmaps=(); # hash map pc -> map src
2944: my %allmaps_inverted=(); # hash map src -> map pc
2945: my %alllevs=(); # hash English level title -> value
2946:
2947: my $uname; # selected user name
2948: my $udom; # selected user domain
2949: my $uhome; # server with the user's files, or 'no_host'
2950: my $csec; # selected section name
2951: my $cgroup; # selected group name
2952: my @usersgroups = (); # list of the user groups
2953: my $numreclinks = 0;
2954:
2955: my $coursename=$env{'course.'.$env{'request.course.id'}.'.description'};
2956:
2957: $alllevs{'Resource Level'}='full';
2958: $alllevs{'Map/Folder Level'}='map';
2959: $alllevs{'Course Level'}='general';
2960:
2961: my %allparms; # hash parameter name -> parameter title
2962: my %allparts; # hash parameter part -> part title
2963: # ------------------------------------------------------------------------------
2964:
2965: #
2966: # Order in which these parameters will be displayed
2967: #
2968: my %keyorder=&standardkeyorder();
2969:
2970: # @ids=();
2971: # %symbp=(); # These seem defined above already.
2972: # %typep=();
2973:
2974: my $message='';
2975:
2976: $csec=$env{'form.csec'};
2977: if ($env{'request.course.sec'} ne '') {
2978: $csec = $env{'request.course.sec'};
2979: }
2980:
2981: # Check group privs.
2982: $cgroup=$env{'form.cgroup'};
2983: my $noeditgrp;
2984: if ($cgroup ne '') {
2985: unless (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
2986: if (($env{'request.course.groups'} eq '') ||
2987: (!grep(/^\Q$cgroup\E$/,split(/:/,$env{'request.course.groups'})))) {
2988: $noeditgrp = 1;
2989: }
2990: }
2991: }
2992:
2993: if ($udom=$env{'form.udom'}) {
2994: } elsif ($udom=$env{'request.role.domain'}) {
2995: } elsif ($udom=$env{'user.domain'}) {
2996: } else {
2997: $udom=$r->dir_config('lonDefDomain');
2998: }
2999:
3000:
3001: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
3002: my $pschp=$env{'form.pschp'};
3003:
3004:
3005: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
3006: if (!@psprt) { $psprt[0]='all'; }
3007: if (($env{'form.part'}) && ($psprt[0] ne 'all')) { $psprt[0]=$env{'form.part'}; }
3008:
3009: my $pssymb='';
3010: my $parmlev='';
3011:
3012: unless ($env{'form.parmlev'}) {
3013: $parmlev = 'map';
3014: } else {
3015: $parmlev = $env{'form.parmlev'};
3016: }
3017:
3018: # ----------------------------------------------- Was this started from grades?
3019:
3020: if (($env{'form.command'} eq 'set') && ($env{'form.url'}) &&
3021: (!$env{'form.dis'})) {
3022: my $url=$env{'form.url'};
3023: $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
3024: $pssymb=&Apache::lonnet::symbread($url);
3025: if (!@pscat) { @pscat=('all'); }
3026: $pschp='';
3027: $parmlev = 'full';
3028: } elsif ($env{'form.symb'}) {
3029: $pssymb=$env{'form.symb'};
3030: if (!@pscat) { @pscat=('all'); }
3031: $pschp='';
3032: $parmlev = 'full';
3033: } else {
3034: $env{'form.url'}='';
3035: }
3036:
3037: my $id=$env{'form.id'};
3038: if (($id) && ($udom)) {
3039: $uname=(&Apache::lonnet::idget($udom,[$id],'ids'))[1];
3040: if ($uname) {
3041: $id='';
3042: } else {
3043: $message=
3044: '<p class="LC_warning">'.
3045: &mt('Unknown ID [_1] at domain [_2]',
3046: "'".$id."'","'".$udom."'").
3047: '</p>';
3048: }
3049: } else {
3050: $uname=$env{'form.uname'};
3051: }
3052: unless ($udom) { $uname=''; }
3053: $uhome='';
3054: if ($uname) {
3055: $uhome=&Apache::lonnet::homeserver($uname,$udom);
3056: if ($uhome eq 'no_host') {
3057: $message=
3058: '<p class="LC_warning">'.
3059: &mt('Unknown user [_1] at domain [_2]',
3060: "'".$uname."'","'".$udom."'").
3061: '</p>';
3062: $uname='';
3063: } else {
3064: $csec=&Apache::lonnet::getsection($udom,$uname,
3065: $env{'request.course.id'});
3066: if ($csec eq '-1') {
3067: $message=
3068: '<p class="LC_warning">'.
3069: &mt('User [_1] at domain [_2] not in this course',
3070: "'".$uname."'","'".$udom."'").
3071: '</p>';
3072: $uname='';
3073: if ($env{'request.course.sec'} ne '') {
3074: $csec=$env{'request.course.sec'};
3075: } else {
3076: $csec=$env{'form.csec'};
3077: }
3078: $cgroup=$env{'form.cgroup'};
3079: } elsif ($env{'request.course.sec'} ne '') {
3080: if ($csec ne $env{'request.course.sec'}) {
3081: $message='<span class="LC_error">'.
3082: &mt("User '[_1]' at domain '[_2]' not in section '[_3]'",
3083: $uname,$udom,$env{'request.course.sec'}).
3084: '</span>';
3085: $uname='';
3086: $csec=$env{'request.course.sec'};
3087: }
3088: $cgroup=$env{'form.cgroup'};
3089: } else {
3090: my %name=&Apache::lonnet::userenvironment($udom,$uname,
3091: ('firstname','middlename','lastname','generation','id'));
3092: $message="\n<p>\n".&mt("Full Name").": ".
3093: $name{'firstname'}.' '.$name{'middlename'}.' '
3094: .$name{'lastname'}.' '.$name{'generation'}.
3095: "<br />\n".&mt('Student/Employee ID').": ".$name{'id'}.'<p>';
3096: }
3097: @usersgroups = &Apache::lonnet::get_users_groups(
3098: $udom,$uname,$env{'request.course.id'});
3099: if (@usersgroups > 0) {
3100: unless (grep(/^\Q$cgroup\E$/,@usersgroups)) {
3101: $cgroup = $usersgroups[0];
3102: }
3103: }
3104: }
3105: }
3106:
3107: unless ($csec) { $csec=''; }
3108: unless ($cgroup) { $cgroup=''; }
3109:
3110: # --------------------------------------------------------- Get all assessments
3111: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
3112: \%mapp, \%symbp,\%maptitles,\%uris,
3113: \%keyorder);
3114:
3115: %allmaps_inverted = reverse(%allmaps);
3116:
3117: $mapp{'0.0'} = '';
3118: $symbp{'0.0'} = '';
3119:
3120: # ---------------------------------------------------------- Anything to store?
3121: if ($env{'form.pres_marker'} && $parm_permission->{'edit'}) {
3122: my @markers=split(/\&\&\&/,$env{'form.pres_marker'});
3123: my @values=split(/\&\&\&/,$env{'form.pres_value'});
3124: my @types=split(/\&\&\&/,$env{'form.pres_type'});
3125: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3126: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3127: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
3128: my ($got_chostname,$chostname,$cmajor,$cminor);
3129: my $totalstored = 0;
3130: my $now = time;
3131: for (my $i=0;$i<=$#markers;$i++) {
3132: my ($needsrelease,$needsnewer,$name,$namematch);
3133: if (($env{'request.course.sec'} ne '') && ($markers[$i] =~ /\&(9|10|11|12)$/)) {
3134: next if ($csec ne $env{'request.course.sec'});
3135: }
3136: if ($markers[$i] =~ /\&(8|7|6|5)$/) {
3137: next if ($noeditgrp);
3138: }
3139: if ($markers[$i] =~ /\&(17|11|7|3)$/) {
3140: $namematch = 'maplevelrecurse';
3141: }
3142: if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3|4)$/) {
3143: my (@ok_slots,@fail_slots,@del_slots);
3144: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
3145: my ($level,@all) =
3146: &parmval_by_symb('0.availablestudent',$pssymb,'',$uname,$udom,
3147: $csec,$cgroup,$courseopt);
3148: foreach my $slot_name (split(/:/,$values[$i])) {
3149: next if ($slot_name eq '');
3150: if (&update_slots($slot_name,$cdom,$cnum,$pssymb,$uname,$udom) eq 'ok') {
3151: push(@ok_slots,$slot_name);
3152:
3153: } else {
3154: push(@fail_slots,$slot_name);
3155: }
3156: }
3157: if (@ok_slots) {
3158: $values[$i] = join(':',@ok_slots);
3159: } else {
3160: $values[$i] = '';
3161: }
3162: if ($all[$level] ne '') {
3163: my @existing = split(/:/,$all[$level]);
3164: foreach my $slot_name (@existing) {
3165: if (!grep(/^\Q$slot_name\E$/,split(/:/,$values[$i]))) {
3166: if (&delete_slots($slot_name,$cdom,$cnum,$uname,$udom,$pssymb) eq 'ok') {
3167: push(@del_slots,$slot_name);
3168: }
3169: }
3170: }
3171: }
3172: } elsif ($markers[$i] =~ /_(type|lenient|retrypartial|discussvote|examcode|printstartdate|printenddate|acc|interval)\&\d+$/) {
3173: $name = $1;
3174: my $val = $values[$i];
3175: my $valmatch = '';
3176: if ($name eq 'examcode') {
3177: if (&Apache::lonnet::validCODE($values[$i])) {
3178: $val = 'valid';
3179: }
3180: } elsif ($name eq 'printstartdate') {
3181: if ($val =~ /^\d+$/) {
3182: if ($val > $now) {
3183: $val = 'future';
3184: }
3185: }
3186: } elsif ($name eq 'printenddate') {
3187: if ($val =~ /^\d+$/) {
3188: if ($val < $now) {
3189: $val = 'past';
3190: }
3191: }
3192: } elsif (($name eq 'lenient') || ($name eq 'acc')) {
3193: my $stringtype = &get_stringtype($name);
3194: my $stringmatch = &standard_string_matches($stringtype);
3195: if (ref($stringmatch) eq 'ARRAY') {
3196: foreach my $item (@{$stringmatch}) {
3197: if (ref($item) eq 'ARRAY') {
3198: my ($regexpname,$pattern) = @{$item};
3199: if ($pattern ne '') {
3200: if ($val =~ /$pattern/) {
3201: $valmatch = $regexpname;
3202: $val = '';
3203: last;
3204: }
3205: }
3206: }
3207: }
3208: }
3209: } elsif ($name eq 'interval') {
3210: my $intervaltype = &get_intervaltype($name);
3211: my $intervalmatch = &standard_interval_matches($intervaltype);
3212: if (ref($intervalmatch) eq 'ARRAY') {
3213: foreach my $item (@{$intervalmatch}) {
3214: if (ref($item) eq 'ARRAY') {
3215: my ($regexpname,$pattern) = @{$item};
3216: if ($pattern ne '') {
3217: if ($val =~ /$pattern/) {
3218: $valmatch = $regexpname;
3219: $val = '';
3220: last;
3221: }
3222: }
3223: }
3224: }
3225: }
3226: }
3227: $needsrelease =
3228: $Apache::lonnet::needsrelease{"parameter:$name:$val:$valmatch:"};
3229: if ($needsrelease) {
3230: unless ($got_chostname) {
3231: ($chostname,$cmajor,$cminor) = ¶meter_release_vars();
3232: $got_chostname = 1;
3233: }
3234: $needsnewer = ¶meter_releasecheck($name,$val,$valmatch,undef,
3235: $needsrelease,
3236: $cmajor,$cminor);
3237: }
3238: }
3239: if ($needsnewer) {
3240: undef($namematch);
3241: } else {
3242: my $currneeded;
3243: if ($needsrelease) {
3244: $currneeded = $needsrelease;
3245: }
3246: if ($namematch) {
3247: $needsrelease =
3248: $Apache::lonnet::needsrelease{"parameter::::$namematch"};
3249: if (($needsrelease) && (($currneeded eq '') || ($needsrelease < $currneeded))) {
3250: unless ($got_chostname) {
3251: ($chostname,$cmajor,$cminor) = ¶meter_release_vars();
3252: $got_chostname = 1;
3253: }
3254: $needsnewer = ¶meter_releasecheck(undef,undef,undef,$namematch,
3255: $needsrelease,
3256: $cmajor,$cminor);
3257: } else {
3258: undef($namematch);
3259: }
3260: }
3261: }
3262: if ($needsnewer) {
3263: $message .= &oldversion_warning($name,$namematch,$values[$i],$chostname,$cmajor,
3264: $cminor,$needsrelease);
3265: } else {
3266: $message.=&storeparm(split(/\&/,$markers[$i]),
3267: $values[$i],
3268: $types[$i],
3269: $uname,$udom,$csec,$cgroup);
3270: $totalstored ++;
3271: }
3272: }
3273: # ---------------------------------------------------------------- Done storing
3274: if ($totalstored) {
3275: $message.='<p class="LC_warning">'
3276: .&mt('Changes can take up to 10 minutes before being active for all students.')
3277: .&Apache::loncommon::help_open_topic('Caching')
3278: .'</p>';
3279: }
3280: }
3281:
3282: #----------------------------------------------- if all selected, fill in array
3283: if ($pscat[0] eq "all") {
3284: @pscat = (keys(%allparms));
3285: }
3286: if (!@pscat) {
3287: @pscat=('duedate','opendate','answerdate','weight','maxtries','type','problemstatus')
3288: };
3289: if ($psprt[0] eq "all" || !@psprt) {
3290: @psprt = (keys(%allparts));
3291: }
3292: # ------------------------------------------------------------------ Start page
3293:
3294: my $crstype = &Apache::loncommon::course_type();
3295: &startpage($r,$pssymb,$crstype);
3296:
3297: foreach my $item ('tolerance','date_default','date_start','date_end',
3298: 'date_interval','int','float','string','string_lenient',
3299: 'string_examcode','string_deeplink','string_discussvote',
3300: 'string_useslots','string_problemstatus','string_ip',
3301: 'string_questiontype') {
3302: $r->print('<input type="hidden" value="'.
3303: &HTML::Entities::encode($env{'form.recent_'.$item},'"&<>').
3304: '" name="recent_'.$item.'" />');
3305: }
3306:
3307: # ----- Start Parameter Selection
3308:
3309: # Hide parm selection?
3310: $r->print(<<ENDPARMSELSCRIPT);
3311: <script type="text/javascript">
3312: // <![CDATA[
3313: function parmsel_show() {
3314: document.getElementById('parmsel').style.display = "";
3315: document.getElementById('parmsellink').style.display = "none";
3316: }
3317: // ]]>
3318: </script>
3319: ENDPARMSELSCRIPT
3320:
3321: if (!$pssymb) {
3322: # No single resource selected, print forms to select things (hidden after first selection)
3323: my $parmselhiddenstyle=' style="display:none"';
3324: if($env{'form.hideparmsel'} eq 'hidden') {
3325: $r->print('<div id="parmsel"'.$parmselhiddenstyle.'>');
3326: } else {
3327: $r->print('<div id="parmsel">');
3328: }
3329:
3330: # Step 1
3331: $r->print(&Apache::lonhtmlcommon::topic_bar(1,&mt('Resource Specification'),'parmstep1'));
3332: $r->print('
3333: <script type="text/javascript">
3334: // <![CDATA['.
3335: &showhide_js().'
3336: // ]]>
3337: </script>
3338: ');
3339: $r->print(&Apache::lonhtmlcommon::start_pick_box(undef,'parmlevel'));
3340: &levelmenu($r,\%alllevs,$parmlev);
3341: $r->print(&Apache::lonhtmlcommon::row_closure());
3342: &mapmenu($r,\%allmaps,$pschp,\%maptitles, \%symbp);
3343: $r->print(&Apache::lonhtmlcommon::row_closure());
3344: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
3345: &partmenu($r,\%allparts,\@psprt);
3346: $r->print(&Apache::lonhtmlcommon::row_closure(1));
3347: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3348:
3349: # Step 2
3350: $r->print(&Apache::lonhtmlcommon::topic_bar(2,&mt('Parameter Specification'),'parmstep2'));
3351: &displaymenu($r,\%allparms,\@pscat,\%keyorder,'parmmenuscroll');
3352:
3353: # Step 3
3354: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('User Specification (optional)'),'parmstep3'));
3355: $r->print(&Apache::lonhtmlcommon::start_pick_box());
3356: &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb);
3357: $r->print(&Apache::lonhtmlcommon::row_closure(1));
3358: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3359:
3360: # Update Display Button
3361: $r->print('<p>'
3362: .'<input type="submit" name="dis"'
3363: .' value="'.&mt('Update Display').'" />'
3364: .'<input type="hidden" name="hideparmsel" value="hidden" />'
3365: .'</p>');
3366: $r->print('</div>');
3367:
3368: # Offer link to display parameter selection again
3369: $r->print('<p id="parmsellink"');
3370: if ($env{'form.hideparmsel'} ne 'hidden') {
3371: $r->print($parmselhiddenstyle);
3372: }
3373: $r->print('>'
3374: .'<a href="javascript:parmsel_show()">'
3375: .&mt('Change Parameter Selection')
3376: .'</a>'
3377: .'</p>');
3378: } else {
3379: # parameter screen for a single resource.
3380: my ($map,$iid,$resource)=&Apache::lonnet::decode_symb($pssymb);
3381: my $title = &Apache::lonnet::gettitle($pssymb);
3382: $r->print(&mt('Specific Resource: [_1] ([_2])',
3383: $title,'<span class="LC_filename">'.$resource.'</span>').
3384: '<input type="hidden" value="'.$pssymb.'" name="symb" />'.
3385: '<br />');
3386: $r->print(&Apache::lonhtmlcommon::topic_bar('',&mt('Additional Display Specification (optional)')));
3387: $r->print(&Apache::lonhtmlcommon::start_pick_box());
3388: &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb);
3389: $r->print(&Apache::lonhtmlcommon::row_closure(1));
3390: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3391: $r->print('<p>'
3392: .'<input type="submit" name="dis"'
3393: .' value="'.&mt('Update Display').'" />'
3394: .'<input type="hidden" name="hideparmsel" value="hidden" />'
3395: .'</p>');
3396: }
3397:
3398: # ----- End Parameter Selection
3399:
3400: # Display Messages
3401: $r->print('<div>'.$message.'</div>');
3402:
3403:
3404: my @temp_pscat;
3405: map {
3406: my $cat = $_;
3407: push(@temp_pscat, map { $_.'.'.$cat } @psprt);
3408: } @pscat;
3409:
3410: @pscat = @temp_pscat;
3411:
3412:
3413: if (($env{'form.prevvisit'}) || ($pschp) || ($pssymb)) {
3414: # ----------------------------------------------------------------- Start Table
3415: my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat;
3416: my $csuname=$env{'user.name'};
3417: my $csudom=$env{'user.domain'};
3418: my $readonly = 1;
3419: if ($parm_permission->{'edit'}) {
3420: undef($readonly);
3421: }
3422:
3423: if ($parmlev eq 'full') {
3424: #
3425: # This produces the cascading table output of parameters
3426: #
3427: my $coursespan=$csec?8:5;
3428: my $userspan=3;
3429: if ($cgroup ne '') {
3430: $coursespan += 3;
3431: }
3432:
3433: $r->print(&Apache::loncommon::start_data_table());
3434: #
3435: # This produces the headers
3436: #
3437: $r->print('<tr><td colspan="5"></td>');
3438: $r->print('<th colspan="'.($coursespan).'">'.&mt('Any User').'</th>');
3439: if ($uname) {
3440: if (@usersgroups > 1) {
3441: $userspan ++;
3442: }
3443: $r->print('<th colspan="'.$userspan.'" rowspan="2">');
3444: $r->print(&mt('User [_1] at Domain [_2]',"'".$uname."'","'".$udom."'").'</th>');
3445: }
3446: my %lt=&Apache::lonlocal::texthash(
3447: 'pie' => "Parameter in Effect",
3448: 'csv' => "Current Session Value",
3449: 'rl' => "Resource Level",
3450: 'ic' => 'in Course',
3451: 'aut' => "Assessment URL and Title",
3452: 'type' => 'Type',
3453: 'emof' => "Enclosing Map or Folder",
3454: 'part' => 'Part',
3455: 'pn' => 'Parameter Name',
3456: 'def' => 'default',
3457: 'femof' => 'from Enclosing Map or Folder',
3458: 'gen' => 'general',
3459: 'foremf' => 'for Enclosing Map or Folder',
3460: 'fr' => 'for Resource'
3461: );
3462: $r->print(<<ENDTABLETWO);
3463: <th rowspan="3">$lt{'pie'}</th>
3464: <th rowspan="3">$lt{'csv'}<br />($csuname:$csudom)</th>
3465: </tr><tr><td colspan="5"></td><th colspan="2">$lt{'ic'}</th><th colspan="2">$lt{'rl'}</th>
3466: <th colspan="1">$lt{'ic'}</th>
3467:
3468: ENDTABLETWO
3469: if ($csec) {
3470: $r->print('<th colspan="3">'.
3471: &mt("in Section")." $csec</th>");
3472: }
3473: if ($cgroup) {
3474: $r->print('<th colspan="3">'.
3475: &mt("in Group")." $cgroup</th>");
3476: }
3477: $r->print(<<ENDTABLEHEADFOUR);
3478: </tr><tr><th>$lt{'aut'}</th><th>$lt{'type'}</th>
3479: <th>$lt{'emof'}</th><th>$lt{'part'}</th><th>$lt{'pn'}</th>
3480: <th>$lt{'gen'}</th><th>$lt{'foremf'}</th>
3481: <th>$lt{'def'}</th><th>$lt{'femof'}</th><th>$lt{'fr'}</th>
3482: ENDTABLEHEADFOUR
3483:
3484: if ($csec) {
3485: $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
3486: }
3487:
3488: if ($cgroup) {
3489: $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
3490: }
3491:
3492: if ($uname) {
3493: if (@usersgroups > 1) {
3494: $r->print('<th>'.&mt('Control by other group?').'</th>');
3495: }
3496: $r->print('<th>'.$lt{'gen'}.'</th><th>'.$lt{'foremf'}.'</th><th>'.$lt{'fr'}.'</th>');
3497: }
3498:
3499: $r->print('</tr>');
3500: #
3501: # Done with the headers
3502: #
3503: my $defbgone='';
3504: my $defbgtwo='';
3505: my $defbgthree = '';
3506:
3507: foreach my $rid (@ids) {
3508:
3509: my ($inmapid)=($rid=~/\.(\d+)$/);
3510: if ((!$pssymb &&
3511: (($pschp eq 'all') || ($allmaps{$pschp} eq $mapp{$rid})))
3512: ||
3513: ($pssymb && $pssymb eq $symbp{$rid})) {
3514: # ------------------------------------------------------ Entry for one resource
3515: if ($defbgone eq '#E0E099') {
3516: $defbgone='#E0E0DD';
3517: } else {
3518: $defbgone='#E0E099';
3519: }
3520: if ($defbgtwo eq '#FFFF99') {
3521: $defbgtwo='#FFFFDD';
3522: } else {
3523: $defbgtwo='#FFFF99';
3524: }
3525: if ($defbgthree eq '#FFBB99') {
3526: $defbgthree='#FFBBDD';
3527: } else {
3528: $defbgthree='#FFBB99';
3529: }
3530:
3531: my $thistitle='';
3532: my %name= ();
3533: undef %name;
3534: my %part= ();
3535: my %display=();
3536: my %type= ();
3537: my %default=();
3538: my $uri=&Apache::lonnet::declutter($uris{$rid});
3539: my $toolsymb;
3540: if ($uri =~ /ext\.tool$/) {
3541: $toolsymb = $symbp{$rid};
3542: }
3543:
3544: my $filter=$env{'form.filter'};
3545: foreach my $tempkeyp (&keysplit($keyp{$rid})) {
3546: if (grep $_ eq $tempkeyp, @catmarker) {
3547: my $parmname=&Apache::lonnet::metadata($uri,$tempkeyp.'.name',$toolsymb);
3548: # We may only want certain parameters listed
3549: if ($filter) {
3550: unless ($filter=~/\Q$parmname\E/) { next; }
3551: }
3552: $name{$tempkeyp}=$parmname;
3553: $part{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp.'.part',$toolsymb);
3554:
3555: my $parmdis=&Apache::lonnet::metadata($uri,$tempkeyp.'.display',$toolsymb);
3556: if ($allparms{$name{$tempkeyp}} ne '') {
3557: my $identifier;
3558: if ($parmdis =~ /(\s*\[Part.*)$/) {
3559: $identifier = $1;
3560: }
3561: $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
3562: } else {
3563: $display{$tempkeyp} = $parmdis;
3564: }
3565: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
3566: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
3567: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp,$toolsymb);
3568: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$tempkeyp.'.type',$toolsymb);
3569: $thistitle=&Apache::lonnet::metadata($uri,$tempkeyp.'.title',$toolsymb);
3570: }
3571: }
3572: my $totalparms=scalar(keys(%name));
3573: if ($totalparms>0) {
3574: my $firstrow=1;
3575: my $title=&Apache::lonnet::gettitle($symbp{$rid});
3576: my $navmap = Apache::lonnavmaps::navmap->new();
3577: my @recurseup;
3578: if (ref($navmap) && $mapp{$rid}) {
3579: @recurseup = $navmap->recurseup_maps($mapp{$rid});
3580: }
3581: $r->print('<tr><td style="background-color:'.$defbgone.';"'.
3582: ' rowspan='.$totalparms.
3583: '><tt><font size="-1">'.
3584: join(' / ',split(/\//,$uri)).
3585: '</font></tt><p><b>'.
3586: "<a href=\"javascript:openWindow('".
3587: &Apache::lonnet::clutter($uri).'?symb='.
3588: &escape($symbp{$rid}).
3589: "', 'metadatafile', '450', '500', 'no', 'yes');\"".
3590: " target=\"_self\">$title");
3591:
3592: if ($thistitle) {
3593: $r->print(' ('.$thistitle.')');
3594: }
3595: $r->print('</a></b></td>');
3596: $r->print('<td style="background-color:'.$defbgtwo.';"'.
3597: ' rowspan='.$totalparms.'>'.$typep{$rid}.
3598: '</td>');
3599:
3600: $r->print('<td style="background-color:'.$defbgone.';"'.
3601: ' rowspan='.$totalparms.
3602: '>'.$maptitles{$mapp{$rid}}.'</td>');
3603: foreach my $item (&keysinorder_bytype(\%name,\%keyorder)) {
3604: unless ($firstrow) {
3605: $r->print('<tr>');
3606: } else {
3607: undef $firstrow;
3608: }
3609: &print_row($r,$item,\%part,\%name,\%symbp,$rid,\%default,
3610: \%type,\%display,$defbgone,$defbgtwo,
3611: $defbgthree,$parmlev,$uname,$udom,$csec,
3612: $cgroup,\@usersgroups,$noeditgrp,$readonly,
3613: \@recurseup,\%maptitles,\%allmaps_inverted,
3614: \$numreclinks);
3615: }
3616: }
3617: }
3618: } # end foreach ids
3619: # -------------------------------------------------- End entry for one resource
3620: $r->print(&Apache::loncommon::end_data_table);
3621: } # end of full
3622: #--------------------------------------------------- Entry for parm level map
3623: if ($parmlev eq 'map') {
3624: my $defbgone = '#E0E099';
3625: my $defbgtwo = '#FFFF99';
3626: my $defbgthree = '#FFBB99';
3627:
3628: my %maplist;
3629:
3630: if ($pschp eq 'all') {
3631: %maplist = %allmaps;
3632: } else {
3633: %maplist = ($pschp => $mapp{$pschp});
3634: }
3635:
3636: #-------------------------------------------- for each map, gather information
3637: my $mapid;
3638: foreach $mapid (sort {$maplist{$a} cmp $maplist{$b}} keys(%maplist)) {
3639: my $maptitle = $maplist{$mapid};
3640:
3641: #----------------------- loop through ids and get all parameter types for map
3642: #----------------------------------------- and associated information
3643: my %name = ();
3644: my %part = ();
3645: my %display = ();
3646: my %type = ();
3647: my %default = ();
3648: my $map = 0;
3649:
3650: # $r->print("Catmarker: @catmarker<br />\n");
3651:
3652: foreach my $id (@ids) {
3653: ($map)=($id =~ /([\d]*?)\./);
3654: my $rid = $id;
3655:
3656: # $r->print("$mapid:$map: $rid <br /> \n");
3657:
3658: if ($map eq $mapid) {
3659: my $uri=&Apache::lonnet::declutter($uris{$rid});
3660: my $toolsymb;
3661: if ($uri =~ /ext\.tool$/) {
3662: $toolsymb = $symbp{$rid};
3663: }
3664:
3665: # $r->print("Keys: $keyp{$rid} <br />\n");
3666:
3667: #--------------------------------------------------------------------
3668: # @catmarker contains list of all possible parameters including part #s
3669: # $fullkeyp contains the full part/id # for the extraction of proper parameters
3670: # $tempkeyp contains part 0 only (no ids - ie, subparts)
3671: # When storing information, store as part 0
3672: # When requesting information, request from full part
3673: #-------------------------------------------------------------------
3674: foreach my $fullkeyp (&keysplit($keyp{$rid})) {
3675: my $tempkeyp = $fullkeyp;
3676: $tempkeyp =~ s/_\w+_/_0_/;
3677:
3678: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
3679: $part{$tempkeyp}="0";
3680: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name',$toolsymb);
3681: my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display',$toolsymb);
3682: if ($allparms{$name{$tempkeyp}} ne '') {
3683: my $identifier;
3684: if ($parmdis =~ /(\s*\[Part.*)$/) {
3685: $identifier = $1;
3686: }
3687: $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
3688: } else {
3689: $display{$tempkeyp} = $parmdis;
3690: }
3691: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
3692: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
3693: $display{$tempkeyp} =~ s/_\w+_/_0_/;
3694: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp,$toolsymb);
3695: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type',$toolsymb);
3696: }
3697: } # end loop through keys
3698: }
3699: } # end loop through ids
3700:
3701: #---------------------------------------------------- print header information
3702: my $foldermap=&mt($maptitle=~/^uploaded/?'Folder':'Map');
3703: my $showtitle=$maptitles{$maptitle}.($maptitle!~/^uploaded/?' ['.$maptitle.']':'');
3704: my $tmp="";
3705: if ($uname) {
3706: my $person=&Apache::loncommon::plainname($uname,$udom);
3707: $tmp.=&mt("User")." <font color=\"red\"><i>$uname \($person\) </i></font> ".
3708: &mt('in')." \n";
3709: } else {
3710: $tmp.="<font color=\"red\"><i>".&mt('all').'</i></font> '.&mt('users in')." \n";
3711: }
3712: if ($cgroup) {
3713: $tmp.=&mt("Group")." <font color=\"red\"><i>$cgroup".
3714: "</i></font> ".&mt('of')." \n";
3715: $csec = '';
3716: } elsif ($csec) {
3717: $tmp.=&mt("Section")." <font color=\"red\"><i>$csec".
3718: "</i></font> ".&mt('of')." \n";
3719: }
3720: $r->print('<div align="center"><h4>'
3721: .&mt('Set Defaults for All Resources in [_1]Specifically for [_2][_3]'
3722: ,$foldermap.'<br /><font color="red"><i>'.$showtitle.'</i></font><br />'
3723: ,$tmp
3724: ,'<font color="red"><i>'.$coursename.'</i></font>'
3725: )
3726: ."<br /></h4>\n"
3727: );
3728: #---------------------------------------------------------------- print table
3729: $r->print('<p>'.&Apache::loncommon::start_data_table()
3730: .&Apache::loncommon::start_data_table_header_row()
3731: .'<th>'.&mt('Parameter Name').'</th>'
3732: .'<th>'.&mt('Value').'</th>'
3733: .'<th>'.&mt('Parameter in Effect').'</th>'
3734: .&Apache::loncommon::end_data_table_header_row()
3735: );
3736:
3737: my $navmap = Apache::lonnavmaps::navmap->new();
3738: my @recurseup;
3739: if (ref($navmap)) {
3740: my $mapres = $navmap->getByMapPc($mapid);
3741: if (ref($mapres)) {
3742: @recurseup = $navmap->recurseup_maps($mapres->src());
3743: }
3744: }
3745:
3746:
3747: foreach my $item (&keysinorder(\%name,\%keyorder)) {
3748: $r->print(&Apache::loncommon::start_data_table_row());
3749: &print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default,
3750: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
3751: $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp,
3752: $readonly,\@recurseup,\%maptitles,\%allmaps_inverted,
3753: \$numreclinks);
3754: }
3755: $r->print(&Apache::loncommon::end_data_table().'</p>'
3756: .'</div>'
3757: );
3758: } # end each map
3759: } # end of $parmlev eq map
3760: #--------------------------------- Entry for parm level general (Course level)
3761: if ($parmlev eq 'general') {
3762: my $defbgone = '#E0E099';
3763: my $defbgtwo = '#FFFF99';
3764: my $defbgthree = '#FFBB99';
3765:
3766: #-------------------------------------------- for each map, gather information
3767: my $mapid="0.0";
3768: #----------------------- loop through ids and get all parameter types for map
3769: #----------------------------------------- and associated information
3770: my %name = ();
3771: my %part = ();
3772: my %display = ();
3773: my %type = ();
3774: my %default = ();
3775:
3776: foreach $id (@ids) {
3777: my $rid = $id;
3778:
3779: my $uri=&Apache::lonnet::declutter($uris{$rid});
3780: my $toolsymb;
3781: if ($uri =~ /ext\.tool$/) {
3782: $toolsymb = $symbp{$rid};
3783: }
3784:
3785: #--------------------------------------------------------------------
3786: # @catmarker contains list of all possible parameters including part #s
3787: # $fullkeyp contains the full part/id # for the extraction of proper parameters
3788: # $tempkeyp contains part 0 only (no ids - ie, subparts)
3789: # When storing information, store as part 0
3790: # When requesting information, request from full part
3791: #-------------------------------------------------------------------
3792: foreach my $fullkeyp (&keysplit($keyp{$rid})) {
3793: my $tempkeyp = $fullkeyp;
3794: $tempkeyp =~ s/_\w+_/_0_/;
3795: if ((grep $_ eq $fullkeyp, @catmarker) &&(!$name{$tempkeyp})) {
3796: $part{$tempkeyp}="0";
3797: $name{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.name',$toolsymb);
3798: my $parmdis=&Apache::lonnet::metadata($uri,$fullkeyp.'.display',$toolsymb);
3799: if ($allparms{$name{$tempkeyp}} ne '') {
3800: my $identifier;
3801: if ($parmdis =~ /(\s*\[Part.*)$/) {
3802: $identifier = $1;
3803: }
3804: $display{$tempkeyp} = $allparms{$name{$tempkeyp}}.$identifier;
3805: } else {
3806: $display{$tempkeyp} = $parmdis;
3807: }
3808: unless ($display{$tempkeyp}) { $display{$tempkeyp}=''; }
3809: $display{$tempkeyp}.=' ('.$name{$tempkeyp}.')';
3810: $display{$tempkeyp} =~ s/_\w+_/_0_/;
3811: $default{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp,$toolsymb);
3812: $type{$tempkeyp}=&Apache::lonnet::metadata($uri,$fullkeyp.'.type',$toolsymb);
3813: }
3814: } # end loop through keys
3815: } # end loop through ids
3816:
3817: #---------------------------------------------------- print header information
3818: my $setdef=&mt("Set Defaults for All Resources in Course");
3819: $r->print(<<ENDMAPONE);
3820: <center>
3821: <h4>$setdef
3822: <font color="red"><i>$coursename</i></font><br />
3823: ENDMAPONE
3824: if ($uname) {
3825: my $person=&Apache::loncommon::plainname($uname,$udom);
3826: $r->print(" ".&mt("User")."<font color=\"red\"> <i>$uname \($person\) </i></font> \n");
3827: } else {
3828: $r->print("<i><font color=\"red\"> ".&mt("ALL")."</i> ".&mt("USERS")."</font> \n");
3829: }
3830:
3831: if ($csec) {$r->print(&mt("Section")."<font color=\"red\"> <i>$csec</i></font>\n")};
3832: if ($cgroup) {$r->print(&mt("Group")."<font color=\"red\"> <i>$cgroup</i></font>\n")};
3833: $r->print("</h4>\n");
3834: #---------------------------------------------------------------- print table
3835: $r->print('<p>'.&Apache::loncommon::start_data_table()
3836: .&Apache::loncommon::start_data_table_header_row()
3837: .'<th>'.&mt('Parameter Name').'</th>'
3838: .'<th>'.&mt('Default Value').'</th>'
3839: .'<th>'.&mt('Parameter in Effect').'</th>'
3840: .&Apache::loncommon::end_data_table_header_row()
3841: );
3842:
3843: foreach my $item (&keysinorder(\%name,\%keyorder)) {
3844: $r->print(&Apache::loncommon::start_data_table_row());
3845: &print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default,
3846: \%type,\%display,$defbgone,$defbgtwo,$defbgthree,
3847: $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp,
3848: $readonly);
3849: }
3850: $r->print(&Apache::loncommon::end_data_table()
3851: .'</p>'
3852: .'</center>'
3853: );
3854: } # end of $parmlev eq general
3855: }
3856: $r->print('</form>');
3857: if ($numreclinks) {
3858: $r->print(<<"END");
3859: <form name="recurseform" action="/adm/parmset?action=settable" method="post">
3860: <input type="hidden" name="pschp" />
3861: <input type="hidden" name="pscat" />
3862: <input type="hidden" name="psprt" />
3863: <input type="hidden" name="hideparmsel" value="hidden" />
3864: </form>
3865: <script type="text/javascript">
3866: function pjumprec(rid,name,part) {
3867: document.forms.recurseform.pschp.value = rid;
3868: document.forms.recurseform.pscat.value = name;
3869: document.forms.recurseform.psprt.value = part;
3870: document.forms.recurseform.submit();
3871: return false;
3872: }
3873: </script>
3874: END
3875: }
3876: &endSettingsScreen($r);
3877: $r->print(&Apache::loncommon::end_page());
3878: } # end sub assessparms
3879:
3880:
3881:
3882: ##################################################
3883: # OVERVIEW MODE
3884: ##################################################
3885:
3886: my $tableopen; # boolean, true if HTML table is already opened
3887:
3888: # Returns HTML with the HTML table start tag and header, unless the table is already opened.
3889: # @param {boolean} $readonly - true if values cannot be edited (otherwise more columns are added)
3890: # @returns {string}
3891: sub tablestart {
3892: my ($readonly,$is_map) = @_;
3893: if ($tableopen) {
3894: return '';
3895: } else {
3896: $tableopen=1;
3897: my $output = &Apache::loncommon::start_data_table().'<tr><th>'.&mt('Parameter').'</th>';
3898: if ($readonly) {
3899: $output .= '<th>'.&mt('Current value').'</th>';
3900: } else {
3901: $output .= '<th>'.&mt('Delete').'</th>'.
3902: '<th>'.&mt('Set to ...').'</th>';
3903: if ($is_map) {
3904: $output .= '<th>'.&mt('Recursive?').'</th>';
3905: }
3906: }
3907: $output .= '</tr>';
3908: return $output;
3909: }
3910: }
3911:
3912: # Returns HTML with the HTML table end tag, unless the table is not opened.
3913: # @returns {string}
3914: sub tableend {
3915: if ($tableopen) {
3916: $tableopen=0;
3917: return &Apache::loncommon::end_data_table();
3918: } else {
3919: return'';
3920: }
3921: }
3922:
3923: # Reads course and user information.
3924: # If the context is looking for a scalar, returns the course parameters hash (result of lonnet::get_courseresdata, dump of course's resourcedata.db) with added student data from lonnet::get_userresdata (which reads the user's resourcedata.db).
3925: # The key for student data is modified with '[useropt:'.username.':'.userdomain.'].'.
3926: # If the context is looking for a list, returns a list with the scalar data and the class list.
3927: # @param {string} $crs - course number
3928: # @param {string} $dom - course domain
3929: # @returns {hash reference|Array}
3930: sub readdata {
3931: my ($crs,$dom)=@_;
3932: # Read coursedata
3933: my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
3934: # Read userdata
3935:
3936: my $classlist=&Apache::loncoursedata::get_classlist();
3937: foreach my $user (keys(%$classlist)) {
3938: if ($user=~/^($match_username)\:($match_domain)$/) {
3939: my ($tuname,$tudom)=($1,$2);
3940: my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
3941: foreach my $userkey (keys(%{$useropt})) {
3942: if ($userkey=~/^\Q$env{'request.course.id'}\E/) {
3943: my $newkey=$userkey;
3944: $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
3945: $$resourcedata{$newkey}=$$useropt{$userkey};
3946: }
3947: }
3948: }
3949: }
3950: if (wantarray) {
3951: return ($resourcedata,$classlist);
3952: } else {
3953: return $resourcedata;
3954: }
3955: }
3956:
3957:
3958: # Stores parameter data, using form parameters directly.
3959: #
3960: # Uses the following form parameters. The variable part in the names is a resourcedata key (except for a modification for user data).
3961: # set_* (except settext, setipallow, setipdeny, setdeeplink) - set a parameter value
3962: # del_* - remove a parameter
3963: # datepointer_* - set a date parameter (value is key_* refering to a set of other form parameters)
3964: # dateinterval_* - set a date interval parameter (value refers to more form parameters)
3965: # key_* - date values
3966: # days_* - for date intervals
3967: # hours_* - for date intervals
3968: # minutes_* - for date intervals
3969: # seconds_* - for date intervals
3970: # done_* - for date intervals
3971: # typeof_* - parameter type
3972: #
3973: # @param {Apache2::RequestRec} $r - the Apache request
3974: # @param {string} $crs - course number
3975: # @param {string} $dom - course domain
3976: sub storedata {
3977: my ($r,$crs,$dom)=@_;
3978: # Set userlevel immediately
3979: # Do an intermediate store of course level
3980: my $olddata=&readdata($crs,$dom);
3981: my %newdata=();
3982: undef %newdata;
3983: my @deldata=();
3984: my @delrec=();
3985: my @delnonrec=();
3986: undef @deldata;
3987: my ($got_chostname,$chostname,$cmajor,$cminor);
3988: my $now = time;
3989: foreach my $key (keys(%env)) {
3990: if ($key =~ /^form\.([a-z]+)\_(.+)$/) {
3991: my $cmd=$1;
3992: my $thiskey=$2;
3993: my ($altkey,$recursive,$tkey,$tkeyrec,$tkeynonrec);
3994: next if ($cmd eq 'rec' || $cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny' || $cmd eq 'setdeeplink');
3995: if ((($cmd eq 'set') || ($cmd eq 'datepointer') || ($cmd eq 'dateinterval') || ($cmd eq 'del')) &&
3996: ($thiskey =~ /(?:sequence|page)\Q___(all)\E/)) {
3997: unless ($thiskey =~ /(encrypturl|hiddenresource)$/) {
3998: $altkey = $thiskey;
3999: $altkey =~ s/\Q___(all)\E/___(rec)/;
4000: if ($env{'form.rec_'.$thiskey}) {
4001: $recursive = 1;
4002: }
4003: }
4004: }
4005: my ($tuname,$tudom)=&extractuser($thiskey);
4006: if ($tuname) {
4007: $tkey=$thiskey;
4008: $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
4009: if ($altkey) {
4010: $tkeynonrec = $tkey;
4011: $tkeyrec = $altkey;
4012: $tkeyrec=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
4013: }
4014: }
4015: if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
4016: my ($data, $typeof, $text, $name, $valchk, $valmatch, $namematch);
4017: if ($cmd eq 'set') {
4018: $data=$env{$key};
4019: $valmatch = '';
4020: $valchk = $data;
4021: $typeof=$env{'form.typeof_'.$thiskey};
4022: $text = &mt('Saved modified parameter for');
4023: if ($typeof eq 'string_questiontype') {
4024: $name = 'type';
4025: } elsif (($typeof eq 'string_lenient') || ($typeof eq 'string_deeplink')) {
4026: ($name) = ($typeof =~ /^string_(lenient|deeplink)$/);
4027: my $stringmatch = &standard_string_matches($typeof);
4028: if (ref($stringmatch) eq 'ARRAY') {
4029: foreach my $item (@{$stringmatch}) {
4030: if (ref($item) eq 'ARRAY') {
4031: my ($regexpname,$pattern) = @{$item};
4032: if ($pattern ne '') {
4033: if ($data =~ /$pattern/) {
4034: $valmatch = $regexpname;
4035: $valchk = '';
4036: last;
4037: }
4038: }
4039: }
4040: }
4041: }
4042: } elsif ($typeof eq 'string_discussvote') {
4043: $name = 'discussvote';
4044: } elsif ($typeof eq 'string_examcode') {
4045: $name = 'examcode';
4046: if (&Apache::lonnet::validCODE($data)) {
4047: $valchk = 'valid';
4048: }
4049: } elsif ($typeof eq 'string_yesno') {
4050: if ($thiskey =~ /\.retrypartial$/) {
4051: $name = 'retrypartial';
4052: }
4053: }
4054: } elsif ($cmd eq 'datepointer') {
4055: $data=&Apache::lonhtmlcommon::get_date_from_form($env{$key});
4056: $typeof=$env{'form.typeof_'.$thiskey};
4057: $text = &mt('Saved modified date for');
4058: if ($typeof eq 'date_start') {
4059: if ($thiskey =~ /\.printstartdate$/) {
4060: $name = 'printstartdate';
4061: if (($data) && ($data > $now)) {
4062: $valchk = 'future';
4063: }
4064: }
4065: } elsif ($typeof eq 'date_end') {
4066: if ($thiskey =~ /\.printenddate$/) {
4067: $name = 'printenddate';
4068: if (($data) && ($data < $now)) {
4069: $valchk = 'past';
4070: }
4071: }
4072: }
4073: } elsif ($cmd eq 'dateinterval') {
4074: $data=&get_date_interval_from_form($thiskey);
4075: if ($thiskey =~ /\.interval$/) {
4076: $name = 'interval';
4077: my $intervaltype = &get_intervaltype($name);
4078: my $intervalmatch = &standard_interval_matches($intervaltype);
4079: if (ref($intervalmatch) eq 'ARRAY') {
4080: foreach my $item (@{$intervalmatch}) {
4081: if (ref($item) eq 'ARRAY') {
4082: my ($regexpname,$pattern) = @{$item};
4083: if ($pattern ne '') {
4084: if ($data =~ /$pattern/) {
4085: $valmatch = $regexpname;
4086: $valchk = '';
4087: last;
4088: }
4089: }
4090: }
4091: }
4092: }
4093: }
4094: $typeof=$env{'form.typeof_'.$thiskey};
4095: $text = &mt('Saved modified date for');
4096: }
4097: if ($recursive) {
4098: $namematch = 'maplevelrecurse';
4099: }
4100: if (($name ne '') || ($namematch ne '')) {
4101: my ($needsrelease,$needsnewer);
4102: if ($name ne '') {
4103: $needsrelease = $Apache::lonnet::needsrelease{"parameter:$name:$valchk:$valmatch:"};
4104: if ($needsrelease) {
4105: unless ($got_chostname) {
4106: ($chostname,$cmajor,$cminor)=¶meter_release_vars();
4107: $got_chostname = 1;
4108: }
4109: $needsnewer = ¶meter_releasecheck($name,$valchk,$valmatch,undef,
4110: $needsrelease,
4111: $cmajor,$cminor);
4112: }
4113: }
4114: if ($namematch ne '') {
4115: if ($needsnewer) {
4116: undef($namematch);
4117: } else {
4118: my $currneeded;
4119: if ($needsrelease) {
4120: $currneeded = $needsrelease;
4121: }
4122: $needsrelease =
4123: $Apache::lonnet::needsrelease{"parameter::::$namematch"};
4124: if (($needsrelease) &&
4125: (($currneeded eq '') || ($needsrelease < $currneeded))) {
4126: unless ($got_chostname) {
4127: ($chostname,$cmajor,$cminor) = ¶meter_release_vars();
4128: $got_chostname = 1;
4129: }
4130: $needsnewer = ¶meter_releasecheck(undef,$valchk,$valmatch,
4131: $namematch, $needsrelease,$cmajor,$cminor);
4132: } else {
4133: undef($namematch);
4134: }
4135: }
4136: }
4137: if ($needsnewer) {
4138: $r->print('<br />'.&oldversion_warning($name,$namematch,$data,
4139: $chostname,$cmajor,
4140: $cminor,$needsrelease));
4141: next;
4142: }
4143: }
4144: my ($reconlychg,$haschange,$storekey);
4145: if ($tuname) {
4146: my $ustorekey;
4147: if ($altkey) {
4148: if ($recursive) {
4149: if (exists($$olddata{$thiskey})) {
4150: if ($$olddata{$thiskey} eq $data) {
4151: $reconlychg = 1;
4152: }
4153: &Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname);
4154: }
4155: if (exists($$olddata{$altkey})) {
4156: if (defined($data) && $$olddata{$altkey} ne $data) {
4157: $haschange = 1;
4158: }
4159: } elsif ((!$reconlychg) && ($data ne '')) {
4160: $haschange = 1;
4161: }
4162: $ustorekey = $tkeyrec;
4163: } else {
4164: if (exists($$olddata{$altkey})) {
4165: if ($$olddata{$altkey} eq $data) {
4166: $reconlychg = 1;
4167: }
4168: &Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname);
4169: }
4170: if (exists($$olddata{$thiskey})) {
4171: if (defined($data) && $$olddata{$thiskey} ne $data) {
4172: $haschange = 1;
4173: }
4174: } elsif ((!$reconlychg) && ($data ne '')) {
4175: $haschange = 1;
4176: }
4177: $ustorekey = $tkeynonrec;
4178: }
4179: } else {
4180: if (exists($$olddata{$tkey})) {
4181: if (defined($data) && $$olddata{$tkey} ne $data) {
4182: $haschange = 1;
4183: }
4184: $ustorekey = $tkey;
4185: }
4186: }
4187: if ($haschange || $reconlychg) {
4188: unless ($env{'form.del_'.$thiskey}) {
4189: if (&Apache::lonnet::put('resourcedata',{$ustorekey=>$data,
4190: $ustorekey.'.type' => $typeof},
4191: $tudom,$tuname) eq 'ok') {
4192: &log_parmset({$ustorekey=>$data,$ustorekey.'.type' => $typeof},0,$tuname,$tudom);
4193: $r->print('<br />'.$text.' '.
4194: &Apache::loncommon::plainname($tuname,$tudom));
4195: } else {
4196: $r->print('<div class="LC_error">'.
4197: &mt('Error saving parameters').'</div>');
4198: }
4199: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
4200: }
4201: }
4202: } else {
4203: if ($altkey) {
4204: if ($recursive) {
4205: if (exists($$olddata{$thiskey})) {
4206: if ($$olddata{$thiskey} eq $data) {
4207: $reconlychg = 1;
4208: }
4209: push(@delnonrec,($thiskey,$thiskey.'.type'));
4210: }
4211: if (exists($$olddata{$altkey})) {
4212: if (defined($data) && $$olddata{$altkey} ne $data) {
4213: $haschange = 1;
4214: }
4215: } elsif (($data ne '') && (!$reconlychg)) {
4216: $haschange = 1;
4217: }
4218: $storekey = $altkey;
4219: } else {
4220: if (exists($$olddata{$altkey})) {
4221: if ($$olddata{$altkey} eq $data) {
4222: $reconlychg = 1;
4223: }
4224: push(@delrec,($altkey,$altkey.'.type'));
4225: }
4226: if (exists($$olddata{$thiskey})) {
4227: if (defined($data) && $$olddata{$thiskey} ne $data) {
4228: $haschange = 1;
4229: }
4230: } elsif (($data ne '') && (!$reconlychg)) {
4231: $haschange = 1;
4232: }
4233: $storekey = $thiskey;
4234: }
4235: } else {
4236: if (defined($data) && $$olddata{$thiskey} ne $data) {
4237: $haschange = 1;
4238: $storekey = $thiskey;
4239: }
4240: }
4241: }
4242: if ($reconlychg || $haschange) {
4243: unless ($env{'form.del_'.$thiskey}) {
4244: $newdata{$storekey}=$data;
4245: $newdata{$storekey.'.type'}=$typeof;
4246: }
4247: }
4248: } elsif ($cmd eq 'del') {
4249: if ($tuname) {
4250: my $error;
4251: if ($altkey) {
4252: if (exists($$olddata{$altkey})) {
4253: if (&Apache::lonnet::del('resourcedata',[$tkeyrec,$tkeyrec.'.type'],$tudom,$tuname) eq 'ok') {
4254: &log_parmset({$tkeyrec=>''},1,$tuname,$tudom);
4255: if ($recursive) {
4256: $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
4257: }
4258: } elsif ($recursive) {
4259: $error = 1;
4260: }
4261: }
4262: if (exists($$olddata{$thiskey})) {
4263: if (&Apache::lonnet::del('resourcedata',[$tkeynonrec,$tkeynonrec.'.type'],$tudom,$tuname) eq 'ok') {
4264: &log_parmset({$tkeynonrec=>''},1,$tuname,$tudom);
4265: unless ($recursive) {
4266: $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
4267: }
4268: } elsif (!$recursive) {
4269: $error = 1;
4270: }
4271: }
4272: } else {
4273: if (exists($$olddata{$thiskey})) {
4274: if (&Apache::lonnet::del('resourcedata',[$tkey,$tkey.'.type'],$tudom,$tuname) eq 'ok') {
4275: &log_parmset({$tkey=>''},1,$tuname,$tudom);
4276: $r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
4277: } else {
4278: $error = 1;
4279: }
4280: }
4281: }
4282: if ($error) {
4283: $r->print('<div class="LC_error">'.
4284: &mt('Error deleting parameters').'</div>');
4285: }
4286: &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
4287: } else {
4288: if ($altkey) {
4289: if (exists($$olddata{$altkey})) {
4290: unless (grep(/^\Q$altkey\E$/,@delrec)) {
4291: push(@deldata,($altkey,$altkey.'.type'));
4292: }
4293: }
4294: if (exists($$olddata{$thiskey})) {
4295: unless (grep(/^\Q$thiskey\E$/,@delnonrec)) {
4296: push(@deldata,($thiskey,$thiskey.'.type'));
4297: }
4298: }
4299: } elsif (exists($$olddata{$thiskey})) {
4300: push(@deldata,($thiskey,$thiskey.'.type'));
4301: }
4302: }
4303: }
4304: }
4305: }
4306: # Store all course level
4307: my $delentries=$#deldata+1;
4308: my @alldels;
4309: if (@delrec) {
4310: push(@alldels,@delrec);
4311: }
4312: if (@delnonrec) {
4313: push(@alldels,@delnonrec);
4314: }
4315: if (@deldata) {
4316: push(@alldels,@deldata);
4317: }
4318: my @newdatakeys=keys(%newdata);
4319: my $putentries=$#newdatakeys+1;
4320: my ($delresult,$devalidate);
4321: if (@alldels) {
4322: if (&Apache::lonnet::del('resourcedata',\@alldels,$dom,$crs) eq 'ok') {
4323: my %loghash=map { $_ => '' } @alldels;
4324: &log_parmset(\%loghash,1);
4325: if ($delentries) {
4326: $r->print('<h2>'.&mt('Deleted [quant,_1,parameter]',$delentries/2).'</h2>');
4327: }
4328: } elsif ($delentries) {
4329: $r->print('<div class="LC_error">'.
4330: &mt('Error deleting parameters').'</div>');
4331: }
4332: $devalidate = 1;
4333: }
4334: if ($putentries) {
4335: if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
4336: &log_parmset(\%newdata,0);
4337: $r->print('<h3>'.&mt('Saved [quant,_1,parameter]',$putentries/2).'</h3>');
4338: } else {
4339: $r->print('<div class="LC_error">'.
4340: &mt('Error saving parameters').'</div>');
4341: }
4342: $devalidate = 1;
4343: }
4344: if ($devalidate) {
4345: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
4346: }
4347: }
4348:
4349: # Returns the username and domain from a key created in readdata from a resourcedata key.
4350: #
4351: # @param {string} $key - the key
4352: # @returns {Array}
4353: sub extractuser {
4354: my $key=shift;
4355: return ($key=~/^$env{'request.course.id'}.\[useropt\:($match_username)\:($match_domain)\]\./);
4356: }
4357:
4358: # Parses a parameter key and returns the components.
4359: #
4360: # @param {string} $key -
4361: # @param {hash reference} $listdata -
4362: # @return {Array} - (student, resource, part, parameter)
4363: sub parse_listdata_key {
4364: my ($key,$listdata) = @_;
4365: # split into student/section affected, and
4366: # the realm (folder/resource part and parameter
4367: my ($student,$realm) =
4368: ($key=~/^\Q$env{'request.course.id'}\E\.\[([^\.]+)\]\.(.+)$/);
4369: # if course wide student would be undefined
4370: if (!defined($student)) {
4371: ($realm)=($key=~/^\Q$env{'request.course.id'}\E\.(.+)$/);
4372: }
4373: # strip off the .type if it's not the Question type parameter
4374: if ($realm=~/\.type$/ && !exists($listdata->{$key.'.type'})) {
4375: $realm=~s/\.type//;
4376: }
4377: # split into resource+part and parameter name
4378: my ($res, $parm) = ($realm=~/^(.*)\.(.*)$/);
4379: ($res, my $part) = ($res =~/^(.*)\.(.*)$/);
4380: return ($student,$res,$part,$parm);
4381: }
4382:
4383: # Prints HTML with forms for the given parameter data in overview mode (newoverview or overview).
4384: #
4385: # @param {Apache2::RequestRec} $r - the Apache request
4386: # @param {hash reference} $resourcedata - parameter data returned by readdata
4387: # @param {hash reference} $listdata - data created in secgroup_lister, course id.[section id].part.name -> 1 or course id.[section id].part.name.type -> parameter type
4388: # @param {string} $sortorder - realmstudent|studentrealm
4389: # @param {string} $caller - name of the calling sub (overview|newoverview)
4390: # @param {hash reference} $classlist - from loncoursedata::get_classlist
4391: # @param {boolean} $readonly - true if editing not allowed
4392: # @returns{integer} - number of $listdata parameters processed
4393: sub listdata {
4394: my ($r,$resourcedata,$listdata,$sortorder,$caller,$classlist,$readonly)=@_;
4395:
4396: # Start list output
4397:
4398: my $oldsection='';
4399: my $oldrealm='';
4400: my $oldpart='';
4401: my $pointer=0;
4402: $tableopen=0;
4403: my $foundkeys=0;
4404: my %keyorder=&standardkeyorder();
4405: my $readonlyall = $readonly;
4406:
4407: my ($secidx,%grouphash);
4408: if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
4409: $secidx = &Apache::loncoursedata::CL_SECTION();
4410: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
4411: %grouphash = &Apache::longroup::coursegroups();
4412: } elsif ($env{'request.course.groups'} ne '') {
4413: map { $grouphash{$_} = 1; } split(/:/,$env{'request.course.groups'});
4414: }
4415: }
4416:
4417: foreach my $key (sort {
4418: my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata);
4419: my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata);
4420:
4421: # get the numerical order for the param
4422: $aparm=$keyorder{'parameter_0_'.$aparm};
4423: $bparm=$keyorder{'parameter_0_'.$bparm};
4424:
4425: my $result=0;
4426:
4427: if ($sortorder eq 'realmstudent') {
4428: if ($ares ne $bres ) {
4429: $result = ($ares cmp $bres);
4430: } elsif ($astudent ne $bstudent) {
4431: $result = ($astudent cmp $bstudent);
4432: } elsif ($apart ne $bpart ) {
4433: $result = ($apart cmp $bpart);
4434: }
4435: } else {
4436: if ($astudent ne $bstudent) {
4437: $result = ($astudent cmp $bstudent);
4438: } elsif ($ares ne $bres ) {
4439: $result = ($ares cmp $bres);
4440: } elsif ($apart ne $bpart ) {
4441: $result = ($apart cmp $bpart);
4442: }
4443: }
4444:
4445: if (!$result) {
4446: if (defined($aparm) && defined($bparm)) {
4447: $result = ($aparm <=> $bparm);
4448: } elsif (defined($aparm)) {
4449: $result = -1;
4450: } elsif (defined($bparm)) {
4451: $result = 1;
4452: }
4453: }
4454:
4455: $result;
4456:
4457: } keys(%{$listdata})) { # foreach my $key
4458: my $thiskey = $key;
4459: if ($$listdata{$thiskey.'.type'}) {
4460: my $thistype=$$listdata{$thiskey.'.type'};
4461: if ($$resourcedata{$thiskey.'.type'}) {
4462: $thistype=$$resourcedata{$thiskey.'.type'};
4463: }
4464: my ($middle,$part,$name)=
4465: ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
4466: my $section=&mt('All Students');
4467: $readonly = $readonlyall;
4468: my $showval = $$resourcedata{$thiskey};
4469: if ($middle=~/^\[(.*)\]/) {
4470: my $issection=$1;
4471: if ($issection=~/^useropt\:($match_username)\:($match_domain)/) {
4472: my ($stuname,$studom) = ($1,$2);
4473: if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
4474: if (ref($classlist) eq 'HASH') {
4475: if (ref($classlist->{$stuname.':'.$studom}) eq 'ARRAY') {
4476: next unless ($classlist->{$stuname.':'.$studom}->[$secidx] eq $env{'request.course.sec'});
4477: }
4478: }
4479: }
4480: $section=&mt('User').": ".&Apache::loncommon::plainname($stuname,$studom);
4481: } else {
4482: if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
4483: if (exists($grouphash{$issection})) {
4484: $section=&mt('Group').': '.$issection;
4485: } elsif ($issection eq $env{'request.course.sec'}) {
4486: $section = &mt('Section').': '.$issection;
4487: } else {
4488: next;
4489: }
4490: } else {
4491: $section=&mt('Group/Section').': '.$issection;
4492: }
4493: }
4494: $middle=~s/^\[(.*)\]//;
4495: } elsif (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) {
4496: $readonly = 1;
4497: }
4498: $middle=~s/\.+$//;
4499: $middle=~s/^\.+//;
4500: my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
4501: my ($is_map,$is_recursive,$mapurl,$maplevel);
4502: if ($caller eq 'overview') {
4503: if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) {
4504: $mapurl = $1;
4505: $maplevel = $2;
4506: $is_map = 1;
4507: }
4508: } elsif ($caller eq 'newoverview') {
4509: if ($middle=~/^(.+)\_\_\_\((all)\)$/) {
4510: $mapurl = $1;
4511: $maplevel = $2;
4512: $is_map = 1;
4513: }
4514: }
4515: if ($is_map) {
4516: my $leveltitle = &mt('Folder/Map');
4517: unless (($name eq 'hiddenresource') || ($name eq 'encrypturl')) {
4518: if ($caller eq 'newoverview') {
4519: my $altkey = $thiskey;
4520: $altkey =~ s/\Q___(all)\E/___(rec)/;
4521: if ((exists($$resourcedata{$altkey})) & (!exists($$resourcedata{$thiskey}))) {
4522: $is_recursive = 1;
4523: if ($$resourcedata{$altkey.'.type'}) {
4524: $thistype=$$resourcedata{$altkey.'.type'};
4525: }
4526: $showval = $$resourcedata{$altkey};
4527: }
4528: } elsif (($caller eq 'overview') && ($maplevel eq 'rec')) {
4529: $thiskey =~ s/\Q___(rec)\E/___(all)/;
4530: $is_recursive = 1;
4531: }
4532: }
4533: $realm='<span class="LC_parm_scope_folder">'.$leveltitle.': '.&Apache::lonnet::gettitle($mapurl).' <br /><span class="LC_parm_folder">('.$mapurl.')</span></span>';
4534: } elsif ($middle) {
4535: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
4536: $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').
4537: ': '.&Apache::lonnet::gettitle($middle).
4538: ' <br /><span class="LC_parm_symb">('.$url.' in '.$map.' id: '.
4539: $id.')</span></span>';
4540: }
4541: if ($sortorder eq 'realmstudent') {
4542: if ($realm ne $oldrealm) {
4543: $r->print(&tableend()."\n<hr /><h1>$realm</h1>");
4544: $oldrealm=$realm;
4545: $oldsection='';
4546: }
4547: if ($section ne $oldsection) {
4548: $r->print(&tableend()."\n<h2>$section</h2>");
4549: $oldsection=$section;
4550: $oldpart='';
4551: }
4552: } else {
4553: if ($section ne $oldsection) {
4554: $r->print(&tableend()."\n<hr /><h1>$section</h1>");
4555: $oldsection=$section;
4556: $oldrealm='';
4557: }
4558: if ($realm ne $oldrealm) {
4559: $r->print(&tableend()."\n<h2>$realm</h2>");
4560: $oldrealm=$realm;
4561: $oldpart='';
4562: }
4563: }
4564: if ($part ne $oldpart) {
4565: $r->print(&tableend().
4566: "\n".'<span class="LC_parm_part">'.&mt('Part').": $part</span>");
4567: $oldpart=$part;
4568: }
4569: #
4570: # Ready to print
4571: #
4572: my $parmitem = &standard_parameter_names($name);
4573: $r->print(&tablestart($readonly,$is_map).
4574: &Apache::loncommon::start_data_table_row().
4575: '<td><b>'.&mt($parmitem).
4576: '</b></td>');
4577: unless ($readonly) {
4578: $r->print('<td><input type="checkbox" name="del_'.
4579: $thiskey.'" /></td>');
4580: }
4581: $r->print('<td>');
4582: $foundkeys++;
4583: if (&isdateparm($thistype)) {
4584: my $jskey='key_'.$pointer;
4585: my $state;
4586: $pointer++;
4587: if ($readonly) {
4588: $state = 'disabled';
4589: }
4590: $r->print(
4591: &Apache::lonhtmlcommon::date_setter('parmform',
4592: $jskey,
4593: $showval,
4594: '',1,$state));
4595: unless ($readonly) {
4596: $r->print(
4597: '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'.
4598: (($showval!=0)?'<span class="LC_nobreak"><a href="/adm/parmset?&action=dateshift1&timebase='.$showval.'">'.
4599: &mt('Shift all dates based on this date').'</a></span>':'').
4600: &date_sanity_info($showval)
4601: );
4602: }
4603: } elsif ($thistype eq 'date_interval') {
4604: $r->print(&date_interval_selector($thiskey,$name,
4605: $showval,$readonly));
4606: } elsif ($thistype =~ m/^string/) {
4607: $r->print(&string_selector($thistype,$thiskey,
4608: $showval,$name,$readonly));
4609: } else {
4610: $r->print(&default_selector($thiskey,$showval,$readonly));
4611: }
4612: unless ($readonly) {
4613: $r->print('<input type="hidden" name="typeof_'.$thiskey.'" value="'.
4614: $thistype.'" />');
4615: }
4616: $r->print('</td>');
4617: if ($is_map) {
4618: if (($name eq 'encrypturl') || ($name eq 'hiddenresource')) {
4619: $r->print('<td><table><tr><td>'.&mt('Yes').'</td></tr></table></td>');
4620: } else {
4621: my ($disabled,$recon,$recoff);
4622: if ($readonly) {
4623: $disabled = ' disabled="disabled"';
4624: }
4625: if ($is_recursive) {
4626: $recon = ' checked="checked"';
4627: } else {
4628: $recoff = ' checked="checked"';
4629: }
4630: $r->print('<td><table><tr><td><label><input type="radio" name="rec_'.$thiskey.'" value="1"'.$recon.$disabled.' />'.&mt('Yes').'</label>'.
4631: '</td><td><label><input type="radio" name="rec_'.$thiskey.'" value="0"'.$recoff.$disabled.' />'.&mt('No').'</label></td></tr></table></td>');
4632: }
4633: }
4634: $r->print(&Apache::loncommon::end_data_table_row());
4635: }
4636: }
4637: return $foundkeys;
4638: }
4639:
4640: # Returns a string representing the interval, directly using form data matching the given key.
4641: # The returned string may also include information related to proctored exams.
4642: # Format: seconds['_done'[':'done button title':']['_proctor'['_'proctor key]]]
4643: #
4644: # @param {string} $key - suffix for form fields related to the interval
4645: # @returns {string}
4646: sub get_date_interval_from_form {
4647: my ($key) = @_;
4648: my $seconds = 0;
4649: foreach my $which (['days', 86400],
4650: ['hours', 3600],
4651: ['minutes', 60],
4652: ['seconds', 1]) {
4653: my ($name, $factor) = @{ $which };
4654: if (defined($env{'form.'.$name.'_'.$key})) {
4655: $seconds += $env{'form.'.$name.'_'.$key} * $factor;
4656: }
4657: }
4658: if (($key =~ /\.interval$/) &&
4659: (($env{'form.done_'.$key} eq '_done') || ($env{'form.done_'.$key} eq '_done_proctor'))) {
4660: if ($env{'form.done_'.$key.'_buttontext'}) {
4661: $env{'form.done_'.$key.'_buttontext'} =~ s/\://g;
4662: $seconds .= '_done:'.$env{'form.done_'.$key.'_buttontext'}.':';
4663: if ($env{'form.done_'.$key} eq '_done_proctor') {
4664: $seconds .= '_proctor';
4665: }
4666: } else {
4667: $seconds .= $env{'form.done_'.$key};
4668: }
4669: if (($env{'form.done_'.$key} eq '_done_proctor') &&
4670: ($env{'form.done_'.$key.'_proctorkey'})) {
4671: $seconds .= '_'.$env{'form.done_'.$key.'_proctorkey'};
4672: }
4673: }
4674: return $seconds;
4675: }
4676:
4677:
4678: # Returns HTML to enter a text value for a parameter.
4679: #
4680: # @param {string} $thiskey - parameter key
4681: # @param {string} $showval - the current value
4682: # @param {boolean} $readonly - true if the field should not be made editable
4683: # @returns {string}
4684: sub default_selector {
4685: my ($thiskey, $showval, $readonly) = @_;
4686: my $disabled;
4687: if ($readonly) {
4688: $disabled = ' disabled="disabled"';
4689: }
4690: return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'"'.$disabled.' />';
4691: }
4692:
4693: # Returns HTML to enter allow/deny rules related to IP addresses.
4694: #
4695: # @param {string} $thiskey - parameter key
4696: # @param {string} $showval - the current value
4697: # @param {boolean} $readonly - true if the fields should not be made editable
4698: # @returns {string}
4699: sub string_ip_selector {
4700: my ($thiskey, $showval, $readonly) = @_;
4701: my %access = (
4702: allow => [],
4703: deny => [],
4704: );
4705: if ($showval ne '') {
4706: my @current;
4707: if ($showval =~ /,/) {
4708: @current = split(/,/,$showval);
4709: } else {
4710: @current = ($showval);
4711: }
4712: foreach my $item (@current) {
4713: if ($item =~ /^\!([\[\]a-zA-Z\.\d\*\-]+)$/) {
4714: push(@{$access{'deny'}},$1);
4715: } elsif ($item =~ /^([\[\]a-zA-Z\.\d\*\-]+)$/) {
4716: push(@{$access{'allow'}},$item);
4717: }
4718: }
4719: }
4720: if (!@{$access{'allow'}}) {
4721: @{$access{'allow'}} = ('');
4722: }
4723: if (!@{$access{'deny'}}) {
4724: @{$access{'deny'}} = ('');
4725: }
4726: my ($disabled,$addmore);
4727: if ($readonly) {
4728: $disabled=' disabled="disabled"';
4729: } else {
4730: $addmore = "\n".'<button class="LC_add_ipacc_button">'.&mt('Add more').'</button>';
4731: }
4732: my $output = '<input type="hidden" name="set_'.$thiskey.'" />
4733: <table><tr><th>'.&mt('Allow from').'</th><th>'.&mt('Deny from').'</th></tr><tr>';
4734: foreach my $acctype ('allow','deny') {
4735: $output .= '
4736: <td valign="top">
4737: <div class="LC_string_ipacc_wrap" id="LC_string_ipacc_'.$acctype.'_'.$thiskey.'">
4738: <div class="LC_string_ipacc_inner">'."\n";
4739: my $num = 0;
4740: foreach my $curr (@{$access{$acctype}}) {
4741: $output .= '<div><input type="text" name="setip'.$acctype.'_'.$thiskey.'" value="'.$curr.'"'.$disabled.' />';
4742: if ($num > 0) {
4743: $output .= '<a href="#" class="LC_remove_ipacc">'.&mt('Remove').'</a>';
4744: }
4745: $output .= '</div>'."\n";
4746: $num ++;
4747: }
4748: $output .= '
4749: </div>'.$addmore.'
4750: </div>
4751: </td>';
4752: }
4753: $output .= '
4754: </tr>
4755: </table>'."\n";
4756: return $output;
4757: }
4758:
4759: sub string_deeplink_selector {
4760: my ($thiskey, $showval, $readonly) = @_;
4761: my (@components,%values,@current,%titles,%options,%optiontext,%defaults,%posslti);
4762: @components = ('listing','scope','urls');
4763: %titles = &Apache::lonlocal::texthash (
4764: listing => 'In Contents and/or Gradebook',
4765: scope => 'Access scope for link',
4766: urls => 'Supported link types',
4767: );
4768: %options = (
4769: listing => ['full','absent','grades','details','datestatus'],
4770: scope => ['res','map','rec'],
4771: urls => ['any','only','key','lti'],
4772: );
4773: %optiontext = &Apache::lonlocal::texthash (
4774: full => 'Listed (linked) in both',
4775: absent => 'Not listed',
4776: grades => 'Listed in grades only',
4777: details => 'Listed (unlinked) in both',
4778: datestatus => 'Listed (unlinked) inc. status in both',
4779: res => 'resource only',
4780: map => 'enclosing map/folder',
4781: rec => 'recursive map/folder',
4782: any => 'regular + deep',
4783: only => 'deep only',
4784: key => 'deep with key',
4785: lti => 'deep with LTI launch',
4786: );
4787: if ($showval =~ /,/) {
4788: @current = split(/,/,$showval);
4789: ($values{'listing'}) = ($current[0] =~ /^(full|absent|grades|details|datestatus)$/);
4790: ($values{'scope'}) = ($current[1] =~ /^(res|map|rec)$/);
4791: ($values{'urls'}) = ($current[2] =~ /^(any|only|key:\w+|lti:\d+)$/);
4792: } else {
4793: $defaults{'listing'} = 'full';
4794: $defaults{'scope'} = 'res';
4795: $defaults{'urls'} = 'any';
4796: }
4797: my $disabled;
4798: if ($readonly) {
4799: $disabled=' disabled="disabled"';
4800: }
4801: my %lti =
4802: &Apache::lonnet::get_domain_lti($env{'course.'.$env{'request.course.id'}.'.domain'},
4803: 'provider');
4804: foreach my $item (keys(%lti)) {
4805: if (ref($lti{$item}) eq 'HASH') {
4806: unless ($lti{$item}{'requser'}) {
4807: $posslti{$item} = $lti{$item}{'consumer'};
4808: }
4809: }
4810: }
4811: my $output = '<input type="hidden" name="set_'.$thiskey.'" /><table><tr>';
4812: foreach my $item ('listing','scope','urls') {
4813: $output .= '<th>'.$titles{$item}.'</th>';
4814: }
4815: $output .= '</tr><tr>';
4816: foreach my $item (@components) {
4817: $output .= '<td>';
4818: if ($item eq 'urls') {
4819: my $selected = $values{$item};
4820: foreach my $option (@{$options{$item}}) {
4821: if ($option eq 'lti') {
4822: next unless (keys(%posslti));
4823: }
4824: my $checked;
4825: if ($selected =~ /^\Q$option\E/) {
4826: $checked = ' checked="checked"';
4827: }
4828: my $onclick;
4829: unless ($readonly) {
4830: my $esc_key = &js_escape($thiskey);
4831: $onclick = ' onclick="toggleDeepLink(this.form,'."'$item','$esc_key'".');"';
4832: }
4833: $output .= '<span class="LC_nobreak"><label>'.
4834: '<input type="radio" name="deeplink_'.$item.'_'.$thiskey.'" value="'.$option.'"'.$onclick.$disabled.$checked.' />'."\n".
4835: $optiontext{$option}.'</label>';
4836: if ($option eq 'key') {
4837: my $visibility="hidden";
4838: my $currkey;
4839: if ($checked) {
4840: $visibility = "text";
4841: $currkey = (split(/\:/,$values{$item}))[1];
4842: }
4843: $output .= ' '.
4844: '<input type="'.$visibility.'" name="deeplink_'.$option.'_'.$thiskey.'" id="deeplink_'.$option.'_'.$item.'_'.$thiskey.'" value="'.$currkey.'" size="6"'.$disabled.' />';
4845: } elsif ($option eq 'lti') {
4846: my $display="none";
4847: my ($currlti,$blankcheck);
4848: if ($checked) {
4849: $display = 'inline-block';
4850: $currlti = (split(/\:/,$values{$item}))[1];
4851: } else {
4852: $blankcheck = ' selected="selected"';
4853: }
4854: $output .= '<div id="deeplinkdiv_'.$option.'_'.$item.'_'.$thiskey.'"'.
4855: ' style="display: '.$display.'"> <select name="'.
4856: 'deeplink_'.$option.'_'.$thiskey.'"'.$disabled.'>'.
4857: '<option value=""'.$blankcheck.'>'.&mt('Select Provider').'</option>'."\n";
4858: foreach my $lti (sort { $a <=> $b } keys(%posslti)) {
4859: my $selected;
4860: if ($lti == $currlti) {
4861: $selected = ' selected="selected"';
4862: }
4863: $output .= '<option value="'.$lti.'"'.$selected.'>'.$posslti{$lti}.'</option>';
4864: }
4865: $output .= '</select></div>';
4866: }
4867: $output .= '</span> ';
4868: }
4869: } else {
4870: my $selected = $values{$item};
4871: my $defsel;
4872: if ($selected eq '') {
4873: $defsel = ' selected="selected"';
4874: }
4875: $output .= '<select name="deeplink_'.$item.'_'.$thiskey.'"'.$disabled.'>'."\n".
4876: '<option value=""'.$defsel.'>'.&mt('Please select').'</option>'."\n";
4877: foreach my $option (@{$options{$item}}) {
4878: $output .= '<option value="'.$option.'"';
4879: if ($option eq $selected) {
4880: $output .= ' selected="selected"';
4881: }
4882: $output .= '>'.$optiontext{$option}.'</option>';
4883: }
4884: $output .= '</select>';
4885: }
4886: $output .= '</td>';
4887: }
4888: $output .= '</tr></table>'."\n";
4889: return $output;
4890: }
4891:
4892:
4893: { # block using some constants related to parameter types (overview mode)
4894:
4895: my %strings =
4896: (
4897: 'string_yesno'
4898: => [[ 'yes', 'Yes' ],
4899: [ 'no', 'No' ]],
4900: 'string_problemstatus'
4901: => [[ 'yes', 'Yes' ],
4902: [ 'answer', 'Yes, and show correct answer if they exceed the maximum number of tries.' ],
4903: [ 'no', 'No, don\'t show correct/incorrect feedback.' ],
4904: [ 'no_feedback_ever', 'No, show no feedback at all.' ]],
4905: 'string_questiontype'
4906: => [[ 'problem', 'Standard Problem'],
4907: [ 'survey', 'Survey'],
4908: [ 'anonsurveycred', 'Anonymous Survey (credit for submission)'],
4909: [ 'exam', 'Bubblesheet Exam'],
4910: [ 'anonsurvey', 'Anonymous Survey'],
4911: [ 'randomizetry', 'New Randomization Each N Tries (default N=1)'],
4912: [ 'practice', 'Practice'],
4913: [ 'surveycred', 'Survey (credit for submission)']],
4914: 'string_lenient'
4915: => [['yes', 'Yes' ],
4916: [ 'no', 'No' ],
4917: [ 'default', 'Default - only bubblesheet grading is lenient' ],
4918: [ 'weighted', 'Yes, weighted (optionresponse in checkbox mode)' ]],
4919: 'string_discussvote'
4920: => [['yes','Yes'],
4921: ['notended','Yes, unless discussion ended'],
4922: ['no','No']],
4923: 'string_ip'
4924: => [['_allowfrom_','Hostname(s), or IP(s) from which access is allowed'],
4925: ['_denyfrom_','Hostname(s) or IP(s) from which access is disallowed']],
4926: 'string_deeplink'
4927: => [['on','Set choices for link protection, resource listing, and access scope']],
4928: );
4929:
4930:
4931: my %stringmatches = (
4932: 'string_lenient'
4933: => [['weighted','^\-?[.\d]+,\-?[.\d]+,\-?[.\d]+,\-?[.\d]+$'],],
4934: 'string_ip'
4935: => [['_allowfrom_','[^\!]+'],
4936: ['_denyfrom_','\!']],
4937: 'string_deeplink'
4938: => [['on','^(full|absent|grades|details|datestatus)\,(res|map|rec)\,(any|only|key\:\w+|lti\:\d+)$']],
4939: );
4940:
4941: my %stringtypes = (
4942: type => 'string_questiontype',
4943: lenient => 'string_lenient',
4944: retrypartial => 'string_yesno',
4945: discussvote => 'string_discussvote',
4946: examcode => 'string_examcode',
4947: acc => 'string_ip',
4948: deeplink => 'string_deeplink',
4949: );
4950:
4951: # Returns the possible values and titles for a given string type, or undef if there are none.
4952: # Used by courseprefs.
4953: #
4954: # @param {string} $string_type - a parameter type for strings
4955: # @returns {array reference} - 2D array, containing values and English titles
4956: sub standard_string_options {
4957: my ($string_type) = @_;
4958: if (ref($strings{$string_type}) eq 'ARRAY') {
4959: return $strings{$string_type};
4960: }
4961: return;
4962: }
4963:
4964: # Returns regular expressions to match kinds of string types, or undef if there are none.
4965: #
4966: # @param {string} $string_type - a parameter type for strings
4967: # @returns {array reference} - 2D array, containing regular expression names and regular expressions
4968: sub standard_string_matches {
4969: my ($string_type) = @_;
4970: if (ref($stringmatches{$string_type}) eq 'ARRAY') {
4971: return $stringmatches{$string_type};
4972: }
4973: return;
4974: }
4975:
4976: # Returns a parameter type for a given parameter with a string type, or undef if not known.
4977: #
4978: # @param {string} $name - parameter name
4979: # @returns {string}
4980: sub get_stringtype {
4981: my ($name) = @_;
4982: if (exists($stringtypes{$name})) {
4983: return $stringtypes{$name};
4984: }
4985: return;
4986: }
4987:
4988: # Returns HTML to edit a string parameter.
4989: #
4990: # @param {string} $thistype - parameter type
4991: # @param {string} $thiskey - parameter key
4992: # @param {string} $showval - parameter current value
4993: # @param {string} $name - parameter name
4994: # @param {boolean} $readonly - true if the values should not be made editable
4995: # @returns {string}
4996: sub string_selector {
4997: my ($thistype, $thiskey, $showval, $name, $readonly) = @_;
4998:
4999: if (!exists($strings{$thistype})) {
5000: return &default_selector($thiskey,$showval,$readonly);
5001: }
5002:
5003: my %skiptype;
5004: if (($thistype eq 'string_questiontype') ||
5005: ($thistype eq 'string_lenient') ||
5006: ($thistype eq 'string_discussvote') ||
5007: ($thistype eq 'string_ip') ||
5008: ($thistype eq 'string_deeplink') ||
5009: ($name eq 'retrypartial')) {
5010: my ($got_chostname,$chostname,$cmajor,$cminor);
5011: foreach my $possibilities (@{ $strings{$thistype} }) {
5012: next unless (ref($possibilities) eq 'ARRAY');
5013: my ($parmval, $description) = @{ $possibilities };
5014: my $parmmatch;
5015: if (ref($stringmatches{$thistype}) eq 'ARRAY') {
5016: foreach my $item (@{$stringmatches{$thistype}}) {
5017: if (ref($item) eq 'ARRAY') {
5018: if ($parmval eq $item->[0]) {
5019: $parmmatch = $parmval;
5020: $parmval = '';
5021: last;
5022: }
5023: }
5024: }
5025: }
5026: my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval:$parmmatch"};
5027: if ($needsrelease) {
5028: unless ($got_chostname) {
5029: ($chostname,$cmajor,$cminor)=¶meter_release_vars();
5030: $got_chostname = 1;
5031: }
5032: my $needsnewer=¶meter_releasecheck($name,$parmval,$parmmatch,undef,
5033: $needsrelease,$cmajor,$cminor);
5034: if ($needsnewer) {
5035: if ($parmmatch ne '') {
5036: $skiptype{$parmmatch} = 1;
5037: } elsif ($parmval ne '') {
5038: $skiptype{$parmval} = 1;
5039: }
5040: }
5041: }
5042: }
5043: }
5044:
5045: if ($thistype eq 'string_ip') {
5046: return &string_ip_selector($thiskey,$showval,$readonly);
5047: } elsif ($thistype eq 'string_deeplink') {
5048: return &string_deeplink_selector($thiskey,$showval,$readonly);
5049: }
5050:
5051: my ($result,$disabled);
5052:
5053: if ($readonly) {
5054: $disabled = ' disabled="disabled"';
5055: }
5056: my $numinrow = 3;
5057: if ($thistype eq 'string_problemstatus') {
5058: $numinrow = 2;
5059: } elsif ($thistype eq 'string_questiontype') {
5060: if (keys(%skiptype) > 0) {
5061: $numinrow = 4;
5062: }
5063: }
5064: my $rem;
5065: if (ref($strings{$thistype}) eq 'ARRAY') {
5066: my $i=0;
5067: foreach my $possibilities (@{ $strings{$thistype} }) {
5068: next unless (ref($possibilities) eq 'ARRAY');
5069: my ($name, $description) = @{ $possibilities };
5070: next if ($skiptype{$name});
5071: $rem = $i%($numinrow);
5072: if ($rem == 0) {
5073: if ($i > 0) {
5074: $result .= '</tr>';
5075: }
5076: $result .= '<tr>';
5077: }
5078: my $colspan;
5079: if ($i == @{ $strings{$thistype} }-1) {
5080: $rem = @{ $strings{$thistype} }%($numinrow);
5081: if ($rem) {
5082: my $colsleft = $numinrow - $rem;
5083: if ($colsleft) {
5084: $colspan = $colsleft+1;
5085: $colspan = ' colspan="'.$colspan.'"';
5086: }
5087: }
5088: }
5089: my ($add,$onchange,$css_class);
5090: if ($thistype eq 'string_lenient') {
5091: if ($name eq 'weighted') {
5092: my $display;
5093: my %relatives = &Apache::lonlocal::texthash(
5094: corrchkd => 'Correct (checked)',
5095: corrunchkd => 'Correct (unchecked)',
5096: incorrchkd => 'Incorrect (checked)',
5097: incorrunchkd => 'Incorrect (unchecked)',
5098: );
5099: my %textval = (
5100: corrchkd => '1.0',
5101: corrunchkd => '1.0',
5102: incorrchkd => '0.0',
5103: incorrunchkd => '0.0',
5104: );
5105: if ($showval =~ /^([\-\d\.]+)\,([\-\d\.]+)\,([\-\d\.]+)\,([\-\d\.]+)$/) {
5106: $textval{'corrchkd'} = $1;
5107: $textval{'corrunchkd'} = $2;
5108: $textval{'incorrchkd'} = $3;
5109: $textval{'incorrunchkd'} = $4;
5110: $display = 'inline';
5111: $showval = $name;
5112: } else {
5113: $display = 'none';
5114: }
5115: $add = ' <div id="LC_parmtext_'.$thiskey.'" style="display:'.$display.'"><table>'.
5116: '<tr><th colspan="2">'.&mt("Foil's submission status").'</th><th>'.&mt('Points').'</th></tr>';
5117: foreach my $reltype ('corrchkd','corrunchkd','incorrchkd','incorrunchkd') {
5118: $add .= '<tr><td> </td><td>'.$relatives{$reltype}.'</td>'."\n".
5119: '<td><input type="text" name="settext_'.$thiskey.'"'.
5120: ' value="'.$textval{$reltype}.'" size="3"'.$disabled.' />'.
5121: '</td></tr>';
5122: }
5123: $add .= '</table></div>'."\n";
5124: }
5125: $onchange = ' onclick="javascript:toggleParmTextbox(this.form,'."'$thiskey'".');"';
5126: $css_class = ' class="LC_lenient_radio"';
5127: }
5128: $result .= '<td class="LC_left_item"'.$colspan.'>'.
5129: '<span class="LC_nobreak"><label>'.
5130: '<input type="radio" name="set_'.$thiskey.
5131: '" value="'.$name.'"'.$onchange.$css_class.$disabled;
5132: if ($showval eq $name) {
5133: $result .= ' checked="checked"';
5134: }
5135: $result .= ' />'.&mt($description).'</label>'.$add.'</span></td>';
5136: $i++;
5137: }
5138: $result .= '</tr>';
5139: }
5140: if ($result) {
5141: $result = '<table border="0">'.$result.'</table>';
5142: }
5143: return $result;
5144: }
5145:
5146: my %intervals =
5147: (
5148: 'date_interval'
5149: => [[ 'done', 'Yes' ],
5150: [ 'done_proctor', 'Yes, with proctor key'],
5151: [ '', 'No' ]],
5152: );
5153:
5154: my %intervalmatches = (
5155: 'date_interval'
5156: => [['done','\d+_done(|\:[^\:]+\:)$'],
5157: ['done_proctor','\d+_done(|\:[^\:]+\:)_proctor_']],
5158: );
5159:
5160: my %intervaltypes = (
5161: interval => 'date_interval',
5162: );
5163:
5164: # Returns regular expressions to match kinds of interval type, or undef if there are none.
5165: #
5166: # @param {string} $interval_type - a parameter type for intervals
5167: # @returns {array reference} - 2D array, containing regular expression names and regular expressions
5168: sub standard_interval_matches {
5169: my ($interval_type) = @_;
5170: if (ref($intervalmatches{$interval_type}) eq 'ARRAY') {
5171: return $intervalmatches{$interval_type};
5172: }
5173: return;
5174: }
5175:
5176: # Returns a parameter type for a given parameter with an interval type, or undef if not known.
5177: #
5178: # @param {string} $name - parameter name
5179: # @returns {string}
5180: sub get_intervaltype {
5181: my ($name) = @_;
5182: if (exists($intervaltypes{$name})) {
5183: return $intervaltypes{$name};
5184: }
5185: return;
5186: }
5187:
5188: # Returns the possible values and titles for a given interval type, or undef if there are none.
5189: # Used by courseprefs.
5190: #
5191: # @param {string} $interval_type - a parameter type for intervals
5192: # @returns {array reference} - 2D array, containing values and English titles
5193: sub standard_interval_options {
5194: my ($interval_type) = @_;
5195: if (ref($intervals{$interval_type}) eq 'ARRAY') {
5196: return $intervals{$interval_type};
5197: }
5198: return;
5199: }
5200:
5201: # Returns HTML to edit a date interval parameter.
5202: #
5203: # @param {string} $thiskey - parameter key
5204: # @param {string} $name - parameter name
5205: # @param {string} $showval - parameter current value
5206: # @param {boolean} $readonly - true if the values should not be made editable
5207: # @returns {string}
5208: sub date_interval_selector {
5209: my ($thiskey, $name, $showval, $readonly) = @_;
5210: my ($result,%skipval);
5211: if ($name eq 'interval') {
5212: my $intervaltype = &get_intervaltype($name);
5213: my ($got_chostname,$chostname,$cmajor,$cminor);
5214: foreach my $possibilities (@{ $intervals{$intervaltype} }) {
5215: next unless (ref($possibilities) eq 'ARRAY');
5216: my ($parmval, $description) = @{ $possibilities };
5217: my $parmmatch;
5218: if (ref($intervalmatches{$intervaltype}) eq 'ARRAY') {
5219: foreach my $item (@{$intervalmatches{$intervaltype}}) {
5220: if (ref($item) eq 'ARRAY') {
5221: if ($parmval eq $item->[0]) {
5222: $parmmatch = $parmval;
5223: $parmval = '';
5224: last;
5225: }
5226: }
5227: }
5228: }
5229: my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval:$parmmatch"};
5230: if ($needsrelease) {
5231: unless ($got_chostname) {
5232: ($chostname,$cmajor,$cminor)=¶meter_release_vars();
5233: $got_chostname = 1;
5234: }
5235: my $needsnewer=¶meter_releasecheck($name,$parmval,$parmmatch,undef,
5236: $needsrelease,$cmajor,$cminor);
5237: if ($needsnewer) {
5238: if ($parmmatch ne '') {
5239: $skipval{$parmmatch} = 1;
5240: } elsif ($parmval ne '') {
5241: $skipval{$parmval} = 1;
5242: }
5243: }
5244: }
5245: }
5246: }
5247:
5248: my $currval = $showval;
5249: foreach my $which (['days', 86400, 31],
5250: ['hours', 3600, 23],
5251: ['minutes', 60, 59],
5252: ['seconds', 1, 59]) {
5253: my ($name, $factor, $max) = @{ $which };
5254: my $amount = int($showval/$factor);
5255: $showval %= $factor;
5256: my %select = ((map {$_ => $_} (0..$max)),
5257: 'select_form_order' => [0..$max]);
5258: $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey,
5259: \%select,'',$readonly);
5260: $result .= ' '.&mt($name);
5261: }
5262: if ($name eq 'interval') {
5263: unless ($skipval{'done'}) {
5264: my $checkedon = '';
5265: my $checkedproc = '';
5266: my $currproctorkey = '';
5267: my $currprocdisplay = 'hidden';
5268: my $currdonetext = &mt('Done');
5269: my $checkedoff = ' checked="checked"';
5270: if ($currval =~ /^(?:\d+)_done$/) {
5271: $checkedon = ' checked="checked"';
5272: $checkedoff = '';
5273: } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:$/) {
5274: $currdonetext = $1;
5275: $checkedon = ' checked="checked"';
5276: $checkedoff = '';
5277: } elsif ($currval =~ /^(?:\d+)_done_proctor_(.+)$/) {
5278: $currproctorkey = $1;
5279: $checkedproc = ' checked="checked"';
5280: $checkedoff = '';
5281: $currprocdisplay = 'text';
5282: } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:_proctor_(.+)$/) {
5283: $currdonetext = $1;
5284: $currproctorkey = $2;
5285: $checkedproc = ' checked="checked"';
5286: $checkedoff = '';
5287: $currprocdisplay = 'text';
5288: }
5289: my $onclick = ' onclick="toggleSecret(this.form,'."'done_','$thiskey'".');"';
5290: my $disabled;
5291: if ($readonly) {
5292: $disabled = ' disabled="disabled"';
5293: }
5294: $result .= '<br /><span class="LC_nobreak">'.&mt('Include "done" button').
5295: '<label><input type="radio" value="" name="done_'.$thiskey.'"'.$checkedoff.$onclick.$disabled.' />'.
5296: &mt('No').'</label>'.(' 'x2).
5297: '<label><input type="radio" value="_done" name="done_'.$thiskey.'"'.$checkedon.$onclick.$disabled.' />'.
5298: &mt('Yes').'</label>'.(' 'x2).
5299: '<label><input type="radio" value="_done_proctor" name="done_'.$thiskey.'"'.$checkedproc.$onclick.$disabled.' />'.
5300: &mt('Yes, with proctor key').'</label>'.
5301: '<input type="'.$currprocdisplay.'" id="done_'.$thiskey.'_proctorkey" '.
5302: 'name="done_'.$thiskey.'_proctorkey" value="'.&HTML::Entities::encode($currproctorkey,'"<>&').'"'.$disabled.' /></span><br />'.
5303: '<span class="LC_nobreak">'.&mt('Button text').': '.
5304: '<input type="text" name="done_'.$thiskey.'_buttontext" value="'.&HTML::Entities::encode($currdonetext,'"<>&').'"'.$disabled.' /></span>';
5305: }
5306: }
5307: unless ($readonly) {
5308: $result .= '<input type="hidden" name="dateinterval_'.$thiskey.'" />';
5309: }
5310: return $result;
5311: }
5312:
5313: # Returns HTML with a warning if a parameter requires a more recent version of LON-CAPA.
5314: #
5315: # @param {string} $name - parameter name
5316: # @param {string} $namematch - parameter level name (recognized: resourcelevel|maplevel|maplevelrecurse|courselevel)
5317: # @param {string} $value - parameter value
5318: # @param {string} $chostname - course server name
5319: # @param {integer} $cmajor - major version number
5320: # @param {integer} $cminor - minor version number
5321: # @param {string} $needsrelease - release version needed (major.minor)
5322: # @returns {string}
5323: sub oldversion_warning {
5324: my ($name,$namematch,$value,$chostname,$cmajor,$cminor,$needsrelease) = @_;
5325: my $standard_name = &standard_parameter_names($name);
5326: if ($namematch) {
5327: my $level = &standard_parameter_levels($namematch);
5328: my $msg = '';
5329: if ($level) {
5330: $msg = &mt('[_1] was [_2]not[_3] set at the level of: [_4].',
5331: $standard_name,'<b>','</b>','"'.$level.'"');
5332: } else {
5333: $msg = &mt('[_1] was [_2]not[_3] set.',
5334: $standard_name,'<b>','</b>');
5335: }
5336: return '<p class="LC_warning">'.$msg.'<br />'.
5337: &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
5338: $cmajor.'.'.$cminor,$chostname,
5339: $needsrelease).
5340: '</p>';
5341: }
5342: my $desc;
5343: my $stringtype = &get_stringtype($name);
5344: if ($stringtype ne '') {
5345: if ($name eq 'examcode') {
5346: $desc = $value;
5347: } elsif (ref($strings{$stringtypes{$name}}) eq 'ARRAY') {
5348: foreach my $possibilities (@{ $strings{$stringtypes{$name}} }) {
5349: next unless (ref($possibilities) eq 'ARRAY');
5350: my ($parmval, $description) = @{ $possibilities };
5351: my $parmmatch;
5352: if (ref($stringmatches{$stringtypes{$name}}) eq 'ARRAY') {
5353: foreach my $item (@{$stringmatches{$stringtypes{$name}}}) {
5354: if (ref($item) eq 'ARRAY') {
5355: my ($regexpname,$pattern) = @{$item};
5356: if ($parmval eq $regexpname) {
5357: if ($value =~ /$pattern/) {
5358: $desc = $description;
5359: $parmmatch = 1;
5360: last;
5361: }
5362: }
5363: }
5364: }
5365: last if ($parmmatch);
5366: } elsif ($parmval eq $value) {
5367: $desc = $description;
5368: last;
5369: }
5370: }
5371: }
5372: } elsif (($name eq 'printstartdate') || ($name eq 'printenddate')) {
5373: my $now = time;
5374: if ($value =~ /^\d+$/) {
5375: if ($name eq 'printstartdate') {
5376: if ($value > $now) {
5377: $desc = &Apache::lonlocal::locallocaltime($value);
5378: }
5379: } elsif ($name eq 'printenddate') {
5380: if ($value < $now) {
5381: $desc = &Apache::lonlocal::locallocaltime($value);
5382: }
5383: }
5384: }
5385: }
5386: return '<p class="LC_warning">'.
5387: &mt('[_1] was [_2]not[_3] set to [_4].',
5388: $standard_name,'<b>','</b>','"'.$desc.'"').'<br />'.
5389: &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
5390: $cmajor.'.'.$cminor,$chostname,
5391: $needsrelease).
5392: '</p>';
5393: }
5394:
5395: } # end of block using some constants related to parameter types
5396:
5397:
5398:
5399: # Shifts all start and end dates in the current course by $shift.
5400: #
5401: # @param {integer} $shift - time to shift, in seconds
5402: # @returns {string} - error name or 'ok'
5403: sub dateshift {
5404: my ($shift,$numchanges)=@_;
5405: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5406: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
5407: my $sec = $env{'request.course.sec'};
5408: my %data=&Apache::lonnet::dump('resourcedata',$dom,$crs);
5409: # ugly retro fix for broken version of types
5410: foreach my $key (keys(%data)) {
5411: if ($key=~/\wtype$/) {
5412: my $newkey=$key;
5413: $newkey=~s/type$/\.type/;
5414: $data{$newkey}=$data{$key};
5415: delete $data{$key};
5416: }
5417: }
5418: my %storecontent=();
5419: # go through all parameters and look for dates
5420: foreach my $key (keys(%data)) {
5421: if ($data{$key.'.type'}=~/^date_(start|end)$/) {
5422: if ($sec ne '') {
5423: next unless ($key =~ /^$env{'request.course.id'}\.\[$sec\]\./);
5424: }
5425: my $newdate=$data{$key}+$shift;
5426: $$numchanges ++;
5427: $storecontent{$key}=$newdate;
5428: }
5429: }
5430: my $reply=&Apache::lonnet::cput
5431: ('resourcedata',\%storecontent,$dom,$crs);
5432: if ($reply eq 'ok') {
5433: &log_parmset(\%storecontent);
5434: }
5435: &Apache::lonnet::devalidatecourseresdata($crs,$dom);
5436: return $reply;
5437: }
5438:
5439: # Overview mode UI to edit course parameters.
5440: #
5441: # @param {Apache2::RequestRec} $r - the Apache request
5442: sub newoverview {
5443: my ($r,$parm_permission) = @_;
5444:
5445: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5446: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
5447: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5448: my $readonly = 1;
5449: if ($parm_permission->{'edit'}) {
5450: undef($readonly);
5451: }
5452: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
5453: text=>"Overview Mode"});
5454:
5455: my %loaditems = (
5456: 'onload' => "showHide_courseContent(); resize_scrollbox('mapmenuscroll','1','1'); showHideLenient();",
5457: );
5458: my $js = '
5459: <script type="text/javascript">
5460: // <![CDATA[
5461: '.
5462: &Apache::lonhtmlcommon::resize_scrollbox_js('params')."\n".
5463: &showhide_js()."\n".
5464: &toggleparmtextbox_js()."\n".
5465: &validateparms_js()."\n".
5466: &ipacc_boxes_js()."\n".
5467: &done_proctor_js()."\n".
5468: &deeplink_js()."\n".
5469: '// ]]>
5470: </script>
5471: ';
5472:
5473: my $start_page = &Apache::loncommon::start_page('Set Parameters',$js,
5474: {'add_entries' => \%loaditems,});
5475: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
5476: $r->print($start_page.$breadcrumbs);
5477: &startSettingsScreen($r,'parmset',$crstype);
5478: $r->print(<<ENDOVER);
5479: <form method="post" action="/adm/parmset?action=newoverview" name="parmform" onsubmit="return validateParms();">
5480: ENDOVER
5481: my @ids=();
5482: my %typep=();
5483: my %keyp=();
5484: my %allparms=();
5485: my %allparts=();
5486: my %allmaps=();
5487: my %mapp=();
5488: my %symbp=();
5489: my %maptitles=();
5490: my %uris=();
5491: my %keyorder=&standardkeyorder();
5492: my %defkeytype=();
5493:
5494: my %alllevs=();
5495: $alllevs{'Resource Level'}='full';
5496: $alllevs{'Map/Folder Level'}='map';
5497: $alllevs{'Course Level'}='general';
5498:
5499: my $csec=$env{'form.csec'};
5500: my $cgroup=$env{'form.cgroup'};
5501:
5502: my @pscat=&Apache::loncommon::get_env_multiple('form.pscat');
5503: my $pschp=$env{'form.pschp'};
5504:
5505: my @psprt=&Apache::loncommon::get_env_multiple('form.psprt');
5506: if (!@psprt) { $psprt[0]='all'; }
5507:
5508: my @selected_sections =
5509: &Apache::loncommon::get_env_multiple('form.Section');
5510: @selected_sections = ('all') if (! @selected_sections);
5511: foreach my $sec (@selected_sections) {
5512: if ($sec eq 'all') {
5513: @selected_sections = ('all');
5514: }
5515: }
5516: if ($env{'request.course.sec'} ne '') {
5517: @selected_sections = ($env{'request.course.sec'});
5518: }
5519: my @selected_groups =
5520: &Apache::loncommon::get_env_multiple('form.Group');
5521:
5522: my $pssymb='';
5523: my $parmlev='';
5524:
5525: unless ($env{'form.parmlev'}) {
5526: $parmlev = 'map';
5527: } else {
5528: $parmlev = $env{'form.parmlev'};
5529: }
5530:
5531: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
5532: \%mapp, \%symbp,\%maptitles,\%uris,
5533: \%keyorder,\%defkeytype);
5534:
5535: if (grep {$_ eq 'all'} (@psprt)) {
5536: @psprt = keys(%allparts);
5537: }
5538: # Menu to select levels, etc
5539:
5540: $r->print('<div class="LC_Box">');
5541: #$r->print('<h2 class="LC_hcell">Step 1</h2>');
5542: $r->print('<div>');
5543: $r->print(&Apache::lonhtmlcommon::start_pick_box(undef,'parmlevel'));
5544: &levelmenu($r,\%alllevs,$parmlev);
5545: if ($parmlev ne 'general') {
5546: $r->print(&Apache::lonhtmlcommon::row_closure());
5547: &mapmenu($r,\%allmaps,$pschp,\%maptitles,\%symbp);
5548: }
5549: $r->print(&Apache::lonhtmlcommon::row_closure(1));
5550: $r->print(&Apache::lonhtmlcommon::end_pick_box());
5551: $r->print('</div></div>');
5552:
5553: $r->print('<div class="LC_Box">');
5554: $r->print('<div>');
5555: &displaymenu($r,\%allparms,\@pscat,\%keyorder);
5556: $r->print(&Apache::lonhtmlcommon::start_pick_box());
5557: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View')));
5558: my $sectionselector = §ionmenu(\@selected_sections);
5559: my $groupselector = &groupmenu(\@selected_groups);
5560: $r->print('<table>'.
5561: '<tr><th>'.&mt('Parts').'</th>');
5562: if ($sectionselector) {
5563: $r->print('<th>'.&mt('Section(s)').'</th>');
5564: }
5565: if ($groupselector) {
5566: $r->print('<th>'.&mt('Group(s)').'</th>');
5567: }
5568: $r->print('</tr><tr><td>');
5569: &partmenu($r,\%allparts,\@psprt);
5570: $r->print('</td>');
5571: if ($sectionselector) {
5572: $r->print('<td>'.$sectionselector.'</td>');
5573: }
5574: if ($groupselector) {
5575: $r->print('<td>'.$groupselector.'</td>');
5576: }
5577: $r->print('</tr></table>');
5578: $r->print(&Apache::lonhtmlcommon::row_closure(1));
5579: $r->print(&Apache::lonhtmlcommon::end_pick_box());
5580: $r->print('</div></div>');
5581:
5582: $r->print('<div class="LC_Box">');
5583: $r->print('<div>');
5584: my $sortorder=$env{'form.sortorder'};
5585: unless ($sortorder) { $sortorder='realmstudent'; }
5586: &sortmenu($r,$sortorder);
5587: $r->print('</div></div>');
5588:
5589: $r->print('<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
5590:
5591: # Build the list data hash from the specified parms
5592:
5593: my $listdata;
5594: %{$listdata}=();
5595:
5596: foreach my $cat (@pscat) {
5597: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_sections,\%defkeytype,\%allmaps,\@ids,\%symbp);
5598: &secgroup_lister($cat,$pschp,$parmlev,$listdata,\@psprt,\@selected_groups,\%defkeytype,\%allmaps,\@ids,\%symbp);
5599: }
5600:
5601: if (($env{'form.store'}) || ($env{'form.dis'})) {
5602:
5603: if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
5604:
5605: # Read modified data
5606:
5607: my $resourcedata=&readdata($crs,$dom);
5608:
5609: # List data
5610:
5611: &listdata($r,$resourcedata,$listdata,$sortorder,'newoverview',undef,$readonly);
5612: }
5613: $r->print(&tableend());
5614: unless ($readonly) {
5615: $r->print( ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Save').'" /></p>':'') );
5616: }
5617: $r->print('</form>');
5618: &endSettingsScreen($r);
5619: $r->print(&Apache::loncommon::end_page());
5620: }
5621:
5622: # Fills $listdata with parameter information.
5623: # Keys use the format course id.[section id].part.name and course id.[section id].part.name.type.
5624: # The non-type value is always 1.
5625: #
5626: # @param {string} $cat - parameter name
5627: # @param {string} $pschp - selected map pc, or 'all'
5628: # @param {string} $parmlev - selected level value (full|map|general), or ''
5629: # @param {hash reference} $listdata - the parameter data that will be modified
5630: # @param {array reference} $psprt - selected parts
5631: # @param {array reference} $selections - selected sections
5632: # @param {hash reference} $defkeytype - hash parameter name -> parameter type
5633: # @param {hash reference} $allmaps - hash map pc -> map src
5634: # @param {array reference} $ids - resource and map ids
5635: # @param {hash reference} $symbp - hash map pc or resource/map id -> map src.'___(all)' or resource symb
5636: sub secgroup_lister {
5637: my ($cat,$pschp,$parmlev,$listdata,$psprt,$selections,$defkeytype,$allmaps,$ids,$symbp) = @_;
5638: foreach my $item (@{$selections}) {
5639: foreach my $part (@{$psprt}) {
5640: my $rootparmkey=$env{'request.course.id'};
5641: if (($item ne 'all') && ($item ne 'none') && ($item)) {
5642: $rootparmkey.='.['.$item.']';
5643: }
5644: if ($parmlev eq 'general') {
5645: # course-level parameter
5646: my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
5647: $$listdata{$newparmkey}=1;
5648: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
5649: } elsif ($parmlev eq 'map') {
5650: # map-level parameter
5651: foreach my $mapid (keys(%{$allmaps})) {
5652: if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
5653: my $newparmkey=$rootparmkey.'.'.$$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
5654: $$listdata{$newparmkey}=1;
5655: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
5656: }
5657: } else {
5658: # resource-level parameter
5659: foreach my $rid (@{$ids}) {
5660: my ($map,$resid,$url)=&Apache::lonnet::decode_symb($$symbp{$rid});
5661: if (($pschp ne 'all') && ($$allmaps{$pschp} ne $map)) { next; }
5662: my $newparmkey=$rootparmkey.'.'.$$symbp{$rid}.'.'.$part.'.'.$cat;
5663: $$listdata{$newparmkey}=1;
5664: $$listdata{$newparmkey.'.type'}=$$defkeytype{$cat};
5665: }
5666: }
5667: }
5668: }
5669: }
5670:
5671: # UI to edit parameter settings starting with a list of all existing parameters.
5672: # (called by setoverview action)
5673: #
5674: # @param {Apache2::RequestRec} $r - the Apache request
5675: sub overview {
5676: my ($r,$parm_permission) = @_;
5677: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5678: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
5679: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5680: my $readonly = 1;
5681: if ($parm_permission->{'edit'}) {
5682: undef($readonly);
5683: }
5684: my $js = '<script type="text/javascript">'."\n".
5685: '// <![CDATA['."\n".
5686: &toggleparmtextbox_js()."\n".
5687: &validateparms_js()."\n".
5688: &ipacc_boxes_js()."\n".
5689: &done_proctor_js()."\n".
5690: &deeplink_js()."\n".
5691: '// ]]>'."\n".
5692: '</script>'."\n";
5693: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview',
5694: text=>"Overview Mode"});
5695: my %loaditems = (
5696: 'onload' => "showHideLenient();",
5697: );
5698:
5699: my $start_page=&Apache::loncommon::start_page('Modify Parameters',$js,{'add_entries' => \%loaditems,});
5700: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview');
5701: $r->print($start_page.$breadcrumbs);
5702: &startSettingsScreen($r,'parmset',$crstype);
5703: $r->print('<form method="post" action="/adm/parmset?action=setoverview" name="parmform" onsubmit="return validateParms();">');
5704:
5705: # Store modified
5706:
5707: unless ($readonly) {
5708: &storedata($r,$crs,$dom);
5709: }
5710:
5711: # Read modified data
5712:
5713: my ($resourcedata,$classlist)=&readdata($crs,$dom);
5714:
5715:
5716: my $sortorder=$env{'form.sortorder'};
5717: unless ($sortorder) { $sortorder='realmstudent'; }
5718: &sortmenu($r,$sortorder);
5719:
5720: my $submitbutton = '<input type="submit" value="'.&mt('Save').'" />';
5721:
5722: if ($readonly) {
5723: $r->print('<p>'.$submitbutton.'</p>');
5724: }
5725:
5726: # List data
5727:
5728: my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder,'overview',$classlist,$readonly);
5729: $r->print(&tableend().'<p>');
5730: if ($foundkeys) {
5731: unless ($readonly) {
5732: $r->print('<p>'.$submitbutton.'</p>');
5733: }
5734: } else {
5735: $r->print('<p class="LC_info">'.&mt('There are no parameters.').'</p>');
5736: }
5737: $r->print('</form>'.&Apache::loncommon::end_page());
5738: }
5739:
5740: # Unused sub.
5741: #
5742: # @param {Apache2::RequestRec} $r - the Apache request
5743: sub clean_parameters {
5744: my ($r) = @_;
5745: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5746: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
5747:
5748: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=cleanparameters',
5749: text=>"Clean Parameters"});
5750: my $start_page=&Apache::loncommon::start_page('Clean Parameters');
5751: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Clean');
5752: $r->print(<<ENDOVER);
5753: $start_page
5754: $breadcrumbs
5755: <form method="post" action="/adm/parmset?action=cleanparameters" name="parmform">
5756: ENDOVER
5757: # Store modified
5758:
5759: &storedata($r,$crs,$dom);
5760:
5761: # Read modified data
5762:
5763: my $resourcedata=&readdata($crs,$dom);
5764:
5765: # List data
5766:
5767: $r->print('<h3>'.
5768: &mt('These parameters refer to resources that do not exist.').
5769: '</h3>'.
5770: '<input type="submit" value="'.&mt('Delete Selected').'" />'.'<br />'.
5771: '<br />');
5772: $r->print(&Apache::loncommon::start_data_table().
5773: '<tr>'.
5774: '<th>'.&mt('Delete').'</th>'.
5775: '<th>'.&mt('Parameter').'</th>'.
5776: '</tr>');
5777: foreach my $thiskey (sort(keys(%{$resourcedata}))) {
5778: next if (!exists($resourcedata->{$thiskey.'.type'})
5779: && $thiskey=~/\.type$/);
5780: my %data = &parse_key($thiskey);
5781: if (1) { #exists($data{'realm_exists'})
5782: #&& !$data{'realm_exists'}) {
5783: $r->print(&Apache::loncommon::start_data_table_row().
5784: '<tr>'.
5785: '<td><input type="checkbox" name="del_'.$thiskey.'" /></td>' );
5786:
5787: $r->print('<td>');
5788: my $display_value = $resourcedata->{$thiskey};
5789: if (&isdateparm($resourcedata->{$thiskey.'.type'})) {
5790: $display_value =
5791: &Apache::lonlocal::locallocaltime($display_value);
5792: }
5793: my $parmitem = &standard_parameter_names($data{'parameter_name'});
5794: $parmitem = &mt($parmitem);
5795: $r->print(&mt('Parameter: "[_1]" with value: "[_2]"',
5796: $parmitem,$resourcedata->{$thiskey}));
5797: $r->print('<br />');
5798: if ($data{'scope_type'} eq 'all') {
5799: $r->print(&mt('All users'));
5800: } elsif ($data{'scope_type'} eq 'user') {
5801: $r->print(&mt('User: [_1]',join(':',@{$data{'scope'}})));
5802: } elsif ($data{'scope_type'} eq 'secgroup') {
5803: $r->print(&mt('Group/Section: [_1]',$data{'scope'}));
5804: }
5805: $r->print('<br />');
5806: if ($data{'realm_type'} eq 'all') {
5807: $r->print(&mt('All Resources'));
5808: } elsif ($data{'realm_type'} eq 'folder') {
5809: $r->print(&mt('Folder: [_1]'),$data{'realm'});
5810: } elsif ($data{'realm_type'} eq 'symb') {
5811: my ($map,$resid,$url) =
5812: &Apache::lonnet::decode_symb($data{'realm'});
5813: $r->print(&mt('Resource: [_1]with ID: [_2]in folder [_3]',
5814: $url.' <br /> ',
5815: $resid.' <br /> ',$map));
5816: }
5817: $r->print(' <br /> '.&mt('Part: [_1]',$data{'parameter_part'}));
5818: $r->print('</td></tr>');
5819:
5820: }
5821: }
5822: $r->print(&Apache::loncommon::end_data_table().'<p>'.
5823: '<input type="submit" value="'.&mt('Delete Selected').'" />'.
5824: '</p></form>');
5825: &endSettingsScreen($r);
5826: $r->print(&Apache::loncommon::end_page());
5827: }
5828:
5829: # UI to shift all dates (called by dateshift1 action).
5830: # Used by overview mode.
5831: #
5832: # @param {Apache2::RequestRec} $r - the Apache request
5833: sub date_shift_one {
5834: my ($r) = @_;
5835: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5836: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
5837: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5838: my $sec = $env{'request.course.sec'};
5839: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
5840: text=>"Shifting Dates"});
5841: my $submit_text = &mt('Shift all dates accordingly');
5842: if ($sec ne '') {
5843: $submit_text = &mt("Shift all dates set explicitly for section '[_1]', accordingly",$sec);
5844: }
5845: my $start_page=&Apache::loncommon::start_page('Shift Dates');
5846: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
5847: $r->print($start_page.$breadcrumbs);
5848: &startSettingsScreen($r,'parmset',$crstype);
5849: $r->print('<form name="shiftform" method="post" action="">'.
5850: '<table><tr><td>'.&mt('Currently set date:').'</td><td>'.
5851: &Apache::lonlocal::locallocaltime($env{'form.timebase'}).'</td></tr>'.
5852: '<tr><td>'.&mt('Shifted date:').'</td><td>'.
5853: &Apache::lonhtmlcommon::date_setter('shiftform',
5854: 'timeshifted',
5855: $env{'form.timebase'},,
5856: '').
5857: '</td></tr></table>'.
5858: '<input type="hidden" name="action" value="dateshift2" />'.
5859: '<input type="hidden" name="timebase" value="'.$env{'form.timebase'}.'" />'.
5860: '<input type="submit" value="'.$submit_text.'" /></form>');
5861: &endSettingsScreen($r);
5862: $r->print(&Apache::loncommon::end_page());
5863: }
5864:
5865: # UI to shift all dates (second form).
5866: #
5867: # @param {Apache2::RequestRec} $r - the Apache request
5868: sub date_shift_two {
5869: my ($r) = @_;
5870: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5871: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
5872: my $sec = $env{'request.course.sec'};
5873: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5874: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=dateshift1&timebase='.$env{'form.timebase'},
5875: text=>"Shifting Dates"});
5876: my $start_page=&Apache::loncommon::start_page('Shift Dates');
5877: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Shift');
5878: $r->print($start_page.$breadcrumbs);
5879: &startSettingsScreen($r,'parmset',$crstype);
5880: my $timeshifted=&Apache::lonhtmlcommon::get_date_from_form('timeshifted');
5881: $r->print('<h2>'.&mt('Shift Dates').'</h2>');
5882: if ($sec ne '') {
5883: $r->print('<p>'.
5884: &mt("Shift all dates set explicitly for section '[_1]', such that [_2] becomes [_3]",
5885: $sec,&Apache::lonlocal::locallocaltime($env{'form.timebase'}),
5886: &Apache::lonlocal::locallocaltime($timeshifted)).
5887: '</p>');
5888: } else {
5889: $r->print('<p>'.&mt('Shifting all dates such that [_1] becomes [_2]',
5890: &Apache::lonlocal::locallocaltime($env{'form.timebase'}),
5891: &Apache::lonlocal::locallocaltime($timeshifted)).
5892: '</p>');
5893: }
5894: my $delta=$timeshifted-$env{'form.timebase'};
5895: my $numchanges = 0;
5896: my $result = &dateshift($delta,\$numchanges);
5897: if ($result eq 'ok') {
5898: $r->print(
5899: &Apache::lonhtmlcommon::confirm_success(&mt('Completed shifting of [quant,_1,date setting]',
5900: $numchanges)));
5901: } elsif ($result eq 'con_delayed') {
5902: $r->print(
5903: &Apache::lonhtmlcommon::confirm_success(&mt('Queued shifting of [quant,_1,date setting]',
5904: $numchanges)));
5905: } else {
5906: $r->print(
5907: &Apache::lonhtmlcommon::confirm_success(&mt('An error occurred attempting to shift dates'),1));
5908: }
5909: $r->print(
5910: '<br /><br />'.
5911: &Apache::lonhtmlcommon::actionbox(
5912: ['<a href="/adm/parmset">'.&mt('Content and Problem Settings').'</a>']));
5913: &endSettingsScreen($r);
5914: $r->print(&Apache::loncommon::end_page());
5915: }
5916:
5917: # Returns the different components of a resourcedata key.
5918: # Keys: scope_type, scope, realm_type, realm, realm_title,
5919: # realm_exists, parameter_part, parameter_name.
5920: # Was used by clean_parameters (which is unused).
5921: #
5922: # @param {string} $key - the parameter key
5923: # @returns {hash}
5924: sub parse_key {
5925: my ($key) = @_;
5926: my %data;
5927: my ($middle,$part,$name)=
5928: ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
5929: $data{'scope_type'} = 'all';
5930: if ($middle=~/^\[(.*)\]/) {
5931: $data{'scope'} = $1;
5932: if ($data{'scope'}=~/^useropt\:($match_username)\:($match_domain)/) {
5933: $data{'scope_type'} = 'user';
5934: $data{'scope'} = [$1,$2];
5935: } else {
5936: $data{'scope_type'} = 'secgroup';
5937: }
5938: $middle=~s/^\[(.*)\]//;
5939: }
5940: $middle=~s/\.+$//;
5941: $middle=~s/^\.+//;
5942: $data{'realm_type'}='all';
5943: if ($middle=~/^(.+)\_\_\_\(all\)$/) {
5944: $data{'realm'} = $1;
5945: $data{'realm_type'} = 'folder';
5946: $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
5947: ($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
5948: } elsif ($middle) {
5949: $data{'realm'} = $middle;
5950: $data{'realm_type'} = 'symb';
5951: $data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
5952: my ($map,$resid,$url) = &Apache::lonnet::decode_symb($data{'realm'});
5953: $data{'realm_exists'} = &Apache::lonnet::symbverify($data{'realm'},$url);
5954: }
5955:
5956: $data{'parameter_part'} = $part;
5957: $data{'parameter_name'} = $name;
5958:
5959: return %data;
5960: }
5961:
5962:
5963: # Calls loncommon::start_page with the "Settings" title.
5964: sub header {
5965: return &Apache::loncommon::start_page('Settings');
5966: }
5967:
5968:
5969:
5970: ##################################################
5971: # MAIN MENU
5972: ##################################################
5973:
5974: # Content and problem settings main menu.
5975: #
5976: # @param {Apache2::RequestRec} $r - the Apache request
5977: # @param {boolean} $parm_permission - true if the user has permission to edit the current course or section
5978: sub print_main_menu {
5979: my ($r,$parm_permission)=@_;
5980: #
5981: $r->print(&header());
5982: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content and Problem Settings'));
5983: my $crstype = &Apache::loncommon::course_type();
5984: my $lc_crstype = lc($crstype);
5985:
5986: &startSettingsScreen($r,'parmset',$crstype);
5987: $r->print(<<ENDMAINFORMHEAD);
5988: <form method="post" enctype="multipart/form-data"
5989: action="/adm/parmset" name="studentform">
5990: ENDMAINFORMHEAD
5991: #
5992: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5993: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5994: my $vgr = &Apache::lonnet::allowed('vgr',$env{'request.course.id'});
5995: my $mgr = &Apache::lonnet::allowed('mgr',$env{'request.course.id'});
5996: my $dcm = &Apache::lonnet::allowed('dcm',$env{'request.course.id'});
5997: my $vcb = &Apache::lonnet::allowed('vcb',$env{'request.course.id'});
5998: my $vpa = &Apache::lonnet::allowed('vpa',$env{'request.course.id'});
5999: if ((!$dcm) && ($env{'request.course.sec'} ne '')) {
6000: $dcm = &Apache::lonnet::allowed('dcm',$env{'request.course.id'}.
6001: '/'.$env{'request.course.sec'});
6002: }
6003: if ((!$vcb) && ($env{'request.course.sec'} ne '')) {
6004: $vcb = &Apache::lonnet::allowed('vcb',$env{'request.course.id'}.
6005: '/'.$env{'request.course.sec'});
6006: }
6007: my (%linktext,%linktitle,%url);
6008: if ($parm_permission->{'edit'}) {
6009: %linktext = (
6010: newoverview => 'Edit Resource Parameters - Overview Mode',
6011: settable => 'Edit Resource Parameters - Table Mode',
6012: setoverview => 'Modify Resource Parameters - Overview Mode',
6013: );
6014: %linktitle = (
6015: newoverview => 'Set/Modify resource parameters in overview mode.',
6016: settable => 'Set/Modify resource parameters in table mode.',
6017: setoverview => 'Set/Modify existing resource parameters in overview mode.',
6018: );
6019: } else {
6020: %linktext = (
6021: newoverview => 'View Resource Parameters - Overview Mode',
6022: settable => 'View Resource Parameters - Table Mode',
6023: setoverview => 'View Resource Parameters - Overview Mode',
6024: );
6025: %linktitle = (
6026: newoverview => 'Display resource parameters in overview mode.',
6027: settable => 'Display resource parameters in table mode.',
6028: setoverview => 'Display existing resource parameters in overview mode.',
6029: );
6030: }
6031: if ($mgr) {
6032: $linktext{'resettimes'} = 'Reset Student Access Times';
6033: $linktitle{'resettimes'} = "Reset access times for folders/maps, resources or the $lc_crstype.";
6034: $url{'resettimes'} = '/adm/helper/resettimes.helper';
6035: } elsif ($vgr) {
6036: $linktext{'resettimes'} = 'Display Student Access Times',
6037: $linktitle{'resettimes'} = "Display access times for folders/maps, resources or the $lc_crstype.",
6038: $url{'resettimes'} = '/adm/accesstimes';
6039: }
6040: my @menu =
6041: ( { categorytitle=>"Content Settings for this $crstype",
6042: items => [
6043: { linktext => 'Portfolio Metadata',
6044: url => '/adm/parmset?action=setrestrictmeta',
6045: permission => $parm_permission->{'setrestrictmeta'},
6046: linktitle => "Restrict metadata for this $lc_crstype." ,
6047: icon =>'contact-new.png' ,
6048: },
6049: { linktext => $linktext{'resettimes'},
6050: url => $url{'resettimes'},
6051: permission => ($vgr || $mgr),
6052: linktitle => $linktitle{'resettimes'},
6053: icon => 'start-here.png',
6054: },
6055: { linktext => 'Blocking Communication/Resource Access',
6056: url => '/adm/setblock',
6057: permission => ($vcb || $dcm),
6058: linktitle => 'Configure blocking of communication/collaboration and access to resources during an exam',
6059: icon => 'comblock.png',
6060: },
6061: { linktext => 'Set Parameter Setting Default Actions',
6062: url => '/adm/parmset?action=setdefaults',
6063: permission => $parm_permission->{'setdefaults'},
6064: linktitle =>'Set default actions for parameters.' ,
6065: icon => 'folder-new.png' ,
6066: }]},
6067: { categorytitle => 'New and Existing Parameter Settings for Resources',
6068: items => [
6069: { linktext => 'Edit Resource Parameters - Helper Mode',
6070: url => '/adm/helper/parameter.helper',
6071: permission => $parm_permission->{'helper'},
6072: linktitle =>'Set/Modify resource parameters in helper mode.' ,
6073: icon => 'dialog-information.png' ,
6074: #help => 'Parameter_Helper',
6075: },
6076: { linktext => $linktext{'newoverview'},
6077: url => '/adm/parmset?action=newoverview',
6078: permission => $parm_permission->{'newoverview'},
6079: linktitle => $linktitle{'newoverview'},
6080: icon => 'edit-find.png',
6081: #help => 'Parameter_Overview',
6082: },
6083: { linktext => $linktext{'settable'},
6084: url => '/adm/parmset?action=settable',
6085: permission => $parm_permission->{'settable'},
6086: linktitle => $linktitle{'settable'},
6087: icon => 'edit-copy.png',
6088: #help => 'Table_Mode',
6089: }]},
6090: { categorytitle => 'Existing Parameter Settings for Resources',
6091: items => [
6092: { linktext => $linktext{'setoverview'},
6093: url => '/adm/parmset?action=setoverview',
6094: permission => $parm_permission->{'setoverview'},
6095: linktitle => $linktitle{'setoverview'},
6096: icon => 'preferences-desktop-wallpaper.png',
6097: #help => 'Parameter_Overview',
6098: },
6099: { linktext => 'Change Log',
6100: url => '/adm/parmset?action=parameterchangelog',
6101: permission => $parm_permission->{'parameterchangelog'},
6102: linktitle =>"View parameter and $lc_crstype blog posting/user notification change log." ,
6103: icon => 'document-properties.png',
6104: }]}
6105: );
6106: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
6107: $r->print('</form>');
6108: &endSettingsScreen($r);
6109: $r->print(&Apache::loncommon::end_page());
6110: return;
6111: }
6112:
6113:
6114:
6115: ##################################################
6116: # PORTFOLIO METADATA
6117: ##################################################
6118:
6119: # Prints HTML to edit an item of portfolio metadata. The HTML contains several td elements (no tr).
6120: # It looks like field titles are not localized.
6121: #
6122: # @param {Apache2::RequestRec} $r - the Apache request
6123: # @param {string} $field_name - metadata field name
6124: # @param {string} $field_text - metadata field title, in English unless manually added
6125: # @param {boolean} $added_flag - true if the field was manually added
6126: sub output_row {
6127: my ($r, $field_name, $field_text, $added_flag) = @_;
6128: my $output;
6129: my $options=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'};
6130: my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.values'};
6131: if (!defined($options)) {
6132: $options = 'active,stuadd';
6133: $values = '';
6134: }
6135: if (!($options =~ /deleted/)) {
6136: my @options= ( ['active', 'Show to student'],
6137: ['stuadd', 'Provide text area for students to type metadata'],
6138: ['choices','Provide choices for students to select from']);
6139: # ['onlyone','Student may select only one choice']);
6140: if ($added_flag) {
6141: push @options,['deleted', 'Delete Metadata Field'];
6142: }
6143: $output = &Apache::loncommon::start_data_table_row();
6144: $output .= '<td><strong>'.$field_text.':</strong></td>';
6145: $output .= &Apache::loncommon::end_data_table_row();
6146: foreach my $opt (@options) {
6147: my $checked = ($options =~ m/$opt->[0]/) ? ' checked="checked" ' : '' ;
6148: $output .= &Apache::loncommon::continue_data_table_row();
6149: $output .= '<td>'.(' ' x 5).'<label>
6150: <input type="checkbox" name="'.
6151: $field_name.'_'.$opt->[0].'" value="yes"'.$checked.' />'.
6152: &mt($opt->[1]).'</label></td>';
6153: $output .= &Apache::loncommon::end_data_table_row();
6154: }
6155: $output .= &Apache::loncommon::continue_data_table_row();
6156: $output .= '<td>'.(' ' x 10).'<input name="'.$field_name.'_values" type="text" value="'.$values.'" size="80" /></td>';
6157: $output .= &Apache::loncommon::end_data_table_row();
6158: my $multiple_checked;
6159: my $single_checked;
6160: if ($options =~ m/onlyone/) {
6161: $multiple_checked = '';
6162: $single_checked = ' checked="checked"';
6163: } else {
6164: $multiple_checked = ' checked="checked"';
6165: $single_checked = '';
6166: }
6167: $output .= &Apache::loncommon::continue_data_table_row();
6168: $output .= '<td>'.(' ' x 10).'
6169: <input type="radio" name="'.$field_name.'_onlyone" value="multiple"'.$multiple_checked .' />
6170: '.&mt('Student may select multiple choices from list').'</td>';
6171: $output .= &Apache::loncommon::end_data_table_row();
6172: $output .= &Apache::loncommon::continue_data_table_row();
6173: $output .= '<td>'.(' ' x 10).'
6174: <input type="radio" name="'.$field_name.'_onlyone" value="single"'.$single_checked.' />
6175: '.&mt('Student may select only one choice from list').'</td>';
6176: $output .= &Apache::loncommon::end_data_table_row();
6177: }
6178: return ($output);
6179: }
6180:
6181:
6182: # UI to order portfolio metadata fields.
6183: # Currently useless because addmetafield does not work.
6184: #
6185: # @param {Apache2::RequestRec} $r - the Apache request
6186: sub order_meta_fields {
6187: my ($r)=@_;
6188: my $idx = 1;
6189: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6190: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
6191: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};;
6192: $r->print(&Apache::loncommon::start_page('Order Metadata Fields'));
6193: &Apache::lonhtmlcommon::add_breadcrumb(
6194: {href=>'/adm/parmset?action=addmetadata',
6195: text=>"Add Metadata Field"});
6196: &Apache::lonhtmlcommon::add_breadcrumb(
6197: {href=>"/adm/parmset?action=setrestrictmeta",
6198: text=>"Restrict Metadata"},
6199: {text=>"Order Metadata"});
6200: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Order Metadata'));
6201: &startSettingsScreen($r,'parmset',$crstype);
6202: if ($env{'form.storeorder'}) {
6203: my $newpos = $env{'form.newpos'} - 1;
6204: my $currentpos = $env{'form.currentpos'} - 1;
6205: my @neworder = ();
6206: my @oldorder = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'});
6207: my $i;
6208: if ($newpos > $currentpos) {
6209: # moving stuff up
6210: for ($i=0;$i<$currentpos;$i++) {
6211: $neworder[$i]=$oldorder[$i];
6212: }
6213: for ($i=$currentpos;$i<$newpos;$i++) {
6214: $neworder[$i]=$oldorder[$i+1];
6215: }
6216: $neworder[$newpos]=$oldorder[$currentpos];
6217: for ($i=$newpos+1;$i<=$#oldorder;$i++) {
6218: $neworder[$i]=$oldorder[$i];
6219: }
6220: } else {
6221: # moving stuff down
6222: for ($i=0;$i<$newpos;$i++) {
6223: $neworder[$i]=$oldorder[$i];
6224: }
6225: $neworder[$newpos]=$oldorder[$currentpos];
6226: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
6227: $neworder[$i]=$oldorder[$i-1];
6228: }
6229: for ($i=$currentpos+1;$i<=$#oldorder;$i++) {
6230: $neworder[$i]=$oldorder[$i];
6231: }
6232: }
6233: my $ordered_fields = join ",", @neworder;
6234: my $put_result = &Apache::lonnet::put('environment',
6235: {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
6236: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields});
6237: }
6238: my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
6239: my $ordered_fields;
6240: my @fields_in_order = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'});
6241: if (!@fields_in_order) {
6242: # no order found, pick sorted order then create metadata.addedorder key.
6243: foreach my $key (sort(keys(%$fields))) {
6244: push @fields_in_order, $key;
6245: $ordered_fields = join ",", @fields_in_order;
6246: }
6247: my $put_result = &Apache::lonnet::put('environment',
6248: {'metadata.addedorder'=>$ordered_fields},$dom,$crs);
6249: }
6250: $r->print('<table>');
6251: my $num_fields = scalar(@fields_in_order);
6252: foreach my $key (@fields_in_order) {
6253: $r->print('<tr><td>');
6254: $r->print('<form method="post" action="">');
6255: $r->print('<select name="newpos" onchange="this.form.submit()">');
6256: for (my $i = 1;$i le $num_fields;$i ++) {
6257: if ($i eq $idx) {
6258: $r->print('<option value="'.$i.'" SELECTED>('.$i.')</option>');
6259: } else {
6260: $r->print('<option value="'.$i.'">'.$i.'</option>');
6261: }
6262: }
6263: $r->print('</select></td><td>');
6264: $r->print('<input type="hidden" name="currentpos" value="'.$idx.'" />');
6265: $r->print('<input type="hidden" name="storeorder" value="true" />');
6266: $r->print('</form>');
6267: $r->print($$fields{$key}.'</td></tr>');
6268: $idx ++;
6269: }
6270: $r->print('</table>');
6271: &endSettingsScreen($r);
6272: return 'ok';
6273: }
6274:
6275:
6276: # Returns HTML with a Continue button redirecting to the initial portfolio metadata screen.
6277: # @returns {string}
6278: sub continue {
6279: my $output;
6280: $output .= '<form action="" method="post">';
6281: $output .= '<input type="hidden" name="action" value="setrestrictmeta" />';
6282: $output .= '<input type="submit" value="'.&mt('Continue').'" />';
6283: return ($output);
6284: }
6285:
6286:
6287: # UI to add a metadata field.
6288: # Currenly does not work because of an HTML error (the field is not visible).
6289: #
6290: # @param {Apache2::RequestRec} $r - the Apache request
6291: sub addmetafield {
6292: my ($r)=@_;
6293: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=addmetadata',
6294: text=>"Add Metadata Field"});
6295: $r->print(&Apache::loncommon::start_page('Add Metadata Field'));
6296: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
6297: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6298: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
6299: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6300: &startSettingsScreen($r,'parmset',$crstype);
6301: if (exists($env{'form.undelete'})) {
6302: my @meta_fields = &Apache::loncommon::get_env_multiple('form.undeletefield');
6303: foreach my $meta_field(@meta_fields) {
6304: my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};
6305: $options =~ s/deleted//;
6306: $options =~ s/,,/,/;
6307: my $put_result = &Apache::lonnet::put('environment',
6308: {'metadata.'.$meta_field.'.options'=>$options},$dom,$crs);
6309:
6310: $r->print(&mt('Undeleted Metadata Field [_1] with result [_2]',
6311: '<strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}.
6312: '</strong>',$put_result).
6313: '<br />');
6314: }
6315: $r->print(&continue());
6316: } elsif (exists($env{'form.fieldname'})) {
6317: my $meta_field = $env{'form.fieldname'};
6318: my $display_field = $env{'form.fieldname'};
6319: $meta_field =~ s/\W/_/g;
6320: $meta_field =~ tr/A-Z/a-z/;
6321: my $put_result = &Apache::lonnet::put('environment',
6322: {'metadata.'.$meta_field.'.values'=>"",
6323: 'metadata.'.$meta_field.'.added'=>"$display_field",
6324: 'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
6325: $r->print(&mt('Added new Metadata Field [_1] with result [_2]',
6326: '<strong>'.$env{'form.fieldname'}.'</strong>',$put_result).
6327: '<br />');
6328: $r->print(&continue());
6329: } else {
6330: my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'});
6331: if ($fields) {
6332: $r->print(&mt('You may undelete previously deleted fields.').
6333: '<br />'.
6334: &mt('Check those you wish to undelete and click Undelete.').
6335: '<br />');
6336: $r->print('<form method="post" action="">');
6337: foreach my $key(keys(%$fields)) {
6338: $r->print('<label><input type="checkbox" name="undeletefield" value="'.$key.'" />'.$$fields{$key}.'</label><br /');
6339: }
6340: $r->print('<input type="submit" name="undelete" value="'.&mt('Undelete').'" />');
6341: $r->print('</form>');
6342: }
6343: $r->print('<hr />'.
6344: &mt('[_1]Or[_2] you may enter a new metadata field name.',
6345: '<strong>','</strong>').
6346: '<form method="post" action="/adm/parmset?action=addmetadata">');
6347: $r->print('<input type="text" name="fieldname" /><br />');
6348: $r->print('<input type="submit" value="'.&mt('Add Metadata Field').'" />');
6349: $r->print('</form>');
6350: }
6351: &endSettingsScreen($r);
6352: }
6353:
6354:
6355:
6356: # Display or save portfolio metadata.
6357: #
6358: # @param {Apache2::RequestRec} $r - the Apache request
6359: sub setrestrictmeta {
6360: my ($r)=@_;
6361: my $next_meta;
6362: my $output;
6363: my $item_num;
6364: my $put_result;
6365: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setrestrictmeta',
6366: text=>"Restrict Metadata"});
6367: $r->print(&Apache::loncommon::start_page('Restrict Metadata'));
6368: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Restrict Metadata'));
6369: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6370: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
6371: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6372: &startSettingsScreen($r,'parmset',$crstype);
6373: my $key_base = $env{'course.'.$env{'request.course.id'}.'.'};
6374: my $save_field = '';
6375: my %lt = &Apache::lonlocal::texthash(
6376: addm => 'Add Metadata Field',
6377: ordm => 'Order Metadata Fields',
6378: save => 'Save',
6379: );
6380: if ($env{'form.restrictmeta'}) {
6381: foreach my $field (sort(keys(%env))) {
6382: if ($field=~m/^form.(.+)_(.+)$/) {
6383: my $options;
6384: my $meta_field = $1;
6385: my $meta_key = $2;
6386: if ($save_field ne $meta_field) {
6387: $save_field = $meta_field;
6388: if ($env{'form.'.$meta_field.'_stuadd'}) {
6389: $options.='stuadd,';
6390: }
6391: if ($env{'form.'.$meta_field.'_choices'}) {
6392: $options.='choices,';
6393: }
6394: if ($env{'form.'.$meta_field.'_onlyone'} eq 'single') {
6395: $options.='onlyone,';
6396: }
6397: if ($env{'form.'.$meta_field.'_active'}) {
6398: $options.='active,';
6399: }
6400: if ($env{'form.'.$meta_field.'_deleted'}) {
6401: $options.='deleted,';
6402: }
6403: my $name = $save_field;
6404: $put_result = &Apache::lonnet::put('environment',
6405: {'metadata.'.$meta_field.'.options'=>$options,
6406: 'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
6407: },$dom,$crs);
6408: }
6409: }
6410: }
6411: }
6412: &Apache::lonnet::coursedescription($env{'request.course.id'},
6413: {'freshen_cache' => 1});
6414: # Get the default metadata fields
6415: my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
6416: # Now get possible added metadata fields
6417: my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
6418: $output .= &Apache::loncommon::start_data_table();
6419: foreach my $field (sort(keys(%metadata_fields))) {
6420: if ($field ne 'courserestricted') {
6421: $output.= &output_row($r,$field,$metadata_fields{$field});
6422: }
6423: }
6424: my $buttons = (<<ENDButtons);
6425: <input type="submit" name="restrictmeta" value="$lt{'save'}" />
6426: </form><br />
6427: <form method="post" action="/adm/parmset?action=addmetadata" name="form1">
6428: <input type="submit" name="restrictmeta" value="$lt{'addm'}" />
6429: </form>
6430: <br />
6431: <form method="post" action="/adm/parmset?action=ordermetadata" name="form2">
6432: <input type="submit" name="restrictmeta" value="$lt{'ordm'}" />
6433: ENDButtons
6434: my $added_flag = 1;
6435: foreach my $field (sort(keys(%$added_metadata_fields))) {
6436: $output.= &output_row($r,$field,$$added_metadata_fields{$field},$added_flag);
6437: }
6438: $output .= &Apache::loncommon::end_data_table();
6439: $r->print(<<ENDenv);
6440: <form method="post" action="/adm/parmset?action=setrestrictmeta" name="form">
6441: $output
6442: $buttons
6443: </form>
6444: ENDenv
6445: &endSettingsScreen($r);
6446: $r->print(&Apache::loncommon::end_page());
6447: return 'ok';
6448: }
6449:
6450:
6451: # Returns metadata fields that have been manually added.
6452: #
6453: # @param {string} $cid - course id
6454: # @returns {hash reference} - hash field name -> field title (not localized)
6455: sub get_added_meta_fieldnames {
6456: my ($cid) = @_;
6457: my %fields;
6458: foreach my $key(%env) {
6459: if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
6460: my $field_name = $1;
6461: my ($display_field_name) = $env{$key};
6462: $fields{$field_name} = $display_field_name;
6463: }
6464: }
6465: return \%fields;
6466: }
6467:
6468:
6469: # Returns metadata fields that have been manually added and deleted.
6470: #
6471: # @param {string} $cid - course id
6472: # @returns {hash reference} - hash field name -> field title (not localized)
6473: sub get_deleted_meta_fieldnames {
6474: my ($cid) = @_;
6475: my %fields;
6476: foreach my $key(%env) {
6477: if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
6478: my $field_name = $1;
6479: if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
6480: my ($display_field_name) = $env{$key};
6481: $fields{$field_name} = $display_field_name;
6482: }
6483: }
6484: }
6485: return \%fields;
6486: }
6487:
6488:
6489: ##################################################
6490: # PARAMETER SETTINGS DEFAULT ACTIONS
6491: ##################################################
6492:
6493: # UI to change parameter setting default actions
6494: #
6495: # @param {Apache2::RequestRec} $r - the Apache request
6496: sub defaultsetter {
6497: my ($r) = @_;
6498:
6499: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setdefaults',
6500: text=>"Set Defaults"});
6501: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6502: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6503: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6504: my $start_page =
6505: &Apache::loncommon::start_page('Parameter Setting Default Actions');
6506: my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Defaults');
6507: $r->print($start_page.$breadcrumbs);
6508: &startSettingsScreen($r,'parmset',$crstype);
6509: $r->print('<form method="post" action="/adm/parmset?action=setdefaults" name="defaultform">');
6510:
6511: my @ids=();
6512: my %typep=();
6513: my %keyp=();
6514: my %allparms=();
6515: my %allparts=();
6516: my %allmaps=();
6517: my %mapp=();
6518: my %symbp=();
6519: my %maptitles=();
6520: my %uris=();
6521: my %keyorder=&standardkeyorder();
6522: my %defkeytype=();
6523:
6524: &extractResourceInformation(\@ids, \%typep,\%keyp, \%allparms, \%allparts, \%allmaps,
6525: \%mapp, \%symbp,\%maptitles,\%uris,
6526: \%keyorder,\%defkeytype);
6527: if ($env{'form.storerules'}) {
6528: my %newrules=();
6529: my @delrules=();
6530: my %triggers=();
6531: foreach my $key (keys(%env)) {
6532: if ($key=~/^form\.(\w+)\_action$/) {
6533: my $tempkey=$1;
6534: my $action=$env{$key};
6535: if ($action) {
6536: $newrules{$tempkey.'_action'}=$action;
6537: if ($action ne 'default') {
6538: my ($whichaction,$whichparm)=($action=~/^(.*\_)([^\_]+)$/);
6539: $triggers{$whichparm}.=$tempkey.':';
6540: }
6541: $newrules{$tempkey.'_type'}=$defkeytype{$tempkey};
6542: if (&isdateparm($defkeytype{$tempkey})) {
6543: $newrules{$tempkey.'_days'}=$env{'form.'.$tempkey.'_days'};
6544: $newrules{$tempkey.'_hours'}=$env{'form.'.$tempkey.'_hours'};
6545: $newrules{$tempkey.'_min'}=$env{'form.'.$tempkey.'_min'};
6546: $newrules{$tempkey.'_sec'}=$env{'form.'.$tempkey.'_sec'};
6547: } else {
6548: $newrules{$tempkey.'_value'}=$env{'form.'.$tempkey.'_value'};
6549: $newrules{$tempkey.'_triggervalue'}=$env{'form.'.$tempkey.'_triggervalue'};
6550: }
6551: } else {
6552: push(@delrules,$tempkey.'_action');
6553: push(@delrules,$tempkey.'_type');
6554: push(@delrules,$tempkey.'_hours');
6555: push(@delrules,$tempkey.'_min');
6556: push(@delrules,$tempkey.'_sec');
6557: push(@delrules,$tempkey.'_value');
6558: }
6559: }
6560: }
6561: foreach my $key (keys(%allparms)) {
6562: $newrules{$key.'_triggers'}=$triggers{$key};
6563: }
6564: &Apache::lonnet::put('parmdefactions',\%newrules,$cdom,$cnum);
6565: &Apache::lonnet::del('parmdefactions',\@delrules,$cdom,$cnum);
6566: &resetrulescache();
6567: }
6568: my %lt=&Apache::lonlocal::texthash('days' => 'Days',
6569: 'hours' => 'Hours',
6570: 'min' => 'Minutes',
6571: 'sec' => 'Seconds',
6572: 'yes' => 'Yes',
6573: 'no' => 'No');
6574: my @standardoptions=('','default');
6575: my @standarddisplay=('',&mt('Default value when manually setting'));
6576: my @dateoptions=('','default');
6577: my @datedisplay=('',&mt('Default value when manually setting'));
6578: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
6579: unless ($tempkey) { next; }
6580: push @standardoptions,'when_setting_'.$tempkey;
6581: push @standarddisplay,&mt('Automatically set when setting ').$tempkey;
6582: if (&isdateparm($defkeytype{$tempkey})) {
6583: push @dateoptions,'later_than_'.$tempkey;
6584: push @datedisplay,&mt('Automatically set later than ').$tempkey;
6585: push @dateoptions,'earlier_than_'.$tempkey;
6586: push @datedisplay,&mt('Automatically set earlier than ').$tempkey;
6587: }
6588: }
6589: $r->print(&mt('Manual setting rules apply to all interfaces.').'<br />'.
6590: &mt('Automatic setting rules apply to table mode interfaces only.'));
6591: $r->print("\n".&Apache::loncommon::start_data_table().
6592: &Apache::loncommon::start_data_table_header_row().
6593: "<th>".&mt('Rule for parameter').'</th><th>'.
6594: &mt('Action').'</th><th>'.&mt('Value').'</th>'.
6595: &Apache::loncommon::end_data_table_header_row());
6596: foreach my $tempkey (&keysindisplayorder(\%allparms,\%keyorder)) {
6597: unless ($tempkey) { next; }
6598: $r->print("\n".&Apache::loncommon::start_data_table_row().
6599: "<td>".$allparms{$tempkey}."\n<br />(".$tempkey.')</td><td>');
6600: my $action=&rulescache($tempkey.'_action');
6601: $r->print('<select name="'.$tempkey.'_action">');
6602: if (&isdateparm($defkeytype{$tempkey})) {
6603: for (my $i=0;$i<=$#dateoptions;$i++) {
6604: if ($dateoptions[$i]=~/\_$tempkey$/) { next; }
6605: $r->print("\n<option value='$dateoptions[$i]'".
6606: ($dateoptions[$i] eq $action?' selected="selected"':'').
6607: ">$datedisplay[$i]</option>");
6608: }
6609: } else {
6610: for (my $i=0;$i<=$#standardoptions;$i++) {
6611: if ($standardoptions[$i]=~/\_$tempkey$/) { next; }
6612: $r->print("\n<option value='$standardoptions[$i]'".
6613: ($standardoptions[$i] eq $action?' selected="selected"':'').
6614: ">$standarddisplay[$i]</option>");
6615: }
6616: }
6617: $r->print('</select>');
6618: unless (&isdateparm($defkeytype{$tempkey})) {
6619: $r->print("\n<br />".&mt('Triggering value(s) of other parameter (optional, comma-separated):').
6620: '<input type="text" size="20" name="'.$tempkey.'_triggervalue" value="'.&rulescache($tempkey.'_triggervalue').'" />');
6621: }
6622: $r->print("\n</td><td>\n");
6623:
6624: if (&isdateparm($defkeytype{$tempkey})) {
6625: my $days=&rulescache($tempkey.'_days');
6626: my $hours=&rulescache($tempkey.'_hours');
6627: my $min=&rulescache($tempkey.'_min');
6628: my $sec=&rulescache($tempkey.'_sec');
6629: $r->print(<<ENDINPUTDATE);
6630: <input name="$tempkey\_days" type="text" size="4" value="$days" />$lt{'days'}<br />
6631: <input name="$tempkey\_hours" type="text" size="4" value="$hours" />$lt{'hours'}<br />
6632: <input name="$tempkey\_min" type="text" size="4" value="$min" />$lt{'min'}<br />
6633: <input name="$tempkey\_sec" type="text" size="4" value="$sec" />$lt{'sec'}
6634: ENDINPUTDATE
6635: } elsif ($defkeytype{$tempkey} eq 'string_yesno') {
6636: my $yeschecked='';
6637: my $nochecked='';
6638: if (&rulescache($tempkey.'_value') eq 'yes') { $yeschecked=' checked="checked"'; }
6639: if (&rulescache($tempkey.'_value') eq 'no') { $nochecked=' checked="checked"'; }
6640:
6641: $r->print(<<ENDYESNO);
6642: <label><input type="radio" name="$tempkey\_value" value="yes"$yeschecked /> $lt{'yes'}</label><br />
6643: <label><input type="radio" name="$tempkey\_value" value="no"$nochecked /> $lt{'no'}</label>
6644: ENDYESNO
6645: } else {
6646: $r->print('<input type="text" size="20" name="'.$tempkey.'_value" value="'.&rulescache($tempkey.'_value').'" />');
6647: }
6648: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
6649: }
6650: $r->print(&Apache::loncommon::end_data_table().
6651: "\n".'<input type="submit" name="storerules" value="'.
6652: &mt('Save').'" /></form>'."\n");
6653: &endSettingsScreen($r);
6654: $r->print(&Apache::loncommon::end_page());
6655: return;
6656: }
6657:
6658: ##################################################
6659: # PARAMETER CHANGES LOG
6660: ##################################################
6661:
6662: # Returns some info for a parameter log entry.
6663: # Returned entries:
6664: # $realm - HTML title for the parameter level and resource
6665: # $section - parameter section
6666: # $name - parameter name
6667: # $part - parameter part
6668: # $what - $part.'.'.$name
6669: # $middle - resource symb ?
6670: # $uname - user name (same as given)
6671: # $udom - user domain (same as given)
6672: # $issection - section or group name
6673: # $realmdescription - title for the parameter level and resource (without using HTML)
6674: #
6675: # @param {string} $key - parameter log key
6676: # @param {string} $uname - user name
6677: # @param {string} $udom - user domain
6678: # @param {boolean} $typeflag - .type log entry
6679: # @returns {Array}
6680: sub components {
6681: my ($key,$uname,$udom,$typeflag)=@_;
6682:
6683: if ($typeflag) {
6684: $key=~s/\.type$//;
6685: }
6686:
6687: my ($middle,$part,$name)=
6688: ($key=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s\-]+)\.(\w+)$/);
6689: my $issection;
6690:
6691: my $section=&mt('All Students');
6692: if ($middle=~/^\[(.*)\]/) {
6693: $issection=$1;
6694: $section=&mt('Group/Section').': '.$issection;
6695: $middle=~s/^\[(.*)\]//;
6696: }
6697: $middle=~s/\.+$//;
6698: $middle=~s/^\.+//;
6699: if ($uname) {
6700: $section=&mt('User').": ".&Apache::loncommon::plainname($uname,$udom);
6701: $issection='';
6702: }
6703: my $realm='<span class="LC_parm_scope_all">'.&mt('All Resources').'</span>';
6704: my $realmdescription=&mt('all resources');
6705: if ($middle=~/^(.+)\_\_\_\((all|rec)\)$/) {
6706: my $mapurl = $1;
6707: my $maplevel = $2;
6708: my $leveltitle = &mt('Folder/Map');
6709: if ($maplevel eq 'rec') {
6710: $leveltitle = &mt('Recursive');
6711: }
6712: $realm='<span class="LC_parm_scope_folder">'.$leveltitle.
6713: ': '.&Apache::lonnet::gettitle($mapurl).' <span class="LC_parm_folder"><br />('.
6714: $mapurl.')</span></span>';
6715: $realmdescription=&mt('folder').' '.&Apache::lonnet::gettitle($mapurl);
6716: } elsif ($middle) {
6717: my ($map,$id,$url)=&Apache::lonnet::decode_symb($middle);
6718: $realm='<span class="LC_parm_scope_resource">'.&mt('Resource').
6719: ': '.&Apache::lonnet::gettitle($middle).' <br /><span class="LC_parm_symb">('.$url.
6720: ' in '.$map.' id: '.$id.')</span></span>';
6721: $realmdescription=&mt('resource').' '.&Apache::lonnet::gettitle($middle);
6722: }
6723: my $what=$part.'.'.$name;
6724: return ($realm,$section,$name,$part,
6725: $what,$middle,$uname,$udom,$issection,$realmdescription);
6726: }
6727:
6728: my %standard_parms; # hash parameter name -> parameter title (not localized)
6729: my %standard_parms_types; # hash parameter name -> parameter type
6730:
6731: # Reads parameter info from packages.tab into %standard_parms.
6732: sub load_parameter_names {
6733: open(my $config,"<","$Apache::lonnet::perlvar{'lonTabDir'}/packages.tab");
6734: while (my $configline=<$config>) {
6735: if ($configline !~ /\S/ || $configline=~/^\#/) { next; }
6736: chomp($configline);
6737: my ($short,$plain)=split(/:/,$configline);
6738: my (undef,$name,$type)=split(/\&/,$short,3);
6739: if ($type eq 'display') {
6740: $standard_parms{$name} = $plain;
6741: } elsif ($type eq 'type') {
6742: $standard_parms_types{$name} = $plain;
6743: }
6744: }
6745: close($config);
6746: $standard_parms{'int_pos'} = 'Positive Integer';
6747: $standard_parms{'int_zero_pos'} = 'Positive Integer or Zero';
6748: $standard_parms{'scoreformat'} = 'Format for display of score';
6749: }
6750:
6751: # Returns a parameter title for standard parameters, the name for others.
6752: #
6753: # @param {string} $name - parameter name
6754: # @returns {string}
6755: sub standard_parameter_names {
6756: my ($name)=@_;
6757: if (!%standard_parms) {
6758: &load_parameter_names();
6759: }
6760: if ($standard_parms{$name}) {
6761: return $standard_parms{$name};
6762: } else {
6763: return $name;
6764: }
6765: }
6766:
6767: # Returns a parameter type for standard parameters, undef for others.
6768: #
6769: # @param {string} $name - parameter name
6770: # @returns {string}
6771: sub standard_parameter_types {
6772: my ($name)=@_;
6773: if (!%standard_parms_types) {
6774: &load_parameter_names();
6775: }
6776: if ($standard_parms_types{$name}) {
6777: return $standard_parms_types{$name};
6778: }
6779: return;
6780: }
6781:
6782: # Returns a parameter level title (not localized) from the parameter level name.
6783: #
6784: # @param {string} $name - parameter level name (recognized: resourcelevel|maplevel|maplevelrecurse|courselevel)
6785: # @returns {string}
6786: sub standard_parameter_levels {
6787: my ($name)=@_;
6788: my %levels = (
6789: 'resourcelevel' => 'a single resource',
6790: 'maplevel' => 'the enclosing map/folder',
6791: 'maplevelrecurse' => 'the enclosing map/folder (recursive into sub-folders)',
6792: 'courselevel' => 'the general (course) level',
6793: );
6794: if ($levels{$name}) {
6795: return $levels{$name};
6796: }
6797: return;
6798: }
6799:
6800: # Display log for parameter changes, blog postings, user notification changes.
6801: #
6802: # @param {Apache2::RequestRec} $r - the Apache request
6803: sub parm_change_log {
6804: my ($r,$parm_permission)=@_;
6805: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6806: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
6807: my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6808: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=settable',
6809: text=>"Parameter Change Log"});
6810: my $js = '<script type="text/javascript">'."\n".
6811: '// <![CDATA['."\n".
6812: &Apache::loncommon::display_filter_js('parmslog')."\n".
6813: '// ]]>'."\n".
6814: '</script>'."\n";
6815: $r->print(&Apache::loncommon::start_page('Parameter Change Log',$js));
6816: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Parameter Change Log'));
6817: &startSettingsScreen($r,'parmset',$crstype);
6818: my %parmlog=&Apache::lonnet::dump('nohist_parameterlog',$cdom,$cnum);
6819:
6820: if ((keys(%parmlog))[0]=~/^error\:/) { undef(%parmlog); }
6821:
6822: $r->print('<div class="LC_left_float">'.
6823: '<fieldset><legend>'.&mt('Display of Changes').'</legend>'.
6824: '<form action="/adm/parmset?action=parameterchangelog"
6825: method="post" name="parameterlog">');
6826:
6827: my %saveable_parameters = ('show' => 'scalar',);
6828: &Apache::loncommon::store_course_settings('parameter_log',
6829: \%saveable_parameters);
6830: &Apache::loncommon::restore_course_settings('parameter_log',
6831: \%saveable_parameters);
6832: $r->print(&Apache::loncommon::display_filter('parmslog').' '."\n".
6833: '<input type="submit" value="'.&mt('Display').'" />'.
6834: '</form></fieldset></div><br clear="all" />');
6835:
6836: my $readonly = 1;
6837: if ($parm_permission->{'edit'}) {
6838: undef($readonly);
6839: }
6840: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
6841: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
6842: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Extent').'</th><th>'.&mt('Users').'</th><th>'.
6843: &mt('Parameter').'</th><th>'.&mt('Part').'</th><th>'.&mt('New Value').'</th>');
6844: unless ($readonly) {
6845: $r->print('<th>'.&mt('Announce').'</th>');
6846: }
6847: $r->print(&Apache::loncommon::end_data_table_header_row());
6848: my $shown=0;
6849: my $folder='';
6850: if ($env{'form.displayfilter'} eq 'currentfolder') {
6851: my $last='';
6852: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
6853: &GDBM_READER(),0640)) {
6854: $last=$hash{'last_known'};
6855: untie(%hash);
6856: }
6857: if ($last) { ($folder) = &Apache::lonnet::decode_symb($last); }
6858: }
6859: foreach my $id (sort {
6860: if ($parmlog{$b}{'exe_time'} ne $parmlog{$a}{'exe_time'}) {
6861: return $parmlog{$b}{'exe_time'} <=>$parmlog{$a}{'exe_time'}
6862: }
6863: my $aid = (split('00000',$a))[-1];
6864: my $bid = (split('00000',$b))[-1];
6865: return $bid<=>$aid;
6866: } (keys(%parmlog))) {
6867: my @changes=keys(%{$parmlog{$id}{'logentry'}});
6868: my $count = 0;
6869: my $time =
6870: &Apache::lonlocal::locallocaltime($parmlog{$id}{'exe_time'});
6871: my $plainname =
6872: &Apache::loncommon::plainname($parmlog{$id}{'exe_uname'},
6873: $parmlog{$id}{'exe_udom'});
6874: my $about_me_link =
6875: &Apache::loncommon::aboutmewrapper($plainname,
6876: $parmlog{$id}{'exe_uname'},
6877: $parmlog{$id}{'exe_udom'});
6878: my $send_msg_link='';
6879: if ((!$readonly) &&
6880: (($parmlog{$id}{'exe_uname'} ne $env{'user.name'})
6881: || ($parmlog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
6882: $send_msg_link ='<br />'.
6883: &Apache::loncommon::messagewrapper(&mt('Send message'),
6884: $parmlog{$id}{'exe_uname'},
6885: $parmlog{$id}{'exe_udom'});
6886: }
6887: my $row_start=&Apache::loncommon::start_data_table_row();
6888: my $makenewrow=0;
6889: my %istype=();
6890: my $output;
6891: foreach my $changed (reverse(sort(@changes))) {
6892: my $value=$parmlog{$id}{'logentry'}{$changed};
6893: my $typeflag = ($changed =~/\.type$/ &&
6894: !exists($parmlog{$id}{'logentry'}{$changed.'.type'}));
6895: my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)=
6896: &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},$typeflag);
6897: if ($env{'request.course.sec'} ne '') {
6898: next if (($issection ne '') && ($issection ne $env{'request.course.sec'}));
6899: if ($uname ne '') {
6900: my $stusection = &Apache::lonnet::getsection($uname,$udom,$env{'request.course.id'});
6901: next if (($stusection ne '-1') && ($stusection ne $env{'request.course.sec'}));
6902: }
6903: }
6904: if ($env{'form.displayfilter'} eq 'currentfolder') {
6905: if ($folder) {
6906: if ($middle!~/^\Q$folder\E/) { next; }
6907: }
6908: }
6909: if ($typeflag) {
6910: $istype{$parmname}=$value;
6911: if (!$env{'form.includetypes'}) { next; }
6912: }
6913: $count++;
6914: if ($makenewrow) {
6915: $output .= $row_start;
6916: } else {
6917: $makenewrow=1;
6918: }
6919: my $parmitem = &standard_parameter_names($parmname);
6920: $output .='<td>'.$realm.'</td><td>'.$section.'</td><td>'.
6921: &mt($parmitem).'</td><td>'.
6922: ($part?&mt('Part: [_1]',$part):&mt('All Parts')).'</td><td>';
6923: my $stillactive=0;
6924: if ($parmlog{$id}{'delflag'}) {
6925: $output .= &mt('Deleted');
6926: } else {
6927: if ($typeflag) {
6928: my $parmitem = &standard_parameter_names($value);
6929: $parmitem = &mt($parmitem);
6930: $output .= &mt('Type: [_1]',$parmitem);
6931: } else {
6932: my $toolsymb;
6933: if ($middle =~ /ext\.tool$/) {
6934: $toolsymb = $middle;
6935: }
6936: my ($level,@all)=&parmval_by_symb($what,$middle,
6937: &Apache::lonnet::metadata($middle,$what,$toolsymb),
6938: $uname,$udom,$issection,$issection,$courseopt);
6939: my $showvalue = $value;
6940: if ($istype{$parmname} eq '') {
6941: my $type = &standard_parameter_types($parmname);
6942: if ($type ne '') {
6943: if (&isdateparm($type)) {
6944: $showvalue =
6945: &Apache::lonlocal::locallocaltime($value);
6946: }
6947: }
6948: } else {
6949: if (&isdateparm($istype{$parmname})) {
6950: $showvalue = &Apache::lonlocal::locallocaltime($value);
6951: }
6952: }
6953: $output .= $showvalue;
6954: if ($value ne $all[$level]) {
6955: $output .= '<br /><span class="LC_warning">'.&mt('Not active anymore').'</span>';
6956: } else {
6957: $stillactive=1;
6958: }
6959: }
6960: }
6961: $output .= '</td>';
6962:
6963: unless ($readonly) {
6964: $output .= '<td>';
6965: if ($stillactive) {
6966: my $parmitem = &standard_parameter_names($parmname);
6967: $parmitem = &mt($parmitem);
6968: my $title=&mt('Changed [_1]',$parmitem);
6969: my $description=&mt('Changed [_1] for [_2] to [_3]',
6970: $parmitem,$realmdescription,
6971: (&isdateparm($istype{$parmname})?&Apache::lonlocal::locallocaltime($value):$value));
6972: if (($uname) && ($udom)) {
6973: $output .=
6974: &Apache::loncommon::messagewrapper('Notify User',
6975: $uname,$udom,$title,
6976: $description);
6977: } else {
6978: $output .=
6979: &Apache::lonrss::course_blog_link($id,$title,
6980: $description);
6981: }
6982: }
6983: $output .= '</td>';
6984: }
6985: $output .= &Apache::loncommon::end_data_table_row();
6986: }
6987: if ($env{'form.displayfilter'} eq 'containing') {
6988: my $wholeentry=$about_me_link.':'.
6989: $parmlog{$id}{'exe_uname'}.':'.$parmlog{$id}{'exe_udom'}.':'.
6990: $output;
6991: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
6992: }
6993: if ($count) {
6994: $r->print($row_start.'<td rowspan="'.$count.'">'.$time.'</td>
6995: <td rowspan="'.$count.'">'.$about_me_link.
6996: '<br /><tt>'.$parmlog{$id}{'exe_uname'}.
6997: ':'.$parmlog{$id}{'exe_udom'}.'</tt>'.
6998: $send_msg_link.'</td>'.$output);
6999: $shown++;
7000: }
7001: if (!($env{'form.show'} eq &mt('all')
7002: || $shown<=$env{'form.show'})) { last; }
7003: }
7004: $r->print(&Apache::loncommon::end_data_table());
7005: &endSettingsScreen($r);
7006: $r->print(&Apache::loncommon::end_page());
7007: }
7008:
7009: ##################################################
7010: # MISC !
7011: ##################################################
7012:
7013: # Stores slot information.
7014: # Used by table UI
7015: # FIXME: I don't understand how this can work when the symb is not defined (if only a map was selected)
7016: #
7017: # @param {string} $slot_name - slot name
7018: # @param {string} $cdom - course domain
7019: # @param {string} $cnum - course number
7020: # @param {string} $symb - resource symb
7021: # @param {string} $uname - user name
7022: # @param {string} $udom - user domain
7023: # @returns {string} - 'ok' or error name
7024: sub update_slots {
7025: my ($slot_name,$cdom,$cnum,$symb,$uname,$udom) = @_;
7026: my %slot=&Apache::lonnet::get_slot($slot_name);
7027: if (!keys(%slot)) {
7028: return 'error: slot does not exist';
7029: }
7030: my $max=$slot{'maxspace'};
7031: if (!defined($max)) { $max=99999; }
7032:
7033: my %consumed=&Apache::lonnet::dump('slot_reservations',$cdom,$cnum,
7034: "^$slot_name\0");
7035: my ($tmp)=%consumed;
7036: if ($tmp=~/^error: 2 / ) {
7037: return 'error: unable to determine current slot status';
7038: }
7039: my $last=0;
7040: foreach my $key (keys(%consumed)) {
7041: my $num=(split('\0',$key))[1];
7042: if ($num > $last) { $last=$num; }
7043: if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
7044: return 'ok';
7045: }
7046: }
7047:
7048: if (scalar(keys(%consumed)) >= $max) {
7049: return 'error: no space left in slot';
7050: }
7051: my $wanted=$last+1;
7052:
7053: my %reservation=('name' => $uname.':'.$udom,
7054: 'timestamp' => time,
7055: 'symb' => $symb);
7056:
7057: my $success=&Apache::lonnet::newput('slot_reservations',
7058: {"$slot_name\0$wanted" =>
7059: \%reservation},
7060: $cdom, $cnum);
7061: if ($success eq 'ok') {
7062: my %storehash = (
7063: symb => $symb,
7064: slot => $slot_name,
7065: action => 'reserve',
7066: context => 'parameter',
7067: );
7068: &Apache::lonnet::write_log('course','slotreservationslog',\%storehash,
7069: '',$uname,$udom,$cnum,$cdom);
7070:
7071: &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash,
7072: '',$uname,$udom,$uname,$udom);
7073: }
7074: return $success;
7075: }
7076:
7077: # Deletes a slot reservation.
7078: # Used by table UI
7079: # FIXME: I don't understand how this can work when the symb is not defined (if only a map was selected)
7080: #
7081: # @param {string} $slot_name - slot name
7082: # @param {string} $cdom - course domain
7083: # @param {string} $cnum - course number
7084: # @param {string} $uname - user name
7085: # @param {string} $udom - user domain
7086: # @param {string} $symb - resource symb
7087: # @returns {string} - 'ok' or error name
7088: sub delete_slots {
7089: my ($slot_name,$cdom,$cnum,$uname,$udom,$symb) = @_;
7090: my $delresult;
7091: my %consumed = &Apache::lonnet::dump('slot_reservations',$cdom,
7092: $cnum, "^$slot_name\0");
7093: if (&Apache::lonnet::error(%consumed)) {
7094: return 'error: unable to determine current slot status';
7095: }
7096: my ($tmp)=%consumed;
7097: if ($tmp=~/^error: 2 /) {
7098: return 'error: unable to determine current slot status';
7099: }
7100: foreach my $key (keys(%consumed)) {
7101: if ($consumed{$key}->{'name'} eq $uname.':'.$udom) {
7102: my $num=(split('\0',$key))[1];
7103: my $entry = $slot_name.'\0'.$num;
7104: $delresult = &Apache::lonnet::del('slot_reservations',[$entry],
7105: $cdom,$cnum);
7106: if ($delresult eq 'ok') {
7107: my %storehash = (
7108: symb => $symb,
7109: slot => $slot_name,
7110: action => 'release',
7111: context => 'parameter',
7112: );
7113: &Apache::lonnet::write_log('course','slotreservationslog',\%storehash,
7114: 1,$uname,$udom,$cnum,$cdom);
7115: &Apache::lonnet::write_log('course',$cdom.'_'.$cnum.'_slotlog',\%storehash,
7116: 1,$uname,$udom,$uname,$udom);
7117: }
7118: }
7119: }
7120: return $delresult;
7121: }
7122:
7123: # Returns true if there is a current course.
7124: # Used by handler
7125: #
7126: # @returns {boolean}
7127: sub check_for_course_info {
7128: my $navmap = Apache::lonnavmaps::navmap->new();
7129: return 1 if ($navmap);
7130: return 0;
7131: }
7132:
7133: # Returns the current course host and host LON-CAPA version.
7134: #
7135: # @returns {Array} - (course hostname, major version number, minor version number)
7136: sub parameter_release_vars {
7137: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7138: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
7139: my $chostname = &Apache::lonnet::hostname($chome);
7140: my ($cmajor,$cminor) =
7141: split(/\./,&Apache::lonnet::get_server_loncaparev($cdom,$chome));
7142: return ($chostname,$cmajor,$cminor);
7143: }
7144:
7145: # Checks if the course host version can handle a parameter required version,
7146: # and if it does, stores the release needed for the course.
7147: #
7148: # @param {string} $name - parameter name
7149: # @param {string} $value - parameter value
7150: # @param {string} $valmatch - name of the test used for checking the value
7151: # @param {string} $namematch - name of the test used for checking the name
7152: # @param {string} $needsrelease - version needed by the parameter, major.minor
7153: # @param {integer} $cmajor - course major version number
7154: # @param {integer} $cminor - course minor version number
7155: # @returns {boolean} - true if a newer version is needed
7156: sub parameter_releasecheck {
7157: my ($name,$value,$valmatch,$namematch,$needsrelease,$cmajor,$cminor) = @_;
7158: my $needsnewer;
7159: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
7160: if (($cmajor < $needsmajor) ||
7161: ($cmajor == $needsmajor && $cminor < $needsminor)) {
7162: $needsnewer = 1;
7163: } elsif ($name) {
7164: if ($valmatch) {
7165: &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.'::'.$valmatch.':'});
7166: } elsif ($value) {
7167: &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.':'.$value.'::'});
7168: }
7169: } elsif ($namematch) {
7170: &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter::::'.$namematch});
7171: }
7172: return $needsnewer;
7173: }
7174:
7175: sub get_permission {
7176: my %permission;
7177: my $allowed = 0;
7178: return (\%permission,$allowed) unless ($env{'request.course.id'});
7179: if ((&Apache::lonnet::allowed('opa',$env{'request.course.id'})) ||
7180: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.
7181: $env{'request.course.sec'}))) {
7182: %permission= (
7183: 'edit' => 1,
7184: 'set' => 1,
7185: 'setoverview' => 1,
7186: 'addmetadata' => 1,
7187: 'ordermetadata' => 1,
7188: 'setrestrictmeta' => 1,
7189: 'newoverview' => 1,
7190: 'setdefaults' => 1,
7191: 'settable' => 1,
7192: 'parameterchangelog' => 1,
7193: 'cleanparameters' => 1,
7194: 'dateshift1' => 1,
7195: 'dateshift2' => 1,
7196: 'helper' => 1,
7197: );
7198: } elsif ((&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) ||
7199: (&Apache::lonnet::allowed('vpa',$env{'request.course.id'}.'/'.
7200: $env{'request.course.sec'}))) {
7201: %permission = (
7202: 'set' => 1,
7203: 'settable' => 1,
7204: 'newoverview' => 1,
7205: 'setoverview' => 1,
7206: 'parameterchangelog' => 1,
7207: );
7208: }
7209: foreach my $perm (values(%permission)) {
7210: if ($perm) { $allowed=1; last; }
7211: }
7212: return (\%permission,$allowed);
7213: }
7214:
7215: ##################################################
7216: # HANDLER
7217: ##################################################
7218:
7219: # Main handler for lonparmset.
7220: # Sub called based on request parameters action and command:
7221: # no command or action: print_main_menu
7222: # command 'set': assessparms (direct access to table mode for a resource)
7223: # (this can also be accessed simply with the symb parameter)
7224: # action 'setoverview': overview (display all existing parameter settings)
7225: # action 'addmetadata': addmetafield (called to add a portfolio metadata field)
7226: # action 'ordermetadata': order_meta_fields (called to order portfolio metadata fields)
7227: # action 'setrestrictmeta': setrestrictmeta (display or save portfolio metadata)
7228: # action 'newoverview': newoverview (overview mode)
7229: # action 'setdefaults': defaultsetter (UI to change parameter setting default actions)
7230: # action 'settable': assessparms (table mode)
7231: # action 'parameterchangelog': parm_change_log (display log for parameter changes,
7232: # blog postings, user notification changes)
7233: # action 'cleanparameters': clean_parameters (unused)
7234: # action 'dateshift1': date_shift_one (overview mode, shift all dates)
7235: # action 'dateshift2': date_shift_two (overview mode, shift all dates)
7236: sub handler {
7237: my $r=shift;
7238:
7239: &reset_caches();
7240:
7241: &Apache::loncommon::content_type($r,'text/html');
7242: $r->send_http_header;
7243: return OK if $r->header_only;
7244:
7245: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
7246: ['action','state',
7247: 'pres_marker',
7248: 'pres_value',
7249: 'pres_type',
7250: 'filter','part',
7251: 'udom','uname','symb','serial','timebase']);
7252:
7253:
7254: &Apache::lonhtmlcommon::clear_breadcrumbs();
7255: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
7256: text=>"Content and Problem Settings",
7257: faq=>10,
7258: bug=>'Instructor Interface',
7259: help =>
7260: 'Parameter_Manager,Course_Environment,Parameter_Helper,Parameter_Overview,Table_Mode'});
7261:
7262: # ----------------------------------------------------- Needs to be in a course
7263: my ($parm_permission,$allowed) = &get_permission();
7264: my $exists = &check_for_course_info();
7265:
7266: if ($env{'request.course.id'} && $allowed && $exists) {
7267: #
7268: # Main switch on form.action and form.state, as appropriate
7269: #
7270: # Check first if coming from someone else headed directly for
7271: # the table mode
7272: if (($parm_permission->{'set'}) &&
7273: ((($env{'form.command'} eq 'set') && ($env{'form.url'})
7274: && (!$env{'form.dis'})) || ($env{'form.symb'}))) {
7275: &assessparms($r,$parm_permission);
7276: } elsif (! exists($env{'form.action'})) {
7277: &print_main_menu($r,$parm_permission);
7278: } elsif (!$parm_permission->{$env{'form.action'}}) {
7279: &print_main_menu($r,$parm_permission);
7280: } elsif ($env{'form.action'} eq 'setoverview') {
7281: &overview($r,$parm_permission);
7282: } elsif ($env{'form.action'} eq 'addmetadata') {
7283: &addmetafield($r);
7284: } elsif ($env{'form.action'} eq 'ordermetadata') {
7285: &order_meta_fields($r);
7286: } elsif ($env{'form.action'} eq 'setrestrictmeta') {
7287: &setrestrictmeta($r);
7288: } elsif ($env{'form.action'} eq 'newoverview') {
7289: &newoverview($r,$parm_permission);
7290: } elsif ($env{'form.action'} eq 'setdefaults') {
7291: &defaultsetter($r);
7292: } elsif ($env{'form.action'} eq 'settable') {
7293: &assessparms($r,$parm_permission);
7294: } elsif ($env{'form.action'} eq 'parameterchangelog') {
7295: &parm_change_log($r,$parm_permission);
7296: } elsif ($env{'form.action'} eq 'cleanparameters') {
7297: &clean_parameters($r);
7298: } elsif ($env{'form.action'} eq 'dateshift1') {
7299: &date_shift_one($r);
7300: } elsif ($env{'form.action'} eq 'dateshift2') {
7301: &date_shift_two($r);
7302: }
7303: } else {
7304: # ----------------------------- Not in a course, or not allowed to modify parms
7305: if ($exists) {
7306: $env{'user.error.msg'}=
7307: "/adm/parmset:opa:0:0:Cannot modify assessment parameters";
7308: } else {
7309: $env{'user.error.msg'}=
7310: "/adm/parmset::0:1:Course environment gone, reinitialize the course";
7311: }
7312: return HTTP_NOT_ACCEPTABLE;
7313: }
7314: &reset_caches();
7315:
7316: return OK;
7317: }
7318:
7319: 1;
7320: __END__
7321:
7322:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>