1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.160.6.118.2.15 2023/09/04 17:40:47 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:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
49: for use by individuals affiliated with the institution. Accordingly, each domain
50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
90: number of rows displayed on the page, and $action is the context (quotas,
91: requestcourses or requestauthor).
92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
98: used by course owners to request creation of a course, and to display/store
99: default quota sizes for Authoring Spaces.
100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
107: (official, unofficial, community, textbook, and lti).
108: In each case the radio buttons allow the selection of one of four values:
109:
110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
121: approval
122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
145: - course requests will be processed automatically up to a limit of
146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
166: use Apache::lonmsg();
167: use Apache::lonconfigsettings;
168: use Apache::lonuserutils();
169: use Apache::loncoursequeueadmin();
170: use Apache::courseprefs();
171: use LONCAPA qw(:DEFAULT :match);
172: use LONCAPA::Enrollment;
173: use LONCAPA::lonauthcgi();
174: use File::Copy;
175: use Locale::Language;
176: use DateTime::TimeZone;
177: use DateTime::Locale;
178: use Time::HiRes qw( sleep );
179: use Net::CIDR;
180: use Crypt::CBC;
181:
182: my $registered_cleanup;
183: my $modified_urls;
184:
185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
193: my $context = 'domain';
194: my $dom = $env{'request.role.domain'};
195: my $domdesc = &Apache::lonnet::domain($dom,'description');
196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
210: ['phase','actions']);
211: my $phase = 'pickactions';
212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
216: my %domconfig =
217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
222: 'coursedefaults','usersessions','loadbalancing',
223: 'requestauthor','selfenrollment','inststatus',
224: 'passwords','ltitools','toolsec','lti','ltisec',
225: 'wafproxy','ipaccess'],$dom);
226: my %encconfig =
227: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','linkprot'],$dom,undef,1);
228: my ($checked_is_home,$is_home);
229: if (ref($domconfig{'ltitools'}) eq 'HASH') {
230: if (ref($encconfig{'ltitools'}) eq 'HASH') {
231: my $home = &Apache::lonnet::domain($dom,'primary');
232: unless (($home eq 'no_host') || ($home eq '')) {
233: my @ids=&Apache::lonnet::current_machine_ids();
234: if (grep(/^\Q$home\E$/,@ids)) {
235: $is_home = 1;
236: }
237: }
238: $checked_is_home = 1;
239: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
240: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
242: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
243: if (($is_home) && ($phase eq 'process')) {
244: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
245: }
246: }
247: }
248: }
249: }
250: if (ref($domconfig{'lti'}) eq 'HASH') {
251: if (ref($encconfig{'lti'}) eq 'HASH') {
252: unless ($checked_is_home) {
253: my $home = &Apache::lonnet::domain($dom,'primary');
254: unless (($home eq 'no_host') || ($home eq '')) {
255: my @ids=&Apache::lonnet::current_machine_ids();
256: if (grep(/^\Q$home\E$/,@ids)) {
257: $is_home = 1;
258: }
259: }
260: $checked_is_home = 1;
261: }
262: foreach my $id (keys(%{$domconfig{'lti'}})) {
263: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
264: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
265: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
266: if (($is_home) && ($phase eq 'process')) {
267: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
268: }
269: }
270: }
271: }
272: }
273: if (ref($domconfig{'ltisec'}) eq 'HASH') {
274: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
275: if (ref($encconfig{'linkprot'}) eq 'HASH') {
276: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
277: unless ($id =~ /^\d+$/) {
278: delete($domconfig{'ltisec'}{'linkprot'}{$id});
279: }
280: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
281: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
282: foreach my $item ('key','secret') {
283: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
284: }
285: }
286: }
287: }
288: }
289: }
290: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
291: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
292: 'contacts','usercreation','selfcreation','usermodification',
293: 'scantron','requestcourses','requestauthor','coursecategories',
294: 'serverstatuses','helpsettings','coursedefaults',
295: 'ltitools','selfenrollment','usersessions','lti');
296: my %existing;
297: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
298: %existing = %{$domconfig{'loadbalancing'}};
299: }
300: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
301: push(@prefs_order,'loadbalancing');
302: }
303: my %prefs = (
304: 'rolecolors' =>
305: { text => 'Default color schemes',
306: help => 'Domain_Configuration_Color_Schemes',
307: header => [{col1 => 'Student Settings',
308: col2 => '',},
309: {col1 => 'Coordinator Settings',
310: col2 => '',},
311: {col1 => 'Author Settings',
312: col2 => '',},
313: {col1 => 'Administrator Settings',
314: col2 => '',}],
315: print => \&print_rolecolors,
316: modify => \&modify_rolecolors,
317: },
318: 'login' =>
319: { text => 'Log-in page options',
320: help => 'Domain_Configuration_Login_Page',
321: header => [{col1 => 'Log-in Page Items',
322: col2 => '',},
323: {col1 => 'Log-in Help',
324: col2 => 'Value'},
325: {col1 => 'Custom HTML in document head',
326: col2 => 'Value'},
327: {col1 => 'SSO',
328: col2 => 'Dual login: SSO and non-SSO options'},
329: ],
330: print => \&print_login,
331: modify => \&modify_login,
332: },
333: 'defaults' =>
334: { text => 'Default authentication/language/timezone/portal/types',
335: help => 'Domain_Configuration_LangTZAuth',
336: header => [{col1 => 'Setting',
337: col2 => 'Value'},
338: {col1 => 'Institutional user types',
339: col2 => 'Name displayed'},
340: {col1 => 'Mapping for missing usernames via standard log-in',
341: col2 => 'Rules in use'}],
342: print => \&print_defaults,
343: modify => \&modify_defaults,
344: },
345: 'wafproxy' =>
346: { text => 'Web Application Firewall/Reverse Proxy',
347: help => 'Domain_Configuration_WAF_Proxy',
348: header => [{col1 => 'Domain(s)',
349: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
350: },
351: {col1 => 'Domain(s)',
352: col2 => 'WAF Configuration',}],
353: print => \&print_wafproxy,
354: modify => \&modify_wafproxy,
355: },
356: 'passwords' =>
357: { text => 'Passwords (Internal authentication)',
358: help => 'Domain_Configuration_Passwords',
359: header => [{col1 => 'Resetting Forgotten Password',
360: col2 => 'Settings'},
361: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
362: col2 => 'Settings'},
363: {col1 => 'Rules for LON-CAPA Passwords',
364: col2 => 'Settings'},
365: {col1 => 'Course Owner Changing Student Passwords',
366: col2 => 'Settings'}],
367: print => \&print_passwords,
368: modify => \&modify_passwords,
369: },
370: 'quotas' =>
371: { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
372: help => 'Domain_Configuration_Quotas',
373: header => [{col1 => 'User affiliation',
374: col2 => 'Available tools',
375: col3 => 'Quotas, MB; (Authoring requires role)',}],
376: print => \&print_quotas,
377: modify => \&modify_quotas,
378: },
379: 'autoenroll' =>
380: { text => 'Auto-enrollment settings',
381: help => 'Domain_Configuration_Auto_Enrollment',
382: header => [{col1 => 'Configuration setting',
383: col2 => 'Value(s)'}],
384: print => \&print_autoenroll,
385: modify => \&modify_autoenroll,
386: },
387: 'autoupdate' =>
388: { text => 'Auto-update settings',
389: help => 'Domain_Configuration_Auto_Updates',
390: header => [{col1 => 'Setting',
391: col2 => 'Value',},
392: {col1 => 'Setting',
393: col2 => 'Affiliation'},
394: {col1 => 'User population',
395: col2 => 'Updatable user data'}],
396: print => \&print_autoupdate,
397: modify => \&modify_autoupdate,
398: },
399: 'autocreate' =>
400: { text => 'Auto-course creation settings',
401: help => 'Domain_Configuration_Auto_Creation',
402: header => [{col1 => 'Configuration Setting',
403: col2 => 'Value',}],
404: print => \&print_autocreate,
405: modify => \&modify_autocreate,
406: },
407: 'directorysrch' =>
408: { text => 'Directory searches',
409: help => 'Domain_Configuration_InstDirectory_Search',
410: header => [{col1 => 'Institutional Directory Setting',
411: col2 => 'Value',},
412: {col1 => 'LON-CAPA Directory Setting',
413: col2 => 'Value',}],
414: print => \&print_directorysrch,
415: modify => \&modify_directorysrch,
416: },
417: 'contacts' =>
418: { text => 'E-mail addresses and helpform',
419: help => 'Domain_Configuration_Contact_Info',
420: header => [{col1 => 'Default e-mail addresses',
421: col2 => 'Value',},
422: {col1 => 'Recipient(s) for notifications',
423: col2 => 'Value',},
424: {col1 => 'Nightly status check e-mail',
425: col2 => 'Settings',},
426: {col1 => 'Ask helpdesk form settings',
427: col2 => 'Value',},],
428: print => \&print_contacts,
429: modify => \&modify_contacts,
430: },
431: 'usercreation' =>
432: { text => 'User creation',
433: help => 'Domain_Configuration_User_Creation',
434: header => [{col1 => 'Format rule type',
435: col2 => 'Format rules in force'},
436: {col1 => 'User account creation',
437: col2 => 'Usernames which may be created',},
438: {col1 => 'Context',
439: col2 => 'Assignable authentication types'}],
440: print => \&print_usercreation,
441: modify => \&modify_usercreation,
442: },
443: 'selfcreation' =>
444: { text => 'Users self-creating accounts',
445: help => 'Domain_Configuration_Self_Creation',
446: header => [{col1 => 'Self-creation with institutional username',
447: col2 => 'Enabled?'},
448: {col1 => 'Institutional user type (login/SSO self-creation)',
449: col2 => 'Information user can enter'},
450: {col1 => 'Self-creation with e-mail verification',
451: col2 => 'Settings'}],
452: print => \&print_selfcreation,
453: modify => \&modify_selfcreation,
454: },
455: 'usermodification' =>
456: { text => 'User modification',
457: help => 'Domain_Configuration_User_Modification',
458: header => [{col1 => 'Target user has role',
459: col2 => 'User information updatable in author context'},
460: {col1 => 'Target user has role',
461: col2 => 'User information updatable in course context'}],
462: print => \&print_usermodification,
463: modify => \&modify_usermodification,
464: },
465: 'scantron' =>
466: { text => 'Bubblesheet format',
467: help => 'Domain_Configuration_Scantron_Format',
468: header => [ {col1 => 'Bubblesheet format file',
469: col2 => ''},
470: {col1 => 'Bubblesheet data upload formats',
471: col2 => 'Settings'}],
472: print => \&print_scantron,
473: modify => \&modify_scantron,
474: },
475: 'requestcourses' =>
476: {text => 'Request creation of courses',
477: help => 'Domain_Configuration_Request_Courses',
478: header => [{col1 => 'User affiliation',
479: col2 => 'Availability/Processing of requests',},
480: {col1 => 'Setting',
481: col2 => 'Value'},
482: {col1 => 'Available textbooks',
483: col2 => ''},
484: {col1 => 'Available templates',
485: col2 => ''},
486: {col1 => 'Validation (not official courses)',
487: col2 => 'Value'},],
488: print => \&print_quotas,
489: modify => \&modify_quotas,
490: },
491: 'requestauthor' =>
492: {text => 'Request Authoring Space',
493: help => 'Domain_Configuration_Request_Author',
494: header => [{col1 => 'User affiliation',
495: col2 => 'Availability/Processing of requests',},
496: {col1 => 'Setting',
497: col2 => 'Value'}],
498: print => \&print_quotas,
499: modify => \&modify_quotas,
500: },
501: 'coursecategories' =>
502: { text => 'Cataloging of courses/communities',
503: help => 'Domain_Configuration_Cataloging_Courses',
504: header => [{col1 => 'Catalog type/availability',
505: col2 => '',},
506: {col1 => 'Category settings for standard catalog',
507: col2 => '',},
508: {col1 => 'Categories',
509: col2 => '',
510: }],
511: print => \&print_coursecategories,
512: modify => \&modify_coursecategories,
513: },
514: 'serverstatuses' =>
515: {text => 'Access to server status pages',
516: help => 'Domain_Configuration_Server_Status',
517: header => [{col1 => 'Status Page',
518: col2 => 'Other named users',
519: col3 => 'Specific IPs',
520: }],
521: print => \&print_serverstatuses,
522: modify => \&modify_serverstatuses,
523: },
524: 'helpsettings' =>
525: {text => 'Support settings',
526: help => 'Domain_Configuration_Help_Settings',
527: header => [{col1 => 'Help Page Settings (logged-in users)',
528: col2 => 'Value'},
529: {col1 => 'Helpdesk Roles',
530: col2 => 'Settings'},],
531: print => \&print_helpsettings,
532: modify => \&modify_helpsettings,
533: },
534: 'coursedefaults' =>
535: {text => 'Course/Community defaults',
536: help => 'Domain_Configuration_Course_Defaults',
537: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
538: col2 => 'Value',},
539: {col1 => 'Defaults which can be overridden for each course by a DC',
540: col2 => 'Value',},],
541: print => \&print_coursedefaults,
542: modify => \&modify_coursedefaults,
543: },
544: 'selfenrollment' =>
545: {text => 'Self-enrollment in Course/Community',
546: help => 'Domain_Configuration_Selfenrollment',
547: header => [{col1 => 'Configuration Rights',
548: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
549: {col1 => 'Defaults',
550: col2 => 'Value'},
551: {col1 => 'Self-enrollment validation (optional)',
552: col2 => 'Value'},],
553: print => \&print_selfenrollment,
554: modify => \&modify_selfenrollment,
555: },
556: 'usersessions' =>
557: {text => 'User session hosting/offloading',
558: help => 'Domain_Configuration_User_Sessions',
559: header => [{col1 => 'Domain server',
560: col2 => 'Servers to offload sessions to when busy'},
561: {col1 => 'Hosting of users from other domains',
562: col2 => 'Rules'},
563: {col1 => "Hosting domain's own users elsewhere",
564: col2 => 'Rules'}],
565: print => \&print_usersessions,
566: modify => \&modify_usersessions,
567: },
568: 'loadbalancing' =>
569: {text => 'Dedicated Load Balancer(s)',
570: help => 'Domain_Configuration_Load_Balancing',
571: header => [{col1 => 'Balancers',
572: col2 => 'Default destinations',
573: col3 => 'User affiliation',
574: col4 => 'Overrides'},
575: ],
576: print => \&print_loadbalancing,
577: modify => \&modify_loadbalancing,
578: },
579: 'ltitools' =>
580: {text => 'External Tools (LTI)',
581: help => 'Domain_Configuration_LTI_Tools',
582: header => [{col1 => 'Encryption of shared secrets',
583: col2 => 'Settings'},
584: {col1 => 'Rules for shared secrets',
585: col2 => 'Settings'},
586: {col1 => 'Providers',
587: col2 => 'Settings',}],
588: print => \&print_ltitools,
589: modify => \&modify_ltitools,
590: },
591: 'lti' =>
592: {text => 'LTI Link Protection and LTI Consumers',
593: help => 'Domain_Configuration_LTI_Provider',
594: header => [{col1 => 'Encryption of shared secrets',
595: col2 => 'Settings'},
596: {col1 => 'Rules for shared secrets',
597: col2 => 'Settings'},
598: {col1 => 'Link Protectors',
599: col2 => 'Settings'},
600: {col1 => 'Consumers',
601: col2 => 'Settings'},],
602: print => \&print_lti,
603: modify => \&modify_lti,
604: },
605: 'ipaccess' =>
606: {text => 'IP-based access control',
607: help => 'Domain_Configuration_IP_Access',
608: header => [{col1 => 'Setting',
609: col2 => 'Value'},],
610: print => \&print_ipaccess,
611: modify => \&modify_ipaccess,
612: },
613: );
614: if (keys(%servers) > 1) {
615: $prefs{'login'} = { text => 'Log-in page options',
616: help => 'Domain_Configuration_Login_Page',
617: header => [{col1 => 'Log-in Service',
618: col2 => 'Server Setting',},
619: {col1 => 'Log-in Page Items',
620: col2 => 'Settings'},
621: {col1 => 'Log-in Help',
622: col2 => 'Value'},
623: {col1 => 'Custom HTML in document head',
624: col2 => 'Value'},
625: {col1 => 'SSO',
626: col2 => 'Dual login: SSO and non-SSO options'},
627: ],
628: print => \&print_login,
629: modify => \&modify_login,
630: };
631: }
632:
633: my @roles = ('student','coordinator','author','admin');
634: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
635: &Apache::lonhtmlcommon::add_breadcrumb
636: ({href=>"javascript:changePage(document.$phase,'pickactions')",
637: text=>"Settings to display/modify"});
638: my $confname = $dom.'-domainconfig';
639:
640: if ($phase eq 'process') {
641: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
642: \%prefs,\%domconfig,$confname,\@roles);
643: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
644: $r->rflush();
645: &devalidate_remote_domconfs($dom,$result);
646: }
647: } elsif ($phase eq 'display') {
648: my $js = &recaptcha_js().
649: &toggle_display_js();
650: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
651: my ($othertitle,$usertypes,$types) =
652: &Apache::loncommon::sorted_inst_types($dom);
653: $js .= &lonbalance_targets_js($dom,$types,\%servers,
654: $domconfig{'loadbalancing'}).
655: &new_spares_js().
656: &common_domprefs_js().
657: &Apache::loncommon::javascript_array_indexof();
658: }
659: if (grep(/^requestcourses$/,@actions)) {
660: my $javascript_validations;
661: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
662: $js .= <<END;
663: <script type="text/javascript">
664: $javascript_validations
665: </script>
666: $coursebrowserjs
667: END
668: } elsif (grep(/^ipaccess$/,@actions)) {
669: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
670: }
671: if (grep(/^selfcreation$/,@actions)) {
672: $js .= &selfcreate_javascript();
673: }
674: if (grep(/^contacts$/,@actions)) {
675: $js .= &contacts_javascript();
676: }
677: if (grep(/^scantron$/,@actions)) {
678: $js .= &scantron_javascript();
679: }
680: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
681: } else {
682: # check if domconfig user exists for the domain.
683: my $servadm = $r->dir_config('lonAdmEMail');
684: my ($configuserok,$author_ok,$switchserver) =
685: &config_check($dom,$confname,$servadm);
686: unless ($configuserok eq 'ok') {
687: &Apache::lonconfigsettings::print_header($r,$phase,$context);
688: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
689: $confname).
690: '<br />'
691: );
692: if ($switchserver) {
693: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
694: '<br />'.
695: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
696: '<br />'.
697: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
698: '<br />'.
699: &mt('To do that now, use the following link: [_1]',$switchserver)
700: );
701: } else {
702: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
703: '<br />'.
704: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
705: );
706: }
707: $r->print(&Apache::loncommon::end_page());
708: return OK;
709: }
710: if (keys(%domconfig) == 0) {
711: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
712: my @ids=&Apache::lonnet::current_machine_ids();
713: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
714: my %designhash = &Apache::loncommon::get_domainconf($dom);
715: my @loginimages = ('img','logo','domlogo','login');
716: my $custom_img_count = 0;
717: foreach my $img (@loginimages) {
718: if ($designhash{$dom.'.login.'.$img} ne '') {
719: $custom_img_count ++;
720: }
721: }
722: foreach my $role (@roles) {
723: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
724: $custom_img_count ++;
725: }
726: }
727: if ($custom_img_count > 0) {
728: &Apache::lonconfigsettings::print_header($r,$phase,$context);
729: my $switch_server = &check_switchserver($dom,$confname);
730: $r->print(
731: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
732: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
733: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
734: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
735: if ($switch_server) {
736: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
737: }
738: $r->print(&Apache::loncommon::end_page());
739: return OK;
740: }
741: }
742: }
743: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
744: }
745: return OK;
746: }
747:
748: sub process_changes {
749: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
750: my %domconfig;
751: if (ref($values) eq 'HASH') {
752: %domconfig = %{$values};
753: }
754: my $output;
755: if ($action eq 'login') {
756: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
757: } elsif ($action eq 'rolecolors') {
758: $output = &modify_rolecolors($r,$dom,$confname,$roles,
759: $lastactref,%domconfig);
760: } elsif ($action eq 'quotas') {
761: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
762: } elsif ($action eq 'autoenroll') {
763: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
764: } elsif ($action eq 'autoupdate') {
765: $output = &modify_autoupdate($dom,%domconfig);
766: } elsif ($action eq 'autocreate') {
767: $output = &modify_autocreate($dom,%domconfig);
768: } elsif ($action eq 'directorysrch') {
769: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
770: } elsif ($action eq 'usercreation') {
771: $output = &modify_usercreation($dom,%domconfig);
772: } elsif ($action eq 'selfcreation') {
773: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
774: } elsif ($action eq 'usermodification') {
775: $output = &modify_usermodification($dom,%domconfig);
776: } elsif ($action eq 'contacts') {
777: $output = &modify_contacts($dom,$lastactref,%domconfig);
778: } elsif ($action eq 'defaults') {
779: $output = &modify_defaults($dom,$lastactref,%domconfig);
780: } elsif ($action eq 'scantron') {
781: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
782: } elsif ($action eq 'coursecategories') {
783: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
784: } elsif ($action eq 'serverstatuses') {
785: $output = &modify_serverstatuses($dom,%domconfig);
786: } elsif ($action eq 'requestcourses') {
787: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
788: } elsif ($action eq 'requestauthor') {
789: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
790: } elsif ($action eq 'helpsettings') {
791: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
792: } elsif ($action eq 'coursedefaults') {
793: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
794: } elsif ($action eq 'selfenrollment') {
795: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
796: } elsif ($action eq 'usersessions') {
797: $output = &modify_usersessions($dom,$lastactref,%domconfig);
798: } elsif ($action eq 'loadbalancing') {
799: $output = &modify_loadbalancing($dom,%domconfig);
800: } elsif ($action eq 'ltitools') {
801: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
802: } elsif ($action eq 'lti') {
803: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
804: } elsif ($action eq 'passwords') {
805: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
806: } elsif ($action eq 'wafproxy') {
807: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
808: } elsif ($action eq 'ipaccess') {
809: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
810: }
811: return $output;
812: }
813:
814: sub print_config_box {
815: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
816: my $rowtotal = 0;
817: my $output;
818: if ($action eq 'coursecategories') {
819: $output = &coursecategories_javascript($settings);
820: } elsif ($action eq 'defaults') {
821: $output = &defaults_javascript($settings);
822: } elsif ($action eq 'passwords') {
823: $output = &passwords_javascript($action);
824: } elsif ($action eq 'helpsettings') {
825: my (%privs,%levelscurrent);
826: my %full=();
827: my %levels=(
828: course => {},
829: domain => {},
830: system => {},
831: );
832: my $context = 'domain';
833: my $crstype = 'Course';
834: my $formname = 'display';
835: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
836: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
837: $output =
838: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
839: \@templateroles);
840: } elsif ($action eq 'ltitools') {
841: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
842: } elsif ($action eq 'lti') {
843: $output .= &passwords_javascript('ltisecrets')."\n".
844: <i_javascript($dom,$settings);
845: } elsif ($action eq 'wafproxy') {
846: $output .= &wafproxy_javascript($dom);
847: } elsif ($action eq 'autoupdate') {
848: $output .= &autoupdate_javascript();
849: } elsif ($action eq 'autoenroll') {
850: $output .= &autoenroll_javascript();
851: } elsif ($action eq 'login') {
852: $output .= &saml_javascript();
853: } elsif ($action eq 'ipaccess') {
854: $output .= &ipaccess_javascript($settings);
855: }
856: $output .=
857: '<table class="LC_nested_outer">
858: <tr>
859: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
860: &mt($item->{text}).' '.
861: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
862: '</tr>';
863: $rowtotal ++;
864: my $numheaders = 1;
865: if (ref($item->{'header'}) eq 'ARRAY') {
866: $numheaders = scalar(@{$item->{'header'}});
867: }
868: if ($numheaders > 1) {
869: my $colspan = '';
870: my $rightcolspan = '';
871: my $leftnobr = '';
872: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
873: ($action eq 'directorysrch') ||
874: (($action eq 'login') && ($numheaders < 5))) {
875: $colspan = ' colspan="2"';
876: }
877: if ($action eq 'usersessions') {
878: $rightcolspan = ' colspan="3"';
879: }
880: if ($action eq 'passwords') {
881: $leftnobr = ' LC_nobreak';
882: }
883: $output .= '
884: <tr>
885: <td>
886: <table class="LC_nested">
887: <tr class="LC_info_row">
888: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
889: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
890: </tr>';
891: $rowtotal ++;
892: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
893: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
894: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
895: ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') ||
896: ($action eq 'lti') || ($action eq 'ltitools')) {
897: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
898: } elsif ($action eq 'passwords') {
899: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
900: } elsif ($action eq 'coursecategories') {
901: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
902: } elsif ($action eq 'scantron') {
903: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
904: } elsif ($action eq 'login') {
905: if ($numheaders == 5) {
906: $colspan = ' colspan="2"';
907: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
908: } else {
909: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
910: }
911: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
912: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
913: } elsif ($action eq 'rolecolors') {
914: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
915: }
916: $output .= '
917: </table>
918: </td>
919: </tr>
920: <tr>
921: <td>
922: <table class="LC_nested">
923: <tr class="LC_info_row">
924: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
925: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
926: </tr>';
927: $rowtotal ++;
928: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
929: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
930: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
931: ($action eq 'contacts') || ($action eq 'passwords') ||
932: ($action eq 'defaults') || ($action eq 'lti') ||
933: ($action eq 'ltitools')) {
934: if ($action eq 'coursecategories') {
935: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
936: $colspan = ' colspan="2"';
937: } elsif ($action eq 'passwords') {
938: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
939: } else {
940: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
941: }
942: $output .= '
943: </table>
944: </td>
945: </tr>
946: <tr>
947: <td>
948: <table class="LC_nested">
949: <tr class="LC_info_row">
950: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
951: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
952: </tr>'."\n";
953: if ($action eq 'coursecategories') {
954: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
955: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
956: if ($action eq 'passwords') {
957: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
958: } else {
959: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
960: }
961: $output .= '
962: </tr>
963: </table>
964: </td>
965: </tr>
966: <tr>
967: <td>
968: <table class="LC_nested">
969: <tr class="LC_info_row">
970: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
971: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
972: if ($action eq 'passwords') {
973: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
974: } else {
975: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
976: }
977: $output .= '
978: </table>
979: </td>
980: </tr>
981: <tr>';
982: } else {
983: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
984: }
985: $rowtotal ++;
986: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
987: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
988: ($action eq 'wafproxy')) {
989: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
990: } elsif ($action eq 'scantron') {
991: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
992: } elsif ($action eq 'login') {
993: if ($numheaders == 5) {
994: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
995: </table>
996: </td>
997: </tr>
998: <tr>
999: <td>
1000: <table class="LC_nested">
1001: <tr class="LC_info_row">
1002: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1003: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1004: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1005: $rowtotal ++;
1006: } else {
1007: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1008: }
1009: $output .= '
1010: </table>
1011: </td>
1012: </tr>
1013: <tr>
1014: <td>
1015: <table class="LC_nested">
1016: <tr class="LC_info_row">';
1017: if ($numheaders == 5) {
1018: $output .= '
1019: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1020: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1021: </tr>';
1022: } else {
1023: $output .= '
1024: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1025: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1026: </tr>';
1027: }
1028: $rowtotal ++;
1029: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1030: </table>
1031: </td>
1032: </tr>
1033: <tr>
1034: <td>
1035: <table class="LC_nested">
1036: <tr class="LC_info_row">';
1037: if ($numheaders == 5) {
1038: $output .= '
1039: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1040: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1041: </tr>';
1042: } else {
1043: $output .= '
1044: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1045: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1046: </tr>';
1047: }
1048: $rowtotal ++;
1049: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1050: } elsif ($action eq 'requestcourses') {
1051: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1052: $rowtotal ++;
1053: $output .= &print_studentcode($settings,\$rowtotal).'
1054: </table>
1055: </td>
1056: </tr>
1057: <tr>
1058: <td>
1059: <table class="LC_nested">
1060: <tr class="LC_info_row">
1061: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1062: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1063: &textbookcourses_javascript($settings).
1064: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1065: </table>
1066: </td>
1067: </tr>
1068: <tr>
1069: <td>
1070: <table class="LC_nested">
1071: <tr class="LC_info_row">
1072: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1073: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1074: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1075: </table>
1076: </td>
1077: </tr>
1078: <tr>
1079: <td>
1080: <table class="LC_nested">
1081: <tr class="LC_info_row">
1082: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1083: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1084: </tr>'.
1085: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1086: } elsif ($action eq 'requestauthor') {
1087: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1088: $rowtotal ++;
1089: } elsif ($action eq 'rolecolors') {
1090: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1091: </table>
1092: </td>
1093: </tr>
1094: <tr>
1095: <td>
1096: <table class="LC_nested">
1097: <tr class="LC_info_row">
1098: <td class="LC_left_item"'.$colspan.' valign="top">'.
1099: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1100: <td class="LC_right_item" valign="top">'.
1101: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1102: </tr>'.
1103: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1104: </table>
1105: </td>
1106: </tr>
1107: <tr>
1108: <td>
1109: <table class="LC_nested">
1110: <tr class="LC_info_row">
1111: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1112: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1113: </tr>'.
1114: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1115: $rowtotal += 2;
1116: }
1117: } else {
1118: $output .= '
1119: <tr>
1120: <td>
1121: <table class="LC_nested">
1122: <tr class="LC_info_row">';
1123: if ($action eq 'login') {
1124: $output .= '
1125: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1126: } elsif ($action eq 'serverstatuses') {
1127: $output .= '
1128: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1129: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1130:
1131: } else {
1132: $output .= '
1133: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1134: }
1135: if (defined($item->{'header'}->[0]->{'col3'})) {
1136: $output .= '<td class="LC_left_item" valign="top">'.
1137: &mt($item->{'header'}->[0]->{'col2'});
1138: if ($action eq 'serverstatuses') {
1139: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1140: }
1141: } else {
1142: $output .= '<td class="LC_right_item" valign="top">'.
1143: &mt($item->{'header'}->[0]->{'col2'});
1144: }
1145: $output .= '</td>';
1146: if ($item->{'header'}->[0]->{'col3'}) {
1147: if (defined($item->{'header'}->[0]->{'col4'})) {
1148: $output .= '<td class="LC_left_item" valign="top">'.
1149: &mt($item->{'header'}->[0]->{'col3'});
1150: } else {
1151: $output .= '<td class="LC_right_item" valign="top">'.
1152: &mt($item->{'header'}->[0]->{'col3'});
1153: }
1154: if ($action eq 'serverstatuses') {
1155: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1156: }
1157: $output .= '</td>';
1158: }
1159: if ($item->{'header'}->[0]->{'col4'}) {
1160: $output .= '<td class="LC_right_item" valign="top">'.
1161: &mt($item->{'header'}->[0]->{'col4'});
1162: }
1163: $output .= '</tr>';
1164: $rowtotal ++;
1165: if ($action eq 'quotas') {
1166: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1167: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1168: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1169: ($action eq 'ipaccess')) {
1170: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1171: }
1172: }
1173: $output .= '
1174: </table>
1175: </td>
1176: </tr>
1177: </table><br />';
1178: return ($output,$rowtotal);
1179: }
1180:
1181: sub print_login {
1182: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1183: my ($css_class,$datatable,$switchserver,%lt);
1184: my %choices = &login_choices();
1185: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1186: %lt = &login_file_options();
1187: $switchserver = &check_switchserver($dom,$confname);
1188: }
1189: if ($caller eq 'service') {
1190: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1191: my $choice = $choices{'disallowlogin'};
1192: $css_class = ' class="LC_odd_row"';
1193: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1194: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1195: '<th>'.$choices{'server'}.'</th>'.
1196: '<th>'.$choices{'serverpath'}.'</th>'.
1197: '<th>'.$choices{'custompath'}.'</th>'.
1198: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1199: my %disallowed;
1200: if (ref($settings) eq 'HASH') {
1201: if (ref($settings->{'loginvia'}) eq 'HASH') {
1202: %disallowed = %{$settings->{'loginvia'}};
1203: }
1204: }
1205: foreach my $lonhost (sort(keys(%servers))) {
1206: my $direct = 'selected="selected"';
1207: if (ref($disallowed{$lonhost}) eq 'HASH') {
1208: if ($disallowed{$lonhost}{'server'} ne '') {
1209: $direct = '';
1210: }
1211: }
1212: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1213: '<td><select name="'.$lonhost.'_server">'.
1214: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1215: '</option>';
1216: foreach my $hostid (sort(keys(%servers))) {
1217: next if ($servers{$hostid} eq $servers{$lonhost});
1218: my $selected = '';
1219: if (ref($disallowed{$lonhost}) eq 'HASH') {
1220: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1221: $selected = 'selected="selected"';
1222: }
1223: }
1224: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1225: $servers{$hostid}.'</option>';
1226: }
1227: $datatable .= '</select></td>'.
1228: '<td><select name="'.$lonhost.'_serverpath">';
1229: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1230: my $pathname = $path;
1231: if ($path eq 'custom') {
1232: $pathname = &mt('Custom Path').' ->';
1233: }
1234: my $selected = '';
1235: if (ref($disallowed{$lonhost}) eq 'HASH') {
1236: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1237: $selected = 'selected="selected"';
1238: }
1239: } elsif ($path eq '') {
1240: $selected = 'selected="selected"';
1241: }
1242: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1243: }
1244: $datatable .= '</select></td>';
1245: my ($custom,$exempt);
1246: if (ref($disallowed{$lonhost}) eq 'HASH') {
1247: $custom = $disallowed{$lonhost}{'custompath'};
1248: $exempt = $disallowed{$lonhost}{'exempt'};
1249: }
1250: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1251: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1252: '</tr>';
1253: }
1254: $datatable .= '</table></td></tr>';
1255: return $datatable;
1256: } elsif ($caller eq 'page') {
1257: my %defaultchecked = (
1258: 'coursecatalog' => 'on',
1259: 'helpdesk' => 'on',
1260: 'adminmail' => 'off',
1261: 'newuser' => 'off',
1262: );
1263: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1264: my (%checkedon,%checkedoff);
1265: foreach my $item (@toggles) {
1266: if ($defaultchecked{$item} eq 'on') {
1267: $checkedon{$item} = ' checked="checked" ';
1268: $checkedoff{$item} = ' ';
1269: } elsif ($defaultchecked{$item} eq 'off') {
1270: $checkedoff{$item} = ' checked="checked" ';
1271: $checkedon{$item} = ' ';
1272: }
1273: }
1274: my @images = ('img','logo','domlogo','login');
1275: my @alttext = ('img','logo','domlogo');
1276: my @logintext = ('textcol','bgcol');
1277: my @bgs = ('pgbg','mainbg','sidebg');
1278: my @links = ('link','alink','vlink');
1279: my %designhash = &Apache::loncommon::get_domainconf($dom);
1280: my %defaultdesign = %Apache::loncommon::defaultdesign;
1281: my (%is_custom,%designs);
1282: my %defaults = (
1283: font => $defaultdesign{'login.font'},
1284: );
1285: foreach my $item (@images) {
1286: $defaults{$item} = $defaultdesign{'login.'.$item};
1287: $defaults{'showlogo'}{$item} = 1;
1288: }
1289: foreach my $item (@bgs) {
1290: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1291: }
1292: foreach my $item (@logintext) {
1293: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1294: }
1295: foreach my $item (@links) {
1296: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1297: }
1298: if (ref($settings) eq 'HASH') {
1299: foreach my $item (@toggles) {
1300: if ($settings->{$item} eq '1') {
1301: $checkedon{$item} = ' checked="checked" ';
1302: $checkedoff{$item} = ' ';
1303: } elsif ($settings->{$item} eq '0') {
1304: $checkedoff{$item} = ' checked="checked" ';
1305: $checkedon{$item} = ' ';
1306: }
1307: }
1308: foreach my $item (@images) {
1309: if (defined($settings->{$item})) {
1310: $designs{$item} = $settings->{$item};
1311: $is_custom{$item} = 1;
1312: }
1313: if (defined($settings->{'showlogo'}{$item})) {
1314: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1315: }
1316: }
1317: foreach my $item (@alttext) {
1318: if (ref($settings->{'alttext'}) eq 'HASH') {
1319: if ($settings->{'alttext'}->{$item} ne '') {
1320: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1321: }
1322: }
1323: }
1324: foreach my $item (@logintext) {
1325: if ($settings->{$item} ne '') {
1326: $designs{'logintext'}{$item} = $settings->{$item};
1327: $is_custom{$item} = 1;
1328: }
1329: }
1330: if ($settings->{'font'} ne '') {
1331: $designs{'font'} = $settings->{'font'};
1332: $is_custom{'font'} = 1;
1333: }
1334: foreach my $item (@bgs) {
1335: if ($settings->{$item} ne '') {
1336: $designs{'bgs'}{$item} = $settings->{$item};
1337: $is_custom{$item} = 1;
1338: }
1339: }
1340: foreach my $item (@links) {
1341: if ($settings->{$item} ne '') {
1342: $designs{'links'}{$item} = $settings->{$item};
1343: $is_custom{$item} = 1;
1344: }
1345: }
1346: } else {
1347: if ($designhash{$dom.'.login.font'} ne '') {
1348: $designs{'font'} = $designhash{$dom.'.login.font'};
1349: $is_custom{'font'} = 1;
1350: }
1351: foreach my $item (@images) {
1352: if ($designhash{$dom.'.login.'.$item} ne '') {
1353: $designs{$item} = $designhash{$dom.'.login.'.$item};
1354: $is_custom{$item} = 1;
1355: }
1356: }
1357: foreach my $item (@bgs) {
1358: if ($designhash{$dom.'.login.'.$item} ne '') {
1359: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1360: $is_custom{$item} = 1;
1361: }
1362: }
1363: foreach my $item (@links) {
1364: if ($designhash{$dom.'.login.'.$item} ne '') {
1365: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1366: $is_custom{$item} = 1;
1367: }
1368: }
1369: }
1370: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1371: logo => 'Institution Logo',
1372: domlogo => 'Domain Logo',
1373: login => 'Login box');
1374: my $itemcount = 1;
1375: foreach my $item (@toggles) {
1376: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1377: $datatable .=
1378: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1379: '</td><td>'.
1380: '<span class="LC_nobreak"><label><input type="radio" name="'.
1381: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1382: '</label> <label><input type="radio" name="'.$item.'"'.
1383: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1384: '</tr>';
1385: $itemcount ++;
1386: }
1387: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1388: $datatable .= '</tr></table></td></tr>';
1389: } elsif ($caller eq 'help') {
1390: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1391: my $itemcount = 1;
1392: $defaulturl = '/adm/loginproblems.html';
1393: $defaulttype = 'default';
1394: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1395: my @currlangs;
1396: if (ref($settings) eq 'HASH') {
1397: if (ref($settings->{'helpurl'}) eq 'HASH') {
1398: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1399: next if ($settings->{'helpurl'}{$key} eq '');
1400: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1401: $type{$key} = 'custom';
1402: unless ($key eq 'nolang') {
1403: push(@currlangs,$key);
1404: }
1405: }
1406: } elsif ($settings->{'helpurl'} ne '') {
1407: $type{'nolang'} = 'custom';
1408: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1409: }
1410: }
1411: foreach my $lang ('nolang',sort(@currlangs)) {
1412: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1413: $datatable .= '<tr'.$css_class.'>';
1414: if ($url{$lang} eq '') {
1415: $url{$lang} = $defaulturl;
1416: }
1417: if ($type{$lang} eq '') {
1418: $type{$lang} = $defaulttype;
1419: }
1420: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1421: if ($lang eq 'nolang') {
1422: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1423: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1424: } else {
1425: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1426: $langchoices{$lang},
1427: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1428: }
1429: $datatable .= '</span></td>'."\n".
1430: '<td class="LC_left_item">';
1431: if ($type{$lang} eq 'custom') {
1432: $datatable .= '<span class="LC_nobreak"><label>'.
1433: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1434: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1435: } else {
1436: $datatable .= $lt{'upl'};
1437: }
1438: $datatable .='<br />';
1439: if ($switchserver) {
1440: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1441: } else {
1442: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1443: }
1444: $datatable .= '</td></tr>';
1445: $itemcount ++;
1446: }
1447: my @addlangs;
1448: foreach my $lang (sort(keys(%langchoices))) {
1449: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1450: push(@addlangs,$lang);
1451: }
1452: if (@addlangs > 0) {
1453: my %toadd;
1454: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1455: $toadd{''} = &mt('Select');
1456: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1457: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1458: &mt('Add log-in help page for a specific language:').' '.
1459: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1460: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1461: if ($switchserver) {
1462: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1463: } else {
1464: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1465: }
1466: $datatable .= '</td></tr>';
1467: $itemcount ++;
1468: }
1469: $datatable .= &captcha_choice('login',$settings,$itemcount);
1470: } elsif ($caller eq 'headtag') {
1471: my %domservers = &Apache::lonnet::get_servers($dom);
1472: my $choice = $choices{'headtag'};
1473: $css_class = ' class="LC_odd_row"';
1474: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1475: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1476: '<th>'.$choices{'current'}.'</th>'.
1477: '<th>'.$choices{'action'}.'</th>'.
1478: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1479: my (%currurls,%currexempt);
1480: if (ref($settings) eq 'HASH') {
1481: if (ref($settings->{'headtag'}) eq 'HASH') {
1482: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1483: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1484: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1485: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1486: }
1487: }
1488: }
1489: }
1490: foreach my $lonhost (sort(keys(%domservers))) {
1491: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1492: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1493: if ($currurls{$lonhost}) {
1494: $datatable .= '<td class="LC_right_item"><a href="'.
1495: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1496: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1497: '">'.$lt{'curr'}.'</a></td>'.
1498: '<td><span class="LC_nobreak"><label>'.
1499: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1500: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1501: } else {
1502: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1503: }
1504: $datatable .='<br />';
1505: if ($switchserver) {
1506: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1507: } else {
1508: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1509: }
1510: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1511: }
1512: $datatable .= '</table></td></tr>';
1513: } elsif ($caller eq 'saml') {
1514: my %domservers = &Apache::lonnet::get_servers($dom);
1515: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1516: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1517: '<th>'.$choices{'samllanding'}.'</th>'.
1518: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1519: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1520: foreach my $lonhost (keys(%domservers)) {
1521: $samlurl{$lonhost} = '/adm/sso';
1522: $styleon{$lonhost} = 'display:none';
1523: $styleoff{$lonhost} = '';
1524: }
1525: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1526: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1527: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1528: $saml{$lonhost} = 1;
1529: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1530: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1531: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1532: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1533: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1534: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1535: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1536: $styleon{$lonhost} = '';
1537: $styleoff{$lonhost} = 'display:none';
1538: } else {
1539: $styleon{$lonhost} = 'display:none';
1540: $styleoff{$lonhost} = '';
1541: }
1542: }
1543: }
1544: my $itemcount = 1;
1545: foreach my $lonhost (sort(keys(%domservers))) {
1546: my $samlon = ' ';
1547: my $samloff = ' checked="checked" ';
1548: if ($saml{$lonhost}) {
1549: $samlon = $samloff;
1550: $samloff = ' ';
1551: }
1552: my $samlwinon = '';
1553: my $samlwinoff = ' checked="checked"';
1554: if ($samlwindow{$lonhost}) {
1555: $samlwinon = $samlwinoff;
1556: $samlwinoff = '';
1557: }
1558: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1559: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1560: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1561: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1562: &mt('No').'</label>'.(' 'x2).
1563: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1564: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1565: &mt('Yes').'</label></span></td>'.
1566: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1567: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1568: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1569: '<th>'.&mt('Alt Text').'</th></tr>'.
1570: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1571: $samltext{$lonhost}.'" /></td><td>';
1572: if ($samlimg{$lonhost}) {
1573: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1574: '<span class="LC_nobreak"><label>'.
1575: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1576: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1577: } else {
1578: $datatable .= $lt{'upl'};
1579: }
1580: $datatable .='<br />';
1581: if ($switchserver) {
1582: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1583: } else {
1584: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1585: }
1586: $datatable .= '</td>'.
1587: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1588: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1589: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1590: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1591: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1592: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1593: '<tr'.$css_class.'>'.
1594: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1595: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1596: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1597: $samltitle{$lonhost}.'</textarea></td>'.
1598: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1599: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1600: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1601: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1602: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1603: '</table></td>'.
1604: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1605: $itemcount ++;
1606: }
1607: $datatable .= '</table></td></tr>';
1608: }
1609: return $datatable;
1610: }
1611:
1612: sub login_choices {
1613: my %choices =
1614: &Apache::lonlocal::texthash (
1615: coursecatalog => 'Display Course/Community Catalog link?',
1616: adminmail => "Display Administrator's E-mail Address?",
1617: helpdesk => 'Display "Contact Helpdesk" link',
1618: disallowlogin => "Login page requests redirected",
1619: hostid => "Server",
1620: server => "Redirect to:",
1621: serverpath => "Path",
1622: custompath => "Custom",
1623: exempt => "Exempt IP(s)",
1624: directlogin => "No redirect",
1625: newuser => "Link to create a user account",
1626: img => "Header",
1627: logo => "Main Logo",
1628: domlogo => "Domain Logo",
1629: login => "Log-in Header",
1630: textcol => "Text color",
1631: bgcol => "Box color",
1632: bgs => "Background colors",
1633: links => "Link colors",
1634: font => "Font color",
1635: pgbg => "Header",
1636: mainbg => "Page",
1637: sidebg => "Login box",
1638: link => "Link",
1639: alink => "Active link",
1640: vlink => "Visited link",
1641: headtag => "Custom markup",
1642: action => "Action",
1643: current => "Current",
1644: samllanding => "Dual login?",
1645: samloptions => "Options",
1646: alttext => "Alt text",
1647: );
1648: return %choices;
1649: }
1650:
1651: sub login_file_options {
1652: return &Apache::lonlocal::texthash(
1653: del => 'Delete?',
1654: rep => 'Replace:',
1655: upl => 'Upload:',
1656: curr => 'View contents',
1657: default => 'Default',
1658: custom => 'Custom',
1659: none => 'None',
1660: );
1661: }
1662:
1663: sub print_ipaccess {
1664: my ($dom,$settings,$rowtotal) = @_;
1665: my $css_class;
1666: my $itemcount = 0;
1667: my $datatable;
1668: my %ordered;
1669: if (ref($settings) eq 'HASH') {
1670: foreach my $item (keys(%{$settings})) {
1671: if (ref($settings->{$item}) eq 'HASH') {
1672: my $num = $settings->{$item}{'order'};
1673: if ($num eq '') {
1674: $num = scalar(keys(%{$settings}));
1675: }
1676: $ordered{$num} = $item;
1677: }
1678: }
1679: }
1680: my $maxnum = scalar(keys(%ordered));
1681: if (keys(%ordered)) {
1682: my @items = sort { $a <=> $b } keys(%ordered);
1683: for (my $i=0; $i<@items; $i++) {
1684: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1685: my $item = $ordered{$items[$i]};
1686: my ($name,$ipranges,%commblocks,%courses);
1687: if (ref($settings->{$item}) eq 'HASH') {
1688: $name = $settings->{$item}->{'name'};
1689: $ipranges = $settings->{$item}->{'ip'};
1690: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1691: %commblocks = %{$settings->{$item}->{'commblocks'}};
1692: }
1693: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1694: %courses = %{$settings->{$item}->{'courses'}};
1695: }
1696: }
1697: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1698: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1699: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1700: for (my $k=0; $k<=$maxnum; $k++) {
1701: my $vpos = $k+1;
1702: my $selstr;
1703: if ($k == $i) {
1704: $selstr = ' selected="selected" ';
1705: }
1706: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1707: }
1708: $datatable .= '</select>'.(' 'x2).
1709: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1710: &mt('Delete?').'</label></span></td>'.
1711: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1712: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1713: '</td></tr>';
1714: $itemcount ++;
1715: }
1716: }
1717: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1718: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1719: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1720: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1721: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1722: for (my $k=0; $k<$maxnum+1; $k++) {
1723: my $vpos = $k+1;
1724: my $selstr;
1725: if ($k == $maxnum) {
1726: $selstr = ' selected="selected" ';
1727: }
1728: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1729: }
1730: $datatable .= '</select> '."\n".
1731: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1732: '<td colspan="2">'.
1733: &ipaccess_options('add',$itemcount,$dom).
1734: '</td>'."\n".
1735: '</tr>'."\n";
1736: $$rowtotal ++;
1737: return $datatable;
1738: }
1739:
1740: sub ipaccess_options {
1741: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1742: my (%currblocks,%currcourses,$output);
1743: if (ref($blocksref) eq 'HASH') {
1744: %currblocks = %{$blocksref};
1745: }
1746: if (ref($coursesref) eq 'HASH') {
1747: %currcourses = %{$coursesref};
1748: }
1749: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1750: '<span class="LC_nobreak">'.&mt('Name').': '.
1751: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1752: '</span></fieldset>'.
1753: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1754: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1755: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1756: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1757: $ipranges.'</textarea></fieldset>'.
1758: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1759: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1760: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1761: '<table>';
1762: foreach my $cid (sort(keys(%currcourses))) {
1763: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1764: $output .= '<tr><td><span class="LC_nobreak">'.
1765: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1766: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1767: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1768: }
1769: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1770: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1771: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1772: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1773: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1774: '</span></td></tr></table>'."\n".
1775: '</fieldset>';
1776: return $output;
1777: }
1778:
1779: sub blocker_checkboxes {
1780: my ($num,$blocks) = @_;
1781: my ($typeorder,$types) = &commblocktype_text();
1782: my $numinrow = 6;
1783: my $output = '<table>';
1784: for (my $i=0; $i<@{$typeorder}; $i++) {
1785: my $block = $typeorder->[$i];
1786: my $blockstatus;
1787: if (ref($blocks) eq 'HASH') {
1788: if ($blocks->{$block} eq 'on') {
1789: $blockstatus = 'checked="checked"';
1790: }
1791: }
1792: my $rem = $i%($numinrow);
1793: if ($rem == 0) {
1794: if ($i > 0) {
1795: $output .= '</tr>';
1796: }
1797: $output .= '<tr>';
1798: }
1799: if ($i == scalar(@{$typeorder})-1) {
1800: my $colsleft = $numinrow-$rem;
1801: if ($colsleft > 1) {
1802: $output .= '<td colspan="'.$colsleft.'">';
1803: } else {
1804: $output .= '<td>';
1805: }
1806: } else {
1807: $output .= '<td>';
1808: }
1809: my $item = 'ipaccess_block_'.$num;
1810: if ($blockstatus) {
1811: $blockstatus = ' '.$blockstatus;
1812: }
1813: $output .= '<span class="LC_nobreak"><label>'."\n".
1814: '<input type="checkbox" name="'.$item.'"'.
1815: $blockstatus.' value="'.$block.'"'.' />'.
1816: $types->{$block}.'</label></span>'."\n".
1817: '<br /></td>';
1818: }
1819: $output .= '</tr></table>';
1820: return $output;
1821: }
1822:
1823: sub commblocktype_text {
1824: my %types = &Apache::lonlocal::texthash(
1825: 'com' => 'Messaging',
1826: 'chat' => 'Chat Room',
1827: 'boards' => 'Discussion',
1828: 'port' => 'Portfolio',
1829: 'groups' => 'Groups',
1830: 'blogs' => 'Blogs',
1831: 'about' => 'User Information',
1832: 'printout' => 'Printouts',
1833: 'passwd' => 'Change Password',
1834: 'grades' => 'Gradebook',
1835: 'search' => 'Course search',
1836: 'wishlist' => 'Stored links',
1837: 'annotate' => 'Annotations',
1838: );
1839: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1840: return ($typeorder,\%types);
1841: }
1842:
1843: sub print_rolecolors {
1844: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1845: my %choices = &color_font_choices();
1846: my @bgs = ('pgbg','tabbg','sidebg');
1847: my @links = ('link','alink','vlink');
1848: my @images = ('img');
1849: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1850: my %designhash = &Apache::loncommon::get_domainconf($dom);
1851: my %defaultdesign = %Apache::loncommon::defaultdesign;
1852: my (%is_custom,%designs);
1853: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1854: if (ref($settings) eq 'HASH') {
1855: if (ref($settings->{$role}) eq 'HASH') {
1856: if ($settings->{$role}->{'img'} ne '') {
1857: $designs{'img'} = $settings->{$role}->{'img'};
1858: $is_custom{'img'} = 1;
1859: }
1860: if ($settings->{$role}->{'font'} ne '') {
1861: $designs{'font'} = $settings->{$role}->{'font'};
1862: $is_custom{'font'} = 1;
1863: }
1864: if ($settings->{$role}->{'fontmenu'} ne '') {
1865: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1866: $is_custom{'fontmenu'} = 1;
1867: }
1868: foreach my $item (@bgs) {
1869: if ($settings->{$role}->{$item} ne '') {
1870: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1871: $is_custom{$item} = 1;
1872: }
1873: }
1874: foreach my $item (@links) {
1875: if ($settings->{$role}->{$item} ne '') {
1876: $designs{'links'}{$item} = $settings->{$role}->{$item};
1877: $is_custom{$item} = 1;
1878: }
1879: }
1880: }
1881: } else {
1882: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1883: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1884: $is_custom{'img'} = 1;
1885: }
1886: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1887: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1888: $is_custom{'fontmenu'} = 1;
1889: }
1890: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1891: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1892: $is_custom{'font'} = 1;
1893: }
1894: foreach my $item (@bgs) {
1895: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1896: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1897: $is_custom{$item} = 1;
1898:
1899: }
1900: }
1901: foreach my $item (@links) {
1902: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1903: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1904: $is_custom{$item} = 1;
1905: }
1906: }
1907: }
1908: my $itemcount = 1;
1909: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1910: $datatable .= '</tr></table></td></tr>';
1911: return $datatable;
1912: }
1913:
1914: sub role_defaults {
1915: my ($role,$bgs,$links,$images,$logintext) = @_;
1916: my %defaults;
1917: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1918: return %defaults;
1919: }
1920: my %defaultdesign = %Apache::loncommon::defaultdesign;
1921: if ($role eq 'login') {
1922: %defaults = (
1923: font => $defaultdesign{$role.'.font'},
1924: );
1925: if (ref($logintext) eq 'ARRAY') {
1926: foreach my $item (@{$logintext}) {
1927: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1928: }
1929: }
1930: foreach my $item (@{$images}) {
1931: $defaults{'showlogo'}{$item} = 1;
1932: }
1933: } else {
1934: %defaults = (
1935: img => $defaultdesign{$role.'.img'},
1936: font => $defaultdesign{$role.'.font'},
1937: fontmenu => $defaultdesign{$role.'.fontmenu'},
1938: );
1939: }
1940: foreach my $item (@{$bgs}) {
1941: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1942: }
1943: foreach my $item (@{$links}) {
1944: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1945: }
1946: foreach my $item (@{$images}) {
1947: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1948: }
1949: return %defaults;
1950: }
1951:
1952: sub display_color_options {
1953: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1954: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1955: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1956: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1957: my $datatable = '<tr'.$css_class.'>'.
1958: '<td>'.$choices->{'font'}.'</td>';
1959: if (!$is_custom->{'font'}) {
1960: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1961: } else {
1962: $datatable .= '<td> </td>';
1963: }
1964: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1965:
1966: $datatable .= '<td><span class="LC_nobreak">'.
1967: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1968: ' value="'.$current_color.'" /> '.
1969: ' </span></td></tr>';
1970: unless ($role eq 'login') {
1971: $datatable .= '<tr'.$css_class.'>'.
1972: '<td>'.$choices->{'fontmenu'}.'</td>';
1973: if (!$is_custom->{'fontmenu'}) {
1974: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1975: } else {
1976: $datatable .= '<td> </td>';
1977: }
1978: $current_color = $designs->{'fontmenu'} ?
1979: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1980: $datatable .= '<td><span class="LC_nobreak">'.
1981: '<input class="colorchooser" type="text" size="10" name="'
1982: .$role.'_fontmenu"'.
1983: ' value="'.$current_color.'" /> '.
1984: ' </span></td></tr>';
1985: }
1986: my $switchserver = &check_switchserver($dom,$confname);
1987: foreach my $img (@{$images}) {
1988: $itemcount ++;
1989: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1990: $datatable .= '<tr'.$css_class.'>'.
1991: '<td>'.$choices->{$img};
1992: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1993: if ($role eq 'login') {
1994: if ($img eq 'login') {
1995: $login_hdr_pick =
1996: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1997: $logincolors =
1998: &login_text_colors($img,$role,$logintext,$phase,$choices,
1999: $designs,$defaults);
2000: } else {
2001: if ($img ne 'domlogo') {
2002: $datatable.= &logo_display_options($img,$defaults,$designs);
2003: }
2004: if (ref($designs->{'alttext'}) eq 'HASH') {
2005: $alttext = $designs->{'alttext'}{$img};
2006: }
2007: }
2008: }
2009: $datatable .= '</td>';
2010: if ($designs->{$img} ne '') {
2011: $imgfile = $designs->{$img};
2012: $img_import = ($imgfile =~ m{^/adm/});
2013: } else {
2014: $imgfile = $defaults->{$img};
2015: }
2016: if ($imgfile) {
2017: my ($showfile,$fullsize);
2018: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
2019: my $urldir = $1;
2020: my $filename = $2;
2021: my @info = &Apache::lonnet::stat_file($designs->{$img});
2022: if (@info) {
2023: my $thumbfile = 'tn-'.$filename;
2024: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2025: if (@thumb) {
2026: $showfile = $urldir.'/'.$thumbfile;
2027: } else {
2028: $showfile = $imgfile;
2029: }
2030: } else {
2031: $showfile = '';
2032: }
2033: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
2034: $showfile = $imgfile;
2035: my $imgdir = $1;
2036: my $filename = $2;
2037: if (-e "$londocroot/$imgdir/tn-".$filename) {
2038: $showfile = "/$imgdir/tn-".$filename;
2039: } else {
2040: my $input = $londocroot.$imgfile;
2041: my $output = "$londocroot/$imgdir/tn-".$filename;
2042: if (!-e $output) {
2043: my ($width,$height) = &thumb_dimensions();
2044: my ($fullwidth,$fullheight) = &check_dimensions($input);
2045: if ($fullwidth ne '' && $fullheight ne '') {
2046: if ($fullwidth > $width && $fullheight > $height) {
2047: my $size = $width.'x'.$height;
2048: my @args = ('convert','-sample',$size,$input,$output);
2049: system({$args[0]} @args);
2050: $showfile = "/$imgdir/tn-".$filename;
2051: }
2052: }
2053: }
2054: }
2055: }
2056: if ($showfile) {
2057: if ($showfile =~ m{^/(adm|res)/}) {
2058: if ($showfile =~ m{^/res/}) {
2059: my $local_showfile =
2060: &Apache::lonnet::filelocation('',$showfile);
2061: &Apache::lonnet::repcopy($local_showfile);
2062: }
2063: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2064: }
2065: if ($imgfile) {
2066: if ($imgfile =~ m{^/(adm|res)/}) {
2067: if ($imgfile =~ m{^/res/}) {
2068: my $local_imgfile =
2069: &Apache::lonnet::filelocation('',$imgfile);
2070: &Apache::lonnet::repcopy($local_imgfile);
2071: }
2072: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2073: } else {
2074: $fullsize = $imgfile;
2075: }
2076: }
2077: $datatable .= '<td>';
2078: if ($img eq 'login') {
2079: $datatable .= $login_hdr_pick;
2080: }
2081: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2082: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
2083: } else {
2084: $datatable .= '<td> </td><td class="LC_left_item">'.
2085: &mt('Upload:').'<br />';
2086: }
2087: } else {
2088: $datatable .= '<td> </td><td class="LC_left_item">'.
2089: &mt('Upload:').'<br />';
2090: }
2091: if ($switchserver) {
2092: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2093: } else {
2094: if ($img ne 'login') { # suppress file selection for Log-in header
2095: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2096: }
2097: }
2098: if (($role eq 'login') && ($img ne 'login')) {
2099: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2100: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2101: '</label></span>';
2102: }
2103: $datatable .= '</td></tr>';
2104: }
2105: $itemcount ++;
2106: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2107: $datatable .= '<tr'.$css_class.'>'.
2108: '<td>'.$choices->{'bgs'}.'</td>';
2109: my $bgs_def;
2110: foreach my $item (@{$bgs}) {
2111: if (!$is_custom->{$item}) {
2112: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
2113: }
2114: }
2115: if ($bgs_def) {
2116: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
2117: } else {
2118: $datatable .= '<td> </td>';
2119: }
2120: $datatable .= '<td class="LC_right_item">'.
2121: '<table border="0"><tr>';
2122:
2123: foreach my $item (@{$bgs}) {
2124: $datatable .= '<td align="center">'.$choices->{$item};
2125: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
2126: if ($designs->{'bgs'}{$item}) {
2127: $datatable .= ' ';
2128: }
2129: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2130: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
2131: }
2132: $datatable .= '</tr></table></td></tr>';
2133: $itemcount ++;
2134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2135: $datatable .= '<tr'.$css_class.'>'.
2136: '<td>'.$choices->{'links'}.'</td>';
2137: my $links_def;
2138: foreach my $item (@{$links}) {
2139: if (!$is_custom->{$item}) {
2140: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
2141: }
2142: }
2143: if ($links_def) {
2144: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
2145: } else {
2146: $datatable .= '<td> </td>';
2147: }
2148: $datatable .= '<td class="LC_right_item">'.
2149: '<table border="0"><tr>';
2150: foreach my $item (@{$links}) {
2151: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
2152: $datatable .= '<td align="center">'.$choices->{$item}."\n";
2153: if ($designs->{'links'}{$item}) {
2154: $datatable.=' ';
2155: }
2156: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
2157: '" /></td>';
2158: }
2159: $$rowtotal += $itemcount;
2160: return $datatable;
2161: }
2162:
2163: sub logo_display_options {
2164: my ($img,$defaults,$designs) = @_;
2165: my $checkedon;
2166: if (ref($defaults) eq 'HASH') {
2167: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2168: if ($defaults->{'showlogo'}{$img}) {
2169: $checkedon = 'checked="checked" ';
2170: }
2171: }
2172: }
2173: if (ref($designs) eq 'HASH') {
2174: if (ref($designs->{'showlogo'}) eq 'HASH') {
2175: if (defined($designs->{'showlogo'}{$img})) {
2176: if ($designs->{'showlogo'}{$img} == 0) {
2177: $checkedon = '';
2178: } elsif ($designs->{'showlogo'}{$img} == 1) {
2179: $checkedon = 'checked="checked" ';
2180: }
2181: }
2182: }
2183: }
2184: return '<br /><label> <input type="checkbox" name="'.
2185: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2186: &mt('show').'</label>'."\n";
2187: }
2188:
2189: sub login_header_options {
2190: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2191: my $output = '';
2192: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
2193: $output .= &mt('Text default(s):').'<br />';
2194: if (!$is_custom->{'textcol'}) {
2195: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2196: ' ';
2197: }
2198: if (!$is_custom->{'bgcol'}) {
2199: $output .= $choices->{'bgcol'}.': '.
2200: '<span id="css_'.$role.'_font" style="background-color: '.
2201: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2202: }
2203: $output .= '<br />';
2204: }
2205: $output .='<br />';
2206: return $output;
2207: }
2208:
2209: sub login_text_colors {
2210: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
2211: my $color_menu = '<table border="0"><tr>';
2212: foreach my $item (@{$logintext}) {
2213: $color_menu .= '<td align="center">'.$choices->{$item};
2214: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2215: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2216: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
2217: }
2218: $color_menu .= '</tr></table><br />';
2219: return $color_menu;
2220: }
2221:
2222: sub image_changes {
2223: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2224: my $output;
2225: if ($img eq 'login') {
2226: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
2227: } elsif (!$is_custom) {
2228: if ($img ne 'domlogo') {
2229: $output = &mt('Default image:').'<br />';
2230: } else {
2231: $output = &mt('Default in use:').'<br />';
2232: }
2233: }
2234: if ($img ne 'login') {
2235: if ($img_import) {
2236: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2237: }
2238: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2239: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2240: if ($is_custom) {
2241: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2242: '<input type="checkbox" name="'.
2243: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2244: '</label> '.&mt('Replace:').'</span><br />';
2245: } else {
2246: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
2247: }
2248: }
2249: return $output;
2250: }
2251:
2252: sub print_quotas {
2253: my ($dom,$settings,$rowtotal,$action) = @_;
2254: my $context;
2255: if ($action eq 'quotas') {
2256: $context = 'tools';
2257: } else {
2258: $context = $action;
2259: }
2260: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
2261: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2262: my $typecount = 0;
2263: my ($css_class,%titles);
2264: if ($context eq 'requestcourses') {
2265: @usertools = ('official','unofficial','community','textbook','lti');
2266: @options =('norequest','approval','validate','autolimit');
2267: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2268: %titles = &courserequest_titles();
2269: } elsif ($context eq 'requestauthor') {
2270: @usertools = ('author');
2271: @options = ('norequest','approval','automatic');
2272: %titles = &authorrequest_titles();
2273: } else {
2274: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
2275: %titles = &tool_titles();
2276: }
2277: if (ref($types) eq 'ARRAY') {
2278: foreach my $type (@{$types}) {
2279: my ($currdefquota,$currauthorquota);
2280: unless (($context eq 'requestcourses') ||
2281: ($context eq 'requestauthor')) {
2282: if (ref($settings) eq 'HASH') {
2283: if (ref($settings->{defaultquota}) eq 'HASH') {
2284: $currdefquota = $settings->{defaultquota}->{$type};
2285: } else {
2286: $currdefquota = $settings->{$type};
2287: }
2288: if (ref($settings->{authorquota}) eq 'HASH') {
2289: $currauthorquota = $settings->{authorquota}->{$type};
2290: }
2291: }
2292: }
2293: if (defined($usertypes->{$type})) {
2294: $typecount ++;
2295: $css_class = $typecount%2?' class="LC_odd_row"':'';
2296: $datatable .= '<tr'.$css_class.'>'.
2297: '<td>'.$usertypes->{$type}.'</td>'.
2298: '<td class="LC_left_item">';
2299: if ($context eq 'requestcourses') {
2300: $datatable .= '<table><tr>';
2301: }
2302: my %cell;
2303: foreach my $item (@usertools) {
2304: if ($context eq 'requestcourses') {
2305: my ($curroption,$currlimit);
2306: if (ref($settings) eq 'HASH') {
2307: if (ref($settings->{$item}) eq 'HASH') {
2308: $curroption = $settings->{$item}->{$type};
2309: if ($curroption =~ /^autolimit=(\d*)$/) {
2310: $currlimit = $1;
2311: }
2312: }
2313: }
2314: if (!$curroption) {
2315: $curroption = 'norequest';
2316: }
2317: $datatable .= '<th>'.$titles{$item}.'</th>';
2318: foreach my $option (@options) {
2319: my $val = $option;
2320: if ($option eq 'norequest') {
2321: $val = 0;
2322: }
2323: if ($option eq 'validate') {
2324: my $canvalidate = 0;
2325: if (ref($validations{$item}) eq 'HASH') {
2326: if ($validations{$item}{$type}) {
2327: $canvalidate = 1;
2328: }
2329: }
2330: next if (!$canvalidate);
2331: }
2332: my $checked = '';
2333: if ($option eq $curroption) {
2334: $checked = ' checked="checked"';
2335: } elsif ($option eq 'autolimit') {
2336: if ($curroption =~ /^autolimit/) {
2337: $checked = ' checked="checked"';
2338: }
2339: }
2340: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2341: '<input type="radio" name="crsreq_'.$item.
2342: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
2343: $titles{$option}.'</label>';
2344: if ($option eq 'autolimit') {
2345: $cell{$item} .= ' <input type="text" name="crsreq_'.
2346: $item.'_limit_'.$type.'" size="1" '.
2347: 'value="'.$currlimit.'" />';
2348: }
2349: $cell{$item} .= '</span> ';
2350: if ($option eq 'autolimit') {
2351: $cell{$item} .= $titles{'unlimited'};
2352: }
2353: }
2354: } elsif ($context eq 'requestauthor') {
2355: my $curroption;
2356: if (ref($settings) eq 'HASH') {
2357: $curroption = $settings->{$type};
2358: }
2359: if (!$curroption) {
2360: $curroption = 'norequest';
2361: }
2362: foreach my $option (@options) {
2363: my $val = $option;
2364: if ($option eq 'norequest') {
2365: $val = 0;
2366: }
2367: my $checked = '';
2368: if ($option eq $curroption) {
2369: $checked = ' checked="checked"';
2370: }
2371: $datatable .= '<span class="LC_nobreak"><label>'.
2372: '<input type="radio" name="authorreq_'.$type.
2373: '" value="'.$val.'"'.$checked.' />'.
2374: $titles{$option}.'</label></span> ';
2375: }
2376: } else {
2377: my $checked = 'checked="checked" ';
2378: if ($item eq 'timezone') {
2379: $checked = '';
2380: }
2381: if (ref($settings) eq 'HASH') {
2382: if (ref($settings->{$item}) eq 'HASH') {
2383: if (!$settings->{$item}->{$type}) {
2384: $checked = '';
2385: } elsif ($settings->{$item}->{$type} == 1) {
2386: $checked = 'checked="checked" ';
2387: }
2388: }
2389: }
2390: $datatable .= '<span class="LC_nobreak"><label>'.
2391: '<input type="checkbox" name="'.$context.'_'.$item.
2392: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2393: '</label></span> ';
2394: }
2395: }
2396: if ($context eq 'requestcourses') {
2397: $datatable .= '</tr><tr>';
2398: foreach my $item (@usertools) {
2399: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
2400: }
2401: $datatable .= '</tr></table>';
2402: }
2403: $datatable .= '</td>';
2404: unless (($context eq 'requestcourses') ||
2405: ($context eq 'requestauthor')) {
2406: $datatable .=
2407: '<td class="LC_right_item">'.
2408: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2409: '<input type="text" name="quota_'.$type.
2410: '" value="'.$currdefquota.
2411: '" size="5" /></span>'.(' ' x 2).
2412: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2413: '<input type="text" name="authorquota_'.$type.
2414: '" value="'.$currauthorquota.
2415: '" size="5" /></span></td>';
2416: }
2417: $datatable .= '</tr>';
2418: }
2419: }
2420: }
2421: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2422: $defaultquota = '20';
2423: $authorquota = '500';
2424: if (ref($settings) eq 'HASH') {
2425: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2426: $defaultquota = $settings->{'defaultquota'}->{'default'};
2427: } elsif (defined($settings->{'default'})) {
2428: $defaultquota = $settings->{'default'};
2429: }
2430: if (ref($settings->{'authorquota'}) eq 'HASH') {
2431: $authorquota = $settings->{'authorquota'}->{'default'};
2432: }
2433: }
2434: }
2435: $typecount ++;
2436: $css_class = $typecount%2?' class="LC_odd_row"':'';
2437: $datatable .= '<tr'.$css_class.'>'.
2438: '<td>'.$othertitle.'</td>'.
2439: '<td class="LC_left_item">';
2440: if ($context eq 'requestcourses') {
2441: $datatable .= '<table><tr>';
2442: }
2443: my %defcell;
2444: foreach my $item (@usertools) {
2445: if ($context eq 'requestcourses') {
2446: my ($curroption,$currlimit);
2447: if (ref($settings) eq 'HASH') {
2448: if (ref($settings->{$item}) eq 'HASH') {
2449: $curroption = $settings->{$item}->{'default'};
2450: if ($curroption =~ /^autolimit=(\d*)$/) {
2451: $currlimit = $1;
2452: }
2453: }
2454: }
2455: if (!$curroption) {
2456: $curroption = 'norequest';
2457: }
2458: $datatable .= '<th>'.$titles{$item}.'</th>';
2459: foreach my $option (@options) {
2460: my $val = $option;
2461: if ($option eq 'norequest') {
2462: $val = 0;
2463: }
2464: if ($option eq 'validate') {
2465: my $canvalidate = 0;
2466: if (ref($validations{$item}) eq 'HASH') {
2467: if ($validations{$item}{'default'}) {
2468: $canvalidate = 1;
2469: }
2470: }
2471: next if (!$canvalidate);
2472: }
2473: my $checked = '';
2474: if ($option eq $curroption) {
2475: $checked = ' checked="checked"';
2476: } elsif ($option eq 'autolimit') {
2477: if ($curroption =~ /^autolimit/) {
2478: $checked = ' checked="checked"';
2479: }
2480: }
2481: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2482: '<input type="radio" name="crsreq_'.$item.
2483: '_default" value="'.$val.'"'.$checked.' />'.
2484: $titles{$option}.'</label>';
2485: if ($option eq 'autolimit') {
2486: $defcell{$item} .= ' <input type="text" name="crsreq_'.
2487: $item.'_limit_default" size="1" '.
2488: 'value="'.$currlimit.'" />';
2489: }
2490: $defcell{$item} .= '</span> ';
2491: if ($option eq 'autolimit') {
2492: $defcell{$item} .= $titles{'unlimited'};
2493: }
2494: }
2495: } elsif ($context eq 'requestauthor') {
2496: my $curroption;
2497: if (ref($settings) eq 'HASH') {
2498: $curroption = $settings->{'default'};
2499: }
2500: if (!$curroption) {
2501: $curroption = 'norequest';
2502: }
2503: foreach my $option (@options) {
2504: my $val = $option;
2505: if ($option eq 'norequest') {
2506: $val = 0;
2507: }
2508: my $checked = '';
2509: if ($option eq $curroption) {
2510: $checked = ' checked="checked"';
2511: }
2512: $datatable .= '<span class="LC_nobreak"><label>'.
2513: '<input type="radio" name="authorreq_default"'.
2514: ' value="'.$val.'"'.$checked.' />'.
2515: $titles{$option}.'</label></span> ';
2516: }
2517: } else {
2518: my $checked = 'checked="checked" ';
2519: if (ref($settings) eq 'HASH') {
2520: if (ref($settings->{$item}) eq 'HASH') {
2521: if ($settings->{$item}->{'default'} == 0) {
2522: $checked = '';
2523: } elsif ($settings->{$item}->{'default'} == 1) {
2524: $checked = 'checked="checked" ';
2525: }
2526: }
2527: }
2528: $datatable .= '<span class="LC_nobreak"><label>'.
2529: '<input type="checkbox" name="'.$context.'_'.$item.
2530: '" value="default" '.$checked.'/>'.$titles{$item}.
2531: '</label></span> ';
2532: }
2533: }
2534: if ($context eq 'requestcourses') {
2535: $datatable .= '</tr><tr>';
2536: foreach my $item (@usertools) {
2537: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
2538: }
2539: $datatable .= '</tr></table>';
2540: }
2541: $datatable .= '</td>';
2542: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2543: $datatable .= '<td class="LC_right_item">'.
2544: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2545: '<input type="text" name="defaultquota" value="'.
2546: $defaultquota.'" size="5" /></span>'.(' ' x2).
2547: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2548: '<input type="text" name="authorquota" value="'.
2549: $authorquota.'" size="5" /></span></td>';
2550: }
2551: $datatable .= '</tr>';
2552: $typecount ++;
2553: $css_class = $typecount%2?' class="LC_odd_row"':'';
2554: $datatable .= '<tr'.$css_class.'>'.
2555: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
2556: if ($context eq 'requestcourses') {
2557: $datatable .= &mt('(overrides affiliation, if set)').
2558: '</td>'.
2559: '<td class="LC_left_item">'.
2560: '<table><tr>';
2561: } else {
2562: $datatable .= &mt('(overrides affiliation, if checked)').
2563: '</td>'.
2564: '<td class="LC_left_item" colspan="2">'.
2565: '<br />';
2566: }
2567: my %advcell;
2568: foreach my $item (@usertools) {
2569: if ($context eq 'requestcourses') {
2570: my ($curroption,$currlimit);
2571: if (ref($settings) eq 'HASH') {
2572: if (ref($settings->{$item}) eq 'HASH') {
2573: $curroption = $settings->{$item}->{'_LC_adv'};
2574: if ($curroption =~ /^autolimit=(\d*)$/) {
2575: $currlimit = $1;
2576: }
2577: }
2578: }
2579: $datatable .= '<th>'.$titles{$item}.'</th>';
2580: my $checked = '';
2581: if ($curroption eq '') {
2582: $checked = ' checked="checked"';
2583: }
2584: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2585: '<input type="radio" name="crsreq_'.$item.
2586: '__LC_adv" value=""'.$checked.' />'.
2587: &mt('No override set').'</label></span> ';
2588: foreach my $option (@options) {
2589: my $val = $option;
2590: if ($option eq 'norequest') {
2591: $val = 0;
2592: }
2593: if ($option eq 'validate') {
2594: my $canvalidate = 0;
2595: if (ref($validations{$item}) eq 'HASH') {
2596: if ($validations{$item}{'_LC_adv'}) {
2597: $canvalidate = 1;
2598: }
2599: }
2600: next if (!$canvalidate);
2601: }
2602: my $checked = '';
2603: if ($val eq $curroption) {
2604: $checked = ' checked="checked"';
2605: } elsif ($option eq 'autolimit') {
2606: if ($curroption =~ /^autolimit/) {
2607: $checked = ' checked="checked"';
2608: }
2609: }
2610: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2611: '<input type="radio" name="crsreq_'.$item.
2612: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2613: $titles{$option}.'</label>';
2614: if ($option eq 'autolimit') {
2615: $advcell{$item} .= ' <input type="text" name="crsreq_'.
2616: $item.'_limit__LC_adv" size="1" '.
2617: 'value="'.$currlimit.'" />';
2618: }
2619: $advcell{$item} .= '</span> ';
2620: if ($option eq 'autolimit') {
2621: $advcell{$item} .= $titles{'unlimited'};
2622: }
2623: }
2624: } elsif ($context eq 'requestauthor') {
2625: my $curroption;
2626: if (ref($settings) eq 'HASH') {
2627: $curroption = $settings->{'_LC_adv'};
2628: }
2629: my $checked = '';
2630: if ($curroption eq '') {
2631: $checked = ' checked="checked"';
2632: }
2633: $datatable .= '<span class="LC_nobreak"><label>'.
2634: '<input type="radio" name="authorreq__LC_adv"'.
2635: ' value=""'.$checked.' />'.
2636: &mt('No override set').'</label></span> ';
2637: foreach my $option (@options) {
2638: my $val = $option;
2639: if ($option eq 'norequest') {
2640: $val = 0;
2641: }
2642: my $checked = '';
2643: if ($val eq $curroption) {
2644: $checked = ' checked="checked"';
2645: }
2646: $datatable .= '<span class="LC_nobreak"><label>'.
2647: '<input type="radio" name="authorreq__LC_adv"'.
2648: ' value="'.$val.'"'.$checked.' />'.
2649: $titles{$option}.'</label></span> ';
2650: }
2651: } else {
2652: my $checked = 'checked="checked" ';
2653: if (ref($settings) eq 'HASH') {
2654: if (ref($settings->{$item}) eq 'HASH') {
2655: if ($settings->{$item}->{'_LC_adv'} == 0) {
2656: $checked = '';
2657: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2658: $checked = 'checked="checked" ';
2659: }
2660: }
2661: }
2662: $datatable .= '<span class="LC_nobreak"><label>'.
2663: '<input type="checkbox" name="'.$context.'_'.$item.
2664: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2665: '</label></span> ';
2666: }
2667: }
2668: if ($context eq 'requestcourses') {
2669: $datatable .= '</tr><tr>';
2670: foreach my $item (@usertools) {
2671: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2672: }
2673: $datatable .= '</tr></table>';
2674: }
2675: $datatable .= '</td></tr>';
2676: $$rowtotal += $typecount;
2677: return $datatable;
2678: }
2679:
2680: sub print_requestmail {
2681: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
2682: my ($now,$datatable,%currapp);
2683: $now = time;
2684: if (ref($settings) eq 'HASH') {
2685: if (ref($settings->{'notify'}) eq 'HASH') {
2686: if ($settings->{'notify'}{'approval'} ne '') {
2687: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2688: }
2689: }
2690: }
2691: my $numinrow = 2;
2692: my $css_class;
2693: if ($$rowtotal%2) {
2694: $css_class = 'LC_odd_row';
2695: }
2696: if ($customcss) {
2697: $css_class .= " $customcss";
2698: }
2699: $css_class =~ s/^\s+//;
2700: if ($css_class) {
2701: $css_class = ' class="'.$css_class.'"';
2702: }
2703: if ($rowstyle) {
2704: $css_class .= ' style="'.$rowstyle.'"';
2705: }
2706: my $text;
2707: if ($action eq 'requestcourses') {
2708: $text = &mt('Receive notification of course requests requiring approval');
2709: } elsif ($action eq 'requestauthor') {
2710: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2711: } else {
2712: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2713: }
2714: $datatable = '<tr'.$css_class.'>'.
2715: ' <td>'.$text.'</td>'.
2716: ' <td class="LC_left_item">';
2717: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2718: $action.'notifyapproval',%currapp);
2719: if ($numdc > 0) {
2720: $datatable .= $table;
2721: } else {
2722: $datatable .= &mt('There are no active Domain Coordinators');
2723: }
2724: $datatable .='</td></tr>';
2725: return $datatable;
2726: }
2727:
2728: sub print_studentcode {
2729: my ($settings,$rowtotal) = @_;
2730: my $rownum = 0;
2731: my ($output,%current);
2732: my @crstypes = ('official','unofficial','community','textbook','lti');
2733: if (ref($settings) eq 'HASH') {
2734: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2735: foreach my $type (@crstypes) {
2736: $current{$type} = $settings->{'uniquecode'}{$type};
2737: }
2738: }
2739: }
2740: $output .= '<tr>'.
2741: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2742: '<td class="LC_left_item">';
2743: foreach my $type (@crstypes) {
2744: my $check = ' ';
2745: if ($current{$type}) {
2746: $check = ' checked="checked" ';
2747: }
2748: $output .= '<span class="LC_nobreak"><label>'.
2749: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2750: &mt($type).'</label></span>'.(' 'x2).' ';
2751: }
2752: $output .= '</td></tr>';
2753: $$rowtotal ++;
2754: return $output;
2755: }
2756:
2757: sub print_textbookcourses {
2758: my ($dom,$type,$settings,$rowtotal) = @_;
2759: my $rownum = 0;
2760: my $css_class;
2761: my $itemcount = 1;
2762: my $maxnum = 0;
2763: my $bookshash;
2764: if (ref($settings) eq 'HASH') {
2765: $bookshash = $settings->{$type};
2766: }
2767: my %ordered;
2768: if (ref($bookshash) eq 'HASH') {
2769: foreach my $item (keys(%{$bookshash})) {
2770: if (ref($bookshash->{$item}) eq 'HASH') {
2771: my $num = $bookshash->{$item}{'order'};
2772: $ordered{$num} = $item;
2773: }
2774: }
2775: }
2776: my $confname = $dom.'-domainconfig';
2777: my $switchserver = &check_switchserver($dom,$confname);
2778: my $maxnum = scalar(keys(%ordered));
2779: my $datatable;
2780: if (keys(%ordered)) {
2781: my @items = sort { $a <=> $b } keys(%ordered);
2782: for (my $i=0; $i<@items; $i++) {
2783: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2784: my $key = $ordered{$items[$i]};
2785: my %coursehash=&Apache::lonnet::coursedescription($key);
2786: my $coursetitle = $coursehash{'description'};
2787: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2788: if (ref($bookshash->{$key}) eq 'HASH') {
2789: $subject = $bookshash->{$key}->{'subject'};
2790: $title = $bookshash->{$key}->{'title'};
2791: if ($type eq 'textbooks') {
2792: $publisher = $bookshash->{$key}->{'publisher'};
2793: $author = $bookshash->{$key}->{'author'};
2794: $image = $bookshash->{$key}->{'image'};
2795: if ($image ne '') {
2796: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2797: my $imagethumb = "$path/tn-".$imagefile;
2798: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2799: }
2800: }
2801: }
2802: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2803: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2804: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2805: for (my $k=0; $k<=$maxnum; $k++) {
2806: my $vpos = $k+1;
2807: my $selstr;
2808: if ($k == $i) {
2809: $selstr = ' selected="selected" ';
2810: }
2811: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2812: }
2813: $datatable .= '</select>'.(' 'x2).
2814: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2815: &mt('Delete?').'</label></span></td>'.
2816: '<td colspan="2">'.
2817: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2818: (' 'x2).
2819: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2820: if ($type eq 'textbooks') {
2821: $datatable .= (' 'x2).
2822: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2823: (' 'x2).
2824: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2825: (' 'x2).
2826: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2827: if ($image) {
2828: $datatable .= $imgsrc.
2829: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2830: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2831: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2832: }
2833: if ($switchserver) {
2834: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2835: } else {
2836: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2837: }
2838: }
2839: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2840: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2841: $coursetitle.'</span></td></tr>'."\n";
2842: $itemcount ++;
2843: }
2844: }
2845: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2846: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2847: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2848: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2849: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2850: for (my $k=0; $k<$maxnum+1; $k++) {
2851: my $vpos = $k+1;
2852: my $selstr;
2853: if ($k == $maxnum) {
2854: $selstr = ' selected="selected" ';
2855: }
2856: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2857: }
2858: $datatable .= '</select> '."\n".
2859: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
2860: '<td colspan="2">'.
2861: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2862: (' 'x2).
2863: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2864: (' 'x2);
2865: if ($type eq 'textbooks') {
2866: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2867: (' 'x2).
2868: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2869: (' 'x2).
2870: '<span class="LC_nobreak">'.&mt('Image:').' ';
2871: if ($switchserver) {
2872: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2873: } else {
2874: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2875: }
2876: $datatable .= '</span>'."\n";
2877: }
2878: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2879: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2880: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2881: &Apache::loncommon::selectcourse_link
2882: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
2883: '</span></td>'."\n".
2884: '</tr>'."\n";
2885: $itemcount ++;
2886: return $datatable;
2887: }
2888:
2889: sub textbookcourses_javascript {
2890: my ($settings) = @_;
2891: return unless(ref($settings) eq 'HASH');
2892: my (%ordered,%total,%jstext);
2893: foreach my $type ('textbooks','templates') {
2894: $total{$type} = 0;
2895: if (ref($settings->{$type}) eq 'HASH') {
2896: foreach my $item (keys(%{$settings->{$type}})) {
2897: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2898: my $num = $settings->{$type}->{$item}{'order'};
2899: $ordered{$type}{$num} = $item;
2900: }
2901: }
2902: $total{$type} = scalar(keys(%{$settings->{$type}}));
2903: }
2904: my @jsarray = ();
2905: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2906: push(@jsarray,$ordered{$type}{$item});
2907: }
2908: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2909: }
2910: return <<"ENDSCRIPT";
2911: <script type="text/javascript">
2912: // <![CDATA[
2913: function reorderBooks(form,item,caller) {
2914: var changedVal;
2915: $jstext{'textbooks'};
2916: $jstext{'templates'};
2917: var newpos;
2918: var maxh;
2919: if (caller == 'textbooks') {
2920: newpos = 'textbooks_addbook_pos';
2921: maxh = 1 + $total{'textbooks'};
2922: } else {
2923: newpos = 'templates_addbook_pos';
2924: maxh = 1 + $total{'templates'};
2925: }
2926: var current = new Array;
2927: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2928: if (item == newpos) {
2929: changedVal = newitemVal;
2930: } else {
2931: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2932: current[newitemVal] = newpos;
2933: }
2934: if (caller == 'textbooks') {
2935: for (var i=0; i<textbooks.length; i++) {
2936: var elementName = 'textbooks_'+textbooks[i];
2937: if (elementName != item) {
2938: if (form.elements[elementName]) {
2939: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2940: current[currVal] = elementName;
2941: }
2942: }
2943: }
2944: }
2945: if (caller == 'templates') {
2946: for (var i=0; i<templates.length; i++) {
2947: var elementName = 'templates_'+templates[i];
2948: if (elementName != item) {
2949: if (form.elements[elementName]) {
2950: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2951: current[currVal] = elementName;
2952: }
2953: }
2954: }
2955: }
2956: var oldVal;
2957: for (var j=0; j<maxh; j++) {
2958: if (current[j] == undefined) {
2959: oldVal = j;
2960: }
2961: }
2962: if (oldVal < changedVal) {
2963: for (var k=oldVal+1; k<=changedVal ; k++) {
2964: var elementName = current[k];
2965: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2966: }
2967: } else {
2968: for (var k=changedVal; k<oldVal; k++) {
2969: var elementName = current[k];
2970: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2971: }
2972: }
2973: return;
2974: }
2975:
2976: // ]]>
2977: </script>
2978:
2979: ENDSCRIPT
2980: }
2981:
2982: sub ltitools_javascript {
2983: my ($settings) = @_;
2984: my $togglejs = <itools_toggle_js();
2985: unless (ref($settings) eq 'HASH') {
2986: return $togglejs;
2987: }
2988: my (%ordered,$total,%jstext);
2989: $total = 0;
2990: foreach my $item (keys(%{$settings})) {
2991: if (ref($settings->{$item}) eq 'HASH') {
2992: my $num = $settings->{$item}{'order'};
2993: $ordered{$num} = $item;
2994: }
2995: }
2996: $total = scalar(keys(%{$settings}));
2997: my @jsarray = ();
2998: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2999: push(@jsarray,$ordered{$item});
3000: }
3001: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3002: return <<"ENDSCRIPT";
3003: <script type="text/javascript">
3004: // <![CDATA[
3005: function reorderLTITools(form,item) {
3006: var changedVal;
3007: $jstext
3008: var newpos = 'ltitools_add_pos';
3009: var maxh = 1 + $total;
3010: var current = new Array;
3011: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3012: if (item == newpos) {
3013: changedVal = newitemVal;
3014: } else {
3015: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3016: current[newitemVal] = newpos;
3017: }
3018: for (var i=0; i<ltitools.length; i++) {
3019: var elementName = 'ltitools_'+ltitools[i];
3020: if (elementName != item) {
3021: if (form.elements[elementName]) {
3022: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3023: current[currVal] = elementName;
3024: }
3025: }
3026: }
3027: var oldVal;
3028: for (var j=0; j<maxh; j++) {
3029: if (current[j] == undefined) {
3030: oldVal = j;
3031: }
3032: }
3033: if (oldVal < changedVal) {
3034: for (var k=oldVal+1; k<=changedVal ; k++) {
3035: var elementName = current[k];
3036: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3037: }
3038: } else {
3039: for (var k=changedVal; k<oldVal; k++) {
3040: var elementName = current[k];
3041: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3042: }
3043: }
3044: return;
3045: }
3046:
3047: // ]]>
3048: </script>
3049:
3050: $togglejs
3051:
3052: ENDSCRIPT
3053: }
3054:
3055: sub ltitools_toggle_js {
3056: return <<"ENDSCRIPT";
3057: <script type="text/javascript">
3058: // <![CDATA[
3059:
3060: function toggleLTITools(form,setting,item) {
3061: var radioname = '';
3062: var divid = '';
3063: if ((setting == 'passback') || (setting == 'roster')) {
3064: radioname = 'ltitools_'+setting+'_'+item;
3065: divid = 'ltitools_'+setting+'time_'+item;
3066: var num = form.elements[radioname].length;
3067: if (num) {
3068: var setvis = '';
3069: for (var i=0; i<num; i++) {
3070: if (form.elements[radioname][i].checked) {
3071: if (form.elements[radioname][i].value == '1') {
3072: if (document.getElementById(divid)) {
3073: document.getElementById(divid).style.display = 'inline-block';
3074: }
3075: setvis = 1;
3076: }
3077: break;
3078: }
3079: }
3080: }
3081: if (!setvis) {
3082: if (document.getElementById(divid)) {
3083: document.getElementById(divid).style.display = 'none';
3084: }
3085: }
3086: }
3087: if (setting == 'user') {
3088: divid = 'ltitools_'+setting+'_div_'+item;
3089: var checkid = 'ltitools_'+setting+'_field_'+item;
3090: if (document.getElementById(divid)) {
3091: if (document.getElementById(checkid)) {
3092: if (document.getElementById(checkid).checked) {
3093: document.getElementById(divid).style.display = 'inline-block';
3094: } else {
3095: document.getElementById(divid).style.display = 'none';
3096: }
3097: }
3098: }
3099: }
3100: return;
3101: }
3102: // ]]>
3103: </script>
3104:
3105: ENDSCRIPT
3106: }
3107:
3108: sub wafproxy_javascript {
3109: my ($dom) = @_;
3110: return <<"ENDSCRIPT";
3111: <script type="text/javascript">
3112: // <![CDATA[
3113: function updateWAF() {
3114: if (document.getElementById('wafproxy_remoteip')) {
3115: var wafremote = 0;
3116: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3117: wafremote = 1;
3118: }
3119: var fields = new Array('header','trust');
3120: for (var i=0; i<fields.length; i++) {
3121: if (document.getElementById('wafproxy_'+fields[i])) {
3122: if (wafremote == 1) {
3123: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3124: }
3125: else {
3126: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3127: }
3128: }
3129: }
3130: if (document.getElementById('wafproxyranges_$dom')) {
3131: if (wafremote == 1) {
3132: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3133: } else {
3134: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3135: if (document.display.wafproxy_vpnaccess[i].checked) {
3136: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3137: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3138: }
3139: }
3140: }
3141: }
3142: }
3143: }
3144: return;
3145: }
3146:
3147: function checkWAF() {
3148: if (document.getElementById('wafproxy_remoteip')) {
3149: var wafvpn = 0;
3150: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3151: if (document.display.wafproxy_vpnaccess[i].checked) {
3152: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3153: wafvpn = 1;
3154: }
3155: break;
3156: }
3157: }
3158: var vpn = new Array('vpnint','vpnext');
3159: for (var i=0; i<vpn.length; i++) {
3160: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3161: if (wafvpn == 1) {
3162: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3163: }
3164: else {
3165: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3166: }
3167: }
3168: }
3169: if (document.getElementById('wafproxyranges_$dom')) {
3170: if (wafvpn == 1) {
3171: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3172: }
3173: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3174: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3175: }
3176: }
3177: }
3178: return;
3179: }
3180:
3181: function toggleWAF() {
3182: if (document.getElementById('wafproxy_table')) {
3183: var wafproxy = 0;
3184: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3185: if (document.display.wafproxy_${dom}[i].checked) {
3186: if (document.display.wafproxy_${dom}[i].value == 1) {
3187: wafproxy = 1;
3188: break;
3189: }
3190: }
3191: }
3192: if (wafproxy == 1) {
3193: document.getElementById('wafproxy_table').style.display='inline';
3194: }
3195: else {
3196: document.getElementById('wafproxy_table').style.display='none';
3197: }
3198: if (document.getElementById('wafproxyrow_${dom}')) {
3199: if (wafproxy == 1) {
3200: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3201: }
3202: else {
3203: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3204: }
3205: }
3206: if (document.getElementById('nowafproxyrow_$dom')) {
3207: if (wafproxy == 1) {
3208: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3209: }
3210: else {
3211: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3212: }
3213: }
3214: }
3215: return;
3216: }
3217: // ]]>
3218: </script>
3219:
3220: ENDSCRIPT
3221: }
3222:
3223: sub lti_javascript {
3224: my ($dom,$settings) = @_;
3225: my $togglejs = <i_toggle_js($dom);
3226: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
3227: unless (ref($settings) eq 'HASH') {
3228: return $togglejs.'
3229: <script type="text/javascript">
3230: // <![CDATA[
3231:
3232: '.$linkprot_js.'
3233:
3234: // ]]>
3235: </script>
3236: ';
3237: }
3238: my (%ordered,$total,%jstext);
3239: $total = scalar(keys(%{$settings}));
3240: foreach my $item (keys(%{$settings})) {
3241: if (ref($settings->{$item}) eq 'HASH') {
3242: my $num = $settings->{$item}{'order'};
3243: if ($num eq '') {
3244: $num = $total - 1;
3245: }
3246: $ordered{$num} = $item;
3247: }
3248: }
3249: my @jsarray = ();
3250: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3251: push(@jsarray,$ordered{$item});
3252: }
3253: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3254: return <<"ENDSCRIPT";
3255: <script type="text/javascript">
3256: // <![CDATA[
3257: function reorderLTI(form,item) {
3258: var changedVal;
3259: $jstext
3260: var newpos = 'lti_pos_add';
3261: var maxh = 1 + $total;
3262: var current = new Array;
3263: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3264: if (item == newpos) {
3265: changedVal = newitemVal;
3266: } else {
3267: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3268: current[newitemVal] = newpos;
3269: }
3270: for (var i=0; i<lti.length; i++) {
3271: var elementName = 'lti_pos_'+lti[i];
3272: if (elementName != item) {
3273: if (form.elements[elementName]) {
3274: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3275: current[currVal] = elementName;
3276: }
3277: }
3278: }
3279: var oldVal;
3280: for (var j=0; j<maxh; j++) {
3281: if (current[j] == undefined) {
3282: oldVal = j;
3283: }
3284: }
3285: if (oldVal < changedVal) {
3286: for (var k=oldVal+1; k<=changedVal ; k++) {
3287: var elementName = current[k];
3288: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3289: }
3290: } else {
3291: for (var k=changedVal; k<oldVal; k++) {
3292: var elementName = current[k];
3293: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3294: }
3295: }
3296: return;
3297: }
3298:
3299: $linkprot_js
3300:
3301: // ]]>
3302: </script>
3303:
3304: $togglejs
3305:
3306: ENDSCRIPT
3307: }
3308:
3309: sub lti_toggle_js {
3310: my ($dom) = @_;
3311: my %lcauthparmtext = &Apache::lonlocal::texthash (
3312: localauth => 'Local auth argument',
3313: krb => 'Kerberos domain',
3314: );
3315: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3316: &js_escape(\$crsincalert);
3317: my %servers = &Apache::lonnet::get_servers($dom,'library');
3318: my $primary = &Apache::lonnet::domain($dom,'primary');
3319: my $course_servers = "'".join("','",keys(%servers))."'";
3320: return <<"ENDSCRIPT";
3321: <script type="text/javascript">
3322: // <![CDATA[
3323:
3324: function toggleLTI(form,setting,item) {
3325: if ((setting == 'requser') || (setting == 'crsinc')) {
3326: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3327: var setvis = '';
3328: var radioname = 'lti_requser_'+item;
3329: var num = form.elements[radioname].length;
3330: if (num) {
3331: for (var i=0; i<num; i++) {
3332: if (form.elements[radioname][i].checked) {
3333: if (form.elements[radioname][i].value == '1') {
3334: setvis = 1;
3335: break;
3336: }
3337: }
3338: }
3339: }
3340: if (usrfieldsets.length) {
3341: for (var j=0; j<usrfieldsets.length; j++) {
3342: if (setvis) {
3343: usrfieldsets[j].style.display = 'block';
3344: } else {
3345: usrfieldsets[j].style.display = 'none';
3346: }
3347: }
3348: }
3349: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3350: if (crsfieldsets.length) {
3351: radioname = 'lti_crsinc_'+item;
3352: var num = form.elements[radioname].length;
3353: if (num) {
3354: var crsvis = '';
3355: for (var i=0; i<num; i++) {
3356: if (form.elements[radioname][i].checked) {
3357: if (form.elements[radioname][i].value == '1') {
3358: if (setvis == '') {
3359: if (setting == 'crsinc'){
3360: alert("$crsincalert");
3361: form.elements[radioname][0].checked = true;
3362: }
3363: } else {
3364: crsvis = 1;
3365: }
3366: break;
3367: }
3368: }
3369: }
3370: setvis = crsvis;
3371: }
3372: for (var j=0; j<crsfieldsets.length; j++) {
3373: if (setvis) {
3374: crsfieldsets[j].style.display = 'block';
3375: } else {
3376: crsfieldsets[j].style.display = 'none';
3377: }
3378: }
3379: }
3380: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
3381: var radioname = '';
3382: var divid = '';
3383: if (setting == 'user') {
3384: radioname = 'lti_mapuser_'+item;
3385: divid = 'lti_userfield_'+item;
3386: } else if (setting == 'crs') {
3387: radioname = 'lti_mapcrs_'+item;
3388: divid = 'lti_crsfield_'+item;
3389: } else if (setting == 'callback') {
3390: radioname = 'lti_callback_'+item;
3391: divid = 'lti_callbackfield_'+item;
3392: } else {
3393: radioname = 'lti_passback_'+item;
3394: divid = 'lti_passback_'+item;
3395: }
3396: var num = form.elements[radioname].length;
3397: if (num) {
3398: var setvis = '';
3399: for (var i=0; i<num; i++) {
3400: if (form.elements[radioname][i].checked) {
3401: if ((setting == 'passback') || (setting == 'callback')) {
3402: if (form.elements[radioname][i].value == '1') {
3403: if (document.getElementById(divid)) {
3404: document.getElementById(divid).style.display = 'inline-block';
3405: }
3406: setvis = 1;
3407: break;
3408: }
3409: } else {
3410: if (form.elements[radioname][i].value == 'other') {
3411: if (document.getElementById(divid)) {
3412: document.getElementById(divid).style.display = 'inline-block';
3413: }
3414: setvis = 1;
3415: break;
3416: }
3417: }
3418: }
3419: }
3420: if (!setvis) {
3421: if (document.getElementById(divid)) {
3422: document.getElementById(divid).style.display = 'none';
3423: }
3424: }
3425: }
3426: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3427: var numsec = form.elements['lti_crssec_'+item].length;
3428: if (numsec) {
3429: var setvis = '';
3430: for (var i=0; i<numsec; i++) {
3431: if (form.elements['lti_crssec_'+item][i].checked) {
3432: if (form.elements['lti_crssec_'+item][i].value == '1') {
3433: if (document.getElementById('lti_crssecfield_'+item)) {
3434: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3435: setvis = 1;
3436: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3437: if (numsrcsec) {
3438: var setsrcvis = '';
3439: for (var j=0; j<numsrcsec; j++) {
3440: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3441: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3442: if (document.getElementById('lti_secsrcfield_'+item)) {
3443: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3444: setsrcvis = 1;
3445: }
3446: }
3447: }
3448: }
3449: if (!setsrcvis) {
3450: if (document.getElementById('lti_secsrcfield_'+item)) {
3451: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3452: }
3453: }
3454: }
3455: }
3456: }
3457: }
3458: }
3459: if (!setvis) {
3460: if (document.getElementById('lti_crssecfield_'+item)) {
3461: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3462: }
3463: if (document.getElementById('lti_secsrcfield_'+item)) {
3464: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3465: }
3466: }
3467: }
3468: } else if (setting == 'lcauth') {
3469: var numauth = form.elements['lti_lcauth_'+item].length;
3470: if (numauth) {
3471: for (var i=0; i<numauth; i++) {
3472: if (form.elements['lti_lcauth_'+item][i].checked) {
3473: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3474: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3475: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3476: } else {
3477: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3478: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3479: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3480: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3481: } else {
3482: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3483: }
3484: }
3485: }
3486: }
3487: }
3488: }
3489: }
3490: } else if (setting == 'lcmenu') {
3491: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3492: var divid = 'lti_menufield_'+item;
3493: var setvis = '';
3494: for (var i=0; i<menus.length; i++) {
3495: var radioname = menus[i];
3496: var num = form.elements[radioname].length;
3497: if (num) {
3498: for (var j=0; j<num; j++) {
3499: if (form.elements[radioname][j].checked) {
3500: if (form.elements[radioname][j].value == '1') {
3501: if (document.getElementById(divid)) {
3502: document.getElementById(divid).style.display = 'inline-block';
3503: }
3504: setvis = 1;
3505: break;
3506: }
3507: }
3508: }
3509: }
3510: if (setvis == 1) {
3511: break;
3512: }
3513: }
3514: if (!setvis) {
3515: if (document.getElementById(divid)) {
3516: document.getElementById(divid).style.display = 'none';
3517: }
3518: }
3519: }
3520: return;
3521: }
3522:
3523: // ]]>
3524: </script>
3525:
3526: ENDSCRIPT
3527: }
3528:
3529: sub autoupdate_javascript {
3530: return <<"ENDSCRIPT";
3531: <script type="text/javascript">
3532: // <![CDATA[
3533: function toggleLastActiveDays(form) {
3534: var radioname = 'lastactive';
3535: var divid = 'lastactive_div';
3536: var num = form.elements[radioname].length;
3537: if (num) {
3538: var setvis = '';
3539: for (var i=0; i<num; i++) {
3540: if (form.elements[radioname][i].checked) {
3541: if (form.elements[radioname][i].value == '1') {
3542: if (document.getElementById(divid)) {
3543: document.getElementById(divid).style.display = 'inline-block';
3544: }
3545: setvis = 1;
3546: }
3547: break;
3548: }
3549: }
3550: if (!setvis) {
3551: if (document.getElementById(divid)) {
3552: document.getElementById(divid).style.display = 'none';
3553: }
3554: }
3555: }
3556: return;
3557: }
3558: // ]]>
3559: </script>
3560:
3561: ENDSCRIPT
3562: }
3563:
3564: sub autoenroll_javascript {
3565: return <<"ENDSCRIPT";
3566: <script type="text/javascript">
3567: // <![CDATA[
3568: function toggleFailsafe(form) {
3569: var radioname = 'autoenroll_failsafe';
3570: var divid = 'autoenroll_failsafe_div';
3571: var num = form.elements[radioname].length;
3572: if (num) {
3573: var setvis = '';
3574: for (var i=0; i<num; i++) {
3575: if (form.elements[radioname][i].checked) {
3576: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3577: if (document.getElementById(divid)) {
3578: document.getElementById(divid).style.display = 'inline-block';
3579: }
3580: setvis = 1;
3581: }
3582: break;
3583: }
3584: }
3585: if (!setvis) {
3586: if (document.getElementById(divid)) {
3587: document.getElementById(divid).style.display = 'none';
3588: }
3589: }
3590: }
3591: return;
3592: }
3593: // ]]>
3594: </script>
3595:
3596: ENDSCRIPT
3597: }
3598:
3599: sub saml_javascript {
3600: return <<"ENDSCRIPT";
3601: <script type="text/javascript">
3602: // <![CDATA[
3603: function toggleSamlOptions(form,hostid) {
3604: var radioname = 'saml_'+hostid;
3605: var tablecellon = 'samloptionson_'+hostid;
3606: var tablecelloff = 'samloptionsoff_'+hostid;
3607: var num = form.elements[radioname].length;
3608: if (num) {
3609: var setvis = '';
3610: for (var i=0; i<num; i++) {
3611: if (form.elements[radioname][i].checked) {
3612: if (form.elements[radioname][i].value == '1') {
3613: if (document.getElementById(tablecellon)) {
3614: document.getElementById(tablecellon).style.display='';
3615: }
3616: if (document.getElementById(tablecelloff)) {
3617: document.getElementById(tablecelloff).style.display='none';
3618: }
3619: setvis = 1;
3620: }
3621: break;
3622: }
3623: }
3624: if (!setvis) {
3625: if (document.getElementById(tablecellon)) {
3626: document.getElementById(tablecellon).style.display='none';
3627: }
3628: if (document.getElementById(tablecelloff)) {
3629: document.getElementById(tablecelloff).style.display='';
3630: }
3631: }
3632: }
3633: return;
3634: }
3635: // ]]>
3636: </script>
3637:
3638: ENDSCRIPT
3639: }
3640:
3641: sub ipaccess_javascript {
3642: my ($settings) = @_;
3643: my (%ordered,$total,%jstext);
3644: $total = 0;
3645: if (ref($settings) eq 'HASH') {
3646: foreach my $item (keys(%{$settings})) {
3647: if (ref($settings->{$item}) eq 'HASH') {
3648: my $num = $settings->{$item}{'order'};
3649: $ordered{$num} = $item;
3650: }
3651: }
3652: $total = scalar(keys(%{$settings}));
3653: }
3654: my @jsarray = ();
3655: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3656: push(@jsarray,$ordered{$item});
3657: }
3658: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3659: return <<"ENDSCRIPT";
3660: <script type="text/javascript">
3661: // <![CDATA[
3662: function reorderIPaccess(form,item) {
3663: var changedVal;
3664: $jstext
3665: var newpos = 'ipaccess_pos_add';
3666: var maxh = 1 + $total;
3667: var current = new Array;
3668: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3669: if (item == newpos) {
3670: changedVal = newitemVal;
3671: } else {
3672: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3673: current[newitemVal] = newpos;
3674: }
3675: for (var i=0; i<ipaccess.length; i++) {
3676: var elementName = 'ipaccess_pos_'+ipaccess[i];
3677: if (elementName != item) {
3678: if (form.elements[elementName]) {
3679: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3680: current[currVal] = elementName;
3681: }
3682: }
3683: }
3684: var oldVal;
3685: for (var j=0; j<maxh; j++) {
3686: if (current[j] == undefined) {
3687: oldVal = j;
3688: }
3689: }
3690: if (oldVal < changedVal) {
3691: for (var k=oldVal+1; k<=changedVal ; k++) {
3692: var elementName = current[k];
3693: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3694: }
3695: } else {
3696: for (var k=changedVal; k<oldVal; k++) {
3697: var elementName = current[k];
3698: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3699: }
3700: }
3701: return;
3702: }
3703: // ]]>
3704: </script>
3705:
3706: ENDSCRIPT
3707: }
3708:
3709: sub print_autoenroll {
3710: my ($dom,$settings,$rowtotal) = @_;
3711: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
3712: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3713: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3714: $failsafesty = 'none';
3715: %failsafechecked = (
3716: off => ' checked="checked"',
3717: );
3718: if (ref($settings) eq 'HASH') {
3719: if (exists($settings->{'run'})) {
3720: if ($settings->{'run'} eq '0') {
3721: $runoff = ' checked="checked" ';
3722: $runon = ' ';
3723: } else {
3724: $runon = ' checked="checked" ';
3725: $runoff = ' ';
3726: }
3727: } else {
3728: if ($autorun) {
3729: $runon = ' checked="checked" ';
3730: $runoff = ' ';
3731: } else {
3732: $runoff = ' checked="checked" ';
3733: $runon = ' ';
3734: }
3735: }
3736: if (exists($settings->{'co-owners'})) {
3737: if ($settings->{'co-owners'} eq '0') {
3738: $coownersoff = ' checked="checked" ';
3739: $coownerson = ' ';
3740: } else {
3741: $coownerson = ' checked="checked" ';
3742: $coownersoff = ' ';
3743: }
3744: } else {
3745: $coownersoff = ' checked="checked" ';
3746: $coownerson = ' ';
3747: }
3748: if (exists($settings->{'sender_domain'})) {
3749: $defdom = $settings->{'sender_domain'};
3750: }
3751: if (exists($settings->{'failsafe'})) {
3752: $failsafe = $settings->{'failsafe'};
3753: if ($failsafe eq 'zero') {
3754: $failsafechecked{'zero'} = ' checked="checked"';
3755: $failsafechecked{'off'} = '';
3756: $failsafesty = 'inline-block';
3757: } elsif ($failsafe eq 'any') {
3758: $failsafechecked{'any'} = ' checked="checked"';
3759: $failsafechecked{'off'} = '';
3760: }
3761: $autofailsafe = $settings->{'autofailsafe'};
3762: } elsif (exists($settings->{'autofailsafe'})) {
3763: $autofailsafe = $settings->{'autofailsafe'};
3764: if ($autofailsafe ne '') {
3765: $failsafechecked{'zero'} = ' checked="checked"';
3766: $failsafe = 'zero';
3767: $failsafechecked{'off'} = '';
3768: }
3769: }
3770: } else {
3771: if ($autorun) {
3772: $runon = ' checked="checked" ';
3773: $runoff = ' ';
3774: } else {
3775: $runoff = ' checked="checked" ';
3776: $runon = ' ';
3777: }
3778: }
3779: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
3780: my $notif_sender;
3781: if (ref($settings) eq 'HASH') {
3782: $notif_sender = $settings->{'sender_uname'};
3783: }
3784: my $datatable='<tr class="LC_odd_row">'.
3785: '<td>'.&mt('Auto-enrollment active?').'</td>'.
3786: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3787: '<input type="radio" name="autoenroll_run"'.
3788: $runon.' value="1" />'.&mt('Yes').'</label> '.
3789: '<label><input type="radio" name="autoenroll_run"'.
3790: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
3791: '</tr><tr>'.
3792: '<td>'.&mt('Notification messages - sender').
3793: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
3794: &mt('username').': '.
3795: '<input type="text" name="sender_uname" value="'.
3796: $notif_sender.'" size="10" /> '.&mt('domain').
3797: ': '.$domform.'</span></td></tr>'.
3798: '<tr class="LC_odd_row">'.
3799: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3800: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3801: '<input type="radio" name="autoassign_coowners"'.
3802: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3803: '<label><input type="radio" name="autoassign_coowners"'.
3804: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
3805: '</tr><tr>'.
3806: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3807: '<td class="LC_left_item"><span class="LC_nobreak">'.
3808: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
3809: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
3810: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
3811: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3812: '<span class="LC_nobreak">'.
3813: &mt('Threshold for number of students in section to drop: [_1]',
3814: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3815: '</span></div></td></tr>';
3816: $$rowtotal += 4;
3817: return $datatable;
3818: }
3819:
3820: sub print_autoupdate {
3821: my ($position,$dom,$settings,$rowtotal) = @_;
3822: my ($enable,$datatable);
3823: if ($position eq 'top') {
3824: my %choices = &Apache::lonlocal::texthash (
3825: run => 'Auto-update active?',
3826: classlists => 'Update information in classlists?',
3827: unexpired => 'Skip updates for users without active or future roles?',
3828: lastactive => 'Skip updates for inactive users?',
3829: );
3830: my $itemcount = 0;
3831: my $updateon = ' ';
3832: my $updateoff = ' checked="checked" ';
3833: if (ref($settings) eq 'HASH') {
3834: if ($settings->{'run'} eq '1') {
3835: $updateon = $updateoff;
3836: $updateoff = ' ';
3837: }
3838: }
3839: $enable = '<tr class="LC_odd_row">'.
3840: '<td>'.$choices{'run'}.'</td>'.
3841: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3842: '<input type="radio" name="autoupdate_run"'.
3843: $updateoff.'value="0" />'.&mt('No').'</label> '.
3844: '<label><input type="radio" name="autoupdate_run"'.
3845: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
3846: '</tr>';
3847: my @toggles = ('classlists','unexpired');
3848: my %defaultchecked = ('classlists' => 'off',
3849: 'unexpired' => 'off'
3850: );
3851: $$rowtotal ++;
3852: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3853: \%choices,$itemcount,'','','left','no');
3854: $datatable = $enable.$datatable;
3855: $$rowtotal += $itemcount;
3856: my $lastactiveon = ' ';
3857: my $lastactiveoff = ' checked="checked" ';
3858: my $lastactivestyle = 'none';
3859: my $lastactivedays;
3860: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3861: if (ref($settings) eq 'HASH') {
3862: if ($settings->{'lastactive'} =~ /^\d+$/) {
3863: $lastactiveon = $lastactiveoff;
3864: $lastactiveoff = ' ';
3865: $lastactivestyle = 'inline-block';
3866: $lastactivedays = $settings->{'lastactive'};
3867: }
3868: }
3869: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3870: $datatable .= '<tr'.$css_class.'>'.
3871: '<td>'.$choices{'lastactive'}.'</td>'.
3872: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3873: '<input type="radio" name="lastactive"'.
3874: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3875: ' <label>'.
3876: '<input type="radio" name="lastactive"'.
3877: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3878: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3879: ': '.&mt('inactive = no activity in last [_1] days',
3880: '<input type="text" size="5" name="lastactivedays" value="'.
3881: $lastactivedays.'" />').
3882: '</span></td>'.
3883: '</tr>';
3884: $$rowtotal ++;
3885: } elsif ($position eq 'middle') {
3886: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3887: my $numinrow = 3;
3888: my $locknamesettings;
3889: $datatable .= &insttypes_row($settings,$types,$usertypes,
3890: $dom,$numinrow,$othertitle,
3891: 'lockablenames',$rowtotal);
3892: $$rowtotal ++;
3893: } else {
3894: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3895: my @fields = ('lastname','firstname','middlename','generation',
3896: 'permanentemail','id');
3897: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3898: my $numrows = 0;
3899: if (ref($types) eq 'ARRAY') {
3900: if (@{$types} > 0) {
3901: $datatable =
3902: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3903: \@fields,$types,\$numrows);
3904: $$rowtotal += @{$types};
3905: }
3906: }
3907: $datatable .=
3908: &usertype_update_row($settings,{'default' => $othertitle},
3909: \%fieldtitles,\@fields,['default'],
3910: \$numrows);
3911: $$rowtotal ++;
3912: }
3913: return $datatable;
3914: }
3915:
3916: sub print_autocreate {
3917: my ($dom,$settings,$rowtotal) = @_;
3918: my (%createon,%createoff,%currhash);
3919: my @types = ('xml','req');
3920: if (ref($settings) eq 'HASH') {
3921: foreach my $item (@types) {
3922: $createoff{$item} = ' checked="checked" ';
3923: $createon{$item} = ' ';
3924: if (exists($settings->{$item})) {
3925: if ($settings->{$item}) {
3926: $createon{$item} = ' checked="checked" ';
3927: $createoff{$item} = ' ';
3928: }
3929: }
3930: }
3931: if ($settings->{'xmldc'} ne '') {
3932: $currhash{$settings->{'xmldc'}} = 1;
3933: }
3934: } else {
3935: foreach my $item (@types) {
3936: $createoff{$item} = ' checked="checked" ';
3937: $createon{$item} = ' ';
3938: }
3939: }
3940: $$rowtotal += 2;
3941: my $numinrow = 2;
3942: my $datatable='<tr class="LC_odd_row">'.
3943: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3944: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3945: '<input type="radio" name="autocreate_xml"'.
3946: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3947: '<label><input type="radio" name="autocreate_xml"'.
3948: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3949: '</td></tr><tr>'.
3950: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3951: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3952: '<input type="radio" name="autocreate_req"'.
3953: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3954: '<label><input type="radio" name="autocreate_req"'.
3955: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
3956: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3957: 'autocreate_xmldc',%currhash);
3958: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
3959: if ($numdc > 1) {
3960: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3961: '</td><td class="LC_left_item">';
3962: } else {
3963: $datatable .= &mt('Course creation processed as:').
3964: '</td><td class="LC_right_item">';
3965: }
3966: $datatable .= $dctable.'</td></tr>';
3967: $$rowtotal += $rows;
3968: return $datatable;
3969: }
3970:
3971: sub print_directorysrch {
3972: my ($position,$dom,$settings,$rowtotal) = @_;
3973: my $datatable;
3974: if ($position eq 'top') {
3975: my $instsrchon = ' ';
3976: my $instsrchoff = ' checked="checked" ';
3977: my ($exacton,$containson,$beginson);
3978: my $instlocalon = ' ';
3979: my $instlocaloff = ' checked="checked" ';
3980: if (ref($settings) eq 'HASH') {
3981: if ($settings->{'available'} eq '1') {
3982: $instsrchon = $instsrchoff;
3983: $instsrchoff = ' ';
3984: }
3985: if ($settings->{'localonly'} eq '1') {
3986: $instlocalon = $instlocaloff;
3987: $instlocaloff = ' ';
3988: }
3989: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3990: foreach my $type (@{$settings->{'searchtypes'}}) {
3991: if ($type eq 'exact') {
3992: $exacton = ' checked="checked" ';
3993: } elsif ($type eq 'contains') {
3994: $containson = ' checked="checked" ';
3995: } elsif ($type eq 'begins') {
3996: $beginson = ' checked="checked" ';
3997: }
3998: }
3999: } else {
4000: if ($settings->{'searchtypes'} eq 'exact') {
4001: $exacton = ' checked="checked" ';
4002: } elsif ($settings->{'searchtypes'} eq 'contains') {
4003: $containson = ' checked="checked" ';
4004: } elsif ($settings->{'searchtypes'} eq 'specify') {
4005: $exacton = ' checked="checked" ';
4006: $containson = ' checked="checked" ';
4007: }
4008: }
4009: }
4010: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4011: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4012:
4013: my $numinrow = 4;
4014: my $cansrchrow = 0;
4015: $datatable='<tr class="LC_odd_row">'.
4016: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4017: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4018: '<input type="radio" name="dirsrch_available"'.
4019: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4020: '<label><input type="radio" name="dirsrch_available"'.
4021: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4022: '</tr><tr>'.
4023: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4024: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4025: '<input type="radio" name="dirsrch_instlocalonly"'.
4026: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4027: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4028: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4029: '</tr>';
4030: $$rowtotal += 2;
4031: if (ref($usertypes) eq 'HASH') {
4032: if (keys(%{$usertypes}) > 0) {
4033: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4034: $numinrow,$othertitle,'cansearch',
4035: $rowtotal);
4036: $cansrchrow = 1;
4037: }
4038: }
4039: if ($cansrchrow) {
4040: $$rowtotal ++;
4041: $datatable .= '<tr>';
4042: } else {
4043: $datatable .= '<tr class="LC_odd_row">';
4044: }
4045: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4046: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4047: foreach my $title (@{$titleorder}) {
4048: if (defined($searchtitles->{$title})) {
4049: my $check = ' ';
4050: if (ref($settings) eq 'HASH') {
4051: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4052: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4053: $check = ' checked="checked" ';
4054: }
4055: }
4056: }
4057: $datatable .= '<td class="LC_left_item">'.
4058: '<span class="LC_nobreak"><label>'.
4059: '<input type="checkbox" name="searchby" '.
4060: 'value="'.$title.'"'.$check.'/>'.
4061: $searchtitles->{$title}.'</label></span></td>';
4062: }
4063: }
4064: $datatable .= '</tr></table></td></tr>';
4065: $$rowtotal ++;
4066: if ($cansrchrow) {
4067: $datatable .= '<tr class="LC_odd_row">';
4068: } else {
4069: $datatable .= '<tr>';
4070: }
4071: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4072: '<td class="LC_left_item" colspan="2">'.
4073: '<span class="LC_nobreak"><label>'.
4074: '<input type="checkbox" name="searchtypes" '.
4075: $exacton.' value="exact" />'.&mt('Exact match').
4076: '</label> '.
4077: '<label><input type="checkbox" name="searchtypes" '.
4078: $beginson.' value="begins" />'.&mt('Begins with').
4079: '</label> '.
4080: '<label><input type="checkbox" name="searchtypes" '.
4081: $containson.' value="contains" />'.&mt('Contains').
4082: '</label></span></td></tr>';
4083: $$rowtotal ++;
4084: } else {
4085: my $domsrchon = ' checked="checked" ';
4086: my $domsrchoff = ' ';
4087: my $domlocalon = ' ';
4088: my $domlocaloff = ' checked="checked" ';
4089: if (ref($settings) eq 'HASH') {
4090: if ($settings->{'lclocalonly'} eq '1') {
4091: $domlocalon = $domlocaloff;
4092: $domlocaloff = ' ';
4093: }
4094: if ($settings->{'lcavailable'} eq '0') {
4095: $domsrchoff = $domsrchon;
4096: $domsrchon = ' ';
4097: }
4098: }
4099: $datatable='<tr class="LC_odd_row">'.
4100: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4101: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4102: '<input type="radio" name="dirsrch_domavailable"'.
4103: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4104: '<label><input type="radio" name="dirsrch_domavailable"'.
4105: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4106: '</tr><tr>'.
4107: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4108: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4109: '<input type="radio" name="dirsrch_domlocalonly"'.
4110: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4111: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4112: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4113: '</tr>';
4114: $$rowtotal += 2;
4115: }
4116: return $datatable;
4117: }
4118:
4119: sub print_contacts {
4120: my ($position,$dom,$settings,$rowtotal) = @_;
4121: my $datatable;
4122: my @contacts = ('adminemail','supportemail');
4123: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
4124: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
4125: if ($position eq 'top') {
4126: if (ref($settings) eq 'HASH') {
4127: foreach my $item (@contacts) {
4128: if (exists($settings->{$item})) {
4129: $to{$item} = $settings->{$item};
4130: }
4131: }
4132: }
4133: } elsif ($position eq 'middle') {
4134: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
4135: 'updatesmail','idconflictsmail','hostipmail');
4136: foreach my $type (@mailings) {
4137: $otheremails{$type} = '';
4138: }
4139: } elsif ($position eq 'lower') {
4140: if (ref($settings) eq 'HASH') {
4141: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4142: %lonstatus = %{$settings->{'lonstatus'}};
4143: }
4144: }
4145: } else {
4146: @mailings = ('helpdeskmail','otherdomsmail');
4147: foreach my $type (@mailings) {
4148: $otheremails{$type} = '';
4149: }
4150: $bccemails{'helpdeskmail'} = '';
4151: $bccemails{'otherdomsmail'} = '';
4152: $includestr{'helpdeskmail'} = '';
4153: $includestr{'otherdomsmail'} = '';
4154: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4155: }
4156: if (ref($settings) eq 'HASH') {
4157: unless (($position eq 'top') || ($position eq 'lower')) {
4158: foreach my $type (@mailings) {
4159: if (exists($settings->{$type})) {
4160: if (ref($settings->{$type}) eq 'HASH') {
4161: foreach my $item (@contacts) {
4162: if ($settings->{$type}{$item}) {
4163: $checked{$type}{$item} = ' checked="checked" ';
4164: }
4165: }
4166: $otheremails{$type} = $settings->{$type}{'others'};
4167: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4168: $bccemails{$type} = $settings->{$type}{'bcc'};
4169: if ($settings->{$type}{'include'} ne '') {
4170: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4171: $includestr{$type} = &unescape($includestr{$type});
4172: }
4173: }
4174: }
4175: } elsif ($type eq 'lonstatusmail') {
4176: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4177: }
4178: }
4179: }
4180: if ($position eq 'bottom') {
4181: foreach my $type (@mailings) {
4182: $bccemails{$type} = $settings->{$type}{'bcc'};
4183: if ($settings->{$type}{'include'} ne '') {
4184: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4185: $includestr{$type} = &unescape($includestr{$type});
4186: }
4187: }
4188: if (ref($settings->{'helpform'}) eq 'HASH') {
4189: if (ref($fields) eq 'ARRAY') {
4190: foreach my $field (@{$fields}) {
4191: $currfield{$field} = $settings->{'helpform'}{$field};
4192: }
4193: }
4194: if (exists($settings->{'helpform'}{'maxsize'})) {
4195: $maxsize = $settings->{'helpform'}{'maxsize'};
4196: } else {
4197: $maxsize = '1.0';
4198: }
4199: } else {
4200: if (ref($fields) eq 'ARRAY') {
4201: foreach my $field (@{$fields}) {
4202: $currfield{$field} = 'yes';
4203: }
4204: }
4205: $maxsize = '1.0';
4206: }
4207: }
4208: } else {
4209: if ($position eq 'top') {
4210: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4211: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4212: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4213: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
4214: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4215: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4216: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4217: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
4218: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
4219: } elsif ($position eq 'bottom') {
4220: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4221: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4222: if (ref($fields) eq 'ARRAY') {
4223: foreach my $field (@{$fields}) {
4224: $currfield{$field} = 'yes';
4225: }
4226: }
4227: $maxsize = '1.0';
4228: }
4229: }
4230: my ($titles,$short_titles) = &contact_titles();
4231: my $rownum = 0;
4232: my $css_class;
4233: if ($position eq 'top') {
4234: foreach my $item (@contacts) {
4235: $css_class = $rownum%2?' class="LC_odd_row"':'';
4236: $datatable .= '<tr'.$css_class.'>'.
4237: '<td><span class="LC_nobreak">'.$titles->{$item}.
4238: '</span></td><td class="LC_right_item">'.
4239: '<input type="text" name="'.$item.'" value="'.
4240: $to{$item}.'" /></td></tr>';
4241: $rownum ++;
4242: }
4243: } elsif ($position eq 'bottom') {
4244: $css_class = $rownum%2?' class="LC_odd_row"':'';
4245: $datatable .= '<tr'.$css_class.'>'.
4246: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4247: &mt('(e-mail, subject, and description always shown)').
4248: '</td><td class="LC_left_item">';
4249: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4250: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4251: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4252: foreach my $field (@{$fields}) {
4253: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4254: if (($field eq 'screenshot') || ($field eq 'cc')) {
4255: $datatable .= ' '.&mt('(logged-in users)');
4256: }
4257: $datatable .='</td><td>';
4258: my $clickaction;
4259: if ($field eq 'screenshot') {
4260: $clickaction = ' onclick="screenshotSize(this);"';
4261: }
4262: if (ref($possoptions->{$field}) eq 'ARRAY') {
4263: foreach my $option (@{$possoptions->{$field}}) {
4264: my $checked;
4265: if ($currfield{$field} eq $option) {
4266: $checked = ' checked="checked"';
4267: }
4268: $datatable .= '<span class="LC_nobreak"><label>'.
4269: '<input type="radio" name="helpform_'.$field.'" '.
4270: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4271: '</label></span>'.(' 'x2);
4272: }
4273: }
4274: if ($field eq 'screenshot') {
4275: my $display;
4276: if ($currfield{$field} eq 'no') {
4277: $display = ' style="display:none"';
4278: }
4279: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4280: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4281: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4282: }
4283: $datatable .= '</td></tr>';
4284: }
4285: $datatable .= '</table>';
4286: }
4287: $datatable .= '</td></tr>'."\n";
4288: $rownum ++;
4289: }
4290: unless (($position eq 'top') || ($position eq 'lower')) {
4291: foreach my $type (@mailings) {
4292: $css_class = $rownum%2?' class="LC_odd_row"':'';
4293: $datatable .= '<tr'.$css_class.'>'.
4294: '<td><span class="LC_nobreak">'.
4295: $titles->{$type}.': </span></td>'.
4296: '<td class="LC_left_item">';
4297: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4298: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4299: }
4300: $datatable .= '<span class="LC_nobreak">';
4301: foreach my $item (@contacts) {
4302: $datatable .= '<label>'.
4303: '<input type="checkbox" name="'.$type.'"'.
4304: $checked{$type}{$item}.
4305: ' value="'.$item.'" />'.$short_titles->{$item}.
4306: '</label> ';
4307: }
4308: $datatable .= '</span><br />'.&mt('Others').': '.
4309: '<input type="text" name="'.$type.'_others" '.
4310: 'value="'.$otheremails{$type}.'" />';
4311: my %locchecked;
4312: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4313: foreach my $loc ('s','b') {
4314: if ($includeloc{$type} eq $loc) {
4315: $locchecked{$loc} = ' checked="checked"';
4316: last;
4317: }
4318: }
4319: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4320: '<input type="text" name="'.$type.'_bcc" '.
4321: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4322: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4323: &mt('Text automatically added to e-mail:').' '.
4324: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
4325: '<span class="LC_nobreak">'.&mt('Location:').' '.
4326: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4327: (' 'x2).
4328: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4329: '</span></fieldset>';
4330: }
4331: $datatable .= '</td></tr>'."\n";
4332: $rownum ++;
4333: }
4334: }
4335: if ($position eq 'middle') {
4336: my %choices;
4337: my $corelink = &core_link_msu();
4338: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
4339: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
4340: $corelink);
4341: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4342: my @toggles = ('reporterrors','reportupdates','reportstatus');
4343: my %defaultchecked = ('reporterrors' => 'on',
4344: 'reportupdates' => 'on',
4345: 'reportstatus' => 'on');
4346: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4347: \%choices,$rownum);
4348: $datatable .= $reports;
4349: } elsif ($position eq 'lower') {
4350: my (%current,%excluded,%weights);
4351: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4352: if ($lonstatus{'threshold'} =~ /^\d+$/) {
4353: $current{'errorthreshold'} = $lonstatus{'threshold'};
4354: } else {
4355: $current{'errorthreshold'} = $defaults->{'threshold'};
4356: }
4357: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
4358: $current{'errorsysmail'} = $lonstatus{'sysmail'};
4359: } else {
4360: $current{'errorsysmail'} = $defaults->{'sysmail'};
4361: }
4362: if (ref($lonstatus{'weights'}) eq 'HASH') {
4363: foreach my $type ('E','W','N','U') {
4364: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4365: $weights{$type} = $lonstatus{'weights'}{$type};
4366: } else {
4367: $weights{$type} = $defaults->{$type};
4368: }
4369: }
4370: } else {
4371: foreach my $type ('E','W','N','U') {
4372: $weights{$type} = $defaults->{$type};
4373: }
4374: }
4375: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4376: if (@{$lonstatus{'excluded'}} > 0) {
4377: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4378: }
4379: }
4380: foreach my $item ('errorthreshold','errorsysmail') {
4381: $css_class = $rownum%2?' class="LC_odd_row"':'';
4382: $datatable .= '<tr'.$css_class.'>'.
4383: '<td class="LC_left_item"><span class="LC_nobreak">'.
4384: $titles->{$item}.
4385: '</span></td><td class="LC_left_item">'.
4386: '<input type="text" name="'.$item.'" value="'.
4387: $current{$item}.'" size="5" /></td></tr>';
4388: $rownum ++;
4389: }
4390: $css_class = $rownum%2?' class="LC_odd_row"':'';
4391: $datatable .= '<tr'.$css_class.'>'.
4392: '<td class="LC_left_item">'.
4393: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4394: '</span></td><td class="LC_left_item"><table><tr>';
4395: foreach my $type ('E','W','N','U') {
4396: $datatable .= '<td>'.$names->{$type}.'<br />'.
4397: '<input type="text" name="errorweights_'.$type.'" value="'.
4398: $weights{$type}.'" size="5" /></td>';
4399: }
4400: $datatable .= '</tr></table></tr>';
4401: $rownum ++;
4402: $css_class = $rownum%2?' class="LC_odd_row"':'';
4403: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4404: $titles->{'errorexcluded'}.'</td>'.
4405: '<td class="LC_left_item"><table>';
4406: my $numinrow = 4;
4407: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4408: for (my $i=0; $i<@ids; $i++) {
4409: my $rem = $i%($numinrow);
4410: if ($rem == 0) {
4411: if ($i > 0) {
4412: $datatable .= '</tr>';
4413: }
4414: $datatable .= '<tr>';
4415: }
4416: my $check;
4417: if ($excluded{$ids[$i]}) {
4418: $check = ' checked="checked" ';
4419: }
4420: $datatable .= '<td class="LC_left_item">'.
4421: '<span class="LC_nobreak"><label>'.
4422: '<input type="checkbox" name="errorexcluded" '.
4423: 'value="'.$ids[$i].'"'.$check.' />'.
4424: $ids[$i].'</label></span></td>';
4425: }
4426: my $colsleft = $numinrow - @ids%($numinrow);
4427: if ($colsleft > 1 ) {
4428: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4429: ' </td>';
4430: } elsif ($colsleft == 1) {
4431: $datatable .= '<td class="LC_left_item"> </td>';
4432: }
4433: $datatable .= '</tr></table></td></tr>';
4434: $rownum ++;
4435: } elsif ($position eq 'bottom') {
4436: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4437: my (@posstypes,%usertypeshash);
4438: if (ref($types) eq 'ARRAY') {
4439: @posstypes = @{$types};
4440: }
4441: if (@posstypes) {
4442: if (ref($usertypes) eq 'HASH') {
4443: %usertypeshash = %{$usertypes};
4444: }
4445: my @overridden;
4446: my $numinrow = 4;
4447: if (ref($settings) eq 'HASH') {
4448: if (ref($settings->{'overrides'}) eq 'HASH') {
4449: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4450: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4451: push(@overridden,$key);
4452: foreach my $item (@contacts) {
4453: if ($settings->{'overrides'}{$key}{$item}) {
4454: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4455: }
4456: }
4457: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4458: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4459: $includeloc{'override_'.$key} = '';
4460: $includestr{'override_'.$key} = '';
4461: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4462: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4463: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4464: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4465: }
4466: }
4467: }
4468: }
4469: }
4470: my $customclass = 'LC_helpdesk_override';
4471: my $optionsprefix = 'LC_options_helpdesk_';
4472:
4473: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4474: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4475: $numinrow,$othertitle,'overrides',
4476: \$rownum,$onclicktypes,$customclass);
4477: $rownum ++;
4478: $usertypeshash{'default'} = $othertitle;
4479: foreach my $status (@posstypes) {
4480: my $css_class;
4481: if ($rownum%2) {
4482: $css_class = 'LC_odd_row ';
4483: }
4484: $css_class .= $customclass;
4485: my $rowid = $optionsprefix.$status;
4486: my $hidden = 1;
4487: my $currstyle = 'display:none';
4488: if (grep(/^\Q$status\E$/,@overridden)) {
4489: $currstyle = 'display:table-row';
4490: $hidden = 0;
4491: }
4492: my $key = 'override_'.$status;
4493: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4494: $includeloc{$key},$includestr{$key},$status,$rowid,
4495: $usertypeshash{$status},$css_class,$currstyle,
4496: \@contacts,$short_titles);
4497: unless ($hidden) {
4498: $rownum ++;
4499: }
4500: }
4501: }
4502: }
4503: $$rowtotal += $rownum;
4504: return $datatable;
4505: }
4506:
4507: sub core_link_msu {
4508: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4509: &mt('LON-CAPA core group - MSU'),600,500);
4510: }
4511:
4512: sub overridden_helpdesk {
4513: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4514: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4515: my $class = 'LC_left_item';
4516: if ($css_class) {
4517: $css_class = ' class="'.$css_class.'"';
4518: }
4519: if ($rowid) {
4520: $rowid = ' id="'.$rowid.'"';
4521: }
4522: if ($rowstyle) {
4523: $rowstyle = ' style="'.$rowstyle.'"';
4524: }
4525: my ($output,$description);
4526: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4527: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4528: "<td>$description</td>\n".
4529: '<td class="'.$class.'" colspan="2">'.
4530: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4531: '<span class="LC_nobreak">';
4532: if (ref($contacts) eq 'ARRAY') {
4533: foreach my $item (@{$contacts}) {
4534: my $check;
4535: if (ref($checked) eq 'HASH') {
4536: $check = $checked->{$item};
4537: }
4538: my $title;
4539: if (ref($short_titles) eq 'HASH') {
4540: $title = $short_titles->{$item};
4541: }
4542: $output .= '<label>'.
4543: '<input type="checkbox" name="override_'.$type.'"'.$check.
4544: ' value="'.$item.'" />'.$title.'</label> ';
4545: }
4546: }
4547: $output .= '</span><br />'.&mt('Others').': '.
4548: '<input type="text" name="override_'.$type.'_others" '.
4549: 'value="'.$otheremails.'" />';
4550: my %locchecked;
4551: foreach my $loc ('s','b') {
4552: if ($includeloc eq $loc) {
4553: $locchecked{$loc} = ' checked="checked"';
4554: last;
4555: }
4556: }
4557: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4558: '<input type="text" name="override_'.$type.'_bcc" '.
4559: 'value="'.$bccemails.'" /></fieldset>'.
4560: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4561: &mt('Text automatically added to e-mail:').' '.
4562: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4563: '<span class="LC_nobreak">'.&mt('Location:').' '.
4564: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4565: (' 'x2).
4566: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4567: '</span></fieldset>'.
4568: '</td></tr>'."\n";
4569: return $output;
4570: }
4571:
4572: sub contacts_javascript {
4573: return <<"ENDSCRIPT";
4574:
4575: <script type="text/javascript">
4576: // <![CDATA[
4577:
4578: function screenshotSize(field) {
4579: if (document.getElementById('help_screenshotsize')) {
4580: if (field.value == 'no') {
4581: document.getElementById('help_screenshotsize').style.display="none";
4582: } else {
4583: document.getElementById('help_screenshotsize').style.display="";
4584: }
4585: }
4586: return;
4587: }
4588:
4589: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4590: if (form.elements[checkbox].length != undefined) {
4591: var count = 0;
4592: if (docount) {
4593: for (var i=0; i<form.elements[checkbox].length; i++) {
4594: if (form.elements[checkbox][i].checked) {
4595: count ++;
4596: }
4597: }
4598: }
4599: for (var i=0; i<form.elements[checkbox].length; i++) {
4600: var type = form.elements[checkbox][i].value;
4601: if (document.getElementById(prefix+type)) {
4602: if (form.elements[checkbox][i].checked) {
4603: document.getElementById(prefix+type).style.display = 'table-row';
4604: if (count % 2 == 1) {
4605: document.getElementById(prefix+type).className = target+' LC_odd_row';
4606: } else {
4607: document.getElementById(prefix+type).className = target;
4608: }
4609: count ++;
4610: } else {
4611: document.getElementById(prefix+type).style.display = 'none';
4612: }
4613: }
4614: }
4615: }
4616: return;
4617: }
4618:
4619: // ]]>
4620: </script>
4621:
4622: ENDSCRIPT
4623: }
4624:
4625: sub print_helpsettings {
4626: my ($position,$dom,$settings,$rowtotal) = @_;
4627: my $confname = $dom.'-domainconfig';
4628: my $formname = 'display';
4629: my ($datatable,$itemcount);
4630: if ($position eq 'top') {
4631: $itemcount = 1;
4632: my (%choices,%defaultchecked,@toggles);
4633: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4634: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4635: &mt('LON-CAPA bug tracker'),600,500));
4636: %defaultchecked = ('submitbugs' => 'on');
4637: @toggles = ('submitbugs');
4638: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4639: \%choices,$itemcount);
4640: $$rowtotal ++;
4641: } else {
4642: my $css_class;
4643: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
4644: my (%customroles,%ordered,%current);
4645: if (ref($settings) eq 'HASH') {
4646: if (ref($settings->{'adhoc'}) eq 'HASH') {
4647: %current = %{$settings->{'adhoc'}};
4648: }
4649: }
4650: my $count = 0;
4651: foreach my $key (sort(keys(%existing))) {
4652: if ($key=~/^rolesdef\_(\w+)$/) {
4653: my $rolename = $1;
4654: my (%privs,$order);
4655: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4656: $customroles{$rolename} = \%privs;
4657: if (ref($current{$rolename}) eq 'HASH') {
4658: $order = $current{$rolename}{'order'};
4659: }
4660: if ($order eq '') {
4661: $order = $count;
4662: }
4663: $ordered{$order} = $rolename;
4664: $count++;
4665: }
4666: }
4667: my $maxnum = scalar(keys(%ordered));
4668: my @roles_by_num = ();
4669: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4670: push(@roles_by_num,$item);
4671: }
4672: my $context = 'domprefs';
4673: my $crstype = 'Course';
4674: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4675: my @accesstypes = ('all','dh','da','none');
4676: my ($numstatustypes,@jsarray);
4677: if (ref($types) eq 'ARRAY') {
4678: if (@{$types} > 0) {
4679: $numstatustypes = scalar(@{$types});
4680: push(@accesstypes,'status');
4681: @jsarray = ('bystatus');
4682: }
4683: }
4684: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
4685: if (keys(%domhelpdesk)) {
4686: push(@accesstypes,('inc','exc'));
4687: push(@jsarray,('notinc','notexc'));
4688: }
4689: my $hiddenstr = join("','",@jsarray);
4690: my $context = 'domprefs';
4691: my $crstype = 'Course';
4692: my $prefix = 'helproles_';
4693: my $add_class = 'LC_hidden';
4694: foreach my $num (@roles_by_num) {
4695: my $role = $ordered{$num};
4696: my ($desc,$access,@statuses);
4697: if (ref($current{$role}) eq 'HASH') {
4698: $desc = $current{$role}{'desc'};
4699: $access = $current{$role}{'access'};
4700: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4701: @statuses = @{$current{$role}{'insttypes'}};
4702: }
4703: }
4704: if ($desc eq '') {
4705: $desc = $role;
4706: }
4707: my $identifier = 'custhelp'.$num;
4708: my %full=();
4709: my %levels= (
4710: course => {},
4711: domain => {},
4712: system => {},
4713: );
4714: my %levelscurrent=(
4715: course => {},
4716: domain => {},
4717: system => {},
4718: );
4719: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4720: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4721: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4722: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4723: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4724: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4725: for (my $k=0; $k<=$maxnum; $k++) {
4726: my $vpos = $k+1;
4727: my $selstr;
4728: if ($k == $num) {
4729: $selstr = ' selected="selected" ';
4730: }
4731: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4732: }
4733: $datatable .= '</select>'.(' 'x2).
4734: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4735: '</td>'.
4736: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4737: &mt('Name shown to users:').
4738: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4739: '</fieldset>'.
4740: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4741: $othertitle,$usertypes,$types,\%domhelpdesk).
4742: '<fieldset>'.
4743: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
4744: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4745: \%levelscurrent,$identifier,
4746: 'LC_hidden',$prefix.$num.'_privs').
4747: '</fieldset></td>';
4748: $itemcount ++;
4749: }
4750: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4751: my $newcust = 'custhelp'.$count;
4752: my (%privs,%levelscurrent);
4753: my %full=();
4754: my %levels= (
4755: course => {},
4756: domain => {},
4757: system => {},
4758: );
4759: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4760: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4761: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4762: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4763: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4764: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4765: for (my $k=0; $k<$maxnum+1; $k++) {
4766: my $vpos = $k+1;
4767: my $selstr;
4768: if ($k == $maxnum) {
4769: $selstr = ' selected="selected" ';
4770: }
4771: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4772: }
4773: $datatable .= '</select> '."\n".
4774: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4775: '</label></span></td>'.
4776: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4777: '<span class="LC_nobreak">'.
4778: &mt('Internal name:').
4779: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4780: '</span>'.(' 'x4).
4781: '<span class="LC_nobreak">'.
4782: &mt('Name shown to users:').
4783: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4784: '</span></fieldset>'.
4785: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4786: $usertypes,$types,\%domhelpdesk).
4787: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
4788: &Apache::lonuserutils::custom_role_header($context,$crstype,
4789: \@templateroles,$newcust).
4790: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4791: \%levelscurrent,$newcust).
4792: '</fieldset>'.
4793: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4794: '</td></tr>';
4795: $count ++;
4796: $$rowtotal += $count;
4797: }
4798: return $datatable;
4799: }
4800:
4801: sub adhocbutton {
4802: my ($prefix,$num,$field,$visibility) = @_;
4803: my %lt = &Apache::lonlocal::texthash(
4804: show => 'Show details',
4805: hide => 'Hide details',
4806: );
4807: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4808: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4809: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4810: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4811: }
4812:
4813: sub helpsettings_javascript {
4814: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4815: return unless(ref($roles_by_num) eq 'ARRAY');
4816: my %html_js_lt = &Apache::lonlocal::texthash(
4817: show => 'Show details',
4818: hide => 'Hide details',
4819: );
4820: &html_escape(\%html_js_lt);
4821: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4822: return <<"ENDSCRIPT";
4823: <script type="text/javascript">
4824: // <![CDATA[
4825:
4826: function reorderHelpRoles(form,item) {
4827: var changedVal;
4828: $jstext
4829: var newpos = 'helproles_${total}_pos';
4830: var maxh = 1 + $total;
4831: var current = new Array();
4832: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4833: if (item == newpos) {
4834: changedVal = newitemVal;
4835: } else {
4836: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4837: current[newitemVal] = newpos;
4838: }
4839: for (var i=0; i<helproles.length; i++) {
4840: var elementName = 'helproles_'+helproles[i]+'_pos';
4841: if (elementName != item) {
4842: if (form.elements[elementName]) {
4843: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4844: current[currVal] = elementName;
4845: }
4846: }
4847: }
4848: var oldVal;
4849: for (var j=0; j<maxh; j++) {
4850: if (current[j] == undefined) {
4851: oldVal = j;
4852: }
4853: }
4854: if (oldVal < changedVal) {
4855: for (var k=oldVal+1; k<=changedVal ; k++) {
4856: var elementName = current[k];
4857: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4858: }
4859: } else {
4860: for (var k=changedVal; k<oldVal; k++) {
4861: var elementName = current[k];
4862: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4863: }
4864: }
4865: return;
4866: }
4867:
4868: function helpdeskAccess(num) {
4869: var curraccess = null;
4870: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4871: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4872: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4873: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4874: }
4875: }
4876: }
4877: var shown = Array();
4878: var hidden = Array();
4879: if (curraccess == 'none') {
4880: hidden = Array('$hiddenstr');
4881: } else {
4882: if (curraccess == 'status') {
4883: shown = Array('bystatus');
4884: hidden = Array('notinc','notexc');
4885: } else {
4886: if (curraccess == 'exc') {
4887: shown = Array('notexc');
4888: hidden = Array('notinc','bystatus');
4889: }
4890: if (curraccess == 'inc') {
4891: shown = Array('notinc');
4892: hidden = Array('notexc','bystatus');
4893: }
4894: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
4895: hidden = Array('notinc','notexc','bystatus');
4896: }
4897: }
4898: }
4899: if (hidden.length > 0) {
4900: for (var i=0; i<hidden.length; i++) {
4901: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4902: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4903: }
4904: }
4905: }
4906: if (shown.length > 0) {
4907: for (var i=0; i<shown.length; i++) {
4908: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4909: if (shown[i] == 'privs') {
4910: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4911: } else {
4912: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4913: }
4914: }
4915: }
4916: }
4917: return;
4918: }
4919:
4920: function toggleHelpdeskItem(num,field) {
4921: if (document.getElementById('helproles_'+num+'_'+field)) {
4922: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4923: document.getElementById('helproles_'+num+'_'+field).className =
4924: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4925: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4926: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4927: }
4928: } else {
4929: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4930: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4931: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4932: }
4933: }
4934: }
4935: return;
4936: }
4937:
4938: // ]]>
4939: </script>
4940:
4941: ENDSCRIPT
4942: }
4943:
4944: sub helpdeskroles_access {
4945: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4946: $usertypes,$types,$domhelpdesk) = @_;
4947: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4948: my %lt = &Apache::lonlocal::texthash(
4949: 'rou' => 'Role usage',
4950: 'whi' => 'Which helpdesk personnel may use this role?',
4951: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4952: 'dh' => 'All with domain helpdesk role',
4953: 'da' => 'All with domain helpdesk assistant role',
4954: 'none' => 'None',
4955: 'status' => 'Determined based on institutional status',
4956: 'inc' => 'Include all, but exclude specific personnel',
4957: 'exc' => 'Exclude all, but include specific personnel',
4958: );
4959: my %usecheck = (
4960: all => ' checked="checked"',
4961: );
4962: my %displaydiv = (
4963: status => 'none',
4964: inc => 'none',
4965: exc => 'none',
4966: priv => 'block',
4967: );
4968: my $output;
4969: if (ref($current) eq 'HASH') {
4970: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4971: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4972: $usecheck{$current->{access}} = $usecheck{'all'};
4973: delete($usecheck{'all'});
4974: if ($current->{access} =~ /^(status|inc|exc)$/) {
4975: my $access = $1;
4976: $displaydiv{$access} = 'inline';
4977: } elsif ($current->{access} eq 'none') {
4978: $displaydiv{'priv'} = 'none';
4979: }
4980: }
4981: }
4982: }
4983: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4984: '<p>'.$lt{'whi'}.'</p>';
4985: foreach my $access (@{$accesstypes}) {
4986: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4987: ' onclick="helpdeskAccess('."'$num'".');" />'.
4988: $lt{$access}.'</label>';
4989: if ($access eq 'status') {
4990: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4991: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4992: $othertitle,$usertypes,$types).
4993: '</div>';
4994: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4995: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4996: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4997: '</div>';
4998: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4999: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5000: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5001: '</div>';
5002: }
5003: $output .= '</p>';
5004: }
5005: $output .= '</fieldset>';
5006: return $output;
5007: }
5008:
5009: sub radiobutton_prefs {
5010: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
5011: $additional,$align,$firstval) = @_;
5012: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5013: (ref($choices) eq 'HASH'));
5014:
5015: my (%checkedon,%checkedoff,$datatable,$css_class);
5016:
5017: foreach my $item (@{$toggles}) {
5018: if ($defaultchecked->{$item} eq 'on') {
5019: $checkedon{$item} = ' checked="checked" ';
5020: $checkedoff{$item} = ' ';
5021: } elsif ($defaultchecked->{$item} eq 'off') {
5022: $checkedoff{$item} = ' checked="checked" ';
5023: $checkedon{$item} = ' ';
5024: }
5025: }
5026: if (ref($settings) eq 'HASH') {
5027: foreach my $item (@{$toggles}) {
5028: if ($settings->{$item} eq '1') {
5029: $checkedon{$item} = ' checked="checked" ';
5030: $checkedoff{$item} = ' ';
5031: } elsif ($settings->{$item} eq '0') {
5032: $checkedoff{$item} = ' checked="checked" ';
5033: $checkedon{$item} = ' ';
5034: }
5035: }
5036: }
5037: if ($onclick) {
5038: $onclick = ' onclick="'.$onclick.'"';
5039: }
5040: foreach my $item (@{$toggles}) {
5041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5042: $datatable .=
5043: '<tr'.$css_class.'><td valign="top">'.
5044: '<span class="LC_nobreak">'.$choices->{$item}.
5045: '</span></td>';
5046: if ($align eq 'left') {
5047: $datatable .= '<td class="LC_left_item">';
5048: } else {
5049: $datatable .= '<td class="LC_right_item">';
5050: }
5051: $datatable .= '<span class="LC_nobreak">';
5052: if ($firstval eq 'no') {
5053: $datatable .=
5054: '<label><input type="radio" name="'.
5055: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5056: '</label> <label><input type="radio" name="'.$item.'" '.
5057: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5058: } else {
5059: $datatable .=
5060: '<label><input type="radio" name="'.
5061: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5062: '</label> <label><input type="radio" name="'.$item.'" '.
5063: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5064: }
5065: $datatable .= '</span>'.$additional.'</td></tr>';
5066: $itemcount ++;
5067: }
5068: return ($datatable,$itemcount);
5069: }
5070:
5071: sub print_ltitools {
5072: my ($position,$dom,$settings,$rowtotal) = @_;
5073: my (%rules,%encrypt,%privkeys,%linkprot);
5074: if (ref($settings) eq 'HASH') {
5075: if ($position eq 'top') {
5076: if (exists($settings->{'encrypt'})) {
5077: if (ref($settings->{'encrypt'}) eq 'HASH') {
5078: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5079: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
5080: }
5081: }
5082: }
5083: if (exists($settings->{'private'})) {
5084: if (ref($settings->{'private'}) eq 'HASH') {
5085: if (ref($settings->{'private'}) eq 'HASH') {
5086: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5087: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5088: }
5089: }
5090: }
5091: }
5092: } elsif ($position eq 'middle') {
5093: if (exists($settings->{'rules'})) {
5094: if (ref($settings->{'rules'}) eq 'HASH') {
5095: %rules = %{$settings->{'rules'}};
5096: }
5097: }
5098: } else {
5099: foreach my $key ('encrypt','private','rules') {
5100: if (exists($settings->{$key})) {
5101: delete($settings->{$key});
5102: }
5103: }
5104: }
5105: }
5106: my $datatable;
5107: my $itemcount = 1;
5108: if ($position eq 'top') {
5109: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5110: } elsif ($position eq 'middle') {
5111: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5112: $$rowtotal += $itemcount;
5113: } else {
5114: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
5115: }
5116: return $datatable;
5117: }
5118:
5119: sub ltitools_names {
5120: my %lt = &Apache::lonlocal::texthash(
5121: 'title' => 'Title',
5122: 'version' => 'Version',
5123: 'msgtype' => 'Message Type',
5124: 'sigmethod' => 'Signature Method',
5125: 'url' => 'URL',
5126: 'key' => 'Key',
5127: 'lifetime' => 'Nonce lifetime (s)',
5128: 'secret' => 'Secret',
5129: 'icon' => 'Icon',
5130: 'user' => 'User',
5131: 'fullname' => 'Full Name',
5132: 'firstname' => 'First Name',
5133: 'lastname' => 'Last Name',
5134: 'email' => 'E-mail',
5135: 'roles' => 'Role',
5136: 'window' => 'Window',
5137: 'tab' => 'Tab',
5138: 'iframe' => 'iFrame',
5139: 'height' => 'Height',
5140: 'width' => 'Width',
5141: 'linktext' => 'Default Link Text',
5142: 'explanation' => 'Default Explanation',
5143: 'passback' => 'Tool can return grades:',
5144: 'roster' => 'Tool can retrieve roster:',
5145: 'crstarget' => 'Display target',
5146: 'crslabel' => 'Course label',
5147: 'crstitle' => 'Course title',
5148: 'crslinktext' => 'Link Text',
5149: 'crsexplanation' => 'Explanation',
5150: 'crsappend' => 'Provider URL',
5151: );
5152: return %lt;
5153: }
5154:
5155: sub secrets_form {
5156: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5157: my @ids=&Apache::lonnet::current_machine_ids();
5158: my %servers = &Apache::lonnet::get_servers($dom,'library');
5159: my $primary = &Apache::lonnet::domain($dom,'primary');
5160: my ($css_class,$extra,$numshown,$itemcount,$output);
5161: $itemcount = 0;
5162: foreach my $hostid (sort(keys(%servers))) {
5163: my ($showextra,$divsty,$switch);
5164: if ($hostid eq $primary) {
5165: if ($context eq 'ltisec') {
5166: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5167: $showextra = 1;
5168: }
5169: if ($encrypt->{'ltisec_crslinkprot'}) {
5170: $showextra = 1;
5171: }
5172: } else {
5173: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5174: $showextra = 1;
5175: }
5176: }
5177: unless (grep(/^\Q$hostid\E$/,@ids)) {
5178: $switch = 1;
5179: }
5180: if ($showextra) {
5181: $numshown ++;
5182: $divsty = 'display:inline-block';
5183: } else {
5184: $divsty = 'display:none';
5185: }
5186: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5187: '<legend>'.$hostid.'</legend>';
5188: if ($switch) {
5189: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5190: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5191: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5192: if (exists($privkeys->{$hostid})) {
5193: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5194: '<span class="LC_nobreak">'.
5195: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5196: '<span class="LC_nobreak">'.&mt('Change?').
5197: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5198: (' 'x2).
5199: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5200: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5201: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5202: '</span></div>';
5203: } else {
5204: $extra .= '<span class="LC_nobreak">'.
5205: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5206: '</span>'."\n";
5207: }
5208: } elsif (exists($privkeys->{$hostid})) {
5209: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5210: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5211: '<span class="LC_nobreak">'.&mt('Change?').
5212: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5213: (' 'x2).
5214: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5215: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5216: '<span class="LC_nobreak">'.&mt('New Key').':'.
5217: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5218: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5219: '</span></div>';
5220: } else {
5221: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5222: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5223: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5224: }
5225: $extra .= '</fieldset>';
5226: }
5227: }
5228: my (%choices,@toggles,%defaultchecked);
5229: if ($context eq 'ltisec') {
5230: %choices = &Apache::lonlocal::texthash (
5231: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5232: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5233: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5234: );
5235: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5236: %defaultchecked = (
5237: 'ltisec_crslinkprot' => 'off',
5238: 'ltisec_domlinkprot' => 'off',
5239: 'ltisec_consumers' => 'off',
5240: );
5241: } else {
5242: %choices = &Apache::lonlocal::texthash (
5243: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5244: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5245: );
5246: @toggles = qw(toolsec_crs toolsec_dom);
5247: %defaultchecked = (
5248: 'toolsec_crs' => 'off',
5249: 'toolsec_dom' => 'off',
5250: );
5251: }
5252: my ($onclick,$itemcount);
5253: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5254: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5255: \%choices,$itemcount,$onclick,'','left','no');
5256:
5257: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5258: my $noprivkeysty = 'display:inline-block';
5259: if ($numshown) {
5260: $noprivkeysty = 'display:none';
5261: }
5262: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5263: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5264: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5265: $extra.
5266: '</td></tr>';
5267: $itemcount ++;
5268: $$rowtotal += $itemcount;
5269: return $output;
5270: }
5271:
5272: sub print_lti {
5273: my ($position,$dom,$settings,$rowtotal) = @_;
5274: my $itemcount = 1;
5275: my ($datatable,$css_class);
5276: my (%rules,%encrypt,%privkeys,%linkprot);
5277: if (ref($settings) eq 'HASH') {
5278: if ($position eq 'top') {
5279: if (exists($settings->{'encrypt'})) {
5280: if (ref($settings->{'encrypt'}) eq 'HASH') {
5281: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5282: if ($key eq 'consumers') {
5283: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
5284: } else {
5285: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5286: }
5287: }
5288: }
5289: }
5290: if (exists($settings->{'private'})) {
5291: if (ref($settings->{'private'}) eq 'HASH') {
5292: if (ref($settings->{'private'}) eq 'HASH') {
5293: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5294: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5295: }
5296: }
5297: }
5298: }
5299: } elsif ($position eq 'middle') {
5300: if (exists($settings->{'rules'})) {
5301: if (ref($settings->{'rules'}) eq 'HASH') {
5302: %rules = %{$settings->{'rules'}};
5303: }
5304: }
5305: } elsif ($position eq 'lower') {
5306: if (exists($settings->{'linkprot'})) {
5307: if (ref($settings->{'linkprot'}) eq 'HASH') {
5308: %linkprot = %{$settings->{'linkprot'}};
5309: if ($linkprot{'lock'}) {
5310: delete($linkprot{'lock'});
5311: }
5312: }
5313: }
5314: } else {
5315: foreach my $key ('encrypt','private','rules','linkprot') {
5316: if (exists($settings->{$key})) {
5317: delete($settings->{$key});
5318: }
5319: }
5320: }
5321: }
5322: if ($position eq 'top') {
5323: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
5324: } elsif ($position eq 'middle') {
5325: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
5326: $$rowtotal += $itemcount;
5327: } elsif ($position eq 'lower') {
5328: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
5329: } else {
5330: my ($switchserver,$switchmessage);
5331: $switchserver = &check_switchserver($dom);
5332: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
5333: my $maxnum = 0;
5334: my %ordered;
5335: if (ref($settings) eq 'HASH') {
5336: foreach my $item (keys(%{$settings})) {
5337: if (ref($settings->{$item}) eq 'HASH') {
5338: my $num = $settings->{$item}{'order'};
5339: if ($num eq '') {
5340: $num = scalar(keys(%{$settings}));
5341: }
5342: $ordered{$num} = $item;
5343: }
5344: }
5345: }
5346: $maxnum = scalar(keys(%ordered));
5347: my %lt = <i_names();
5348: if (keys(%ordered)) {
5349: my @items = sort { $a <=> $b } keys(%ordered);
5350: for (my $i=0; $i<@items; $i++) {
5351: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5352: my $item = $ordered{$items[$i]};
5353: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
5354: if (ref($settings->{$item}) eq 'HASH') {
5355: $key = $settings->{$item}->{'key'};
5356: $usable = $settings->{$item}->{'usable'};
5357: $lifetime = $settings->{$item}->{'lifetime'};
5358: $consumer = $settings->{$item}->{'consumer'};
5359: $requser = $settings->{$item}->{'requser'};
5360: $crsinc = $settings->{$item}->{'crsinc'};
5361: $current = $settings->{$item};
5362: }
5363: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5364: my %checkedrequser = (
5365: yes => ' checked="checked"',
5366: no => '',
5367: );
5368: if (!$requser) {
5369: $checkedrequser{'no'} = $checkedrequser{'yes'};
5370: $checkedrequser{'yes'} = '';
5371: }
5372: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
5373: my %checkedcrsinc = (
5374: yes => ' checked="checked"',
5375: no => '',
5376: );
5377: if (!$crsinc) {
5378: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
5379: $checkedcrsinc{'yes'} = '';
5380: }
5381: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5382: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5383: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5384: for (my $k=0; $k<=$maxnum; $k++) {
5385: my $vpos = $k+1;
5386: my $selstr;
5387: if ($k == $i) {
5388: $selstr = ' selected="selected" ';
5389: }
5390: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5391: }
5392: $datatable .= '</select>'.(' 'x2).
5393: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5394: &mt('Delete?').'</label></span></td>'.
5395: '<td colspan="2">'.
5396: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5397: '<span class="LC_nobreak">'.$lt{'consumer'}.
5398: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
5399: (' 'x2).
5400: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5401: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5402: (' 'x2).
5403: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
5404: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
5405: if ($key ne '') {
5406: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
5407: if ($switchserver) {
5408: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
5409: } else {
5410: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
5411: }
5412: $datatable .= '</span> '.(' 'x2);
5413: } elsif (!$switchserver) {
5414: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
5415: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
5416: '</span> '.(' 'x2);
5417: }
5418: if ($switchserver) {
5419: if ($usable ne '') {
5420: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5421: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5422: '<span class="LC_nobreak">'.&mt('Change secret?').
5423: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5424: (' 'x2).
5425: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
5426: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5427: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
5428: '</div>';
5429: } elsif ($key eq '') {
5430: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5431: } else {
5432: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
5433: }
5434: } else {
5435: if ($usable ne '') {
5436: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5437: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5438: '<span class="LC_nobreak">'.&mt('Change?').
5439: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5440: (' 'x2).
5441: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
5442: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5443: '<span class="LC_nobreak">'.&mt('New Secret').':'.
5444: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5445: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
5446: } else {
5447: $datatable .=
5448: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5449: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5450: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5451: }
5452: }
5453: $datatable .= '<br /><br />'.
5454: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5455: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5456: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
5457: '<br /><br />'.
5458: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5459: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
5460: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
5461: (' 'x4).
5462: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
5463: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
5464: $itemcount ++;
5465: }
5466: }
5467: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5468: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5469: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5470: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5471: '<select name="lti_pos_add"'.$chgstr.'>';
5472: for (my $k=0; $k<$maxnum+1; $k++) {
5473: my $vpos = $k+1;
5474: my $selstr;
5475: if ($k == $maxnum) {
5476: $selstr = ' selected="selected" ';
5477: }
5478: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5479: }
5480: $datatable .= '</select> '."\n".
5481: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5482: '<td colspan="2">'.
5483: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5484: '<span class="LC_nobreak">'.$lt{'consumer'}.
5485: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
5486: (' 'x2).
5487: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5488: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5489: (' 'x2).
5490: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
5491: if ($switchserver) {
5492: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5493: } else {
5494: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
5495: (' 'x2).
5496: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
5497: '<label><input type="checkbox" name="lti_add_visible" id="lti_add_visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n";
5498: }
5499: $datatable .= '<br /><br />'.
5500: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5501: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5502: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
5503: '<br /><br />'.
5504: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5505: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5506: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
5507: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
5508: '</td>'."\n".
5509: '</tr>'."\n";
5510: $itemcount ++;
5511: }
5512: $$rowtotal += $itemcount;
5513: return $datatable;
5514: }
5515:
5516: sub lti_names {
5517: my %lt = &Apache::lonlocal::texthash(
5518: 'version' => 'LTI Version',
5519: 'url' => 'URL',
5520: 'key' => 'Key',
5521: 'lifetime' => 'Nonce lifetime (s)',
5522: 'consumer' => 'Consumer',
5523: 'secret' => 'Secret',
5524: 'requser' => "User's identity sent",
5525: 'crsinc' => "Course's identity sent",
5526: 'email' => 'Email address',
5527: 'sourcedid' => 'User ID',
5528: 'other' => 'Other',
5529: 'passback' => 'Can return grades to Consumer:',
5530: 'roster' => 'Can retrieve roster from Consumer:',
5531: 'topmenu' => 'Display LON-CAPA page header',
5532: 'inlinemenu'=> 'Display LON-CAPA inline menu',
5533: );
5534: return %lt;
5535: }
5536:
5537: sub lti_options {
5538: my ($num,$current,$itemcount,%lt) = @_;
5539: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
5540: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5541: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5542: $checked{'storecrs'}{'Y'} = ' checked="checked"';
5543: $checked{'makecrs'}{'N'} = ' checked="checked"';
5544: $checked{'mapcrstype'} = {};
5545: $checked{'makeuser'} = {};
5546: $checked{'selfenroll'} = {};
5547: $checked{'crssec'} = {};
5548: $checked{'crssecsrc'} = {};
5549: $checked{'lcauth'} = {};
5550: $checked{'menuitem'} = {};
5551: if ($num eq 'add') {
5552: $checked{'lcauth'}{'lti'} = ' checked="checked"';
5553: }
5554: my $userfieldsty = 'none';
5555: my $crsfieldsty = 'none';
5556: my $crssecfieldsty = 'none';
5557: my $secsrcfieldsty = 'none';
5558: my $callbacksty = 'none';
5559: my $passbacksty = 'none';
5560: my $optionsty = 'block';
5561: my $crssty = 'block';
5562: my $lcauthparm;
5563: my $lcauthparmstyle = 'display:none';
5564: my $lcauthparmtext;
5565: my $menusty;
5566: my $numinrow = 4;
5567: my %menutitles = <imenu_titles();
5568:
5569: if (ref($current) eq 'HASH') {
5570: if (!$current->{'requser'}) {
5571: $optionsty = 'none';
5572: $crssty = 'none';
5573: } elsif (!$current->{'crsinc'}) {
5574: $crssty = 'none';
5575: }
5576: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5577: $checked{'mapuser'}{'sourcedid'} = '';
5578: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5579: $checked{'mapuser'}{'email'} = ' checked="checked"';
5580: } else {
5581: $checked{'mapuser'}{'other'} = ' checked="checked"';
5582: $userfield = $current->{'mapuser'};
5583: $userfieldsty = 'inline-block';
5584: }
5585: }
5586: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5587: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5588: if ($current->{'mapcrs'} eq 'context_id') {
5589: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5590: } else {
5591: $checked{'mapcrs'}{'other'} = ' checked="checked"';
5592: $cidfield = $current->{'mapcrs'};
5593: $crsfieldsty = 'inline-block';
5594: }
5595: }
5596: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5597: foreach my $type (@{$current->{'mapcrstype'}}) {
5598: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5599: }
5600: }
5601: if (!$current->{'storecrs'}) {
5602: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
5603: $checked{'storecrs'}{'Y'} = '';
5604: }
5605: if ($current->{'makecrs'}) {
5606: $checked{'makecrs'}{'Y'} = ' checked="checked"';
5607: }
5608: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5609: foreach my $role (@{$current->{'makeuser'}}) {
5610: $checked{'makeuser'}{$role} = ' checked="checked"';
5611: }
5612: }
5613: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5614: $checked{'lcauth'}{$1} = ' checked="checked"';
5615: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5616: $lcauthparm = $current->{'lcauthparm'};
5617: $lcauthparmstyle = 'display:table-row';
5618: if ($current->{'lcauth'} eq 'localauth') {
5619: $lcauthparmtext = &mt('Local auth argument');
5620: } else {
5621: $lcauthparmtext = &mt('Kerberos domain');
5622: }
5623: }
5624: }
5625: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5626: foreach my $role (@{$current->{'selfenroll'}}) {
5627: $checked{'selfenroll'}{$role} = ' checked="checked"';
5628: }
5629: }
5630: if (ref($current->{'maproles'}) eq 'HASH') {
5631: %rolemaps = %{$current->{'maproles'}};
5632: }
5633: if ($current->{'section'} ne '') {
5634: $checked{'crssec'}{'Y'} = ' checked="checked"';
5635: $crssecfieldsty = 'inline-block';
5636: if ($current->{'section'} eq 'course_section_sourcedid') {
5637: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5638: } else {
5639: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5640: $crssecsrc = $current->{'section'};
5641: $secsrcfieldsty = 'inline-block';
5642: }
5643: } else {
5644: $checked{'crssec'}{'N'} = ' checked="checked"';
5645: }
5646: if ($current->{'callback'} ne '') {
5647: $callback = $current->{'callback'};
5648: $checked{'callback'}{'Y'} = ' checked="checked"';
5649: $callbacksty = 'inline-block';
5650: } else {
5651: $checked{'callback'}{'N'} = ' checked="checked"';
5652: }
5653: if ($current->{'topmenu'}) {
5654: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5655: } else {
5656: $checked{'topmenu'}{'N'} = ' checked="checked"';
5657: }
5658: if ($current->{'inlinemenu'}) {
5659: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5660: } else {
5661: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5662: }
5663: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5664: $menusty = 'inline-block';
5665: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5666: foreach my $item (@{$current->{'lcmenu'}}) {
5667: if (exists($menutitles{$item})) {
5668: $checked{'menuitem'}{$item} = ' checked="checked"';
5669: }
5670: }
5671: }
5672: } else {
5673: $menusty = 'none';
5674: }
5675: } else {
5676: $checked{'makecrs'}{'N'} = ' checked="checked"';
5677: $checked{'crssec'}{'N'} = ' checked="checked"';
5678: $checked{'callback'}{'N'} = ' checked="checked"';
5679: $checked{'topmenu'}{'N'} = ' checked="checked"';
5680: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5681: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5682: $menusty = 'inline-block';
5683: }
5684: my @coursetypes = ('official','unofficial','community','textbook','lti');
5685: my %coursetypetitles = &Apache::lonlocal::texthash (
5686: official => 'Official',
5687: unofficial => 'Unofficial',
5688: community => 'Community',
5689: textbook => 'Textbook',
5690: lti => 'LTI Provider',
5691: );
5692: my @authtypes = ('internal','krb4','krb5','localauth');
5693: my %shortauth = (
5694: internal => 'int',
5695: krb4 => 'krb4',
5696: krb5 => 'krb5',
5697: localauth => 'loc'
5698: );
5699: my %authnames = &authtype_names();
5700: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5701: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5702: my @courseroles = ('cc','in','ta','ep','st');
5703: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5704: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5705: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5706: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
5707: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
5708: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
5709: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
5710: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
5711: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
5712: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
5713: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
5714: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
5715: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
5716: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
5717: '<span class="LC_nobreak">'.&mt('Parameter').': '.
5718: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
5719: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
5720: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
5721: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5722: foreach my $option ('sourcedid','email','other') {
5723: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5724: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5725: ($option eq 'other' ? '' : (' 'x2) );
5726: }
5727: $output .= '</span></div>'.
5728: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5729: '<input type="text" name="lti_customuser_'.$num.'" '.
5730: 'value="'.$userfield.'" /></div></fieldset>'.
5731: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
5732: foreach my $ltirole (@ltiroles) {
5733: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5734: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5735: }
5736: $output .= '</fieldset>'.
5737: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
5738: '<table>'.
5739: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5740: '</table>'.
5741: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5742: '<td class="LC_left_item">';
5743: foreach my $auth ('lti',@authtypes) {
5744: my $authtext;
5745: if ($auth eq 'lti') {
5746: $authtext = &mt('None');
5747: } else {
5748: $authtext = $authnames{$shortauth{$auth}};
5749: }
5750: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5751: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5752: $authtext.'</label></span> ';
5753: }
5754: $output .= '</td></tr>'.
5755: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5756: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5757: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5758: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5759: '</table></fieldset>'.
5760: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
5761: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
5762: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5763: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5764: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5765: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
5766: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
5767: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5768: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5769: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5770: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5771: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
5772: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
5773: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5774: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5775: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5776: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5777: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5778: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5779: (' 'x2);
5780: }
5781: $output .= '</span></div></fieldset>'.
5782: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
5783: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5784: &mt('Unique course identifier').': ';
5785: foreach my $option ('course_offering_sourcedid','context_id','other') {
5786: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5787: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5788: ($option eq 'other' ? '' : (' 'x2) );
5789: }
5790: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
5791: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5792: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5793: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5794: foreach my $type (@coursetypes) {
5795: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5796: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5797: (' 'x2);
5798: }
5799: $output .= '</span><br /><br />'.
5800: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
5801: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
5802: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5803: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
5804: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5805: '</fieldset>'.
5806: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
5807: foreach my $ltirole (@lticourseroles) {
5808: my ($selected,$selectnone);
5809: if ($rolemaps{$ltirole} eq '') {
5810: $selectnone = ' selected="selected"';
5811: }
5812: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5813: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5814: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5815: foreach my $role (@courseroles) {
5816: unless ($selectnone) {
5817: if ($rolemaps{$ltirole} eq $role) {
5818: $selected = ' selected="selected"';
5819: } else {
5820: $selected = '';
5821: }
5822: }
5823: $output .= '<option value="'.$role.'"'.$selected.'>'.
5824: &Apache::lonnet::plaintext($role,'Course').
5825: '</option>';
5826: }
5827: $output .= '</select></td>';
5828: }
5829: $output .= '</tr></table></fieldset>'.
5830: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
5831: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5832: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5833: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5834: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5835: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5836: '</fieldset>'.
5837: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
5838: foreach my $lticrsrole (@lticourseroles) {
5839: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5840: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5841: }
5842: $output .= '</fieldset>'.
5843: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
5844: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5845: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5846: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5847: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
5848: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
5849: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5850: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5851: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5852: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5853: &mt('Standard field').'</label>'.(' 'x2).
5854: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5855: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
5856: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
5857: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
5858: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5859: my ($pb1p1chk,$pb1p0chk,$onclickpb);
5860: foreach my $extra ('roster','passback') {
5861: my $checkedon = '';
5862: my $checkedoff = ' checked="checked"';
5863: if ($extra eq 'passback') {
5864: $pb1p1chk = ' checked="checked"';
5865: $pb1p0chk = '';
5866: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5867: } else {
5868: $onclickpb = '';
5869: }
5870: if (ref($current) eq 'HASH') {
5871: if (($current->{$extra})) {
5872: $checkedon = $checkedoff;
5873: $checkedoff = '';
5874: if ($extra eq 'passback') {
5875: $passbacksty = 'inline-block';
5876: }
5877: if ($current->{'passbackformat'} eq '1.0') {
5878: $pb1p0chk = ' checked="checked"';
5879: $pb1p1chk = '';
5880: }
5881: }
5882: }
5883: $output .= $lt{$extra}.' '.
5884: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
5885: &mt('No').'</label>'.(' 'x2).
5886: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
5887: &mt('Yes').'</label><br />';
5888: }
5889: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5890: '<span class="LC_nobreak">'.&mt('Grade format').
5891: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5892: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5893: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5894: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
5895: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
5896: $output .= '</span></div></fieldset>';
5897: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5898: #
5899: # $output .= '</fieldset>'.
5900: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5901: return $output;
5902: }
5903:
5904: sub ltimenu_titles {
5905: return &Apache::lonlocal::texthash(
5906: fullname => 'Full name',
5907: coursetitle => 'Course title',
5908: role => 'Role',
5909: logout => 'Logout',
5910: grades => 'Grades',
5911: );
5912: }
5913:
5914:
5915:
5916: sub print_coursedefaults {
5917: my ($position,$dom,$settings,$rowtotal) = @_;
5918: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
5919: my $itemcount = 1;
5920: my %choices = &Apache::lonlocal::texthash (
5921: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
5922: coursequota => 'Default cumulative quota for all group portfolio spaces in course',
5923: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5924: coursecredits => 'Credits can be specified for courses',
5925: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5926: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
5927: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
5928: texengine => 'Default method to display mathematics',
5929: postsubmit => 'Disable submit button/keypress following student submission',
5930: canclone => "People who may clone a course (besides course's owner and coordinators)",
5931: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
5932: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
5933: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
5934: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
5935: );
5936: my %staticdefaults = (
5937: anonsurvey_threshold => 10,
5938: uploadquota => 500,
5939: coursequota => 20,
5940: postsubmit => 60,
5941: mysqltables => 172800,
5942: domexttool => 1,
5943: exttool => 0,
5944: );
5945: if ($position eq 'top') {
5946: %defaultchecked = (
5947: 'uselcmath' => 'on',
5948: 'usejsme' => 'on',
5949: 'inline_chem' => 'on',
5950: 'canclone' => 'none',
5951: );
5952: @toggles = ('uselcmath','usejsme','inline_chem');
5953: my $deftex = $Apache::lonnet::deftex;
5954: if (ref($settings) eq 'HASH') {
5955: if ($settings->{'texengine'}) {
5956: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5957: $deftex = $settings->{'texengine'};
5958: }
5959: }
5960: }
5961: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5962: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5963: '<span class="LC_nobreak">'.$choices{'texengine'}.
5964: '</span></td><td class="LC_right_item">'.
5965: '<select name="texengine">'."\n";
5966: my %texoptions = (
5967: MathJax => 'MathJax',
5968: mimetex => &mt('Convert to Images'),
5969: tth => &mt('TeX to HTML'),
5970: );
5971: foreach my $renderer ('MathJax','mimetex','tth') {
5972: my $selected = '';
5973: if ($renderer eq $deftex) {
5974: $selected = ' selected="selected"';
5975: }
5976: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5977: }
5978: $mathdisp .= '</select></td></tr>'."\n";
5979: $itemcount ++;
5980: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
5981: \%choices,$itemcount);
5982: $datatable = $mathdisp.$datatable;
5983: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5984: $datatable .=
5985: '<tr'.$css_class.'><td valign="top">'.
5986: '<span class="LC_nobreak">'.$choices{'canclone'}.
5987: '</span></td><td class="LC_left_item">';
5988: my $currcanclone = 'none';
5989: my $onclick;
5990: my @cloneoptions = ('none','domain');
5991: my %clonetitles = &Apache::lonlocal::texthash (
5992: none => 'No additional course requesters',
5993: domain => "Any course requester in course's domain",
5994: instcode => 'Course requests for official courses ...',
5995: );
5996: my (%codedefaults,@code_order,@posscodes);
5997: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5998: \@code_order) eq 'ok') {
5999: if (@code_order > 0) {
6000: push(@cloneoptions,'instcode');
6001: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6002: }
6003: }
6004: if (ref($settings) eq 'HASH') {
6005: if ($settings->{'canclone'}) {
6006: if (ref($settings->{'canclone'}) eq 'HASH') {
6007: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6008: if (@code_order > 0) {
6009: $currcanclone = 'instcode';
6010: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6011: }
6012: }
6013: } elsif ($settings->{'canclone'} eq 'domain') {
6014: $currcanclone = $settings->{'canclone'};
6015: }
6016: }
6017: }
6018: foreach my $option (@cloneoptions) {
6019: my ($checked,$additional);
6020: if ($currcanclone eq $option) {
6021: $checked = ' checked="checked"';
6022: }
6023: if ($option eq 'instcode') {
6024: if (@code_order) {
6025: my $show = 'none';
6026: if ($checked) {
6027: $show = 'block';
6028: }
6029: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
6030: &mt('Institutional codes for new and cloned course have identical:').
6031: '<br />';
6032: foreach my $item (@code_order) {
6033: my $codechk;
6034: if ($checked) {
6035: if (grep(/^\Q$item\E$/,@posscodes)) {
6036: $codechk = ' checked="checked"';
6037: }
6038: }
6039: $additional .= '<label>'.
6040: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6041: $item.'</label>';
6042: }
6043: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6044: }
6045: }
6046: $datatable .=
6047: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6048: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6049: '</label> '.$additional.'</span><br />';
6050: }
6051: $datatable .= '</td>'.
6052: '</tr>';
6053: $itemcount ++;
6054: } else {
6055: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6056: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6057: %deftimeout,%currmysql);
6058: my $currusecredits = 0;
6059: my $postsubmitclient = 1;
6060: my $ltiauth = 0;
6061: my %domexttool;
6062: my %exttool;
6063: my @types = ('official','unofficial','community','textbook');
6064: if (ref($settings) eq 'HASH') {
6065: if ($settings->{'ltiauth'}) {
6066: $ltiauth = 1;
6067: }
6068: if (ref($settings->{'domexttool'}) eq 'HASH') {
6069: foreach my $type (@types) {
6070: if ($settings->{'domexttool'}->{$type}) {
6071: $domexttool{$type} = ' checked="checked"';
6072: }
6073: }
6074: } else {
6075: foreach my $type (@types) {
6076: if ($staticdefaults{'domexttool'}) {
6077: $domexttool{$type} = ' checked="checked"';
6078: }
6079: }
6080: }
6081: if (ref($settings->{'exttool'}) eq 'HASH') {
6082: foreach my $type (@types) {
6083: if ($settings->{'exttool'}->{$type}) {
6084: $exttool{$type} = ' checked="checked"';
6085: }
6086: }
6087: }
6088: $currdefresponder = $settings->{'anonsurvey_threshold'};
6089: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6090: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6091: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6092: }
6093: }
6094: if (ref($settings->{'coursequota'}) eq 'HASH') {
6095: foreach my $type (keys(%{$settings->{'coursequota'}})) {
6096: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
6097: }
6098: }
6099: if (ref($settings->{'coursecredits'}) eq 'HASH') {
6100: foreach my $type (@types) {
6101: next if ($type eq 'community');
6102: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6103: if ($defcredits{$type} ne '') {
6104: $currusecredits = 1;
6105: }
6106: }
6107: }
6108: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6109: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6110: $postsubmitclient = 0;
6111: foreach my $type (@types) {
6112: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6113: }
6114: } else {
6115: foreach my $type (@types) {
6116: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6117: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
6118: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
6119: } else {
6120: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6121: }
6122: } else {
6123: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6124: }
6125: }
6126: }
6127: } else {
6128: foreach my $type (@types) {
6129: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6130: }
6131: }
6132: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6133: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6134: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6135: }
6136: } else {
6137: foreach my $type (@types) {
6138: $currmysql{$type} = $staticdefaults{'mysqltables'};
6139: }
6140: }
6141: } else {
6142: foreach my $type (@types) {
6143: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6144: if ($staticdefaults{'domexttool'}) {
6145: $domexttool{$type} = ' checked="checked"';
6146: }
6147: }
6148: }
6149: if (!$currdefresponder) {
6150: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
6151: } elsif ($currdefresponder < 1) {
6152: $currdefresponder = 1;
6153: }
6154: foreach my $type (@types) {
6155: if ($curruploadquota{$type} eq '') {
6156: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6157: }
6158: if ($currcoursequota{$type} eq '') {
6159: $currcoursequota{$type} = $staticdefaults{'coursequota'};
6160: }
6161: }
6162: $datatable .=
6163: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6164: $choices{'anonsurvey_threshold'}.
6165: '</span></td>'.
6166: '<td class="LC_right_item"><span class="LC_nobreak">'.
6167: '<input type="text" name="anonsurvey_threshold"'.
6168: ' value="'.$currdefresponder.'" size="5" /></span>'.
6169: '</td></tr>'."\n";
6170: $itemcount ++;
6171: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6172: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6173: $choices{'uploadquota'}.
6174: '</span></td>'.
6175: '<td align="right" class="LC_right_item">'.
6176: '<table><tr>';
6177: foreach my $type (@types) {
6178: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6179: '<input type="text" name="uploadquota_'.$type.'"'.
6180: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6181: }
6182: $datatable .= '</tr></table></td></tr>'."\n";
6183: $itemcount ++;
6184: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6185: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6186: $choices{'coursequota'}.
6187: '</span></td>'.
6188: '<td style="text-align: right" class="LC_right_item">'.
6189: '<table><tr>';
6190: foreach my $type (@types) {
6191: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
6192: '<input type="text" name="coursequota_'.$type.'"'.
6193: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
6194: }
6195: $datatable .= '</tr></table></td></tr>'."\n";
6196: $itemcount ++;
6197: my $onclick = "toggleDisplay(this.form,'credits');";
6198: my $display = 'none';
6199: if ($currusecredits) {
6200: $display = 'block';
6201: }
6202: my $additional = '<div id="credits" style="display: '.$display.'">'.
6203: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6204: foreach my $type (@types) {
6205: next if ($type eq 'community');
6206: $additional .= '<td align="center">'.&mt($type).'<br />'.
6207: '<input type="text" name="'.$type.'_credits"'.
6208: ' value="'.$defcredits{$type}.'" size="3" /></td>';
6209: }
6210: $additional .= '</tr></table></div>'."\n";
6211: %defaultchecked = ('coursecredits' => 'off');
6212: @toggles = ('coursecredits');
6213: my $current = {
6214: 'coursecredits' => $currusecredits,
6215: };
6216: (my $table,$itemcount) =
6217: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6218: \%choices,$itemcount,$onclick,$additional,'left');
6219: $datatable .= $table;
6220: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6221: my $display = 'none';
6222: if ($postsubmitclient) {
6223: $display = 'block';
6224: }
6225: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
6226: &mt('Number of seconds submit is disabled').'<br />'.
6227: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6228: '<table><tr>';
6229: foreach my $type (@types) {
6230: $additional .= '<td align="center">'.&mt($type).'<br />'.
6231: '<input type="text" name="'.$type.'_timeout" value="'.
6232: $deftimeout{$type}.'" size="5" /></td>';
6233: }
6234: $additional .= '</tr></table></div>'."\n";
6235: %defaultchecked = ('postsubmit' => 'on');
6236: @toggles = ('postsubmit');
6237: $current = {
6238: 'postsubmit' => $postsubmitclient,
6239: };
6240: ($table,$itemcount) =
6241: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6242: \%choices,$itemcount,$onclick,$additional,'left');
6243: $datatable .= $table;
6244: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6245: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6246: $choices{'mysqltables'}.
6247: '</span></td>'.
6248: '<td align="right" class="LC_right_item">'.
6249: '<table><tr>';
6250: foreach my $type (@types) {
6251: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6252: '<input type="text" name="mysqltables_'.$type.'"'.
6253: ' value="'.$currmysql{$type}.'" size="8" /></td>';
6254: }
6255: $datatable .= '</tr></table></td></tr>'."\n";
6256: $itemcount ++;
6257: %defaultchecked = ('ltiauth' => 'off');
6258: @toggles = ('ltiauth');
6259: $current = {
6260: 'ltiauth' => $ltiauth,
6261: };
6262: ($table,$itemcount) =
6263: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6264: \%choices,$itemcount,undef,undef,'left');
6265: $datatable .= $table;
6266: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6267: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6268: $choices{'domexttool'}.
6269: '</span></td>'.
6270: '<td style="text-align: right" class="LC_right_item">'.
6271: '<table><tr>';
6272: foreach my $type (@types) {
6273: $datatable .= '<td style="text-align: left">'.
6274: '<span class="LC_nobreak">'.
6275: '<input type="checkbox" name="domexttool"'.
6276: ' value="'.$type.'"'.$domexttool{$type}.' />'.
6277: &mt($type).'</span></td>'."\n";
6278: }
6279: $datatable .= '</tr></table></td></tr>'."\n";
6280: $itemcount ++;
6281: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6282: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6283: $choices{'exttool'}.
6284: '</span></td>'.
6285: '<td style="text-align: right" class="LC_right_item">'.
6286: '<table><tr>';
6287: foreach my $type (@types) {
6288: $datatable .= '<td style="text-align: left">'.
6289: '<span class="LC_nobreak">'.
6290: '<input type="checkbox" name="exttool"'.
6291: ' value="'.$type.'"'.$exttool{$type}.' />'.
6292: &mt($type).'</span></td>'."\n";
6293: }
6294: $datatable .= '</tr></table></td></tr>'."\n";
6295: }
6296: $$rowtotal += $itemcount;
6297: return $datatable;
6298: }
6299:
6300: sub print_selfenrollment {
6301: my ($position,$dom,$settings,$rowtotal) = @_;
6302: my ($css_class,$datatable);
6303: my $itemcount = 1;
6304: my @types = ('official','unofficial','community','textbook');
6305: if (($position eq 'top') || ($position eq 'middle')) {
6306: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6307: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
6308: my @rows;
6309: my $key;
6310: if ($position eq 'top') {
6311: $key = 'admin';
6312: if (ref($rowsref) eq 'ARRAY') {
6313: @rows = @{$rowsref};
6314: }
6315: } elsif ($position eq 'middle') {
6316: $key = 'default';
6317: @rows = ('types','registered','approval','limit');
6318: }
6319: foreach my $row (@rows) {
6320: if (defined($titlesref->{$row})) {
6321: $itemcount ++;
6322: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6323: $datatable .= '<tr'.$css_class.'>'.
6324: '<td>'.$titlesref->{$row}.'</td>'.
6325: '<td class="LC_left_item">'.
6326: '<table><tr>';
6327: my (%current,%currentcap);
6328: if (ref($settings) eq 'HASH') {
6329: if (ref($settings->{$key}) eq 'HASH') {
6330: foreach my $type (@types) {
6331: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6332: $current{$type} = $settings->{$key}->{$type}->{$row};
6333: }
6334: if (($row eq 'limit') && ($key eq 'default')) {
6335: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6336: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6337: }
6338: }
6339: }
6340: }
6341: }
6342: my %roles = (
6343: '0' => &Apache::lonnet::plaintext('dc'),
6344: );
6345:
6346: foreach my $type (@types) {
6347: unless (($row eq 'registered') && ($key eq 'default')) {
6348: $datatable .= '<th>'.&mt($type).'</th>';
6349: }
6350: }
6351: unless (($row eq 'registered') && ($key eq 'default')) {
6352: $datatable .= '</tr><tr>';
6353: }
6354: foreach my $type (@types) {
6355: if ($type eq 'community') {
6356: $roles{'1'} = &mt('Community personnel');
6357: } else {
6358: $roles{'1'} = &mt('Course personnel');
6359: }
6360: $datatable .= '<td style="vertical-align: top">';
6361: if ($position eq 'top') {
6362: my %checked;
6363: if ($current{$type} eq '0') {
6364: $checked{'0'} = ' checked="checked"';
6365: } else {
6366: $checked{'1'} = ' checked="checked"';
6367: }
6368: foreach my $role ('1','0') {
6369: $datatable .= '<span class="LC_nobreak"><label>'.
6370: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6371: 'value="'.$role.'"'.$checked{$role}.' />'.
6372: $roles{$role}.'</label></span> ';
6373: }
6374: } else {
6375: if ($row eq 'types') {
6376: my %checked;
6377: if ($current{$type} =~ /^(all|dom)$/) {
6378: $checked{$1} = ' checked="checked"';
6379: } else {
6380: $checked{''} = ' checked="checked"';
6381: }
6382: foreach my $val ('','dom','all') {
6383: $datatable .= '<span class="LC_nobreak"><label>'.
6384: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6385: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6386: }
6387: } elsif ($row eq 'registered') {
6388: my %checked;
6389: if ($current{$type} eq '1') {
6390: $checked{'1'} = ' checked="checked"';
6391: } else {
6392: $checked{'0'} = ' checked="checked"';
6393: }
6394: foreach my $val ('0','1') {
6395: $datatable .= '<span class="LC_nobreak"><label>'.
6396: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6397: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6398: }
6399: } elsif ($row eq 'approval') {
6400: my %checked;
6401: if ($current{$type} =~ /^([12])$/) {
6402: $checked{$1} = ' checked="checked"';
6403: } else {
6404: $checked{'0'} = ' checked="checked"';
6405: }
6406: for my $val (0..2) {
6407: $datatable .= '<span class="LC_nobreak"><label>'.
6408: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6409: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6410: }
6411: } elsif ($row eq 'limit') {
6412: my %checked;
6413: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6414: $checked{$1} = ' checked="checked"';
6415: } else {
6416: $checked{'none'} = ' checked="checked"';
6417: }
6418: my $cap;
6419: if ($currentcap{$type} =~ /^\d+$/) {
6420: $cap = $currentcap{$type};
6421: }
6422: foreach my $val ('none','allstudents','selfenrolled') {
6423: $datatable .= '<span class="LC_nobreak"><label>'.
6424: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6425: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6426: }
6427: $datatable .= '<br />'.
6428: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6429: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6430: '</span>';
6431: }
6432: }
6433: $datatable .= '</td>';
6434: }
6435: $datatable .= '</tr>';
6436: }
6437: $datatable .= '</table></td></tr>';
6438: }
6439: } elsif ($position eq 'bottom') {
6440: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6441: }
6442: $$rowtotal += $itemcount;
6443: return $datatable;
6444: }
6445:
6446: sub print_validation_rows {
6447: my ($caller,$dom,$settings,$rowtotal) = @_;
6448: my ($itemsref,$namesref,$fieldsref);
6449: if ($caller eq 'selfenroll') {
6450: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6451: } elsif ($caller eq 'requestcourses') {
6452: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6453: }
6454: my %currvalidation;
6455: if (ref($settings) eq 'HASH') {
6456: if (ref($settings->{'validation'}) eq 'HASH') {
6457: %currvalidation = %{$settings->{'validation'}};
6458: }
6459: }
6460: my $datatable;
6461: my $itemcount = 0;
6462: foreach my $item (@{$itemsref}) {
6463: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6464: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6465: $namesref->{$item}.
6466: '</span></td>'.
6467: '<td class="LC_left_item">';
6468: if (($item eq 'url') || ($item eq 'button')) {
6469: $datatable .= '<span class="LC_nobreak">'.
6470: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6471: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6472: } elsif ($item eq 'fields') {
6473: my @currfields;
6474: if (ref($currvalidation{$item}) eq 'ARRAY') {
6475: @currfields = @{$currvalidation{$item}};
6476: }
6477: foreach my $field (@{$fieldsref}) {
6478: my $check = '';
6479: if (grep(/^\Q$field\E$/,@currfields)) {
6480: $check = ' checked="checked"';
6481: }
6482: $datatable .= '<span class="LC_nobreak"><label>'.
6483: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6484: ' value="'.$field.'"'.$check.' />'.$field.
6485: '</label></span> ';
6486: }
6487: } elsif ($item eq 'markup') {
6488: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
6489: $currvalidation{$item}.
6490: '</textarea>';
6491: }
6492: $datatable .= '</td></tr>'."\n";
6493: if (ref($rowtotal)) {
6494: $itemcount ++;
6495: }
6496: }
6497: if ($caller eq 'requestcourses') {
6498: my %currhash;
6499: if (ref($settings) eq 'HASH') {
6500: if (ref($settings->{'validation'}) eq 'HASH') {
6501: if ($settings->{'validation'}{'dc'} ne '') {
6502: $currhash{$settings->{'validation'}{'dc'}} = 1;
6503: }
6504: }
6505: }
6506: my $numinrow = 2;
6507: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6508: 'validationdc',%currhash);
6509: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6510: $datatable .= '<tr'.$css_class.'><td>';
6511: if ($numdc > 1) {
6512: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
6513: } else {
6514: $datatable .= &mt('Course creation processed as: ');
6515: }
6516: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
6517: $itemcount ++;
6518: }
6519: if (ref($rowtotal)) {
6520: $$rowtotal += $itemcount;
6521: }
6522: return $datatable;
6523: }
6524:
6525: sub print_passwords {
6526: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6527: my ($datatable,$css_class);
6528: my $itemcount = 0;
6529: my %titles = &Apache::lonlocal::texthash (
6530: captcha => '"Forgot Password" CAPTCHA validation',
6531: link => 'Reset link expiration (hours)',
6532: case => 'Case-sensitive usernames/e-mail',
6533: prelink => 'Information required (form 1)',
6534: postlink => 'Information required (form 2)',
6535: emailsrc => 'LON-CAPA e-mail address type(s)',
6536: customtext => 'Domain specific text (HTML)',
6537: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6538: intauth_check => 'Check bcrypt cost if authenticated',
6539: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6540: permanent => 'Permanent e-mail address',
6541: critical => 'Critical notification address',
6542: notify => 'Notification address',
6543: min => 'Minimum password length',
6544: max => 'Maximum password length',
6545: chars => 'Required characters',
6546: numsaved => 'Number of previous passwords to save and disallow reuse',
6547: );
6548: if ($position eq 'top') {
6549: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6550: my $shownlinklife = 2;
6551: my $prelink = 'both';
6552: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6553: if (ref($settings) eq 'HASH') {
6554: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6555: $shownlinklife = $settings->{resetlink};
6556: }
6557: if (ref($settings->{resetcase}) eq 'ARRAY') {
6558: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6559: }
6560: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6561: $prelink = $settings->{resetprelink};
6562: }
6563: if (ref($settings->{resetpostlink}) eq 'HASH') {
6564: %postlink = %{$settings->{resetpostlink}};
6565: }
6566: if (ref($settings->{resetemail}) eq 'ARRAY') {
6567: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6568: }
6569: if ($settings->{resetremove}) {
6570: $nostdtext = 1;
6571: }
6572: if ($settings->{resetcustom}) {
6573: $customurl = $settings->{resetcustom};
6574: }
6575: } else {
6576: if (ref($types) eq 'ARRAY') {
6577: foreach my $item (@{$types}) {
6578: $casesens{$item} = 1;
6579: $postlink{$item} = ['username','email'];
6580: }
6581: }
6582: $casesens{'default'} = 1;
6583: $postlink{'default'} = ['username','email'];
6584: $prelink = 'both';
6585: %emailsrc = (
6586: permanent => 1,
6587: critical => 1,
6588: notify => 1,
6589: );
6590: }
6591: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6592: $itemcount ++;
6593: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6594: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6595: '<td class="LC_left_item">'.
6596: '<input type="textbox" value="'.$shownlinklife.'" '.
6597: 'name="passwords_link" size="3" /></td></tr>';
6598: $itemcount ++;
6599: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6600: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6601: '<td class="LC_left_item">';
6602: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6603: foreach my $item (@{$types}) {
6604: my $checkedcase;
6605: if ($casesens{$item}) {
6606: $checkedcase = ' checked="checked"';
6607: }
6608: $datatable .= '<span class="LC_nobreak"><label>'.
6609: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6610: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
6611: '</span> ';
6612: }
6613: }
6614: my $checkedcase;
6615: if ($casesens{'default'}) {
6616: $checkedcase = ' checked="checked"';
6617: }
6618: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6619: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6620: $othertitle.'</label></span></td>';
6621: $itemcount ++;
6622: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6623: my %checkedpre = (
6624: both => ' checked="checked"',
6625: either => '',
6626: );
6627: if ($prelink eq 'either') {
6628: $checkedpre{either} = ' checked="checked"';
6629: $checkedpre{both} = '';
6630: }
6631: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6632: '<td class="LC_left_item"><span class="LC_nobreak">'.
6633: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6634: &mt('Both username and e-mail address').'</label></span> '.
6635: '<span class="LC_nobreak"><label>'.
6636: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6637: &mt('Either username or e-mail address').'</label></span></td></tr>';
6638: $itemcount ++;
6639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6640: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6641: '<td class="LC_left_item">';
6642: my %postlinked;
6643: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6644: foreach my $item (@{$types}) {
6645: undef(%postlinked);
6646: $datatable .= '<fieldset style="display: inline-block;">'.
6647: '<legend>'.$usertypes->{$item}.'</legend>';
6648: if (ref($postlink{$item}) eq 'ARRAY') {
6649: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6650: }
6651: foreach my $field ('email','username') {
6652: my $checked;
6653: if ($postlinked{$field}) {
6654: $checked = ' checked="checked"';
6655: }
6656: $datatable .= '<span class="LC_nobreak"><label>'.
6657: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6658: $field.'"'.$checked.' />'.$field.'</label>'.
6659: '<span> ';
6660: }
6661: $datatable .= '</fieldset>';
6662: }
6663: }
6664: if (ref($postlink{'default'}) eq 'ARRAY') {
6665: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6666: }
6667: $datatable .= '<fieldset style="display: inline-block;">'.
6668: '<legend>'.$othertitle.'</legend>';
6669: foreach my $field ('email','username') {
6670: my $checked;
6671: if ($postlinked{$field}) {
6672: $checked = ' checked="checked"';
6673: }
6674: $datatable .= '<span class="LC_nobreak"><label>'.
6675: '<input type="checkbox" name="passwords_postlink_default" value="'.
6676: $field.'"'.$checked.' />'.$field.'</label>'.
6677: '<span> ';
6678: }
6679: $datatable .= '</fieldset></td></tr>';
6680: $itemcount ++;
6681: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6682: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6683: '<td class="LC_left_item">';
6684: foreach my $type ('permanent','critical','notify') {
6685: my $checkedemail;
6686: if ($emailsrc{$type}) {
6687: $checkedemail = ' checked="checked"';
6688: }
6689: $datatable .= '<span class="LC_nobreak"><label>'.
6690: '<input type="checkbox" name="passwords_emailsrc" value="'.
6691: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6692: '<span> ';
6693: }
6694: $datatable .= '</td></tr>';
6695: $itemcount ++;
6696: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6697: my $switchserver = &check_switchserver($dom,$confname);
6698: my ($showstd,$noshowstd);
6699: if ($nostdtext) {
6700: $noshowstd = ' checked="checked"';
6701: } else {
6702: $showstd = ' checked="checked"';
6703: }
6704: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6705: '<td class="LC_left_item"><span class="LC_nobreak">'.
6706: &mt('Retain standard text:').
6707: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6708: &mt('Yes').'</label>'.' '.
6709: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6710: &mt('No').'</label></span><br />'.
6711: '<span class="LC_fontsize_small">'.
6712: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6713: &mt('Include custom text:');
6714: if ($customurl) {
6715: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
6716: undef,undef,undef,undef,'background-color:#ffffff');
6717: $datatable .= '<span class="LC_nobreak"> '.$link.
6718: '<label><input type="checkbox" name="passwords_custom_del"'.
6719: ' value="1" />'.&mt('Delete?').'</label></span>'.
6720: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6721: }
6722: if ($switchserver) {
6723: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6724: } else {
6725: $datatable .='<span class="LC_nobreak"> '.
6726: '<input type="file" name="passwords_customfile" /></span>';
6727: }
6728: $datatable .= '</td></tr>';
6729: } elsif ($position eq 'middle') {
6730: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6731: my @items = ('intauth_cost','intauth_check','intauth_switch');
6732: my %defaults;
6733: if (ref($domconf{'defaults'}) eq 'HASH') {
6734: %defaults = %{$domconf{'defaults'}};
6735: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6736: $defaults{'intauth_cost'} = 10;
6737: }
6738: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6739: $defaults{'intauth_check'} = 0;
6740: }
6741: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6742: $defaults{'intauth_switch'} = 0;
6743: }
6744: } else {
6745: %defaults = (
6746: 'intauth_cost' => 10,
6747: 'intauth_check' => 0,
6748: 'intauth_switch' => 0,
6749: );
6750: }
6751: foreach my $item (@items) {
6752: if ($itemcount%2) {
6753: $css_class = '';
6754: } else {
6755: $css_class = ' class="LC_odd_row" ';
6756: }
6757: $datatable .= '<tr'.$css_class.'>'.
6758: '<td><span class="LC_nobreak">'.$titles{$item}.
6759: '</span></td><td class="LC_left_item" colspan="3">';
6760: if ($item eq 'intauth_switch') {
6761: my @options = (0,1,2);
6762: my %optiondesc = &Apache::lonlocal::texthash (
6763: 0 => 'No',
6764: 1 => 'Yes',
6765: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6766: );
6767: $datatable .= '<table width="100%">';
6768: foreach my $option (@options) {
6769: my $checked = ' ';
6770: if ($defaults{$item} eq $option) {
6771: $checked = ' checked="checked"';
6772: }
6773: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6774: '<label><input type="radio" name="'.$item.
6775: '" value="'.$option.'"'.$checked.' />'.
6776: $optiondesc{$option}.'</label></span></td></tr>';
6777: }
6778: $datatable .= '</table>';
6779: } elsif ($item eq 'intauth_check') {
6780: my @options = (0,1,2);
6781: my %optiondesc = &Apache::lonlocal::texthash (
6782: 0 => 'No',
6783: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6784: 2 => 'Yes, disallow login if stored cost is less than domain default',
6785: );
6786: $datatable .= '<table width="100%">';
6787: foreach my $option (@options) {
6788: my $checked = ' ';
6789: my $onclick;
6790: if ($defaults{$item} eq $option) {
6791: $checked = ' checked="checked"';
6792: }
6793: if ($option == 2) {
6794: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6795: }
6796: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6797: '<label><input type="radio" name="'.$item.
6798: '" value="'.$option.'"'.$checked.$onclick.' />'.
6799: $optiondesc{$option}.'</label></span></td></tr>';
6800: }
6801: $datatable .= '</table>';
6802: } else {
6803: $datatable .= '<input type="text" name="'.$item.'" value="'.
6804: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6805: }
6806: $datatable .= '</td></tr>';
6807: $itemcount ++;
6808: }
6809: } elsif ($position eq 'lower') {
6810: $datatable .= &password_rules('passwords',\$itemcount,$settings);
6811: } else {
6812: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6813: my %ownerchg = (
6814: by => {},
6815: for => {},
6816: );
6817: my %ownertitles = &Apache::lonlocal::texthash (
6818: by => 'Course owner status(es) allowed',
6819: for => 'Student status(es) allowed',
6820: );
6821: if (ref($settings) eq 'HASH') {
6822: if (ref($settings->{crsownerchg}) eq 'HASH') {
6823: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6824: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6825: }
6826: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6827: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6828: }
6829: }
6830: }
6831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6832: $datatable .= '<tr '.$css_class.'>'.
6833: '<td>'.
6834: &mt('Requirements').'<ul>'.
6835: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6836: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6837: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6838: '<li>'.&mt('User, course, and student share same domain').'</li>'.
6839: '</ul>'.
6840: '</td>'.
6841: '<td class="LC_left_item">';
6842: foreach my $item ('by','for') {
6843: $datatable .= '<fieldset style="display: inline-block;">'.
6844: '<legend>'.$ownertitles{$item}.'</legend>';
6845: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6846: foreach my $type (@{$types}) {
6847: my $checked;
6848: if ($ownerchg{$item}{$type}) {
6849: $checked = ' checked="checked"';
6850: }
6851: $datatable .= '<span class="LC_nobreak"><label>'.
6852: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6853: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
6854: '</span> ';
6855: }
6856: }
6857: my $checked;
6858: if ($ownerchg{$item}{'default'}) {
6859: $checked = ' checked="checked"';
6860: }
6861: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6862: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6863: $othertitle.'</label></span></fieldset>';
6864: }
6865: $datatable .= '</td></tr>';
6866: }
6867: return $datatable;
6868: }
6869:
6870: sub password_rules {
6871: my ($prefix,$itemcountref,$settings) = @_;
6872: my ($min,$max,%chars,$numsaved,$numinrow);
6873: my %titles;
6874: if ($prefix eq 'passwords') {
6875: %titles = &Apache::lonlocal::texthash (
6876: min => 'Minimum password length',
6877: max => 'Maximum password length',
6878: chars => 'Required characters',
6879: );
6880: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
6881: %titles = &Apache::lonlocal::texthash (
6882: min => 'Minimum secret length',
6883: max => 'Maximum secret length',
6884: chars => 'Required characters',
6885: );
6886: }
6887: $min = $Apache::lonnet::passwdmin;
6888: my $datatable;
6889: my $itemcount;
6890: if (ref($itemcountref)) {
6891: $itemcount = $$itemcountref;
6892: }
6893: if (ref($settings) eq 'HASH') {
6894: if ($settings->{min}) {
6895: $min = $settings->{min};
6896: }
6897: if ($settings->{max}) {
6898: $max = $settings->{max};
6899: }
6900: if (ref($settings->{chars}) eq 'ARRAY') {
6901: map { $chars{$_} = 1; } (@{$settings->{chars}});
6902: }
6903: if ($prefix eq 'passwords') {
6904: if ($settings->{numsaved}) {
6905: $numsaved = $settings->{numsaved};
6906: }
6907: }
6908: }
6909: my %rulenames = &Apache::lonlocal::texthash(
6910: uc => 'At least one upper case letter',
6911: lc => 'At least one lower case letter',
6912: num => 'At least one number',
6913: spec => 'At least one non-alphanumeric',
6914: );
6915: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6916: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6917: '<td class="LC_left_item"><span class="LC_nobreak">'.
6918: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
6919: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6920: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
6921: '</span></td></tr>';
6922: $itemcount ++;
6923: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6924: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6925: '<td class="LC_left_item"><span class="LC_nobreak">'.
6926: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
6927: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6928: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6929: '</span></td></tr>';
6930: $itemcount ++;
6931: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6932: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6933: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6934: '</span></td>';
6935: my $numinrow = 2;
6936: my @possrules = ('uc','lc','num','spec');
6937: $datatable .= '<td class="LC_left_item"><table>';
6938: for (my $i=0; $i<@possrules; $i++) {
6939: my ($rem,$checked);
6940: if ($chars{$possrules[$i]}) {
6941: $checked = ' checked="checked"';
6942: }
6943: $rem = $i%($numinrow);
6944: if ($rem == 0) {
6945: if ($i > 0) {
6946: $datatable .= '</tr>';
6947: }
6948: $datatable .= '<tr>';
6949: }
6950: $datatable .= '<td><span class="LC_nobreak"><label>'.
6951: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6952: $rulenames{$possrules[$i]}.'</label></span></td>';
6953: }
6954: my $rem = @possrules%($numinrow);
6955: my $colsleft = $numinrow - $rem;
6956: if ($colsleft > 1 ) {
6957: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6958: ' </td>';
6959: } elsif ($colsleft == 1) {
6960: $datatable .= '<td class="LC_left_item"> </td>';
6961: }
6962: $datatable .='</table></td></tr>';
6963: $itemcount ++;
6964: if ($prefix eq 'passwords') {
6965: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
6966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6967: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6968: '<td class="LC_left_item"><span class="LC_nobreak">'.
6969: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
6970: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6971: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6972: '</span></td></tr>';
6973: $itemcount ++;
6974: }
6975: if (ref($itemcountref)) {
6976: $$itemcountref += $itemcount;
6977: }
6978: return $datatable;
6979: }
6980:
6981: sub print_wafproxy {
6982: my ($position,$dom,$settings,$rowtotal) = @_;
6983: my $css_class;
6984: my $itemcount = 0;
6985: my $datatable;
6986: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6987: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
6988: my %lt = &wafproxy_titles();
6989: foreach my $server (sort(keys(%servers))) {
6990: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
6991: next if ($serverhome eq '');
6992: my $serverdom;
6993: if ($serverhome ne $server) {
6994: $serverdom = &Apache::lonnet::host_domain($serverhome);
6995: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
6996: $othercontrol{$server} = $serverdom;
6997: }
6998: } else {
6999: $serverdom = &Apache::lonnet::host_domain($server);
7000: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
7001: if ($serverdom ne $dom) {
7002: $othercontrol{$server} = $serverdom;
7003: } else {
7004: $setdom = 1;
7005: if (ref($settings) eq 'HASH') {
7006: if (ref($settings->{'alias'}) eq 'HASH') {
7007: $aliases{$dom} = $settings->{'alias'};
7008: if ($aliases{$dom} ne '') {
7009: $showdom = 1;
7010: }
7011: }
7012: if (ref($settings->{'saml'}) eq 'HASH') {
7013: $saml{$dom} = $settings->{'saml'};
7014: }
7015: }
7016: }
7017: }
7018: }
7019: if ($setdom) {
7020: %{$values{$dom}} = ();
7021: if (ref($settings) eq 'HASH') {
7022: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7023: $values{$dom}{$item} = $settings->{$item};
7024: }
7025: }
7026: }
7027: if (keys(%othercontrol)) {
7028: %otherdoms = reverse(%othercontrol);
7029: foreach my $domain (keys(%otherdoms)) {
7030: %{$values{$domain}} = ();
7031: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7032: if (ref($config{'wafproxy'}) eq 'HASH') {
7033: $aliases{$domain} = $config{'wafproxy'}{'alias'};
7034: if (exists($config{'wafproxy'}{'saml'})) {
7035: $saml{$domain} = $config{'wafproxy'}{'saml'};
7036: }
7037: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7038: $values{$domain}{$item} = $config{'wafproxy'}{$item};
7039: }
7040: }
7041: }
7042: }
7043: if ($position eq 'top') {
7044: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7045: my %aliasinfo;
7046: foreach my $server (sort(keys(%servers))) {
7047: $itemcount ++;
7048: my $dom_in_effect;
7049: my $aliasrows = '<tr>'.
7050: '<td class="LC_left_item" style="vertical-align: baseline;">'.
7051: &mt('Hostname').': '.
7052: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
7053: if ($othercontrol{$server}) {
7054: $dom_in_effect = $othercontrol{$server};
7055: my ($current,$forsaml);
7056: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7057: $current = $aliases{$dom_in_effect}{$server};
7058: }
7059: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7060: if ($saml{$dom_in_effect}{$server}) {
7061: $forsaml = 1;
7062: }
7063: }
7064: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7065: &mt('Alias').': ';
7066: if ($current) {
7067: $aliasrows .= $current;
7068: if ($forsaml) {
7069: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
7070: }
7071: } else {
7072: $aliasrows .= &mt('None');
7073: }
7074: $aliasrows .= ' <span class="LC_small">('.
7075: &mt('controlled by domain: [_1]',
7076: '<b>'.$dom_in_effect.'</b>').')</span></td>';
7077: } else {
7078: $dom_in_effect = $dom;
7079: my ($current,$samlon,$samloff);
7080: $samloff = ' checked="checked"';
7081: if (ref($aliases{$dom}) eq 'HASH') {
7082: if ($aliases{$dom}{$server}) {
7083: $current = $aliases{$dom}{$server};
7084: }
7085: }
7086: if (ref($saml{$dom}) eq 'HASH') {
7087: if ($saml{$dom}{$server}) {
7088: $samlon = $samloff;
7089: undef($samloff);
7090: }
7091: }
7092: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7093: &mt('Alias').': '.
7094: '<input type="text" name="wafproxy_alias_'.$server.'" '.
7095: 'value="'.$current.'" size="30" />'.
7096: (' 'x2).'<span class="LC_nobreak">'.
7097: &mt('Alias used for SSO Auth').': <label>'.
7098: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7099: &mt('No').'</label> <label>'.
7100: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7101: &mt('Yes').'</label></span>'.
7102: '</td>';
7103: }
7104: $aliasrows .= '</tr>';
7105: $aliasinfo{$dom_in_effect} .= $aliasrows;
7106: }
7107: if ($aliasinfo{$dom}) {
7108: my ($onclick,$wafon,$wafoff,$showtable);
7109: $onclick = ' onclick="javascript:toggleWAF();"';
7110: $wafoff = ' checked="checked"';
7111: $showtable = ' style="display:none";';
7112: if ($showdom) {
7113: $wafon = $wafoff;
7114: $wafoff = '';
7115: $showtable = ' style="display:inline;"';
7116: }
7117: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7118: $datatable = '<tr'.$css_class.'>'.
7119: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7120: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7121: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7122: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7123: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7124: &mt('No').'</label></span></td>'.
7125: '<td class="LC_left_item">'.
7126: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7127: '</table></td></tr>';
7128: $itemcount++;
7129: }
7130: if (keys(%otherdoms)) {
7131: foreach my $key (sort(keys(%otherdoms))) {
7132: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7133: $datatable .= '<tr'.$css_class.'>'.
7134: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7135: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7136: '</table></td></tr>';
7137: $itemcount++;
7138: }
7139: }
7140: } else {
7141: my %ip_methods = &remoteip_methods();
7142: if ($setdom) {
7143: $itemcount ++;
7144: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7145: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
7146: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
7147: $wafstyle = ' style="display:none;"';
7148: $nowafstyle = ' style="display:table-row;"';
7149: $currwafdisplay = ' style="display: none"';
7150: $wafrangestyle = ' style="display: none"';
7151: $curr_remotip = 'n';
7152: $ssltossl = ' checked="checked"';
7153: if ($showdom) {
7154: $wafstyle = ' style="display:table-row;"';
7155: $nowafstyle = ' style="display:none;"';
7156: if (keys(%{$values{$dom}})) {
7157: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7158: $curr_remotip = $values{$dom}{remoteip};
7159: }
7160: if ($curr_remotip eq 'h') {
7161: $currwafdisplay = ' style="display:table-row"';
7162: $wafrangestyle = ' style="display:inline-block;"';
7163: }
7164: if ($values{$dom}{'sslopt'}) {
7165: $alltossl = ' checked="checked"';
7166: $ssltossl = '';
7167: }
7168: }
7169: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7170: $vpndircheck = ' checked="checked"';
7171: $currwafvpn = ' style="display:table-row;"';
7172: $wafrangestyle = ' style="display:inline-block;"';
7173: } else {
7174: $vpnaliascheck = ' checked="checked"';
7175: $currwafvpn = ' style="display:none;"';
7176: }
7177: }
7178: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7179: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7180: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7181: '</tr>'.
7182: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7183: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
7184: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7185: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
7186: &mt('Range(s) stored in CIDR notation').'</div></td>'.
7187: '<td class="LC_left_item"><table>'.
7188: '<tr>'.
7189: '<td valign="top">'.$lt{'remoteip'}.': '.
7190: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7191: foreach my $option ('m','h','n') {
7192: my $sel;
7193: if ($option eq $curr_remotip) {
7194: $sel = ' selected="selected"';
7195: }
7196: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7197: $ip_methods{$option}.'</option>';
7198: }
7199: $datatable .= '</select></td></tr>'."\n".
7200: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7201: $lt{'ipheader'}.': '.
7202: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7203: 'name="wafproxy_ipheader" />'.
7204: '</td></tr>'."\n".
7205: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
7206: $lt{'trusted'}.':<br />'.
7207: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7208: $values{$dom}{'trusted'}.'</textarea>'.
7209: '</td></tr>'."\n".
7210: '<tr><td><hr /></td></tr>'."\n".
7211: '<tr>'.
7212: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7213: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7214: $lt{'vpndirect'}.'</label>'.(' 'x2).
7215: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7216: $lt{'vpnaliased'}.'</label></span></td></tr>';
7217: foreach my $item ('vpnint','vpnext') {
7218: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
7219: '<td valign="top">'.$lt{$item}.':<br />'.
7220: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7221: $values{$dom}{$item}.'</textarea>'.
7222: '</td></tr>'."\n";
7223: }
7224: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7225: '<tr>'.
7226: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7227: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7228: $lt{'alltossl'}.'</label>'.(' 'x2).
7229: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7230: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7231: '</table></td></tr>';
7232: }
7233: if (keys(%otherdoms)) {
7234: foreach my $domain (sort(keys(%otherdoms))) {
7235: $itemcount ++;
7236: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7237: $datatable .= '<tr'.$css_class.'>'.
7238: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
7239: '<td class="LC_left_item"><table>';
7240: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
7241: my $showval = &mt('None');
7242: if ($item eq 'ssl') {
7243: $showval = $lt{'ssltossl'};
7244: }
7245: if ($values{$domain}{$item}) {
7246: $showval = $values{$domain}{$item};
7247: if ($item eq 'ssl') {
7248: $showval = $lt{'alltossl'};
7249: } elsif ($item eq 'remoteip') {
7250: $showval = $ip_methods{$values{$domain}{$item}};
7251: }
7252: }
7253: $datatable .= '<tr>'.
7254: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7255: }
7256: $datatable .= '</table></td></tr>';
7257: }
7258: }
7259: }
7260: $$rowtotal += $itemcount;
7261: return $datatable;
7262: }
7263:
7264: sub wafproxy_titles {
7265: return &Apache::lonlocal::texthash(
7266: remoteip => "Method for determining user's IP",
7267: ipheader => 'Request header containing remote IP',
7268: trusted => 'Trusted IP range(s)',
7269: vpnaccess => 'Access from institutional VPN',
7270: vpndirect => 'via regular hostname (no WAF)',
7271: vpnaliased => 'via aliased hostname (WAF)',
7272: vpnint => 'Internal IP Range(s) for VPN sessions',
7273: vpnext => 'IP Range(s) for backend WAF connections',
7274: sslopt => 'Forwarding http/https',
7275: alltossl => 'WAF forwards both http and https requests to https',
7276: ssltossl => 'WAF forwards http requests to http and https to https',
7277: );
7278: }
7279:
7280: sub remoteip_methods {
7281: return &Apache::lonlocal::texthash(
7282: m => 'Use Apache mod_remoteip',
7283: h => 'Use headers parsed by LON-CAPA',
7284: n => 'Not in use',
7285: );
7286: }
7287:
7288: sub print_usersessions {
7289: my ($position,$dom,$settings,$rowtotal) = @_;
7290: my ($css_class,$datatable,%checked,%choices);
7291: my (%by_ip,%by_location,@intdoms);
7292: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7293:
7294: my @alldoms = &Apache::lonnet::all_domains();
7295: my %serverhomes = %Apache::lonnet::serverhomeIDs;
7296: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7297: my %altids = &id_for_thisdom(%servers);
7298: my $itemcount = 1;
7299: if ($position eq 'top') {
7300: if (keys(%serverhomes) > 1) {
7301: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
7302: my ($curroffloadnow,$curroffloadoth);
7303: if (ref($settings) eq 'HASH') {
7304: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7305: $curroffloadnow = $settings->{'offloadnow'};
7306: }
7307: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7308: $curroffloadoth = $settings->{'offloadoth'};
7309: }
7310: }
7311: my $other_insts = scalar(keys(%by_location));
7312: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7313: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
7314: } else {
7315: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
7316: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7317: '</td></tr>';
7318: }
7319: } else {
7320: if (keys(%by_location) == 0) {
7321: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
7322: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7323: '</td></tr>';
7324: } else {
7325: my %lt = &usersession_titles();
7326: my $numinrow = 5;
7327: my $prefix;
7328: my @types;
7329: if ($position eq 'bottom') {
7330: $prefix = 'remote';
7331: @types = ('version','excludedomain','includedomain');
7332: } else {
7333: $prefix = 'hosted';
7334: @types = ('excludedomain','includedomain');
7335: }
7336: my (%current,%checkedon,%checkedoff);
7337: my @lcversions = &Apache::lonnet::all_loncaparevs();
7338: my @locations = sort(keys(%by_location));
7339: foreach my $type (@types) {
7340: $checkedon{$type} = '';
7341: $checkedoff{$type} = ' checked="checked"';
7342: }
7343: if (ref($settings) eq 'HASH') {
7344: if (ref($settings->{$prefix}) eq 'HASH') {
7345: foreach my $key (keys(%{$settings->{$prefix}})) {
7346: $current{$key} = $settings->{$prefix}{$key};
7347: if ($key eq 'version') {
7348: if ($current{$key} ne '') {
7349: $checkedon{$key} = ' checked="checked"';
7350: $checkedoff{$key} = '';
7351: }
7352: } elsif (ref($current{$key}) eq 'ARRAY') {
7353: $checkedon{$key} = ' checked="checked"';
7354: $checkedoff{$key} = '';
7355: }
7356: }
7357: }
7358: }
7359: foreach my $type (@types) {
7360: next if ($type ne 'version' && !@locations);
7361: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7362: $datatable .= '<tr'.$css_class.'>
7363: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
7364: <span class="LC_nobreak">
7365: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7366: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7367: if ($type eq 'version') {
7368: my $selector = '<select name="'.$prefix.'_version">';
7369: foreach my $version (@lcversions) {
7370: my $selected = '';
7371: if ($current{'version'} eq $version) {
7372: $selected = ' selected="selected"';
7373: }
7374: $selector .= ' <option value="'.$version.'"'.
7375: $selected.'>'.$version.'</option>';
7376: }
7377: $selector .= '</select> ';
7378: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7379: } else {
7380: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7381: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7382: ' />'.(' 'x2).
7383: '<input type="button" value="'.&mt('uncheck all').'" '.
7384: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7385: "\n".
7386: '</div><div><table>';
7387: my $rem;
7388: for (my $i=0; $i<@locations; $i++) {
7389: my ($showloc,$value,$checkedtype);
7390: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
7391: my $ip = $by_location{$locations[$i]}->[0];
7392: if (ref($by_ip{$ip}) eq 'ARRAY') {
7393: $value = join(':',@{$by_ip{$ip}});
7394: $showloc = join(', ',@{$by_ip{$ip}});
7395: if (ref($current{$type}) eq 'ARRAY') {
7396: foreach my $loc (@{$by_ip{$ip}}) {
7397: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7398: $checkedtype = ' checked="checked"';
7399: last;
7400: }
7401: }
7402: }
7403: }
7404: }
7405: $rem = $i%($numinrow);
7406: if ($rem == 0) {
7407: if ($i > 0) {
7408: $datatable .= '</tr>';
7409: }
7410: $datatable .= '<tr>';
7411: }
7412: $datatable .= '<td class="LC_left_item">'.
7413: '<span class="LC_nobreak"><label>'.
7414: '<input type="checkbox" name="'.$prefix.'_'.$type.
7415: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7416: '</label></span></td>';
7417: }
7418: $rem = @locations%($numinrow);
7419: my $colsleft = $numinrow - $rem;
7420: if ($colsleft > 1 ) {
7421: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7422: ' </td>';
7423: } elsif ($colsleft == 1) {
7424: $datatable .= '<td class="LC_left_item"> </td>';
7425: }
7426: $datatable .= '</tr></table>';
7427: }
7428: $datatable .= '</td></tr>';
7429: $itemcount ++;
7430: }
7431: }
7432: }
7433: $$rowtotal += $itemcount;
7434: return $datatable;
7435: }
7436:
7437: sub build_location_hashes {
7438: my ($intdoms,$by_ip,$by_location) = @_;
7439: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
7440: (ref($by_location) eq 'HASH'));
7441: my %iphost = &Apache::lonnet::get_iphost();
7442: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7443: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7444: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7445: foreach my $id (@{$iphost{$primary_ip}}) {
7446: my $intdom = &Apache::lonnet::internet_dom($id);
7447: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7448: push(@{$intdoms},$intdom);
7449: }
7450: }
7451: }
7452: foreach my $ip (keys(%iphost)) {
7453: if (ref($iphost{$ip}) eq 'ARRAY') {
7454: foreach my $id (@{$iphost{$ip}}) {
7455: my $location = &Apache::lonnet::internet_dom($id);
7456: if ($location) {
7457: next if (grep(/^\Q$location\E$/,@{$intdoms}));
7458: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7459: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7460: push(@{$by_ip->{$ip}},$location);
7461: }
7462: } else {
7463: $by_ip->{$ip} = [$location];
7464: }
7465: }
7466: }
7467: }
7468: }
7469: foreach my $ip (sort(keys(%{$by_ip}))) {
7470: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7471: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7472: my $first = $by_ip->{$ip}->[0];
7473: if (ref($by_location->{$first}) eq 'ARRAY') {
7474: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7475: push(@{$by_location->{$first}},$ip);
7476: }
7477: } else {
7478: $by_location->{$first} = [$ip];
7479: }
7480: }
7481: }
7482: return;
7483: }
7484:
7485: sub current_offloads_to {
7486: my ($dom,$settings,$servers) = @_;
7487: my (%spareid,%otherdomconfigs);
7488: if (ref($servers) eq 'HASH') {
7489: foreach my $lonhost (sort(keys(%{$servers}))) {
7490: my $gotspares;
7491: if (ref($settings) eq 'HASH') {
7492: if (ref($settings->{'spares'}) eq 'HASH') {
7493: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7494: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7495: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7496: $gotspares = 1;
7497: }
7498: }
7499: }
7500: unless ($gotspares) {
7501: my $gotspares;
7502: my $serverhomeID =
7503: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7504: my $serverhomedom =
7505: &Apache::lonnet::host_domain($serverhomeID);
7506: if ($serverhomedom ne $dom) {
7507: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7508: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7509: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7510: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7511: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7512: $gotspares = 1;
7513: }
7514: }
7515: } else {
7516: $otherdomconfigs{$serverhomedom} =
7517: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7518: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7519: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7520: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7521: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7522: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7523: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7524: $gotspares = 1;
7525: }
7526: }
7527: }
7528: }
7529: }
7530: }
7531: }
7532: unless ($gotspares) {
7533: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7534: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7535: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7536: } else {
7537: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7538: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7539: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7540: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7541: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7542: } else {
7543: my %what = (
7544: spareid => 1,
7545: );
7546: my ($result,$returnhash) =
7547: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7548: if ($result eq 'ok') {
7549: if (ref($returnhash) eq 'HASH') {
7550: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7551: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7552: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7553: }
7554: }
7555: }
7556: }
7557: }
7558: }
7559: }
7560: }
7561: return %spareid;
7562: }
7563:
7564: sub spares_row {
7565: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7566: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
7567: my $css_class;
7568: my $numinrow = 4;
7569: my $itemcount = 1;
7570: my $datatable;
7571: my %typetitles = &sparestype_titles();
7572: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
7573: foreach my $server (sort(keys(%{$servers}))) {
7574: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7575: my ($othercontrol,$serverdom);
7576: if ($serverhome ne $server) {
7577: $serverdom = &Apache::lonnet::host_domain($serverhome);
7578: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7579: } else {
7580: $serverdom = &Apache::lonnet::host_domain($server);
7581: if ($serverdom ne $dom) {
7582: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7583: }
7584: }
7585: next unless (ref($spareid->{$server}) eq 'HASH');
7586: my ($checkednow,$checkedoth);
7587: if (ref($curroffloadnow) eq 'HASH') {
7588: if ($curroffloadnow->{$server}) {
7589: $checkednow = ' checked="checked"';
7590: }
7591: }
7592: if (ref($curroffloadoth) eq 'HASH') {
7593: if ($curroffloadoth->{$server}) {
7594: $checkedoth = ' checked="checked"';
7595: }
7596: }
7597: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7598: $datatable .= '<tr'.$css_class.'>
7599: <td rowspan="2">
7600: <span class="LC_nobreak">'.
7601: &mt('[_1] when busy, offloads to:'
7602: ,'<b>'.$server.'</b>').'</span><br />'.
7603: '<span class="LC_nobreak">'."\n".
7604: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
7605: ' '.&mt('Switch any active user on next access').'</label></span>'.
7606: "\n";
7607: if ($other_insts) {
7608: $datatable .= '<br />'.
7609: '<span class="LC_nobreak">'."\n".
7610: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7611: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7612: "\n";
7613: }
7614: my (%current,%canselect);
7615: my @choices =
7616: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7617: foreach my $type ('primary','default') {
7618: if (ref($spareid->{$server}) eq 'HASH') {
7619: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7620: my @spares = @{$spareid->{$server}{$type}};
7621: if (@spares > 0) {
7622: if ($othercontrol) {
7623: $current{$type} = join(', ',@spares);
7624: } else {
7625: $current{$type} .= '<table>';
7626: my $numspares = scalar(@spares);
7627: for (my $i=0; $i<@spares; $i++) {
7628: my $rem = $i%($numinrow);
7629: if ($rem == 0) {
7630: if ($i > 0) {
7631: $current{$type} .= '</tr>';
7632: }
7633: $current{$type} .= '<tr>';
7634: }
7635: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
7636: $spareid->{$server}{$type}[$i].
7637: '</label></td>'."\n";
7638: }
7639: my $rem = @spares%($numinrow);
7640: my $colsleft = $numinrow - $rem;
7641: if ($colsleft > 1 ) {
7642: $current{$type} .= '<td colspan="'.$colsleft.
7643: '" class="LC_left_item">'.
7644: ' </td>';
7645: } elsif ($colsleft == 1) {
7646: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
7647: }
7648: $current{$type} .= '</tr></table>';
7649: }
7650: }
7651: }
7652: if ($current{$type} eq '') {
7653: $current{$type} = &mt('None specified');
7654: }
7655: if ($othercontrol) {
7656: if ($type eq 'primary') {
7657: $canselect{$type} = $othercontrol;
7658: }
7659: } else {
7660: $canselect{$type} =
7661: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7662: '<select name="newspare_'.$type.'_'.$server.'" '.
7663: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7664: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7665: if (@choices > 0) {
7666: foreach my $lonhost (@choices) {
7667: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7668: }
7669: }
7670: $canselect{$type} .= '</select>'."\n";
7671: }
7672: } else {
7673: $current{$type} = &mt('Could not be determined');
7674: if ($type eq 'primary') {
7675: $canselect{$type} = $othercontrol;
7676: }
7677: }
7678: if ($type eq 'default') {
7679: $datatable .= '<tr'.$css_class.'>';
7680: }
7681: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7682: '<td>'.$current{$type}.'</td>'."\n".
7683: '<td>'.$canselect{$type}.'</td></tr>'."\n";
7684: }
7685: $itemcount ++;
7686: }
7687: }
7688: $$rowtotal += $itemcount;
7689: return $datatable;
7690: }
7691:
7692: sub possible_newspares {
7693: my ($server,$currspares,$serverhomes,$altids) = @_;
7694: my $serverhostname = &Apache::lonnet::hostname($server);
7695: my %excluded;
7696: if ($serverhostname ne '') {
7697: %excluded = (
7698: $serverhostname => 1,
7699: );
7700: }
7701: if (ref($currspares) eq 'HASH') {
7702: foreach my $type (keys(%{$currspares})) {
7703: if (ref($currspares->{$type}) eq 'ARRAY') {
7704: if (@{$currspares->{$type}} > 0) {
7705: foreach my $curr (@{$currspares->{$type}}) {
7706: my $hostname = &Apache::lonnet::hostname($curr);
7707: $excluded{$hostname} = 1;
7708: }
7709: }
7710: }
7711: }
7712: }
7713: my @choices;
7714: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7715: if (keys(%{$serverhomes}) > 1) {
7716: foreach my $name (sort(keys(%{$serverhomes}))) {
7717: unless ($excluded{$name}) {
7718: if (exists($altids->{$serverhomes->{$name}})) {
7719: push(@choices,$altids->{$serverhomes->{$name}});
7720: } else {
7721: push(@choices,$serverhomes->{$name});
7722: }
7723: }
7724: }
7725: }
7726: }
7727: return sort(@choices);
7728: }
7729:
7730: sub print_loadbalancing {
7731: my ($dom,$settings,$rowtotal) = @_;
7732: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7733: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7734: my $numinrow = 1;
7735: my $datatable;
7736: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7737: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
7738: if (ref($settings) eq 'HASH') {
7739: %existing = %{$settings};
7740: }
7741: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7742: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
7743: \%currtargets,\%currrules,\%currcookies);
7744: } else {
7745: return;
7746: }
7747: my ($othertitle,$usertypes,$types) =
7748: &Apache::loncommon::sorted_inst_types($dom);
7749: my $rownum = 8;
7750: if (ref($types) eq 'ARRAY') {
7751: $rownum += scalar(@{$types});
7752: }
7753: my @css_class = ('LC_odd_row','LC_even_row');
7754: my $balnum = 0;
7755: my $islast;
7756: my (@toshow,$disabledtext);
7757: if (keys(%currbalancer) > 0) {
7758: @toshow = sort(keys(%currbalancer));
7759: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7760: push(@toshow,'');
7761: }
7762: } else {
7763: @toshow = ('');
7764: $disabledtext = &mt('No existing load balancer');
7765: }
7766: foreach my $lonhost (@toshow) {
7767: if ($balnum == scalar(@toshow)-1) {
7768: $islast = 1;
7769: } else {
7770: $islast = 0;
7771: }
7772: my $cssidx = $balnum%2;
7773: my $targets_div_style = 'display: none';
7774: my $disabled_div_style = 'display: block';
7775: my $homedom_div_style = 'display: none';
7776: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
7777: '<td rowspan="'.$rownum.'" valign="top">'.
7778: '<p>';
7779: if ($lonhost eq '') {
7780: $datatable .= '<span class="LC_nobreak">';
7781: if (keys(%currbalancer) > 0) {
7782: $datatable .= &mt('Add balancer:');
7783: } else {
7784: $datatable .= &mt('Enable balancer:');
7785: }
7786: $datatable .= ' '.
7787: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7788: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7789: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7790: '<option value="" selected="selected">'.&mt('None').
7791: '</option>'."\n";
7792: foreach my $server (sort(keys(%servers))) {
7793: next if ($currbalancer{$server});
7794: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7795: }
7796: $datatable .=
7797: '</select>'."\n".
7798: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7799: } else {
7800: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7801: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7802: &mt('Stop balancing').'</label>'.
7803: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7804: $targets_div_style = 'display: block';
7805: $disabled_div_style = 'display: none';
7806: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7807: $homedom_div_style = 'display: block';
7808: }
7809: }
7810: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
7811: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7812: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7813: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7814: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7815: my @sparestypes = ('primary','default');
7816: my %typetitles = &sparestype_titles();
7817: my %hostherechecked = (
7818: no => ' checked="checked"',
7819: );
7820: my %balcookiechecked = (
7821: no => ' checked="checked"',
7822: );
7823: foreach my $sparetype (@sparestypes) {
7824: my $targettable;
7825: for (my $i=0; $i<$numspares; $i++) {
7826: my $checked;
7827: if (ref($currtargets{$lonhost}) eq 'HASH') {
7828: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7829: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7830: $checked = ' checked="checked"';
7831: }
7832: }
7833: }
7834: my ($chkboxval,$disabled);
7835: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7836: $chkboxval = $spares[$i];
7837: }
7838: if (exists($currbalancer{$spares[$i]})) {
7839: $disabled = ' disabled="disabled"';
7840: }
7841: $targettable .=
7842: '<td><span class="LC_nobreak"><label>'.
7843: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
7844: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
7845: '</span></label></span></td>';
7846: my $rem = $i%($numinrow);
7847: if ($rem == 0) {
7848: if (($i > 0) && ($i < $numspares-1)) {
7849: $targettable .= '</tr>';
7850: }
7851: if ($i < $numspares-1) {
7852: $targettable .= '<tr>';
7853: }
7854: }
7855: }
7856: if ($targettable ne '') {
7857: my $rem = $numspares%($numinrow);
7858: my $colsleft = $numinrow - $rem;
7859: if ($colsleft > 1 ) {
7860: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7861: ' </td>';
7862: } elsif ($colsleft == 1) {
7863: $targettable .= '<td class="LC_left_item"> </td>';
7864: }
7865: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7866: '<table><tr>'.$targettable.'</tr></table><br />';
7867: }
7868: $hostherechecked{$sparetype} = '';
7869: if (ref($currtargets{$lonhost}) eq 'HASH') {
7870: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7871: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7872: $hostherechecked{$sparetype} = ' checked="checked"';
7873: $hostherechecked{'no'} = '';
7874: }
7875: }
7876: }
7877: }
7878: if ($currcookies{$lonhost}) {
7879: %balcookiechecked = (
7880: yes => ' checked="checked"',
7881: );
7882: }
7883: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7884: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7885: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7886: foreach my $sparetype (@sparestypes) {
7887: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7888: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7889: '</i></label><br />';
7890: }
7891: $datatable .= &mt('Use balancer cookie').'<br />'.
7892: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7893: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7894: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7895: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7896: '</div></td></tr>'.
7897: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7898: $othertitle,$usertypes,$types,\%servers,
7899: \%currbalancer,$lonhost,
7900: $targets_div_style,$homedom_div_style,
7901: $css_class[$cssidx],$balnum,$islast);
7902: $$rowtotal += $rownum;
7903: $balnum ++;
7904: }
7905: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7906: return $datatable;
7907: }
7908:
7909: sub get_loadbalancers_config {
7910: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
7911: return unless ((ref($servers) eq 'HASH') &&
7912: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
7913: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7914: (ref($currcookies) eq 'HASH'));
7915: if (keys(%{$existing}) > 0) {
7916: my $oldlonhost;
7917: foreach my $key (sort(keys(%{$existing}))) {
7918: if ($key eq 'lonhost') {
7919: $oldlonhost = $existing->{'lonhost'};
7920: $currbalancer->{$oldlonhost} = 1;
7921: } elsif ($key eq 'targets') {
7922: if ($oldlonhost) {
7923: $currtargets->{$oldlonhost} = $existing->{'targets'};
7924: }
7925: } elsif ($key eq 'rules') {
7926: if ($oldlonhost) {
7927: $currrules->{$oldlonhost} = $existing->{'rules'};
7928: }
7929: } elsif (ref($existing->{$key}) eq 'HASH') {
7930: $currbalancer->{$key} = 1;
7931: $currtargets->{$key} = $existing->{$key}{'targets'};
7932: $currrules->{$key} = $existing->{$key}{'rules'};
7933: if ($existing->{$key}{'cookie'}) {
7934: $currcookies->{$key} = 1;
7935: }
7936: }
7937: }
7938: } else {
7939: my ($balancerref,$targetsref) =
7940: &Apache::lonnet::get_lonbalancer_config($servers);
7941: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7942: foreach my $server (sort(keys(%{$balancerref}))) {
7943: $currbalancer->{$server} = 1;
7944: $currtargets->{$server} = $targetsref->{$server};
7945: }
7946: }
7947: }
7948: return;
7949: }
7950:
7951: sub loadbalancing_rules {
7952: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
7953: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7954: $css_class,$balnum,$islast) = @_;
7955: my $output;
7956: my $num = 0;
7957: my ($alltypes,$othertypes,$titles) =
7958: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7959: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7960: foreach my $type (@{$alltypes}) {
7961: $num ++;
7962: my $current;
7963: if (ref($currrules) eq 'HASH') {
7964: $current = $currrules->{$type};
7965: }
7966: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
7967: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
7968: $current = '';
7969: }
7970: }
7971: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
7972: $servers,$currbalancer,$lonhost,$dom,
7973: $targets_div_style,$homedom_div_style,
7974: $css_class,$balnum,$num,$islast);
7975: }
7976: }
7977: return $output;
7978: }
7979:
7980: sub loadbalancing_titles {
7981: my ($dom,$intdom,$usertypes,$types) = @_;
7982: my %othertypes = (
7983: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7984: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7985: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7986: '_LC_external' => &mt('Users not from [_1]',$intdom),
7987: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7988: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
7989: );
7990: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
7991: my @available;
7992: if (ref($types) eq 'ARRAY') {
7993: @available = @{$types};
7994: }
7995: unless (grep(/^default$/,@available)) {
7996: push(@available,'default');
7997: }
7998: unshift(@alltypes,@available);
7999: my %titles;
8000: foreach my $type (@alltypes) {
8001: if ($type =~ /^_LC_/) {
8002: $titles{$type} = $othertypes{$type};
8003: } elsif ($type eq 'default') {
8004: $titles{$type} = &mt('All users from [_1]',$dom);
8005: if (ref($types) eq 'ARRAY') {
8006: if (@{$types} > 0) {
8007: $titles{$type} = &mt('Other users from [_1]',$dom);
8008: }
8009: }
8010: } elsif (ref($usertypes) eq 'HASH') {
8011: $titles{$type} = $usertypes->{$type};
8012: }
8013: }
8014: return (\@alltypes,\%othertypes,\%titles);
8015: }
8016:
8017: sub loadbalance_rule_row {
8018: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8019: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
8020: my @rulenames;
8021: my %ruletitles = &offloadtype_text();
8022: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
8023: @rulenames = ('balancer','offloadedto','specific');
8024: } else {
8025: @rulenames = ('default','homeserver');
8026: if ($type eq '_LC_external') {
8027: push(@rulenames,'externalbalancer');
8028: } else {
8029: push(@rulenames,'specific');
8030: }
8031: push(@rulenames,'none');
8032: }
8033: my $style = $targets_div_style;
8034: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
8035: $style = $homedom_div_style;
8036: }
8037: my $space;
8038: if ($islast && $num == 1) {
8039: $space = '<div style="display:inline-block;"> </div>';
8040: }
8041: my $output =
8042: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
8043: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8044: '<td valaign="top">'.$space.
8045: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
8046: for (my $i=0; $i<@rulenames; $i++) {
8047: my $rule = $rulenames[$i];
8048: my ($checked,$extra);
8049: if ($rulenames[$i] eq 'default') {
8050: $rule = '';
8051: }
8052: if ($rulenames[$i] eq 'specific') {
8053: if (ref($servers) eq 'HASH') {
8054: my $default;
8055: if (($current ne '') && (exists($servers->{$current}))) {
8056: $checked = ' checked="checked"';
8057: }
8058: unless ($checked) {
8059: $default = ' selected="selected"';
8060: }
8061: $extra =
8062: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8063: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8064: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8065: '<option value=""'.$default.'></option>'."\n";
8066: foreach my $server (sort(keys(%{$servers}))) {
8067: if (ref($currbalancer) eq 'HASH') {
8068: next if (exists($currbalancer->{$server}));
8069: }
8070: my $selected;
8071: if ($server eq $current) {
8072: $selected = ' selected="selected"';
8073: }
8074: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
8075: }
8076: $extra .= '</select>';
8077: }
8078: } elsif ($rule eq $current) {
8079: $checked = ' checked="checked"';
8080: }
8081: $output .= '<span class="LC_nobreak"><label>'.
8082: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8083: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8084: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
8085: ')"'.$checked.' /> ';
8086: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
8087: $output .= $ruletitles{'particular'};
8088: } else {
8089: $output .= $ruletitles{$rulenames[$i]};
8090: }
8091: $output .= '</label>'.$extra.'</span><br />'."\n";
8092: }
8093: $output .= '</div></td></tr>'."\n";
8094: return $output;
8095: }
8096:
8097: sub offloadtype_text {
8098: my %ruletitles = &Apache::lonlocal::texthash (
8099: 'default' => 'Offloads to default destinations',
8100: 'homeserver' => "Offloads to user's home server",
8101: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8102: 'specific' => 'Offloads to specific server',
8103: 'none' => 'No offload',
8104: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8105: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
8106: 'particular' => 'Session hosted (after re-auth) on server:',
8107: );
8108: return %ruletitles;
8109: }
8110:
8111: sub sparestype_titles {
8112: my %typestitles = &Apache::lonlocal::texthash (
8113: 'primary' => 'primary',
8114: 'default' => 'default',
8115: );
8116: return %typestitles;
8117: }
8118:
8119: sub contact_titles {
8120: my %titles = &Apache::lonlocal::texthash (
8121: 'supportemail' => 'Support E-mail address',
8122: 'adminemail' => 'Default Server Admin E-mail address',
8123: 'errormail' => 'Error reports to be e-mailed to',
8124: 'packagesmail' => 'Package update alerts to be e-mailed to',
8125: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8126: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
8127: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8128: 'requestsmail' => 'E-mail from course requests requiring approval',
8129: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
8130: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
8131: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
8132: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8133: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
8134: 'errorweights' => 'Weights used to compute error count',
8135: 'errorexcluded' => 'Servers with unsent updates excluded from count',
8136: );
8137: my %short_titles = &Apache::lonlocal::texthash (
8138: adminemail => 'Admin E-mail address',
8139: supportemail => 'Support E-mail',
8140: );
8141: return (\%titles,\%short_titles);
8142: }
8143:
8144: sub helpform_fields {
8145: my %titles = &Apache::lonlocal::texthash (
8146: 'username' => 'Name',
8147: 'user' => 'Username/domain',
8148: 'phone' => 'Phone',
8149: 'cc' => 'Cc e-mail',
8150: 'course' => 'Course Details',
8151: 'section' => 'Sections',
8152: 'screenshot' => 'File upload',
8153: );
8154: my @fields = ('username','phone','user','course','section','cc','screenshot');
8155: my %possoptions = (
8156: username => ['yes','no','req'],
8157: phone => ['yes','no','req'],
8158: user => ['yes','no'],
8159: cc => ['yes','no'],
8160: course => ['yes','no'],
8161: section => ['yes','no'],
8162: screenshot => ['yes','no'],
8163: );
8164: my %fieldoptions = &Apache::lonlocal::texthash (
8165: 'yes' => 'Optional',
8166: 'req' => 'Required',
8167: 'no' => "Not shown",
8168: );
8169: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8170: }
8171:
8172: sub tool_titles {
8173: my %titles = &Apache::lonlocal::texthash (
8174: aboutme => 'Personal web page',
8175: blog => 'Blog',
8176: webdav => 'WebDAV',
8177: portfolio => 'Portfolio',
8178: timezone => 'Can set time zone',
8179: official => 'Official courses (with institutional codes)',
8180: unofficial => 'Unofficial courses',
8181: community => 'Communities',
8182: textbook => 'Textbook courses',
8183: );
8184: return %titles;
8185: }
8186:
8187: sub courserequest_titles {
8188: my %titles = &Apache::lonlocal::texthash (
8189: official => 'Official',
8190: unofficial => 'Unofficial',
8191: community => 'Communities',
8192: textbook => 'Textbook',
8193: lti => 'LTI Provider',
8194: norequest => 'Not allowed',
8195: approval => 'Approval by Dom. Coord.',
8196: validate => 'With validation',
8197: autolimit => 'Numerical limit',
8198: unlimited => '(blank for unlimited)',
8199: );
8200: return %titles;
8201: }
8202:
8203: sub authorrequest_titles {
8204: my %titles = &Apache::lonlocal::texthash (
8205: norequest => 'Not allowed',
8206: approval => 'Approval by Dom. Coord.',
8207: automatic => 'Automatic approval',
8208: );
8209: return %titles;
8210: }
8211:
8212: sub courserequest_conditions {
8213: my %conditions = &Apache::lonlocal::texthash (
8214: approval => '(Processing of request subject to approval by Domain Coordinator).',
8215: validate => '(Processing of request subject to institutional validation).',
8216: );
8217: return %conditions;
8218: }
8219:
8220:
8221: sub print_usercreation {
8222: my ($position,$dom,$settings,$rowtotal) = @_;
8223: my $numinrow = 4;
8224: my $datatable;
8225: if ($position eq 'top') {
8226: $$rowtotal ++;
8227: my $rowcount = 0;
8228: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
8229: if (ref($rules) eq 'HASH') {
8230: if (keys(%{$rules}) > 0) {
8231: $datatable .= &user_formats_row('username',$settings,$rules,
8232: $ruleorder,$numinrow,$rowcount);
8233: $$rowtotal ++;
8234: $rowcount ++;
8235: }
8236: }
8237: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8238: if (ref($idrules) eq 'HASH') {
8239: if (keys(%{$idrules}) > 0) {
8240: $datatable .= &user_formats_row('id',$settings,$idrules,
8241: $idruleorder,$numinrow,$rowcount);
8242: $$rowtotal ++;
8243: $rowcount ++;
8244: }
8245: }
8246: if ($rowcount == 0) {
8247: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8248: $$rowtotal ++;
8249: $rowcount ++;
8250: }
8251: } elsif ($position eq 'middle') {
8252: my @creators = ('author','course','requestcrs');
8253: my ($rules,$ruleorder) =
8254: &Apache::lonnet::inst_userrules($dom,'username');
8255: my %lt = &usercreation_types();
8256: my %checked;
8257: if (ref($settings) eq 'HASH') {
8258: if (ref($settings->{'cancreate'}) eq 'HASH') {
8259: foreach my $item (@creators) {
8260: $checked{$item} = $settings->{'cancreate'}{$item};
8261: }
8262: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8263: foreach my $item (@creators) {
8264: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8265: $checked{$item} = 'none';
8266: }
8267: }
8268: }
8269: }
8270: my $rownum = 0;
8271: foreach my $item (@creators) {
8272: $rownum ++;
8273: if ($checked{$item} eq '') {
8274: $checked{$item} = 'any';
8275: }
8276: my $css_class;
8277: if ($rownum%2) {
8278: $css_class = '';
8279: } else {
8280: $css_class = ' class="LC_odd_row" ';
8281: }
8282: $datatable .= '<tr'.$css_class.'>'.
8283: '<td><span class="LC_nobreak">'.$lt{$item}.
8284: '</span></td><td align="right">';
8285: my @options = ('any');
8286: if (ref($rules) eq 'HASH') {
8287: if (keys(%{$rules}) > 0) {
8288: push(@options,('official','unofficial'));
8289: }
8290: }
8291: push(@options,'none');
8292: foreach my $option (@options) {
8293: my $type = 'radio';
8294: my $check = ' ';
8295: if ($checked{$item} eq $option) {
8296: $check = ' checked="checked" ';
8297: }
8298: $datatable .= '<span class="LC_nobreak"><label>'.
8299: '<input type="'.$type.'" name="can_createuser_'.
8300: $item.'" value="'.$option.'"'.$check.'/> '.
8301: $lt{$option}.'</label> </span>';
8302: }
8303: $datatable .= '</td></tr>';
8304: }
8305: } else {
8306: my @contexts = ('author','course','domain');
8307: my @authtypes = ('int','krb4','krb5','loc','lti');
8308: my %checked;
8309: if (ref($settings) eq 'HASH') {
8310: if (ref($settings->{'authtypes'}) eq 'HASH') {
8311: foreach my $item (@contexts) {
8312: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8313: foreach my $auth (@authtypes) {
8314: if ($settings->{'authtypes'}{$item}{$auth}) {
8315: $checked{$item}{$auth} = ' checked="checked" ';
8316: }
8317: }
8318: }
8319: }
8320: }
8321: } else {
8322: foreach my $item (@contexts) {
8323: foreach my $auth (@authtypes) {
8324: $checked{$item}{$auth} = ' checked="checked" ';
8325: }
8326: }
8327: }
8328: my %title = &context_names();
8329: my %authname = &authtype_names();
8330: my $rownum = 0;
8331: my $css_class;
8332: foreach my $item (@contexts) {
8333: if ($rownum%2) {
8334: $css_class = '';
8335: } else {
8336: $css_class = ' class="LC_odd_row" ';
8337: }
8338: $datatable .= '<tr'.$css_class.'>'.
8339: '<td>'.$title{$item}.
8340: '</td><td class="LC_left_item">'.
8341: '<span class="LC_nobreak">';
8342: foreach my $auth (@authtypes) {
8343: $datatable .= '<label>'.
8344: '<input type="checkbox" name="'.$item.'_auth" '.
8345: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8346: $authname{$auth}.'</label> ';
8347: }
8348: $datatable .= '</span></td></tr>';
8349: $rownum ++;
8350: }
8351: $$rowtotal += $rownum;
8352: }
8353: return $datatable;
8354: }
8355:
8356: sub print_selfcreation {
8357: my ($position,$dom,$settings,$rowtotal) = @_;
8358: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8359: $emaildomain,$datatable);
8360: if (ref($settings) eq 'HASH') {
8361: if (ref($settings->{'cancreate'}) eq 'HASH') {
8362: $createsettings = $settings->{'cancreate'};
8363: if (ref($createsettings) eq 'HASH') {
8364: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8365: @selfcreate = @{$createsettings->{'selfcreate'}};
8366: } elsif ($createsettings->{'selfcreate'} ne '') {
8367: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8368: @selfcreate = ('email','login','sso');
8369: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8370: @selfcreate = ($createsettings->{'selfcreate'});
8371: }
8372: }
8373: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8374: $processing = $createsettings->{'selfcreateprocessing'};
8375: }
8376: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8377: $emailoptions = $createsettings->{'emailoptions'};
8378: }
8379: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8380: $emailverified = $createsettings->{'emailverified'};
8381: }
8382: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8383: $emaildomain = $createsettings->{'emaildomain'};
8384: }
8385: }
8386: }
8387: }
8388: my %radiohash;
8389: my $numinrow = 4;
8390: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
8391: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8392: if ($position eq 'top') {
8393: my %choices = &Apache::lonlocal::texthash (
8394: cancreate_login => 'Institutional Login',
8395: cancreate_sso => 'Institutional Single Sign On',
8396: );
8397: my @toggles = sort(keys(%choices));
8398: my %defaultchecked = (
8399: 'cancreate_login' => 'off',
8400: 'cancreate_sso' => 'off',
8401: );
8402: my ($onclick,$itemcount);
8403: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8404: \%choices,$itemcount,$onclick);
8405: $$rowtotal += $itemcount;
8406:
8407: if (ref($usertypes) eq 'HASH') {
8408: if (keys(%{$usertypes}) > 0) {
8409: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8410: $dom,$numinrow,$othertitle,
8411: 'statustocreate',$rowtotal);
8412: $$rowtotal ++;
8413: }
8414: }
8415: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8416: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8417: $fieldtitles{'inststatus'} = &mt('Institutional status');
8418: my $rem;
8419: my $numperrow = 2;
8420: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8421: $datatable .= '<tr'.$css_class.'>'.
8422: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
8423: '<td class="LC_left_item">'."\n".
8424: '<table>'."\n";
8425: for (my $i=0; $i<@fields; $i++) {
8426: $rem = $i%($numperrow);
8427: if ($rem == 0) {
8428: if ($i > 0) {
8429: $datatable .= '</tr>';
8430: }
8431: $datatable .= '<tr>';
8432: }
8433: my $currval;
8434: if (ref($createsettings) eq 'HASH') {
8435: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8436: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8437: }
8438: }
8439: $datatable .= '<td class="LC_left_item">'.
8440: '<span class="LC_nobreak">'.
8441: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8442: 'value="'.$currval.'" size="10" /> '.
8443: $fieldtitles{$fields[$i]}.'</span></td>';
8444: }
8445: my $colsleft = $numperrow - $rem;
8446: if ($colsleft > 1 ) {
8447: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8448: ' </td>';
8449: } elsif ($colsleft == 1) {
8450: $datatable .= '<td class="LC_left_item"> </td>';
8451: }
8452: $datatable .= '</tr></table></td></tr>';
8453: $$rowtotal ++;
8454: } elsif ($position eq 'middle') {
8455: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
8456: my @posstypes;
8457: if (ref($types) eq 'ARRAY') {
8458: @posstypes = @{$types};
8459: }
8460: unless (grep(/^default$/,@posstypes)) {
8461: push(@posstypes,'default');
8462: }
8463: my %usertypeshash;
8464: if (ref($usertypes) eq 'HASH') {
8465: %usertypeshash = %{$usertypes};
8466: }
8467: $usertypeshash{'default'} = $othertitle;
8468: foreach my $status (@posstypes) {
8469: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8470: $numinrow,$$rowtotal,\%usertypeshash);
8471: $$rowtotal ++;
8472: }
8473: } else {
8474: my %choices = &Apache::lonlocal::texthash (
8475: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
8476: );
8477: my @toggles = sort(keys(%choices));
8478: my %defaultchecked = (
8479: 'cancreate_email' => 'off',
8480: );
8481: my $customclass = 'LC_selfcreate_email';
8482: my $classprefix = 'LC_canmodify_emailusername_';
8483: my $optionsprefix = 'LC_options_emailusername_';
8484: my $display = 'none';
8485: my $rowstyle = 'display:none';
8486: if (grep(/^\Qemail\E$/,@selfcreate)) {
8487: $display = 'block';
8488: $rowstyle = 'display:table-row';
8489: }
8490: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8491: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8492: \%choices,$$rowtotal,$onclick);
8493: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8494: $rowstyle);
8495: $$rowtotal ++;
8496: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8497: $rowstyle);
8498: $$rowtotal ++;
8499: my (@ordered,@posstypes,%usertypeshash);
8500: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8501: my ($emailrules,$emailruleorder) =
8502: &Apache::lonnet::inst_userrules($dom,'email');
8503: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8504: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8505: if (ref($types) eq 'ARRAY') {
8506: @posstypes = @{$types};
8507: }
8508: if (@posstypes) {
8509: unless (grep(/^default$/,@posstypes)) {
8510: push(@posstypes,'default');
8511: }
8512: if (ref($usertypes) eq 'HASH') {
8513: %usertypeshash = %{$usertypes};
8514: }
8515: my $currassign;
8516: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8517: $currassign = {
8518: selfassign => $domdefaults{'inststatusguest'},
8519: };
8520: @ordered = @{$domdefaults{'inststatusguest'}};
8521: } else {
8522: $currassign = { selfassign => [] };
8523: }
8524: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8525: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8526: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8527: $numinrow,$othertitle,'selfassign',
8528: $rowtotal,$onclicktypes,$customclass,
8529: $rowstyle);
8530: $$rowtotal ++;
8531: $usertypeshash{'default'} = $othertitle;
8532: foreach my $status (@posstypes) {
8533: my $css_class;
8534: if ($$rowtotal%2) {
8535: $css_class = 'LC_odd_row ';
8536: }
8537: $css_class .= $customclass;
8538: my $rowid = $optionsprefix.$status;
8539: my $hidden = 1;
8540: my $currstyle = 'display:none';
8541: if (grep(/^\Q$status\E$/,@ordered)) {
8542: $currstyle = $rowstyle;
8543: $hidden = 0;
8544: }
8545: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8546: $emailrules,$emailruleorder,$settings,$status,$rowid,
8547: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8548: unless ($hidden) {
8549: $$rowtotal ++;
8550: }
8551: }
8552: } else {
8553: my $css_class;
8554: if ($$rowtotal%2) {
8555: $css_class = 'LC_odd_row ';
8556: }
8557: $css_class .= $customclass;
8558: $usertypeshash{'default'} = $othertitle;
8559: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8560: $emailrules,$emailruleorder,$settings,'default','',
8561: $othertitle,$css_class,$rowstyle,$intdom);
8562: $$rowtotal ++;
8563: }
8564: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8565: $numinrow = 1;
8566: if (@posstypes) {
8567: foreach my $status (@posstypes) {
8568: my $rowid = $classprefix.$status;
8569: my $datarowstyle = 'display:none';
8570: if (grep(/^\Q$status\E$/,@ordered)) {
8571: $datarowstyle = $rowstyle;
8572: }
8573: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8574: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8575: $infotitles,$rowid,$customclass,$datarowstyle);
8576: unless ($datarowstyle eq 'display:none') {
8577: $$rowtotal ++;
8578: }
8579: }
8580: } else {
8581: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8582: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8583: $infotitles,'',$customclass,$rowstyle);
8584: }
8585: }
8586: return $datatable;
8587: }
8588:
8589: sub selfcreate_javascript {
8590: return <<"ENDSCRIPT";
8591:
8592: <script type="text/javascript">
8593: // <![CDATA[
8594:
8595: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8596: var x = document.getElementsByClassName(target);
8597: var insttypes = 0;
8598: var insttypeRegExp = new RegExp(prefix);
8599: if ((x.length != undefined) && (x.length > 0)) {
8600: if (form.elements[radio].length != undefined) {
8601: for (var i=0; i<form.elements[radio].length; i++) {
8602: if (form.elements[radio][i].checked) {
8603: if (form.elements[radio][i].value == 1) {
8604: for (var j=0; j<x.length; j++) {
8605: if (x[j].id == 'undefined') {
8606: x[j].style.display = 'table-row';
8607: } else if (insttypeRegExp.test(x[j].id)) {
8608: insttypes ++;
8609: } else {
8610: x[j].style.display = 'table-row';
8611: }
8612: }
8613: } else {
8614: for (var j=0; j<x.length; j++) {
8615: x[j].style.display = 'none';
8616: }
8617: }
8618: break;
8619: }
8620: }
8621: if (insttypes > 0) {
8622: toggleDataRow(form,checkbox,target,altprefix);
8623: toggleDataRow(form,checkbox,target,prefix,1);
8624: }
8625: }
8626: }
8627: return;
8628: }
8629:
8630: function toggleDataRow(form,checkbox,target,prefix,docount) {
8631: if (form.elements[checkbox].length != undefined) {
8632: var count = 0;
8633: if (docount) {
8634: for (var i=0; i<form.elements[checkbox].length; i++) {
8635: if (form.elements[checkbox][i].checked) {
8636: count ++;
8637: }
8638: }
8639: }
8640: for (var i=0; i<form.elements[checkbox].length; i++) {
8641: var type = form.elements[checkbox][i].value;
8642: if (document.getElementById(prefix+type)) {
8643: if (form.elements[checkbox][i].checked) {
8644: document.getElementById(prefix+type).style.display = 'table-row';
8645: if (count % 2 == 1) {
8646: document.getElementById(prefix+type).className = target+' LC_odd_row';
8647: } else {
8648: document.getElementById(prefix+type).className = target;
8649: }
8650: count ++;
8651: } else {
8652: document.getElementById(prefix+type).style.display = 'none';
8653: }
8654: }
8655: }
8656: }
8657: return;
8658: }
8659:
8660: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8661: var caller = radio+'_'+status;
8662: if (form.elements[caller].length != undefined) {
8663: for (var i=0; i<form.elements[caller].length; i++) {
8664: if (form.elements[caller][i].checked) {
8665: if (document.getElementById(altprefix+'_inst_'+status)) {
8666: var curr = form.elements[caller][i].value;
8667: if (prefix) {
8668: document.getElementById(prefix+'_'+status).style.display = 'none';
8669: }
8670: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8671: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8672: if (curr == 'custom') {
8673: if (prefix) {
8674: document.getElementById(prefix+'_'+status).style.display = 'inline';
8675: }
8676: } else if (curr == 'inst') {
8677: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8678: } else if (curr == 'noninst') {
8679: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
8680: }
8681: break;
8682: }
8683: }
8684: }
8685: }
8686: }
8687:
8688: // ]]>
8689: </script>
8690:
8691: ENDSCRIPT
8692: }
8693:
8694: sub noninst_users {
8695: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8696: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8697: my $class = 'LC_left_item';
8698: if ($css_class) {
8699: $css_class = ' class="'.$css_class.'"';
8700: }
8701: if ($rowid) {
8702: $rowid = ' id="'.$rowid.'"';
8703: }
8704: if ($rowstyle) {
8705: $rowstyle = ' style="'.$rowstyle.'"';
8706: }
8707: my ($output,$description);
8708: if ($type eq 'default') {
8709: $description = &mt('Requests for: [_1]',$typetitle);
8710: } else {
8711: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8712: }
8713: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8714: "<td>$description</td>\n".
8715: '<td class="'.$class.'" colspan="2">'.
8716: '<table><tr>';
8717: my %headers = &Apache::lonlocal::texthash(
8718: approve => 'Processing',
8719: email => 'E-mail',
8720: username => 'Username',
8721: );
8722: foreach my $item ('approve','email','username') {
8723: $output .= '<th>'.$headers{$item}.'</th>';
8724: }
8725: $output .= '</tr><tr>';
8726: foreach my $item ('approve','email','username') {
8727: $output .= '<td valign="top">';
8728: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8729: if ($item eq 'approve') {
8730: %choices = &Apache::lonlocal::texthash (
8731: automatic => 'Automatically approved',
8732: approval => 'Queued for approval',
8733: );
8734: @options = ('automatic','approval');
8735: $hashref = $processing;
8736: $defoption = 'automatic';
8737: $name = 'cancreate_emailprocess_'.$type;
8738: } elsif ($item eq 'email') {
8739: %choices = &Apache::lonlocal::texthash (
8740: any => 'Any e-mail',
8741: inst => 'Institutional only',
8742: noninst => 'Non-institutional only',
8743: custom => 'Custom restrictions',
8744: );
8745: @options = ('any','inst','noninst');
8746: my $showcustom;
8747: if (ref($emailrules) eq 'HASH') {
8748: if (keys(%{$emailrules}) > 0) {
8749: push(@options,'custom');
8750: $showcustom = 'cancreate_emailrule';
8751: if (ref($settings) eq 'HASH') {
8752: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8753: foreach my $rule (@{$settings->{'email_rule'}}) {
8754: if (exists($emailrules->{$rule})) {
8755: $hascustom ++;
8756: }
8757: }
8758: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8759: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8760: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8761: if (exists($emailrules->{$rule})) {
8762: $hascustom ++;
8763: }
8764: }
8765: }
8766: }
8767: }
8768: }
8769: }
8770: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8771: "'cancreate_emaildomain','$type'".');"';
8772: $hashref = $emailoptions;
8773: $defoption = 'any';
8774: $name = 'cancreate_emailoptions_'.$type;
8775: } elsif ($item eq 'username') {
8776: %choices = &Apache::lonlocal::texthash (
8777: all => 'Same as e-mail',
8778: first => 'Omit @domain',
8779: free => 'Free to choose',
8780: );
8781: @options = ('all','first','free');
8782: $hashref = $emailverified;
8783: $defoption = 'all';
8784: $name = 'cancreate_usernameoptions_'.$type;
8785: }
8786: foreach my $option (@options) {
8787: my $checked;
8788: if (ref($hashref) eq 'HASH') {
8789: if ($type eq '') {
8790: if (!exists($hashref->{'default'})) {
8791: if ($option eq $defoption) {
8792: $checked = ' checked="checked"';
8793: }
8794: } else {
8795: if ($hashref->{'default'} eq $option) {
8796: $checked = ' checked="checked"';
8797: }
8798: }
8799: } else {
8800: if (!exists($hashref->{$type})) {
8801: if ($option eq $defoption) {
8802: $checked = ' checked="checked"';
8803: }
8804: } else {
8805: if ($hashref->{$type} eq $option) {
8806: $checked = ' checked="checked"';
8807: }
8808: }
8809: }
8810: } elsif (($item eq 'email') && ($hascustom)) {
8811: if ($option eq 'custom') {
8812: $checked = ' checked="checked"';
8813: }
8814: } elsif ($option eq $defoption) {
8815: $checked = ' checked="checked"';
8816: }
8817: $output .= '<span class="LC_nobreak"><label>'.
8818: '<input type="radio" name="'.$name.'"'.
8819: $checked.' value="'.$option.'"'.$onclick.' />'.
8820: $choices{$option}.'</label></span><br />';
8821: if ($item eq 'email') {
8822: if ($option eq 'custom') {
8823: my $id = 'cancreate_emailrule_'.$type;
8824: my $display = 'none';
8825: if ($checked) {
8826: $display = 'inline';
8827: }
8828: my $numinrow = 2;
8829: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8830: '<legend>'.&mt('Disallow').'</legend><table>'.
8831: &user_formats_row('email',$settings,$emailrules,
8832: $emailruleorder,$numinrow,'',$type);
8833: '</table></fieldset>';
8834: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8835: my %text = &Apache::lonlocal::texthash (
8836: inst => 'must end:',
8837: noninst => 'cannot end:',
8838: );
8839: my $value;
8840: if (ref($emaildomain) eq 'HASH') {
8841: if (ref($emaildomain->{$type}) eq 'HASH') {
8842: $value = $emaildomain->{$type}->{$option};
8843: }
8844: }
8845: if ($value eq '') {
8846: $value = '@'.$intdom;
8847: }
8848: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8849: my $display = 'none';
8850: if ($checked) {
8851: $display = 'inline';
8852: }
8853: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8854: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8855: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8856: '</div>';
8857: }
8858: }
8859: }
8860: $output .= '</td>'."\n";
8861: }
8862: $output .= "</tr></table></td></tr>\n";
8863: return $output;
8864: }
8865:
8866: sub captcha_choice {
8867: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
8868: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
8869: $vertext,$currver);
8870: my %lt = &captcha_phrases();
8871: $keyentry = 'hidden';
8872: my $colspan=2;
8873: if ($context eq 'cancreate') {
8874: $rowname = &mt('CAPTCHA validation');
8875: } elsif ($context eq 'login') {
8876: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
8877: } elsif ($context eq 'passwords') {
8878: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8879: $colspan=1;
8880: }
8881: if (ref($settings) eq 'HASH') {
8882: if ($settings->{'captcha'}) {
8883: $checked{$settings->{'captcha'}} = ' checked="checked"';
8884: } else {
8885: $checked{'original'} = ' checked="checked"';
8886: }
8887: if ($settings->{'captcha'} eq 'recaptcha') {
8888: $pubtext = $lt{'pub'};
8889: $privtext = $lt{'priv'};
8890: $keyentry = 'text';
8891: $vertext = $lt{'ver'};
8892: $currver = $settings->{'recaptchaversion'};
8893: if ($currver ne '2') {
8894: $currver = 1;
8895: }
8896: }
8897: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8898: $currpub = $settings->{'recaptchakeys'}{'public'};
8899: $currpriv = $settings->{'recaptchakeys'}{'private'};
8900: }
8901: } else {
8902: $checked{'original'} = ' checked="checked"';
8903: }
8904: my $css_class;
8905: if ($itemcount%2) {
8906: $css_class = 'LC_odd_row';
8907: }
8908: if ($customcss) {
8909: $css_class .= " $customcss";
8910: }
8911: $css_class =~ s/^\s+//;
8912: if ($css_class) {
8913: $css_class = ' class="'.$css_class.'"';
8914: }
8915: if ($rowstyle) {
8916: $css_class .= ' style="'.$rowstyle.'"';
8917: }
8918: my $output = '<tr'.$css_class.'>'.
8919: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
8920: '<table><tr><td>'."\n";
8921: foreach my $option ('original','recaptcha','notused') {
8922: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8923: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8924: $lt{$option}.'</label></span>';
8925: unless ($option eq 'notused') {
8926: $output .= (' 'x2)."\n";
8927: }
8928: }
8929: #
8930: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8931: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
8932: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
8933: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
8934: #
8935: $output .= '</td></tr>'."\n".
8936: '<tr><td class="LC_zero_height">'."\n".
8937: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8938: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8939: $currpub.'" size="40" /></span><br />'."\n".
8940: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8941: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
8942: $currpriv.'" size="40" /></span><br />'.
8943: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8944: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8945: $currver.'" size="3" /></span><br />'.
8946: '</td></tr></table>'."\n".
8947: '</td></tr>';
8948: return $output;
8949: }
8950:
8951: sub user_formats_row {
8952: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
8953: my $output;
8954: my %text = (
8955: 'username' => 'new usernames',
8956: 'id' => 'IDs',
8957: );
8958: unless (($type eq 'email') || ($type eq 'unamemap')) {
8959: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8960: $output = '<tr '.$css_class.'>'.
8961: '<td><span class="LC_nobreak">'.
8962: &mt("Format rules to check for $text{$type}: ").
8963: '</td><td class="LC_left_item" colspan="2"><table>';
8964: }
8965: my $rem;
8966: if (ref($ruleorder) eq 'ARRAY') {
8967: for (my $i=0; $i<@{$ruleorder}; $i++) {
8968: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8969: my $rem = $i%($numinrow);
8970: if ($rem == 0) {
8971: if ($i > 0) {
8972: $output .= '</tr>';
8973: }
8974: $output .= '<tr>';
8975: }
8976: my $check = ' ';
8977: if (ref($settings) eq 'HASH') {
8978: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8979: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8980: $check = ' checked="checked" ';
8981: }
8982: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8983: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8984: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8985: $check = ' checked="checked" ';
8986: }
8987: }
8988: }
8989: }
8990: my $name = $type.'_rule';
8991: if ($type eq 'email') {
8992: $name .= '_'.$status;
8993: }
8994: $output .= '<td class="LC_left_item">'.
8995: '<span class="LC_nobreak"><label>'.
8996: '<input type="checkbox" name="'.$name.'" '.
8997: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8998: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8999: }
9000: }
9001: $rem = @{$ruleorder}%($numinrow);
9002: }
9003: my $colsleft;
9004: if ($rem) {
9005: $colsleft = $numinrow - $rem;
9006: }
9007: if ($colsleft > 1 ) {
9008: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9009: ' </td>';
9010: } elsif ($colsleft == 1) {
9011: $output .= '<td class="LC_left_item"> </td>';
9012: }
9013: $output .= '</tr>';
9014: unless (($type eq 'email') || ($type eq 'unamemap')) {
9015: $output .= '</table></td></tr>';
9016: }
9017: return $output;
9018: }
9019:
9020: sub usercreation_types {
9021: my %lt = &Apache::lonlocal::texthash (
9022: author => 'When adding a co-author',
9023: course => 'When adding a user to a course',
9024: requestcrs => 'When requesting a course',
9025: any => 'Any',
9026: official => 'Institutional only ',
9027: unofficial => 'Non-institutional only',
9028: none => 'None',
9029: );
9030: return %lt;
9031: }
9032:
9033: sub selfcreation_types {
9034: my %lt = &Apache::lonlocal::texthash (
9035: selfcreate => 'User creates own account',
9036: any => 'Any',
9037: official => 'Institutional only ',
9038: unofficial => 'Non-institutional only',
9039: email => 'E-mail address',
9040: login => 'Institutional Login',
9041: sso => 'SSO',
9042: );
9043: }
9044:
9045: sub authtype_names {
9046: my %lt = &Apache::lonlocal::texthash(
9047: int => 'Internal',
9048: krb4 => 'Kerberos 4',
9049: krb5 => 'Kerberos 5',
9050: loc => 'Local',
9051: lti => 'LTI',
9052: );
9053: return %lt;
9054: }
9055:
9056: sub context_names {
9057: my %context_title = &Apache::lonlocal::texthash(
9058: author => 'Creating users when an Author',
9059: course => 'Creating users when in a course',
9060: domain => 'Creating users when a Domain Coordinator',
9061: );
9062: return %context_title;
9063: }
9064:
9065: sub print_usermodification {
9066: my ($position,$dom,$settings,$rowtotal) = @_;
9067: my $numinrow = 4;
9068: my ($context,$datatable,$rowcount);
9069: if ($position eq 'top') {
9070: $rowcount = 0;
9071: $context = 'author';
9072: foreach my $role ('ca','aa') {
9073: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9074: $numinrow,$rowcount);
9075: $$rowtotal ++;
9076: $rowcount ++;
9077: }
9078: } elsif ($position eq 'bottom') {
9079: $context = 'course';
9080: $rowcount = 0;
9081: foreach my $role ('st','ep','ta','in','cr') {
9082: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9083: $numinrow,$rowcount);
9084: $$rowtotal ++;
9085: $rowcount ++;
9086: }
9087: }
9088: return $datatable;
9089: }
9090:
9091: sub print_defaults {
9092: my ($position,$dom,$settings,$rowtotal) = @_;
9093: my $rownum = 0;
9094: my ($datatable,$css_class,$titles);
9095: unless ($position eq 'bottom') {
9096: $titles = &defaults_titles($dom);
9097: }
9098: if ($position eq 'top') {
9099: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9100: 'datelocale_def','portal_def');
9101: my %defaults;
9102: if (ref($settings) eq 'HASH') {
9103: %defaults = %{$settings};
9104: } else {
9105: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9106: foreach my $item (@items) {
9107: $defaults{$item} = $domdefaults{$item};
9108: }
9109: }
9110: foreach my $item (@items) {
9111: if ($rownum%2) {
9112: $css_class = '';
9113: } else {
9114: $css_class = ' class="LC_odd_row" ';
9115: }
9116: $datatable .= '<tr'.$css_class.'>'.
9117: '<td><span class="LC_nobreak">'.$titles->{$item}.
9118: '</span></td><td class="LC_right_item" colspan="3">';
9119: if ($item eq 'auth_def') {
9120: my @authtypes = ('internal','krb4','krb5','localauth','lti');
9121: my %shortauth = (
9122: internal => 'int',
9123: krb4 => 'krb4',
9124: krb5 => 'krb5',
9125: localauth => 'loc',
9126: lti => 'lti',
9127: );
9128: my %authnames = &authtype_names();
9129: foreach my $auth (@authtypes) {
9130: my $checked = ' ';
9131: if ($defaults{$item} eq $auth) {
9132: $checked = ' checked="checked" ';
9133: }
9134: $datatable .= '<label><input type="radio" name="'.$item.
9135: '" value="'.$auth.'"'.$checked.'/>'.
9136: $authnames{$shortauth{$auth}}.'</label> ';
9137: }
9138: } elsif ($item eq 'timezone_def') {
9139: my $includeempty = 1;
9140: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9141: } elsif ($item eq 'datelocale_def') {
9142: my $includeempty = 1;
9143: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9144: } elsif ($item eq 'lang_def') {
9145: my $includeempty = 1;
9146: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
9147: } elsif ($item eq 'portal_def') {
9148: $datatable .= '<input type="text" name="'.$item.'" value="'.
9149: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
9150: my $portalsty = 'none';
9151: if ($defaults{$item}) {
9152: $portalsty = 'block';
9153: }
9154: foreach my $field ('email','web') {
9155: my $checkedoff = ' checked="checked"';
9156: my $checkedon;
9157: if ($defaults{$item.'_'.$field}) {
9158: $checkedon = $checkedoff;
9159: $checkedoff = '';
9160: }
9161: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
9162: '<span class="LC_nobreak">'.$titles->{$field}.' '.
9163: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
9164: (' 'x2).
9165: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
9166: '</div>';
9167: }
9168: } else {
9169: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
9170: }
9171: $datatable .= '</td></tr>';
9172: $rownum ++;
9173: }
9174: } elsif ($position eq 'middle') {
9175: my %defaults;
9176: if (ref($settings) eq 'HASH') {
9177: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9178: my $maxnum = @{$settings->{'inststatusorder'}};
9179: for (my $i=0; $i<$maxnum; $i++) {
9180: $css_class = $rownum%2?' class="LC_odd_row"':'';
9181: my $item = $settings->{'inststatusorder'}->[$i];
9182: my $title = $settings->{'inststatustypes'}->{$item};
9183: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9184: $datatable .= '<tr'.$css_class.'>'.
9185: '<td><span class="LC_nobreak">'.
9186: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9187: for (my $k=0; $k<=$maxnum; $k++) {
9188: my $vpos = $k+1;
9189: my $selstr;
9190: if ($k == $i) {
9191: $selstr = ' selected="selected" ';
9192: }
9193: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9194: }
9195: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9196: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9197: &mt('delete').'</span></td>'.
9198: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
9199: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
9200: '</span></td></tr>';
9201: }
9202: $css_class = $rownum%2?' class="LC_odd_row"':'';
9203: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9204: $datatable .= '<tr '.$css_class.'>'.
9205: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9206: for (my $k=0; $k<=$maxnum; $k++) {
9207: my $vpos = $k+1;
9208: my $selstr;
9209: if ($k == $maxnum) {
9210: $selstr = ' selected="selected" ';
9211: }
9212: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9213: }
9214: $datatable .= '</select> '.&mt('Internal ID:').
9215: '<input type="text" size="10" name="addinststatus" value="" />'.
9216: ' '.&mt('(new)').
9217: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
9218: &mt('Name displayed').':'.
9219: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9220: '</tr>'."\n";
9221: $rownum ++;
9222: }
9223: }
9224: } else {
9225: my ($unamemaprules,$ruleorder) =
9226: &Apache::lonnet::inst_userrules($dom,'unamemap');
9227: $css_class = $rownum%2?' class="LC_odd_row"':'';
9228: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9229: my $numinrow = 2;
9230: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
9231: &user_formats_row('unamemap',$settings,$unamemaprules,
9232: $ruleorder,$numinrow).
9233: '</table></td></tr>';
9234: }
9235: if ($datatable eq '') {
9236: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
9237: &mt('No rules set for domain in customized localenroll.pm').
9238: '</td></tr>';
9239: }
9240: }
9241: $$rowtotal += $rownum;
9242: return $datatable;
9243: }
9244:
9245: sub get_languages_hash {
9246: my %langchoices;
9247: foreach my $id (&Apache::loncommon::languageids()) {
9248: my $code = &Apache::loncommon::supportedlanguagecode($id);
9249: if ($code ne '') {
9250: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9251: }
9252: }
9253: return %langchoices;
9254: }
9255:
9256: sub defaults_titles {
9257: my ($dom) = @_;
9258: my %titles = &Apache::lonlocal::texthash (
9259: 'auth_def' => 'Default authentication type',
9260: 'auth_arg_def' => 'Default authentication argument',
9261: 'lang_def' => 'Default language',
9262: 'timezone_def' => 'Default timezone',
9263: 'datelocale_def' => 'Default locale for dates',
9264: 'portal_def' => 'Portal/Default URL',
9265: 'email' => 'Email links use portal URL',
9266: 'web' => 'Public web links use portal URL',
9267: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9268: 'intauth_check' => 'Check bcrypt cost if authenticated',
9269: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
9270: );
9271: if ($dom) {
9272: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9273: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9274: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9275: $protocol = 'http' if ($protocol ne 'https');
9276: if ($uint_dom) {
9277: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9278: $uint_dom);
9279: }
9280: }
9281: return (\%titles);
9282: }
9283:
9284: sub print_scantron {
9285: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9286: if ($position eq 'top') {
9287: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9288: } else {
9289: return &print_scantronconfig($dom,$settings,\$rowtotal);
9290: }
9291: }
9292:
9293: sub scantron_javascript {
9294: return <<"ENDSCRIPT";
9295:
9296: <script type="text/javascript">
9297: // <![CDATA[
9298:
9299: function toggleScantron(form) {
9300: var csvfieldset = new Array();
9301: if (document.getElementById('scantroncsv_cols')) {
9302: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9303: }
9304: if (document.getElementById('scantroncsv_options')) {
9305: csvfieldset.push(document.getElementById('scantroncsv_options'));
9306: }
9307: if (csvfieldset.length) {
9308: if (document.getElementById('scantronconfcsv')) {
9309: var scantroncsv = document.getElementById('scantronconfcsv');
9310: if (scantroncsv.checked) {
9311: for (var i=0; i<csvfieldset.length; i++) {
9312: csvfieldset[i].style.display = 'block';
9313: }
9314: } else {
9315: for (var i=0; i<csvfieldset.length; i++) {
9316: csvfieldset[i].style.display = 'none';
9317: }
9318: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9319: if (csvselects.length) {
9320: for (var j=0; j<csvselects.length; j++) {
9321: csvselects[j].selectedIndex = 0;
9322: }
9323: }
9324: }
9325: }
9326: }
9327: return;
9328: }
9329: // ]]>
9330: </script>
9331:
9332: ENDSCRIPT
9333:
9334: }
9335:
9336: sub print_scantronformat {
9337: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9338: my $itemcount = 1;
9339: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9340: %confhash);
9341: my $switchserver = &check_switchserver($dom,$confname);
9342: my %lt = &Apache::lonlocal::texthash (
9343: default => 'Default bubblesheet format file error',
9344: custom => 'Custom bubblesheet format file error',
9345: );
9346: my %scantronfiles = (
9347: default => 'default.tab',
9348: custom => 'custom.tab',
9349: );
9350: foreach my $key (keys(%scantronfiles)) {
9351: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9352: .$scantronfiles{$key};
9353: }
9354: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9355: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9356: if (!$switchserver) {
9357: my $servadm = $r->dir_config('lonAdmEMail');
9358: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9359: if ($configuserok eq 'ok') {
9360: if ($author_ok eq 'ok') {
9361: my %legacyfile = (
9362: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9363: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
9364: );
9365: my %md5chk;
9366: foreach my $type (keys(%legacyfile)) {
9367: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9368: chomp($md5chk{$type});
9369: }
9370: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9371: foreach my $type (keys(%legacyfile)) {
9372: ($scantronurls{$type},my $error) =
9373: &legacy_scantronformat($r,$dom,$confname,
9374: $type,$legacyfile{$type},
9375: $scantronurls{$type},
9376: $scantronfiles{$type});
9377: if ($error ne '') {
9378: $error{$type} = $error;
9379: }
9380: }
9381: if (keys(%error) == 0) {
9382: $is_custom = 1;
9383: $confhash{'scantron'}{'scantronformat'} =
9384: $scantronurls{'custom'};
9385: my $putresult =
9386: &Apache::lonnet::put_dom('configuration',
9387: \%confhash,$dom);
9388: if ($putresult ne 'ok') {
9389: $error{'custom'} =
9390: '<span class="LC_error">'.
9391: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9392: }
9393: }
9394: } else {
9395: ($scantronurls{'default'},my $error) =
9396: &legacy_scantronformat($r,$dom,$confname,
9397: 'default',$legacyfile{'default'},
9398: $scantronurls{'default'},
9399: $scantronfiles{'default'});
9400: if ($error eq '') {
9401: $confhash{'scantron'}{'scantronformat'} = '';
9402: my $putresult =
9403: &Apache::lonnet::put_dom('configuration',
9404: \%confhash,$dom);
9405: if ($putresult ne 'ok') {
9406: $error{'default'} =
9407: '<span class="LC_error">'.
9408: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9409: }
9410: } else {
9411: $error{'default'} = $error;
9412: }
9413: }
9414: }
9415: }
9416: } else {
9417: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
9418: }
9419: }
9420: if (ref($settings) eq 'HASH') {
9421: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9422: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9423: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9424: $scantronurl = '';
9425: } else {
9426: $scantronurl = $settings->{'scantronformat'};
9427: }
9428: $is_custom = 1;
9429: } else {
9430: $scantronurl = $scantronurls{'default'};
9431: }
9432: } else {
9433: if ($is_custom) {
9434: $scantronurl = $scantronurls{'custom'};
9435: } else {
9436: $scantronurl = $scantronurls{'default'};
9437: }
9438: }
9439: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9440: $datatable .= '<tr'.$css_class.'>';
9441: if (!$is_custom) {
9442: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9443: '<span class="LC_nobreak">';
9444: if ($scantronurl) {
9445: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9446: undef,undef,undef,undef,'background-color:#ffffff');
9447: } else {
9448: $datatable = &mt('File unavailable for display');
9449: }
9450: $datatable .= '</span></td>';
9451: if (keys(%error) == 0) {
9452: $datatable .= '<td valign="bottom">';
9453: if (!$switchserver) {
9454: $datatable .= &mt('Upload:').'<br />';
9455: }
9456: } else {
9457: my $errorstr;
9458: foreach my $key (sort(keys(%error))) {
9459: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9460: }
9461: $datatable .= '<td>'.$errorstr;
9462: }
9463: } else {
9464: if (keys(%error) > 0) {
9465: my $errorstr;
9466: foreach my $key (sort(keys(%error))) {
9467: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9468: }
9469: $datatable .= '<td>'.$errorstr.'</td><td> ';
9470: } elsif ($scantronurl) {
9471: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
9472: undef,undef,undef,undef,'background-color:#ffffff');
9473: $datatable .= '<td><span class="LC_nobreak">'.
9474: $link.
9475: '<label><input type="checkbox" name="scantronformat_del"'.
9476: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
9477: '<td><span class="LC_nobreak"> '.
9478: &mt('Replace:').'</span><br />';
9479: }
9480: }
9481: if (keys(%error) == 0) {
9482: if ($switchserver) {
9483: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9484: } else {
9485: $datatable .='<span class="LC_nobreak"> '.
9486: '<input type="file" name="scantronformat" /></span>';
9487: }
9488: }
9489: $datatable .= '</td></tr>';
9490: $$rowtotal ++;
9491: return $datatable;
9492: }
9493:
9494: sub legacy_scantronformat {
9495: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9496: my ($url,$error);
9497: my @statinfo = &Apache::lonnet::stat_file($newurl);
9498: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
9499: my $modified = [];
9500: (my $result,$url) =
9501: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
9502: 'scantron','','',$newfile,$modified);
9503: if ($result eq 'ok') {
9504: &update_modify_urls($r,$modified);
9505: } else {
9506: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
9507: }
9508: }
9509: return ($url,$error);
9510: }
9511:
9512: sub print_scantronconfig {
9513: my ($dom,$settings,$rowtotal) = @_;
9514: my $itemcount = 2;
9515: my $is_checked = ' checked="checked"';
9516: my %optionson = (
9517: hdr => ' checked="checked"',
9518: pad => ' checked="checked"',
9519: rem => ' checked="checked"',
9520: );
9521: my %optionsoff = (
9522: hdr => '',
9523: pad => '',
9524: rem => '',
9525: );
9526: my $currcsvsty = 'none';
9527: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
9528: my @fields = &scantroncsv_fields();
9529: my %titles = &scantronconfig_titles();
9530: if (ref($settings) eq 'HASH') {
9531: if (ref($settings->{config}) eq 'HASH') {
9532: if ($settings->{config}->{dat}) {
9533: $checked{'dat'} = $is_checked;
9534: }
9535: if (ref($settings->{config}->{csv}) eq 'HASH') {
9536: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9537: %csvfields = %{$settings->{config}->{csv}->{fields}};
9538: if (keys(%csvfields) > 0) {
9539: $checked{'csv'} = $is_checked;
9540: $currcsvsty = 'block';
9541: }
9542: }
9543: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9544: %csvoptions = %{$settings->{config}->{csv}->{options}};
9545: foreach my $option (keys(%optionson)) {
9546: unless ($csvoptions{$option}) {
9547: $optionsoff{$option} = $optionson{$option};
9548: $optionson{$option} = '';
9549: }
9550: }
9551: }
9552: }
9553: } else {
9554: $checked{'dat'} = $is_checked;
9555: }
9556: } else {
9557: $checked{'dat'} = $is_checked;
9558: }
9559: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9560: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9561: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9562: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9563: foreach my $item ('dat','csv') {
9564: my $id;
9565: if ($item eq 'csv') {
9566: $id = 'id="scantronconfcsv" ';
9567: }
9568: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9569: $titles{$item}.'</label>'.(' 'x3);
9570: if ($item eq 'csv') {
9571: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9572: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9573: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9574: foreach my $col (@fields) {
9575: my $selnone;
9576: if ($csvfields{$col} eq '') {
9577: $selnone = ' selected="selected"';
9578: }
9579: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9580: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9581: '<option value=""'.$selnone.'></option>';
9582: for (my $i=0; $i<20; $i++) {
9583: my $shown = $i+1;
9584: my $sel;
9585: unless ($selnone) {
9586: if (exists($csvfields{$col})) {
9587: if ($csvfields{$col} == $i) {
9588: $sel = ' selected="selected"';
9589: }
9590: }
9591: }
9592: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9593: }
9594: $datatable .= '</select></td></tr>';
9595: }
9596: $datatable .= '</table></fieldset>'.
9597: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9598: '<legend>'.&mt('CSV Options').'</legend>';
9599: foreach my $option ('hdr','pad','rem') {
9600: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9601: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9602: &mt('Yes').'</label>'.(' 'x2)."\n".
9603: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9604: }
9605: $datatable .= '</fieldset>';
9606: $itemcount ++;
9607: }
9608: }
9609: $datatable .= '</td></tr>';
9610: $$rowtotal ++;
9611: return $datatable;
9612: }
9613:
9614: sub scantronconfig_titles {
9615: return &Apache::lonlocal::texthash(
9616: dat => 'Standard format (.dat)',
9617: csv => 'Comma separated values (.csv)',
9618: hdr => 'Remove first line in file (contains column titles)',
9619: pad => 'Prepend 0s to PaperID',
9620: rem => 'Remove leading spaces (except Question Response columns)',
9621: CODE => 'CODE',
9622: ID => 'Student ID',
9623: PaperID => 'Paper ID',
9624: FirstName => 'First Name',
9625: LastName => 'Last Name',
9626: FirstQuestion => 'First Question Response',
9627: Section => 'Section',
9628: );
9629: }
9630:
9631: sub scantroncsv_fields {
9632: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
9633: }
9634:
9635: sub print_coursecategories {
9636: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
9637: my $datatable;
9638: if ($position eq 'top') {
9639: my (%checked);
9640: my @catitems = ('unauth','auth');
9641: my @cattypes = ('std','domonly','codesrch','none');
9642: $checked{'unauth'} = 'std';
9643: $checked{'auth'} = 'std';
9644: if (ref($settings) eq 'HASH') {
9645: foreach my $type (@cattypes) {
9646: if ($type eq $settings->{'unauth'}) {
9647: $checked{'unauth'} = $type;
9648: }
9649: if ($type eq $settings->{'auth'}) {
9650: $checked{'auth'} = $type;
9651: }
9652: }
9653: }
9654: my %lt = &Apache::lonlocal::texthash (
9655: unauth => 'Catalog type for unauthenticated users',
9656: auth => 'Catalog type for authenticated users',
9657: none => 'No catalog',
9658: std => 'Standard catalog',
9659: domonly => 'Domain-only catalog',
9660: codesrch => "Code search form",
9661: );
9662: my $itemcount = 0;
9663: foreach my $item (@catitems) {
9664: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9665: $datatable .= '<tr '.$css_class.'>'.
9666: '<td>'.$lt{$item}.'</td>'.
9667: '<td class="LC_right_item"><span class="LC_nobreak">';
9668: foreach my $type (@cattypes) {
9669: my $ischecked;
9670: if ($checked{$item} eq $type) {
9671: $ischecked=' checked="checked"';
9672: }
9673: $datatable .= '<label>'.
9674: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9675: ' />'.$lt{$type}.'</label> ';
9676: }
9677: $datatable .= '</span></td></tr>';
9678: $itemcount ++;
9679: }
9680: $$rowtotal += $itemcount;
9681: } elsif ($position eq 'middle') {
9682: my $toggle_cats_crs = ' ';
9683: my $toggle_cats_dom = ' checked="checked" ';
9684: my $can_cat_crs = ' ';
9685: my $can_cat_dom = ' checked="checked" ';
9686: my $toggle_catscomm_comm = ' ';
9687: my $toggle_catscomm_dom = ' checked="checked" ';
9688: my $can_catcomm_comm = ' ';
9689: my $can_catcomm_dom = ' checked="checked" ';
9690:
9691: if (ref($settings) eq 'HASH') {
9692: if ($settings->{'togglecats'} eq 'crs') {
9693: $toggle_cats_crs = $toggle_cats_dom;
9694: $toggle_cats_dom = ' ';
9695: }
9696: if ($settings->{'categorize'} eq 'crs') {
9697: $can_cat_crs = $can_cat_dom;
9698: $can_cat_dom = ' ';
9699: }
9700: if ($settings->{'togglecatscomm'} eq 'comm') {
9701: $toggle_catscomm_comm = $toggle_catscomm_dom;
9702: $toggle_catscomm_dom = ' ';
9703: }
9704: if ($settings->{'categorizecomm'} eq 'comm') {
9705: $can_catcomm_comm = $can_catcomm_dom;
9706: $can_catcomm_dom = ' ';
9707: }
9708: }
9709: my %title = &Apache::lonlocal::texthash (
9710: togglecats => 'Show/Hide a course in catalog',
9711: togglecatscomm => 'Show/Hide a community in catalog',
9712: categorize => 'Assign a category to a course',
9713: categorizecomm => 'Assign a category to a community',
9714: );
9715: my %level = &Apache::lonlocal::texthash (
9716: dom => 'Set in Domain',
9717: crs => 'Set in Course',
9718: comm => 'Set in Community',
9719: );
9720: $datatable = '<tr class="LC_odd_row">'.
9721: '<td>'.$title{'togglecats'}.'</td>'.
9722: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9723: '<input type="radio" name="togglecats"'.
9724: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9725: '<label><input type="radio" name="togglecats"'.
9726: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9727: '</tr><tr>'.
9728: '<td>'.$title{'categorize'}.'</td>'.
9729: '<td class="LC_right_item"><span class="LC_nobreak">'.
9730: '<label><input type="radio" name="categorize"'.
9731: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9732: '<label><input type="radio" name="categorize"'.
9733: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
9734: '</tr><tr class="LC_odd_row">'.
9735: '<td>'.$title{'togglecatscomm'}.'</td>'.
9736: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9737: '<input type="radio" name="togglecatscomm"'.
9738: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9739: '<label><input type="radio" name="togglecatscomm"'.
9740: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9741: '</tr><tr>'.
9742: '<td>'.$title{'categorizecomm'}.'</td>'.
9743: '<td class="LC_right_item"><span class="LC_nobreak">'.
9744: '<label><input type="radio" name="categorizecomm"'.
9745: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9746: '<label><input type="radio" name="categorizecomm"'.
9747: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
9748: '</tr>';
9749: $$rowtotal += 4;
9750: } else {
9751: my $css_class;
9752: my $itemcount = 1;
9753: my $cathash;
9754: if (ref($settings) eq 'HASH') {
9755: $cathash = $settings->{'cats'};
9756: }
9757: if (ref($cathash) eq 'HASH') {
9758: my (@cats,@trails,%allitems,%idx,@jsarray);
9759: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9760: \%allitems,\%idx,\@jsarray);
9761: my $maxdepth = scalar(@cats);
9762: my $colattrib = '';
9763: if ($maxdepth > 2) {
9764: $colattrib = ' colspan="2" ';
9765: }
9766: my @path;
9767: if (@cats > 0) {
9768: if (ref($cats[0]) eq 'ARRAY') {
9769: my $numtop = @{$cats[0]};
9770: my $maxnum = $numtop;
9771: my %default_names = (
9772: instcode => &mt('Official courses'),
9773: communities => &mt('Communities'),
9774: );
9775:
9776: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9777: ($cathash->{'instcode::0'} eq '') ||
9778: (!grep(/^communities$/,@{$cats[0]})) ||
9779: ($cathash->{'communities::0'} eq '')) {
9780: $maxnum ++;
9781: }
9782: my $lastidx;
9783: for (my $i=0; $i<$numtop; $i++) {
9784: my $parent = $cats[0][$i];
9785: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9786: my $item = &escape($parent).'::0';
9787: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9788: $lastidx = $idx{$item};
9789: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9790: .'<select name="'.$item.'"'.$chgstr.'>';
9791: for (my $k=0; $k<=$maxnum; $k++) {
9792: my $vpos = $k+1;
9793: my $selstr;
9794: if ($k == $i) {
9795: $selstr = ' selected="selected" ';
9796: }
9797: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9798: }
9799: $datatable .= '</select></span></td><td>';
9800: if ($parent eq 'instcode' || $parent eq 'communities') {
9801: $datatable .= '<span class="LC_nobreak">'
9802: .$default_names{$parent}.'</span>';
9803: if ($parent eq 'instcode') {
9804: $datatable .= '<br /><span class="LC_nobreak">('
9805: .&mt('with institutional codes')
9806: .')</span></td><td'.$colattrib.'>';
9807: } else {
9808: $datatable .= '<table><tr><td>';
9809: }
9810: $datatable .= '<span class="LC_nobreak">'
9811: .'<label><input type="radio" name="'
9812: .$parent.'" value="1" checked="checked" />'
9813: .&mt('Display').'</label>';
9814: if ($parent eq 'instcode') {
9815: $datatable .= ' ';
9816: } else {
9817: $datatable .= '</span></td></tr><tr><td>'
9818: .'<span class="LC_nobreak">';
9819: }
9820: $datatable .= '<label><input type="radio" name="'
9821: .$parent.'" value="0" />'
9822: .&mt('Do not display').'</label></span>';
9823: if ($parent eq 'communities') {
9824: $datatable .= '</td></tr></table>';
9825: }
9826: $datatable .= '</td>';
9827: } else {
9828: $datatable .= $parent
9829: .' <span class="LC_nobreak"><label>'
9830: .'<input type="checkbox" name="deletecategory" '
9831: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9832: }
9833: my $depth = 1;
9834: push(@path,$parent);
9835: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9836: pop(@path);
9837: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9838: $itemcount ++;
9839: }
9840: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9841: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9842: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
9843: for (my $k=0; $k<=$maxnum; $k++) {
9844: my $vpos = $k+1;
9845: my $selstr;
9846: if ($k == $numtop) {
9847: $selstr = ' selected="selected" ';
9848: }
9849: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9850: }
9851: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
9852: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9853: .'</tr>'."\n";
9854: $itemcount ++;
9855: foreach my $default ('instcode','communities') {
9856: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9858: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9859: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9860: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9861: for (my $k=0; $k<=$maxnum; $k++) {
9862: my $vpos = $k+1;
9863: my $selstr;
9864: if ($k == $maxnum) {
9865: $selstr = ' selected="selected" ';
9866: }
9867: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9868: }
9869: $datatable .= '</select></span></td>'.
9870: '<td><span class="LC_nobreak">'.
9871: $default_names{$default}.'</span>';
9872: if ($default eq 'instcode') {
9873: $datatable .= '<br /><span class="LC_nobreak">('
9874: .&mt('with institutional codes').')</span>';
9875: }
9876: $datatable .= '</td>'
9877: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9878: .&mt('Display').'</label> '
9879: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9880: .&mt('Do not display').'</label></span></td></tr>';
9881: }
9882: }
9883: }
9884: } else {
9885: $datatable .= &initialize_categories($itemcount);
9886: }
9887: } else {
9888: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
9889: .&initialize_categories($itemcount);
9890: }
9891: $$rowtotal += $itemcount;
9892: }
9893: return $datatable;
9894: }
9895:
9896: sub print_serverstatuses {
9897: my ($dom,$settings,$rowtotal) = @_;
9898: my $datatable;
9899: my @pages = &serverstatus_pages();
9900: my (%namedaccess,%machineaccess);
9901: foreach my $type (@pages) {
9902: $namedaccess{$type} = '';
9903: $machineaccess{$type}= '';
9904: }
9905: if (ref($settings) eq 'HASH') {
9906: foreach my $type (@pages) {
9907: if (exists($settings->{$type})) {
9908: if (ref($settings->{$type}) eq 'HASH') {
9909: foreach my $key (keys(%{$settings->{$type}})) {
9910: if ($key eq 'namedusers') {
9911: $namedaccess{$type} = $settings->{$type}->{$key};
9912: } elsif ($key eq 'machines') {
9913: $machineaccess{$type} = $settings->{$type}->{$key};
9914: }
9915: }
9916: }
9917: }
9918: }
9919: }
9920: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
9921: my $rownum = 0;
9922: my $css_class;
9923: foreach my $type (@pages) {
9924: $rownum ++;
9925: $css_class = $rownum%2?' class="LC_odd_row"':'';
9926: $datatable .= '<tr'.$css_class.'>'.
9927: '<td><span class="LC_nobreak">'.
9928: $titles->{$type}.'</span></td>'.
9929: '<td class="LC_left_item">'.
9930: '<input type="text" name="'.$type.'_namedusers" '.
9931: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9932: '<td class="LC_right_item">'.
9933: '<span class="LC_nobreak">'.
9934: '<input type="text" name="'.$type.'_machines" '.
9935: 'value="'.$machineaccess{$type}.'" size="10" />'.
9936: '</span></td></tr>'."\n";
9937: }
9938: $$rowtotal += $rownum;
9939: return $datatable;
9940: }
9941:
9942: sub serverstatus_pages {
9943: return ('userstatus','lonstatus','loncron','server-status','codeversions',
9944: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
9945: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
9946: 'uniquecodes','diskusage','coursecatalog');
9947: }
9948:
9949: sub defaults_javascript {
9950: my ($settings) = @_;
9951: return unless (ref($settings) eq 'HASH');
9952: my $portal_js = <<"ENDPORTAL";
9953:
9954: function portalExtras(caller) {
9955: var x = caller.value;
9956: var y = new Array('email','web');
9957: for (var i=0; i<y.length; i++) {
9958: if (document.getElementById('portal_def_'+y[i]+'_div')) {
9959: var z = document.getElementById('portal_def_'+y[i]+'_div');
9960: if (x.length > 0) {
9961: z.style.display = 'block';
9962: } else {
9963: z.style.display = 'none';
9964: }
9965: }
9966: }
9967: }
9968: ENDPORTAL
9969: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9970: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9971: if ($maxnum eq '') {
9972: $maxnum = 0;
9973: }
9974: $maxnum ++;
9975: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
9976: return <<"ENDSCRIPT";
9977: <script type="text/javascript">
9978: // <![CDATA[
9979: function reorderTypes(form,caller) {
9980: var changedVal;
9981: $jstext
9982: var newpos = 'addinststatus_pos';
9983: var current = new Array;
9984: var maxh = $maxnum;
9985: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9986: var oldVal;
9987: if (caller == newpos) {
9988: changedVal = newitemVal;
9989: } else {
9990: var curritem = 'inststatus_pos_'+caller;
9991: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9992: current[newitemVal] = newpos;
9993: }
9994: for (var i=0; i<inststatuses.length; i++) {
9995: if (inststatuses[i] != caller) {
9996: var elementName = 'inststatus_pos_'+inststatuses[i];
9997: if (form.elements[elementName]) {
9998: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9999: current[currVal] = elementName;
10000: }
10001: }
10002: }
10003: for (var j=0; j<maxh; j++) {
10004: if (current[j] == undefined) {
10005: oldVal = j;
10006: }
10007: }
10008: if (oldVal < changedVal) {
10009: for (var k=oldVal+1; k<=changedVal ; k++) {
10010: var elementName = current[k];
10011: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10012: }
10013: } else {
10014: for (var k=changedVal; k<oldVal; k++) {
10015: var elementName = current[k];
10016: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10017: }
10018: }
10019: return;
10020: }
10021:
10022: $portal_js
10023:
10024: // ]]>
10025: </script>
10026:
10027: ENDSCRIPT
10028: } else {
10029: return <<"ENDSCRIPT";
10030: <script type="text/javascript">
10031: // <![CDATA[
10032: $portal_js
10033: // ]]>
10034: </script>
10035:
10036: ENDSCRIPT
10037: }
10038: return;
10039: }
10040:
10041: sub passwords_javascript {
10042: my ($prefix) = @_;
10043: my %intalert;
10044: if ($prefix eq 'passwords') {
10045: %intalert = &Apache::lonlocal::texthash (
10046: authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
10047: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10048: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10049: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10050: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10051: );
10052: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
10053: %intalert = &Apache::lonlocal::texthash (
10054: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
10055: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
10056: );
10057: }
10058: &js_escape(\%intalert);
10059: my $defmin = $Apache::lonnet::passwdmin;
10060: my $intauthjs;
10061: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
10062:
10063: function warnIntAuth(field) {
10064: if (field.name == 'intauth_check') {
10065: if (field.value == '2') {
10066: alert('$intalert{authcheck}');
10067: }
10068: }
10069: if (field.name == 'intauth_cost') {
10070: field.value.replace(/\s/g,'');
10071: if (field.value != '') {
10072: var regexdigit=/^\\d+\$/;
10073: if (!regexdigit.test(field.value)) {
10074: alert('$intalert{authcost}');
10075: }
10076: }
10077: }
10078: return;
10079: }
10080:
10081: ENDSCRIPT
10082:
10083: }
10084:
10085: $intauthjs .= <<"ENDSCRIPT";
10086:
10087: function warnInt$prefix(field) {
10088: field.value.replace(/^\s+/,'');
10089: field.value.replace(/\s+\$/,'');
10090: var regexdigit=/^\\d+\$/;
10091: if (field.name == '${prefix}_min') {
10092: if (field.value == '') {
10093: alert('$intalert{passmin}');
10094: field.value = '$defmin';
10095: } else {
10096: if (!regexdigit.test(field.value)) {
10097: alert('$intalert{passmin}');
10098: field.value = '$defmin';
10099: }
10100: var minval = parseInt(field.value,10);
10101: if (minval < $defmin) {
10102: alert('$intalert{passmin}');
10103: field.value = '$defmin';
10104: }
10105: }
10106: } else {
10107: if (field.value == '0') {
10108: field.value = '';
10109: }
10110: if (field.value != '') {
10111: if (!regexdigit.test(field.value)) {
10112: if (field.name == '${prefix}_max') {
10113: alert('$intalert{passmax}');
10114: } else {
10115: if (field.name == '${prefix}_numsaved') {
10116: alert('$intalert{passnum}');
10117: }
10118: }
10119: field.value = '';
10120: }
10121: }
10122: }
10123: return;
10124: }
10125:
10126: ENDSCRIPT
10127: return &Apache::lonhtmlcommon::scripttag($intauthjs);
10128: }
10129:
10130: sub coursecategories_javascript {
10131: my ($settings) = @_;
10132: my ($output,$jstext,$cathash);
10133: if (ref($settings) eq 'HASH') {
10134: $cathash = $settings->{'cats'};
10135: }
10136: if (ref($cathash) eq 'HASH') {
10137: my (@cats,@jsarray,%idx);
10138: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
10139: if (@jsarray > 0) {
10140: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10141: for (my $i=0; $i<@jsarray; $i++) {
10142: if (ref($jsarray[$i]) eq 'ARRAY') {
10143: my $catstr = join('","',@{$jsarray[$i]});
10144: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10145: }
10146: }
10147: }
10148: } else {
10149: $jstext = ' var categories = Array(1);'."\n".
10150: ' categories[0] = Array("instcode_pos");'."\n";
10151: }
10152: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10153: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
10154: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10155: &js_escape(\$instcode_reserved);
10156: &js_escape(\$communities_reserved);
10157: &js_escape(\$choose_again);
10158: $output = <<"ENDSCRIPT";
10159: <script type="text/javascript">
10160: // <![CDATA[
10161: function reorderCats(form,parent,item,idx) {
10162: var changedVal;
10163: $jstext
10164: var newpos = 'addcategory_pos';
10165: if (parent == '') {
10166: var has_instcode = 0;
10167: var maxtop = categories[idx].length;
10168: for (var j=0; j<maxtop; j++) {
10169: if (categories[idx][j] == 'instcode::0') {
10170: has_instcode == 1;
10171: }
10172: }
10173: if (has_instcode == 0) {
10174: categories[idx][maxtop] = 'instcode_pos';
10175: }
10176: } else {
10177: newpos += '_'+parent;
10178: }
10179: var maxh = 1 + categories[idx].length;
10180: var current = new Array;
10181: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10182: if (item == newpos) {
10183: changedVal = newitemVal;
10184: } else {
10185: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10186: current[newitemVal] = newpos;
10187: }
10188: for (var i=0; i<categories[idx].length; i++) {
10189: var elementName = categories[idx][i];
10190: if (elementName != item) {
10191: if (form.elements[elementName]) {
10192: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10193: current[currVal] = elementName;
10194: }
10195: }
10196: }
10197: var oldVal;
10198: for (var j=0; j<maxh; j++) {
10199: if (current[j] == undefined) {
10200: oldVal = j;
10201: }
10202: }
10203: if (oldVal < changedVal) {
10204: for (var k=oldVal+1; k<=changedVal ; k++) {
10205: var elementName = current[k];
10206: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10207: }
10208: } else {
10209: for (var k=changedVal; k<oldVal; k++) {
10210: var elementName = current[k];
10211: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10212: }
10213: }
10214: return;
10215: }
10216:
10217: function categoryCheck(form) {
10218: if (form.elements['addcategory_name'].value == 'instcode') {
10219: alert('$instcode_reserved\\n$choose_again');
10220: return false;
10221: }
10222: if (form.elements['addcategory_name'].value == 'communities') {
10223: alert('$communities_reserved\\n$choose_again');
10224: return false;
10225: }
10226: return true;
10227: }
10228:
10229: // ]]>
10230: </script>
10231:
10232: ENDSCRIPT
10233: return $output;
10234: }
10235:
10236: sub initialize_categories {
10237: my ($itemcount) = @_;
10238: my ($datatable,$css_class,$chgstr);
10239: my %default_names = &Apache::lonlocal::texthash (
10240: instcode => 'Official courses (with institutional codes)',
10241: communities => 'Communities',
10242: );
10243: my $select0 = ' selected="selected"';
10244: my $select1 = '';
10245: foreach my $default ('instcode','communities') {
10246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10247: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
10248: if ($default eq 'communities') {
10249: $select1 = $select0;
10250: $select0 = '';
10251: }
10252: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10253: .'<select name="'.$default.'_pos">'
10254: .'<option value="0"'.$select0.'>1</option>'
10255: .'<option value="1"'.$select1.'>2</option>'
10256: .'<option value="2">3</option></select> '
10257: .$default_names{$default}
10258: .'</span></td><td><span class="LC_nobreak">'
10259: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10260: .&mt('Display').'</label> <label>'
10261: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
10262: .'</label></span></td></tr>';
10263: $itemcount ++;
10264: }
10265: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10266: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
10267: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10268: .'<select name="addcategory_pos"'.$chgstr.'>'
10269: .'<option value="0">1</option>'
10270: .'<option value="1">2</option>'
10271: .'<option value="2" selected="selected">3</option></select> '
10272: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
10273: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10274: .'</td></tr>';
10275: return $datatable;
10276: }
10277:
10278: sub build_category_rows {
10279: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10280: my ($text,$name,$item,$chgstr);
10281: if (ref($cats) eq 'ARRAY') {
10282: my $maxdepth = scalar(@{$cats});
10283: if (ref($cats->[$depth]) eq 'HASH') {
10284: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10285: my $numchildren = @{$cats->[$depth]{$parent}};
10286: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10287: $text .= '<td><table class="LC_data_table">';
10288: my ($idxnum,$parent_name,$parent_item);
10289: my $higher = $depth - 1;
10290: if ($higher == 0) {
10291: $parent_name = &escape($parent).'::'.$higher;
10292: } else {
10293: if (ref($path) eq 'ARRAY') {
10294: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10295: }
10296: }
10297: $parent_item = 'addcategory_pos_'.$parent_name;
10298: for (my $j=0; $j<=$numchildren; $j++) {
10299: if ($j < $numchildren) {
10300: $name = $cats->[$depth]{$parent}[$j];
10301: $item = &escape($name).':'.&escape($parent).':'.$depth;
10302: $idxnum = $idx->{$item};
10303: } else {
10304: $name = $parent_name;
10305: $item = $parent_item;
10306: }
10307: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10308: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
10309: for (my $i=0; $i<=$numchildren; $i++) {
10310: my $vpos = $i+1;
10311: my $selstr;
10312: if ($j == $i) {
10313: $selstr = ' selected="selected" ';
10314: }
10315: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10316: }
10317: $text .= '</select> ';
10318: if ($j < $numchildren) {
10319: my $deeper = $depth+1;
10320: $text .= $name.' '
10321: .'<label><input type="checkbox" name="deletecategory" value="'
10322: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10323: if(ref($path) eq 'ARRAY') {
10324: push(@{$path},$name);
10325: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
10326: pop(@{$path});
10327: }
10328: } else {
10329: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
10330: if ($j == $numchildren) {
10331: $text .= $name;
10332: } else {
10333: $text .= $item;
10334: }
10335: $text .= '" value="" />';
10336: }
10337: $text .= '</td></tr>';
10338: }
10339: $text .= '</table></td>';
10340: } else {
10341: my $higher = $depth-1;
10342: if ($higher == 0) {
10343: $name = &escape($parent).'::'.$higher;
10344: } else {
10345: if (ref($path) eq 'ARRAY') {
10346: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10347: }
10348: }
10349: my $colspan;
10350: if ($parent ne 'instcode') {
10351: $colspan = $maxdepth - $depth - 1;
10352: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
10353: }
10354: }
10355: }
10356: }
10357: return $text;
10358: }
10359:
10360: sub modifiable_userdata_row {
10361: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
10362: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
10363: my ($role,$rolename,$statustype);
10364: $role = $item;
10365: if ($context eq 'cancreate') {
10366: if ($item =~ /^(emailusername)_(.+)$/) {
10367: $role = $1;
10368: $statustype = $2;
10369: if (ref($usertypes) eq 'HASH') {
10370: if ($usertypes->{$statustype}) {
10371: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10372: } else {
10373: $rolename = &mt('Data provided by user');
10374: }
10375: }
10376: }
10377: } elsif ($context eq 'selfcreate') {
10378: if (ref($usertypes) eq 'HASH') {
10379: $rolename = $usertypes->{$role};
10380: } else {
10381: $rolename = $role;
10382: }
10383: } elsif ($context eq 'lti') {
10384: $rolename = &mt('Institutional data used (if available)');
10385: } else {
10386: if ($role eq 'cr') {
10387: $rolename = &mt('Custom role');
10388: } else {
10389: $rolename = &Apache::lonnet::plaintext($role);
10390: }
10391: }
10392: my (@fields,%fieldtitles);
10393: if (ref($fieldsref) eq 'ARRAY') {
10394: @fields = @{$fieldsref};
10395: } else {
10396: @fields = ('lastname','firstname','middlename','generation',
10397: 'permanentemail','id');
10398: }
10399: if ((ref($titlesref) eq 'HASH')) {
10400: %fieldtitles = %{$titlesref};
10401: } else {
10402: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10403: }
10404: my $output;
10405: my $css_class;
10406: if ($rowcount%2) {
10407: $css_class = 'LC_odd_row';
10408: }
10409: if ($customcss) {
10410: $css_class .= " $customcss";
10411: }
10412: $css_class =~ s/^\s+//;
10413: if ($css_class) {
10414: $css_class = ' class="'.$css_class.'"';
10415: }
10416: if ($rowstyle) {
10417: $css_class .= ' style="'.$rowstyle.'"';
10418: }
10419: if ($rowid) {
10420: $rowid = ' id="'.$rowid.'"';
10421: }
10422: $output = '<tr '.$css_class.$rowid.'>'.
10423: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10424: '<td class="LC_left_item" colspan="2"><table>';
10425: my $rem;
10426: my %checks;
10427: if (ref($settings) eq 'HASH') {
10428: my $hashref;
10429: if ($context eq 'lti') {
10430: if (ref($settings) eq 'HASH') {
10431: $hashref = $settings->{'instdata'};
10432: }
10433: } elsif (ref($settings->{$context}) eq 'HASH') {
10434: if (ref($settings->{$context}->{$role}) eq 'HASH') {
10435: $hashref = $settings->{'lti_instdata'};
10436: }
10437: if ($role eq 'emailusername') {
10438: if ($statustype) {
10439: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10440: $hashref = $settings->{$context}->{$role}->{$statustype};
10441: }
10442: }
10443: }
10444: }
10445: if (ref($hashref) eq 'HASH') {
10446: foreach my $field (@fields) {
10447: if ($hashref->{$field}) {
10448: if ($role eq 'emailusername') {
10449: $checks{$field} = $hashref->{$field};
10450: } else {
10451: $checks{$field} = ' checked="checked" ';
10452: }
10453: }
10454: }
10455: }
10456: }
10457: my $total = scalar(@fields);
10458: for (my $i=0; $i<$total; $i++) {
10459: $rem = $i%($numinrow);
10460: if ($rem == 0) {
10461: if ($i > 0) {
10462: $output .= '</tr>';
10463: }
10464: $output .= '<tr>';
10465: }
10466: my $check = ' ';
10467: unless ($role eq 'emailusername') {
10468: if (exists($checks{$fields[$i]})) {
10469: $check = $checks{$fields[$i]};
10470: } elsif ($context ne 'lti') {
10471: if ($role eq 'st') {
10472: if (ref($settings) ne 'HASH') {
10473: $check = ' checked="checked" ';
10474: }
10475: }
10476: }
10477: }
10478: $output .= '<td class="LC_left_item">'.
10479: '<span class="LC_nobreak">';
10480: my $prefix = 'canmodify';
10481: if ($role eq 'emailusername') {
10482: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10483: $checks{$fields[$i]} = 'omit';
10484: }
10485: foreach my $option ('required','optional','omit') {
10486: my $checked='';
10487: if ($checks{$fields[$i]} eq $option) {
10488: $checked='checked="checked" ';
10489: }
10490: $output .= '<label>'.
10491: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
10492: &mt($option).'</label>'.(' ' x2);
10493: }
10494: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10495: } else {
10496: if ($context eq 'lti') {
10497: $prefix = 'lti';
10498: }
10499: $output .= '<label>'.
10500: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
10501: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10502: '</label>';
10503: }
10504: $output .= '</span></td>';
10505: }
10506: $rem = $total%$numinrow;
10507: my $colsleft;
10508: if ($rem) {
10509: $colsleft = $numinrow - $rem;
10510: }
10511: if ($colsleft > 1) {
10512: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10513: ' </td>';
10514: } elsif ($colsleft == 1) {
10515: $output .= '<td class="LC_left_item"> </td>';
10516: }
10517: $output .= '</tr></table></td></tr>';
10518: return $output;
10519: }
10520:
10521: sub insttypes_row {
10522: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10523: $customcss,$rowstyle) = @_;
10524: my %lt = &Apache::lonlocal::texthash (
10525: cansearch => 'Users allowed to search',
10526: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
10527: lockablenames => 'User preference to lock name',
10528: selfassign => 'Self-reportable affiliations',
10529: overrides => "Override domain's helpdesk settings based on requester's affiliation",
10530: );
10531: my $showdom;
10532: if ($context eq 'cansearch') {
10533: $showdom = ' ('.$dom.')';
10534: }
10535: my $class = 'LC_left_item';
10536: if ($context eq 'statustocreate') {
10537: $class = 'LC_right_item';
10538: }
10539: my $css_class;
10540: if ($$rowtotal%2) {
10541: $css_class = 'LC_odd_row';
10542: }
10543: if ($customcss) {
10544: $css_class .= ' '.$customcss;
10545: }
10546: $css_class =~ s/^\s+//;
10547: if ($css_class) {
10548: $css_class = ' class="'.$css_class.'"';
10549: }
10550: if ($rowstyle) {
10551: $css_class .= ' style="'.$rowstyle.'"';
10552: }
10553: if ($onclick) {
10554: $onclick = 'onclick="'.$onclick.'" ';
10555: }
10556: my $output = '<tr'.$css_class.'>'.
10557: '<td>'.$lt{$context}.$showdom.
10558: '</td><td class="'.$class.'" colspan="2"><table>';
10559: my $rem;
10560: if (ref($types) eq 'ARRAY') {
10561: for (my $i=0; $i<@{$types}; $i++) {
10562: if (defined($usertypes->{$types->[$i]})) {
10563: my $rem = $i%($numinrow);
10564: if ($rem == 0) {
10565: if ($i > 0) {
10566: $output .= '</tr>';
10567: }
10568: $output .= '<tr>';
10569: }
10570: my $check = ' ';
10571: if (ref($settings) eq 'HASH') {
10572: if (ref($settings->{$context}) eq 'ARRAY') {
10573: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10574: $check = ' checked="checked" ';
10575: }
10576: } elsif (ref($settings->{$context}) eq 'HASH') {
10577: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10578: $check = ' checked="checked" ';
10579: }
10580: } elsif ($context eq 'statustocreate') {
10581: $check = ' checked="checked" ';
10582: }
10583: }
10584: $output .= '<td class="LC_left_item">'.
10585: '<span class="LC_nobreak"><label>'.
10586: '<input type="checkbox" name="'.$context.'" '.
10587: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
10588: $usertypes->{$types->[$i]}.'</label></span></td>';
10589: }
10590: }
10591: $rem = @{$types}%($numinrow);
10592: }
10593: my $colsleft = $numinrow - $rem;
10594: if ($context eq 'overrides') {
10595: if ($colsleft > 1) {
10596: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10597: } else {
10598: $output .= '<td class="LC_left_item">';
10599: }
10600: $output .= ' ';
10601: } else {
10602: if ($rem == 0) {
10603: $output .= '<tr>';
10604: }
10605: if ($colsleft > 1) {
10606: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10607: } else {
10608: $output .= '<td class="LC_left_item">';
10609: }
10610: my $defcheck = ' ';
10611: if (ref($settings) eq 'HASH') {
10612: if (ref($settings->{$context}) eq 'ARRAY') {
10613: if (grep(/^default$/,@{$settings->{$context}})) {
10614: $defcheck = ' checked="checked" ';
10615: }
10616: } elsif ($context eq 'statustocreate') {
10617: $defcheck = ' checked="checked" ';
10618: }
10619: }
10620: $output .= '<span class="LC_nobreak"><label>'.
10621: '<input type="checkbox" name="'.$context.'" '.
10622: 'value="default"'.$defcheck.$onclick.' />'.
10623: $othertitle.'</label></span>';
10624: }
10625: $output .= '</td></tr></table></td></tr>';
10626: return $output;
10627: }
10628:
10629: sub sorted_searchtitles {
10630: my %searchtitles = &Apache::lonlocal::texthash(
10631: 'uname' => 'username',
10632: 'lastname' => 'last name',
10633: 'lastfirst' => 'last name, first name',
10634: );
10635: my @titleorder = ('uname','lastname','lastfirst');
10636: return (\%searchtitles,\@titleorder);
10637: }
10638:
10639: sub sorted_searchtypes {
10640: my %srchtypes_desc = (
10641: exact => 'is exact match',
10642: contains => 'contains ..',
10643: begins => 'begins with ..',
10644: );
10645: my @srchtypeorder = ('exact','begins','contains');
10646: return (\%srchtypes_desc,\@srchtypeorder);
10647: }
10648:
10649: sub usertype_update_row {
10650: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
10651: my $datatable;
10652: my $numinrow = 4;
10653: foreach my $type (@{$types}) {
10654: if (defined($usertypes->{$type})) {
10655: $$rownums ++;
10656: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
10657: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
10658: '</td><td class="LC_left_item"><table>';
10659: for (my $i=0; $i<@{$fields}; $i++) {
10660: my $rem = $i%($numinrow);
10661: if ($rem == 0) {
10662: if ($i > 0) {
10663: $datatable .= '</tr>';
10664: }
10665: $datatable .= '<tr>';
10666: }
10667: my $check = ' ';
10668: if (ref($settings) eq 'HASH') {
10669: if (ref($settings->{'fields'}) eq 'HASH') {
10670: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
10671: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
10672: $check = ' checked="checked" ';
10673: }
10674: }
10675: }
10676: }
10677:
10678: if ($i == @{$fields}-1) {
10679: my $colsleft = $numinrow - $rem;
10680: if ($colsleft > 1) {
10681: $datatable .= '<td colspan="'.$colsleft.'">';
10682: } else {
10683: $datatable .= '<td>';
10684: }
10685: } else {
10686: $datatable .= '<td>';
10687: }
10688: $datatable .= '<span class="LC_nobreak"><label>'.
10689: '<input type="checkbox" name="updateable_'.$type.
10690: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
10691: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
10692: }
10693: $datatable .= '</tr></table></td></tr>';
10694: }
10695: }
10696: return $datatable;
10697: }
10698:
10699: sub modify_login {
10700: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
10701: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
10702: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
10703: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
10704: %title = ( coursecatalog => 'Display course catalog',
10705: adminmail => 'Display administrator E-mail address',
10706: helpdesk => 'Display "Contact Helpdesk" link',
10707: newuser => 'Link for visitors to create a user account',
10708: loginheader => 'Log-in box header',
10709: saml => 'Dual SSO and non-SSO login');
10710: @offon = ('off','on');
10711: if (ref($domconfig{login}) eq 'HASH') {
10712: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10713: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10714: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10715: }
10716: }
10717: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
10718: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
10719: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
10720: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
10721: $saml{$lonhost} = 1;
10722: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
10723: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
10724: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
10725: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
10726: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
10727: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
10728: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
10729: }
10730: }
10731: }
10732: }
10733: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10734: \%domconfig,\%loginhash);
10735: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
10736: foreach my $item (@toggles) {
10737: $loginhash{login}{$item} = $env{'form.'.$item};
10738: }
10739: $loginhash{login}{loginheader} = $env{'form.loginheader'};
10740: if (ref($colchanges{'login'}) eq 'HASH') {
10741: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10742: \%loginhash);
10743: }
10744:
10745: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10746: my %domservers = &Apache::lonnet::get_servers($dom);
10747: my @loginvia_attribs = ('serverpath','custompath','exempt');
10748: if (keys(%servers) > 1) {
10749: foreach my $lonhost (keys(%servers)) {
10750: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10751: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10752: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10753: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10754: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10755: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10757: $changes{'loginvia'}{$lonhost} = 1;
10758: } else {
10759: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10760: $changes{'loginvia'}{$lonhost} = 1;
10761: }
10762: } else {
10763: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10764: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10765: $changes{'loginvia'}{$lonhost} = 1;
10766: }
10767: }
10768: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10769: foreach my $item (@loginvia_attribs) {
10770: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10771: }
10772: } else {
10773: foreach my $item (@loginvia_attribs) {
10774: my $new = $env{'form.'.$lonhost.'_'.$item};
10775: if (($item eq 'serverpath') && ($new eq 'custom')) {
10776: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10777: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10778: $new = '/';
10779: }
10780: }
10781: if (($item eq 'custompath') &&
10782: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10783: $new = '';
10784: }
10785: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10786: $changes{'loginvia'}{$lonhost} = 1;
10787: }
10788: if ($item eq 'exempt') {
10789: $new = &check_exempt_addresses($new);
10790: }
10791: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10792: }
10793: }
10794: } else {
10795: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10796: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10797: $changes{'loginvia'}{$lonhost} = 1;
10798: foreach my $item (@loginvia_attribs) {
10799: my $new = $env{'form.'.$lonhost.'_'.$item};
10800: if (($item eq 'serverpath') && ($new eq 'custom')) {
10801: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10802: $new = '/';
10803: }
10804: }
10805: if (($item eq 'custompath') &&
10806: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10807: $new = '';
10808: }
10809: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10810: }
10811: }
10812: }
10813: }
10814: }
10815:
10816: my $servadm = $r->dir_config('lonAdmEMail');
10817: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10818: if (ref($domconfig{'login'}) eq 'HASH') {
10819: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10820: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10821: if ($lang eq 'nolang') {
10822: push(@currlangs,$lang);
10823: } elsif (defined($langchoices{$lang})) {
10824: push(@currlangs,$lang);
10825: } else {
10826: next;
10827: }
10828: }
10829: }
10830: }
10831: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10832: if (@currlangs > 0) {
10833: foreach my $lang (@currlangs) {
10834: if (grep(/^\Q$lang\E$/,@delurls)) {
10835: $changes{'helpurl'}{$lang} = 1;
10836: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10837: $changes{'helpurl'}{$lang} = 1;
10838: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10839: push(@newlangs,$lang);
10840: } else {
10841: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10842: }
10843: }
10844: }
10845: unless (grep(/^nolang$/,@currlangs)) {
10846: if ($env{'form.loginhelpurl_nolang.filename'}) {
10847: $changes{'helpurl'}{'nolang'} = 1;
10848: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10849: push(@newlangs,'nolang');
10850: }
10851: }
10852: if ($env{'form.loginhelpurl_add_lang'}) {
10853: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10854: ($env{'form.loginhelpurl_add_file.filename'})) {
10855: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10856: $addedfile = $env{'form.loginhelpurl_add_lang'};
10857: }
10858: }
10859: if ((@newlangs > 0) || ($addedfile)) {
10860: my $error;
10861: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10862: if ($configuserok eq 'ok') {
10863: if ($switchserver) {
10864: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10865: } elsif ($author_ok eq 'ok') {
10866: my @allnew = @newlangs;
10867: if ($addedfile ne '') {
10868: push(@allnew,$addedfile);
10869: }
10870: my $modified = [];
10871: foreach my $lang (@allnew) {
10872: my $formelem = 'loginhelpurl_'.$lang;
10873: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10874: $formelem = 'loginhelpurl_add_file';
10875: }
10876: (my $result,$newurl{$lang}) =
10877: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
10878: "help/$lang",'','',$newfile{$lang},
10879: $modified);
10880: if ($result eq 'ok') {
10881: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10882: $changes{'helpurl'}{$lang} = 1;
10883: } else {
10884: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10885: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10886: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
10887: (!grep(/^\Q$lang\E$/,@delurls))) {
10888: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10889: }
10890: }
10891: }
10892: &update_modify_urls($r,$modified);
10893: } else {
10894: $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
10895: }
10896: } else {
10897: $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
10898: }
10899: if ($error) {
10900: &Apache::lonnet::logthis($error);
10901: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10902: }
10903: }
10904:
10905: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10906: if (ref($domconfig{'login'}) eq 'HASH') {
10907: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10908: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10909: if ($domservers{$lonhost}) {
10910: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10911: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
10912: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
10913: }
10914: }
10915: }
10916: }
10917: }
10918: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10919: foreach my $lonhost (sort(keys(%domservers))) {
10920: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10921: $changes{'headtag'}{$lonhost} = 1;
10922: } else {
10923: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10924: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10925: }
10926: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10927: push(@newhosts,$lonhost);
10928: } elsif ($currheadtagurls{$lonhost}) {
10929: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10930: if ($currexempt{$lonhost}) {
10931: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
10932: $changes{'headtag'}{$lonhost} = 1;
10933: }
10934: } elsif ($possexempt{$lonhost}) {
10935: $changes{'headtag'}{$lonhost} = 1;
10936: }
10937: if ($possexempt{$lonhost}) {
10938: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10939: }
10940: }
10941: }
10942: }
10943: if (@newhosts) {
10944: my $error;
10945: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10946: if ($configuserok eq 'ok') {
10947: if ($switchserver) {
10948: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10949: } elsif ($author_ok eq 'ok') {
10950: my $modified = [];
10951: foreach my $lonhost (@newhosts) {
10952: my $formelem = 'loginheadtag_'.$lonhost;
10953: (my $result,$newheadtagurls{$lonhost}) =
10954: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
10955: "login/headtag/$lonhost",'','',
10956: $env{'form.loginheadtag_'.$lonhost.'.filename'},
10957: $modified);
10958: if ($result eq 'ok') {
10959: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10960: $changes{'headtag'}{$lonhost} = 1;
10961: if ($possexempt{$lonhost}) {
10962: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10963: }
10964: } else {
10965: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10966: $newheadtagurls{$lonhost},$result);
10967: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10968: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10969: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10970: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10971: }
10972: }
10973: }
10974: &update_modify_urls($r,$modified);
10975: } else {
10976: $error = &mt("Upload of custom markup file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
10977: }
10978: } else {
10979: $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
10980: }
10981: if ($error) {
10982: &Apache::lonnet::logthis($error);
10983: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10984: }
10985: }
10986: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
10987: my @newsamlimgs;
10988: foreach my $lonhost (keys(%domservers)) {
10989: if ($env{'form.saml_'.$lonhost}) {
10990: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
10991: push(@newsamlimgs,$lonhost);
10992: }
10993: foreach my $item ('text','alt','url','title','window','notsso') {
10994: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
10995: }
10996: if ($saml{$lonhost}) {
10997: if ($env{'form.saml_window_'.$lonhost} ne '1') {
10998: $env{'form.saml_window_'.$lonhost} = '';
10999: }
11000: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11001: #FIXME Need to obsolete published image
11002: delete($currsaml{$lonhost}{'img'});
11003: $changes{'saml'}{$lonhost} = 1;
11004: }
11005: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11006: $changes{'saml'}{$lonhost} = 1;
11007: }
11008: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11009: $changes{'saml'}{$lonhost} = 1;
11010: }
11011: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11012: $changes{'saml'}{$lonhost} = 1;
11013: }
11014: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11015: $changes{'saml'}{$lonhost} = 1;
11016: }
11017: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
11018: $changes{'saml'}{$lonhost} = 1;
11019: }
11020: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11021: $changes{'saml'}{$lonhost} = 1;
11022: }
11023: } else {
11024: $changes{'saml'}{$lonhost} = 1;
11025: }
11026: foreach my $item ('text','alt','url','title','window','notsso') {
11027: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11028: }
11029: } else {
11030: if ($saml{$lonhost}) {
11031: $changes{'saml'}{$lonhost} = 1;
11032: delete($currsaml{$lonhost});
11033: }
11034: }
11035: }
11036: foreach my $posshost (keys(%currsaml)) {
11037: unless (exists($domservers{$posshost})) {
11038: delete($currsaml{$posshost});
11039: }
11040: }
11041: %{$loginhash{'login'}{'saml'}} = %currsaml;
11042: if (@newsamlimgs) {
11043: my $error;
11044: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11045: if ($configuserok eq 'ok') {
11046: if ($switchserver) {
11047: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11048: } elsif ($author_ok eq 'ok') {
11049: my $modified = [];
11050: foreach my $lonhost (@newsamlimgs) {
11051: my $formelem = 'saml_img_'.$lonhost;
11052: my ($result,$imgurl) =
11053: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11054: "login/saml/$lonhost",'','',
11055: $env{'form.saml_img_'.$lonhost.'.filename'},
11056: $modified);
11057: if ($result eq 'ok') {
11058: $currsaml{$lonhost}{'img'} = $imgurl;
11059: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11060: $changes{'saml'}{$lonhost} = 1;
11061: } else {
11062: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11063: $lonhost,$result);
11064: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11065: }
11066: }
11067: &update_modify_urls($r,$modified);
11068: } else {
11069: $error = &mt("Upload of SSO button image file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
11070: }
11071: } else {
11072: $error = &mt("Upload of SSO button image file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
11073: }
11074: if ($error) {
11075: &Apache::lonnet::logthis($error);
11076: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11077: }
11078: }
11079: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
11080:
11081: my $defaulthelpfile = '/adm/loginproblems.html';
11082: my $defaulttext = &mt('Default in use');
11083:
11084: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11085: $dom);
11086: if ($putresult eq 'ok') {
11087: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
11088: my %defaultchecked = (
11089: 'coursecatalog' => 'on',
11090: 'helpdesk' => 'on',
11091: 'adminmail' => 'off',
11092: 'newuser' => 'off',
11093: );
11094: if (ref($domconfig{'login'}) eq 'HASH') {
11095: foreach my $item (@toggles) {
11096: if ($defaultchecked{$item} eq 'on') {
11097: if (($domconfig{'login'}{$item} eq '0') &&
11098: ($env{'form.'.$item} eq '1')) {
11099: $changes{$item} = 1;
11100: } elsif (($domconfig{'login'}{$item} eq '' ||
11101: $domconfig{'login'}{$item} eq '1') &&
11102: ($env{'form.'.$item} eq '0')) {
11103: $changes{$item} = 1;
11104: }
11105: } elsif ($defaultchecked{$item} eq 'off') {
11106: if (($domconfig{'login'}{$item} eq '1') &&
11107: ($env{'form.'.$item} eq '0')) {
11108: $changes{$item} = 1;
11109: } elsif (($domconfig{'login'}{$item} eq '' ||
11110: $domconfig{'login'}{$item} eq '0') &&
11111: ($env{'form.'.$item} eq '1')) {
11112: $changes{$item} = 1;
11113: }
11114: }
11115: }
11116: }
11117: if (keys(%changes) > 0 || $colchgtext) {
11118: &Apache::loncommon::devalidate_domconfig_cache($dom);
11119: if (exists($changes{'saml'})) {
11120: my $hostid_in_use;
11121: my @hosts = &Apache::lonnet::current_machine_ids();
11122: if (@hosts > 1) {
11123: foreach my $hostid (@hosts) {
11124: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11125: $hostid_in_use = $hostid;
11126: last;
11127: }
11128: }
11129: } else {
11130: $hostid_in_use = $r->dir_config('lonHostID');
11131: }
11132: if (($hostid_in_use) &&
11133: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
11134: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
11135: }
11136: if (ref($lastactref) eq 'HASH') {
11137: if (ref($changes{'saml'}) eq 'HASH') {
11138: my %updates;
11139: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11140: $lastactref->{'samllanding'} = \%updates;
11141: }
11142: }
11143: }
11144: if (ref($lastactref) eq 'HASH') {
11145: $lastactref->{'domainconfig'} = 1;
11146: }
11147: $resulttext = &mt('Changes made:').'<ul>';
11148: foreach my $item (sort(keys(%changes))) {
11149: if ($item eq 'loginvia') {
11150: if (ref($changes{$item}) eq 'HASH') {
11151: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11152: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11153: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11154: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11155: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11156: $protocol = 'http' if ($protocol ne 'https');
11157: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11158:
11159: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11160: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11161: } else {
11162: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11163: }
11164: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11165: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11166: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11167: }
11168: $resulttext .= '</li>';
11169: } else {
11170: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11171: }
11172: } else {
11173: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
11174: }
11175: }
11176: $resulttext .= '</ul></li>';
11177: }
11178: } elsif ($item eq 'helpurl') {
11179: if (ref($changes{$item}) eq 'HASH') {
11180: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11181: if (grep(/^\Q$lang\E$/,@delurls)) {
11182: my ($chg,$link);
11183: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11184: if ($lang eq 'nolang') {
11185: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11186: } else {
11187: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11188: }
11189: $resulttext .= '<li>'.$chg.'</li>';
11190: } else {
11191: my $chg;
11192: if ($lang eq 'nolang') {
11193: $chg = &mt('custom log-in help file for no preferred language');
11194: } else {
11195: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11196: }
11197: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11198: $loginhash{'login'}{'helpurl'}{$lang}.
11199: '?inhibitmenu=yes',$chg,600,500).
11200: '</li>';
11201: }
11202: }
11203: }
11204: } elsif ($item eq 'headtag') {
11205: if (ref($changes{$item}) eq 'HASH') {
11206: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11207: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11208: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11209: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11210: $resulttext .= '<li><a href="'.
11211: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11212: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11213: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11214: if ($possexempt{$lonhost}) {
11215: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11216: } else {
11217: $resulttext .= &mt('included for any client IP');
11218: }
11219: $resulttext .= '</li>';
11220: }
11221: }
11222: }
11223: } elsif ($item eq 'saml') {
11224: if (ref($changes{$item}) eq 'HASH') {
11225: my %notlt = (
11226: text => 'Text for log-in by SSO',
11227: img => 'SSO button image',
11228: alt => 'Alt text for button image',
11229: url => 'SSO URL',
11230: title => 'Tooltip for SSO link',
11231: window => 'Pop-up window if iframe',
11232: notsso => 'Text for non-SSO log-in',
11233: );
11234: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11235: if (ref($currsaml{$lonhost}) eq 'HASH') {
11236: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11237: '<ul>';
11238: foreach my $key ('text','img','alt','url','title','window','notsso') {
11239: if ($currsaml{$lonhost}{$key} eq '') {
11240: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11241: } else {
11242: my $value = "'$currsaml{$lonhost}{$key}'";
11243: if ($key eq 'img') {
11244: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
11245: } elsif ($key eq 'window') {
11246: $value = 'On';
11247: }
11248: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11249: $value).'</li>';
11250: }
11251: }
11252: $resulttext .= '</ul></li>';
11253: } else {
11254: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11255: }
11256: }
11257: }
11258: } elsif ($item eq 'captcha') {
11259: if (ref($loginhash{'login'}) eq 'HASH') {
11260: my $chgtxt;
11261: if ($loginhash{'login'}{$item} eq 'notused') {
11262: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11263: } else {
11264: my %captchas = &captcha_phrases();
11265: if ($captchas{$loginhash{'login'}{$item}}) {
11266: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11267: } else {
11268: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11269: }
11270: }
11271: $resulttext .= '<li>'.$chgtxt.'</li>';
11272: }
11273: } elsif ($item eq 'recaptchakeys') {
11274: if (ref($loginhash{'login'}) eq 'HASH') {
11275: my ($privkey,$pubkey);
11276: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11277: $pubkey = $loginhash{'login'}{$item}{'public'};
11278: $privkey = $loginhash{'login'}{$item}{'private'};
11279: }
11280: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11281: if (!$pubkey) {
11282: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11283: } else {
11284: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11285: }
11286: if (!$privkey) {
11287: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11288: } else {
11289: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
11290: }
11291: $chgtxt .= '</ul>';
11292: $resulttext .= '<li>'.$chgtxt.'</li>';
11293: }
11294: } elsif ($item eq 'recaptchaversion') {
11295: if (ref($loginhash{'login'}) eq 'HASH') {
11296: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
11297: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
11298: '</li>';
11299: }
11300: }
11301: } else {
11302: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11303: }
11304: }
11305: $resulttext .= $colchgtext.'</ul>';
11306: } else {
11307: $resulttext = &mt('No changes made to log-in page settings');
11308: }
11309: } else {
11310: $resulttext = '<span class="LC_error">'.
11311: &mt('An error occurred: [_1]',$putresult).'</span>';
11312: }
11313: if ($errors) {
11314: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
11315: $errors.'</ul>';
11316: }
11317: return $resulttext;
11318: }
11319:
11320: sub check_exempt_addresses {
11321: my ($iplist) = @_;
11322: $iplist =~ s/^\s+//;
11323: $iplist =~ s/\s+$//;
11324: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11325: my (@okips,$new);
11326: foreach my $ip (@poss_ips) {
11327: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11328: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11329: push(@okips,$ip);
11330: }
11331: }
11332: }
11333: if (@okips > 0) {
11334: $new = join(',',@okips);
11335: } else {
11336: $new = '';
11337: }
11338: return $new;
11339: }
11340:
11341: sub color_font_choices {
11342: my %choices =
11343: &Apache::lonlocal::texthash (
11344: img => "Header",
11345: bgs => "Background colors",
11346: links => "Link colors",
11347: images => "Images",
11348: font => "Font color",
11349: fontmenu => "Font menu",
11350: pgbg => "Page",
11351: tabbg => "Header",
11352: sidebg => "Border",
11353: link => "Link",
11354: alink => "Active link",
11355: vlink => "Visited link",
11356: );
11357: return %choices;
11358: }
11359:
11360: sub modify_ipaccess {
11361: my ($dom,$lastactref,%domconfig) = @_;
11362: my (@allpos,%changes,%confhash,$errors,$resulttext);
11363: my (@items,%deletions,%itemids,@warnings);
11364: my ($typeorder,$types) = &commblocktype_text();
11365: if ($env{'form.ipaccess_add'}) {
11366: my $name = $env{'form.ipaccess_name_add'};
11367: my ($newid,$error) = &get_ipaccess_id($dom,$name);
11368: if ($newid) {
11369: $itemids{'add'} = $newid;
11370: push(@items,'add');
11371: $changes{$newid} = 1;
11372: } else {
11373: $error = &mt('Failed to acquire unique ID for new IP access control item');
11374: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11375: }
11376: }
11377: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11378: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
11379: if (@todelete) {
11380: map { $deletions{$_} = 1; } @todelete;
11381: }
11382: my $maxnum = $env{'form.ipaccess_maxnum'};
11383: for (my $i=0; $i<$maxnum; $i++) {
11384: my $itemid = $env{'form.ipaccess_id_'.$i};
11385: $itemid =~ s/\D+//g;
11386: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11387: if ($deletions{$itemid}) {
11388: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
11389: } else {
11390: push(@items,$i);
11391: $itemids{$i} = $itemid;
11392: }
11393: }
11394: }
11395: }
11396: foreach my $idx (@items) {
11397: my $itemid = $itemids{$idx};
11398: next unless ($itemid);
11399: my %current;
11400: unless ($idx eq 'add') {
11401: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11402: %current = %{$domconfig{'ipaccess'}{$itemid}};
11403: }
11404: }
11405: my $position = $env{'form.ipaccess_pos_'.$itemid};
11406: $position =~ s/\D+//g;
11407: if ($position ne '') {
11408: $allpos[$position] = $itemid;
11409: }
11410: my $name = $env{'form.ipaccess_name_'.$idx};
11411: $name =~ s/^\s+|\s+$//g;
11412: $confhash{$itemid}{'name'} = $name;
11413: my $possrange = $env{'form.ipaccess_range_'.$idx};
11414: $possrange =~ s/^\s+|\s+$//g;
11415: unless ($possrange eq '') {
11416: $possrange =~ s/[\r\n]+/\s/g;
11417: $possrange =~ s/\s*-\s*/-/g;
11418: $possrange =~ s/\s+/,/g;
11419: $possrange =~ s/,+/,/g;
11420: if ($possrange ne '') {
11421: my (@ok,$count);
11422: $count = 0;
11423: foreach my $poss (split(/\,/,$possrange)) {
11424: $count ++;
11425: $poss = &validate_ip_pattern($poss);
11426: if ($poss ne '') {
11427: push(@ok,$poss);
11428: }
11429: }
11430: my $diff = $count - scalar(@ok);
11431: if ($diff) {
11432: $errors .= '<li><span class="LC_error">'.
11433: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
11434: $diff,$name).
11435: '</span></li>';
11436: }
11437: if (@ok) {
11438: my @cidr_list;
11439: foreach my $item (@ok) {
11440: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
11441: }
11442: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
11443: }
11444: }
11445: }
11446: foreach my $field ('name','ip') {
11447: unless (($idx eq 'add') || ($changes{$itemid})) {
11448: if ($current{$field} ne $confhash{$itemid}{$field}) {
11449: $changes{$itemid} = 1;
11450: last;
11451: }
11452: }
11453: }
11454: $confhash{$itemid}{'commblocks'} = {};
11455:
11456: my %commblocks;
11457: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
11458: foreach my $type (@{$typeorder}) {
11459: if ($commblocks{$type}) {
11460: $confhash{$itemid}{'commblocks'}{$type} = 'on';
11461: }
11462: unless (($idx eq 'add') || ($changes{$itemid})) {
11463: if (ref($current{'commblocks'}) eq 'HASH') {
11464: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
11465: $changes{$itemid} = 1;
11466: }
11467: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
11468: $changes{$itemid} = 1;
11469: }
11470: }
11471: }
11472: $confhash{$itemid}{'courses'} = {};
11473: my %crsdeletions;
11474: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
11475: if (@delcrs) {
11476: map { $crsdeletions{$_} = 1; } @delcrs;
11477: }
11478: if (ref($current{'courses'}) eq 'HASH') {
11479: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
11480: if ($crsdeletions{$cid}) {
11481: $changes{$itemid} = 1;
11482: } else {
11483: $confhash{$itemid}{'courses'}{$cid} = 1;
11484: }
11485: }
11486: }
11487: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
11488: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
11489: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
11490: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
11491: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
11492: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
11493: $errors .= '<li><span class="LC_error">'.
11494: &mt('Invalid courseID [_1] omitted from list of allowed courses',
11495: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
11496: '</span></li>';
11497: } else {
11498: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
11499: $changes{$itemid} = 1;
11500: }
11501: }
11502: }
11503: if (@allpos > 0) {
11504: my $idx = 0;
11505: foreach my $itemid (@allpos) {
11506: if ($itemid ne '') {
11507: $confhash{$itemid}{'order'} = $idx;
11508: unless ($changes{$itemid}) {
11509: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11510: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11511: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
11512: $changes{$itemid} = 1;
11513: }
11514: }
11515: }
11516: }
11517: $idx ++;
11518: }
11519: }
11520: }
11521: if (keys(%changes)) {
11522: my %defaultshash = (
11523: ipaccess => \%confhash,
11524: );
11525: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11526: $dom);
11527: if ($putresult eq 'ok') {
11528: my $cachetime = 1800;
11529: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
11530: if (ref($lastactref) eq 'HASH') {
11531: $lastactref->{'ipaccess'} = 1;
11532: }
11533: $resulttext = &mt('Changes made:').'<ul>';
11534: my %bynum;
11535: foreach my $itemid (sort(keys(%changes))) {
11536: if (ref($confhash{$itemid}) eq 'HASH') {
11537: my $position = $confhash{$itemid}{'order'};
11538: if ($position =~ /^\d+$/) {
11539: $bynum{$position} = $itemid;
11540: }
11541: }
11542: }
11543: if (keys(%deletions)) {
11544: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
11545: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11546: }
11547: }
11548: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11549: my $itemid = $bynum{$pos};
11550: if (ref($confhash{$itemid}) eq 'HASH') {
11551: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
11552: my $position = $pos + 1;
11553: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11554: if ($confhash{$itemid}{'ip'} eq '') {
11555: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
11556: } else {
11557: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
11558: }
11559: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
11560: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
11561: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
11562: '</li>';
11563: } else {
11564: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
11565: }
11566: if (keys(%{$confhash{$itemid}{'courses'}})) {
11567: my @courses;
11568: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
11569: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
11570: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
11571: }
11572: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
11573: join('</li><li>',@courses).'</li></ul>';
11574: } else {
11575: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
11576: }
11577: $resulttext .= '</ul></li>';
11578: }
11579: }
11580: $resulttext .= '</ul>';
11581: } else {
11582: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11583: }
11584: } else {
11585: $resulttext = &mt('No changes made');
11586: }
11587: if ($errors) {
11588: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
11589: $errors.'</ul></p>';
11590: }
11591: return $resulttext;
11592: }
11593:
11594: sub get_ipaccess_id {
11595: my ($domain,$location) = @_;
11596: # get lock on ipaccess db
11597: my $lockhash = {
11598: lock => $env{'user.name'}.
11599: ':'.$env{'user.domain'},
11600: };
11601: my $tries = 0;
11602: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
11603: my ($id,$error);
11604:
11605: while (($gotlock ne 'ok') && ($tries<10)) {
11606: $tries ++;
11607: sleep (0.1);
11608: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
11609: }
11610: if ($gotlock eq 'ok') {
11611: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
11612: if ($currids{'lock'}) {
11613: delete($currids{'lock'});
11614: if (keys(%currids)) {
11615: my @curr = sort { $a <=> $b } keys(%currids);
11616: if ($curr[-1] =~ /^\d+$/) {
11617: $id = 1 + $curr[-1];
11618: }
11619: } else {
11620: $id = 1;
11621: }
11622: if ($id) {
11623: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
11624: $error = 'nostore';
11625: }
11626: } else {
11627: $error = 'nonumber';
11628: }
11629: }
11630: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
11631: } else {
11632: $error = 'nolock';
11633: }
11634: return ($id,$error);
11635: }
11636:
11637: sub modify_rolecolors {
11638: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
11639: my ($resulttext,%rolehash);
11640: $rolehash{'rolecolors'} = {};
11641: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
11642: if ($domconfig{'rolecolors'} eq '') {
11643: $domconfig{'rolecolors'} = {};
11644: }
11645: }
11646: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
11647: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
11648: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
11649: $dom);
11650: if ($putresult eq 'ok') {
11651: if (keys(%changes) > 0) {
11652: &Apache::loncommon::devalidate_domconfig_cache($dom);
11653: if (ref($lastactref) eq 'HASH') {
11654: $lastactref->{'domainconfig'} = 1;
11655: }
11656: $resulttext = &display_colorchgs($dom,\%changes,$roles,
11657: $rolehash{'rolecolors'});
11658: } else {
11659: $resulttext = &mt('No changes made to default color schemes');
11660: }
11661: } else {
11662: $resulttext = '<span class="LC_error">'.
11663: &mt('An error occurred: [_1]',$putresult).'</span>';
11664: }
11665: if ($errors) {
11666: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11667: $errors.'</ul>';
11668: }
11669: return $resulttext;
11670: }
11671:
11672: sub modify_colors {
11673: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
11674: my (%changes,%choices);
11675: my @bgs;
11676: my @links = ('link','alink','vlink');
11677: my @logintext;
11678: my @images;
11679: my $servadm = $r->dir_config('lonAdmEMail');
11680: my $errors;
11681: my %defaults;
11682: foreach my $role (@{$roles}) {
11683: if ($role eq 'login') {
11684: %choices = &login_choices();
11685: @logintext = ('textcol','bgcol');
11686: } else {
11687: %choices = &color_font_choices();
11688: }
11689: if ($role eq 'login') {
11690: @images = ('img','logo','domlogo','login');
11691: @bgs = ('pgbg','mainbg','sidebg');
11692: } else {
11693: @images = ('img');
11694: @bgs = ('pgbg','tabbg','sidebg');
11695: }
11696: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11697: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11698: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11699: }
11700: if ($role eq 'login') {
11701: foreach my $item (@logintext) {
11702: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11703: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11704: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11705: }
11706: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
11707: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11708: }
11709: }
11710: } else {
11711: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11712: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11713: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11714: }
11715: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
11716: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11717: }
11718: }
11719: foreach my $item (@bgs) {
11720: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11721: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11722: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11723: }
11724: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
11725: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11726: }
11727: }
11728: foreach my $item (@links) {
11729: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11730: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11731: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11732: }
11733: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
11734: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11735: }
11736: }
11737: my ($configuserok,$author_ok,$switchserver) =
11738: &config_check($dom,$confname,$servadm);
11739: my ($width,$height) = &thumb_dimensions();
11740: if (ref($domconfig->{$role}) ne 'HASH') {
11741: $domconfig->{$role} = {};
11742: }
11743: foreach my $img (@images) {
11744: if ($role eq 'login') {
11745: if (($img eq 'img') || ($img eq 'logo')) {
11746: if (defined($env{'form.login_showlogo_'.$img})) {
11747: $confhash->{$role}{'showlogo'}{$img} = 1;
11748: } else {
11749: $confhash->{$role}{'showlogo'}{$img} = 0;
11750: }
11751: }
11752: if ($env{'form.login_alt_'.$img} ne '') {
11753: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
11754: }
11755: }
11756: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11757: && !defined($domconfig->{$role}{$img})
11758: && !$env{'form.'.$role.'_del_'.$img}
11759: && $env{'form.'.$role.'_import_'.$img}) {
11760: # import the old configured image from the .tab setting
11761: # if they haven't provided a new one
11762: $domconfig->{$role}{$img} =
11763: $env{'form.'.$role.'_import_'.$img};
11764: }
11765: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
11766: my $error;
11767: if ($configuserok eq 'ok') {
11768: if ($switchserver) {
11769: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
11770: } else {
11771: if ($author_ok eq 'ok') {
11772: my $modified = [];
11773: my ($result,$logourl) =
11774: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
11775: $dom,$confname,$img,$width,$height,
11776: '',$modified);
11777: if ($result eq 'ok') {
11778: $confhash->{$role}{$img} = $logourl;
11779: $changes{$role}{'images'}{$img} = 1;
11780: &update_modify_urls($r,$modified);
11781: } else {
11782: $error = &mt("Upload of [_1] image for $role page(s) failed because an error occurred publishing the file in RES space. Error was: [_2].",$choices{img},$result);
11783: }
11784: } else {
11785: $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
11786: }
11787: }
11788: } else {
11789: $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
11790: }
11791: if ($error) {
11792: &Apache::lonnet::logthis($error);
11793: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11794: }
11795: } elsif ($domconfig->{$role}{$img} ne '') {
11796: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11797: my $error;
11798: if ($configuserok eq 'ok') {
11799: # is confname an author?
11800: if ($switchserver eq '') {
11801: if ($author_ok eq 'ok') {
11802: my $modified = [];
11803: my ($result,$logourl) =
11804: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
11805: $dom,$confname,$img,$width,$height,
11806: '',$modified);
11807: if ($result eq 'ok') {
11808: $confhash->{$role}{$img} = $logourl;
11809: $changes{$role}{'images'}{$img} = 1;
11810: &update_modify_urls($r,$modified);
11811: }
11812: }
11813: }
11814: }
11815: }
11816: }
11817: }
11818: if (ref($domconfig) eq 'HASH') {
11819: if (ref($domconfig->{$role}) eq 'HASH') {
11820: foreach my $img (@images) {
11821: if ($domconfig->{$role}{$img} ne '') {
11822: if ($env{'form.'.$role.'_del_'.$img}) {
11823: $confhash->{$role}{$img} = '';
11824: $changes{$role}{'images'}{$img} = 1;
11825: } else {
11826: if ($confhash->{$role}{$img} eq '') {
11827: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11828: }
11829: }
11830: } else {
11831: if ($env{'form.'.$role.'_del_'.$img}) {
11832: $confhash->{$role}{$img} = '';
11833: $changes{$role}{'images'}{$img} = 1;
11834: }
11835: }
11836: if ($role eq 'login') {
11837: if (($img eq 'logo') || ($img eq 'img')) {
11838: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11839: if ($confhash->{$role}{'showlogo'}{$img} ne
11840: $domconfig->{$role}{'showlogo'}{$img}) {
11841: $changes{$role}{'showlogo'}{$img} = 1;
11842: }
11843: } else {
11844: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11845: $changes{$role}{'showlogo'}{$img} = 1;
11846: }
11847: }
11848: }
11849: if ($img ne 'login') {
11850: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
11851: if ($confhash->{$role}{'alttext'}{$img} ne
11852: $domconfig->{$role}{'alttext'}{$img}) {
11853: $changes{$role}{'alttext'}{$img} = 1;
11854: }
11855: } else {
11856: if ($confhash->{$role}{'alttext'}{$img} ne '') {
11857: $changes{$role}{'alttext'}{$img} = 1;
11858: }
11859: }
11860: }
11861: }
11862: }
11863: if ($domconfig->{$role}{'font'} ne '') {
11864: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11865: $changes{$role}{'font'} = 1;
11866: }
11867: } else {
11868: if ($confhash->{$role}{'font'}) {
11869: $changes{$role}{'font'} = 1;
11870: }
11871: }
11872: if ($role ne 'login') {
11873: if ($domconfig->{$role}{'fontmenu'} ne '') {
11874: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11875: $changes{$role}{'fontmenu'} = 1;
11876: }
11877: } else {
11878: if ($confhash->{$role}{'fontmenu'}) {
11879: $changes{$role}{'fontmenu'} = 1;
11880: }
11881: }
11882: }
11883: foreach my $item (@bgs) {
11884: if ($domconfig->{$role}{$item} ne '') {
11885: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11886: $changes{$role}{'bgs'}{$item} = 1;
11887: }
11888: } else {
11889: if ($confhash->{$role}{$item}) {
11890: $changes{$role}{'bgs'}{$item} = 1;
11891: }
11892: }
11893: }
11894: foreach my $item (@links) {
11895: if ($domconfig->{$role}{$item} ne '') {
11896: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11897: $changes{$role}{'links'}{$item} = 1;
11898: }
11899: } else {
11900: if ($confhash->{$role}{$item}) {
11901: $changes{$role}{'links'}{$item} = 1;
11902: }
11903: }
11904: }
11905: foreach my $item (@logintext) {
11906: if ($domconfig->{$role}{$item} ne '') {
11907: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11908: $changes{$role}{'logintext'}{$item} = 1;
11909: }
11910: } else {
11911: if ($confhash->{$role}{$item}) {
11912: $changes{$role}{'logintext'}{$item} = 1;
11913: }
11914: }
11915: }
11916: } else {
11917: &default_change_checker($role,\@images,\@links,\@bgs,
11918: \@logintext,$confhash,\%changes);
11919: }
11920: } else {
11921: &default_change_checker($role,\@images,\@links,\@bgs,
11922: \@logintext,$confhash,\%changes);
11923: }
11924: }
11925: return ($errors,%changes);
11926: }
11927:
11928: sub config_check {
11929: my ($dom,$confname,$servadm) = @_;
11930: my ($configuserok,$author_ok,$switchserver,%currroles);
11931: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11932: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11933: $confname,$servadm);
11934: if ($configuserok eq 'ok') {
11935: $switchserver = &check_switchserver($dom,$confname);
11936: if ($switchserver eq '') {
11937: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11938: }
11939: }
11940: return ($configuserok,$author_ok,$switchserver);
11941: }
11942:
11943: sub default_change_checker {
11944: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
11945: foreach my $item (@{$links}) {
11946: if ($confhash->{$role}{$item}) {
11947: $changes->{$role}{'links'}{$item} = 1;
11948: }
11949: }
11950: foreach my $item (@{$bgs}) {
11951: if ($confhash->{$role}{$item}) {
11952: $changes->{$role}{'bgs'}{$item} = 1;
11953: }
11954: }
11955: foreach my $item (@{$logintext}) {
11956: if ($confhash->{$role}{$item}) {
11957: $changes->{$role}{'logintext'}{$item} = 1;
11958: }
11959: }
11960: foreach my $img (@{$images}) {
11961: if ($env{'form.'.$role.'_del_'.$img}) {
11962: $confhash->{$role}{$img} = '';
11963: $changes->{$role}{'images'}{$img} = 1;
11964: }
11965: if ($role eq 'login') {
11966: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11967: $changes->{$role}{'showlogo'}{$img} = 1;
11968: }
11969: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
11970: if ($confhash->{$role}{'alttext'}{$img} ne '') {
11971: $changes->{$role}{'alttext'}{$img} = 1;
11972: }
11973: }
11974: }
11975: }
11976: if ($confhash->{$role}{'font'}) {
11977: $changes->{$role}{'font'} = 1;
11978: }
11979: }
11980:
11981: sub display_colorchgs {
11982: my ($dom,$changes,$roles,$confhash) = @_;
11983: my (%choices,$resulttext);
11984: if (!grep(/^login$/,@{$roles})) {
11985: $resulttext = &mt('Changes made:').'<br />';
11986: }
11987: foreach my $role (@{$roles}) {
11988: if ($role eq 'login') {
11989: %choices = &login_choices();
11990: } else {
11991: %choices = &color_font_choices();
11992: }
11993: if (ref($changes->{$role}) eq 'HASH') {
11994: if ($role ne 'login') {
11995: $resulttext .= '<h4>'.&mt($role).'</h4>';
11996: }
11997: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11998: if ($role ne 'login') {
11999: $resulttext .= '<ul>';
12000: }
12001: if (ref($changes->{$role}{$key}) eq 'HASH') {
12002: if ($role ne 'login') {
12003: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12004: }
12005: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
12006: if (($role eq 'login') && ($key eq 'showlogo')) {
12007: if ($confhash->{$role}{$key}{$item}) {
12008: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12009: } else {
12010: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12011: }
12012: } elsif (($role eq 'login') && ($key eq 'alttext')) {
12013: if ($confhash->{$role}{$key}{$item} ne '') {
12014: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
12015: $confhash->{$role}{$key}{$item}).'</li>';
12016: } else {
12017: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
12018: }
12019: } elsif ($confhash->{$role}{$item} eq '') {
12020: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12021: } else {
12022: my $newitem = $confhash->{$role}{$item};
12023: if ($key eq 'images') {
12024: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
12025: }
12026: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
12027: }
12028: }
12029: if ($role ne 'login') {
12030: $resulttext .= '</ul></li>';
12031: }
12032: } else {
12033: if ($confhash->{$role}{$key} eq '') {
12034: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12035: } else {
12036: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12037: }
12038: }
12039: if ($role ne 'login') {
12040: $resulttext .= '</ul>';
12041: }
12042: }
12043: }
12044: }
12045: return $resulttext;
12046: }
12047:
12048: sub thumb_dimensions {
12049: return ('200','50');
12050: }
12051:
12052: sub check_dimensions {
12053: my ($inputfile) = @_;
12054: my ($fullwidth,$fullheight);
12055: if ($inputfile =~ m|^[/\w.\-]+$|) {
12056: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12057: my $imageinfo = <PIPE>;
12058: if (!close(PIPE)) {
12059: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12060: }
12061: chomp($imageinfo);
12062: my ($fullsize) =
12063: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
12064: if ($fullsize) {
12065: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12066: }
12067: }
12068: }
12069: return ($fullwidth,$fullheight);
12070: }
12071:
12072: sub check_configuser {
12073: my ($uhome,$dom,$confname,$servadm) = @_;
12074: my ($configuserok,%currroles);
12075: if ($uhome eq 'no_host') {
12076: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
12077: my $configpass = &LONCAPA::Enrollment::create_password($dom);
12078: $configuserok =
12079: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12080: $configpass,'','','','','',undef,$servadm);
12081: } else {
12082: $configuserok = 'ok';
12083: %currroles =
12084: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12085: }
12086: return ($configuserok,%currroles);
12087: }
12088:
12089: sub check_authorstatus {
12090: my ($dom,$confname,%currroles) = @_;
12091: my $author_ok;
12092: if (!$currroles{':'.$dom.':au'}) {
12093: my $start = time;
12094: my $end = 0;
12095: $author_ok =
12096: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
12097: 'au',$end,$start,'','','domconfig');
12098: } else {
12099: $author_ok = 'ok';
12100: }
12101: return $author_ok;
12102: }
12103:
12104: sub update_modify_urls {
12105: my ($r,$modified) = @_;
12106: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
12107: push(@{$modified_urls},$modified);
12108: unless ($registered_cleanup) {
12109: my $handlers = $r->get_handlers('PerlCleanupHandler');
12110: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12111: $registered_cleanup=1;
12112: }
12113: }
12114: }
12115:
12116: sub notifysubscribed {
12117: foreach my $targetsource (@{$modified_urls}){
12118: next unless (ref($targetsource) eq 'ARRAY');
12119: my ($target,$source)=@{$targetsource};
12120: if ($source ne '') {
12121: if (open(my $logfh,">>",$source.'.log')) {
12122: print $logfh "\nCleanup phase: Notifications\n";
12123: my @subscribed=&subscribed_hosts($target);
12124: foreach my $subhost (@subscribed) {
12125: print $logfh "\nNotifying host ".$subhost.':';
12126: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12127: print $logfh $reply;
12128: }
12129: my @subscribedmeta=&subscribed_hosts("$target.meta");
12130: foreach my $subhost (@subscribedmeta) {
12131: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12132: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12133: $subhost);
12134: print $logfh $reply;
12135: }
12136: print $logfh "\n============ Done ============\n";
12137: close($logfh);
12138: }
12139: }
12140: }
12141: return OK;
12142: }
12143:
12144: sub subscribed_hosts {
12145: my ($target) = @_;
12146: my @subscribed;
12147: if (open(my $fh,"<","$target.subscription")) {
12148: while (my $subline=<$fh>) {
12149: if ($subline =~ /^($match_lonid):/) {
12150: my $host = $1;
12151: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12152: unless (grep(/^\Q$host\E$/,@subscribed)) {
12153: push(@subscribed,$host);
12154: }
12155: }
12156: }
12157: }
12158: }
12159: return @subscribed;
12160: }
12161:
12162: sub check_switchserver {
12163: my ($dom,$confname) = @_;
12164: my ($allowed,$switchserver,$home);
12165: if ($confname eq '') {
12166: $home = &Apache::lonnet::domain($dom,'primary');
12167: } else {
12168: $home = &Apache::lonnet::homeserver($confname,$dom);
12169: if ($home eq 'no_host') {
12170: $home = &Apache::lonnet::domain($dom,'primary');
12171: }
12172: }
12173: my @ids=&Apache::lonnet::current_machine_ids();
12174: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12175: if (!$allowed) {
12176: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
12177: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
12178: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
12179: }
12180: return $switchserver;
12181: }
12182:
12183: sub modify_quotas {
12184: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12185: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
12186: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
12187: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12188: $validationfieldsref);
12189: if ($action eq 'quotas') {
12190: $context = 'tools';
12191: } else {
12192: $context = $action;
12193: }
12194: if ($context eq 'requestcourses') {
12195: @usertools = ('official','unofficial','community','textbook','lti');
12196: @options =('norequest','approval','validate','autolimit');
12197: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12198: %titles = &courserequest_titles();
12199: $toolregexp = join('|',@usertools);
12200: %conditions = &courserequest_conditions();
12201: $confname = $dom.'-domainconfig';
12202: my $servadm = $r->dir_config('lonAdmEMail');
12203: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12204: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12205: &Apache::loncoursequeueadmin::requestcourses_validation_types();
12206: } elsif ($context eq 'requestauthor') {
12207: @usertools = ('author');
12208: %titles = &authorrequest_titles();
12209: } else {
12210: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
12211: %titles = &tool_titles();
12212: }
12213: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12214: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12215: foreach my $key (keys(%env)) {
12216: if ($context eq 'requestcourses') {
12217: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12218: my $item = $1;
12219: my $type = $2;
12220: if ($type =~ /^limit_(.+)/) {
12221: $limithash{$item}{$1} = $env{$key};
12222: } else {
12223: $confhash{$item}{$type} = $env{$key};
12224: }
12225: }
12226: } elsif ($context eq 'requestauthor') {
12227: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12228: $confhash{$1} = $env{$key};
12229: }
12230: } else {
12231: if ($key =~ /^form\.quota_(.+)$/) {
12232: $confhash{'defaultquota'}{$1} = $env{$key};
12233: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12234: $confhash{'authorquota'}{$1} = $env{$key};
12235: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
12236: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12237: }
12238: }
12239: }
12240: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
12241: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
12242: @approvalnotify = sort(@approvalnotify);
12243: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
12244: my @crstypes = ('official','unofficial','community','textbook','lti');
12245: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12246: foreach my $type (@hasuniquecode) {
12247: if (grep(/^\Q$type\E$/,@crstypes)) {
12248: $confhash{'uniquecode'}{$type} = 1;
12249: }
12250: }
12251: my (%newbook,%allpos);
12252: if ($context eq 'requestcourses') {
12253: foreach my $type ('textbooks','templates') {
12254: @{$allpos{$type}} = ();
12255: my $invalid;
12256: if ($type eq 'textbooks') {
12257: $invalid = &mt('Invalid LON-CAPA course for textbook');
12258: } else {
12259: $invalid = &mt('Invalid LON-CAPA course for template');
12260: }
12261: if ($env{'form.'.$type.'_addbook'}) {
12262: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12263: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12264: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12265: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12266: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12267: } else {
12268: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12269: my $position = $env{'form.'.$type.'_addbook_pos'};
12270: $position =~ s/\D+//g;
12271: if ($position ne '') {
12272: $allpos{$type}[$position] = $newbook{$type};
12273: }
12274: }
12275: } else {
12276: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12277: }
12278: }
12279: }
12280: }
12281: if (ref($domconfig{$action}) eq 'HASH') {
12282: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12283: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12284: $changes{'notify'}{'approval'} = 1;
12285: }
12286: } else {
12287: if ($confhash{'notify'}{'approval'}) {
12288: $changes{'notify'}{'approval'} = 1;
12289: }
12290: }
12291: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12292: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12293: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12294: unless ($confhash{'uniquecode'}{$crstype}) {
12295: $changes{'uniquecode'} = 1;
12296: }
12297: }
12298: unless ($changes{'uniquecode'}) {
12299: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12300: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12301: $changes{'uniquecode'} = 1;
12302: }
12303: }
12304: }
12305: } else {
12306: $changes{'uniquecode'} = 1;
12307: }
12308: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12309: $changes{'uniquecode'} = 1;
12310: }
12311: if ($context eq 'requestcourses') {
12312: foreach my $type ('textbooks','templates') {
12313: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12314: my %deletions;
12315: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12316: if (@todelete) {
12317: map { $deletions{$_} = 1; } @todelete;
12318: }
12319: my %imgdeletions;
12320: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12321: if (@todeleteimages) {
12322: map { $imgdeletions{$_} = 1; } @todeleteimages;
12323: }
12324: my $maxnum = $env{'form.'.$type.'_maxnum'};
12325: for (my $i=0; $i<=$maxnum; $i++) {
12326: my $itemid = $env{'form.'.$type.'_id_'.$i};
12327: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12328: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12329: if ($deletions{$key}) {
12330: if ($domconfig{$action}{$type}{$key}{'image'}) {
12331: #FIXME need to obsolete item in RES space
12332: }
12333: next;
12334: } else {
12335: my $newpos = $env{'form.'.$itemid};
12336: $newpos =~ s/\D+//g;
12337: foreach my $item ('subject','title','publisher','author') {
12338: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12339: ($type eq 'templates'));
12340: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12341: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12342: $changes{$type}{$key} = 1;
12343: }
12344: }
12345: $allpos{$type}[$newpos] = $key;
12346: }
12347: if ($imgdeletions{$key}) {
12348: $changes{$type}{$key} = 1;
12349: #FIXME need to obsolete item in RES space
12350: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12351: my ($cdom,$cnum) = split(/_/,$key);
12352: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12353: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12354: } else {
12355: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12356: $cdom,$cnum,$type,$configuserok,
12357: $switchserver,$author_ok);
12358: if ($imgurl) {
12359: $confhash{$type}{$key}{'image'} = $imgurl;
12360: $changes{$type}{$key} = 1;
12361: }
12362: if ($error) {
12363: &Apache::lonnet::logthis($error);
12364: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12365: }
12366: }
12367: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12368: $confhash{$type}{$key}{'image'} =
12369: $domconfig{$action}{$type}{$key}{'image'};
12370: }
12371: }
12372: }
12373: }
12374: }
12375: }
12376: } else {
12377: if ($confhash{'notify'}{'approval'}) {
12378: $changes{'notify'}{'approval'} = 1;
12379: }
12380: if (ref($confhash{'uniquecode'} eq 'HASH')) {
12381: $changes{'uniquecode'} = 1;
12382: }
12383: }
12384: if ($context eq 'requestcourses') {
12385: foreach my $type ('textbooks','templates') {
12386: if ($newbook{$type}) {
12387: $changes{$type}{$newbook{$type}} = 1;
12388: foreach my $item ('subject','title','publisher','author') {
12389: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12390: ($type eq 'template'));
12391: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
12392: if ($env{'form.'.$type.'_addbook_'.$item}) {
12393: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
12394: }
12395: }
12396: if ($type eq 'textbooks') {
12397: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
12398: my ($cdom,$cnum) = split(/_/,$newbook{$type});
12399: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12400: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12401: } else {
12402: my ($imageurl,$error) =
12403: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
12404: $configuserok,$switchserver,$author_ok);
12405: if ($imageurl) {
12406: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
12407: }
12408: if ($error) {
12409: &Apache::lonnet::logthis($error);
12410: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12411: }
12412: }
12413: }
12414: }
12415: }
12416: if (@{$allpos{$type}} > 0) {
12417: my $idx = 0;
12418: foreach my $item (@{$allpos{$type}}) {
12419: if ($item ne '') {
12420: $confhash{$type}{$item}{'order'} = $idx;
12421: if (ref($domconfig{$action}) eq 'HASH') {
12422: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12423: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
12424: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
12425: $changes{$type}{$item} = 1;
12426: }
12427: }
12428: }
12429: }
12430: $idx ++;
12431: }
12432: }
12433: }
12434: }
12435: if (ref($validationitemsref) eq 'ARRAY') {
12436: foreach my $item (@{$validationitemsref}) {
12437: if ($item eq 'fields') {
12438: my @changed;
12439: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
12440: if (@{$confhash{'validation'}{$item}} > 0) {
12441: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
12442: }
12443: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12444: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12445: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
12446: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
12447: $domconfig{'requestcourses'}{'validation'}{$item});
12448: } else {
12449: @changed = @{$confhash{'validation'}{$item}};
12450: }
12451: } else {
12452: @changed = @{$confhash{'validation'}{$item}};
12453: }
12454: } else {
12455: @changed = @{$confhash{'validation'}{$item}};
12456: }
12457: if (@changed) {
12458: if ($confhash{'validation'}{$item}) {
12459: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
12460: } else {
12461: $changes{'validation'}{$item} = &mt('None');
12462: }
12463: }
12464: } else {
12465: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
12466: if ($item eq 'markup') {
12467: if ($env{'form.requestcourses_validation_'.$item}) {
12468: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12469: }
12470: }
12471: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12472: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12473: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
12474: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12475: }
12476: } else {
12477: if ($confhash{'validation'}{$item} ne '') {
12478: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12479: }
12480: }
12481: } else {
12482: if ($confhash{'validation'}{$item} ne '') {
12483: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12484: }
12485: }
12486: }
12487: }
12488: }
12489: if ($env{'form.validationdc'}) {
12490: my $newval = $env{'form.validationdc'};
12491: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
12492: if (exists($domcoords{$newval})) {
12493: $confhash{'validation'}{'dc'} = $newval;
12494: }
12495: }
12496: if (ref($confhash{'validation'}) eq 'HASH') {
12497: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12498: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12499: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12500: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12501: if ($confhash{'validation'}{'dc'} eq '') {
12502: $changes{'validation'}{'dc'} = &mt('None');
12503: } else {
12504: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12505: }
12506: }
12507: } elsif ($confhash{'validation'}{'dc'} ne '') {
12508: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12509: }
12510: } elsif ($confhash{'validation'}{'dc'} ne '') {
12511: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12512: }
12513: } elsif ($confhash{'validation'}{'dc'} ne '') {
12514: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12515: }
12516: } else {
12517: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12518: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12519: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12520: $changes{'validation'}{'dc'} = &mt('None');
12521: }
12522: }
12523: }
12524: }
12525: }
12526: } else {
12527: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
12528: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
12529: }
12530: foreach my $item (@usertools) {
12531: foreach my $type (@{$types},'default','_LC_adv') {
12532: my $unset;
12533: if ($context eq 'requestcourses') {
12534: $unset = '0';
12535: if ($type eq '_LC_adv') {
12536: $unset = '';
12537: }
12538: if ($confhash{$item}{$type} eq 'autolimit') {
12539: $confhash{$item}{$type} .= '=';
12540: unless ($limithash{$item}{$type} =~ /\D/) {
12541: $confhash{$item}{$type} .= $limithash{$item}{$type};
12542: }
12543: }
12544: } elsif ($context eq 'requestauthor') {
12545: $unset = '0';
12546: if ($type eq '_LC_adv') {
12547: $unset = '';
12548: }
12549: } else {
12550: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12551: $confhash{$item}{$type} = 1;
12552: } else {
12553: $confhash{$item}{$type} = 0;
12554: }
12555: }
12556: if (ref($domconfig{$action}) eq 'HASH') {
12557: if ($action eq 'requestauthor') {
12558: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12559: $changes{$type} = 1;
12560: }
12561: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
12562: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12563: $changes{$item}{$type} = 1;
12564: }
12565: } else {
12566: if ($context eq 'requestcourses') {
12567: if ($confhash{$item}{$type} ne $unset) {
12568: $changes{$item}{$type} = 1;
12569: }
12570: } else {
12571: if (!$confhash{$item}{$type}) {
12572: $changes{$item}{$type} = 1;
12573: }
12574: }
12575: }
12576: } else {
12577: if ($context eq 'requestcourses') {
12578: if ($confhash{$item}{$type} ne $unset) {
12579: $changes{$item}{$type} = 1;
12580: }
12581: } elsif ($context eq 'requestauthor') {
12582: if ($confhash{$type} ne $unset) {
12583: $changes{$type} = 1;
12584: }
12585: } else {
12586: if (!$confhash{$item}{$type}) {
12587: $changes{$item}{$type} = 1;
12588: }
12589: }
12590: }
12591: }
12592: }
12593: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
12594: if (ref($domconfig{'quotas'}) eq 'HASH') {
12595: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12596: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12597: if (exists($confhash{'defaultquota'}{$key})) {
12598: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12599: $changes{'defaultquota'}{$key} = 1;
12600: }
12601: } else {
12602: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
12603: }
12604: }
12605: } else {
12606: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12607: if (exists($confhash{'defaultquota'}{$key})) {
12608: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12609: $changes{'defaultquota'}{$key} = 1;
12610: }
12611: } else {
12612: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
12613: }
12614: }
12615: }
12616: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12617: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12618: if (exists($confhash{'authorquota'}{$key})) {
12619: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12620: $changes{'authorquota'}{$key} = 1;
12621: }
12622: } else {
12623: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12624: }
12625: }
12626: }
12627: }
12628: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12629: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12630: if (ref($domconfig{'quotas'}) eq 'HASH') {
12631: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12632: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12633: $changes{'defaultquota'}{$key} = 1;
12634: }
12635: } else {
12636: if (!exists($domconfig{'quotas'}{$key})) {
12637: $changes{'defaultquota'}{$key} = 1;
12638: }
12639: }
12640: } else {
12641: $changes{'defaultquota'}{$key} = 1;
12642: }
12643: }
12644: }
12645: if (ref($confhash{'authorquota'}) eq 'HASH') {
12646: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12647: if (ref($domconfig{'quotas'}) eq 'HASH') {
12648: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12649: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12650: $changes{'authorquota'}{$key} = 1;
12651: }
12652: } else {
12653: $changes{'authorquota'}{$key} = 1;
12654: }
12655: } else {
12656: $changes{'authorquota'}{$key} = 1;
12657: }
12658: }
12659: }
12660: }
12661:
12662: if ($context eq 'requestauthor') {
12663: $domdefaults{'requestauthor'} = \%confhash;
12664: } else {
12665: foreach my $key (keys(%confhash)) {
12666: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
12667: $domdefaults{$key} = $confhash{$key};
12668: }
12669: }
12670: }
12671:
12672: my %quotahash = (
12673: $action => { %confhash }
12674: );
12675: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12676: $dom);
12677: if ($putresult eq 'ok') {
12678: if (keys(%changes) > 0) {
12679: my $cachetime = 24*60*60;
12680: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12681: if (ref($lastactref) eq 'HASH') {
12682: $lastactref->{'domdefaults'} = 1;
12683: }
12684: $resulttext = &mt('Changes made:').'<ul>';
12685: unless (($context eq 'requestcourses') ||
12686: ($context eq 'requestauthor')) {
12687: if (ref($changes{'defaultquota'}) eq 'HASH') {
12688: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12689: foreach my $type (@{$types},'default') {
12690: if (defined($changes{'defaultquota'}{$type})) {
12691: my $typetitle = $usertypes->{$type};
12692: if ($type eq 'default') {
12693: $typetitle = $othertitle;
12694: }
12695: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
12696: }
12697: }
12698: $resulttext .= '</ul></li>';
12699: }
12700: if (ref($changes{'authorquota'}) eq 'HASH') {
12701: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
12702: foreach my $type (@{$types},'default') {
12703: if (defined($changes{'authorquota'}{$type})) {
12704: my $typetitle = $usertypes->{$type};
12705: if ($type eq 'default') {
12706: $typetitle = $othertitle;
12707: }
12708: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
12709: }
12710: }
12711: $resulttext .= '</ul></li>';
12712: }
12713: }
12714: my %newenv;
12715: foreach my $item (@usertools) {
12716: my (%haschgs,%inconf);
12717: if ($context eq 'requestauthor') {
12718: %haschgs = %changes;
12719: %inconf = %confhash;
12720: } else {
12721: if (ref($changes{$item}) eq 'HASH') {
12722: %haschgs = %{$changes{$item}};
12723: }
12724: if (ref($confhash{$item}) eq 'HASH') {
12725: %inconf = %{$confhash{$item}};
12726: }
12727: }
12728: if (keys(%haschgs) > 0) {
12729: my $newacc =
12730: &Apache::lonnet::usertools_access($env{'user.name'},
12731: $env{'user.domain'},
12732: $item,'reload',$context);
12733: if (($context eq 'requestcourses') ||
12734: ($context eq 'requestauthor')) {
12735: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12736: $newenv{'environment.canrequest.'.$item} = $newacc;
12737: }
12738: } else {
12739: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12740: $newenv{'environment.availabletools.'.$item} = $newacc;
12741: }
12742: }
12743: unless ($context eq 'requestauthor') {
12744: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12745: }
12746: foreach my $type (@{$types},'default','_LC_adv') {
12747: if ($haschgs{$type}) {
12748: my $typetitle = $usertypes->{$type};
12749: if ($type eq 'default') {
12750: $typetitle = $othertitle;
12751: } elsif ($type eq '_LC_adv') {
12752: $typetitle = 'LON-CAPA Advanced Users';
12753: }
12754: if ($inconf{$type}) {
12755: if ($context eq 'requestcourses') {
12756: my $cond;
12757: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
12758: if ($1 eq '') {
12759: $cond = &mt('(Automatic processing of any request).');
12760: } else {
12761: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12762: }
12763: } else {
12764: $cond = $conditions{$inconf{$type}};
12765: }
12766: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
12767: } elsif ($context eq 'requestauthor') {
12768: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12769: $titles{$inconf{$type}},$typetitle);
12770:
12771: } else {
12772: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12773: }
12774: } else {
12775: if ($type eq '_LC_adv') {
12776: if ($inconf{$type} eq '0') {
12777: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12778: } else {
12779: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12780: }
12781: } else {
12782: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12783: }
12784: }
12785: }
12786: }
12787: unless ($context eq 'requestauthor') {
12788: $resulttext .= '</ul></li>';
12789: }
12790: }
12791: }
12792: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
12793: if (ref($changes{'notify'}) eq 'HASH') {
12794: if ($changes{'notify'}{'approval'}) {
12795: if (ref($confhash{'notify'}) eq 'HASH') {
12796: if ($confhash{'notify'}{'approval'}) {
12797: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12798: } else {
12799: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
12800: }
12801: }
12802: }
12803: }
12804: }
12805: if ($action eq 'requestcourses') {
12806: my @offon = ('off','on');
12807: if ($changes{'uniquecode'}) {
12808: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12809: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12810: $resulttext .= '<li>'.
12811: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12812: '</li>';
12813: } else {
12814: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12815: '</li>';
12816: }
12817: }
12818: foreach my $type ('textbooks','templates') {
12819: if (ref($changes{$type}) eq 'HASH') {
12820: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12821: foreach my $key (sort(keys(%{$changes{$type}}))) {
12822: my %coursehash = &Apache::lonnet::coursedescription($key);
12823: my $coursetitle = $coursehash{'description'};
12824: my $position = $confhash{$type}{$key}{'order'} + 1;
12825: $resulttext .= '<li>';
12826: foreach my $item ('subject','title','publisher','author') {
12827: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12828: ($type eq 'templates'));
12829: my $name = $item.':';
12830: $name =~ s/^(\w)/\U$1/;
12831: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12832: }
12833: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12834: if ($type eq 'textbooks') {
12835: if ($confhash{$type}{$key}{'image'}) {
12836: $resulttext .= ' '.&mt('Image: [_1]',
12837: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12838: ' alt="Textbook cover" />').'<br />';
12839: }
12840: }
12841: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
12842: }
12843: $resulttext .= '</ul></li>';
12844: }
12845: }
12846: if (ref($changes{'validation'}) eq 'HASH') {
12847: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12848: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12849: foreach my $item (@{$validationitemsref}) {
12850: if (exists($changes{'validation'}{$item})) {
12851: if ($item eq 'markup') {
12852: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12853: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12854: } else {
12855: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12856: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12857: }
12858: }
12859: }
12860: if (exists($changes{'validation'}{'dc'})) {
12861: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12862: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12863: }
12864: }
12865: }
12866: }
12867: $resulttext .= '</ul>';
12868: if (keys(%newenv)) {
12869: &Apache::lonnet::appenv(\%newenv);
12870: }
12871: } else {
12872: if ($context eq 'requestcourses') {
12873: $resulttext = &mt('No changes made to rights to request creation of courses.');
12874: } elsif ($context eq 'requestauthor') {
12875: $resulttext = &mt('No changes made to rights to request author space.');
12876: } else {
12877: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
12878: }
12879: }
12880: } else {
12881: $resulttext = '<span class="LC_error">'.
12882: &mt('An error occurred: [_1]',$putresult).'</span>';
12883: }
12884: if ($errors) {
12885: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12886: '<ul>'.$errors.'</ul></p>';
12887: }
12888: return $resulttext;
12889: }
12890:
12891: sub process_textbook_image {
12892: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
12893: my $filename = $env{'form.'.$caller.'.filename'};
12894: my ($error,$url);
12895: my ($width,$height) = (50,50);
12896: if ($configuserok eq 'ok') {
12897: if ($switchserver) {
12898: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12899: $switchserver);
12900: } elsif ($author_ok eq 'ok') {
12901: my $modified = [];
12902: my ($result,$imageurl) =
12903: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
12904: "$type/$cdom/$cnum/cover",$width,$height,
12905: '',$modified);
12906: if ($result eq 'ok') {
12907: $url = $imageurl;
12908: &update_modify_urls($r,$modified);
12909: } else {
12910: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12911: }
12912: } else {
12913: $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$author_ok);
12914: }
12915: } else {
12916: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$configuserok);
12917: }
12918: return ($url,$error);
12919: }
12920:
12921: sub modify_ltitools {
12922: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12923: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
12924: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
12925:
12926: my $confname = $dom.'-domainconfig';
12927: my $servadm = $r->dir_config('lonAdmEMail');
12928: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12929:
12930: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
12931: my $toolserror =
12932: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
12933: $lastactref,$configuserok,$switchserver,$author_ok);
12934:
12935: my $home = &Apache::lonnet::domain($dom,'primary');
12936: unless (($home eq 'no_host') || ($home eq '')) {
12937: my @ids=&Apache::lonnet::current_machine_ids();
12938: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
12939: }
12940:
12941: if (keys(%ltitoolschg)) {
12942: foreach my $id (keys(%ltitoolschg)) {
12943: if (ref($ltitoolschg{$id}) eq 'HASH') {
12944: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
12945: if (($inner eq 'secret') || ($inner eq 'key')) {
12946: if ($is_home) {
12947: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
12948: }
12949: }
12950: }
12951: }
12952: }
12953: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
12954: if (keys(%ltitoolschg)) {
12955: %newltitools = %ltitoolschg;
12956: }
12957: }
12958: if (ref($domconfig{'ltitools'}) eq 'HASH') {
12959: foreach my $id (%{$domconfig{'ltitools'}}) {
12960: next if ($id !~ /^\d+$/);
12961: unless (exists($ltitoolschg{$id})) {
12962: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
12963: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
12964: if (($inner eq 'secret') || ($inner eq 'key')) {
12965: if ($is_home) {
12966: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
12967: }
12968: } else {
12969: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
12970: }
12971: }
12972: } else {
12973: $newltitools{$id} = $domconfig{'ltitools'}{$id};
12974: }
12975: }
12976: }
12977: }
12978: if ($toolserror) {
12979: $errors = '<li>'.$toolserror.'</li>';
12980: }
12981: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
12982: $resulttext = &mt('No changes made.');
12983: if ($errors) {
12984: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
12985: $errors.'</ul>';
12986: }
12987: return $resulttext;
12988: }
12989: my %ltitoolshash = (
12990: $action => { %newltitools }
12991: );
12992: if (keys(%secchanges)) {
12993: $ltitoolshash{'toolsec'} = \%newtoolsec;
12994: }
12995: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
12996: if ($putresult eq 'ok') {
12997: my %keystore;
12998: if ($is_home) {
12999: my %toolsenchash = (
13000: $action => { %newtoolsenc }
13001: );
13002: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
13003: my $cachetime = 24*60*60;
13004: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
13005: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
13006: }
13007: $resulttext = &mt('Changes made:').'<ul>';
13008: if (keys(%secchanges) > 0) {
13009: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
13010: }
13011: if (keys(%ltitoolschg) > 0) {
13012: $resulttext .= $ltitoolsoutput;
13013: }
13014: my $cachetime = 24*60*60;
13015: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
13016: if (ref($lastactref) eq 'HASH') {
13017: $lastactref->{'ltitools'} = 1;
13018: }
13019: } else {
13020: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13021: }
13022: if ($errors) {
13023: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13024: $errors.'</ul></p>';
13025: }
13026: return $resulttext;
13027: }
13028:
13029: sub fetch_secrets {
13030: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
13031: my %keyset;
13032: %{$currsec} = ();
13033: $newsec->{'private'}{'keys'} = [];
13034: $newsec->{'encrypt'} = {};
13035: $newsec->{'rules'} = {};
13036: if ($context eq 'ltisec') {
13037: $newsec->{'linkprot'} = {};
13038: }
13039: if (ref($domconfig->{$context}) eq 'HASH') {
13040: %{$currsec} = %{$domconfig->{$context}};
13041: if ($context eq 'ltisec') {
13042: if (ref($currsec->{'linkprot'}) eq 'HASH') {
13043: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
13044: unless ($id =~ /^\d+$/) {
13045: delete($currsec->{'linkprot'}{$id});
13046: }
13047: }
13048: }
13049: }
13050: if (ref($currsec->{'private'}) eq 'HASH') {
13051: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
13052: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
13053: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
13054: }
13055: }
13056: }
13057: my @items= ('crs','dom');
13058: if ($context eq 'ltisec') {
13059: push(@items,'consumers');
13060: }
13061: foreach my $item (@items) {
13062: my $formelement;
13063: if (($context eq 'toolsec') || ($item eq 'consumers')) {
13064: $formelement = 'form.'.$context.'_'.$item;
13065: } else {
13066: $formelement = 'form.'.$context.'_'.$item.'linkprot';
13067: }
13068: if ($env{$formelement}) {
13069: $newsec->{'encrypt'}{$item} = 1;
13070: if (ref($currsec->{'encrypt'}) eq 'HASH') {
13071: unless ($currsec->{'encrypt'}{$item}) {
13072: $secchanges->{'encrypt'} = 1;
13073: }
13074: } else {
13075: $secchanges->{'encrypt'} = 1;
13076: }
13077: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
13078: if ($currsec->{'encrypt'}{$item}) {
13079: $secchanges->{'encrypt'} = 1;
13080: }
13081: }
13082: }
13083: my $secrets;
13084: if ($context eq 'ltisec') {
13085: $secrets = 'ltisecrets';
13086: } else {
13087: $secrets = 'toolsecrets';
13088: }
13089: unless (exists($currsec->{'rules'})) {
13090: $currsec->{'rules'} = {};
13091: }
13092: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
13093:
13094: my @ids=&Apache::lonnet::current_machine_ids();
13095: my %servers = &Apache::lonnet::get_servers($dom,'library');
13096:
13097: foreach my $hostid (keys(%servers)) {
13098: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13099: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
13100: if (exists($env{$keyitem})) {
13101: $env{$keyitem} =~ s/(`)/'/g;
13102: if ($keyset{$hostid}) {
13103: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
13104: if ($env{$keyitem} ne '') {
13105: $secchanges->{'private'} = 1;
13106: $newkeyset->{$hostid} = $env{$keyitem};
13107: }
13108: }
13109: } elsif ($env{$keyitem} ne '') {
13110: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
13111: push(@{$newsec->{'private'}{'keys'}},$hostid);
13112: }
13113: $secchanges->{'private'} = 1;
13114: $newkeyset->{$hostid} = $env{$keyitem};
13115: }
13116: }
13117: }
13118: }
13119: }
13120:
13121: sub store_security {
13122: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
13123: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
13124: (ref($keystore) eq 'HASH'));
13125: if (keys(%{$secchanges})) {
13126: if ($secchanges->{'private'}) {
13127: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13128: foreach my $hostid (keys(%{$newkeyset})) {
13129: my $storehash = {
13130: key => $newkeyset->{$hostid},
13131: who => $env{'user.name'}.':'.$env{'user.domain'},
13132: };
13133: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
13134: $dom,$hostid);
13135: }
13136: }
13137: }
13138: }
13139:
13140: sub lti_security_results {
13141: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
13142: my $output;
13143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13144: my $needs_update;
13145: foreach my $item (keys(%{$secchanges})) {
13146: if ($item eq 'encrypt') {
13147: $needs_update = 1;
13148: my %encrypted;
13149: if ($context eq 'lti') {
13150: %encrypted = (
13151: crs => {
13152: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13153: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13154: },
13155: dom => {
13156: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13157: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13158: },
13159: consumers => {
13160: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
13161: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
13162: },
13163: );
13164: } else {
13165: %encrypted = (
13166: crs => {
13167: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
13168: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
13169: },
13170: dom => {
13171: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
13172: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
13173: },
13174: );
13175:
13176: }
13177: my @types= ('crs','dom');
13178: if ($context eq 'lti') {
13179: foreach my $type (@types) {
13180: undef($domdefaults{'linkprotenc_'.$type});
13181: }
13182: push(@types,'consumers');
13183: undef($domdefaults{'ltienc_consumers'});
13184: } elsif ($context eq 'ltitools') {
13185: foreach my $type (@types) {
13186: undef($domdefaults{'toolenc_'.$type});
13187: }
13188: }
13189: foreach my $type (@types) {
13190: my $shown = $encrypted{$type}{'off'};
13191: if (ref($newsec->{$item}) eq 'HASH') {
13192: if ($newsec->{$item}{$type}) {
13193: if ($context eq 'lti') {
13194: if ($type eq 'consumers') {
13195: $domdefaults{'ltienc_consumers'} = 1;
13196: } else {
13197: $domdefaults{'linkprotenc_'.$type} = 1;
13198: }
13199: } elsif ($context eq 'ltitools') {
13200: $domdefaults{'toolenc_'.$type} = 1;
13201: }
13202: $shown = $encrypted{$type}{'on'};
13203: }
13204: }
13205: $output .= '<li>'.$shown.'</li>';
13206: }
13207: } elsif ($item eq 'rules') {
13208: my %titles = &Apache::lonlocal::texthash(
13209: min => 'Minimum password length',
13210: max => 'Maximum password length',
13211: chars => 'Required characters',
13212: );
13213: foreach my $rule ('min','max') {
13214: if ($newsec->{rules}{$rule} eq '') {
13215: if ($rule eq 'min') {
13216: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13217: ' '.&mt('Default of [_1] will be used',
13218: $Apache::lonnet::passwdmin).'</li>';
13219: } else {
13220: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13221: }
13222: } else {
13223: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
13224: }
13225: }
13226: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
13227: if (@{$newsec->{'rules'}{'chars'}} > 0) {
13228: my %rulenames = &Apache::lonlocal::texthash(
13229: uc => 'At least one upper case letter',
13230: lc => 'At least one lower case letter',
13231: num => 'At least one number',
13232: spec => 'At least one non-alphanumeric',
13233: );
13234: my $needed = '<ul><li>'.
13235: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
13236: '</li></ul>';
13237: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13238: } else {
13239: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13240: }
13241: } else {
13242: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13243: }
13244: } elsif ($item eq 'private') {
13245: $needs_update = 1;
13246: if ($context eq 'lti') {
13247: undef($domdefaults{'ltiprivhosts'});
13248: } elsif ($context eq 'ltitools') {
13249: undef($domdefaults{'toolprivhosts'});
13250: }
13251: if (keys(%{$newkeyset})) {
13252: my @privhosts;
13253: foreach my $hostid (sort(keys(%{$newkeyset}))) {
13254: if ($keystore->{$hostid} eq 'ok') {
13255: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13256: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
13257: push(@privhosts,$hostid);
13258: }
13259: }
13260: }
13261: if (@privhosts) {
13262: if ($context eq 'lti') {
13263: $domdefaults{'ltiprivhosts'} = \@privhosts;
13264: } elsif ($context eq 'ltitools') {
13265: $domdefaults{'toolprivhosts'} = \@privhosts;
13266: }
13267: }
13268: }
13269: } elsif ($item eq 'linkprot') {
13270: next;
13271: }
13272: }
13273: if ($needs_update) {
13274: my $cachetime = 24*60*60;
13275: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13276: }
13277: return $output;
13278: }
13279:
13280: sub modify_lti {
13281: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13282: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13283: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
13284: my (%posslti,%posslticrs,%posscrstype);
13285: my @courseroles = ('cc','in','ta','ep','st');
13286: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
13287: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
13288: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
13289: my %coursetypetitles = &Apache::lonlocal::texthash (
13290: official => 'Official',
13291: unofficial => 'Unofficial',
13292: community => 'Community',
13293: textbook => 'Textbook',
13294: placement => 'Placement Test',
13295: lti => 'LTI Provider',
13296: );
13297: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13298: my %lt = <i_names();
13299: map { $posslti{$_} = 1; } @ltiroles;
13300: map { $posslticrs{$_} = 1; } @lticourseroles;
13301: map { $posscrstype{$_} = 1; } @coursetypes;
13302:
13303: my %menutitles = <imenu_titles();
13304: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
13305:
13306: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
13307:
13308: my (%linkprotchg,$linkprotoutput,$is_home);
13309: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13310: \%linkprotchg,'domain');
13311: my $home = &Apache::lonnet::domain($dom,'primary');
13312: unless (($home eq 'no_host') || ($home eq '')) {
13313: my @ids=&Apache::lonnet::current_machine_ids();
13314: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13315: }
13316:
13317: if (keys(%linkprotchg)) {
13318: $secchanges{'linkprot'} = 1;
13319: my %oldlinkprot;
13320: if (ref($currltisec{'linkprot'}) eq 'HASH') {
13321: %oldlinkprot = %{$currltisec{'linkprot'}};
13322: }
13323: foreach my $id (keys(%linkprotchg)) {
13324: if (ref($linkprotchg{$id}) eq 'HASH') {
13325: foreach my $inner (keys(%{$linkprotchg{$id}})) {
13326: if (($inner eq 'secret') || ($inner eq 'key')) {
13327: if ($is_home) {
13328: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13329: }
13330: }
13331: }
13332: } else {
13333: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
13334: }
13335: }
13336: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13337: if (keys(%linkprotchg)) {
13338: %{$newltisec{'linkprot'}} = %linkprotchg;
13339: }
13340: }
13341: if (ref($currltisec{'linkprot'}) eq 'HASH') {
13342: foreach my $id (%{$currltisec{'linkprot'}}) {
13343: next if ($id !~ /^\d+$/);
13344: unless (exists($linkprotchg{$id})) {
13345: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13346: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13347: if (($inner eq 'secret') || ($inner eq 'key')) {
13348: if ($is_home) {
13349: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13350: }
13351: } else {
13352: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13353: }
13354: }
13355: } else {
13356: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
13357: }
13358: }
13359: }
13360: }
13361: if ($proterror) {
13362: $errors .= '<li>'.$proterror.'</li>';
13363: }
13364: my (@items,%deletions,%itemids);
13365: if ($env{'form.lti_add'}) {
13366: my $consumer = $env{'form.lti_consumer_add'};
13367: $consumer =~ s/(`)/'/g;
13368: ($newid,my $error) = &get_lti_id($dom,$consumer);
13369: if ($newid) {
13370: $itemids{'add'} = $newid;
13371: push(@items,'add');
13372: $changes{$newid} = 1;
13373: } else {
13374: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
13375: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13376: }
13377: }
13378: if (ref($domconfig{$action}) eq 'HASH') {
13379: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
13380: if (@todelete) {
13381: map { $deletions{$_} = 1; } @todelete;
13382: }
13383: my $maxnum = $env{'form.lti_maxnum'};
13384: for (my $i=0; $i<$maxnum; $i++) {
13385: my $itemid = $env{'form.lti_id_'.$i};
13386: $itemid =~ s/\D+//g;
13387: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13388: if ($deletions{$itemid}) {
13389: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
13390: } else {
13391: push(@items,$i);
13392: $itemids{$i} = $itemid;
13393: }
13394: }
13395: }
13396: }
13397: my (%keystore,$secstored);
13398: if ($is_home) {
13399: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
13400: }
13401:
13402: my ($cipher,$privnum);
13403: if ((@items > 0) && ($is_home)) {
13404: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
13405: $newltisec{'encrypt'},$keystore{$home});
13406: }
13407: foreach my $idx (@items) {
13408: my $itemid = $itemids{$idx};
13409: next unless ($itemid);
13410: my %currlti;
13411: unless ($idx eq 'add') {
13412: if (ref($domconfig{$action}) eq 'HASH') {
13413: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13414: %currlti = %{$domconfig{$action}{$itemid}};
13415: }
13416: }
13417: }
13418: my $position = $env{'form.lti_pos_'.$itemid};
13419: $position =~ s/\D+//g;
13420: if ($position ne '') {
13421: $allpos[$position] = $itemid;
13422: }
13423: foreach my $item ('consumer','lifetime','requser','crsinc') {
13424: my $formitem = 'form.lti_'.$item.'_'.$idx;
13425: $env{$formitem} =~ s/(`)/'/g;
13426: if ($item eq 'lifetime') {
13427: $env{$formitem} =~ s/[^\d.]//g;
13428: }
13429: if ($env{$formitem} ne '') {
13430: $confhash{$itemid}{$item} = $env{$formitem};
13431: unless (($idx eq 'add') || ($changes{$itemid})) {
13432: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
13433: $changes{$itemid} = 1;
13434: }
13435: }
13436: }
13437: }
13438: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
13439: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
13440: }
13441: if ($confhash{$itemid}{'requser'}) {
13442: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
13443: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
13444: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
13445: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
13446: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
13447: my $mapuser = $env{'form.lti_customuser_'.$idx};
13448: $mapuser =~ s/(`)/'/g;
13449: $mapuser =~ s/^\s+|\s+$//g;
13450: $confhash{$itemid}{'mapuser'} = $mapuser;
13451: }
13452: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
13453: my @makeuser;
13454: foreach my $ltirole (sort(@possmakeuser)) {
13455: if ($posslti{$ltirole}) {
13456: push(@makeuser,$ltirole);
13457: }
13458: }
13459: $confhash{$itemid}{'makeuser'} = \@makeuser;
13460: if (@makeuser) {
13461: my $lcauth = $env{'form.lti_lcauth_'.$idx};
13462: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
13463: $confhash{$itemid}{'lcauth'} = $lcauth;
13464: if ($lcauth ne 'internal') {
13465: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
13466: $lcauthparm =~ s/^(\s+|\s+)$//g;
13467: $lcauthparm =~ s/`//g;
13468: if ($lcauthparm ne '') {
13469: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
13470: }
13471: }
13472: } else {
13473: $confhash{$itemid}{'lcauth'} = 'lti';
13474: }
13475: }
13476: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
13477: if (@possinstdata) {
13478: foreach my $field (@possinstdata) {
13479: if (exists($fieldtitles{$field})) {
13480: push(@{$confhash{$itemid}{'instdata'}});
13481: }
13482: }
13483: }
13484: if ($env{'form.lti_callback_'.$idx}) {
13485: if ($env{'form.lti_callbackparam_'.$idx}) {
13486: my $callback = $env{'form.lti_callbackparam_'.$idx};
13487: $callback =~ s/^\s+|\s+$//g;
13488: $confhash{$itemid}{'callback'} = $callback;
13489: }
13490: }
13491: foreach my $field ('topmenu','inlinemenu') {
13492: if ($env{'form.lti_'.$field.'_'.$idx}) {
13493: $confhash{$itemid}{$field} = 1;
13494: }
13495: }
13496: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
13497: $confhash{$itemid}{lcmenu} = [];
13498: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
13499: foreach my $field (@possmenu) {
13500: if (exists($menutitles{$field})) {
13501: if ($field eq 'grades') {
13502: next unless ($env{'form.lti_inlinemenu_'.$idx});
13503: }
13504: push(@{$confhash{$itemid}{lcmenu}},$field);
13505: }
13506: }
13507: }
13508: if ($confhash{$itemid}{'crsinc'}) {
13509: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
13510: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
13511: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
13512: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
13513: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
13514: $mapcrs =~ s/(`)/'/g;
13515: $mapcrs =~ s/^\s+|\s+$//g;
13516: $confhash{$itemid}{'mapcrs'} = $mapcrs;
13517: }
13518: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
13519: my @crstypes;
13520: foreach my $type (sort(@posstypes)) {
13521: if ($posscrstype{$type}) {
13522: push(@crstypes,$type);
13523: }
13524: }
13525: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
13526: if ($env{'form.lti_storecrs_'.$idx}) {
13527: $confhash{$itemid}{'storecrs'} = 1;
13528: }
13529: if ($env{'form.lti_makecrs_'.$idx}) {
13530: $confhash{$itemid}{'makecrs'} = 1;
13531: }
13532: foreach my $ltirole (@lticourseroles) {
13533: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
13534: if (grep(/^\Q$possrole\E$/,@courseroles)) {
13535: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
13536: }
13537: }
13538: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
13539: my @selfenroll;
13540: foreach my $type (sort(@possenroll)) {
13541: if ($posslticrs{$type}) {
13542: push(@selfenroll,$type);
13543: }
13544: }
13545: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
13546: if ($env{'form.lti_crssec_'.$idx}) {
13547: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
13548: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
13549: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
13550: my $section = $env{'form.lti_customsection_'.$idx};
13551: $section =~ s/(`)/'/g;
13552: $section =~ s/^\s+|\s+$//g;
13553: if ($section ne '') {
13554: $confhash{$itemid}{'section'} = $section;
13555: }
13556: }
13557: }
13558: foreach my $field ('passback','roster') {
13559: if ($env{'form.lti_'.$field.'_'.$idx}) {
13560: $confhash{$itemid}{$field} = 1;
13561: }
13562: }
13563: if ($env{'form.lti_passback_'.$idx}) {
13564: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
13565: $confhash{$itemid}{'passbackformat'} = '1.0';
13566: } else {
13567: $confhash{$itemid}{'passbackformat'} = '1.1';
13568: }
13569: }
13570: }
13571: unless (($idx eq 'add') || ($changes{$itemid})) {
13572: if ($confhash{$itemid}{'crsinc'}) {
13573: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
13574: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
13575: $changes{$itemid} = 1;
13576: }
13577: }
13578: unless ($changes{$itemid}) {
13579: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
13580: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
13581: $changes{$itemid} = 1;
13582: }
13583: }
13584: }
13585: foreach my $field ('mapcrstype','selfenroll') {
13586: unless ($changes{$itemid}) {
13587: if (ref($currlti{$field}) eq 'ARRAY') {
13588: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13589: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
13590: $confhash{$itemid}{$field});
13591: if (@diffs) {
13592: $changes{$itemid} = 1;
13593: }
13594: } elsif (@{$currlti{$field}} > 0) {
13595: $changes{$itemid} = 1;
13596: }
13597: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13598: if (@{$confhash{$itemid}{$field}} > 0) {
13599: $changes{$itemid} = 1;
13600: }
13601: }
13602: }
13603: }
13604: unless ($changes{$itemid}) {
13605: if (ref($currlti{'maproles'}) eq 'HASH') {
13606: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
13607: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
13608: if ($currlti{'maproles'}{$ltirole} ne
13609: $confhash{$itemid}{'maproles'}{$ltirole}) {
13610: $changes{$itemid} = 1;
13611: last;
13612: }
13613: }
13614: unless ($changes{$itemid}) {
13615: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
13616: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
13617: $currlti{'maproles'}{$ltirole}) {
13618: $changes{$itemid} = 1;
13619: last;
13620: }
13621: }
13622: }
13623: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
13624: $changes{$itemid} = 1;
13625: }
13626: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
13627: unless ($changes{$itemid}) {
13628: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
13629: $changes{$itemid} = 1;
13630: }
13631: }
13632: }
13633: }
13634: }
13635: unless ($changes{$itemid}) {
13636: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
13637: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
13638: $changes{$itemid} = 1;
13639: }
13640: }
13641: unless ($changes{$itemid}) {
13642: foreach my $field ('makeuser','lcmenu') {
13643: if (ref($currlti{$field}) eq 'ARRAY') {
13644: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13645: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
13646: $confhash{$itemid}{$field});
13647: if (@diffs) {
13648: $changes{$itemid} = 1;
13649: }
13650: } elsif (@{$currlti{$field}} > 0) {
13651: $changes{$itemid} = 1;
13652: }
13653: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13654: if (@{$confhash{$itemid}{$field}} > 0) {
13655: $changes{$itemid} = 1;
13656: }
13657: }
13658: }
13659: }
13660: }
13661: }
13662: }
13663: if ($is_home) {
13664: my $keyitem = 'form.lti_key_'.$idx;
13665: $env{$keyitem} =~ s/(`)/'/g;
13666: if ($env{$keyitem} ne '') {
13667: $ltienc{$itemid}{'key'} = $env{$keyitem};
13668: unless ($changes{$itemid}) {
13669: if ($currlti{'key'} ne $env{$keyitem}) {
13670: $changes{$itemid} = 1;
13671: }
13672: }
13673: }
13674: my $secretitem = 'form.lti_secret_'.$idx;
13675: $env{$secretitem} =~ s/(`)/'/g;
13676: if ($currlti{'usable'}) {
13677: if ($env{'form.lti_changesecret_'.$idx}) {
13678: if ($env{$secretitem} ne '') {
13679: if ($privnum && $cipher) {
13680: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
13681: $confhash{$itemid}{'cipher'} = $privnum;
13682: } else {
13683: $ltienc{$itemid}{'secret'} = $env{$secretitem};
13684: }
13685: $changes{$itemid} = 1;
13686: }
13687: } else {
13688: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
13689: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
13690: }
13691: if (ref($ltienc{$itemid}) eq 'HASH') {
13692: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
13693: $confhash{$itemid}{'usable'} = 1;
13694: }
13695: }
13696: } elsif ($env{$secretitem} ne '') {
13697: if ($privnum && $cipher) {
13698: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
13699: $confhash{$itemid}{'cipher'} = $privnum;
13700: } else {
13701: $ltienc{$itemid}{'secret'} = $env{$secretitem};
13702: }
13703: if (ref($ltienc{$itemid}) eq 'HASH') {
13704: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
13705: $confhash{$itemid}{'usable'} = 1;
13706: }
13707: }
13708: $changes{$itemid} = 1;
13709: }
13710: }
13711: unless ($changes{$itemid}) {
13712: foreach my $key (keys(%currlti)) {
13713: if (ref($currlti{$key}) eq 'HASH') {
13714: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13715: foreach my $innerkey (keys(%{$currlti{$key}})) {
13716: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
13717: $changes{$itemid} = 1;
13718: last;
13719: }
13720: }
13721: } elsif (keys(%{$currlti{$key}}) > 0) {
13722: $changes{$itemid} = 1;
13723: }
13724: }
13725: last if ($changes{$itemid});
13726: }
13727: }
13728: }
13729: if (@allpos > 0) {
13730: my $idx = 0;
13731: foreach my $itemid (@allpos) {
13732: if ($itemid ne '') {
13733: $confhash{$itemid}{'order'} = $idx;
13734: if (ref($domconfig{$action}) eq 'HASH') {
13735: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13736: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13737: $changes{$itemid} = 1;
13738: }
13739: }
13740: }
13741: $idx ++;
13742: }
13743: }
13744: }
13745:
13746: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
13747: return &mt('No changes made.');
13748: }
13749:
13750: my %ltihash = (
13751: $action => { %confhash }
13752: );
13753: my %ltienchash;
13754:
13755: if ($is_home) {
13756: %ltienchash = (
13757: $action => { %ltienc }
13758: );
13759: }
13760: if (keys(%secchanges)) {
13761: $ltihash{'ltisec'} = \%newltisec;
13762: if ($secchanges{'linkprot'}) {
13763: if ($is_home) {
13764: $ltienchash{'linkprot'} = \%newltienc;
13765: }
13766: }
13767: }
13768: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
13769: if ($putresult eq 'ok') {
13770: if (keys(%ltienchash)) {
13771: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
13772: }
13773: $resulttext = &mt('Changes made:').'<ul>';
13774: if (keys(%secchanges) > 0) {
13775: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
13776: if (exists($secchanges{'linkprot'})) {
13777: $resulttext .= $linkprotoutput;
13778: }
13779: }
13780: if (keys(%changes) > 0) {
13781: my $cachetime = 24*60*60;
13782: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
13783: if (ref($lastactref) eq 'HASH') {
13784: $lastactref->{'lti'} = 1;
13785: }
13786: my %bynum;
13787: foreach my $itemid (sort(keys(%changes))) {
13788: if (ref($confhash{$itemid}) eq 'HASH') {
13789: my $position = $confhash{$itemid}{'order'};
13790: $bynum{$position} = $itemid;
13791: }
13792: }
13793: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13794: my $itemid = $bynum{$pos};
13795: if (ref($confhash{$itemid}) eq 'HASH') {
13796: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
13797: my $position = $pos + 1;
13798: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13799: foreach my $item ('version','lifetime') {
13800: if ($confhash{$itemid}{$item} ne '') {
13801: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13802: }
13803: }
13804: if ($ltienc{$itemid}{'key'} ne '') {
13805: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
13806: }
13807: if ($ltienc{$itemid}{'secret'} ne '') {
13808: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
13809: }
13810: if ($confhash{$itemid}{'requser'}) {
13811: if ($confhash{$itemid}{'callback'}) {
13812: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
13813: } else {
13814: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
13815: }
13816: if ($confhash{$itemid}{'mapuser'}) {
13817: my $shownmapuser;
13818: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
13819: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
13820: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
13821: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
13822: } else {
13823: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
13824: }
13825: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
13826: }
13827: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
13828: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
13829: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
13830: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
13831: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
13832: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
13833: } else {
13834: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
13835: $confhash{$itemid}{'lcauth'});
13836: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
13837: $resulttext .= '; '.&mt('a randomly generated password will be created');
13838: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
13839: if ($confhash{$itemid}{'lcauthparm'} ne '') {
13840: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
13841: }
13842: } else {
13843: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
13844: }
13845: }
13846: $resulttext .= '</li>';
13847: } else {
13848: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
13849: }
13850: }
13851: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
13852: if (@{$confhash{$itemid}{'instdata'}} > 0) {
13853: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
13854: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
13855: } else {
13856: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
13857: }
13858: }
13859: foreach my $item ('topmenu','inlinemenu') {
13860: $resulttext .= '<li>'.$lt{$item}.': ';
13861: if ($confhash{$itemid}{$item}) {
13862: $resulttext .= &mt('Yes');
13863: } else {
13864: $resulttext .= &mt('No');
13865: }
13866: $resulttext .= '</li>';
13867: }
13868: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
13869: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
13870: $resulttext .= '<li>'.&mt('Menu items:').' '.
13871: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
13872: } else {
13873: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
13874: }
13875: }
13876: if ($confhash{$itemid}{'crsinc'}) {
13877: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
13878: my $rolemaps;
13879: foreach my $role (@ltiroles) {
13880: if ($confhash{$itemid}{'maproles'}{$role}) {
13881: $rolemaps .= (' 'x2).$role.'='.
13882: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
13883: 'Course').',';
13884: }
13885: }
13886: if ($rolemaps) {
13887: $rolemaps =~ s/,$//;
13888: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13889: }
13890: }
13891: if ($confhash{$itemid}{'mapcrs'}) {
13892: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
13893: }
13894: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
13895: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
13896: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
13897: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
13898: '</li>';
13899: } else {
13900: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
13901: }
13902: }
13903: if ($confhash{$itemid}{'storecrs'}) {
13904: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
13905: }
13906: if ($confhash{$itemid}{'makecrs'}) {
13907: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
13908: } else {
13909: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
13910: }
13911: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
13912: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
13913: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
13914: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
13915: '</li>';
13916: } else {
13917: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
13918: }
13919: }
13920: if ($confhash{$itemid}{'section'}) {
13921: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
13922: $resulttext .= '<li>'.&mt('User section from standard field:').
13923: ' (course_section_sourcedid)'.'</li>';
13924: } else {
13925: $resulttext .= '<li>'.&mt('User section from:').' '.
13926: $confhash{$itemid}{'section'}.'</li>';
13927: }
13928: } else {
13929: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
13930: }
13931: foreach my $item ('passback','roster','topmenu','inlinemenu') {
13932: $resulttext .= '<li>'.$lt{$item}.': ';
13933: if ($confhash{$itemid}{$item}) {
13934: $resulttext .= &mt('Yes');
13935: if ($item eq 'passback') {
13936: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
13937: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
13938: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
13939: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
13940: }
13941: }
13942: } else {
13943: $resulttext .= &mt('No');
13944: }
13945: $resulttext .= '</li>';
13946: }
13947: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
13948: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
13949: $resulttext .= '<li>'.&mt('Menu items:').' '.
13950: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
13951: } else {
13952: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
13953: }
13954: }
13955: }
13956: }
13957: $resulttext .= '</ul></li>';
13958: }
13959: }
13960: if (keys(%deletions)) {
13961: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13962: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13963: }
13964: }
13965: }
13966: $resulttext .= '</ul>';
13967: if (ref($lastactref) eq 'HASH') {
13968: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
13969: $lastactref->{'domdefaults'} = 1;
13970: }
13971: }
13972: } else {
13973: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13974: }
13975: if ($errors) {
13976: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13977: $errors.'</ul>';
13978: }
13979: return $resulttext;
13980: }
13981:
13982: sub get_priv_creds {
13983: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
13984: my ($needenc,$cipher,$privnum);
13985: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
13986: if (($encchg) && (ref($encrypt) eq 'HASH')) {
13987: $needenc = $encrypt->{'consumers'}
13988: } else {
13989: $needenc = $domdefs{'ltienc_consumers'};
13990: }
13991: if ($needenc) {
13992: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
13993: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
13994: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
13995: my $privkey = $privhash{'key'};
13996: $privnum = $privhash{'version'};
13997: if (($privnum) && ($privkey ne '')) {
13998: $cipher = Crypt::CBC->new({'key' => $privkey,
13999: 'cipher' => 'DES'});
14000: }
14001: }
14002: }
14003: return ($cipher,$privnum);
14004: }
14005:
14006: sub get_lti_id {
14007: my ($domain,$consumer) = @_;
14008: # get lock on lti db
14009: my $lockhash = {
14010: lock => $env{'user.name'}.
14011: ':'.$env{'user.domain'},
14012: };
14013: my $tries = 0;
14014: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14015: my ($id,$error);
14016:
14017: while (($gotlock ne 'ok') && ($tries<10)) {
14018: $tries ++;
14019: sleep (0.1);
14020: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
14021: }
14022: if ($gotlock eq 'ok') {
14023: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
14024: if ($currids{'lock'}) {
14025: delete($currids{'lock'});
14026: if (keys(%currids)) {
14027: my @curr = sort { $a <=> $b } keys(%currids);
14028: if ($curr[-1] =~ /^\d+$/) {
14029: $id = 1 + $curr[-1];
14030: }
14031: } else {
14032: $id = 1;
14033: }
14034: if ($id) {
14035: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
14036: $error = 'nostore';
14037: }
14038: } else {
14039: $error = 'nonumber';
14040: }
14041: }
14042: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
14043: } else {
14044: $error = 'nolock';
14045: }
14046: return ($id,$error);
14047: }
14048:
14049: sub modify_autoenroll {
14050: my ($dom,$lastactref,%domconfig) = @_;
14051: my ($resulttext,%changes);
14052: my %currautoenroll;
14053: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14054: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14055: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14056: }
14057: }
14058: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14059: my %title = ( run => 'Auto-enrollment active',
14060: sender => 'Sender for notification messages',
14061: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
14062: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
14063: my @offon = ('off','on');
14064: my $sender_uname = $env{'form.sender_uname'};
14065: my $sender_domain = $env{'form.sender_domain'};
14066: if ($sender_domain eq '') {
14067: $sender_uname = '';
14068: } elsif ($sender_uname eq '') {
14069: $sender_domain = '';
14070: }
14071: my $coowners = $env{'form.autoassign_coowners'};
14072: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
14073: $autofailsafe =~ s{^\s+|\s+$}{}g;
14074: if ($autofailsafe =~ /\D/) {
14075: undef($autofailsafe);
14076: }
14077: my $failsafe = $env{'form.autoenroll_failsafe'};
14078: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
14079: $failsafe = 'off';
14080: undef($autofailsafe);
14081: }
14082: my %autoenrollhash = (
14083: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14084: 'sender_uname' => $sender_uname,
14085: 'sender_domain' => $sender_domain,
14086: 'co-owners' => $coowners,
14087: 'autofailsafe' => $autofailsafe,
14088: 'failsafe' => $failsafe,
14089: }
14090: );
14091: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14092: $dom);
14093: if ($putresult eq 'ok') {
14094: if (exists($currautoenroll{'run'})) {
14095: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14096: $changes{'run'} = 1;
14097: }
14098: } elsif ($autorun) {
14099: if ($env{'form.autoenroll_run'} ne '1') {
14100: $changes{'run'} = 1;
14101: }
14102: }
14103: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
14104: $changes{'sender'} = 1;
14105: }
14106: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
14107: $changes{'sender'} = 1;
14108: }
14109: if ($currautoenroll{'co-owners'} ne '') {
14110: if ($currautoenroll{'co-owners'} ne $coowners) {
14111: $changes{'coowners'} = 1;
14112: }
14113: } elsif ($coowners) {
14114: $changes{'coowners'} = 1;
14115: }
14116: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
14117: $changes{'autofailsafe'} = 1;
14118: }
14119: if ($currautoenroll{'failsafe'} ne $failsafe) {
14120: $changes{'failsafe'} = 1;
14121: }
14122: if (keys(%changes) > 0) {
14123: $resulttext = &mt('Changes made:').'<ul>';
14124: if ($changes{'run'}) {
14125: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14126: }
14127: if ($changes{'sender'}) {
14128: if ($sender_uname eq '' || $sender_domain eq '') {
14129: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14130: } else {
14131: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14132: }
14133: }
14134: if ($changes{'coowners'}) {
14135: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14136: &Apache::loncommon::devalidate_domconfig_cache($dom);
14137: if (ref($lastactref) eq 'HASH') {
14138: $lastactref->{'domainconfig'} = 1;
14139: }
14140: }
14141: if ($changes{'autofailsafe'}) {
14142: if ($autofailsafe ne '') {
14143: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
14144: } else {
14145: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
14146: }
14147: }
14148: if ($changes{'failsafe'}) {
14149: if ($failsafe eq 'off') {
14150: unless ($changes{'autofailsafe'}) {
14151: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
14152: }
14153: } elsif ($failsafe eq 'zero') {
14154: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
14155: } else {
14156: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
14157: }
14158: }
14159: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
14160: &Apache::lonnet::get_domain_defaults($dom,1);
14161: if (ref($lastactref) eq 'HASH') {
14162: $lastactref->{'domdefaults'} = 1;
14163: }
14164: }
14165: $resulttext .= '</ul>';
14166: } else {
14167: $resulttext = &mt('No changes made to auto-enrollment settings');
14168: }
14169: } else {
14170: $resulttext = '<span class="LC_error">'.
14171: &mt('An error occurred: [_1]',$putresult).'</span>';
14172: }
14173: return $resulttext;
14174: }
14175:
14176: sub modify_autoupdate {
14177: my ($dom,%domconfig) = @_;
14178: my ($resulttext,%currautoupdate,%fields,%changes);
14179: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14180: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14181: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14182: }
14183: }
14184: my @offon = ('off','on');
14185: my %title = &Apache::lonlocal::texthash (
14186: run => 'Auto-update:',
14187: classlists => 'Updates to user information in classlists?',
14188: unexpired => 'Skip updates for users without active or future roles?',
14189: lastactive => 'Skip updates for inactive users?',
14190: );
14191: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14192: my %fieldtitles = &Apache::lonlocal::texthash (
14193: id => 'Student/Employee ID',
14194: permanentemail => 'E-mail address',
14195: lastname => 'Last Name',
14196: firstname => 'First Name',
14197: middlename => 'Middle Name',
14198: generation => 'Generation',
14199: );
14200: $othertitle = &mt('All users');
14201: if (keys(%{$usertypes}) > 0) {
14202: $othertitle = &mt('Other users');
14203: }
14204: foreach my $key (keys(%env)) {
14205: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
14206: my ($usertype,$item) = ($1,$2);
14207: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14208: if ($usertype eq 'default') {
14209: push(@{$fields{$1}},$2);
14210: } elsif (ref($types) eq 'ARRAY') {
14211: if (grep(/^\Q$usertype\E$/,@{$types})) {
14212: push(@{$fields{$1}},$2);
14213: }
14214: }
14215: }
14216: }
14217: }
14218: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14219: @lockablenames = sort(@lockablenames);
14220: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14221: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14222: if (@changed) {
14223: $changes{'lockablenames'} = 1;
14224: }
14225: } else {
14226: if (@lockablenames) {
14227: $changes{'lockablenames'} = 1;
14228: }
14229: }
14230: my %updatehash = (
14231: autoupdate => { run => $env{'form.autoupdate_run'},
14232: classlists => $env{'form.classlists'},
14233: unexpired => $env{'form.unexpired'},
14234: fields => {%fields},
14235: lockablenames => \@lockablenames,
14236: }
14237: );
14238: my $lastactivedays;
14239: if ($env{'form.lastactive'}) {
14240: $lastactivedays = $env{'form.lastactivedays'};
14241: $lastactivedays =~ s/^\s+|\s+$//g;
14242: unless ($lastactivedays =~ /^\d+$/) {
14243: undef($lastactivedays);
14244: $env{'form.lastactive'} = 0;
14245: }
14246: }
14247: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
14248: foreach my $key (keys(%currautoupdate)) {
14249: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
14250: if (exists($updatehash{autoupdate}{$key})) {
14251: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14252: $changes{$key} = 1;
14253: }
14254: }
14255: } elsif ($key eq 'fields') {
14256: if (ref($currautoupdate{$key}) eq 'HASH') {
14257: foreach my $item (@{$types},'default') {
14258: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14259: my $change = 0;
14260: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14261: if (!exists($fields{$item})) {
14262: $change = 1;
14263: last;
14264: } elsif (ref($fields{$item}) eq 'ARRAY') {
14265: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
14266: $change = 1;
14267: last;
14268: }
14269: }
14270: }
14271: if ($change) {
14272: push(@{$changes{$key}},$item);
14273: }
14274: }
14275: }
14276: }
14277: } elsif ($key eq 'lockablenames') {
14278: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14279: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14280: if (@changed) {
14281: $changes{'lockablenames'} = 1;
14282: }
14283: } else {
14284: if (@lockablenames) {
14285: $changes{'lockablenames'} = 1;
14286: }
14287: }
14288: }
14289: }
14290: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
14291: if (@lockablenames) {
14292: $changes{'lockablenames'} = 1;
14293: }
14294: }
14295: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
14296: if ($updatehash{'autoupdate'}{'unexpired'}) {
14297: $changes{'unexpired'} = 1;
14298: }
14299: }
14300: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
14301: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
14302: $changes{'lastactive'} = 1;
14303: }
14304: }
14305: foreach my $item (@{$types},'default') {
14306: if (defined($fields{$item})) {
14307: if (ref($currautoupdate{'fields'}) eq 'HASH') {
14308: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
14309: my $change = 0;
14310: if (ref($fields{$item}) eq 'ARRAY') {
14311: foreach my $type (@{$fields{$item}}) {
14312: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
14313: $change = 1;
14314: last;
14315: }
14316: }
14317: }
14318: if ($change) {
14319: push(@{$changes{'fields'}},$item);
14320: }
14321: } else {
14322: push(@{$changes{'fields'}},$item);
14323: }
14324: } else {
14325: push(@{$changes{'fields'}},$item);
14326: }
14327: }
14328: }
14329: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
14330: $dom);
14331: if ($putresult eq 'ok') {
14332: if (keys(%changes) > 0) {
14333: $resulttext = &mt('Changes made:').'<ul>';
14334: foreach my $key (sort(keys(%changes))) {
14335: if ($key eq 'lockablenames') {
14336: $resulttext .= '<li>';
14337: if (@lockablenames) {
14338: $usertypes->{'default'} = $othertitle;
14339: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
14340: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
14341: } else {
14342: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
14343: }
14344: $resulttext .= '</li>';
14345: } elsif (ref($changes{$key}) eq 'ARRAY') {
14346: foreach my $item (@{$changes{$key}}) {
14347: my @newvalues;
14348: foreach my $type (@{$fields{$item}}) {
14349: push(@newvalues,$fieldtitles{$type});
14350: }
14351: my $newvaluestr;
14352: if (@newvalues > 0) {
14353: $newvaluestr = join(', ',@newvalues);
14354: } else {
14355: $newvaluestr = &mt('none');
14356: }
14357: if ($item eq 'default') {
14358: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
14359: } else {
14360: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
14361: }
14362: }
14363: } else {
14364: my $newvalue;
14365: if ($key eq 'run') {
14366: $newvalue = $offon[$env{'form.autoupdate_run'}];
14367: } elsif ($key eq 'lastactive') {
14368: $newvalue = $offon[$env{'form.lastactive'}];
14369: unless ($lastactivedays eq '') {
14370: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
14371: }
14372: } else {
14373: $newvalue = $offon[$env{'form.'.$key}];
14374: }
14375: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
14376: }
14377: }
14378: $resulttext .= '</ul>';
14379: } else {
14380: $resulttext = &mt('No changes made to autoupdates');
14381: }
14382: } else {
14383: $resulttext = '<span class="LC_error">'.
14384: &mt('An error occurred: [_1]',$putresult).'</span>';
14385: }
14386: return $resulttext;
14387: }
14388:
14389: sub modify_autocreate {
14390: my ($dom,%domconfig) = @_;
14391: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
14392: if (ref($domconfig{'autocreate'}) eq 'HASH') {
14393: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
14394: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
14395: }
14396: }
14397: my %title= ( xml => 'Auto-creation of courses in XML course description files',
14398: req => 'Auto-creation of validated requests for official courses',
14399: xmldc => 'Identity of course creator of courses from XML files',
14400: );
14401: my @types = ('xml','req');
14402: foreach my $item (@types) {
14403: $newvals{$item} = $env{'form.autocreate_'.$item};
14404: $newvals{$item} =~ s/\D//g;
14405: $newvals{$item} = 0 if ($newvals{$item} eq '');
14406: }
14407: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
14408: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
14409: unless (exists($domcoords{$newvals{'xmldc'}})) {
14410: $newvals{'xmldc'} = '';
14411: }
14412: %autocreatehash = (
14413: autocreate => { xml => $newvals{'xml'},
14414: req => $newvals{'req'},
14415: }
14416: );
14417: if ($newvals{'xmldc'} ne '') {
14418: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
14419: }
14420: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
14421: $dom);
14422: if ($putresult eq 'ok') {
14423: my @items = @types;
14424: if ($newvals{'xml'}) {
14425: push(@items,'xmldc');
14426: }
14427: foreach my $item (@items) {
14428: if (exists($currautocreate{$item})) {
14429: if ($currautocreate{$item} ne $newvals{$item}) {
14430: $changes{$item} = 1;
14431: }
14432: } elsif ($newvals{$item}) {
14433: $changes{$item} = 1;
14434: }
14435: }
14436: if (keys(%changes) > 0) {
14437: my @offon = ('off','on');
14438: $resulttext = &mt('Changes made:').'<ul>';
14439: foreach my $item (@types) {
14440: if ($changes{$item}) {
14441: my $newtxt = $offon[$newvals{$item}];
14442: $resulttext .= '<li>'.
14443: &mt("$title{$item} set to [_1]$newtxt [_2]",
14444: '<b>','</b>').
14445: '</li>';
14446: }
14447: }
14448: if ($changes{'xmldc'}) {
14449: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
14450: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
14451: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
14452: }
14453: $resulttext .= '</ul>';
14454: } else {
14455: $resulttext = &mt('No changes made to auto-creation settings');
14456: }
14457: } else {
14458: $resulttext = '<span class="LC_error">'.
14459: &mt('An error occurred: [_1]',$putresult).'</span>';
14460: }
14461: return $resulttext;
14462: }
14463:
14464: sub modify_directorysrch {
14465: my ($dom,$lastactref,%domconfig) = @_;
14466: my ($resulttext,%changes);
14467: my %currdirsrch;
14468: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
14469: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
14470: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
14471: }
14472: }
14473: my %title = ( available => 'Institutional directory search available',
14474: localonly => 'Other domains can search institution',
14475: lcavailable => 'LON-CAPA directory search available',
14476: lclocalonly => 'Other domains can search LON-CAPA domain',
14477: searchby => 'Search types',
14478: searchtypes => 'Search latitude');
14479: my @offon = ('off','on');
14480: my @otherdoms = ('Yes','No');
14481:
14482: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
14483: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
14484: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
14485:
14486: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14487: if (keys(%{$usertypes}) == 0) {
14488: @cansearch = ('default');
14489: } else {
14490: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
14491: foreach my $type (@{$currdirsrch{'cansearch'}}) {
14492: if (!grep(/^\Q$type\E$/,@cansearch)) {
14493: push(@{$changes{'cansearch'}},$type);
14494: }
14495: }
14496: foreach my $type (@cansearch) {
14497: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
14498: push(@{$changes{'cansearch'}},$type);
14499: }
14500: }
14501: } else {
14502: push(@{$changes{'cansearch'}},@cansearch);
14503: }
14504: }
14505:
14506: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
14507: foreach my $by (@{$currdirsrch{'searchby'}}) {
14508: if (!grep(/^\Q$by\E$/,@searchby)) {
14509: push(@{$changes{'searchby'}},$by);
14510: }
14511: }
14512: foreach my $by (@searchby) {
14513: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
14514: push(@{$changes{'searchby'}},$by);
14515: }
14516: }
14517: } else {
14518: push(@{$changes{'searchby'}},@searchby);
14519: }
14520:
14521: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
14522: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
14523: if (!grep(/^\Q$type\E$/,@searchtypes)) {
14524: push(@{$changes{'searchtypes'}},$type);
14525: }
14526: }
14527: foreach my $type (@searchtypes) {
14528: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
14529: push(@{$changes{'searchtypes'}},$type);
14530: }
14531: }
14532: } else {
14533: if (exists($currdirsrch{'searchtypes'})) {
14534: foreach my $type (@searchtypes) {
14535: if ($type ne $currdirsrch{'searchtypes'}) {
14536: push(@{$changes{'searchtypes'}},$type);
14537: }
14538: }
14539: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
14540: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
14541: }
14542: } else {
14543: push(@{$changes{'searchtypes'}},@searchtypes);
14544: }
14545: }
14546:
14547: my %dirsrch_hash = (
14548: directorysrch => { available => $env{'form.dirsrch_available'},
14549: cansearch => \@cansearch,
14550: localonly => $env{'form.dirsrch_instlocalonly'},
14551: lclocalonly => $env{'form.dirsrch_domlocalonly'},
14552: lcavailable => $env{'form.dirsrch_domavailable'},
14553: searchby => \@searchby,
14554: searchtypes => \@searchtypes,
14555: }
14556: );
14557: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
14558: $dom);
14559: if ($putresult eq 'ok') {
14560: if (exists($currdirsrch{'available'})) {
14561: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
14562: $changes{'available'} = 1;
14563: }
14564: } else {
14565: if ($env{'form.dirsrch_available'} eq '1') {
14566: $changes{'available'} = 1;
14567: }
14568: }
14569: if (exists($currdirsrch{'lcavailable'})) {
14570: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
14571: $changes{'lcavailable'} = 1;
14572: }
14573: } else {
14574: if ($env{'form.dirsrch_lcavailable'} eq '1') {
14575: $changes{'lcavailable'} = 1;
14576: }
14577: }
14578: if (exists($currdirsrch{'localonly'})) {
14579: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
14580: $changes{'localonly'} = 1;
14581: }
14582: } else {
14583: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
14584: $changes{'localonly'} = 1;
14585: }
14586: }
14587: if (exists($currdirsrch{'lclocalonly'})) {
14588: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
14589: $changes{'lclocalonly'} = 1;
14590: }
14591: } else {
14592: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
14593: $changes{'lclocalonly'} = 1;
14594: }
14595: }
14596: if (keys(%changes) > 0) {
14597: $resulttext = &mt('Changes made:').'<ul>';
14598: if ($changes{'available'}) {
14599: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
14600: }
14601: if ($changes{'lcavailable'}) {
14602: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
14603: }
14604: if ($changes{'localonly'}) {
14605: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
14606: }
14607: if ($changes{'lclocalonly'}) {
14608: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
14609: }
14610: if (ref($changes{'cansearch'}) eq 'ARRAY') {
14611: my $chgtext;
14612: if (ref($usertypes) eq 'HASH') {
14613: if (keys(%{$usertypes}) > 0) {
14614: foreach my $type (@{$types}) {
14615: if (grep(/^\Q$type\E$/,@cansearch)) {
14616: $chgtext .= $usertypes->{$type}.'; ';
14617: }
14618: }
14619: if (grep(/^default$/,@cansearch)) {
14620: $chgtext .= $othertitle;
14621: } else {
14622: $chgtext =~ s/\; $//;
14623: }
14624: $resulttext .=
14625: '<li>'.
14626: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
14627: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
14628: '</li>';
14629: }
14630: }
14631: }
14632: if (ref($changes{'searchby'}) eq 'ARRAY') {
14633: my ($searchtitles,$titleorder) = &sorted_searchtitles();
14634: my $chgtext;
14635: foreach my $type (@{$titleorder}) {
14636: if (grep(/^\Q$type\E$/,@searchby)) {
14637: if (defined($searchtitles->{$type})) {
14638: $chgtext .= $searchtitles->{$type}.'; ';
14639: }
14640: }
14641: }
14642: $chgtext =~ s/\; $//;
14643: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
14644: }
14645: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
14646: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
14647: my $chgtext;
14648: foreach my $type (@{$srchtypeorder}) {
14649: if (grep(/^\Q$type\E$/,@searchtypes)) {
14650: if (defined($srchtypes_desc->{$type})) {
14651: $chgtext .= $srchtypes_desc->{$type}.'; ';
14652: }
14653: }
14654: }
14655: $chgtext =~ s/\; $//;
14656: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
14657: }
14658: $resulttext .= '</ul>';
14659: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
14660: if (ref($lastactref) eq 'HASH') {
14661: $lastactref->{'directorysrch'} = 1;
14662: }
14663: } else {
14664: $resulttext = &mt('No changes made to directory search settings');
14665: }
14666: } else {
14667: $resulttext = '<span class="LC_error">'.
14668: &mt('An error occurred: [_1]',$putresult).'</span>';
14669: }
14670: return $resulttext;
14671: }
14672:
14673: sub modify_contacts {
14674: my ($dom,$lastactref,%domconfig) = @_;
14675: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
14676: if (ref($domconfig{'contacts'}) eq 'HASH') {
14677: foreach my $key (keys(%{$domconfig{'contacts'}})) {
14678: $currsetting{$key} = $domconfig{'contacts'}{$key};
14679: }
14680: }
14681: my (%others,%to,%bcc,%includestr,%includeloc);
14682: my @contacts = ('supportemail','adminemail');
14683: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
14684: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
14685: my @toggles = ('reporterrors','reportupdates','reportstatus');
14686: my @lonstatus = ('threshold','sysmail','weights','excluded');
14687: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
14688: foreach my $type (@mailings) {
14689: @{$newsetting{$type}} =
14690: &Apache::loncommon::get_env_multiple('form.'.$type);
14691: foreach my $item (@contacts) {
14692: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
14693: $contacts_hash{contacts}{$type}{$item} = 1;
14694: } else {
14695: $contacts_hash{contacts}{$type}{$item} = 0;
14696: }
14697: }
14698: $others{$type} = $env{'form.'.$type.'_others'};
14699: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
14700: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14701: $bcc{$type} = $env{'form.'.$type.'_bcc'};
14702: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
14703: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
14704: $includestr{$type} = $env{'form.'.$type.'_includestr'};
14705: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
14706: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14707: }
14708: }
14709: }
14710: foreach my $item (@contacts) {
14711: $to{$item} = $env{'form.'.$item};
14712: $contacts_hash{'contacts'}{$item} = $to{$item};
14713: }
14714: foreach my $item (@toggles) {
14715: if ($env{'form.'.$item} =~ /^(0|1)$/) {
14716: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
14717: }
14718: }
14719: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
14720: foreach my $item (@lonstatus) {
14721: if ($item eq 'excluded') {
14722: my (%serverhomes,@excluded);
14723: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
14724: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
14725: if (@possexcluded) {
14726: foreach my $id (sort(@possexcluded)) {
14727: if ($serverhomes{$id}) {
14728: push(@excluded,$id);
14729: }
14730: }
14731: }
14732: if (@excluded) {
14733: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
14734: }
14735: } elsif ($item eq 'weights') {
14736: foreach my $type ('E','W','N','U') {
14737: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
14738: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
14739: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
14740: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
14741: $env{'form.error'.$item.'_'.$type};
14742: }
14743: }
14744: }
14745: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
14746: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
14747: if ($env{'form.error'.$item} =~ /^\d+$/) {
14748: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
14749: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
14750: }
14751: }
14752: }
14753: }
14754: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
14755: foreach my $field (@{$fields}) {
14756: if (ref($possoptions->{$field}) eq 'ARRAY') {
14757: my $value = $env{'form.helpform_'.$field};
14758: $value =~ s/^\s+|\s+$//g;
14759: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
14760: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
14761: if ($field eq 'screenshot') {
14762: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
14763: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
14764: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
14765: }
14766: }
14767: }
14768: }
14769: }
14770: }
14771: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14772: my (@statuses,%usertypeshash,@overrides);
14773: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
14774: @statuses = @{$types};
14775: if (ref($usertypes) eq 'HASH') {
14776: %usertypeshash = %{$usertypes};
14777: }
14778: }
14779: if (@statuses) {
14780: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
14781: foreach my $type (@possoverrides) {
14782: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
14783: push(@overrides,$type);
14784: }
14785: }
14786: if (@overrides) {
14787: foreach my $type (@overrides) {
14788: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
14789: foreach my $item (@contacts) {
14790: if (grep(/^\Q$item\E$/,@standard)) {
14791: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
14792: $newsetting{'override_'.$type}{$item} = 1;
14793: } else {
14794: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
14795: $newsetting{'override_'.$type}{$item} = 0;
14796: }
14797: }
14798: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
14799: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14800: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
14801: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14802: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
14803: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
14804: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
14805: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14806: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
14807: }
14808: }
14809: }
14810: }
14811: if (keys(%currsetting) > 0) {
14812: foreach my $item (@contacts) {
14813: if ($to{$item} ne $currsetting{$item}) {
14814: $changes{$item} = 1;
14815: }
14816: }
14817: foreach my $type (@mailings) {
14818: foreach my $item (@contacts) {
14819: if (ref($currsetting{$type}) eq 'HASH') {
14820: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
14821: push(@{$changes{$type}},$item);
14822: }
14823: } else {
14824: push(@{$changes{$type}},@{$newsetting{$type}});
14825: }
14826: }
14827: if ($others{$type} ne $currsetting{$type}{'others'}) {
14828: push(@{$changes{$type}},'others');
14829: }
14830: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14831: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
14832: push(@{$changes{$type}},'bcc');
14833: }
14834: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
14835: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
14836: push(@{$changes{$type}},'include');
14837: }
14838: }
14839: }
14840: if (ref($fields) eq 'ARRAY') {
14841: if (ref($currsetting{'helpform'}) eq 'HASH') {
14842: foreach my $field (@{$fields}) {
14843: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
14844: push(@{$changes{'helpform'}},$field);
14845: }
14846: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14847: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
14848: push(@{$changes{'helpform'}},'maxsize');
14849: }
14850: }
14851: }
14852: } else {
14853: foreach my $field (@{$fields}) {
14854: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14855: push(@{$changes{'helpform'}},$field);
14856: }
14857: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14858: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14859: push(@{$changes{'helpform'}},'maxsize');
14860: }
14861: }
14862: }
14863: }
14864: }
14865: if (@statuses) {
14866: if (ref($currsetting{'overrides'}) eq 'HASH') {
14867: foreach my $key (keys(%{$currsetting{'overrides'}})) {
14868: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
14869: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
14870: foreach my $item (@contacts,'bcc','others','include') {
14871: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
14872: push(@{$changes{'overrides'}},$key);
14873: last;
14874: }
14875: }
14876: } else {
14877: push(@{$changes{'overrides'}},$key);
14878: }
14879: }
14880: }
14881: foreach my $key (@overrides) {
14882: unless (exists($currsetting{'overrides'}{$key})) {
14883: push(@{$changes{'overrides'}},$key);
14884: }
14885: }
14886: } else {
14887: foreach my $key (@overrides) {
14888: push(@{$changes{'overrides'}},$key);
14889: }
14890: }
14891: }
14892: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
14893: foreach my $key ('excluded','weights','threshold','sysmail') {
14894: if ($key eq 'excluded') {
14895: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14896: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
14897: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14898: (@{$currsetting{'lonstatus'}{$key}})) {
14899: my @diffs =
14900: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
14901: $currsetting{'lonstatus'}{$key});
14902: if (@diffs) {
14903: push(@{$changes{'lonstatus'}},$key);
14904: }
14905: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
14906: push(@{$changes{'lonstatus'}},$key);
14907: }
14908: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14909: (@{$currsetting{'lonstatus'}{$key}})) {
14910: push(@{$changes{'lonstatus'}},$key);
14911: }
14912: } elsif ($key eq 'weights') {
14913: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14914: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
14915: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14916: foreach my $type ('E','W','N','U') {
14917: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
14918: $currsetting{'lonstatus'}{$key}{$type}) {
14919: push(@{$changes{'lonstatus'}},$key);
14920: last;
14921: }
14922: }
14923: } else {
14924: foreach my $type ('E','W','N','U') {
14925: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
14926: push(@{$changes{'lonstatus'}},$key);
14927: last;
14928: }
14929: }
14930: }
14931: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14932: foreach my $type ('E','W','N','U') {
14933: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
14934: push(@{$changes{'lonstatus'}},$key);
14935: last;
14936: }
14937: }
14938: }
14939: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
14940: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14941: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14942: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
14943: push(@{$changes{'lonstatus'}},$key);
14944: }
14945: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
14946: push(@{$changes{'lonstatus'}},$key);
14947: }
14948: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14949: push(@{$changes{'lonstatus'}},$key);
14950: }
14951: }
14952: }
14953: } else {
14954: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14955: foreach my $key ('excluded','weights','threshold','sysmail') {
14956: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14957: push(@{$changes{'lonstatus'}},$key);
14958: }
14959: }
14960: }
14961: }
14962: } else {
14963: my %default;
14964: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
14965: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
14966: $default{'errormail'} = 'adminemail';
14967: $default{'packagesmail'} = 'adminemail';
14968: $default{'helpdeskmail'} = 'supportemail';
14969: $default{'otherdomsmail'} = 'supportemail';
14970: $default{'lonstatusmail'} = 'adminemail';
14971: $default{'requestsmail'} = 'adminemail';
14972: $default{'updatesmail'} = 'adminemail';
14973: $default{'hostipmail'} = 'adminemail';
14974: foreach my $item (@contacts) {
14975: if ($to{$item} ne $default{$item}) {
14976: $changes{$item} = 1;
14977: }
14978: }
14979: foreach my $type (@mailings) {
14980: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
14981: push(@{$changes{$type}},@{$newsetting{$type}});
14982: }
14983: if ($others{$type} ne '') {
14984: push(@{$changes{$type}},'others');
14985: }
14986: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14987: if ($bcc{$type} ne '') {
14988: push(@{$changes{$type}},'bcc');
14989: }
14990: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
14991: push(@{$changes{$type}},'include');
14992: }
14993: }
14994: }
14995: if (ref($fields) eq 'ARRAY') {
14996: foreach my $field (@{$fields}) {
14997: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14998: push(@{$changes{'helpform'}},$field);
14999: }
15000: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15001: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15002: push(@{$changes{'helpform'}},'maxsize');
15003: }
15004: }
15005: }
15006: }
15007: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15008: foreach my $key ('excluded','weights','threshold','sysmail') {
15009: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15010: push(@{$changes{'lonstatus'}},$key);
15011: }
15012: }
15013: }
15014: }
15015: foreach my $item (@toggles) {
15016: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15017: $changes{$item} = 1;
15018: } elsif ((!$env{'form.'.$item}) &&
15019: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15020: $changes{$item} = 1;
15021: }
15022: }
15023: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15024: $dom);
15025: if ($putresult eq 'ok') {
15026: if (keys(%changes) > 0) {
15027: &Apache::loncommon::devalidate_domconfig_cache($dom);
15028: if (ref($lastactref) eq 'HASH') {
15029: $lastactref->{'domainconfig'} = 1;
15030: }
15031: my ($titles,$short_titles) = &contact_titles();
15032: $resulttext = &mt('Changes made:').'<ul>';
15033: foreach my $item (@contacts) {
15034: if ($changes{$item}) {
15035: $resulttext .= '<li>'.$titles->{$item}.
15036: &mt(' set to: ').
15037: '<span class="LC_cusr_emph">'.
15038: $to{$item}.'</span></li>';
15039: }
15040: }
15041: foreach my $type (@mailings) {
15042: if (ref($changes{$type}) eq 'ARRAY') {
15043: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
15044: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
15045: } else {
15046: $resulttext .= '<li>'.$titles->{$type}.': ';
15047: }
15048: my @text;
15049: foreach my $item (@{$newsetting{$type}}) {
15050: push(@text,$short_titles->{$item});
15051: }
15052: if ($others{$type} ne '') {
15053: push(@text,$others{$type});
15054: }
15055: if (@text) {
15056: $resulttext .= '<span class="LC_cusr_emph">'.
15057: join(', ',@text).'</span>';
15058: }
15059: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
15060: if ($bcc{$type} ne '') {
15061: my $bcctext;
15062: if (@text) {
15063: $bcctext = ' '.&mt('with Bcc to');
15064: } else {
15065: $bcctext = '(Bcc)';
15066: }
15067: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15068: } elsif (!@text) {
15069: $resulttext .= &mt('No one');
15070: }
15071: if ($includestr{$type} ne '') {
15072: if ($includeloc{$type} eq 'b') {
15073: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15074: } elsif ($includeloc{$type} eq 's') {
15075: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15076: }
15077: }
15078: } elsif (!@text) {
15079: $resulttext .= &mt('No recipients');
15080: }
15081: $resulttext .= '</li>';
15082: }
15083: }
15084: if (ref($changes{'overrides'}) eq 'ARRAY') {
15085: my @deletions;
15086: foreach my $type (@{$changes{'overrides'}}) {
15087: if ($usertypeshash{$type}) {
15088: if (grep(/^\Q$type\E/,@overrides)) {
15089: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15090: $usertypeshash{$type}).'<ul><li>';
15091: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15092: my @text;
15093: foreach my $item (@contacts) {
15094: if ($newsetting{'override_'.$type}{$item}) {
15095: push(@text,$short_titles->{$item});
15096: }
15097: }
15098: if ($newsetting{'override_'.$type}{'others'} ne '') {
15099: push(@text,$newsetting{'override_'.$type}{'others'});
15100: }
15101:
15102: if (@text) {
15103: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15104: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15105: }
15106: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15107: my $bcctext;
15108: if (@text) {
15109: $bcctext = ' '.&mt('with Bcc to');
15110: } else {
15111: $bcctext = '(Bcc)';
15112: }
15113: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15114: } elsif (!@text) {
15115: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15116: }
15117: $resulttext .= '</li>';
15118: if ($newsetting{'override_'.$type}{'include'} ne '') {
15119: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15120: if ($loc eq 'b') {
15121: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15122: } elsif ($loc eq 's') {
15123: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15124: }
15125: }
15126: }
15127: $resulttext .= '</li></ul></li>';
15128: } else {
15129: push(@deletions,$usertypeshash{$type});
15130: }
15131: }
15132: }
15133: if (@deletions) {
15134: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15135: join(', ',@deletions)).'</li>';
15136: }
15137: }
15138: my @offon = ('off','on');
15139: my $corelink = &core_link_msu();
15140: if ($changes{'reporterrors'}) {
15141: $resulttext .= '<li>'.
15142: &mt('E-mail error reports to [_1] set to "'.
15143: $offon[$env{'form.reporterrors'}].'".',
15144: $corelink).
15145: '</li>';
15146: }
15147: if ($changes{'reportupdates'}) {
15148: $resulttext .= '<li>'.
15149: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15150: $offon[$env{'form.reportupdates'}].'".',
15151: $corelink).
15152: '</li>';
15153: }
15154: if ($changes{'reportstatus'}) {
15155: $resulttext .= '<li>'.
15156: &mt('E-mail status if errors above threshold to [_1] set to "'.
15157: $offon[$env{'form.reportstatus'}].'".',
15158: $corelink).
15159: '</li>';
15160: }
15161: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15162: $resulttext .= '<li>'.
15163: &mt('Nightly status check e-mail settings').':<ul>';
15164: my (%defval,%use_def,%shown);
15165: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15166: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15167: $defval{'weights'} =
15168: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
15169: $defval{'excluded'} = &mt('None');
15170: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15171: foreach my $item ('threshold','sysmail','weights','excluded') {
15172: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15173: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15174: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15175: } elsif ($item eq 'weights') {
15176: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
15177: foreach my $type ('E','W','N','U') {
15178: $shown{$item} .= $lonstatus_names->{$type}.'=';
15179: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15180: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15181: } else {
15182: $shown{$item} .= $lonstatus_defs->{$type};
15183: }
15184: $shown{$item} .= ', ';
15185: }
15186: $shown{$item} =~ s/, $//;
15187: } else {
15188: $shown{$item} = $defval{$item};
15189: }
15190: } elsif ($item eq 'excluded') {
15191: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15192: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15193: } else {
15194: $shown{$item} = $defval{$item};
15195: }
15196: }
15197: } else {
15198: $shown{$item} = $defval{$item};
15199: }
15200: }
15201: } else {
15202: foreach my $item ('threshold','weights','excluded','sysmail') {
15203: $shown{$item} = $defval{$item};
15204: }
15205: }
15206: foreach my $item ('threshold','weights','excluded','sysmail') {
15207: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15208: $shown{$item}).'</li>';
15209: }
15210: $resulttext .= '</ul></li>';
15211: }
15212: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15213: my (@optional,@required,@unused,$maxsizechg);
15214: foreach my $field (@{$changes{'helpform'}}) {
15215: if ($field eq 'maxsize') {
15216: $maxsizechg = 1;
15217: next;
15218: }
15219: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
15220: push(@optional,$field);
15221: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15222: push(@unused,$field);
15223: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
15224: push(@required,$field);
15225: }
15226: }
15227: if (@optional) {
15228: $resulttext .= '<li>'.
15229: &mt('Help form fields changed to "Optional": [_1].',
15230: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15231: '</li>';
15232: }
15233: if (@required) {
15234: $resulttext .= '<li>'.
15235: &mt('Help form fields changed to "Required": [_1].',
15236: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15237: '</li>';
15238: }
15239: if (@unused) {
15240: $resulttext .= '<li>'.
15241: &mt('Help form fields changed to "Not shown": [_1].',
15242: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15243: '</li>';
15244: }
15245: if ($maxsizechg) {
15246: $resulttext .= '<li>'.
15247: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15248: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15249: '</li>';
15250: }
15251: }
15252: $resulttext .= '</ul>';
15253: } else {
15254: $resulttext = &mt('No changes made to contacts and form settings');
15255: }
15256: } else {
15257: $resulttext = '<span class="LC_error">'.
15258: &mt('An error occurred: [_1]',$putresult).'</span>';
15259: }
15260: return $resulttext;
15261: }
15262:
15263: sub modify_passwords {
15264: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
15265: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15266: $updatedefaults,$updateconf);
15267: my $customfn = 'resetpw.html';
15268: if (ref($domconfig{'passwords'}) eq 'HASH') {
15269: %current = %{$domconfig{'passwords'}};
15270: }
15271: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15272: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15273: if (ref($types) eq 'ARRAY') {
15274: @oktypes = @{$types};
15275: }
15276: push(@oktypes,'default');
15277:
15278: my %titles = &Apache::lonlocal::texthash (
15279: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15280: intauth_check => 'Check bcrypt cost if authenticated',
15281: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
15282: permanent => 'Permanent e-mail address',
15283: critical => 'Critical notification address',
15284: notify => 'Notification address',
15285: min => 'Minimum password length',
15286: max => 'Maximum password length',
15287: chars => 'Required characters',
15288: numsaved => 'Number of previous passwords to save',
15289: reset => 'Resetting Forgotten Password',
15290: intauth => 'Encryption of Stored Passwords (Internal Auth)',
15291: rules => 'Rules for LON-CAPA Passwords',
15292: crsownerchg => 'Course Owner Changing Student Passwords',
15293: username => 'Username',
15294: email => 'E-mail address',
15295: );
15296:
15297: #
15298: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
15299: #
15300: my (%curr_defaults,%save_defaults);
15301: if (ref($domconfig{'defaults'}) eq 'HASH') {
15302: foreach my $key (keys(%{$domconfig{'defaults'}})) {
15303: if ($key =~ /^intauth_(cost|check|switch)$/) {
15304: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
15305: } else {
15306: $save_defaults{$key} = $domconfig{'defaults'}{$key};
15307: }
15308: }
15309: }
15310: my %staticdefaults = (
15311: 'resetlink' => 2,
15312: 'resetcase' => \@oktypes,
15313: 'resetprelink' => 'both',
15314: 'resetemail' => ['critical','notify','permanent'],
15315: 'intauth_cost' => 10,
15316: 'intauth_check' => 0,
15317: 'intauth_switch' => 0,
15318: );
15319: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
15320: foreach my $type (@oktypes) {
15321: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
15322: }
15323: my $linklife = $env{'form.passwords_link'};
15324: $linklife =~ s/^\s+|\s+$//g;
15325: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
15326: $newvalues{'resetlink'} = $linklife;
15327: if ($current{'resetlink'}) {
15328: if ($current{'resetlink'} ne $linklife) {
15329: $changes{'reset'} = 1;
15330: }
15331: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
15332: if ($staticdefaults{'resetlink'} ne $linklife) {
15333: $changes{'reset'} = 1;
15334: }
15335: }
15336: } elsif ($current{'resetlink'}) {
15337: $changes{'reset'} = 1;
15338: }
15339: my @casesens;
15340: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
15341: foreach my $case (sort(@posscase)) {
15342: if (grep(/^\Q$case\E$/,@oktypes)) {
15343: push(@casesens,$case);
15344: }
15345: }
15346: $newvalues{'resetcase'} = \@casesens;
15347: if (ref($current{'resetcase'}) eq 'ARRAY') {
15348: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
15349: if (@diffs > 0) {
15350: $changes{'reset'} = 1;
15351: }
15352: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
15353: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
15354: if (@diffs > 0) {
15355: $changes{'reset'} = 1;
15356: }
15357: }
15358: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
15359: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
15360: if (exists($current{'resetprelink'})) {
15361: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
15362: $changes{'reset'} = 1;
15363: }
15364: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
15365: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
15366: $changes{'reset'} = 1;
15367: }
15368: }
15369: } elsif ($current{'resetprelink'}) {
15370: $changes{'reset'} = 1;
15371: }
15372: foreach my $type (@oktypes) {
15373: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
15374: my @postlink;
15375: foreach my $item (sort(@possplink)) {
15376: if ($item =~ /^(email|username)$/) {
15377: push(@postlink,$item);
15378: }
15379: }
15380: $newvalues{'resetpostlink'}{$type} = \@postlink;
15381: unless ($changes{'reset'}) {
15382: if (ref($current{'resetpostlink'}) eq 'HASH') {
15383: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
15384: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
15385: if (@diffs > 0) {
15386: $changes{'reset'} = 1;
15387: }
15388: } else {
15389: $changes{'reset'} = 1;
15390: }
15391: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
15392: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
15393: if (@diffs > 0) {
15394: $changes{'reset'} = 1;
15395: }
15396: }
15397: }
15398: }
15399: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
15400: my @resetemail;
15401: foreach my $item (sort(@possemailsrc)) {
15402: if ($item =~ /^(permanent|critical|notify)$/) {
15403: push(@resetemail,$item);
15404: }
15405: }
15406: $newvalues{'resetemail'} = \@resetemail;
15407: unless ($changes{'reset'}) {
15408: if (ref($current{'resetemail'}) eq 'ARRAY') {
15409: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
15410: if (@diffs > 0) {
15411: $changes{'reset'} = 1;
15412: }
15413: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
15414: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
15415: if (@diffs > 0) {
15416: $changes{'reset'} = 1;
15417: }
15418: }
15419: }
15420: if ($env{'form.passwords_stdtext'} == 0) {
15421: $newvalues{'resetremove'} = 1;
15422: unless ($current{'resetremove'}) {
15423: $changes{'reset'} = 1;
15424: }
15425: } elsif ($current{'resetremove'}) {
15426: $changes{'reset'} = 1;
15427: }
15428: if ($env{'form.passwords_customfile.filename'} ne '') {
15429: my $servadm = $r->dir_config('lonAdmEMail');
15430: my ($configuserok,$author_ok,$switchserver) =
15431: &config_check($dom,$confname,$servadm);
15432: my $error;
15433: if ($configuserok eq 'ok') {
15434: if ($switchserver) {
15435: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
15436: } else {
15437: if ($author_ok eq 'ok') {
15438: my $modified = [];
15439: my ($result,$customurl) =
15440: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
15441: $confname,'customtext/resetpw','','',$customfn,
15442: $modified);
15443: if ($result eq 'ok') {
15444: $newvalues{'resetcustom'} = $customurl;
15445: $changes{'reset'} = 1;
15446: &update_modify_urls($r,$modified);
15447: } else {
15448: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
15449: }
15450: } else {
15451: $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$customfn,$confname,$dom,$author_ok);
15452: }
15453: }
15454: } else {
15455: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customfn,$confname,$dom,$configuserok);
15456: }
15457: if ($error) {
15458: &Apache::lonnet::logthis($error);
15459: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15460: }
15461: } elsif ($current{'resetcustom'}) {
15462: if ($env{'form.passwords_custom_del'}) {
15463: $changes{'reset'} = 1;
15464: } else {
15465: $newvalues{'resetcustom'} = $current{'resetcustom'};
15466: }
15467: }
15468: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
15469: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
15470: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
15471: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
15472: $changes{'intauth'} = 1;
15473: }
15474: } else {
15475: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
15476: }
15477: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
15478: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
15479: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
15480: $changes{'intauth'} = 1;
15481: }
15482: } else {
15483: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
15484: }
15485: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
15486: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
15487: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
15488: $changes{'intauth'} = 1;
15489: }
15490: } else {
15491: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
15492: }
15493: foreach my $item ('cost','check','switch') {
15494: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
15495: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
15496: $updatedefaults = 1;
15497: }
15498: }
15499: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
15500: my %crsownerchg = (
15501: by => [],
15502: for => [],
15503: );
15504: foreach my $item ('by','for') {
15505: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
15506: foreach my $type (sort(@posstypes)) {
15507: if (grep(/^\Q$type\E$/,@oktypes)) {
15508: push(@{$crsownerchg{$item}},$type);
15509: }
15510: }
15511: }
15512: $newvalues{'crsownerchg'} = \%crsownerchg;
15513: if (ref($current{'crsownerchg'}) eq 'HASH') {
15514: foreach my $item ('by','for') {
15515: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
15516: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
15517: if (@diffs > 0) {
15518: $changes{'crsownerchg'} = 1;
15519: last;
15520: }
15521: }
15522: }
15523: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
15524: foreach my $item ('by','for') {
15525: if (@{$crsownerchg{$item}} > 0) {
15526: $changes{'crsownerchg'} = 1;
15527: last;
15528: }
15529: }
15530: }
15531:
15532: my %confighash = (
15533: defaults => \%save_defaults,
15534: passwords => \%newvalues,
15535: );
15536: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
15537:
15538: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
15539: if ($putresult eq 'ok') {
15540: if (keys(%changes) > 0) {
15541: $resulttext = &mt('Changes made: ').'<ul>';
15542: foreach my $key ('reset','intauth','rules','crsownerchg') {
15543: if ($changes{$key}) {
15544: unless ($key eq 'intauth') {
15545: $updateconf = 1;
15546: }
15547: $resulttext .= '<li>'.$titles{$key}.':<ul>';
15548: if ($key eq 'reset') {
15549: if ($confighash{'passwords'}{'captcha'} eq 'original') {
15550: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
15551: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
15552: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
15553: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
15554: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
15555: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
15556: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
15557: }
15558: } else {
15559: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
15560: }
15561: if ($confighash{'passwords'}{'resetlink'}) {
15562: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
15563: } else {
15564: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
15565: &mt('Will default to 2 hours').'</li>';
15566: }
15567: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
15568: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
15569: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
15570: } else {
15571: my $casesens;
15572: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
15573: if ($type eq 'default') {
15574: $casesens .= $othertitle.', ';
15575: } elsif ($usertypes->{$type} ne '') {
15576: $casesens .= $usertypes->{$type}.', ';
15577: }
15578: }
15579: $casesens =~ s/\Q, \E$//;
15580: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
15581: }
15582: } else {
15583: $resulttext .= '<li>'.&mt('Case-sensitivity not set for "Forgot Password" web form').' '.&mt('Will default to case-sensitive for username and/or e-mail address for all').'</li>';
15584: }
15585: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
15586: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
15587: } else {
15588: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
15589: }
15590: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
15591: my $output;
15592: if (ref($types) eq 'ARRAY') {
15593: foreach my $type (@{$types}) {
15594: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
15595: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
15596: $output .= $usertypes->{$type}.' -- '.&mt('none');
15597: } else {
15598: $output .= $usertypes->{$type}.' -- '.
15599: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
15600: }
15601: }
15602: }
15603: }
15604: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
15605: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
15606: $output .= $othertitle.' -- '.&mt('none');
15607: } else {
15608: $output .= $othertitle.' -- '.
15609: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
15610: }
15611: }
15612: if ($output) {
15613: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
15614: } else {
15615: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
15616: }
15617: } else {
15618: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
15619: }
15620: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
15621: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
15622: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
15623: } else {
15624: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
15625: }
15626: } else {
15627: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
15628: }
15629: if ($confighash{'passwords'}{'resetremove'}) {
15630: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
15631: } else {
15632: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
15633: }
15634: if ($confighash{'passwords'}{'resetcustom'}) {
15635: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
15636: &mt('custom text'),600,500,undef,undef,
15637: undef,undef,'background-color:#ffffff');
15638: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
15639: } else {
15640: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
15641: }
15642: } elsif ($key eq 'intauth') {
15643: foreach my $item ('cost','switch','check') {
15644: my $value = $save_defaults{$key.'_'.$item};
15645: if ($item eq 'switch') {
15646: my %optiondesc = &Apache::lonlocal::texthash (
15647: 0 => 'No',
15648: 1 => 'Yes',
15649: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
15650: );
15651: if ($value =~ /^(0|1|2)$/) {
15652: $value = $optiondesc{$value};
15653: } else {
15654: $value = &mt('none -- defaults to No');
15655: }
15656: } elsif ($item eq 'check') {
15657: my %optiondesc = &Apache::lonlocal::texthash (
15658: 0 => 'No',
15659: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
15660: 2 => 'Yes, disallow login if stored cost is less than domain default',
15661: );
15662: if ($value =~ /^(0|1|2)$/) {
15663: $value = $optiondesc{$value};
15664: } else {
15665: $value = &mt('none -- defaults to No');
15666: }
15667: }
15668: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
15669: }
15670: } elsif ($key eq 'rules') {
15671: foreach my $rule ('min','max','numsaved') {
15672: if ($confighash{'passwords'}{$rule} eq '') {
15673: if ($rule eq 'min') {
15674: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15675: ' '.&mt('Default of [_1] will be used',
15676: $Apache::lonnet::passwdmin).'</li>';
15677: } else {
15678: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15679: }
15680: } else {
15681: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
15682: }
15683: }
15684: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
15685: if (@{$confighash{'passwords'}{'chars'}} > 0) {
15686: my %rulenames = &Apache::lonlocal::texthash(
15687: uc => 'At least one upper case letter',
15688: lc => 'At least one lower case letter',
15689: num => 'At least one number',
15690: spec => 'At least one non-alphanumeric',
15691: );
15692: my $needed = '<ul><li>'.
15693: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
15694: '</li></ul>';
15695: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15696: } else {
15697: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
15698: }
15699: } else {
15700: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
15701: }
15702: } elsif ($key eq 'crsownerchg') {
15703: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
15704: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
15705: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
15706: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
15707: } else {
15708: my %crsownerstr;
15709: foreach my $item ('by','for') {
15710: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
15711: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
15712: if ($type eq 'default') {
15713: $crsownerstr{$item} .= $othertitle.', ';
15714: } elsif ($usertypes->{$type} ne '') {
15715: $crsownerstr{$item} .= $usertypes->{$type}.', ';
15716: }
15717: }
15718: $crsownerstr{$item} =~ s/\Q, \E$//;
15719: }
15720: }
15721: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
15722: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
15723: }
15724: } else {
15725: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
15726: }
15727: }
15728: $resulttext .= '</ul></li>';
15729: }
15730: }
15731: $resulttext .= '</ul>';
15732: } else {
15733: $resulttext = &mt('No changes made to password settings');
15734: }
15735: my $cachetime = 24*60*60;
15736: if ($updatedefaults) {
15737: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15738: if (ref($lastactref) eq 'HASH') {
15739: $lastactref->{'domdefaults'} = 1;
15740: }
15741: }
15742: if ($updateconf) {
15743: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
15744: if (ref($lastactref) eq 'HASH') {
15745: $lastactref->{'passwdconf'} = 1;
15746: }
15747: }
15748: } else {
15749: $resulttext = '<span class="LC_error">'.
15750: &mt('An error occurred: [_1]',$putresult).'</span>';
15751: }
15752: if ($errors) {
15753: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15754: $errors.'</ul></p>';
15755: }
15756: return $resulttext;
15757: }
15758:
15759: sub password_rule_changes {
15760: my ($prefix,$newvalues,$current,$changes) = @_;
15761: return unless ((ref($newvalues) eq 'HASH') &&
15762: (ref($current) eq 'HASH') &&
15763: (ref($changes) eq 'HASH'));
15764: my (@rules,%staticdefaults);
15765: if ($prefix eq 'passwords') {
15766: @rules = ('min','max','numsaved');
15767: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
15768: @rules = ('min','max');
15769: }
15770: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
15771: foreach my $rule (@rules) {
15772: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
15773: my $ruleok;
15774: if ($rule eq 'min') {
15775: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
15776: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
15777: $ruleok = 1;
15778: }
15779: }
15780: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
15781: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
15782: $ruleok = 1;
15783: }
15784: if ($ruleok) {
15785: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
15786: if (exists($current->{$rule})) {
15787: if ($newvalues->{$rule} ne $current->{$rule}) {
15788: $changes->{'rules'} = 1;
15789: }
15790: } elsif ($rule eq 'min') {
15791: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
15792: $changes->{'rules'} = 1;
15793: }
15794: } else {
15795: $changes->{'rules'} = 1;
15796: }
15797: } elsif (exists($current->{$rule})) {
15798: $changes->{'rules'} = 1;
15799: }
15800: }
15801: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
15802: my @chars;
15803: foreach my $item (sort(@posschars)) {
15804: if ($item =~ /^(uc|lc|num|spec)$/) {
15805: push(@chars,$item);
15806: }
15807: }
15808: $newvalues->{'chars'} = \@chars;
15809: unless ($changes->{'rules'}) {
15810: if (ref($current->{'chars'}) eq 'ARRAY') {
15811: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
15812: if (@diffs > 0) {
15813: $changes->{'rules'} = 1;
15814: }
15815: } else {
15816: if (@chars > 0) {
15817: $changes->{'rules'} = 1;
15818: }
15819: }
15820: }
15821: return;
15822: }
15823:
15824: sub modify_usercreation {
15825: my ($dom,%domconfig) = @_;
15826: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
15827: my $warningmsg;
15828: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15829: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15830: if ($key eq 'cancreate') {
15831: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15832: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15833: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
15834: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15835: } else {
15836: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15837: }
15838: }
15839: }
15840: } elsif ($key eq 'email_rule') {
15841: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15842: } else {
15843: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15844: }
15845: }
15846: }
15847: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
15848: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
15849: my @contexts = ('author','course','requestcrs');
15850: foreach my $item(@contexts) {
15851: $cancreate{$item} = $env{'form.can_createuser_'.$item};
15852: }
15853: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15854: foreach my $item (@contexts) {
15855: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
15856: push(@{$changes{'cancreate'}},$item);
15857: }
15858: }
15859: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
15860: foreach my $item (@contexts) {
15861: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
15862: if ($cancreate{$item} ne 'any') {
15863: push(@{$changes{'cancreate'}},$item);
15864: }
15865: } else {
15866: if ($cancreate{$item} ne 'none') {
15867: push(@{$changes{'cancreate'}},$item);
15868: }
15869: }
15870: }
15871: } else {
15872: foreach my $item (@contexts) {
15873: push(@{$changes{'cancreate'}},$item);
15874: }
15875: }
15876:
15877: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
15878: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
15879: if (!grep(/^\Q$type\E$/,@username_rule)) {
15880: push(@{$changes{'username_rule'}},$type);
15881: }
15882: }
15883: foreach my $type (@username_rule) {
15884: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
15885: push(@{$changes{'username_rule'}},$type);
15886: }
15887: }
15888: } else {
15889: push(@{$changes{'username_rule'}},@username_rule);
15890: }
15891:
15892: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
15893: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
15894: if (!grep(/^\Q$type\E$/,@id_rule)) {
15895: push(@{$changes{'id_rule'}},$type);
15896: }
15897: }
15898: foreach my $type (@id_rule) {
15899: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
15900: push(@{$changes{'id_rule'}},$type);
15901: }
15902: }
15903: } else {
15904: push(@{$changes{'id_rule'}},@id_rule);
15905: }
15906:
15907: my @authen_contexts = ('author','course','domain');
15908: my @authtypes = ('int','krb4','krb5','loc','lti');
15909: my %authhash;
15910: foreach my $item (@authen_contexts) {
15911: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
15912: foreach my $auth (@authtypes) {
15913: if (grep(/^\Q$auth\E$/,@authallowed)) {
15914: $authhash{$item}{$auth} = 1;
15915: } else {
15916: $authhash{$item}{$auth} = 0;
15917: }
15918: }
15919: }
15920: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
15921: foreach my $item (@authen_contexts) {
15922: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
15923: foreach my $auth (@authtypes) {
15924: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15925: push(@{$changes{'authtypes'}},$item);
15926: last;
15927: }
15928: }
15929: }
15930: }
15931: } else {
15932: foreach my $item (@authen_contexts) {
15933: push(@{$changes{'authtypes'}},$item);
15934: }
15935: }
15936:
15937: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15938: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15939: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15940: $save_usercreate{'id_rule'} = \@id_rule;
15941: $save_usercreate{'username_rule'} = \@username_rule,
15942: $save_usercreate{'authtypes'} = \%authhash;
15943:
15944: my %usercreation_hash = (
15945: usercreation => \%save_usercreate,
15946: );
15947:
15948: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15949: $dom);
15950:
15951: if ($putresult eq 'ok') {
15952: if (keys(%changes) > 0) {
15953: $resulttext = &mt('Changes made:').'<ul>';
15954: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15955: my %lt = &usercreation_types();
15956: foreach my $type (@{$changes{'cancreate'}}) {
15957: my $chgtext = $lt{$type}.', ';
15958: if ($cancreate{$type} eq 'none') {
15959: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15960: } elsif ($cancreate{$type} eq 'any') {
15961: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15962: } elsif ($cancreate{$type} eq 'official') {
15963: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15964: } elsif ($cancreate{$type} eq 'unofficial') {
15965: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15966: }
15967: $resulttext .= '<li>'.$chgtext.'</li>';
15968: }
15969: }
15970: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15971: my ($rules,$ruleorder) =
15972: &Apache::lonnet::inst_userrules($dom,'username');
15973: my $chgtext = '<ul>';
15974: foreach my $type (@username_rule) {
15975: if (ref($rules->{$type}) eq 'HASH') {
15976: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15977: }
15978: }
15979: $chgtext .= '</ul>';
15980: if (@username_rule > 0) {
15981: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15982: } else {
15983: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15984: }
15985: }
15986: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15987: my ($idrules,$idruleorder) =
15988: &Apache::lonnet::inst_userrules($dom,'id');
15989: my $chgtext = '<ul>';
15990: foreach my $type (@id_rule) {
15991: if (ref($idrules->{$type}) eq 'HASH') {
15992: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15993: }
15994: }
15995: $chgtext .= '</ul>';
15996: if (@id_rule > 0) {
15997: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15998: } else {
15999: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16000: }
16001: }
16002: my %authname = &authtype_names();
16003: my %context_title = &context_names();
16004: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16005: my $chgtext = '<ul>';
16006: foreach my $type (@{$changes{'authtypes'}}) {
16007: my @allowed;
16008: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16009: foreach my $auth (@authtypes) {
16010: if ($authhash{$type}{$auth}) {
16011: push(@allowed,$authname{$auth});
16012: }
16013: }
16014: if (@allowed > 0) {
16015: $chgtext .= join(', ',@allowed).'</li>';
16016: } else {
16017: $chgtext .= &mt('none').'</li>';
16018: }
16019: }
16020: $chgtext .= '</ul>';
16021: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16022: $resulttext .= '</li>';
16023: }
16024: $resulttext .= '</ul>';
16025: } else {
16026: $resulttext = &mt('No changes made to user creation settings');
16027: }
16028: } else {
16029: $resulttext = '<span class="LC_error">'.
16030: &mt('An error occurred: [_1]',$putresult).'</span>';
16031: }
16032: if ($warningmsg ne '') {
16033: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16034: }
16035: return $resulttext;
16036: }
16037:
16038: sub modify_selfcreation {
16039: my ($dom,$lastactref,%domconfig) = @_;
16040: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16041: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16042: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16043: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16044: if (ref($typesref) eq 'ARRAY') {
16045: @types = @{$typesref};
16046: }
16047: if (ref($usertypesref) eq 'HASH') {
16048: %usertypes = %{$usertypesref};
16049: }
16050: $usertypes{'default'} = $othertitle;
16051: #
16052: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16053: #
16054: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16055: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16056: if ($key eq 'cancreate') {
16057: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16058: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16059: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
16060: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16061: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16062: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16063: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
16064: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
16065: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16066: } else {
16067: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16068: }
16069: }
16070: }
16071: } elsif ($key eq 'email_rule') {
16072: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16073: } else {
16074: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16075: }
16076: }
16077: }
16078: #
16079: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16080: #
16081: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16082: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16083: if ($key eq 'selfcreate') {
16084: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16085: } else {
16086: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16087: }
16088: }
16089: }
16090: #
16091: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16092: #
16093: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16094: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16095: if ($key eq 'inststatusguest') {
16096: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16097: } else {
16098: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16099: }
16100: }
16101: }
16102:
16103: my @contexts = ('selfcreate');
16104: @{$cancreate{'selfcreate'}} = ();
16105: %{$cancreate{'emailusername'}} = ();
16106: if (@types) {
16107: @{$cancreate{'statustocreate'}} = ();
16108: }
16109: %{$cancreate{'selfcreateprocessing'}} = ();
16110: %{$cancreate{'shibenv'}} = ();
16111: %{$cancreate{'emailverified'}} = ();
16112: %{$cancreate{'emailoptions'}} = ();
16113: %{$cancreate{'emaildomain'}} = ();
16114: my %selfcreatetypes = (
16115: sso => 'users authenticated by institutional single sign on',
16116: login => 'users authenticated by institutional log-in',
16117: email => 'users verified by e-mail',
16118: );
16119: #
16120: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16121: # is permitted.
16122: #
16123: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
16124:
16125: my (@statuses,%email_rule);
16126: foreach my $item ('login','sso','email') {
16127: if ($item eq 'email') {
16128: if ($env{'form.cancreate_email'}) {
16129: if (@types) {
16130: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16131: foreach my $status (@poss_statuses) {
16132: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16133: push(@statuses,$status);
16134: }
16135: }
16136: $save_inststatus{'inststatusguest'} = \@statuses;
16137: } else {
16138: push(@statuses,'default');
16139: }
16140: if (@statuses) {
16141: my %curr_rule;
16142: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16143: foreach my $type (@statuses) {
16144: $curr_rule{$type} = $curr_usercreation{'email_rule'};
16145: }
16146: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16147: foreach my $type (@statuses) {
16148: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16149: }
16150: }
16151: push(@{$cancreate{'selfcreate'}},'email');
16152: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16153: my %curremaildom;
16154: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16155: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16156: }
16157: foreach my $type (@statuses) {
16158: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16159: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16160: }
16161: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16162: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16163: }
16164: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16165: #
16166: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16167: #
16168: my $chosen = $1;
16169: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16170: my $emaildom;
16171: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16172: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16173: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16174: if (ref($curremaildom{$type}) eq 'HASH') {
16175: if (exists($curremaildom{$type}{$chosen})) {
16176: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16177: push(@{$changes{'cancreate'}},'emaildomain');
16178: }
16179: } elsif ($emaildom ne '') {
16180: push(@{$changes{'cancreate'}},'emaildomain');
16181: }
16182: } elsif ($emaildom ne '') {
16183: push(@{$changes{'cancreate'}},'emaildomain');
16184: }
16185: }
16186: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16187: } elsif ($chosen eq 'custom') {
16188: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16189: $email_rule{$type} = [];
16190: if (ref($emailrules) eq 'HASH') {
16191: foreach my $rule (@possemail_rules) {
16192: if (exists($emailrules->{$rule})) {
16193: push(@{$email_rule{$type}},$rule);
16194: }
16195: }
16196: }
16197: if (@{$email_rule{$type}}) {
16198: $cancreate{'emailoptions'}{$type} = 'custom';
16199: if (ref($curr_rule{$type}) eq 'ARRAY') {
16200: if (@{$curr_rule{$type}} > 0) {
16201: foreach my $rule (@{$curr_rule{$type}}) {
16202: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16203: push(@{$changes{'email_rule'}},$type);
16204: }
16205: }
16206: }
16207: foreach my $type (@{$email_rule{$type}}) {
16208: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16209: push(@{$changes{'email_rule'}},$type);
16210: }
16211: }
16212: } else {
16213: push(@{$changes{'email_rule'}},$type);
16214: }
16215: }
16216: } else {
16217: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16218: }
16219: }
16220: }
16221: if (@types) {
16222: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16223: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16224: if (@changed) {
16225: push(@{$changes{'inststatus'}},'inststatusguest');
16226: }
16227: } else {
16228: push(@{$changes{'inststatus'}},'inststatusguest');
16229: }
16230: }
16231: } else {
16232: delete($env{'form.cancreate_email'});
16233: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16234: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16235: push(@{$changes{'inststatus'}},'inststatusguest');
16236: }
16237: }
16238: }
16239: } else {
16240: $save_inststatus{'inststatusguest'} = [];
16241: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16242: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16243: push(@{$changes{'inststatus'}},'inststatusguest');
16244: }
16245: }
16246: }
16247: } else {
16248: if ($env{'form.cancreate_'.$item}) {
16249: push(@{$cancreate{'selfcreate'}},$item);
16250: }
16251: }
16252: }
16253: my (%userinfo,%savecaptcha);
16254: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16255: #
16256: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16257: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
16258: #
16259:
16260: if ($env{'form.cancreate_email'}) {
16261: push(@contexts,'emailusername');
16262: if (@statuses) {
16263: foreach my $type (@statuses) {
16264: if (ref($infofields) eq 'ARRAY') {
16265: foreach my $field (@{$infofields}) {
16266: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16267: $cancreate{'emailusername'}{$type}{$field} = $1;
16268: }
16269: }
16270: }
16271: }
16272: }
16273: #
16274: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
16275: # queued requests for self-creation of account verified by e-mail.
16276: #
16277:
16278: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16279: @approvalnotify = sort(@approvalnotify);
16280: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16281: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16282: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
16283: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
16284: push(@{$changes{'cancreate'}},'notify');
16285: }
16286: } else {
16287: if ($cancreate{'notify'}{'approval'}) {
16288: push(@{$changes{'cancreate'}},'notify');
16289: }
16290: }
16291: } elsif ($cancreate{'notify'}{'approval'}) {
16292: push(@{$changes{'cancreate'}},'notify');
16293: }
16294:
16295: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
16296: }
16297: #
16298: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
16299: # institutional log-in.
16300: #
16301: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
16302: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
16303: ($domdefaults{'auth_def'} eq 'localauth'))) {
16304: $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.
16305: &mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');
16306: }
16307: }
16308: my @fields = ('lastname','firstname','middlename','generation',
16309: 'permanentemail','id');
16310: my @shibfields = (@fields,'inststatus');
16311: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16312: #
16313: # Where usernames may created for institutional log-in and/or institutional single sign on:
16314: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
16315: # may self-create accounts
16316: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
16317: # which the user may supply, if institutional data is unavailable.
16318: #
16319: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
16320: if (@types) {
16321: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
16322: push(@contexts,'statustocreate');
16323: foreach my $type (@types) {
16324: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
16325: foreach my $field (@fields) {
16326: if (grep(/^\Q$field\E$/,@modifiable)) {
16327: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
16328: } else {
16329: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
16330: }
16331: }
16332: }
16333: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
16334: foreach my $type (@types) {
16335: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
16336: foreach my $field (@fields) {
16337: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
16338: $curr_usermodify{'selfcreate'}{$type}{$field}) {
16339: push(@{$changes{'selfcreate'}},$type);
16340: last;
16341: }
16342: }
16343: }
16344: }
16345: } else {
16346: foreach my $type (@types) {
16347: push(@{$changes{'selfcreate'}},$type);
16348: }
16349: }
16350: }
16351: foreach my $field (@shibfields) {
16352: if ($env{'form.shibenv_'.$field} ne '') {
16353: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
16354: }
16355: }
16356: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16357: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
16358: foreach my $field (@shibfields) {
16359: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
16360: push(@{$changes{'cancreate'}},'shibenv');
16361: }
16362: }
16363: } else {
16364: foreach my $field (@shibfields) {
16365: if ($env{'form.shibenv_'.$field}) {
16366: push(@{$changes{'cancreate'}},'shibenv');
16367: last;
16368: }
16369: }
16370: }
16371: }
16372: }
16373: foreach my $item (@contexts) {
16374: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
16375: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
16376: if (ref($cancreate{$item}) eq 'ARRAY') {
16377: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
16378: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16379: push(@{$changes{'cancreate'}},$item);
16380: }
16381: }
16382: }
16383: }
16384: if (ref($cancreate{$item}) eq 'ARRAY') {
16385: foreach my $type (@{$cancreate{$item}}) {
16386: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
16387: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16388: push(@{$changes{'cancreate'}},$item);
16389: }
16390: }
16391: }
16392: }
16393: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
16394: if (ref($cancreate{$item}) eq 'HASH') {
16395: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
16396: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
16397: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
16398: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
16399: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16400: push(@{$changes{'cancreate'}},$item);
16401: }
16402: }
16403: }
16404: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16405: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
16406: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16407: push(@{$changes{'cancreate'}},$item);
16408: }
16409: }
16410: }
16411: }
16412: foreach my $type (keys(%{$cancreate{$item}})) {
16413: if (ref($cancreate{$item}{$type}) eq 'HASH') {
16414: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
16415: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
16416: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
16417: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16418: push(@{$changes{'cancreate'}},$item);
16419: }
16420: }
16421: } else {
16422: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16423: push(@{$changes{'cancreate'}},$item);
16424: }
16425: }
16426: }
16427: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16428: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
16429: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16430: push(@{$changes{'cancreate'}},$item);
16431: }
16432: }
16433: }
16434: }
16435: }
16436: } elsif ($curr_usercreation{'cancreate'}{$item}) {
16437: if (ref($cancreate{$item}) eq 'ARRAY') {
16438: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
16439: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16440: push(@{$changes{'cancreate'}},$item);
16441: }
16442: }
16443: }
16444: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16445: if (ref($cancreate{$item}) eq 'HASH') {
16446: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16447: push(@{$changes{'cancreate'}},$item);
16448: }
16449: }
16450: } elsif ($item eq 'emailusername') {
16451: if (ref($cancreate{$item}) eq 'HASH') {
16452: foreach my $type (keys(%{$cancreate{$item}})) {
16453: if (ref($cancreate{$item}{$type}) eq 'HASH') {
16454: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
16455: if ($cancreate{$item}{$type}{$field}) {
16456: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16457: push(@{$changes{'cancreate'}},$item);
16458: }
16459: last;
16460: }
16461: }
16462: }
16463: }
16464: }
16465: }
16466: }
16467: #
16468: # Populate %save_usercreate hash with updates to self-creation configuration.
16469: #
16470: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
16471: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
16472: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
16473: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
16474: if (ref($cancreate{'notify'}) eq 'HASH') {
16475: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
16476: }
16477: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
16478: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
16479: }
16480: if (ref($cancreate{'emailverified'}) eq 'HASH') {
16481: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
16482: }
16483: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
16484: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
16485: }
16486: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
16487: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
16488: }
16489: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
16490: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
16491: }
16492: if (ref($cancreate{'shibenv'}) eq 'HASH') {
16493: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
16494: }
16495: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
16496: $save_usercreate{'email_rule'} = \%email_rule;
16497:
16498: my %userconfig_hash = (
16499: usercreation => \%save_usercreate,
16500: usermodification => \%save_usermodify,
16501: inststatus => \%save_inststatus,
16502: );
16503:
16504: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
16505: $dom);
16506: #
16507: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
16508: #
16509: if ($putresult eq 'ok') {
16510: if (keys(%changes) > 0) {
16511: $resulttext = &mt('Changes made:').'<ul>';
16512: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16513: my %lt = &selfcreation_types();
16514: foreach my $type (@{$changes{'cancreate'}}) {
16515: my $chgtext = '';
16516: if ($type eq 'selfcreate') {
16517: if (@{$cancreate{$type}} == 0) {
16518: $chgtext .= &mt('Self creation of a new user account is not permitted.');
16519: } else {
16520: $chgtext .= &mt('Self-creation of a new account is permitted for:').
16521: '<ul>';
16522: foreach my $case (@{$cancreate{$type}}) {
16523: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
16524: }
16525: $chgtext .= '</ul>';
16526: if (ref($cancreate{$type}) eq 'ARRAY') {
16527: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
16528: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
16529: if (@{$cancreate{'statustocreate'}} == 0) {
16530: $chgtext .= '<span class="LC_warning">'.
16531: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
16532: '</span><br />';
16533: }
16534: }
16535: }
16536: if (grep(/^email$/,@{$cancreate{$type}})) {
16537: if (!@statuses) {
16538: $chgtext .= '<span class="LC_warning">'.
16539: &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
16540: '</span><br />';
16541:
16542: }
16543: }
16544: }
16545: }
16546: } elsif ($type eq 'shibenv') {
16547: if (keys(%{$cancreate{$type}}) == 0) {
16548: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
16549: } else {
16550: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
16551: '<ul>';
16552: foreach my $field (@shibfields) {
16553: next if ($cancreate{$type}{$field} eq '');
16554: if ($field eq 'inststatus') {
16555: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
16556: } else {
16557: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
16558: }
16559: }
16560: $chgtext .= '</ul>';
16561: }
16562: } elsif ($type eq 'statustocreate') {
16563: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
16564: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
16565: if (@{$cancreate{'selfcreate'}} > 0) {
16566: if (@{$cancreate{'statustocreate'}} == 0) {
16567: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
16568: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
16569: $chgtext .= '<br />'.
16570: '<span class="LC_warning">'.
16571: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
16572: '</span>';
16573: }
16574: } elsif (keys(%usertypes) > 0) {
16575: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
16576: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
16577: } else {
16578: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
16579: }
16580: $chgtext .= '<ul>';
16581: foreach my $case (@{$cancreate{$type}}) {
16582: if ($case eq 'default') {
16583: $chgtext .= '<li>'.$othertitle.'</li>';
16584: } else {
16585: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
16586: }
16587: }
16588: $chgtext .= '</ul>';
16589: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
16590: $chgtext .= '<span class="LC_warning">'.
16591: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
16592: '</span>';
16593: }
16594: }
16595: } else {
16596: if (@{$cancreate{$type}} == 0) {
16597: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
16598: } else {
16599: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
16600: }
16601: }
16602: $chgtext .= '<br />';
16603: }
16604: } elsif ($type eq 'selfcreateprocessing') {
16605: my %choices = &Apache::lonlocal::texthash (
16606: automatic => 'Automatic approval',
16607: approval => 'Queued for approval',
16608: );
16609: if (@types) {
16610: if (@statuses) {
16611: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
16612: '<ul>';
16613: foreach my $status (@statuses) {
16614: if ($status eq 'default') {
16615: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
16616: } else {
16617: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
16618: }
16619: }
16620: $chgtext .= '</ul>';
16621: }
16622: } else {
16623: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
16624: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
16625: }
16626: } elsif ($type eq 'emailverified') {
16627: my %options = &Apache::lonlocal::texthash (
16628: all => 'Same as e-mail',
16629: first => 'Omit @domain',
16630: free => 'Free to choose',
16631: );
16632: if (@types) {
16633: if (@statuses) {
16634: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
16635: '<ul>';
16636: foreach my $status (@statuses) {
16637: if ($status eq 'default') {
16638: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
16639: } else {
16640: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
16641: }
16642: }
16643: $chgtext .= '</ul>';
16644: }
16645: } else {
16646: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
16647: $options{$cancreate{'emailverified'}{'default'}});
16648: }
16649: } elsif ($type eq 'emailoptions') {
16650: my %options = &Apache::lonlocal::texthash (
16651: any => 'Any e-mail',
16652: inst => 'Institutional only',
16653: noninst => 'Non-institutional only',
16654: custom => 'Custom restrictions',
16655: );
16656: if (@types) {
16657: if (@statuses) {
16658: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
16659: '<ul>';
16660: foreach my $status (@statuses) {
16661: if ($type eq 'default') {
16662: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
16663: } else {
16664: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
16665: }
16666: }
16667: $chgtext .= '</ul>';
16668: }
16669: } else {
16670: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
16671: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
16672: } else {
16673: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
16674: $options{$cancreate{'emailoptions'}{'default'}});
16675: }
16676: }
16677: } elsif ($type eq 'emaildomain') {
16678: my $output;
16679: if (@statuses) {
16680: foreach my $type (@statuses) {
16681: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
16682: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
16683: if ($type eq 'default') {
16684: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16685: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
16686: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
16687: } else {
16688: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
16689: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
16690: }
16691: } else {
16692: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16693: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
16694: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
16695: } else {
16696: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
16697: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
16698: }
16699: }
16700: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
16701: if ($type eq 'default') {
16702: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16703: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
16704: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
16705: } else {
16706: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
16707: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
16708: }
16709: } else {
16710: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16711: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
16712: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
16713: } else {
16714: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
16715: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
16716: }
16717: }
16718: }
16719: }
16720: }
16721: }
16722: if ($output ne '') {
16723: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
16724: '<ul>'.$output.'</ul>';
16725: }
16726: } elsif ($type eq 'captcha') {
16727: if ($savecaptcha{$type} eq 'notused') {
16728: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
16729: } else {
16730: my %captchas = &captcha_phrases();
16731: if ($captchas{$savecaptcha{$type}}) {
16732: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
16733: } else {
16734: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
16735: }
16736: }
16737: } elsif ($type eq 'recaptchakeys') {
16738: my ($privkey,$pubkey);
16739: if (ref($savecaptcha{$type}) eq 'HASH') {
16740: $pubkey = $savecaptcha{$type}{'public'};
16741: $privkey = $savecaptcha{$type}{'private'};
16742: }
16743: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
16744: if (!$pubkey) {
16745: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
16746: } else {
16747: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
16748: }
16749: if (!$privkey) {
16750: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
16751: } else {
16752: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
16753: }
16754: $chgtext .= '</ul>';
16755: } elsif ($type eq 'recaptchaversion') {
16756: if ($savecaptcha{'captcha'} eq 'recaptcha') {
16757: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
16758: }
16759: } elsif ($type eq 'emailusername') {
16760: if (ref($cancreate{'emailusername'}) eq 'HASH') {
16761: if (@statuses) {
16762: foreach my $type (@statuses) {
16763: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
16764: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
16765: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
16766: '<ul>';
16767: foreach my $field (@{$infofields}) {
16768: if ($cancreate{'emailusername'}{$type}{$field}) {
16769: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
16770: }
16771: }
16772: $chgtext .= '</ul>';
16773: } else {
16774: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
16775: }
16776: } else {
16777: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
16778: }
16779: }
16780: }
16781: }
16782: } elsif ($type eq 'notify') {
16783: my $numapprove = 0;
16784: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16785: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
16786: if ($cancreate{'notify'}{'approval'}) {
16787: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
16788: $numapprove ++;
16789: }
16790: }
16791: }
16792: unless ($numapprove) {
16793: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
16794: }
16795: }
16796: if ($chgtext) {
16797: $resulttext .= '<li>'.$chgtext.'</li>';
16798: }
16799: }
16800: }
16801: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
16802: my ($emailrules,$emailruleorder) =
16803: &Apache::lonnet::inst_userrules($dom,'email');
16804: foreach my $type (@{$changes{'email_rule'}}) {
16805: if (ref($email_rule{$type}) eq 'ARRAY') {
16806: my $chgtext = '<ul>';
16807: foreach my $rule (@{$email_rule{$type}}) {
16808: if (ref($emailrules->{$rule}) eq 'HASH') {
16809: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
16810: }
16811: }
16812: $chgtext .= '</ul>';
16813: my $typename;
16814: if (@types) {
16815: if ($type eq 'default') {
16816: $typename = $othertitle;
16817: } else {
16818: $typename = $usertypes{$type};
16819: }
16820: $chgtext .= &mt('(Affiliation: [_1])',$typename);
16821: }
16822: if (@{$email_rule{$type}} > 0) {
16823: $resulttext .= '<li>'.
16824: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
16825: $usertypes{$type}).
16826: $chgtext.
16827: '</li>';
16828: } else {
16829: $resulttext .= '<li>'.
16830: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
16831: '</li>'.
16832: &mt('(Affiliation: [_1])',$typename);
16833: }
16834: }
16835: }
16836: }
16837: if (ref($changes{'inststatus'}) eq 'ARRAY') {
16838: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
16839: if (@{$save_inststatus{'inststatusguest'}} > 0) {
16840: my $chgtext = '<ul>';
16841: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
16842: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
16843: }
16844: $chgtext .= '</ul>';
16845: $resulttext .= '<li>'.
16846: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
16847: $chgtext.
16848: '</li>';
16849: } else {
16850: $resulttext .= '<li>'.
16851: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
16852: '</li>';
16853: }
16854: }
16855: }
16856: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
16857: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
16858: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16859: foreach my $type (@{$changes{'selfcreate'}}) {
16860: my $typename = $type;
16861: if (keys(%usertypes) > 0) {
16862: if ($usertypes{$type} ne '') {
16863: $typename = $usertypes{$type};
16864: }
16865: }
16866: my @modifiable;
16867: $resulttext .= '<li>'.
16868: &mt('Self-creation of account by users with status: [_1]',
16869: '<span class="LC_cusr_emph">'.$typename.'</span>').
16870: ' - '.&mt('modifiable fields (if institutional data blank): ');
16871: foreach my $field (@fields) {
16872: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
16873: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
16874: }
16875: }
16876: if (@modifiable > 0) {
16877: $resulttext .= join(', ',@modifiable);
16878: } else {
16879: $resulttext .= &mt('none');
16880: }
16881: $resulttext .= '</li>';
16882: }
16883: $resulttext .= '</ul></li>';
16884: }
16885: $resulttext .= '</ul>';
16886: my $cachetime = 24*60*60;
16887: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
16888: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16889: if (ref($lastactref) eq 'HASH') {
16890: $lastactref->{'domdefaults'} = 1;
16891: }
16892: } else {
16893: $resulttext = &mt('No changes made to self-creation settings');
16894: }
16895: } else {
16896: $resulttext = '<span class="LC_error">'.
16897: &mt('An error occurred: [_1]',$putresult).'</span>';
16898: }
16899: if ($warningmsg ne '') {
16900: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16901: }
16902: return $resulttext;
16903: }
16904:
16905: sub process_captcha {
16906: my ($container,$changes,$newsettings,$currsettings) = @_;
16907: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
16908: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
16909: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
16910: $newsettings->{'captcha'} = 'original';
16911: }
16912: my %current;
16913: if (ref($currsettings) eq 'HASH') {
16914: %current = %{$currsettings};
16915: }
16916: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
16917: if ($container eq 'cancreate') {
16918: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16919: push(@{$changes->{'cancreate'}},'captcha');
16920: } elsif (!defined($changes->{'cancreate'})) {
16921: $changes->{'cancreate'} = ['captcha'];
16922: }
16923: } elsif ($container eq 'passwords') {
16924: $changes->{'reset'} = 1;
16925: } else {
16926: $changes->{'captcha'} = 1;
16927: }
16928: }
16929: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
16930: if ($newsettings->{'captcha'} eq 'recaptcha') {
16931: $newpub = $env{'form.'.$container.'_recaptchapub'};
16932: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
16933: $newpub =~ s/[^\w\-]//g;
16934: $newpriv =~ s/[^\w\-]//g;
16935: $newsettings->{'recaptchakeys'} = {
16936: public => $newpub,
16937: private => $newpriv,
16938: };
16939: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16940: $newversion =~ s/\D//g;
16941: if ($newversion ne '2') {
16942: $newversion = 1;
16943: }
16944: $newsettings->{'recaptchaversion'} = $newversion;
16945: }
16946: if (ref($current{'recaptchakeys'}) eq 'HASH') {
16947: $currpub = $current{'recaptchakeys'}{'public'};
16948: $currpriv = $current{'recaptchakeys'}{'private'};
16949: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16950: $newsettings->{'recaptchakeys'} = {
16951: public => '',
16952: private => '',
16953: }
16954: }
16955: }
16956: if ($current{'captcha'} eq 'recaptcha') {
16957: $currversion = $current{'recaptchaversion'};
16958: if ($currversion ne '2') {
16959: $currversion = 1;
16960: }
16961: }
16962: if ($currversion ne $newversion) {
16963: if ($container eq 'cancreate') {
16964: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16965: push(@{$changes->{'cancreate'}},'recaptchaversion');
16966: } elsif (!defined($changes->{'cancreate'})) {
16967: $changes->{'cancreate'} = ['recaptchaversion'];
16968: }
16969: } elsif ($container eq 'passwords') {
16970: $changes->{'reset'} = 1;
16971: } else {
16972: $changes->{'recaptchaversion'} = 1;
16973: }
16974: }
16975: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
16976: if ($container eq 'cancreate') {
16977: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16978: push(@{$changes->{'cancreate'}},'recaptchakeys');
16979: } elsif (!defined($changes->{'cancreate'})) {
16980: $changes->{'cancreate'} = ['recaptchakeys'];
16981: }
16982: } elsif ($container eq 'passwords') {
16983: $changes->{'reset'} = 1;
16984: } else {
16985: $changes->{'recaptchakeys'} = 1;
16986: }
16987: }
16988: return;
16989: }
16990:
16991: sub modify_usermodification {
16992: my ($dom,%domconfig) = @_;
16993: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
16994: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16995: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16996: if ($key eq 'selfcreate') {
16997: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16998: } else {
16999: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17000: }
17001: }
17002: }
17003: my @contexts = ('author','course');
17004: my %context_title = (
17005: author => 'In author context',
17006: course => 'In course context',
17007: );
17008: my @fields = ('lastname','firstname','middlename','generation',
17009: 'permanentemail','id');
17010: my %roles = (
17011: author => ['ca','aa'],
17012: course => ['st','ep','ta','in','cr'],
17013: );
17014: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17015: foreach my $context (@contexts) {
17016: foreach my $role (@{$roles{$context}}) {
17017: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
17018: foreach my $item (@fields) {
17019: if (grep(/^\Q$item\E$/,@modifiable)) {
17020: $modifyhash{$context}{$role}{$item} = 1;
17021: } else {
17022: $modifyhash{$context}{$role}{$item} = 0;
17023: }
17024: }
17025: }
17026: if (ref($curr_usermodification{$context}) eq 'HASH') {
17027: foreach my $role (@{$roles{$context}}) {
17028: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17029: foreach my $field (@fields) {
17030: if ($modifyhash{$context}{$role}{$field} ne
17031: $curr_usermodification{$context}{$role}{$field}) {
17032: push(@{$changes{$context}},$role);
17033: last;
17034: }
17035: }
17036: }
17037: }
17038: } else {
17039: foreach my $context (@contexts) {
17040: foreach my $role (@{$roles{$context}}) {
17041: push(@{$changes{$context}},$role);
17042: }
17043: }
17044: }
17045: }
17046: my %usermodification_hash = (
17047: usermodification => \%modifyhash,
17048: );
17049: my $putresult = &Apache::lonnet::put_dom('configuration',
17050: \%usermodification_hash,$dom);
17051: if ($putresult eq 'ok') {
17052: if (keys(%changes) > 0) {
17053: $resulttext = &mt('Changes made: ').'<ul>';
17054: foreach my $context (@contexts) {
17055: if (ref($changes{$context}) eq 'ARRAY') {
17056: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17057: if (ref($changes{$context}) eq 'ARRAY') {
17058: foreach my $role (@{$changes{$context}}) {
17059: my $rolename;
17060: if ($role eq 'cr') {
17061: $rolename = &mt('Custom');
17062: } else {
17063: $rolename = &Apache::lonnet::plaintext($role);
17064: }
17065: my @modifiable;
17066: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
17067: foreach my $field (@fields) {
17068: if ($modifyhash{$context}{$role}{$field}) {
17069: push(@modifiable,$fieldtitles{$field});
17070: }
17071: }
17072: if (@modifiable > 0) {
17073: $resulttext .= join(', ',@modifiable);
17074: } else {
17075: $resulttext .= &mt('none');
17076: }
17077: $resulttext .= '</li>';
17078: }
17079: $resulttext .= '</ul></li>';
17080: }
17081: }
17082: }
17083: $resulttext .= '</ul>';
17084: } else {
17085: $resulttext = &mt('No changes made to user modification settings');
17086: }
17087: } else {
17088: $resulttext = '<span class="LC_error">'.
17089: &mt('An error occurred: [_1]',$putresult).'</span>';
17090: }
17091: return $resulttext;
17092: }
17093:
17094: sub modify_defaults {
17095: my ($dom,$lastactref,%domconfig) = @_;
17096: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
17097: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17098: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
17099: 'portal_def');
17100: my @authtypes = ('internal','krb4','krb5','localauth','lti');
17101: foreach my $item (@items) {
17102: $newvalues{$item} = $env{'form.'.$item};
17103: if ($item eq 'auth_def') {
17104: if ($newvalues{$item} ne '') {
17105: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17106: push(@errors,$item);
17107: }
17108: }
17109: } elsif ($item eq 'lang_def') {
17110: if ($newvalues{$item} ne '') {
17111: if ($newvalues{$item} =~ /^(\w+)/) {
17112: my $langcode = $1;
17113: if ($langcode ne 'x_chef') {
17114: if (code2language($langcode) eq '') {
17115: push(@errors,$item);
17116: }
17117: }
17118: } else {
17119: push(@errors,$item);
17120: }
17121: }
17122: } elsif ($item eq 'timezone_def') {
17123: if ($newvalues{$item} ne '') {
17124: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
17125: push(@errors,$item);
17126: }
17127: }
17128: } elsif ($item eq 'datelocale_def') {
17129: if ($newvalues{$item} ne '') {
17130: my @datelocale_ids = DateTime::Locale->ids();
17131: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17132: push(@errors,$item);
17133: }
17134: }
17135: } elsif ($item eq 'portal_def') {
17136: if ($newvalues{$item} ne '') {
17137: if ($newvalues{$item} =~ /^https?\:\/\/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/?$/) {
17138: foreach my $field ('email','web') {
17139: if ($env{'form.'.$item.'_'.$field}) {
17140: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
17141: }
17142: }
17143: } else {
17144: push(@errors,$item);
17145: }
17146: }
17147: }
17148: if (grep(/^\Q$item\E$/,@errors)) {
17149: $newvalues{$item} = $domdefaults{$item};
17150: if ($item eq 'portal_def') {
17151: if ($domdefaults{$item}) {
17152: foreach my $field ('email','web') {
17153: if (exists($domdefaults{$item.'_'.$field})) {
17154: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
17155: }
17156: }
17157: }
17158: }
17159: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17160: $changes{$item} = 1;
17161: }
17162: if ($item eq 'portal_def') {
17163: unless (grep(/^\Q$item\E$/,@errors)) {
17164: if ($newvalues{$item} eq '') {
17165: foreach my $field ('email','web') {
17166: if (exists($domdefaults{$item.'_'.$field})) {
17167: delete($domdefaults{$item.'_'.$field});
17168: }
17169: }
17170: } else {
17171: unless ($changes{$item}) {
17172: foreach my $field ('email','web') {
17173: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
17174: $changes{$item} = 1;
17175: last;
17176: }
17177: }
17178: }
17179: foreach my $field ('email','web') {
17180: if ($newvalues{$item.'_'.$field}) {
17181: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
17182: } elsif (exists($domdefaults{$item.'_'.$field})) {
17183: delete($domdefaults{$item.'_'.$field});
17184: }
17185: }
17186: }
17187: }
17188: }
17189: $domdefaults{$item} = $newvalues{$item};
17190: }
17191: my %staticdefaults = (
17192: 'intauth_cost' => 10,
17193: 'intauth_check' => 0,
17194: 'intauth_switch' => 0,
17195: );
17196: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17197: if (exists($domdefaults{$item})) {
17198: $newvalues{$item} = $domdefaults{$item};
17199: } else {
17200: $newvalues{$item} = $staticdefaults{$item};
17201: }
17202: }
17203: my ($unamemaprules,$ruleorder);
17204: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
17205: if (@possunamemaprules) {
17206: ($unamemaprules,$ruleorder) =
17207: &Apache::lonnet::inst_userrules($dom,'unamemap');
17208: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
17209: if (@{$ruleorder} > 0) {
17210: my %possrules;
17211: map { $possrules{$_} = 1; } @possunamemaprules;
17212: foreach my $rule (@{$ruleorder}) {
17213: if ($possrules{$rule}) {
17214: push(@{$newvalues{'unamemap_rule'}},$rule);
17215: }
17216: }
17217: }
17218: }
17219: }
17220: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
17221: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17222: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
17223: $newvalues{'unamemap_rule'});
17224: if (@rulediffs) {
17225: $changes{'unamemap_rule'} = 1;
17226: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17227: }
17228: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
17229: $changes{'unamemap_rule'} = 1;
17230: delete($domdefaults{'unamemap_rule'});
17231: }
17232: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17233: if (@{$newvalues{'unamemap_rule'}} > 0) {
17234: $changes{'unamemap_rule'} = 1;
17235: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17236: }
17237: }
17238: my %defaults_hash = (
17239: defaults => \%newvalues,
17240: );
17241: my $title = &defaults_titles();
17242:
17243: my $currinststatus;
17244: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17245: $currinststatus = $domconfig{'inststatus'};
17246: } else {
17247: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17248: $currinststatus = {
17249: inststatustypes => $usertypes,
17250: inststatusorder => $types,
17251: inststatusguest => [],
17252: };
17253: }
17254: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17255: my @allpos;
17256: my %alltypes;
17257: my @inststatusguest;
17258: if (ref($currinststatus) eq 'HASH') {
17259: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17260: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17261: unless (grep(/^\Q$type\E$/,@todelete)) {
17262: push(@inststatusguest,$type);
17263: }
17264: }
17265: }
17266: }
17267: my ($currtitles,$currorder);
17268: if (ref($currinststatus) eq 'HASH') {
17269: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17270: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17271: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17272: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17273: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17274: }
17275: }
17276: unless (grep(/^\Q$type\E$/,@todelete)) {
17277: my $position = $env{'form.inststatus_pos_'.$type};
17278: $position =~ s/\D+//g;
17279: $allpos[$position] = $type;
17280: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
17281: $alltypes{$type} =~ s/`//g;
17282: }
17283: }
17284: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
17285: $currtitles =~ s/,$//;
17286: }
17287: }
17288: if ($env{'form.addinststatus'}) {
17289: my $newtype = $env{'form.addinststatus'};
17290: $newtype =~ s/\W//g;
17291: unless (exists($alltypes{$newtype})) {
17292: $alltypes{$newtype} = $env{'form.addinststatus_title'};
17293: $alltypes{$newtype} =~ s/`//g;
17294: my $position = $env{'form.addinststatus_pos'};
17295: $position =~ s/\D+//g;
17296: if ($position ne '') {
17297: $allpos[$position] = $newtype;
17298: }
17299: }
17300: }
17301: my @orderedstatus;
17302: foreach my $type (@allpos) {
17303: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
17304: push(@orderedstatus,$type);
17305: }
17306: }
17307: foreach my $type (keys(%alltypes)) {
17308: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
17309: delete($alltypes{$type});
17310: }
17311: }
17312: $defaults_hash{'inststatus'} = {
17313: inststatustypes => \%alltypes,
17314: inststatusorder => \@orderedstatus,
17315: inststatusguest => \@inststatusguest,
17316: };
17317: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
17318: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
17319: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
17320: }
17321: }
17322: if ($currorder ne join(',',@orderedstatus)) {
17323: $changes{'inststatus'}{'inststatusorder'} = 1;
17324: }
17325: my $newtitles;
17326: foreach my $item (@orderedstatus) {
17327: $newtitles .= $alltypes{$item}.',';
17328: }
17329: $newtitles =~ s/,$//;
17330: if ($currtitles ne $newtitles) {
17331: $changes{'inststatus'}{'inststatustypes'} = 1;
17332: }
17333: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
17334: $dom);
17335: if ($putresult eq 'ok') {
17336: if (keys(%changes) > 0) {
17337: $resulttext = &mt('Changes made:').'<ul>';
17338: my $version = &Apache::lonnet::get_server_loncaparev($dom);
17339: my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
17340: foreach my $item (sort(keys(%changes))) {
17341: if ($item eq 'inststatus') {
17342: if (ref($changes{'inststatus'}) eq 'HASH') {
17343: if (@orderedstatus) {
17344: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
17345: foreach my $type (@orderedstatus) {
17346: $resulttext .= $alltypes{$type}.', ';
17347: }
17348: $resulttext =~ s/, $//;
17349: $resulttext .= '</li>';
17350: } else {
17351: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
17352: }
17353: }
17354: } elsif ($item eq 'unamemap_rule') {
17355: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17356: my @rulenames;
17357: if (ref($unamemaprules) eq 'HASH') {
17358: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
17359: if (ref($unamemaprules->{$rule}) eq 'HASH') {
17360: push(@rulenames,$unamemaprules->{$rule}->{'name'});
17361: }
17362: }
17363: }
17364: if (@rulenames) {
17365: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
17366: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
17367: '</li>';
17368: } else {
17369: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
17370: }
17371: } else {
17372: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
17373: }
17374: } else {
17375: my $value = $env{'form.'.$item};
17376: if ($value eq '') {
17377: $value = &mt('none');
17378: } elsif ($item eq 'auth_def') {
17379: my %authnames = &authtype_names();
17380: my %shortauth = (
17381: internal => 'int',
17382: krb4 => 'krb4',
17383: krb5 => 'krb5',
17384: localauth => 'loc',
17385: lti => 'lti',
17386: );
17387: $value = $authnames{$shortauth{$value}};
17388: }
17389: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
17390: $mailmsgtext .= "$title->{$item} set to $value\n";
17391: if ($item eq 'portal_def') {
17392: if ($env{'form.'.$item} ne '') {
17393: foreach my $field ('email','web') {
17394: $value = $env{'form.'.$item.'_'.$field};
17395: if ($value) {
17396: $value = &mt('Yes');
17397: } else {
17398: $value = &mt('No');
17399: }
17400: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
17401: }
17402: }
17403: }
17404: }
17405: }
17406: $resulttext .= '</ul>';
17407: $mailmsgtext .= "\n";
17408: my $cachetime = 24*60*60;
17409: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17410: if (ref($lastactref) eq 'HASH') {
17411: $lastactref->{'domdefaults'} = 1;
17412: }
17413: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
17414: my $notify = 1;
17415: if (ref($domconfig{'contacts'}) eq 'HASH') {
17416: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
17417: $notify = 0;
17418: }
17419: }
17420: if ($notify) {
17421: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
17422: "LON-CAPA Domain Settings Change - $dom",
17423: $mailmsgtext);
17424: }
17425: }
17426: } else {
17427: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
17428: }
17429: } else {
17430: $resulttext = '<span class="LC_error">'.
17431: &mt('An error occurred: [_1]',$putresult).'</span>';
17432: }
17433: if (@errors > 0) {
17434: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
17435: foreach my $item (@errors) {
17436: $resulttext .= ' "'.$title->{$item}.'",';
17437: }
17438: $resulttext =~ s/,$//;
17439: }
17440: return $resulttext;
17441: }
17442:
17443: sub modify_scantron {
17444: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
17445: my ($resulttext,%confhash,%changes,$errors);
17446: my $custom = 'custom.tab';
17447: my $default = 'default.tab';
17448: my $servadm = $r->dir_config('lonAdmEMail');
17449: my ($configuserok,$author_ok,$switchserver) =
17450: &config_check($dom,$confname,$servadm);
17451: if ($env{'form.scantronformat.filename'} ne '') {
17452: my $error;
17453: if ($configuserok eq 'ok') {
17454: if ($switchserver) {
17455: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
17456: } else {
17457: if ($author_ok eq 'ok') {
17458: my $modified = [];
17459: my ($result,$scantronurl) =
17460: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
17461: $confname,'scantron','','',$custom,
17462: $modified);
17463: if ($result eq 'ok') {
17464: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
17465: $changes{'scantronformat'} = 1;
17466: &update_modify_urls($r,$modified);
17467: } else {
17468: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
17469: }
17470: } else {
17471: $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$author_ok);
17472: }
17473: }
17474: } else {
17475: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$configuserok);
17476: }
17477: if ($error) {
17478: &Apache::lonnet::logthis($error);
17479: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
17480: }
17481: }
17482: if (ref($domconfig{'scantron'}) eq 'HASH') {
17483: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
17484: if ($env{'form.scantronformat_del'}) {
17485: $confhash{'scantron'}{'scantronformat'} = '';
17486: $changes{'scantronformat'} = 1;
17487: } else {
17488: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
17489: }
17490: }
17491: }
17492: my @options = ('hdr','pad','rem');
17493: my @fields = &scantroncsv_fields();
17494: my %titles = &scantronconfig_titles();
17495: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
17496: my ($newdat,$currdat,%newcol,%currcol);
17497: if (grep(/^dat$/,@formats)) {
17498: $confhash{'scantron'}{config}{dat} = 1;
17499: $newdat = 1;
17500: } else {
17501: $newdat = 0;
17502: }
17503: if (grep(/^csv$/,@formats)) {
17504: my %bynum;
17505: foreach my $field (@fields) {
17506: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
17507: my $posscol = $1;
17508: if (($posscol < 20) && (!$bynum{$posscol})) {
17509: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
17510: $bynum{$posscol} = $field;
17511: $newcol{$field} = $posscol;
17512: }
17513: }
17514: }
17515: if (keys(%newcol)) {
17516: foreach my $option (@options) {
17517: if ($env{'form.scantroncsv_'.$option}) {
17518: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
17519: }
17520: }
17521: }
17522: }
17523: $currdat = 1;
17524: if (ref($domconfig{'scantron'}) eq 'HASH') {
17525: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
17526: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
17527: $currdat = 0;
17528: }
17529: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
17530: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
17531: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
17532: }
17533: }
17534: }
17535: }
17536: if ($currdat != $newdat) {
17537: $changes{'config'} = 1;
17538: } else {
17539: foreach my $field (@fields) {
17540: if ($currcol{$field} ne '') {
17541: if ($currcol{$field} ne $newcol{$field}) {
17542: $changes{'config'} = 1;
17543: last;
17544: }
17545: } elsif ($newcol{$field} ne '') {
17546: $changes{'config'} = 1;
17547: last;
17548: }
17549: }
17550: }
17551: if (keys(%confhash) > 0) {
17552: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
17553: $dom);
17554: if ($putresult eq 'ok') {
17555: if (keys(%changes) > 0) {
17556: if (ref($confhash{'scantron'}) eq 'HASH') {
17557: $resulttext = &mt('Changes made:').'<ul>';
17558: if ($changes{'scantronformat'}) {
17559: if ($confhash{'scantron'}{'scantronformat'} eq '') {
17560: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
17561: } else {
17562: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
17563: }
17564: }
17565: if ($changes{'config'}) {
17566: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
17567: if ($confhash{'scantron'}{'config'}{'dat'}) {
17568: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
17569: }
17570: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
17571: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
17572: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
17573: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
17574: foreach my $field (@fields) {
17575: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
17576: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
17577: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
17578: }
17579: }
17580: $resulttext .= '</ul></li>';
17581: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
17582: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
17583: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
17584: foreach my $option (@options) {
17585: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
17586: $resulttext .= '<li>'.$titles{$option}.'</li>';
17587: }
17588: }
17589: $resulttext .= '</ul></li>';
17590: }
17591: }
17592: }
17593: }
17594: }
17595: } else {
17596: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
17597: }
17598: }
17599: $resulttext .= '</ul>';
17600: } else {
17601: $resulttext = &mt('Changes made to bubblesheet format file.');
17602: }
17603: &Apache::loncommon::devalidate_domconfig_cache($dom);
17604: if (ref($lastactref) eq 'HASH') {
17605: $lastactref->{'domainconfig'} = 1;
17606: }
17607: } else {
17608: $resulttext = &mt('No changes made to bubblesheet format settings');
17609: }
17610: } else {
17611: $resulttext = '<span class="LC_error">'.
17612: &mt('An error occurred: [_1]',$putresult).'</span>';
17613: }
17614: } else {
17615: $resulttext = &mt('No changes made to bubblesheet format settings');
17616: }
17617: if ($errors) {
17618: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17619: $errors.'</ul></p>';
17620: }
17621: return $resulttext;
17622: }
17623:
17624: sub modify_coursecategories {
17625: my ($dom,$lastactref,%domconfig) = @_;
17626: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
17627: $cathash);
17628: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
17629: my @catitems = ('unauth','auth');
17630: my @cattypes = ('std','domonly','codesrch','none');
17631: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
17632: $cathash = $domconfig{'coursecategories'}{'cats'};
17633: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
17634: $changes{'togglecats'} = 1;
17635: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
17636: }
17637: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
17638: $changes{'categorize'} = 1;
17639: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
17640: }
17641: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
17642: $changes{'togglecatscomm'} = 1;
17643: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
17644: }
17645: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
17646: $changes{'categorizecomm'} = 1;
17647: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
17648: }
17649: foreach my $item (@catitems) {
17650: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
17651: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
17652: $changes{$item} = 1;
17653: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
17654: }
17655: }
17656: }
17657: } else {
17658: $changes{'togglecats'} = 1;
17659: $changes{'categorize'} = 1;
17660: $changes{'togglecatscomm'} = 1;
17661: $changes{'categorizecomm'} = 1;
17662: $domconfig{'coursecategories'} = {
17663: togglecats => $env{'form.togglecats'},
17664: categorize => $env{'form.categorize'},
17665: togglecatscomm => $env{'form.togglecatscomm'},
17666: categorizecomm => $env{'form.categorizecomm'},
17667: };
17668: foreach my $item (@catitems) {
17669: if ($env{'form.coursecat_'.$item} ne 'std') {
17670: $changes{$item} = 1;
17671: }
17672: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
17673: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
17674: }
17675: }
17676: }
17677: if (ref($cathash) eq 'HASH') {
17678: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
17679: push (@deletecategory,'instcode::0');
17680: }
17681: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
17682: push(@deletecategory,'communities::0');
17683: }
17684: }
17685: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
17686: if (ref($cathash) eq 'HASH') {
17687: if (@deletecategory > 0) {
17688: #FIXME Need to remove category from all courses using a deleted category
17689: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
17690: foreach my $item (@deletecategory) {
17691: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
17692: delete($domconfig{'coursecategories'}{'cats'}{$item});
17693: $deletions{$item} = 1;
17694: &recurse_cat_deletes($item,$cathash,\%deletions);
17695: }
17696: }
17697: }
17698: foreach my $item (keys(%{$cathash})) {
17699: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17700: if ($cathash->{$item} ne $env{'form.'.$item}) {
17701: $reorderings{$item} = 1;
17702: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
17703: }
17704: if ($env{'form.addcategory_name_'.$item} ne '') {
17705: my $newcat = $env{'form.addcategory_name_'.$item};
17706: my $newdepth = $depth+1;
17707: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
17708: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
17709: $adds{$newitem} = 1;
17710: }
17711: if ($env{'form.subcat_'.$item} ne '') {
17712: my $newcat = $env{'form.subcat_'.$item};
17713: my $newdepth = $depth+1;
17714: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
17715: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
17716: $adds{$newitem} = 1;
17717: }
17718: }
17719: }
17720: if ($env{'form.instcode'} eq '1') {
17721: if (ref($cathash) eq 'HASH') {
17722: my $newitem = 'instcode::0';
17723: if ($cathash->{$newitem} eq '') {
17724: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
17725: $adds{$newitem} = 1;
17726: }
17727: } else {
17728: my $newitem = 'instcode::0';
17729: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
17730: $adds{$newitem} = 1;
17731: }
17732: }
17733: if ($env{'form.communities'} eq '1') {
17734: if (ref($cathash) eq 'HASH') {
17735: my $newitem = 'communities::0';
17736: if ($cathash->{$newitem} eq '') {
17737: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
17738: $adds{$newitem} = 1;
17739: }
17740: } else {
17741: my $newitem = 'communities::0';
17742: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
17743: $adds{$newitem} = 1;
17744: }
17745: }
17746: if ($env{'form.addcategory_name'} ne '') {
17747: if (($env{'form.addcategory_name'} ne 'instcode') &&
17748: ($env{'form.addcategory_name'} ne 'communities')) {
17749: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
17750: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
17751: $adds{$newitem} = 1;
17752: }
17753: }
17754: my $putresult;
17755: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17756: if (keys(%deletions) > 0) {
17757: foreach my $key (keys(%deletions)) {
17758: if ($predelallitems{$key} ne '') {
17759: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
17760: }
17761: }
17762: }
17763: my (@chkcats,@chktrails,%chkallitems);
17764: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
17765: if (ref($chkcats[0]) eq 'ARRAY') {
17766: my $depth = 0;
17767: my $chg = 0;
17768: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
17769: my $name = $chkcats[0][$i];
17770: my $item;
17771: if ($name eq '') {
17772: $chg ++;
17773: } else {
17774: $item = &escape($name).'::0';
17775: if ($chg) {
17776: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
17777: }
17778: $depth ++;
17779: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
17780: $depth --;
17781: }
17782: }
17783: }
17784: }
17785: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17786: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
17787: if ($putresult eq 'ok') {
17788: my %title = (
17789: togglecats => 'Show/Hide a course in catalog',
17790: categorize => 'Assign a category to a course',
17791: togglecatscomm => 'Show/Hide a community in catalog',
17792: categorizecomm => 'Assign a category to a community',
17793: );
17794: my %level = (
17795: dom => 'set in Domain ("Modify Course/Community")',
17796: crs => 'set in Course ("Course Configuration")',
17797: comm => 'set in Community ("Community Configuration")',
17798: none => 'No catalog',
17799: std => 'Standard catalog',
17800: domonly => 'Domain-only catalog',
17801: codesrch => 'Code search form',
17802: );
17803: $resulttext = &mt('Changes made:').'<ul>';
17804: if ($changes{'togglecats'}) {
17805: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
17806: }
17807: if ($changes{'categorize'}) {
17808: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
17809: }
17810: if ($changes{'togglecatscomm'}) {
17811: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
17812: }
17813: if ($changes{'categorizecomm'}) {
17814: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
17815: }
17816: if ($changes{'unauth'}) {
17817: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
17818: }
17819: if ($changes{'auth'}) {
17820: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
17821: }
17822: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17823: my $cathash;
17824: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
17825: $cathash = $domconfig{'coursecategories'}{'cats'};
17826: } else {
17827: $cathash = {};
17828: }
17829: my (@cats,@trails,%allitems);
17830: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
17831: if (keys(%deletions) > 0) {
17832: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
17833: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
17834: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
17835: }
17836: $resulttext .= '</ul></li>';
17837: }
17838: if (keys(%reorderings) > 0) {
17839: my %sort_by_trail;
17840: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
17841: foreach my $key (keys(%reorderings)) {
17842: if ($allitems{$key} ne '') {
17843: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17844: }
17845: }
17846: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17847: $resulttext .= '<li>'.$trails[$trail].'</li>';
17848: }
17849: $resulttext .= '</ul></li>';
17850: }
17851: if (keys(%adds) > 0) {
17852: my %sort_by_trail;
17853: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
17854: foreach my $key (keys(%adds)) {
17855: if ($allitems{$key} ne '') {
17856: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17857: }
17858: }
17859: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17860: $resulttext .= '<li>'.$trails[$trail].'</li>';
17861: }
17862: $resulttext .= '</ul></li>';
17863: }
17864: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
17865: if (ref($lastactref) eq 'HASH') {
17866: $lastactref->{'cats'} = 1;
17867: }
17868: }
17869: $resulttext .= '</ul>';
17870: if ($changes{'unauth'} || $changes{'auth'}) {
17871: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17872: if ($changes{'auth'}) {
17873: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
17874: }
17875: if ($changes{'unauth'}) {
17876: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
17877: }
17878: my $cachetime = 24*60*60;
17879: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17880: if (ref($lastactref) eq 'HASH') {
17881: $lastactref->{'domdefaults'} = 1;
17882: }
17883: }
17884: } else {
17885: $resulttext = '<span class="LC_error">'.
17886: &mt('An error occurred: [_1]',$putresult).'</span>';
17887: }
17888: } else {
17889: $resulttext = &mt('No changes made to course and community categories');
17890: }
17891: return $resulttext;
17892: }
17893:
17894: sub modify_serverstatuses {
17895: my ($dom,%domconfig) = @_;
17896: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
17897: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
17898: %currserverstatus = %{$domconfig{'serverstatuses'}};
17899: }
17900: my @pages = &serverstatus_pages();
17901: foreach my $type (@pages) {
17902: $newserverstatus{$type}{'namedusers'} = '';
17903: $newserverstatus{$type}{'machines'} = '';
17904: if (defined($env{'form.'.$type.'_namedusers'})) {
17905: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
17906: my @okusers;
17907: foreach my $user (@users) {
17908: my ($uname,$udom) = split(/:/,$user);
17909: if (($udom =~ /^$match_domain$/) &&
17910: (&Apache::lonnet::domain($udom)) &&
17911: ($uname =~ /^$match_username$/)) {
17912: if (!grep(/^\Q$user\E/,@okusers)) {
17913: push(@okusers,$user);
17914: }
17915: }
17916: }
17917: if (@okusers > 0) {
17918: @okusers = sort(@okusers);
17919: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
17920: }
17921: }
17922: if (defined($env{'form.'.$type.'_machines'})) {
17923: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
17924: my @okmachines;
17925: foreach my $ip (@machines) {
17926: my @parts = split(/\./,$ip);
17927: next if (@parts < 4);
17928: my $badip = 0;
17929: for (my $i=0; $i<4; $i++) {
17930: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
17931: $badip = 1;
17932: last;
17933: }
17934: }
17935: if (!$badip) {
17936: push(@okmachines,$ip);
17937: }
17938: }
17939: @okmachines = sort(@okmachines);
17940: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
17941: }
17942: }
17943: my %serverstatushash = (
17944: serverstatuses => \%newserverstatus,
17945: );
17946: foreach my $type (@pages) {
17947: foreach my $setting ('namedusers','machines') {
17948: my (@current,@new);
17949: if (ref($currserverstatus{$type}) eq 'HASH') {
17950: if ($currserverstatus{$type}{$setting} ne '') {
17951: @current = split(/,/,$currserverstatus{$type}{$setting});
17952: }
17953: }
17954: if ($newserverstatus{$type}{$setting} ne '') {
17955: @new = split(/,/,$newserverstatus{$type}{$setting});
17956: }
17957: if (@current > 0) {
17958: if (@new > 0) {
17959: foreach my $item (@current) {
17960: if (!grep(/^\Q$item\E$/,@new)) {
17961: $changes{$type}{$setting} = 1;
17962: last;
17963: }
17964: }
17965: foreach my $item (@new) {
17966: if (!grep(/^\Q$item\E$/,@current)) {
17967: $changes{$type}{$setting} = 1;
17968: last;
17969: }
17970: }
17971: } else {
17972: $changes{$type}{$setting} = 1;
17973: }
17974: } elsif (@new > 0) {
17975: $changes{$type}{$setting} = 1;
17976: }
17977: }
17978: }
17979: if (keys(%changes) > 0) {
17980: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
17981: my $putresult = &Apache::lonnet::put_dom('configuration',
17982: \%serverstatushash,$dom);
17983: if ($putresult eq 'ok') {
17984: $resulttext .= &mt('Changes made:').'<ul>';
17985: foreach my $type (@pages) {
17986: if (ref($changes{$type}) eq 'HASH') {
17987: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
17988: if ($changes{$type}{'namedusers'}) {
17989: if ($newserverstatus{$type}{'namedusers'} eq '') {
17990: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
17991: } else {
17992: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
17993: }
17994: }
17995: if ($changes{$type}{'machines'}) {
17996: if ($newserverstatus{$type}{'machines'} eq '') {
17997: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
17998: } else {
17999: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18000: }
18001:
18002: }
18003: $resulttext .= '</ul></li>';
18004: }
18005: }
18006: $resulttext .= '</ul>';
18007: } else {
18008: $resulttext = '<span class="LC_error">'.
18009: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18010:
18011: }
18012: } else {
18013: $resulttext = &mt('No changes made to access to server status pages');
18014: }
18015: return $resulttext;
18016: }
18017:
18018: sub modify_helpsettings {
18019: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
18020: my ($resulttext,$errors,%changes,%helphash);
18021: my %defaultchecked = ('submitbugs' => 'on');
18022: my @offon = ('off','on');
18023: my @toggles = ('submitbugs');
18024: my %current = ('submitbugs' => '',
18025: 'adhoc' => {},
18026: );
18027: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
18028: %current = %{$domconfig{'helpsettings'}};
18029: }
18030: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18031: foreach my $item (@toggles) {
18032: if ($defaultchecked{$item} eq 'on') {
18033: if ($current{$item} eq '') {
18034: if ($env{'form.'.$item} eq '0') {
18035: $changes{$item} = 1;
18036: }
18037: } elsif ($current{$item} ne $env{'form.'.$item}) {
18038: $changes{$item} = 1;
18039: }
18040: } elsif ($defaultchecked{$item} eq 'off') {
18041: if ($current{$item} eq '') {
18042: if ($env{'form.'.$item} eq '1') {
18043: $changes{$item} = 1;
18044: }
18045: } elsif ($current{$item} ne $env{'form.'.$item}) {
18046: $changes{$item} = 1;
18047: }
18048: }
18049: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18050: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18051: }
18052: }
18053: my $maxnum = $env{'form.helproles_maxnum'};
18054: my $confname = $dom.'-domainconfig';
18055: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
18056: my (@allpos,%newsettings,%changedprivs,$newrole);
18057: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18058: my @accesstypes = ('all','dh','da','none','status','inc','exc');
18059: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
18060: my %lt = &Apache::lonlocal::texthash(
18061: s => 'system',
18062: d => 'domain',
18063: order => 'Display order',
18064: access => 'Role usage',
18065: all => 'All with domain helpdesk or helpdesk assistant role',
18066: dh => 'All with domain helpdesk role',
18067: da => 'All with domain helpdesk assistant role',
18068: none => 'None',
18069: status => 'Determined based on institutional status',
18070: inc => 'Include all, but exclude specific personnel',
18071: exc => 'Exclude all, but include specific personnel',
18072: );
18073: for (my $num=0; $num<=$maxnum; $num++) {
18074: my ($prefix,$identifier,$rolename,%curr);
18075: if ($num == $maxnum) {
18076: next unless ($env{'form.newcusthelp'} == $maxnum);
18077: $identifier = 'custhelp'.$num;
18078: $prefix = 'helproles_'.$num;
18079: $rolename = $env{'form.custhelpname'.$num};
18080: $rolename=~s/[^A-Za-z0-9]//gs;
18081: next if ($rolename eq '');
18082: next if (exists($existing{'rolesdef_'.$rolename}));
18083: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18084: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18085: $newprivs{'c'},$confname,$dom);
18086: if ($result ne 'ok') {
18087: $errors .= '<li><span class="LC_error">'.
18088: &mt('An error occurred storing the new custom role: [_1]',
18089: $result).'</span></li>';
18090: next;
18091: } else {
18092: $changedprivs{$rolename} = \%newprivs;
18093: $newrole = $rolename;
18094: }
18095: } else {
18096: $prefix = 'helproles_'.$num;
18097: $rolename = $env{'form.'.$prefix};
18098: next if ($rolename eq '');
18099: next unless (exists($existing{'rolesdef_'.$rolename}));
18100: $identifier = 'custhelp'.$num;
18101: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18102: my %currprivs;
18103: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
18104: split(/\_/,$existing{'rolesdef_'.$rolename});
18105: foreach my $level ('c','d','s') {
18106: if ($newprivs{$level} ne $currprivs{$level}) {
18107: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18108: $newprivs{'c'},$confname,$dom);
18109: if ($result ne 'ok') {
18110: $errors .= '<li><span class="LC_error">'.
18111: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18112: $rolename,$result).'</span></li>';
18113: } else {
18114: $changedprivs{$rolename} = \%newprivs;
18115: }
18116: last;
18117: }
18118: }
18119: if (ref($current{'adhoc'}) eq 'HASH') {
18120: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18121: %curr = %{$current{'adhoc'}{$rolename}};
18122: }
18123: }
18124: }
18125: my $newpos = $env{'form.'.$prefix.'_pos'};
18126: $newpos =~ s/\D+//g;
18127: $allpos[$newpos] = $rolename;
18128: my $newdesc = $env{'form.'.$prefix.'_desc'};
18129: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18130: if ($curr{'desc'}) {
18131: if ($curr{'desc'} ne $newdesc) {
18132: $changes{'customrole'}{$rolename}{'desc'} = 1;
18133: $newsettings{$rolename}{'desc'} = $newdesc;
18134: }
18135: } elsif ($newdesc ne '') {
18136: $changes{'customrole'}{$rolename}{'desc'} = 1;
18137: $newsettings{$rolename}{'desc'} = $newdesc;
18138: }
18139: my $access = $env{'form.'.$prefix.'_access'};
18140: if (grep(/^\Q$access\E$/,@accesstypes)) {
18141: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18142: if ($access eq 'status') {
18143: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18144: if (scalar(@statuses) == 0) {
18145: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
18146: } else {
18147: my (@shownstatus,$numtypes);
18148: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18149: if (ref($types) eq 'ARRAY') {
18150: $numtypes = scalar(@{$types});
18151: foreach my $type (sort(@statuses)) {
18152: if ($type eq 'default') {
18153: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18154: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18155: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18156: push(@shownstatus,$usertypes->{$type});
18157: }
18158: }
18159: }
18160: if (grep(/^default$/,@statuses)) {
18161: push(@shownstatus,$othertitle);
18162: }
18163: if (scalar(@shownstatus) == 1+$numtypes) {
18164: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18165: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18166: } else {
18167: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18168: if (ref($curr{'status'}) eq 'ARRAY') {
18169: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18170: if (@diffs) {
18171: $changes{'customrole'}{$rolename}{$access} = 1;
18172: }
18173: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18174: $changes{'customrole'}{$rolename}{$access} = 1;
18175: }
18176: }
18177: }
18178: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18179: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18180: my @newspecstaff;
18181: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18182: foreach my $person (sort(@personnel)) {
18183: if ($domhelpdesk{$person}) {
18184: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18185: }
18186: }
18187: if (ref($curr{$access}) eq 'ARRAY') {
18188: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18189: if (@diffs) {
18190: $changes{'customrole'}{$rolename}{$access} = 1;
18191: }
18192: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18193: $changes{'customrole'}{$rolename}{$access} = 1;
18194: }
18195: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18196: my ($uname,$udom) = split(/:/,$person);
18197: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18198: }
18199: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
18200: }
18201: } else {
18202: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18203: }
18204: unless ($curr{'access'} eq $access) {
18205: $changes{'customrole'}{$rolename}{'access'} = 1;
18206: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
18207: }
18208: }
18209: if (@allpos > 0) {
18210: my $idx = 0;
18211: foreach my $rolename (@allpos) {
18212: if ($rolename ne '') {
18213: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18214: if (ref($current{'adhoc'}) eq 'HASH') {
18215: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18216: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18217: $changes{'customrole'}{$rolename}{'order'} = 1;
18218: $newsettings{$rolename}{'order'} = $idx+1;
18219: }
18220: }
18221: }
18222: $idx ++;
18223: }
18224: }
18225: }
18226: my $putresult;
18227: if (keys(%changes) > 0) {
18228: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
18229: if ($putresult eq 'ok') {
18230: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18231: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18232: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18233: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18234: }
18235: }
18236: my $cachetime = 24*60*60;
18237: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18238: if (ref($lastactref) eq 'HASH') {
18239: $lastactref->{'domdefaults'} = 1;
18240: }
18241: } else {
18242: $errors .= '<li><span class="LC_error">'.
18243: &mt('An error occurred storing the settings: [_1]',
18244: $putresult).'</span></li>';
18245: }
18246: }
18247: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18248: $resulttext = &mt('Changes made:').'<ul>';
18249: my (%shownprivs,@levelorder);
18250: @levelorder = ('c','d','s');
18251: if ((keys(%changes)) && ($putresult eq 'ok')) {
18252: foreach my $item (sort(keys(%changes))) {
18253: if ($item eq 'submitbugs') {
18254: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18255: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18256: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
18257: } elsif ($item eq 'customrole') {
18258: if (ref($changes{'customrole'}) eq 'HASH') {
18259: my @keyorder = ('order','desc','access','status','exc','inc');
18260: my %keytext = &Apache::lonlocal::texthash(
18261: order => 'Order',
18262: desc => 'Role description',
18263: access => 'Role usage',
18264: status => 'Allowed institutional types',
18265: exc => 'Allowed personnel',
18266: inc => 'Disallowed personnel',
18267: );
18268: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
18269: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18270: if ($role eq $newrole) {
18271: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18272: $role).'<ul>';
18273: } else {
18274: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18275: $role).'<ul>';
18276: }
18277: foreach my $key (@keyorder) {
18278: if ($changes{'customrole'}{$role}{$key}) {
18279: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
18280: $keytext{$key},$newsettings{$role}{$key}).
18281: '</li>';
18282: }
18283: }
18284: if (ref($changedprivs{$role}) eq 'HASH') {
18285: $shownprivs{$role} = 1;
18286: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
18287: foreach my $level (@levelorder) {
18288: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18289: next if ($item eq '');
18290: my ($priv) = split(/\&/,$item,2);
18291: if (&Apache::lonnet::plaintext($priv)) {
18292: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18293: unless ($level eq 'c') {
18294: $resulttext .= ' ('.$lt{$level}.')';
18295: }
18296: $resulttext .= '</li>';
18297: }
18298: }
18299: }
18300: $resulttext .= '</ul>';
18301: }
18302: $resulttext .= '</ul></li>';
18303: }
18304: }
18305: }
18306: }
18307: }
18308: }
18309: if (keys(%changedprivs)) {
18310: foreach my $role (sort(keys(%changedprivs))) {
18311: unless ($shownprivs{$role}) {
18312: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18313: $role).'<ul>'.
18314: '<li>'.&mt('Privileges set to :').'<ul>';
18315: foreach my $level (@levelorder) {
18316: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18317: next if ($item eq '');
18318: my ($priv) = split(/\&/,$item,2);
18319: if (&Apache::lonnet::plaintext($priv)) {
18320: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18321: unless ($level eq 'c') {
18322: $resulttext .= ' ('.$lt{$level}.')';
18323: }
18324: $resulttext .= '</li>';
18325: }
18326: }
18327: }
18328: $resulttext .= '</ul></li></ul></li>';
18329: }
18330: }
18331: }
18332: $resulttext .= '</ul>';
18333: } else {
18334: $resulttext = &mt('No changes made to help settings');
18335: }
18336: if ($errors) {
18337: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
18338: $errors.'</ul>';
18339: }
18340: return $resulttext;
18341: }
18342:
18343: sub modify_coursedefaults {
18344: my ($dom,$lastactref,%domconfig) = @_;
18345: my ($resulttext,$errors,%changes,%defaultshash);
18346: my %defaultchecked = (
18347: 'uselcmath' => 'on',
18348: 'usejsme' => 'on',
18349: 'inline_chem' => 'on',
18350: 'ltiauth' => 'off',
18351: );
18352: my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
18353: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
18354: 'uploadquota_community','uploadquota_textbook','coursequota_official',
18355: 'coursequota_unofficial','coursequota_community','coursequota_textbook',
18356: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
18357: 'mysqltables_textbook');
18358: my @types = ('official','unofficial','community','textbook');
18359: my %staticdefaults = (
18360: anonsurvey_threshold => 10,
18361: uploadquota => 500,
18362: coursequota => 20,
18363: postsubmit => 60,
18364: mysqltables => 172800,
18365: domexttool => 1,
18366: );
18367: my %texoptions = (
18368: MathJax => 'MathJax',
18369: mimetex => &mt('Convert to Images'),
18370: tth => &mt('TeX to HTML'),
18371: );
18372: $defaultshash{'coursedefaults'} = {};
18373:
18374: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
18375: if ($domconfig{'coursedefaults'} eq '') {
18376: $domconfig{'coursedefaults'} = {};
18377: }
18378: }
18379:
18380: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
18381: foreach my $item (@toggles) {
18382: if ($defaultchecked{$item} eq 'on') {
18383: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18384: ($env{'form.'.$item} eq '0')) {
18385: $changes{$item} = 1;
18386: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
18387: $changes{$item} = 1;
18388: }
18389: } elsif ($defaultchecked{$item} eq 'off') {
18390: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18391: ($env{'form.'.$item} eq '1')) {
18392: $changes{$item} = 1;
18393: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
18394: $changes{$item} = 1;
18395: }
18396: }
18397: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
18398: }
18399: foreach my $item (@numbers) {
18400: my ($currdef,$newdef);
18401: $newdef = $env{'form.'.$item};
18402: if ($item eq 'anonsurvey_threshold') {
18403: $currdef = $domconfig{'coursedefaults'}{$item};
18404: $newdef =~ s/\D//g;
18405: if ($newdef eq '' || $newdef < 1) {
18406: $newdef = 1;
18407: }
18408: $defaultshash{'coursedefaults'}{$item} = $newdef;
18409: } else {
18410: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
18411: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
18412: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
18413: }
18414: $newdef =~ s/[^\w.\-]//g;
18415: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
18416: }
18417: if ($currdef ne $newdef) {
18418: if ($item eq 'anonsurvey_threshold') {
18419: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
18420: $changes{$item} = 1;
18421: }
18422: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
18423: my $setting = $1;
18424: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
18425: $changes{$setting} = 1;
18426: }
18427: }
18428: }
18429: }
18430: my $texengine;
18431: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
18432: $texengine = $env{'form.texengine'};
18433: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
18434: if ($currdef eq '') {
18435: unless ($texengine eq $Apache::lonnet::deftex) {
18436: $changes{'texengine'} = 1;
18437: }
18438: } elsif ($currdef ne $texengine) {
18439: $changes{'texengine'} = 1;
18440: }
18441: }
18442: if ($texengine ne '') {
18443: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
18444: }
18445: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
18446: my @currclonecode;
18447: if (ref($currclone) eq 'HASH') {
18448: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
18449: @currclonecode = @{$currclone->{'instcode'}};
18450: }
18451: }
18452: my $newclone;
18453: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
18454: $newclone = $env{'form.canclone'};
18455: }
18456: if ($newclone eq 'instcode') {
18457: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
18458: my (%codedefaults,@code_order,@clonecode);
18459: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
18460: \@code_order);
18461: foreach my $item (@code_order) {
18462: if (grep(/^\Q$item\E$/,@newcodes)) {
18463: push(@clonecode,$item);
18464: }
18465: }
18466: if (@clonecode) {
18467: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
18468: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
18469: if (@diffs) {
18470: $changes{'canclone'} = 1;
18471: }
18472: } else {
18473: $newclone eq '';
18474: }
18475: } elsif ($newclone ne '') {
18476: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
18477: }
18478: if ($newclone ne $currclone) {
18479: $changes{'canclone'} = 1;
18480: }
18481: my %credits;
18482: foreach my $type (@types) {
18483: unless ($type eq 'community') {
18484: $credits{$type} = $env{'form.'.$type.'_credits'};
18485: $credits{$type} =~ s/[^\d.]+//g;
18486: }
18487: }
18488: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
18489: ($env{'form.coursecredits'} eq '1')) {
18490: $changes{'coursecredits'} = 1;
18491: foreach my $type (keys(%credits)) {
18492: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
18493: }
18494: } else {
18495: if ($env{'form.coursecredits'} eq '1') {
18496: foreach my $type (@types) {
18497: unless ($type eq 'community') {
18498: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
18499: $changes{'coursecredits'} = 1;
18500: }
18501: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
18502: }
18503: }
18504: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
18505: foreach my $type (@types) {
18506: unless ($type eq 'community') {
18507: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
18508: $changes{'coursecredits'} = 1;
18509: last;
18510: }
18511: }
18512: }
18513: }
18514: }
18515: if ($env{'form.postsubmit'} eq '1') {
18516: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
18517: my %currtimeout;
18518: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18519: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
18520: $changes{'postsubmit'} = 1;
18521: }
18522: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18523: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
18524: }
18525: } else {
18526: $changes{'postsubmit'} = 1;
18527: }
18528: foreach my $type (@types) {
18529: my $timeout = $env{'form.'.$type.'_timeout'};
18530: $timeout =~ s/\D//g;
18531: if ($timeout == $staticdefaults{'postsubmit'}) {
18532: $timeout = '';
18533: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
18534: $timeout = '0';
18535: }
18536: unless ($timeout eq '') {
18537: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
18538: }
18539: if (exists($currtimeout{$type})) {
18540: if ($timeout ne $currtimeout{$type}) {
18541: $changes{'postsubmit'} = 1;
18542: }
18543: } elsif ($timeout ne '') {
18544: $changes{'postsubmit'} = 1;
18545: }
18546: }
18547: } else {
18548: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
18549: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18550: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
18551: $changes{'postsubmit'} = 1;
18552: }
18553: } else {
18554: $changes{'postsubmit'} = 1;
18555: }
18556: }
18557: my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool);
18558: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
18559: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
18560: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18561: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
18562: } else {
18563: foreach my $type (@types) {
18564: if ($staticdefaults{'domexttool'}) {
18565: $olddomexttool{$type} = 1;
18566: } else {
18567: $olddomexttool{$type} = 0;
18568: }
18569: }
18570: }
18571: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
18572: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
18573: } else {
18574: foreach my $type (@types) {
18575: if ($staticdefaults{'exttool'}) {
18576: $oldexttool{$type} = 1;
18577: } else {
18578: $oldexttool{$type} = 0;
18579: }
18580: }
18581: }
18582: foreach my $type (@types) {
18583: unless ($newdomexttool{$type}) {
18584: $newdomexttool{$type} = 0;
18585: }
18586: unless ($newexttool{$type}) {
18587: $newexttool{$type} = 0;
18588: }
18589: if ($newdomexttool{$type} != $olddomexttool{$type}) {
18590: $changes{'domexttool'} = 1;
18591: }
18592: if ($newexttool{$type} != $oldexttool{$type}) {
18593: $changes{'exttool'} = 1;
18594: }
18595: }
18596: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
18597: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
18598: }
18599: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18600: $dom);
18601: if ($putresult eq 'ok') {
18602: if (keys(%changes) > 0) {
18603: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18604: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
18605: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
18606: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
18607: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
18608: ($changes{'exttool'}) || ($changes{'coursequota'})) {
18609: foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
18610: if ($changes{$item}) {
18611: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
18612: }
18613: }
18614: if ($changes{'coursecredits'}) {
18615: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
18616: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
18617: $domdefaults{$type.'credits'} =
18618: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
18619: }
18620: }
18621: }
18622: if ($changes{'postsubmit'}) {
18623: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18624: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
18625: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18626: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
18627: $domdefaults{$type.'postsubtimeout'} =
18628: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
18629: }
18630: }
18631: }
18632: }
18633: if ($changes{'uploadquota'}) {
18634: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
18635: foreach my $type (@types) {
18636: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
18637: }
18638: }
18639: }
18640: if ($changes{'coursequota'}) {
18641: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
18642: foreach my $type (@types) {
18643: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
18644: }
18645: }
18646: }
18647: if ($changes{'canclone'}) {
18648: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
18649: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
18650: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
18651: if (@clonecodes) {
18652: $domdefaults{'canclone'} = join('+',@clonecodes);
18653: }
18654: }
18655: } else {
18656: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
18657: }
18658: }
18659: if ($changes{'domexttool'}) {
18660: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18661: foreach my $type (@types) {
18662: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
18663: }
18664: }
18665: }
18666: if ($changes{'exttool'}) {
18667: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
18668: foreach my $type (@types) {
18669: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
18670: }
18671: }
18672: }
18673: my $cachetime = 24*60*60;
18674: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18675: if (ref($lastactref) eq 'HASH') {
18676: $lastactref->{'domdefaults'} = 1;
18677: }
18678: }
18679: $resulttext = &mt('Changes made:').'<ul>';
18680: foreach my $item (sort(keys(%changes))) {
18681: if ($item eq 'uselcmath') {
18682: if ($env{'form.'.$item} eq '1') {
18683: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
18684: } else {
18685: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
18686: }
18687: } elsif ($item eq 'usejsme') {
18688: if ($env{'form.'.$item} eq '1') {
18689: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
18690: } else {
18691: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
18692: }
18693: } elsif ($item eq 'inline_chem') {
18694: if ($env{'form.'.$item} eq '1') {
18695: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
18696: } else {
18697: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
18698: }
18699: } elsif ($item eq 'texengine') {
18700: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
18701: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
18702: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
18703: }
18704: } elsif ($item eq 'anonsurvey_threshold') {
18705: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
18706: } elsif ($item eq 'uploadquota') {
18707: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
18708: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
18709: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
18710: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
18711: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
18712: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
18713: '</ul>'.
18714: '</li>';
18715: } else {
18716: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
18717: }
18718: } elsif ($item eq 'coursequota') {
18719: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
18720: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
18721: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
18722: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
18723: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
18724: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
18725: '</ul>'.
18726: '</li>';
18727: } else {
18728: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
18729: }
18730: } elsif ($item eq 'mysqltables') {
18731: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
18732: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
18733: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
18734: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
18735: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
18736: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
18737: '</ul>'.
18738: '</li>';
18739: } else {
18740: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
18741: }
18742: } elsif ($item eq 'postsubmit') {
18743: if ($domdefaults{'postsubmit'} eq 'off') {
18744: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
18745: } else {
18746: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
18747: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18748: $resulttext .= &mt('durations:').'<ul>';
18749: foreach my $type (@types) {
18750: $resulttext .= '<li>';
18751: my $timeout;
18752: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18753: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
18754: }
18755: my $display;
18756: if ($timeout eq '0') {
18757: $display = &mt('unlimited');
18758: } elsif ($timeout eq '') {
18759: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
18760: } else {
18761: $display = &mt('[quant,_1,second]',$timeout);
18762: }
18763: if ($type eq 'community') {
18764: $resulttext .= &mt('Communities');
18765: } elsif ($type eq 'official') {
18766: $resulttext .= &mt('Official courses');
18767: } elsif ($type eq 'unofficial') {
18768: $resulttext .= &mt('Unofficial courses');
18769: } elsif ($type eq 'textbook') {
18770: $resulttext .= &mt('Textbook courses');
18771: }
18772: $resulttext .= ' -- '.$display.'</li>';
18773: }
18774: $resulttext .= '</ul>';
18775: }
18776: $resulttext .= '</li>';
18777: }
18778: } elsif ($item eq 'coursecredits') {
18779: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
18780: if (($domdefaults{'officialcredits'} eq '') &&
18781: ($domdefaults{'unofficialcredits'} eq '') &&
18782: ($domdefaults{'textbookcredits'} eq '')) {
18783: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
18784: } else {
18785: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
18786: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
18787: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
18788: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
18789: '</ul>'.
18790: '</li>';
18791: }
18792: } else {
18793: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
18794: }
18795: } elsif ($item eq 'canclone') {
18796: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
18797: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
18798: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
18799: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
18800: }
18801: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
18802: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
18803: } else {
18804: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
18805: }
18806: } elsif ($item eq 'ltiauth') {
18807: if ($env{'form.'.$item} eq '1') {
18808: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
18809: } else {
18810: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
18811: }
18812: } elsif ($item eq 'domexttool') {
18813: my @noyes = (&mt('no'),&mt('yes'));
18814: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18815: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
18816: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
18817: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
18818: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
18819: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
18820: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
18821: '</ul>'.
18822: '</li>';
18823: } else {
18824: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
18825: }
18826: } elsif ($item eq 'exttool') {
18827: my @noyes = (&mt('no'),&mt('yes'));
18828: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
18829: $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
18830: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
18831: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
18832: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
18833: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
18834: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
18835: '</ul>'.
18836: '</li>';
18837: } else {
18838: $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
18839: }
18840: }
18841: }
18842: $resulttext .= '</ul>';
18843: } else {
18844: $resulttext = &mt('No changes made to course defaults');
18845: }
18846: } else {
18847: $resulttext = '<span class="LC_error">'.
18848: &mt('An error occurred: [_1]',$putresult).'</span>';
18849: }
18850: return $resulttext;
18851: }
18852:
18853: sub modify_selfenrollment {
18854: my ($dom,$lastactref,%domconfig) = @_;
18855: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
18856: my @types = ('official','unofficial','community','textbook');
18857: my %titles = &tool_titles();
18858: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
18859: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
18860: $ordered{'default'} = ['types','registered','approval','limit'];
18861:
18862: my (%roles,%shown,%toplevel);
18863: $roles{'0'} = &Apache::lonnet::plaintext('dc');
18864:
18865: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
18866: if ($domconfig{'selfenrollment'} eq '') {
18867: $domconfig{'selfenrollment'} = {};
18868: }
18869: }
18870: %toplevel = (
18871: admin => 'Configuration Rights',
18872: default => 'Default settings',
18873: validation => 'Validation of self-enrollment requests',
18874: );
18875: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
18876:
18877: if (ref($ordered{'admin'}) eq 'ARRAY') {
18878: foreach my $item (@{$ordered{'admin'}}) {
18879: foreach my $type (@types) {
18880: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
18881: $selfenrollhash{'admin'}{$type}{$item} = 1;
18882: } else {
18883: $selfenrollhash{'admin'}{$type}{$item} = 0;
18884: }
18885: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
18886: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
18887: if ($selfenrollhash{'admin'}{$type}{$item} ne
18888: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
18889: push(@{$changes{'admin'}{$type}},$item);
18890: }
18891: } else {
18892: if (!$selfenrollhash{'admin'}{$type}{$item}) {
18893: push(@{$changes{'admin'}{$type}},$item);
18894: }
18895: }
18896: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
18897: push(@{$changes{'admin'}{$type}},$item);
18898: }
18899: }
18900: }
18901: }
18902:
18903: foreach my $item (@{$ordered{'default'}}) {
18904: foreach my $type (@types) {
18905: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
18906: if ($item eq 'types') {
18907: unless (($value eq 'all') || ($value eq 'dom')) {
18908: $value = '';
18909: }
18910: } elsif ($item eq 'registered') {
18911: unless ($value eq '1') {
18912: $value = 0;
18913: }
18914: } elsif ($item eq 'approval') {
18915: unless ($value =~ /^[012]$/) {
18916: $value = 0;
18917: }
18918: } else {
18919: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
18920: $value = 'none';
18921: }
18922: }
18923: $selfenrollhash{'default'}{$type}{$item} = $value;
18924: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
18925: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
18926: if ($selfenrollhash{'default'}{$type}{$item} ne
18927: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
18928: push(@{$changes{'default'}{$type}},$item);
18929: }
18930: } else {
18931: push(@{$changes{'default'}{$type}},$item);
18932: }
18933: } else {
18934: push(@{$changes{'default'}{$type}},$item);
18935: }
18936: if ($item eq 'limit') {
18937: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
18938: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
18939: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
18940: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
18941: }
18942: } else {
18943: $selfenrollhash{'default'}{$type}{'cap'} = '';
18944: }
18945: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
18946: if ($selfenrollhash{'default'}{$type}{'cap'} ne
18947: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
18948: push(@{$changes{'default'}{$type}},'cap');
18949: }
18950: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
18951: push(@{$changes{'default'}{$type}},'cap');
18952: }
18953: }
18954: }
18955: }
18956:
18957: foreach my $item (@{$itemsref}) {
18958: if ($item eq 'fields') {
18959: my @changed;
18960: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
18961: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
18962: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
18963: }
18964: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18965: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
18966: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
18967: $domconfig{'selfenrollment'}{'validation'}{$item});
18968: } else {
18969: @changed = @{$selfenrollhash{'validation'}{$item}};
18970: }
18971: } else {
18972: @changed = @{$selfenrollhash{'validation'}{$item}};
18973: }
18974: if (@changed) {
18975: if ($selfenrollhash{'validation'}{$item}) {
18976: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
18977: } else {
18978: $changes{'validation'}{$item} = &mt('None');
18979: }
18980: }
18981: } else {
18982: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
18983: if ($item eq 'markup') {
18984: if ($env{'form.selfenroll_validation_'.$item}) {
18985: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
18986: }
18987: }
18988: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18989: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
18990: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
18991: }
18992: }
18993: }
18994: }
18995:
18996: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
18997: $dom);
18998: if ($putresult eq 'ok') {
18999: if (keys(%changes) > 0) {
19000: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19001: $resulttext = &mt('Changes made:').'<ul>';
19002: foreach my $key ('admin','default','validation') {
19003: if (ref($changes{$key}) eq 'HASH') {
19004: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19005: if ($key eq 'validation') {
19006: foreach my $item (@{$itemsref}) {
19007: if (exists($changes{$key}{$item})) {
19008: if ($item eq 'markup') {
19009: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19010: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19011: } else {
19012: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19013: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19014: }
19015: }
19016: }
19017: } else {
19018: foreach my $type (@types) {
19019: if ($type eq 'community') {
19020: $roles{'1'} = &mt('Community personnel');
19021: } else {
19022: $roles{'1'} = &mt('Course personnel');
19023: }
19024: if (ref($changes{$key}{$type}) eq 'ARRAY') {
19025: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19026: if ($key eq 'admin') {
19027: my @mgrdc = ();
19028: if (ref($ordered{$key}) eq 'ARRAY') {
19029: foreach my $item (@{$ordered{'admin'}}) {
19030: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19031: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19032: push(@mgrdc,$item);
19033: }
19034: }
19035: }
19036: if (@mgrdc) {
19037: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19038: } else {
19039: delete($domdefaults{$type.'selfenrolladmdc'});
19040: }
19041: }
19042: } else {
19043: if (ref($ordered{$key}) eq 'ARRAY') {
19044: foreach my $item (@{$ordered{$key}}) {
19045: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19046: $domdefaults{$type.'selfenroll'.$item} =
19047: $selfenrollhash{$key}{$type}{$item};
19048: }
19049: }
19050: }
19051: }
19052: }
19053: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19054: foreach my $item (@{$ordered{$key}}) {
19055: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19056: $resulttext .= '<li>';
19057: if ($key eq 'admin') {
19058: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19059: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19060: } else {
19061: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19062: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19063: }
19064: $resulttext .= '</li>';
19065: }
19066: }
19067: $resulttext .= '</ul></li>';
19068: }
19069: }
19070: $resulttext .= '</ul></li>';
19071: }
19072: }
19073: }
19074: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19075: my $cachetime = 24*60*60;
19076: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19077: if (ref($lastactref) eq 'HASH') {
19078: $lastactref->{'domdefaults'} = 1;
19079: }
19080: }
19081: $resulttext .= '</ul>';
19082: } else {
19083: $resulttext = &mt('No changes made to self-enrollment settings');
19084: }
19085: } else {
19086: $resulttext = '<span class="LC_error">'.
19087: &mt('An error occurred: [_1]',$putresult).'</span>';
19088: }
19089: return $resulttext;
19090: }
19091:
19092: sub modify_wafproxy {
19093: my ($dom,$action,$lastactref,%domconfig) = @_;
19094: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19095: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
19096: %wafproxy,%changes,%expirecache,%expiresaml);
19097: foreach my $server (sort(keys(%servers))) {
19098: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19099: if ($serverhome eq $server) {
19100: my $serverdom = &Apache::lonnet::host_domain($server);
19101: if ($serverdom eq $dom) {
19102: $canset{$server} = 1;
19103: }
19104: }
19105: }
19106: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19107: %{$values{$dom}} = ();
19108: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19109: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19110: }
19111: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
19112: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
19113: }
19114: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19115: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19116: }
19117: }
19118: my $output;
19119: if (keys(%canset)) {
19120: %{$wafproxy{'alias'}} = ();
19121: %{$wafproxy{'saml'}} = ();
19122: foreach my $key (sort(keys(%canset))) {
19123: if ($env{'form.wafproxy_'.$dom}) {
19124: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19125: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19126: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19127: $changes{'alias'} = 1;
19128: }
19129: if ($env{'form.wafproxy_alias_saml_'.$key}) {
19130: $wafproxy{'saml'}{$key} = 1;
19131: }
19132: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
19133: $changes{'saml'} = 1;
19134: }
19135: } else {
19136: $wafproxy{'alias'}{$key} = '';
19137: $wafproxy{'saml'}{$key} = '';
19138: if ($curralias{$key}) {
19139: $changes{'alias'} = 1;
19140: }
19141: if ($currsaml{$key}) {
19142: $changes{'saml'} = 1;
19143: }
19144: }
19145: if ($wafproxy{'alias'}{$key} eq '') {
19146: if ($curralias{$key}) {
19147: $expirecache{$key} = 1;
19148: }
19149: delete($wafproxy{'alias'}{$key});
19150: }
19151: if ($wafproxy{'saml'}{$key} eq '') {
19152: if ($currsaml{$key}) {
19153: $expiresaml{$key} = 1;
19154: }
19155: delete($wafproxy{'saml'}{$key});
19156: }
19157: }
19158: unless (keys(%{$wafproxy{'alias'}})) {
19159: delete($wafproxy{'alias'});
19160: }
19161: unless (keys(%{$wafproxy{'saml'}})) {
19162: delete($wafproxy{'saml'});
19163: }
19164: # Localization for values in %warn occurs in &mt() calls separately.
19165: my %warn = (
19166: trusted => 'trusted IP range(s)',
19167: vpnint => 'internal IP range(s) for VPN sessions(s)',
19168: vpnext => 'IP range(s) for backend WAF connections',
19169: );
19170: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19171: my $possible = $env{'form.wafproxy_'.$item};
19172: $possible =~ s/^\s+|\s+$//g;
19173: if ($possible ne '') {
19174: if ($item eq 'remoteip') {
19175: if ($possible =~ /^[mhn]$/) {
19176: $wafproxy{$item} = $possible;
19177: }
19178: } elsif ($item eq 'ipheader') {
19179: if ($wafproxy{'remoteip'} eq 'h') {
19180: $wafproxy{$item} = $possible;
19181: }
19182: } elsif ($item eq 'sslopt') {
19183: if ($possible =~ /^0|1$/) {
19184: $wafproxy{$item} = $possible;
19185: }
19186: } else {
19187: my (@ok,$count);
19188: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
19189: unless ($env{'form.wafproxy_vpnaccess'}) {
19190: $possible = '';
19191: }
19192: } elsif ($item eq 'trusted') {
19193: unless ($wafproxy{'remoteip'} eq 'h') {
19194: $possible = '';
19195: }
19196: }
19197: unless ($possible eq '') {
19198: $possible =~ s/[\r\n]+/\s/g;
19199: $possible =~ s/\s*-\s*/-/g;
19200: $possible =~ s/\s+/,/g;
19201: $possible =~ s/,+/,/g;
19202: }
19203: $count = 0;
19204: if ($possible ne '') {
19205: foreach my $poss (split(/\,/,$possible)) {
19206: $count ++;
19207: $poss = &validate_ip_pattern($poss);
19208: if ($poss ne '') {
19209: push(@ok,$poss);
19210: }
19211: }
19212: my $diff = $count - scalar(@ok);
19213: if ($diff) {
19214: push(@warnings,'<li>'.
19215: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19216: $diff,$warn{$item}).
19217: '</li>');
19218: }
19219: if (@ok) {
19220: my @cidr_list;
19221: foreach my $item (@ok) {
19222: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
19223: }
19224: $wafproxy{$item} = join(',',@cidr_list);
19225: }
19226: }
19227: }
19228: if ($wafproxy{$item} ne $currvalue{$item}) {
19229: $changes{$item} = 1;
19230: }
19231: } elsif ($currvalue{$item}) {
19232: $changes{$item} = 1;
19233: }
19234: }
19235: } else {
19236: if (keys(%curralias)) {
19237: $changes{'alias'} = 1;
19238: }
19239: if (keys(%currsaml)) {
19240: $changes{'saml'} = 1;
19241: }
19242: if (keys(%currvalue)) {
19243: foreach my $key (keys(%currvalue)) {
19244: $changes{$key} = 1;
19245: }
19246: }
19247: }
19248: if (keys(%changes)) {
19249: my %defaultshash = (
19250: wafproxy => \%wafproxy,
19251: );
19252: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19253: $dom);
19254: if ($putresult eq 'ok') {
19255: my $cachetime = 24*60*60;
19256: my (%domdefaults,$updatedomdefs);
19257: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
19258: if ($changes{$item}) {
19259: unless ($updatedomdefs) {
19260: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19261: $updatedomdefs = 1;
19262: }
19263: if ($wafproxy{$item}) {
19264: $domdefaults{'waf_'.$item} = $wafproxy{$item};
19265: } elsif (exists($domdefaults{'waf_'.$item})) {
19266: delete($domdefaults{'waf_'.$item});
19267: }
19268: }
19269: }
19270: if ($updatedomdefs) {
19271: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19272: if (ref($lastactref) eq 'HASH') {
19273: $lastactref->{'domdefaults'} = 1;
19274: }
19275: }
19276: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
19277: my %updates = %expirecache;
19278: foreach my $key (keys(%expirecache)) {
19279: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
19280: }
19281: if (ref($wafproxy{'alias'}) eq 'HASH') {
19282: my $cachetime = 24*60*60;
19283: foreach my $key (keys(%{$wafproxy{'alias'}})) {
19284: $updates{$key} = 1;
19285: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
19286: $cachetime);
19287: }
19288: }
19289: if (ref($lastactref) eq 'HASH') {
19290: $lastactref->{'proxyalias'} = \%updates;
19291: }
19292: }
19293: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
19294: my %samlupdates = %expiresaml;
19295: foreach my $key (keys(%expiresaml)) {
19296: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
19297: }
19298: if (ref($wafproxy{'saml'}) eq 'HASH') {
19299: my $cachetime = 24*60*60;
19300: foreach my $key (keys(%{$wafproxy{'saml'}})) {
19301: $samlupdates{$key} = 1;
19302: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
19303: $cachetime);
19304: }
19305: }
19306: if (ref($lastactref) eq 'HASH') {
19307: $lastactref->{'proxysaml'} = \%samlupdates;
19308: }
19309: }
19310: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
19311: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19312: if ($changes{$item}) {
19313: if ($item eq 'alias') {
19314: my $numaliased = 0;
19315: if (ref($wafproxy{'alias'}) eq 'HASH') {
19316: my $shown;
19317: if (keys(%{$wafproxy{'alias'}})) {
19318: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
19319: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
19320: &Apache::lonnet::hostname($server),
19321: $wafproxy{'alias'}{$server}).'</li>';
19322: $numaliased ++;
19323: }
19324: if ($numaliased) {
19325: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
19326: '<ul>'.$shown.'</ul>').'</li>';
19327: }
19328: }
19329: }
19330: unless ($numaliased) {
19331: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
19332: }
19333: } elsif ($item eq 'saml') {
19334: my $shown;
19335: if (ref($wafproxy{'saml'}) eq 'HASH') {
19336: if (keys(%{$wafproxy{'saml'}})) {
19337: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
19338: }
19339: }
19340: if ($shown) {
19341: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
19342: $shown).'</li>';
19343: } else {
19344: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
19345: }
19346: } else {
19347: if ($item eq 'remoteip') {
19348: my %ip_methods = &remoteip_methods();
19349: if ($wafproxy{$item} =~ /^[mh]$/) {
19350: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
19351: $ip_methods{$wafproxy{$item}}).'</li>';
19352: } else {
19353: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
19354: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
19355: '</li>';
19356: } else {
19357: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
19358: }
19359: }
19360: } elsif ($item eq 'ipheader') {
19361: if ($wafproxy{$item}) {
19362: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
19363: $wafproxy{$item}).'</li>';
19364: } else {
19365: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
19366: }
19367: } elsif ($item eq 'trusted') {
19368: if ($wafproxy{$item}) {
19369: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
19370: $wafproxy{$item}).'</li>';
19371: } else {
19372: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
19373: }
19374: } elsif ($item eq 'vpnint') {
19375: if ($wafproxy{$item}) {
19376: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
19377: $wafproxy{$item}).'</li>';
19378: } else {
19379: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
19380: }
19381: } elsif ($item eq 'vpnext') {
19382: if ($wafproxy{$item}) {
19383: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
19384: $wafproxy{$item}).'</li>';
19385: } else {
19386: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
19387: }
19388: } elsif ($item eq 'sslopt') {
19389: if ($wafproxy{$item}) {
19390: $output .= '<li>'.&mt('WAF/Reverse Proxy expected to forward requests to https on LON-CAPA node, regardless of original protocol in web browser (http or https).').'</li>';
19391: } else {
19392: $output .= '<li>'.&mt('WAF/Reverse Proxy expected to preserve original protocol in web browser (either http or https) when forwarding to LON-CAPA node.').'</li>';
19393: }
19394: }
19395: }
19396: }
19397: }
19398: $output .= '</ul>';
19399: } else {
19400: $output = '<span class="LC_error">'.
19401: &mt('An error occurred: [_1]',$putresult).'</span>';
19402: }
19403: } elsif (keys(%canset)) {
19404: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
19405: }
19406: if (@warnings) {
19407: $output .= '<br />'.&mt('Warnings:').'<ul>'.
19408: join("\n",@warnings).'</ul>';
19409: }
19410: return $output;
19411: }
19412:
19413: sub validate_ip_pattern {
19414: my ($pattern) = @_;
19415: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
19416: my ($start,$end) = ($1,$2);
19417: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
19418: if (($start !~ m{/}) && ($end !~ m{/})) {
19419: return $start.'-'.$end;
19420: }
19421: }
19422: } elsif ($pattern ne '') {
19423: $pattern = &Net::CIDR::cidrvalidate($pattern);
19424: if ($pattern ne '') {
19425: return $pattern;
19426: }
19427: }
19428: return;
19429: }
19430:
19431: sub modify_usersessions {
19432: my ($dom,$lastactref,%domconfig) = @_;
19433: my @hostingtypes = ('version','excludedomain','includedomain');
19434: my @offloadtypes = ('primary','default');
19435: my %types = (
19436: remote => \@hostingtypes,
19437: hosted => \@hostingtypes,
19438: spares => \@offloadtypes,
19439: );
19440: my @prefixes = ('remote','hosted','spares');
19441: my @lcversions = &Apache::lonnet::all_loncaparevs();
19442: my (%by_ip,%by_location,@intdoms);
19443: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
19444: my @locations = sort(keys(%by_location));
19445: my (%defaultshash,%changes);
19446: foreach my $prefix (@prefixes) {
19447: $defaultshash{'usersessions'}{$prefix} = {};
19448: }
19449: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19450: my $resulttext;
19451: my %iphost = &Apache::lonnet::get_iphost();
19452: foreach my $prefix (@prefixes) {
19453: next if ($prefix eq 'spares');
19454: foreach my $type (@{$types{$prefix}}) {
19455: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
19456: if ($type eq 'version') {
19457: my $value = $env{'form.'.$prefix.'_'.$type};
19458: my $okvalue;
19459: if ($value ne '') {
19460: if (grep(/^\Q$value\E$/,@lcversions)) {
19461: $okvalue = $value;
19462: }
19463: }
19464: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19465: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19466: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
19467: if ($inuse == 0) {
19468: $changes{$prefix}{$type} = 1;
19469: } else {
19470: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
19471: $changes{$prefix}{$type} = 1;
19472: }
19473: if ($okvalue ne '') {
19474: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19475: }
19476: }
19477: } else {
19478: if (($inuse == 1) && ($okvalue ne '')) {
19479: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19480: $changes{$prefix}{$type} = 1;
19481: }
19482: }
19483: } else {
19484: if (($inuse == 1) && ($okvalue ne '')) {
19485: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19486: $changes{$prefix}{$type} = 1;
19487: }
19488: }
19489: } else {
19490: if (($inuse == 1) && ($okvalue ne '')) {
19491: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19492: $changes{$prefix}{$type} = 1;
19493: }
19494: }
19495: } else {
19496: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
19497: my @okvals;
19498: foreach my $val (@vals) {
19499: if ($val =~ /:/) {
19500: my @items = split(/:/,$val);
19501: foreach my $item (@items) {
19502: if (ref($by_location{$item}) eq 'ARRAY') {
19503: push(@okvals,$item);
19504: }
19505: }
19506: } else {
19507: if (ref($by_location{$val}) eq 'ARRAY') {
19508: push(@okvals,$val);
19509: }
19510: }
19511: }
19512: @okvals = sort(@okvals);
19513: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19514: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19515: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19516: if ($inuse == 0) {
19517: $changes{$prefix}{$type} = 1;
19518: } else {
19519: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19520: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
19521: if (@changed > 0) {
19522: $changes{$prefix}{$type} = 1;
19523: }
19524: }
19525: } else {
19526: if ($inuse == 1) {
19527: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19528: $changes{$prefix}{$type} = 1;
19529: }
19530: }
19531: } else {
19532: if ($inuse == 1) {
19533: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19534: $changes{$prefix}{$type} = 1;
19535: }
19536: }
19537: } else {
19538: if ($inuse == 1) {
19539: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19540: $changes{$prefix}{$type} = 1;
19541: }
19542: }
19543: }
19544: }
19545: }
19546:
19547: my @alldoms = &Apache::lonnet::all_domains();
19548: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19549: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
19550: my $savespares;
19551:
19552: foreach my $lonhost (sort(keys(%servers))) {
19553: my $serverhomeID =
19554: &Apache::lonnet::get_server_homeID($servers{$lonhost});
19555: my $serverhostname = &Apache::lonnet::hostname($lonhost);
19556: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
19557: my %spareschg;
19558: foreach my $type (@{$types{'spares'}}) {
19559: my @okspares;
19560: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
19561: foreach my $server (@checked) {
19562: if (&Apache::lonnet::hostname($server) ne '') {
19563: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
19564: unless (grep(/^\Q$server\E$/,@okspares)) {
19565: push(@okspares,$server);
19566: }
19567: }
19568: }
19569: }
19570: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
19571: my $newspare;
19572: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
19573: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
19574: $newspare = $new;
19575: }
19576: }
19577: my @spares;
19578: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
19579: @spares = sort(@okspares,$newspare);
19580: } else {
19581: @spares = sort(@okspares);
19582: }
19583: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
19584: if (ref($spareid{$lonhost}) eq 'HASH') {
19585: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
19586: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
19587: if (@diffs > 0) {
19588: $spareschg{$type} = 1;
19589: }
19590: }
19591: }
19592: }
19593: if (keys(%spareschg) > 0) {
19594: $changes{'spares'}{$lonhost} = \%spareschg;
19595: }
19596: }
19597: $defaultshash{'usersessions'}{'offloadnow'} = {};
19598: $defaultshash{'usersessions'}{'offloadoth'} = {};
19599: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
19600: my @okoffload;
19601: if (@offloadnow) {
19602: foreach my $server (@offloadnow) {
19603: if (&Apache::lonnet::hostname($server) ne '') {
19604: unless (grep(/^\Q$server\E$/,@okoffload)) {
19605: push(@okoffload,$server);
19606: }
19607: }
19608: }
19609: if (@okoffload) {
19610: foreach my $lonhost (@okoffload) {
19611: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
19612: }
19613: }
19614: }
19615: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
19616: my @okoffloadoth;
19617: if (@offloadoth) {
19618: foreach my $server (@offloadoth) {
19619: if (&Apache::lonnet::hostname($server) ne '') {
19620: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
19621: push(@okoffloadoth,$server);
19622: }
19623: }
19624: }
19625: if (@okoffloadoth) {
19626: foreach my $lonhost (@okoffloadoth) {
19627: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
19628: }
19629: }
19630: }
19631: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19632: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
19633: if (ref($changes{'spares'}) eq 'HASH') {
19634: if (keys(%{$changes{'spares'}}) > 0) {
19635: $savespares = 1;
19636: }
19637: }
19638: } else {
19639: $savespares = 1;
19640: }
19641: foreach my $offload ('offloadnow','offloadoth') {
19642: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
19643: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
19644: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
19645: $changes{$offload} = 1;
19646: last;
19647: }
19648: }
19649: unless ($changes{$offload}) {
19650: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
19651: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
19652: $changes{$offload} = 1;
19653: last;
19654: }
19655: }
19656: }
19657: } else {
19658: if (($offload eq 'offloadnow') && (@okoffload)) {
19659: $changes{'offloadnow'} = 1;
19660: }
19661: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
19662: $changes{'offloadoth'} = 1;
19663: }
19664: }
19665: }
19666: } else {
19667: if (@okoffload) {
19668: $changes{'offloadnow'} = 1;
19669: }
19670: if (@okoffloadoth) {
19671: $changes{'offloadoth'} = 1;
19672: }
19673: }
19674: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
19675: if ((keys(%changes) > 0) || ($savespares)) {
19676: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19677: $dom);
19678: if ($putresult eq 'ok') {
19679: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
19680: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
19681: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
19682: }
19683: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
19684: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
19685: }
19686: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
19687: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
19688: }
19689: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
19690: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
19691: }
19692: }
19693: my $cachetime = 24*60*60;
19694: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19695: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
19696: if (ref($lastactref) eq 'HASH') {
19697: $lastactref->{'domdefaults'} = 1;
19698: $lastactref->{'usersessions'} = 1;
19699: }
19700: if (keys(%changes) > 0) {
19701: my %lt = &usersession_titles();
19702: $resulttext = &mt('Changes made:').'<ul>';
19703: foreach my $prefix (@prefixes) {
19704: if (ref($changes{$prefix}) eq 'HASH') {
19705: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
19706: if ($prefix eq 'spares') {
19707: if (ref($changes{$prefix}) eq 'HASH') {
19708: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
19709: $resulttext .= '<li><b>'.$lonhost.'</b> ';
19710: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
19711: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
19712: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
19713: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
19714: foreach my $type (@{$types{$prefix}}) {
19715: if ($changes{$prefix}{$lonhost}{$type}) {
19716: my $offloadto = &mt('None');
19717: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
19718: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
19719: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
19720: }
19721: }
19722: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
19723: }
19724: }
19725: }
19726: $resulttext .= '</li>';
19727: }
19728: }
19729: } else {
19730: foreach my $type (@{$types{$prefix}}) {
19731: if (defined($changes{$prefix}{$type})) {
19732: my $newvalue;
19733: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
19734: if (ref($defaultshash{'usersessions'}{$prefix})) {
19735: if ($type eq 'version') {
19736: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
19737: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19738: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
19739: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
19740: }
19741: }
19742: }
19743: }
19744: if ($newvalue eq '') {
19745: if ($type eq 'version') {
19746: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
19747: } else {
19748: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
19749: }
19750: } else {
19751: if ($type eq 'version') {
19752: $newvalue .= ' '.&mt('(or later)');
19753: }
19754: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
19755: }
19756: }
19757: }
19758: }
19759: $resulttext .= '</ul>';
19760: }
19761: }
19762: if ($changes{'offloadnow'}) {
19763: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
19764: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
19765: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
19766: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
19767: $resulttext .= '<li>'.$lonhost.'</li>';
19768: }
19769: $resulttext .= '</ul>';
19770: } else {
19771: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
19772: }
19773: } else {
19774: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
19775: }
19776: }
19777: if ($changes{'offloadoth'}) {
19778: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
19779: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
19780: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
19781: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
19782: $resulttext .= '<li>'.$lonhost.'</li>';
19783: }
19784: $resulttext .= '</ul>';
19785: } else {
19786: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
19787: }
19788: } else {
19789: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
19790: }
19791: }
19792: $resulttext .= '</ul>';
19793: } else {
19794: $resulttext = $nochgmsg;
19795: }
19796: } else {
19797: $resulttext = '<span class="LC_error">'.
19798: &mt('An error occurred: [_1]',$putresult).'</span>';
19799: }
19800: } else {
19801: $resulttext = $nochgmsg;
19802: }
19803: return $resulttext;
19804: }
19805:
19806: sub modify_loadbalancing {
19807: my ($dom,%domconfig) = @_;
19808: my $primary_id = &Apache::lonnet::domain($dom,'primary');
19809: my $intdom = &Apache::lonnet::internet_dom($primary_id);
19810: my ($othertitle,$usertypes,$types) =
19811: &Apache::loncommon::sorted_inst_types($dom);
19812: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19813: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
19814: my @sparestypes = ('primary','default');
19815: my %typetitles = &sparestype_titles();
19816: my $resulttext;
19817: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
19818: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
19819: %existing = %{$domconfig{'loadbalancing'}};
19820: }
19821: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
19822: \%currtargets,\%currrules,\%currcookies);
19823: my ($saveloadbalancing,%defaultshash,%changes);
19824: my ($alltypes,$othertypes,$titles) =
19825: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
19826: my %ruletitles = &offloadtype_text();
19827: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
19828: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
19829: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
19830: if ($balancer eq '') {
19831: next;
19832: }
19833: if (!exists($servers{$balancer})) {
19834: if (exists($currbalancer{$balancer})) {
19835: push(@{$changes{'delete'}},$balancer);
19836: }
19837: next;
19838: }
19839: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
19840: push(@{$changes{'delete'}},$balancer);
19841: next;
19842: }
19843: if (!exists($currbalancer{$balancer})) {
19844: push(@{$changes{'add'}},$balancer);
19845: }
19846: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
19847: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
19848: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
19849: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
19850: $saveloadbalancing = 1;
19851: }
19852: foreach my $sparetype (@sparestypes) {
19853: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
19854: my @offloadto;
19855: foreach my $target (@targets) {
19856: if (($servers{$target}) && ($target ne $balancer)) {
19857: if ($sparetype eq 'default') {
19858: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
19859: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
19860: }
19861: }
19862: unless(grep(/^\Q$target\E$/,@offloadto)) {
19863: push(@offloadto,$target);
19864: }
19865: }
19866: }
19867: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
19868: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
19869: push(@offloadto,$balancer);
19870: }
19871: }
19872: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
19873: }
19874: if ($env{'form.loadbalancing_cookie_'.$i}) {
19875: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
19876: if (exists($currbalancer{$balancer})) {
19877: unless ($currcookies{$balancer}) {
19878: $changes{'curr'}{$balancer}{'cookie'} = 1;
19879: }
19880: }
19881: } elsif (exists($currbalancer{$balancer})) {
19882: if ($currcookies{$balancer}) {
19883: $changes{'curr'}{$balancer}{'cookie'} = 1;
19884: }
19885: }
19886: if (ref($currtargets{$balancer}) eq 'HASH') {
19887: foreach my $sparetype (@sparestypes) {
19888: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
19889: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
19890: if (@targetdiffs > 0) {
19891: $changes{'curr'}{$balancer}{'targets'} = 1;
19892: }
19893: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19894: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19895: $changes{'curr'}{$balancer}{'targets'} = 1;
19896: }
19897: }
19898: }
19899: } else {
19900: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
19901: foreach my $sparetype (@sparestypes) {
19902: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19903: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19904: $changes{'curr'}{$balancer}{'targets'} = 1;
19905: }
19906: }
19907: }
19908: }
19909: }
19910: my $ishomedom;
19911: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
19912: $ishomedom = 1;
19913: }
19914: if (ref($alltypes) eq 'ARRAY') {
19915: foreach my $type (@{$alltypes}) {
19916: my $rule;
19917: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
19918: (!$ishomedom)) {
19919: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
19920: }
19921: if ($rule eq 'specific') {
19922: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
19923: if (exists($servers{$specifiedhost})) {
19924: $rule = $specifiedhost;
19925: }
19926: }
19927: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
19928: if (ref($currrules{$balancer}) eq 'HASH') {
19929: if ($rule ne $currrules{$balancer}{$type}) {
19930: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
19931: }
19932: } elsif ($rule ne '') {
19933: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
19934: }
19935: }
19936: }
19937: }
19938: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
19939: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
19940: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
19941: $defaultshash{'loadbalancing'} = {};
19942: }
19943: my $putresult = &Apache::lonnet::put_dom('configuration',
19944: \%defaultshash,$dom);
19945: if ($putresult eq 'ok') {
19946: if (keys(%changes) > 0) {
19947: my %toupdate;
19948: if (ref($changes{'delete'}) eq 'ARRAY') {
19949: foreach my $balancer (sort(@{$changes{'delete'}})) {
19950: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
19951: $toupdate{$balancer} = 1;
19952: }
19953: }
19954: if (ref($changes{'add'}) eq 'ARRAY') {
19955: foreach my $balancer (sort(@{$changes{'add'}})) {
19956: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
19957: $toupdate{$balancer} = 1;
19958: }
19959: }
19960: if (ref($changes{'curr'}) eq 'HASH') {
19961: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
19962: $toupdate{$balancer} = 1;
19963: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
19964: if ($changes{'curr'}{$balancer}{'targets'}) {
19965: my %offloadstr;
19966: foreach my $sparetype (@sparestypes) {
19967: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19968: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19969: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
19970: }
19971: }
19972: }
19973: if (keys(%offloadstr) == 0) {
19974: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
19975: } else {
19976: my $showoffload;
19977: foreach my $sparetype (@sparestypes) {
19978: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
19979: if (defined($offloadstr{$sparetype})) {
19980: $showoffload .= $offloadstr{$sparetype};
19981: } else {
19982: $showoffload .= &mt('None');
19983: }
19984: $showoffload .= (' 'x3);
19985: }
19986: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
19987: }
19988: }
19989: }
19990: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
19991: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
19992: foreach my $type (@{$alltypes}) {
19993: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
19994: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
19995: my $balancetext;
19996: if ($rule eq '') {
19997: $balancetext = $ruletitles{'default'};
19998: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
19999: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
20000: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
20001: foreach my $sparetype (@sparestypes) {
20002: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20003: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20004: }
20005: }
20006: foreach my $item (@{$alltypes}) {
20007: next if ($item =~ /^_LC_ipchange/);
20008: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20009: if ($hasrule eq 'homeserver') {
20010: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20011: } else {
20012: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20013: if ($servers{$hasrule}) {
20014: $toupdate{$hasrule} = 1;
20015: }
20016: }
20017: }
20018: }
20019: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20020: $balancetext = $ruletitles{$rule};
20021: } else {
20022: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20023: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20024: if ($receiver) {
20025: $toupdate{$receiver};
20026: }
20027: }
20028: } else {
20029: $balancetext = $ruletitles{$rule};
20030: }
20031: } else {
20032: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20033: }
20034: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
20035: }
20036: }
20037: }
20038: }
20039: if ($changes{'curr'}{$balancer}{'cookie'}) {
20040: if ($currcookies{$balancer}) {
20041: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
20042: $balancer).'</li>';
20043: } else {
20044: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20045: $balancer).'</li>';
20046: }
20047: }
20048: }
20049: }
20050: if (keys(%toupdate)) {
20051: my %thismachine;
20052: my $updatedhere;
20053: my $cachetime = 60*60*24;
20054: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20055: foreach my $lonhost (keys(%toupdate)) {
20056: if ($thismachine{$lonhost}) {
20057: unless ($updatedhere) {
20058: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20059: $defaultshash{'loadbalancing'},
20060: $cachetime);
20061: $updatedhere = 1;
20062: }
20063: } else {
20064: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20065: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
20066: }
20067: }
20068: }
20069: if ($resulttext ne '') {
20070: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
20071: } else {
20072: $resulttext = $nochgmsg;
20073: }
20074: } else {
20075: $resulttext = $nochgmsg;
20076: }
20077: } else {
20078: $resulttext = '<span class="LC_error">'.
20079: &mt('An error occurred: [_1]',$putresult).'</span>';
20080: }
20081: } else {
20082: $resulttext = $nochgmsg;
20083: }
20084: return $resulttext;
20085: }
20086:
20087: sub recurse_check {
20088: my ($chkcats,$categories,$depth,$name) = @_;
20089: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20090: my $chg = 0;
20091: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20092: my $category = $chkcats->[$depth]{$name}[$j];
20093: my $item;
20094: if ($category eq '') {
20095: $chg ++;
20096: } else {
20097: my $deeper = $depth + 1;
20098: $item = &escape($category).':'.&escape($name).':'.$depth;
20099: if ($chg) {
20100: $categories->{$item} -= $chg;
20101: }
20102: &recurse_check($chkcats,$categories,$deeper,$category);
20103: $deeper --;
20104: }
20105: }
20106: }
20107: return;
20108: }
20109:
20110: sub recurse_cat_deletes {
20111: my ($item,$coursecategories,$deletions) = @_;
20112: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20113: my $subdepth = $depth + 1;
20114: if (ref($coursecategories) eq 'HASH') {
20115: foreach my $subitem (keys(%{$coursecategories})) {
20116: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20117: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20118: delete($coursecategories->{$subitem});
20119: $deletions->{$subitem} = 1;
20120: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
20121: }
20122: }
20123: }
20124: return;
20125: }
20126:
20127: sub active_dc_picker {
20128: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
20129: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
20130: my @domcoord = keys(%domcoords);
20131: if (keys(%currhash)) {
20132: foreach my $dc (keys(%currhash)) {
20133: unless (exists($domcoords{$dc})) {
20134: push(@domcoord,$dc);
20135: }
20136: }
20137: }
20138: @domcoord = sort(@domcoord);
20139: my $numdcs = scalar(@domcoord);
20140: my $rows = 0;
20141: my $table;
20142: if ($numdcs > 1) {
20143: $table = '<table>';
20144: for (my $i=0; $i<@domcoord; $i++) {
20145: my $rem = $i%($numinrow);
20146: if ($rem == 0) {
20147: if ($i > 0) {
20148: $table .= '</tr>';
20149: }
20150: $table .= '<tr>';
20151: $rows ++;
20152: }
20153: my $check = '';
20154: if ($inputtype eq 'radio') {
20155: if (keys(%currhash) == 0) {
20156: if (!$i) {
20157: $check = ' checked="checked"';
20158: }
20159: } elsif (exists($currhash{$domcoord[$i]})) {
20160: $check = ' checked="checked"';
20161: }
20162: } else {
20163: if (exists($currhash{$domcoord[$i]})) {
20164: $check = ' checked="checked"';
20165: }
20166: }
20167: if ($i == @domcoord - 1) {
20168: my $colsleft = $numinrow - $rem;
20169: if ($colsleft > 1) {
20170: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
20171: } else {
20172: $table .= '<td class="LC_left_item">';
20173: }
20174: } else {
20175: $table .= '<td class="LC_left_item">';
20176: }
20177: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20178: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20179: $table .= '<span class="LC_nobreak"><label>'.
20180: '<input type="'.$inputtype.'" name="'.$name.'"'.
20181: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20182: if ($user ne $dcname.':'.$dcdom) {
20183: $table .= ' ('.$dcname.':'.$dcdom.')';
20184: }
20185: $table .= '</label></span></td>';
20186: }
20187: $table .= '</tr></table>';
20188: } elsif ($numdcs == 1) {
20189: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20190: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20191: if ($inputtype eq 'radio') {
20192: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
20193: if ($user ne $dcname.':'.$dcdom) {
20194: $table .= ' ('.$dcname.':'.$dcdom.')';
20195: }
20196: } else {
20197: my $check;
20198: if (exists($currhash{$domcoord[0]})) {
20199: $check = ' checked="checked"';
20200: }
20201: $table = '<span class="LC_nobreak"><label>'.
20202: '<input type="checkbox" name="'.$name.'" '.
20203: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
20204: if ($user ne $dcname.':'.$dcdom) {
20205: $table .= ' ('.$dcname.':'.$dcdom.')';
20206: }
20207: $table .= '</label></span>';
20208: $rows ++;
20209: }
20210: }
20211: return ($numdcs,$table,$rows);
20212: }
20213:
20214: sub usersession_titles {
20215: return &Apache::lonlocal::texthash(
20216: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20217: remote => 'Hosting of sessions for users in this domain on servers in other domains',
20218: spares => 'Servers offloaded to, when busy',
20219: version => 'LON-CAPA version requirement',
20220: excludedomain => 'Allow all, but exclude specific domains',
20221: includedomain => 'Deny all, but include specific domains',
20222: primary => 'Primary (checked first)',
20223: default => 'Default',
20224: );
20225: }
20226:
20227: sub id_for_thisdom {
20228: my (%servers) = @_;
20229: my %altids;
20230: foreach my $server (keys(%servers)) {
20231: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20232: if ($serverhome ne $server) {
20233: $altids{$serverhome} = $server;
20234: }
20235: }
20236: return %altids;
20237: }
20238:
20239: sub count_servers {
20240: my ($currbalancer,%servers) = @_;
20241: my (@spares,$numspares);
20242: foreach my $lonhost (sort(keys(%servers))) {
20243: next if ($currbalancer eq $lonhost);
20244: push(@spares,$lonhost);
20245: }
20246: if ($currbalancer) {
20247: $numspares = scalar(@spares);
20248: } else {
20249: $numspares = scalar(@spares) - 1;
20250: }
20251: return ($numspares,@spares);
20252: }
20253:
20254: sub lonbalance_targets_js {
20255: my ($dom,$types,$servers,$settings) = @_;
20256: my $select = &mt('Select');
20257: my ($alltargets,$allishome,$allinsttypes,@alltypes);
20258: if (ref($servers) eq 'HASH') {
20259: $alltargets = join("','",sort(keys(%{$servers})));
20260: my @homedoms;
20261: foreach my $server (sort(keys(%{$servers}))) {
20262: if (&Apache::lonnet::host_domain($server) eq $dom) {
20263: push(@homedoms,'1');
20264: } else {
20265: push(@homedoms,'0');
20266: }
20267: }
20268: $allishome = join("','",@homedoms);
20269: }
20270: if (ref($types) eq 'ARRAY') {
20271: if (@{$types} > 0) {
20272: @alltypes = @{$types};
20273: }
20274: }
20275: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
20276: $allinsttypes = join("','",@alltypes);
20277: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
20278: if (ref($settings) eq 'HASH') {
20279: %existing = %{$settings};
20280: }
20281: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
20282: \%currtargets,\%currrules,\%currcookies);
20283: my $balancers = join("','",sort(keys(%currbalancer)));
20284: return <<"END";
20285:
20286: <script type="text/javascript">
20287: // <![CDATA[
20288:
20289: currBalancers = new Array('$balancers');
20290:
20291: function toggleTargets(balnum) {
20292: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20293: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
20294: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
20295: var prevbalancer = prevhostitem.value;
20296: var baltotal = document.getElementById('loadbalancing_total').value;
20297: prevhostitem.value = balancer;
20298: if (prevbalancer != '') {
20299: var prevIdx = currBalancers.indexOf(prevbalancer);
20300: if (prevIdx != -1) {
20301: currBalancers.splice(prevIdx,1);
20302: }
20303: }
20304: if (balancer == '') {
20305: hideSpares(balnum);
20306: } else {
20307: var currIdx = currBalancers.indexOf(balancer);
20308: if (currIdx == -1) {
20309: currBalancers.push(balancer);
20310: }
20311: var homedoms = new Array('$allishome');
20312: var ishomedom = homedoms[lonhostitem.selectedIndex];
20313: showSpares(balancer,ishomedom,balnum);
20314: }
20315: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
20316: return;
20317: }
20318:
20319: function showSpares(balancer,ishomedom,balnum) {
20320: var alltargets = new Array('$alltargets');
20321: var insttypes = new Array('$allinsttypes');
20322: var offloadtypes = new Array('primary','default');
20323:
20324: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
20325: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
20326:
20327: for (var i=0; i<offloadtypes.length; i++) {
20328: var count = 0;
20329: for (var j=0; j<alltargets.length; j++) {
20330: if (alltargets[j] != balancer) {
20331: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
20332: item.value = alltargets[j];
20333: item.style.textAlign='left';
20334: item.style.textFace='normal';
20335: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
20336: if (currBalancers.indexOf(alltargets[j]) == -1) {
20337: item.disabled = '';
20338: } else {
20339: item.disabled = 'disabled';
20340: item.checked = false;
20341: }
20342: count ++;
20343: }
20344: }
20345: }
20346: for (var k=0; k<insttypes.length; k++) {
20347: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
20348: if (ishomedom == 1) {
20349: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
20350: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
20351: } else {
20352: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
20353: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
20354: }
20355: } else {
20356: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
20357: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
20358: }
20359: if ((insttypes[k] != '_LC_external') &&
20360: ((insttypes[k] != '_LC_internetdom') ||
20361: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
20362: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
20363: item.options.length = 0;
20364: item.options[0] = new Option("","",true,true);
20365: var idx = 0;
20366: for (var m=0; m<alltargets.length; m++) {
20367: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
20368: idx ++;
20369: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
20370: }
20371: }
20372: }
20373: }
20374: return;
20375: }
20376:
20377: function hideSpares(balnum) {
20378: var alltargets = new Array('$alltargets');
20379: var insttypes = new Array('$allinsttypes');
20380: var offloadtypes = new Array('primary','default');
20381:
20382: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
20383: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
20384:
20385: var total = alltargets.length - 1;
20386: for (var i=0; i<offloadtypes; i++) {
20387: for (var j=0; j<total; j++) {
20388: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
20389: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
20390: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
20391: }
20392: }
20393: for (var k=0; k<insttypes.length; k++) {
20394: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
20395: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
20396: if (insttypes[k] != '_LC_external') {
20397: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
20398: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
20399: }
20400: }
20401: return;
20402: }
20403:
20404: function checkOffloads(item,balnum,type) {
20405: var alltargets = new Array('$alltargets');
20406: var offloadtypes = new Array('primary','default');
20407: if (item.checked) {
20408: var total = alltargets.length - 1;
20409: var other;
20410: if (type == offloadtypes[0]) {
20411: other = offloadtypes[1];
20412: } else {
20413: other = offloadtypes[0];
20414: }
20415: for (var i=0; i<total; i++) {
20416: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
20417: if (server == item.value) {
20418: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
20419: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
20420: }
20421: }
20422: }
20423: }
20424: return;
20425: }
20426:
20427: function singleServerToggle(balnum,type) {
20428: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
20429: if (offloadtoSelIdx == 0) {
20430: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
20431: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
20432:
20433: } else {
20434: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
20435: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
20436: }
20437: return;
20438: }
20439:
20440: function balanceruleChange(formname,balnum,type) {
20441: if (type == '_LC_external') {
20442: return;
20443: }
20444: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
20445: for (var i=0; i<typesRules.length; i++) {
20446: if (formname.elements[typesRules[i]].checked) {
20447: if (formname.elements[typesRules[i]].value != 'specific') {
20448: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
20449: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
20450: } else {
20451: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
20452: }
20453: }
20454: }
20455: return;
20456: }
20457:
20458: function balancerDeleteChange(balnum) {
20459: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20460: var baltotal = document.getElementById('loadbalancing_total').value;
20461: var addtarget;
20462: var removetarget;
20463: var action = 'delete';
20464: if (document.getElementById('loadbalancing_delete_'+balnum)) {
20465: var lonhost = hostitem.value;
20466: var currIdx = currBalancers.indexOf(lonhost);
20467: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
20468: if (currIdx != -1) {
20469: currBalancers.splice(currIdx,1);
20470: }
20471: addtarget = lonhost;
20472: } else {
20473: if (currIdx == -1) {
20474: currBalancers.push(lonhost);
20475: }
20476: removetarget = lonhost;
20477: action = 'undelete';
20478: }
20479: balancerChange(balnum,baltotal,action,addtarget,removetarget);
20480: }
20481: return;
20482: }
20483:
20484: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
20485: if (baltotal > 1) {
20486: var offloadtypes = new Array('primary','default');
20487: var alltargets = new Array('$alltargets');
20488: var insttypes = new Array('$allinsttypes');
20489: for (var i=0; i<baltotal; i++) {
20490: if (i != balnum) {
20491: for (var j=0; j<offloadtypes.length; j++) {
20492: var total = alltargets.length - 1;
20493: for (var k=0; k<total; k++) {
20494: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
20495: var server = serveritem.value;
20496: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
20497: if (server == addtarget) {
20498: serveritem.disabled = '';
20499: }
20500: }
20501: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
20502: if (server == removetarget) {
20503: serveritem.disabled = 'disabled';
20504: serveritem.checked = false;
20505: }
20506: }
20507: }
20508: }
20509: for (var j=0; j<insttypes.length; j++) {
20510: if (insttypes[j] != '_LC_external') {
20511: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
20512: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
20513: var currSel = singleserver.selectedIndex;
20514: var currVal = singleserver.options[currSel].value;
20515: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
20516: var numoptions = singleserver.options.length;
20517: var needsnew = 1;
20518: for (var k=0; k<numoptions; k++) {
20519: if (singleserver.options[k] == addtarget) {
20520: needsnew = 0;
20521: break;
20522: }
20523: }
20524: if (needsnew == 1) {
20525: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
20526: }
20527: }
20528: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
20529: singleserver.options.length = 0;
20530: if ((currVal) && (currVal != removetarget)) {
20531: singleserver.options[0] = new Option("","",false,false);
20532: } else {
20533: singleserver.options[0] = new Option("","",true,true);
20534: }
20535: var idx = 0;
20536: for (var m=0; m<alltargets.length; m++) {
20537: if (currBalancers.indexOf(alltargets[m]) == -1) {
20538: idx ++;
20539: if (currVal == alltargets[m]) {
20540: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
20541: } else {
20542: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
20543: }
20544: }
20545: }
20546: }
20547: }
20548: }
20549: }
20550: }
20551: }
20552: }
20553: return;
20554: }
20555:
20556: // ]]>
20557: </script>
20558:
20559: END
20560: }
20561:
20562: sub new_spares_js {
20563: my @sparestypes = ('primary','default');
20564: my $types = join("','",@sparestypes);
20565: my $select = &mt('Select');
20566: return <<"END";
20567:
20568: <script type="text/javascript">
20569: // <![CDATA[
20570:
20571: function updateNewSpares(formname,lonhost) {
20572: var types = new Array('$types');
20573: var include = new Array();
20574: var exclude = new Array();
20575: for (var i=0; i<types.length; i++) {
20576: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
20577: for (var j=0; j<spareboxes.length; j++) {
20578: if (formname.elements[spareboxes[j]].checked) {
20579: exclude.push(formname.elements[spareboxes[j]].value);
20580: } else {
20581: include.push(formname.elements[spareboxes[j]].value);
20582: }
20583: }
20584: }
20585: for (var i=0; i<types.length; i++) {
20586: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
20587: var selIdx = newSpare.selectedIndex;
20588: var currnew = newSpare.options[selIdx].value;
20589: var okSpares = new Array();
20590: for (var j=0; j<newSpare.options.length; j++) {
20591: var possible = newSpare.options[j].value;
20592: if (possible != '') {
20593: if (exclude.indexOf(possible) == -1) {
20594: okSpares.push(possible);
20595: } else {
20596: if (currnew == possible) {
20597: selIdx = 0;
20598: }
20599: }
20600: }
20601: }
20602: for (var k=0; k<include.length; k++) {
20603: if (okSpares.indexOf(include[k]) == -1) {
20604: okSpares.push(include[k]);
20605: }
20606: }
20607: okSpares.sort();
20608: newSpare.options.length = 0;
20609: if (selIdx == 0) {
20610: newSpare.options[0] = new Option("$select","",true,true);
20611: } else {
20612: newSpare.options[0] = new Option("$select","",false,false);
20613: }
20614: for (var m=0; m<okSpares.length; m++) {
20615: var idx = m+1;
20616: var selThis = 0;
20617: if (selIdx != 0) {
20618: if (okSpares[m] == currnew) {
20619: selThis = 1;
20620: }
20621: }
20622: if (selThis == 1) {
20623: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
20624: } else {
20625: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
20626: }
20627: }
20628: }
20629: return;
20630: }
20631:
20632: function checkNewSpares(lonhost,type) {
20633: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
20634: var chosen = newSpare.options[newSpare.selectedIndex].value;
20635: if (chosen != '') {
20636: var othertype;
20637: var othernewSpare;
20638: if (type == 'primary') {
20639: othernewSpare = document.getElementById('newspare_default_'+lonhost);
20640: }
20641: if (type == 'default') {
20642: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
20643: }
20644: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
20645: othernewSpare.selectedIndex = 0;
20646: }
20647: }
20648: return;
20649: }
20650:
20651: // ]]>
20652: </script>
20653:
20654: END
20655:
20656: }
20657:
20658: sub common_domprefs_js {
20659: return <<"END";
20660:
20661: <script type="text/javascript">
20662: // <![CDATA[
20663:
20664: function getIndicesByName(formname,item) {
20665: var group = new Array();
20666: for (var i=0;i<formname.elements.length;i++) {
20667: if (formname.elements[i].name == item) {
20668: group.push(formname.elements[i].id);
20669: }
20670: }
20671: return group;
20672: }
20673:
20674: // ]]>
20675: </script>
20676:
20677: END
20678:
20679: }
20680:
20681: sub recaptcha_js {
20682: my %lt = &captcha_phrases();
20683: return <<"END";
20684:
20685: <script type="text/javascript">
20686: // <![CDATA[
20687:
20688: function updateCaptcha(caller,context) {
20689: var privitem;
20690: var pubitem;
20691: var privtext;
20692: var pubtext;
20693: var versionitem;
20694: var versiontext;
20695: if (document.getElementById(context+'_recaptchapub')) {
20696: pubitem = document.getElementById(context+'_recaptchapub');
20697: } else {
20698: return;
20699: }
20700: if (document.getElementById(context+'_recaptchapriv')) {
20701: privitem = document.getElementById(context+'_recaptchapriv');
20702: } else {
20703: return;
20704: }
20705: if (document.getElementById(context+'_recaptchapubtxt')) {
20706: pubtext = document.getElementById(context+'_recaptchapubtxt');
20707: } else {
20708: return;
20709: }
20710: if (document.getElementById(context+'_recaptchaprivtxt')) {
20711: privtext = document.getElementById(context+'_recaptchaprivtxt');
20712: } else {
20713: return;
20714: }
20715: if (document.getElementById(context+'_recaptchaversion')) {
20716: versionitem = document.getElementById(context+'_recaptchaversion');
20717: } else {
20718: return;
20719: }
20720: if (document.getElementById(context+'_recaptchavertxt')) {
20721: versiontext = document.getElementById(context+'_recaptchavertxt');
20722: } else {
20723: return;
20724: }
20725: if (caller.checked) {
20726: if (caller.value == 'recaptcha') {
20727: pubitem.type = 'text';
20728: privitem.type = 'text';
20729: pubitem.size = '40';
20730: privitem.size = '40';
20731: pubtext.innerHTML = "$lt{'pub'}";
20732: privtext.innerHTML = "$lt{'priv'}";
20733: versionitem.type = 'text';
20734: versionitem.size = '3';
20735: versiontext.innerHTML = "$lt{'ver'}";
20736: } else {
20737: pubitem.type = 'hidden';
20738: privitem.type = 'hidden';
20739: versionitem.type = 'hidden';
20740: pubtext.innerHTML = '';
20741: privtext.innerHTML = '';
20742: versiontext.innerHTML = '';
20743: }
20744: }
20745: return;
20746: }
20747:
20748: // ]]>
20749: </script>
20750:
20751: END
20752:
20753: }
20754:
20755: sub toggle_display_js {
20756: return <<"END";
20757:
20758: <script type="text/javascript">
20759: // <![CDATA[
20760:
20761: function toggleDisplay(domForm,caller) {
20762: if (document.getElementById(caller)) {
20763: var divitem = document.getElementById(caller);
20764: var optionsElement = domForm.coursecredits;
20765: var checkval = 1;
20766: var dispval = 'block';
20767: var selfcreateRegExp = /^cancreate_emailverified/;
20768: if (caller == 'emailoptions') {
20769: optionsElement = domForm.cancreate_email;
20770: }
20771: if (caller == 'studentsubmission') {
20772: optionsElement = domForm.postsubmit;
20773: }
20774: if (caller == 'cloneinstcode') {
20775: optionsElement = domForm.canclone;
20776: checkval = 'instcode';
20777: }
20778: if (selfcreateRegExp.test(caller)) {
20779: optionsElement = domForm.elements[caller];
20780: checkval = 'other';
20781: dispval = 'inline'
20782: }
20783: if (optionsElement.length) {
20784: var currval;
20785: for (var i=0; i<optionsElement.length; i++) {
20786: if (optionsElement[i].checked) {
20787: currval = optionsElement[i].value;
20788: }
20789: }
20790: if (currval == checkval) {
20791: divitem.style.display = dispval;
20792: } else {
20793: divitem.style.display = 'none';
20794: }
20795: }
20796: }
20797: return;
20798: }
20799:
20800: // ]]>
20801: </script>
20802:
20803: END
20804:
20805: }
20806:
20807: sub captcha_phrases {
20808: return &Apache::lonlocal::texthash (
20809: priv => 'Private key',
20810: pub => 'Public key',
20811: original => 'original (CAPTCHA)',
20812: recaptcha => 'successor (ReCAPTCHA)',
20813: notused => 'unused',
20814: ver => 'ReCAPTCHA version (1 or 2)',
20815: );
20816: }
20817:
20818: sub devalidate_remote_domconfs {
20819: my ($dom,$cachekeys) = @_;
20820: return unless (ref($cachekeys) eq 'HASH');
20821: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20822: my %thismachine;
20823: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20824: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
20825: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
20826: 'ipaccess');
20827: my %cache_by_lonhost;
20828: if (exists($cachekeys->{'samllanding'})) {
20829: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
20830: my %landing = %{$cachekeys->{'samllanding'}};
20831: my %domservers = &Apache::lonnet::get_servers($dom);
20832: if (keys(%domservers)) {
20833: foreach my $server (keys(%domservers)) {
20834: my @cached;
20835: next if ($thismachine{$server});
20836: if ($landing{$server}) {
20837: push(@cached,&escape('samllanding').':'.&escape($server));
20838: }
20839: if (@cached) {
20840: $cache_by_lonhost{$server} = \@cached;
20841: }
20842: }
20843: }
20844: }
20845: }
20846: if (keys(%servers)) {
20847: foreach my $server (keys(%servers)) {
20848: next if ($thismachine{$server});
20849: my @cached;
20850: foreach my $name (@posscached) {
20851: if ($cachekeys->{$name}) {
20852: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
20853: if (ref($cachekeys->{$name}) eq 'HASH') {
20854: foreach my $key (keys(%{$cachekeys->{$name}})) {
20855: push(@cached,&escape($name).':'.&escape($key));
20856: }
20857: }
20858: } else {
20859: push(@cached,&escape($name).':'.&escape($dom));
20860: }
20861: }
20862: }
20863: if ((exists($cache_by_lonhost{$server})) &&
20864: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
20865: push(@cached,@{$cache_by_lonhost{$server}});
20866: }
20867: if (@cached) {
20868: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
20869: }
20870: }
20871: }
20872: return;
20873: }
20874:
20875: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>