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