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.11 2023/01/23 03:28:37 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, and textbook). In each case the radio buttons
108: 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 LONCAPA qw(:DEFAULT :match);
171: use LONCAPA::Enrollment;
172: use LONCAPA::lonauthcgi();
173: use File::Copy;
174: use Locale::Language;
175: use DateTime::TimeZone;
176: use DateTime::Locale;
177: use Net::CIDR;
178:
179: my $registered_cleanup;
180: my $modified_urls;
181:
182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
190: my $context = 'domain';
191: my $dom = $env{'request.role.domain'};
192: my $domdesc = &Apache::lonnet::domain($dom,'description');
193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
207: ['phase','actions']);
208: my $phase = 'pickactions';
209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
213: my %domconfig =
214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
218: 'serverstatuses','requestcourses','helpsettings',
219: 'coursedefaults','usersessions','loadbalancing',
220: 'requestauthor','selfenrollment','inststatus',
221: 'passwords','ltitools','ltisec','wafproxy','ipaccess'],$dom);
222: my %encconfig =
223: &Apache::lonnet::get_dom('encconfig',['ltitools','linkprot'],$dom,undef,1);
224: if (ref($domconfig{'ltitools'}) eq 'HASH') {
225: if (ref($encconfig{'ltitools'}) eq 'HASH') {
226: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
227: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
228: foreach my $item ('key','secret') {
229: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
230: }
231: }
232: }
233: }
234: }
235: if (ref($domconfig{'ltisec'}) eq 'HASH') {
236: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
237: if (ref($encconfig{'linkprot'}) eq 'HASH') {
238: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
239: unless ($id =~ /^\d+$/) {
240: delete($domconfig{'ltisec'}{'linkprot'}{$id});
241: }
242: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
243: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
244: foreach my $item ('key','secret') {
245: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
246: }
247: }
248: }
249: }
250: }
251: }
252: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
253: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
254: 'contacts','usercreation','selfcreation','usermodification',
255: 'scantron','requestcourses','requestauthor','coursecategories',
256: 'serverstatuses','helpsettings','coursedefaults',
257: 'ltitools','selfenrollment','usersessions','lti');
258: my %existing;
259: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
260: %existing = %{$domconfig{'loadbalancing'}};
261: }
262: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
263: push(@prefs_order,'loadbalancing');
264: }
265: my %prefs = (
266: 'rolecolors' =>
267: { text => 'Default color schemes',
268: help => 'Domain_Configuration_Color_Schemes',
269: header => [{col1 => 'Student Settings',
270: col2 => '',},
271: {col1 => 'Coordinator Settings',
272: col2 => '',},
273: {col1 => 'Author Settings',
274: col2 => '',},
275: {col1 => 'Administrator Settings',
276: col2 => '',}],
277: print => \&print_rolecolors,
278: modify => \&modify_rolecolors,
279: },
280: 'login' =>
281: { text => 'Log-in page options',
282: help => 'Domain_Configuration_Login_Page',
283: header => [{col1 => 'Log-in Page Items',
284: col2 => '',},
285: {col1 => 'Log-in Help',
286: col2 => 'Value'},
287: {col1 => 'Custom HTML in document head',
288: col2 => 'Value'},
289: {col1 => 'SSO',
290: col2 => 'Dual login: SSO and non-SSO options'},
291: ],
292: print => \&print_login,
293: modify => \&modify_login,
294: },
295: 'defaults' =>
296: { text => 'Default authentication/language/timezone/portal/types',
297: help => 'Domain_Configuration_LangTZAuth',
298: header => [{col1 => 'Setting',
299: col2 => 'Value'},
300: {col1 => 'Institutional user types',
301: col2 => 'Name displayed'},
302: {col1 => 'Mapping for missing usernames via standard log-in',
303: col2 => 'Rules in use'}],
304: print => \&print_defaults,
305: modify => \&modify_defaults,
306: },
307: 'wafproxy' =>
308: { text => 'Web Application Firewall/Reverse Proxy',
309: help => 'Domain_Configuration_WAF_Proxy',
310: header => [{col1 => 'Domain(s)',
311: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
312: },
313: {col1 => 'Domain(s)',
314: col2 => 'WAF Configuration',}],
315: print => \&print_wafproxy,
316: modify => \&modify_wafproxy,
317: },
318: 'passwords' =>
319: { text => 'Passwords (Internal authentication)',
320: help => 'Domain_Configuration_Passwords',
321: header => [{col1 => 'Resetting Forgotten Password',
322: col2 => 'Settings'},
323: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
324: col2 => 'Settings'},
325: {col1 => 'Rules for LON-CAPA Passwords',
326: col2 => 'Settings'},
327: {col1 => 'Course Owner Changing Student Passwords',
328: col2 => 'Settings'}],
329: print => \&print_passwords,
330: modify => \&modify_passwords,
331: },
332: 'quotas' =>
333: { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
334: help => 'Domain_Configuration_Quotas',
335: header => [{col1 => 'User affiliation',
336: col2 => 'Available tools',
337: col3 => 'Quotas, MB; (Authoring requires role)',}],
338: print => \&print_quotas,
339: modify => \&modify_quotas,
340: },
341: 'autoenroll' =>
342: { text => 'Auto-enrollment settings',
343: help => 'Domain_Configuration_Auto_Enrollment',
344: header => [{col1 => 'Configuration setting',
345: col2 => 'Value(s)'}],
346: print => \&print_autoenroll,
347: modify => \&modify_autoenroll,
348: },
349: 'autoupdate' =>
350: { text => 'Auto-update settings',
351: help => 'Domain_Configuration_Auto_Updates',
352: header => [{col1 => 'Setting',
353: col2 => 'Value',},
354: {col1 => 'Setting',
355: col2 => 'Affiliation'},
356: {col1 => 'User population',
357: col2 => 'Updatable user data'}],
358: print => \&print_autoupdate,
359: modify => \&modify_autoupdate,
360: },
361: 'autocreate' =>
362: { text => 'Auto-course creation settings',
363: help => 'Domain_Configuration_Auto_Creation',
364: header => [{col1 => 'Configuration Setting',
365: col2 => 'Value',}],
366: print => \&print_autocreate,
367: modify => \&modify_autocreate,
368: },
369: 'directorysrch' =>
370: { text => 'Directory searches',
371: help => 'Domain_Configuration_InstDirectory_Search',
372: header => [{col1 => 'Institutional Directory Setting',
373: col2 => 'Value',},
374: {col1 => 'LON-CAPA Directory Setting',
375: col2 => 'Value',}],
376: print => \&print_directorysrch,
377: modify => \&modify_directorysrch,
378: },
379: 'contacts' =>
380: { text => 'E-mail addresses and helpform',
381: help => 'Domain_Configuration_Contact_Info',
382: header => [{col1 => 'Default e-mail addresses',
383: col2 => 'Value',},
384: {col1 => 'Recipient(s) for notifications',
385: col2 => 'Value',},
386: {col1 => 'Nightly status check e-mail',
387: col2 => 'Settings',},
388: {col1 => 'Ask helpdesk form settings',
389: col2 => 'Value',},],
390: print => \&print_contacts,
391: modify => \&modify_contacts,
392: },
393: 'usercreation' =>
394: { text => 'User creation',
395: help => 'Domain_Configuration_User_Creation',
396: header => [{col1 => 'Format rule type',
397: col2 => 'Format rules in force'},
398: {col1 => 'User account creation',
399: col2 => 'Usernames which may be created',},
400: {col1 => 'Context',
401: col2 => 'Assignable authentication types'}],
402: print => \&print_usercreation,
403: modify => \&modify_usercreation,
404: },
405: 'selfcreation' =>
406: { text => 'Users self-creating accounts',
407: help => 'Domain_Configuration_Self_Creation',
408: header => [{col1 => 'Self-creation with institutional username',
409: col2 => 'Enabled?'},
410: {col1 => 'Institutional user type (login/SSO self-creation)',
411: col2 => 'Information user can enter'},
412: {col1 => 'Self-creation with e-mail verification',
413: col2 => 'Settings'}],
414: print => \&print_selfcreation,
415: modify => \&modify_selfcreation,
416: },
417: 'usermodification' =>
418: { text => 'User modification',
419: help => 'Domain_Configuration_User_Modification',
420: header => [{col1 => 'Target user has role',
421: col2 => 'User information updatable in author context'},
422: {col1 => 'Target user has role',
423: col2 => 'User information updatable in course context'}],
424: print => \&print_usermodification,
425: modify => \&modify_usermodification,
426: },
427: 'scantron' =>
428: { text => 'Bubblesheet format',
429: help => 'Domain_Configuration_Scantron_Format',
430: header => [ {col1 => 'Bubblesheet format file',
431: col2 => ''},
432: {col1 => 'Bubblesheet data upload formats',
433: col2 => 'Settings'}],
434: print => \&print_scantron,
435: modify => \&modify_scantron,
436: },
437: 'requestcourses' =>
438: {text => 'Request creation of courses',
439: help => 'Domain_Configuration_Request_Courses',
440: header => [{col1 => 'User affiliation',
441: col2 => 'Availability/Processing of requests',},
442: {col1 => 'Setting',
443: col2 => 'Value'},
444: {col1 => 'Available textbooks',
445: col2 => ''},
446: {col1 => 'Available templates',
447: col2 => ''},
448: {col1 => 'Validation (not official courses)',
449: col2 => 'Value'},],
450: print => \&print_quotas,
451: modify => \&modify_quotas,
452: },
453: 'requestauthor' =>
454: {text => 'Request Authoring Space',
455: help => 'Domain_Configuration_Request_Author',
456: header => [{col1 => 'User affiliation',
457: col2 => 'Availability/Processing of requests',},
458: {col1 => 'Setting',
459: col2 => 'Value'}],
460: print => \&print_quotas,
461: modify => \&modify_quotas,
462: },
463: 'coursecategories' =>
464: { text => 'Cataloging of courses/communities',
465: help => 'Domain_Configuration_Cataloging_Courses',
466: header => [{col1 => 'Catalog type/availability',
467: col2 => '',},
468: {col1 => 'Category settings for standard catalog',
469: col2 => '',},
470: {col1 => 'Categories',
471: col2 => '',
472: }],
473: print => \&print_coursecategories,
474: modify => \&modify_coursecategories,
475: },
476: 'serverstatuses' =>
477: {text => 'Access to server status pages',
478: help => 'Domain_Configuration_Server_Status',
479: header => [{col1 => 'Status Page',
480: col2 => 'Other named users',
481: col3 => 'Specific IPs',
482: }],
483: print => \&print_serverstatuses,
484: modify => \&modify_serverstatuses,
485: },
486: 'helpsettings' =>
487: {text => 'Support settings',
488: help => 'Domain_Configuration_Help_Settings',
489: header => [{col1 => 'Help Page Settings (logged-in users)',
490: col2 => 'Value'},
491: {col1 => 'Helpdesk Roles',
492: col2 => 'Settings'},],
493: print => \&print_helpsettings,
494: modify => \&modify_helpsettings,
495: },
496: 'coursedefaults' =>
497: {text => 'Course/Community defaults',
498: help => 'Domain_Configuration_Course_Defaults',
499: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
500: col2 => 'Value',},
501: {col1 => 'Defaults which can be overridden for each course by a DC',
502: col2 => 'Value',},],
503: print => \&print_coursedefaults,
504: modify => \&modify_coursedefaults,
505: },
506: 'selfenrollment' =>
507: {text => 'Self-enrollment in Course/Community',
508: help => 'Domain_Configuration_Selfenrollment',
509: header => [{col1 => 'Configuration Rights',
510: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
511: {col1 => 'Defaults',
512: col2 => 'Value'},
513: {col1 => 'Self-enrollment validation (optional)',
514: col2 => 'Value'},],
515: print => \&print_selfenrollment,
516: modify => \&modify_selfenrollment,
517: },
518: 'usersessions' =>
519: {text => 'User session hosting/offloading',
520: help => 'Domain_Configuration_User_Sessions',
521: header => [{col1 => 'Domain server',
522: col2 => 'Servers to offload sessions to when busy'},
523: {col1 => 'Hosting of users from other domains',
524: col2 => 'Rules'},
525: {col1 => "Hosting domain's own users elsewhere",
526: col2 => 'Rules'}],
527: print => \&print_usersessions,
528: modify => \&modify_usersessions,
529: },
530: 'loadbalancing' =>
531: {text => 'Dedicated Load Balancer(s)',
532: help => 'Domain_Configuration_Load_Balancing',
533: header => [{col1 => 'Balancers',
534: col2 => 'Default destinations',
535: col3 => 'User affiliation',
536: col4 => 'Overrides'},
537: ],
538: print => \&print_loadbalancing,
539: modify => \&modify_loadbalancing,
540: },
541: 'ltitools' =>
542: {text => 'External Tools (LTI)',
543: help => 'Domain_Configuration_LTI_Tools',
544: header => [{col1 => 'Setting',
545: col2 => 'Value',}],
546: print => \&print_ltitools,
547: modify => \&modify_ltitools,
548: },
549: 'lti' =>
550: {text => 'LTI Link Protection and LTI Consumers',
551: help => 'Domain_Configuration_LTI_Provider',
552: header => [{col1 => 'Encryption of shared secrets',
553: col2 => 'Settings'},
554: {col1 => 'Rules for shared secrets',
555: col2 => 'Settings'},
556: {col1 => 'Link Protectors',
557: col2 => 'Settings'},],
558: print => \&print_lti,
559: modify => \&modify_lti,
560: },
561: 'ipaccess' =>
562: {text => 'IP-based access control',
563: help => 'Domain_Configuration_IP_Access',
564: header => [{col1 => 'Setting',
565: col2 => 'Value'},],
566: print => \&print_ipaccess,
567: modify => \&modify_ipaccess,
568: },
569: );
570: if (keys(%servers) > 1) {
571: $prefs{'login'} = { text => 'Log-in page options',
572: help => 'Domain_Configuration_Login_Page',
573: header => [{col1 => 'Log-in Service',
574: col2 => 'Server Setting',},
575: {col1 => 'Log-in Page Items',
576: col2 => 'Settings'},
577: {col1 => 'Log-in Help',
578: col2 => 'Value'},
579: {col1 => 'Custom HTML in document head',
580: col2 => 'Value'},
581: {col1 => 'SSO',
582: col2 => 'Dual login: SSO and non-SSO options'},
583: ],
584: print => \&print_login,
585: modify => \&modify_login,
586: };
587: }
588:
589: my @roles = ('student','coordinator','author','admin');
590: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
591: &Apache::lonhtmlcommon::add_breadcrumb
592: ({href=>"javascript:changePage(document.$phase,'pickactions')",
593: text=>"Settings to display/modify"});
594: my $confname = $dom.'-domainconfig';
595:
596: if ($phase eq 'process') {
597: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
598: \%prefs,\%domconfig,$confname,\@roles);
599: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
600: $r->rflush();
601: &devalidate_remote_domconfs($dom,$result);
602: }
603: } elsif ($phase eq 'display') {
604: my $js = &recaptcha_js().
605: &toggle_display_js();
606: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
607: my ($othertitle,$usertypes,$types) =
608: &Apache::loncommon::sorted_inst_types($dom);
609: $js .= &lonbalance_targets_js($dom,$types,\%servers,
610: $domconfig{'loadbalancing'}).
611: &new_spares_js().
612: &common_domprefs_js().
613: &Apache::loncommon::javascript_array_indexof();
614: }
615: if (grep(/^requestcourses$/,@actions)) {
616: my $javascript_validations;
617: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
618: $js .= <<END;
619: <script type="text/javascript">
620: $javascript_validations
621: </script>
622: $coursebrowserjs
623: END
624: } elsif (grep(/^ipaccess$/,@actions)) {
625: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
626: }
627: if (grep(/^selfcreation$/,@actions)) {
628: $js .= &selfcreate_javascript();
629: }
630: if (grep(/^contacts$/,@actions)) {
631: $js .= &contacts_javascript();
632: }
633: if (grep(/^scantron$/,@actions)) {
634: $js .= &scantron_javascript();
635: }
636: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
637: } else {
638: # check if domconfig user exists for the domain.
639: my $servadm = $r->dir_config('lonAdmEMail');
640: my ($configuserok,$author_ok,$switchserver) =
641: &config_check($dom,$confname,$servadm);
642: unless ($configuserok eq 'ok') {
643: &Apache::lonconfigsettings::print_header($r,$phase,$context);
644: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
645: $confname).
646: '<br />'
647: );
648: if ($switchserver) {
649: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
650: '<br />'.
651: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
652: '<br />'.
653: &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).
654: '<br />'.
655: &mt('To do that now, use the following link: [_1]',$switchserver)
656: );
657: } else {
658: $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.').
659: '<br />'.
660: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
661: );
662: }
663: $r->print(&Apache::loncommon::end_page());
664: return OK;
665: }
666: if (keys(%domconfig) == 0) {
667: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
668: my @ids=&Apache::lonnet::current_machine_ids();
669: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
670: my %designhash = &Apache::loncommon::get_domainconf($dom);
671: my @loginimages = ('img','logo','domlogo','login');
672: my $custom_img_count = 0;
673: foreach my $img (@loginimages) {
674: if ($designhash{$dom.'.login.'.$img} ne '') {
675: $custom_img_count ++;
676: }
677: }
678: foreach my $role (@roles) {
679: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
680: $custom_img_count ++;
681: }
682: }
683: if ($custom_img_count > 0) {
684: &Apache::lonconfigsettings::print_header($r,$phase,$context);
685: my $switch_server = &check_switchserver($dom,$confname);
686: $r->print(
687: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
688: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
689: &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 />'.
690: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
691: if ($switch_server) {
692: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
693: }
694: $r->print(&Apache::loncommon::end_page());
695: return OK;
696: }
697: }
698: }
699: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
700: }
701: return OK;
702: }
703:
704: sub process_changes {
705: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
706: my %domconfig;
707: if (ref($values) eq 'HASH') {
708: %domconfig = %{$values};
709: }
710: my $output;
711: if ($action eq 'login') {
712: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
713: } elsif ($action eq 'rolecolors') {
714: $output = &modify_rolecolors($r,$dom,$confname,$roles,
715: $lastactref,%domconfig);
716: } elsif ($action eq 'quotas') {
717: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
718: } elsif ($action eq 'autoenroll') {
719: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
720: } elsif ($action eq 'autoupdate') {
721: $output = &modify_autoupdate($dom,%domconfig);
722: } elsif ($action eq 'autocreate') {
723: $output = &modify_autocreate($dom,%domconfig);
724: } elsif ($action eq 'directorysrch') {
725: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
726: } elsif ($action eq 'usercreation') {
727: $output = &modify_usercreation($dom,%domconfig);
728: } elsif ($action eq 'selfcreation') {
729: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
730: } elsif ($action eq 'usermodification') {
731: $output = &modify_usermodification($dom,%domconfig);
732: } elsif ($action eq 'contacts') {
733: $output = &modify_contacts($dom,$lastactref,%domconfig);
734: } elsif ($action eq 'defaults') {
735: $output = &modify_defaults($dom,$lastactref,%domconfig);
736: } elsif ($action eq 'scantron') {
737: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
738: } elsif ($action eq 'coursecategories') {
739: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
740: } elsif ($action eq 'serverstatuses') {
741: $output = &modify_serverstatuses($dom,%domconfig);
742: } elsif ($action eq 'requestcourses') {
743: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
744: } elsif ($action eq 'requestauthor') {
745: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
746: } elsif ($action eq 'helpsettings') {
747: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
748: } elsif ($action eq 'coursedefaults') {
749: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
750: } elsif ($action eq 'selfenrollment') {
751: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
752: } elsif ($action eq 'usersessions') {
753: $output = &modify_usersessions($dom,$lastactref,%domconfig);
754: } elsif ($action eq 'loadbalancing') {
755: $output = &modify_loadbalancing($dom,%domconfig);
756: } elsif ($action eq 'lti') {
757: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
758: } elsif ($action eq 'passwords') {
759: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
760: } elsif ($action eq 'ltitools') {
761: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
762: } elsif ($action eq 'wafproxy') {
763: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
764: } elsif ($action eq 'ipaccess') {
765: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
766: }
767: return $output;
768: }
769:
770: sub print_config_box {
771: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
772: my $rowtotal = 0;
773: my $output;
774: if ($action eq 'coursecategories') {
775: $output = &coursecategories_javascript($settings);
776: } elsif ($action eq 'defaults') {
777: $output = &defaults_javascript($settings);
778: } elsif ($action eq 'passwords') {
779: $output = &passwords_javascript($action);
780: } elsif ($action eq 'helpsettings') {
781: my (%privs,%levelscurrent);
782: my %full=();
783: my %levels=(
784: course => {},
785: domain => {},
786: system => {},
787: );
788: my $context = 'domain';
789: my $crstype = 'Course';
790: my $formname = 'display';
791: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
792: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
793: $output =
794: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
795: \@templateroles);
796: } elsif ($action eq 'ltitools') {
797: $output .= <itools_javascript($settings);
798: } elsif ($action eq 'lti') {
799: $output .= &passwords_javascript('secrets')."\n".
800: <i_javascript($dom,$settings);
801: } elsif ($action eq 'wafproxy') {
802: $output .= &wafproxy_javascript($dom);
803: } elsif ($action eq 'autoupdate') {
804: $output .= &autoupdate_javascript();
805: } elsif ($action eq 'autoenroll') {
806: $output .= &autoenroll_javascript();
807: } elsif ($action eq 'login') {
808: $output .= &saml_javascript();
809: } elsif ($action eq 'ipaccess') {
810: $output .= &ipaccess_javascript($settings);
811: }
812: $output .=
813: '<table class="LC_nested_outer">
814: <tr>
815: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
816: &mt($item->{text}).' '.
817: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
818: '</tr>';
819: $rowtotal ++;
820: my $numheaders = 1;
821: if (ref($item->{'header'}) eq 'ARRAY') {
822: $numheaders = scalar(@{$item->{'header'}});
823: }
824: if ($numheaders > 1) {
825: my $colspan = '';
826: my $rightcolspan = '';
827: my $leftnobr = '';
828: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
829: ($action eq 'directorysrch') ||
830: (($action eq 'login') && ($numheaders < 5))) {
831: $colspan = ' colspan="2"';
832: }
833: if ($action eq 'usersessions') {
834: $rightcolspan = ' colspan="3"';
835: }
836: if ($action eq 'passwords') {
837: $leftnobr = ' LC_nobreak';
838: }
839: $output .= '
840: <tr>
841: <td>
842: <table class="LC_nested">
843: <tr class="LC_info_row">
844: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
845: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
846: </tr>';
847: $rowtotal ++;
848: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
849: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
850: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
851: ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') || ($action eq 'lti')) {
852: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
853: } elsif ($action eq 'passwords') {
854: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
855: } elsif ($action eq 'coursecategories') {
856: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
857: } elsif ($action eq 'scantron') {
858: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
859: } elsif ($action eq 'login') {
860: if ($numheaders == 5) {
861: $colspan = ' colspan="2"';
862: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
863: } else {
864: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
865: }
866: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
867: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
868: } elsif ($action eq 'rolecolors') {
869: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
870: }
871: $output .= '
872: </table>
873: </td>
874: </tr>
875: <tr>
876: <td>
877: <table class="LC_nested">
878: <tr class="LC_info_row">
879: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
880: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
881: </tr>';
882: $rowtotal ++;
883: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
884: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
885: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
886: ($action eq 'contacts') || ($action eq 'passwords') ||
887: ($action eq 'defaults') || ($action eq 'lti')) {
888: if ($action eq 'coursecategories') {
889: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
890: $colspan = ' colspan="2"';
891: } elsif ($action eq 'passwords') {
892: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
893: } else {
894: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
895: }
896: $output .= '
897: </table>
898: </td>
899: </tr>
900: <tr>
901: <td>
902: <table class="LC_nested">
903: <tr class="LC_info_row">
904: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
905: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
906: </tr>'."\n";
907: if ($action eq 'coursecategories') {
908: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
909: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
910: if ($action eq 'passwords') {
911: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
912: } else {
913: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
914: }
915: $output .= '
916: </tr>
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'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
925: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
926: if ($action eq 'passwords') {
927: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
928: } else {
929: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
930: }
931: $output .= '
932: </table>
933: </td>
934: </tr>
935: <tr>';
936: } else {
937: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
938: }
939: $rowtotal ++;
940: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
941: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
942: ($action eq 'wafproxy')) {
943: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
944: } elsif ($action eq 'scantron') {
945: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
946: } elsif ($action eq 'login') {
947: if ($numheaders == 5) {
948: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
949: </table>
950: </td>
951: </tr>
952: <tr>
953: <td>
954: <table class="LC_nested">
955: <tr class="LC_info_row">
956: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
957: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
958: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
959: $rowtotal ++;
960: } else {
961: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
962: }
963: $output .= '
964: </table>
965: </td>
966: </tr>
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">';
971: if ($numheaders == 5) {
972: $output .= '
973: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
974: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
975: </tr>';
976: } else {
977: $output .= '
978: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
979: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
980: </tr>';
981: }
982: $rowtotal ++;
983: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
984: </table>
985: </td>
986: </tr>
987: <tr>
988: <td>
989: <table class="LC_nested">
990: <tr class="LC_info_row">';
991: if ($numheaders == 5) {
992: $output .= '
993: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
994: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
995: </tr>';
996: } else {
997: $output .= '
998: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
999: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1000: </tr>';
1001: }
1002: $rowtotal ++;
1003: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1004: } elsif ($action eq 'requestcourses') {
1005: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1006: $rowtotal ++;
1007: $output .= &print_studentcode($settings,\$rowtotal).'
1008: </table>
1009: </td>
1010: </tr>
1011: <tr>
1012: <td>
1013: <table class="LC_nested">
1014: <tr class="LC_info_row">
1015: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1016: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1017: &textbookcourses_javascript($settings).
1018: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1019: </table>
1020: </td>
1021: </tr>
1022: <tr>
1023: <td>
1024: <table class="LC_nested">
1025: <tr class="LC_info_row">
1026: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1027: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1028: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1029: </table>
1030: </td>
1031: </tr>
1032: <tr>
1033: <td>
1034: <table class="LC_nested">
1035: <tr class="LC_info_row">
1036: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1037: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1038: </tr>'.
1039: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1040: } elsif ($action eq 'requestauthor') {
1041: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1042: $rowtotal ++;
1043: } elsif ($action eq 'rolecolors') {
1044: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1045: </table>
1046: </td>
1047: </tr>
1048: <tr>
1049: <td>
1050: <table class="LC_nested">
1051: <tr class="LC_info_row">
1052: <td class="LC_left_item"'.$colspan.' valign="top">'.
1053: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1054: <td class="LC_right_item" valign="top">'.
1055: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1056: </tr>'.
1057: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1058: </table>
1059: </td>
1060: </tr>
1061: <tr>
1062: <td>
1063: <table class="LC_nested">
1064: <tr class="LC_info_row">
1065: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1066: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1067: </tr>'.
1068: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1069: $rowtotal += 2;
1070: }
1071: } else {
1072: $output .= '
1073: <tr>
1074: <td>
1075: <table class="LC_nested">
1076: <tr class="LC_info_row">';
1077: if ($action eq 'login') {
1078: $output .= '
1079: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1080: } elsif ($action eq 'serverstatuses') {
1081: $output .= '
1082: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1083: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1084:
1085: } else {
1086: $output .= '
1087: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1088: }
1089: if (defined($item->{'header'}->[0]->{'col3'})) {
1090: $output .= '<td class="LC_left_item" valign="top">'.
1091: &mt($item->{'header'}->[0]->{'col2'});
1092: if ($action eq 'serverstatuses') {
1093: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1094: }
1095: } else {
1096: $output .= '<td class="LC_right_item" valign="top">'.
1097: &mt($item->{'header'}->[0]->{'col2'});
1098: }
1099: $output .= '</td>';
1100: if ($item->{'header'}->[0]->{'col3'}) {
1101: if (defined($item->{'header'}->[0]->{'col4'})) {
1102: $output .= '<td class="LC_left_item" valign="top">'.
1103: &mt($item->{'header'}->[0]->{'col3'});
1104: } else {
1105: $output .= '<td class="LC_right_item" valign="top">'.
1106: &mt($item->{'header'}->[0]->{'col3'});
1107: }
1108: if ($action eq 'serverstatuses') {
1109: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1110: }
1111: $output .= '</td>';
1112: }
1113: if ($item->{'header'}->[0]->{'col4'}) {
1114: $output .= '<td class="LC_right_item" valign="top">'.
1115: &mt($item->{'header'}->[0]->{'col4'});
1116: }
1117: $output .= '</tr>';
1118: $rowtotal ++;
1119: if ($action eq 'quotas') {
1120: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1121: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1122: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1123: ($action eq 'ltitools') || ($action eq 'ipaccess')) {
1124: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1125: }
1126: }
1127: $output .= '
1128: </table>
1129: </td>
1130: </tr>
1131: </table><br />';
1132: return ($output,$rowtotal);
1133: }
1134:
1135: sub print_login {
1136: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1137: my ($css_class,$datatable,$switchserver,%lt);
1138: my %choices = &login_choices();
1139: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1140: %lt = &login_file_options();
1141: $switchserver = &check_switchserver($dom,$confname);
1142: }
1143:
1144: if ($caller eq 'service') {
1145: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1146: my $choice = $choices{'disallowlogin'};
1147: $css_class = ' class="LC_odd_row"';
1148: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1149: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1150: '<th>'.$choices{'server'}.'</th>'.
1151: '<th>'.$choices{'serverpath'}.'</th>'.
1152: '<th>'.$choices{'custompath'}.'</th>'.
1153: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1154: my %disallowed;
1155: if (ref($settings) eq 'HASH') {
1156: if (ref($settings->{'loginvia'}) eq 'HASH') {
1157: %disallowed = %{$settings->{'loginvia'}};
1158: }
1159: }
1160: foreach my $lonhost (sort(keys(%servers))) {
1161: my $direct = 'selected="selected"';
1162: if (ref($disallowed{$lonhost}) eq 'HASH') {
1163: if ($disallowed{$lonhost}{'server'} ne '') {
1164: $direct = '';
1165: }
1166: }
1167: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1168: '<td><select name="'.$lonhost.'_server">'.
1169: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1170: '</option>';
1171: foreach my $hostid (sort(keys(%servers))) {
1172: next if ($servers{$hostid} eq $servers{$lonhost});
1173: my $selected = '';
1174: if (ref($disallowed{$lonhost}) eq 'HASH') {
1175: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1176: $selected = 'selected="selected"';
1177: }
1178: }
1179: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1180: $servers{$hostid}.'</option>';
1181: }
1182: $datatable .= '</select></td>'.
1183: '<td><select name="'.$lonhost.'_serverpath">';
1184: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1185: my $pathname = $path;
1186: if ($path eq 'custom') {
1187: $pathname = &mt('Custom Path').' ->';
1188: }
1189: my $selected = '';
1190: if (ref($disallowed{$lonhost}) eq 'HASH') {
1191: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1192: $selected = 'selected="selected"';
1193: }
1194: } elsif ($path eq '') {
1195: $selected = 'selected="selected"';
1196: }
1197: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1198: }
1199: $datatable .= '</select></td>';
1200: my ($custom,$exempt);
1201: if (ref($disallowed{$lonhost}) eq 'HASH') {
1202: $custom = $disallowed{$lonhost}{'custompath'};
1203: $exempt = $disallowed{$lonhost}{'exempt'};
1204: }
1205: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1206: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1207: '</tr>';
1208: }
1209: $datatable .= '</table></td></tr>';
1210: return $datatable;
1211: } elsif ($caller eq 'page') {
1212: my %defaultchecked = (
1213: 'coursecatalog' => 'on',
1214: 'helpdesk' => 'on',
1215: 'adminmail' => 'off',
1216: 'newuser' => 'off',
1217: );
1218: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1219: my (%checkedon,%checkedoff);
1220: foreach my $item (@toggles) {
1221: if ($defaultchecked{$item} eq 'on') {
1222: $checkedon{$item} = ' checked="checked" ';
1223: $checkedoff{$item} = ' ';
1224: } elsif ($defaultchecked{$item} eq 'off') {
1225: $checkedoff{$item} = ' checked="checked" ';
1226: $checkedon{$item} = ' ';
1227: }
1228: }
1229: my @images = ('img','logo','domlogo','login');
1230: my @alttext = ('img','logo','domlogo');
1231: my @logintext = ('textcol','bgcol');
1232: my @bgs = ('pgbg','mainbg','sidebg');
1233: my @links = ('link','alink','vlink');
1234: my %designhash = &Apache::loncommon::get_domainconf($dom);
1235: my %defaultdesign = %Apache::loncommon::defaultdesign;
1236: my (%is_custom,%designs);
1237: my %defaults = (
1238: font => $defaultdesign{'login.font'},
1239: );
1240: foreach my $item (@images) {
1241: $defaults{$item} = $defaultdesign{'login.'.$item};
1242: $defaults{'showlogo'}{$item} = 1;
1243: }
1244: foreach my $item (@bgs) {
1245: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1246: }
1247: foreach my $item (@logintext) {
1248: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1249: }
1250: foreach my $item (@links) {
1251: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1252: }
1253: if (ref($settings) eq 'HASH') {
1254: foreach my $item (@toggles) {
1255: if ($settings->{$item} eq '1') {
1256: $checkedon{$item} = ' checked="checked" ';
1257: $checkedoff{$item} = ' ';
1258: } elsif ($settings->{$item} eq '0') {
1259: $checkedoff{$item} = ' checked="checked" ';
1260: $checkedon{$item} = ' ';
1261: }
1262: }
1263: foreach my $item (@images) {
1264: if (defined($settings->{$item})) {
1265: $designs{$item} = $settings->{$item};
1266: $is_custom{$item} = 1;
1267: }
1268: if (defined($settings->{'showlogo'}{$item})) {
1269: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1270: }
1271: }
1272: foreach my $item (@alttext) {
1273: if (ref($settings->{'alttext'}) eq 'HASH') {
1274: if ($settings->{'alttext'}->{$item} ne '') {
1275: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1276: }
1277: }
1278: }
1279: foreach my $item (@logintext) {
1280: if ($settings->{$item} ne '') {
1281: $designs{'logintext'}{$item} = $settings->{$item};
1282: $is_custom{$item} = 1;
1283: }
1284: }
1285: if ($settings->{'font'} ne '') {
1286: $designs{'font'} = $settings->{'font'};
1287: $is_custom{'font'} = 1;
1288: }
1289: foreach my $item (@bgs) {
1290: if ($settings->{$item} ne '') {
1291: $designs{'bgs'}{$item} = $settings->{$item};
1292: $is_custom{$item} = 1;
1293: }
1294: }
1295: foreach my $item (@links) {
1296: if ($settings->{$item} ne '') {
1297: $designs{'links'}{$item} = $settings->{$item};
1298: $is_custom{$item} = 1;
1299: }
1300: }
1301: } else {
1302: if ($designhash{$dom.'.login.font'} ne '') {
1303: $designs{'font'} = $designhash{$dom.'.login.font'};
1304: $is_custom{'font'} = 1;
1305: }
1306: foreach my $item (@images) {
1307: if ($designhash{$dom.'.login.'.$item} ne '') {
1308: $designs{$item} = $designhash{$dom.'.login.'.$item};
1309: $is_custom{$item} = 1;
1310: }
1311: }
1312: foreach my $item (@bgs) {
1313: if ($designhash{$dom.'.login.'.$item} ne '') {
1314: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1315: $is_custom{$item} = 1;
1316: }
1317: }
1318: foreach my $item (@links) {
1319: if ($designhash{$dom.'.login.'.$item} ne '') {
1320: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1321: $is_custom{$item} = 1;
1322: }
1323: }
1324: }
1325: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1326: logo => 'Institution Logo',
1327: domlogo => 'Domain Logo',
1328: login => 'Login box');
1329: my $itemcount = 1;
1330: foreach my $item (@toggles) {
1331: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1332: $datatable .=
1333: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1334: '</td><td>'.
1335: '<span class="LC_nobreak"><label><input type="radio" name="'.
1336: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1337: '</label> <label><input type="radio" name="'.$item.'"'.
1338: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1339: '</tr>';
1340: $itemcount ++;
1341: }
1342: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1343: $datatable .= '</tr></table></td></tr>';
1344: } elsif ($caller eq 'help') {
1345: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1346: my $itemcount = 1;
1347: $defaulturl = '/adm/loginproblems.html';
1348: $defaulttype = 'default';
1349: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1350: my @currlangs;
1351: if (ref($settings) eq 'HASH') {
1352: if (ref($settings->{'helpurl'}) eq 'HASH') {
1353: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1354: next if ($settings->{'helpurl'}{$key} eq '');
1355: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1356: $type{$key} = 'custom';
1357: unless ($key eq 'nolang') {
1358: push(@currlangs,$key);
1359: }
1360: }
1361: } elsif ($settings->{'helpurl'} ne '') {
1362: $type{'nolang'} = 'custom';
1363: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1364: }
1365: }
1366: foreach my $lang ('nolang',sort(@currlangs)) {
1367: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1368: $datatable .= '<tr'.$css_class.'>';
1369: if ($url{$lang} eq '') {
1370: $url{$lang} = $defaulturl;
1371: }
1372: if ($type{$lang} eq '') {
1373: $type{$lang} = $defaulttype;
1374: }
1375: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1376: if ($lang eq 'nolang') {
1377: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1378: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1379: } else {
1380: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1381: $langchoices{$lang},
1382: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1383: }
1384: $datatable .= '</span></td>'."\n".
1385: '<td class="LC_left_item">';
1386: if ($type{$lang} eq 'custom') {
1387: $datatable .= '<span class="LC_nobreak"><label>'.
1388: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1389: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1390: } else {
1391: $datatable .= $lt{'upl'};
1392: }
1393: $datatable .='<br />';
1394: if ($switchserver) {
1395: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1396: } else {
1397: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1398: }
1399: $datatable .= '</td></tr>';
1400: $itemcount ++;
1401: }
1402: my @addlangs;
1403: foreach my $lang (sort(keys(%langchoices))) {
1404: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1405: push(@addlangs,$lang);
1406: }
1407: if (@addlangs > 0) {
1408: my %toadd;
1409: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1410: $toadd{''} = &mt('Select');
1411: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1412: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1413: &mt('Add log-in help page for a specific language:').' '.
1414: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1415: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1416: if ($switchserver) {
1417: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1418: } else {
1419: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1420: }
1421: $datatable .= '</td></tr>';
1422: $itemcount ++;
1423: }
1424: $datatable .= &captcha_choice('login',$settings,$itemcount);
1425: } elsif ($caller eq 'headtag') {
1426: my %domservers = &Apache::lonnet::get_servers($dom);
1427: my $choice = $choices{'headtag'};
1428: $css_class = ' class="LC_odd_row"';
1429: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1430: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1431: '<th>'.$choices{'current'}.'</th>'.
1432: '<th>'.$choices{'action'}.'</th>'.
1433: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1434: my (%currurls,%currexempt);
1435: if (ref($settings) eq 'HASH') {
1436: if (ref($settings->{'headtag'}) eq 'HASH') {
1437: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1438: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1439: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1440: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1441: }
1442: }
1443: }
1444: }
1445: foreach my $lonhost (sort(keys(%domservers))) {
1446: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1447: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1448: if ($currurls{$lonhost}) {
1449: $datatable .= '<td class="LC_right_item"><a href="'.
1450: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1451: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1452: '">'.$lt{'curr'}.'</a></td>'.
1453: '<td><span class="LC_nobreak"><label>'.
1454: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1455: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1456: } else {
1457: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1458: }
1459: $datatable .='<br />';
1460: if ($switchserver) {
1461: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1462: } else {
1463: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1464: }
1465: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1466: }
1467: $datatable .= '</table></td></tr>';
1468: } elsif ($caller eq 'saml') {
1469: my %domservers = &Apache::lonnet::get_servers($dom);
1470: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1471: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1472: '<th>'.$choices{'samllanding'}.'</th>'.
1473: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1474: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1475: foreach my $lonhost (keys(%domservers)) {
1476: $samlurl{$lonhost} = '/adm/sso';
1477: $styleon{$lonhost} = 'display:none';
1478: $styleoff{$lonhost} = '';
1479: }
1480: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1481: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1482: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1483: $saml{$lonhost} = 1;
1484: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1485: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1486: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1487: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1488: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1489: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1490: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1491: $styleon{$lonhost} = '';
1492: $styleoff{$lonhost} = 'display:none';
1493: } else {
1494: $styleon{$lonhost} = 'display:none';
1495: $styleoff{$lonhost} = '';
1496: }
1497: }
1498: }
1499: my $itemcount = 1;
1500: foreach my $lonhost (sort(keys(%domservers))) {
1501: my $samlon = ' ';
1502: my $samloff = ' checked="checked" ';
1503: if ($saml{$lonhost}) {
1504: $samlon = $samloff;
1505: $samloff = ' ';
1506: }
1507: my $samlwinon = '';
1508: my $samlwinoff = ' checked="checked"';
1509: if ($samlwindow{$lonhost}) {
1510: $samlwinon = $samlwinoff;
1511: $samlwinoff = '';
1512: }
1513: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1514: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1515: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1516: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1517: &mt('No').'</label>'.(' 'x2).
1518: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1519: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1520: &mt('Yes').'</label></span></td>'.
1521: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1522: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1523: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1524: '<th>'.&mt('Alt Text').'</th></tr>'.
1525: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1526: $samltext{$lonhost}.'" /></td><td>';
1527: if ($samlimg{$lonhost}) {
1528: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1529: '<span class="LC_nobreak"><label>'.
1530: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1531: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1532: } else {
1533: $datatable .= $lt{'upl'};
1534: }
1535: $datatable .='<br />';
1536: if ($switchserver) {
1537: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1538: } else {
1539: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1540: }
1541: $datatable .= '</td>'.
1542: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1543: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1544: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1545: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1546: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1547: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1548: '<tr'.$css_class.'>'.
1549: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1550: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1551: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1552: $samltitle{$lonhost}.'</textarea></td>'.
1553: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1554: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1555: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1556: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1557: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1558: '</table></td>'.
1559: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1560: $itemcount ++;
1561: }
1562: $datatable .= '</table></td></tr>';
1563: }
1564: return $datatable;
1565: }
1566:
1567: sub login_choices {
1568: my %choices =
1569: &Apache::lonlocal::texthash (
1570: coursecatalog => 'Display Course/Community Catalog link?',
1571: adminmail => "Display Administrator's E-mail Address?",
1572: helpdesk => 'Display "Contact Helpdesk" link',
1573: disallowlogin => "Login page requests redirected",
1574: hostid => "Server",
1575: server => "Redirect to:",
1576: serverpath => "Path",
1577: custompath => "Custom",
1578: exempt => "Exempt IP(s)",
1579: directlogin => "No redirect",
1580: newuser => "Link to create a user account",
1581: img => "Header",
1582: logo => "Main Logo",
1583: domlogo => "Domain Logo",
1584: login => "Log-in Header",
1585: textcol => "Text color",
1586: bgcol => "Box color",
1587: bgs => "Background colors",
1588: links => "Link colors",
1589: font => "Font color",
1590: pgbg => "Header",
1591: mainbg => "Page",
1592: sidebg => "Login box",
1593: link => "Link",
1594: alink => "Active link",
1595: vlink => "Visited link",
1596: headtag => "Custom markup",
1597: action => "Action",
1598: current => "Current",
1599: samllanding => "Dual login?",
1600: samloptions => "Options",
1601: alttext => "Alt text",
1602: );
1603: return %choices;
1604: }
1605:
1606: sub login_file_options {
1607: return &Apache::lonlocal::texthash(
1608: del => 'Delete?',
1609: rep => 'Replace:',
1610: upl => 'Upload:',
1611: curr => 'View contents',
1612: default => 'Default',
1613: custom => 'Custom',
1614: none => 'None',
1615: );
1616: }
1617:
1618: sub print_ipaccess {
1619: my ($dom,$settings,$rowtotal) = @_;
1620: my $css_class;
1621: my $itemcount = 0;
1622: my $datatable;
1623: my %ordered;
1624: if (ref($settings) eq 'HASH') {
1625: foreach my $item (keys(%{$settings})) {
1626: if (ref($settings->{$item}) eq 'HASH') {
1627: my $num = $settings->{$item}{'order'};
1628: if ($num eq '') {
1629: $num = scalar(keys(%{$settings}));
1630: }
1631: $ordered{$num} = $item;
1632: }
1633: }
1634: }
1635: my $maxnum = scalar(keys(%ordered));
1636: if (keys(%ordered)) {
1637: my @items = sort { $a <=> $b } keys(%ordered);
1638: for (my $i=0; $i<@items; $i++) {
1639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1640: my $item = $ordered{$items[$i]};
1641: my ($name,$ipranges,%commblocks,%courses);
1642: if (ref($settings->{$item}) eq 'HASH') {
1643: $name = $settings->{$item}->{'name'};
1644: $ipranges = $settings->{$item}->{'ip'};
1645: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1646: %commblocks = %{$settings->{$item}->{'commblocks'}};
1647: }
1648: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1649: %courses = %{$settings->{$item}->{'courses'}};
1650: }
1651: }
1652: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1653: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1654: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1655: for (my $k=0; $k<=$maxnum; $k++) {
1656: my $vpos = $k+1;
1657: my $selstr;
1658: if ($k == $i) {
1659: $selstr = ' selected="selected" ';
1660: }
1661: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1662: }
1663: $datatable .= '</select>'.(' 'x2).
1664: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1665: &mt('Delete?').'</label></span></td>'.
1666: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1667: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1668: '</td></tr>';
1669: $itemcount ++;
1670: }
1671: }
1672: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1673: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1674: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1675: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1676: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1677: for (my $k=0; $k<$maxnum+1; $k++) {
1678: my $vpos = $k+1;
1679: my $selstr;
1680: if ($k == $maxnum) {
1681: $selstr = ' selected="selected" ';
1682: }
1683: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1684: }
1685: $datatable .= '</select> '."\n".
1686: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1687: '<td colspan="2">'.
1688: &ipaccess_options('add',$itemcount,$dom).
1689: '</td>'."\n".
1690: '</tr>'."\n";
1691: $$rowtotal ++;
1692: return $datatable;
1693: }
1694:
1695: sub ipaccess_options {
1696: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1697: my (%currblocks,%currcourses,$output);
1698: if (ref($blocksref) eq 'HASH') {
1699: %currblocks = %{$blocksref};
1700: }
1701: if (ref($coursesref) eq 'HASH') {
1702: %currcourses = %{$coursesref};
1703: }
1704: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1705: '<span class="LC_nobreak">'.&mt('Name').': '.
1706: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1707: '</span></fieldset>'.
1708: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1709: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1710: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1711: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1712: $ipranges.'</textarea></fieldset>'.
1713: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1714: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1715: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1716: '<table>';
1717: foreach my $cid (sort(keys(%currcourses))) {
1718: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1719: $output .= '<tr><td><span class="LC_nobreak">'.
1720: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1721: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1722: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1723: }
1724: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1725: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1726: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1727: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1728: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1729: '</span></td></tr></table>'."\n".
1730: '</fieldset>';
1731: return $output;
1732: }
1733:
1734: sub blocker_checkboxes {
1735: my ($num,$blocks) = @_;
1736: my ($typeorder,$types) = &commblocktype_text();
1737: my $numinrow = 6;
1738: my $output = '<table>';
1739: for (my $i=0; $i<@{$typeorder}; $i++) {
1740: my $block = $typeorder->[$i];
1741: my $blockstatus;
1742: if (ref($blocks) eq 'HASH') {
1743: if ($blocks->{$block} eq 'on') {
1744: $blockstatus = 'checked="checked"';
1745: }
1746: }
1747: my $rem = $i%($numinrow);
1748: if ($rem == 0) {
1749: if ($i > 0) {
1750: $output .= '</tr>';
1751: }
1752: $output .= '<tr>';
1753: }
1754: if ($i == scalar(@{$typeorder})-1) {
1755: my $colsleft = $numinrow-$rem;
1756: if ($colsleft > 1) {
1757: $output .= '<td colspan="'.$colsleft.'">';
1758: } else {
1759: $output .= '<td>';
1760: }
1761: } else {
1762: $output .= '<td>';
1763: }
1764: my $item = 'ipaccess_block_'.$num;
1765: if ($blockstatus) {
1766: $blockstatus = ' '.$blockstatus;
1767: }
1768: $output .= '<span class="LC_nobreak"><label>'."\n".
1769: '<input type="checkbox" name="'.$item.'"'.
1770: $blockstatus.' value="'.$block.'"'.' />'.
1771: $types->{$block}.'</label></span>'."\n".
1772: '<br /></td>';
1773: }
1774: $output .= '</tr></table>';
1775: return $output;
1776: }
1777:
1778: sub commblocktype_text {
1779: my %types = &Apache::lonlocal::texthash(
1780: 'com' => 'Messaging',
1781: 'chat' => 'Chat Room',
1782: 'boards' => 'Discussion',
1783: 'port' => 'Portfolio',
1784: 'groups' => 'Groups',
1785: 'blogs' => 'Blogs',
1786: 'about' => 'User Information',
1787: 'printout' => 'Printouts',
1788: 'passwd' => 'Change Password',
1789: 'grades' => 'Gradebook',
1790: 'search' => 'Course search',
1791: 'wishlist' => 'Stored links',
1792: 'annotate' => 'Annotations',
1793: );
1794: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1795: return ($typeorder,\%types);
1796: }
1797:
1798: sub print_rolecolors {
1799: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1800: my %choices = &color_font_choices();
1801: my @bgs = ('pgbg','tabbg','sidebg');
1802: my @links = ('link','alink','vlink');
1803: my @images = ('img');
1804: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1805: my %designhash = &Apache::loncommon::get_domainconf($dom);
1806: my %defaultdesign = %Apache::loncommon::defaultdesign;
1807: my (%is_custom,%designs);
1808: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1809: if (ref($settings) eq 'HASH') {
1810: if (ref($settings->{$role}) eq 'HASH') {
1811: if ($settings->{$role}->{'img'} ne '') {
1812: $designs{'img'} = $settings->{$role}->{'img'};
1813: $is_custom{'img'} = 1;
1814: }
1815: if ($settings->{$role}->{'font'} ne '') {
1816: $designs{'font'} = $settings->{$role}->{'font'};
1817: $is_custom{'font'} = 1;
1818: }
1819: if ($settings->{$role}->{'fontmenu'} ne '') {
1820: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1821: $is_custom{'fontmenu'} = 1;
1822: }
1823: foreach my $item (@bgs) {
1824: if ($settings->{$role}->{$item} ne '') {
1825: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1826: $is_custom{$item} = 1;
1827: }
1828: }
1829: foreach my $item (@links) {
1830: if ($settings->{$role}->{$item} ne '') {
1831: $designs{'links'}{$item} = $settings->{$role}->{$item};
1832: $is_custom{$item} = 1;
1833: }
1834: }
1835: }
1836: } else {
1837: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1838: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1839: $is_custom{'img'} = 1;
1840: }
1841: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1842: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1843: $is_custom{'fontmenu'} = 1;
1844: }
1845: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1846: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1847: $is_custom{'font'} = 1;
1848: }
1849: foreach my $item (@bgs) {
1850: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1851: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1852: $is_custom{$item} = 1;
1853:
1854: }
1855: }
1856: foreach my $item (@links) {
1857: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1858: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1859: $is_custom{$item} = 1;
1860: }
1861: }
1862: }
1863: my $itemcount = 1;
1864: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1865: $datatable .= '</tr></table></td></tr>';
1866: return $datatable;
1867: }
1868:
1869: sub role_defaults {
1870: my ($role,$bgs,$links,$images,$logintext) = @_;
1871: my %defaults;
1872: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1873: return %defaults;
1874: }
1875: my %defaultdesign = %Apache::loncommon::defaultdesign;
1876: if ($role eq 'login') {
1877: %defaults = (
1878: font => $defaultdesign{$role.'.font'},
1879: );
1880: if (ref($logintext) eq 'ARRAY') {
1881: foreach my $item (@{$logintext}) {
1882: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1883: }
1884: }
1885: foreach my $item (@{$images}) {
1886: $defaults{'showlogo'}{$item} = 1;
1887: }
1888: } else {
1889: %defaults = (
1890: img => $defaultdesign{$role.'.img'},
1891: font => $defaultdesign{$role.'.font'},
1892: fontmenu => $defaultdesign{$role.'.fontmenu'},
1893: );
1894: }
1895: foreach my $item (@{$bgs}) {
1896: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1897: }
1898: foreach my $item (@{$links}) {
1899: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1900: }
1901: foreach my $item (@{$images}) {
1902: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1903: }
1904: return %defaults;
1905: }
1906:
1907: sub display_color_options {
1908: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1909: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1910: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1911: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1912: my $datatable = '<tr'.$css_class.'>'.
1913: '<td>'.$choices->{'font'}.'</td>';
1914: if (!$is_custom->{'font'}) {
1915: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1916: } else {
1917: $datatable .= '<td> </td>';
1918: }
1919: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1920:
1921: $datatable .= '<td><span class="LC_nobreak">'.
1922: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1923: ' value="'.$current_color.'" /> '.
1924: ' </span></td></tr>';
1925: unless ($role eq 'login') {
1926: $datatable .= '<tr'.$css_class.'>'.
1927: '<td>'.$choices->{'fontmenu'}.'</td>';
1928: if (!$is_custom->{'fontmenu'}) {
1929: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1930: } else {
1931: $datatable .= '<td> </td>';
1932: }
1933: $current_color = $designs->{'fontmenu'} ?
1934: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1935: $datatable .= '<td><span class="LC_nobreak">'.
1936: '<input class="colorchooser" type="text" size="10" name="'
1937: .$role.'_fontmenu"'.
1938: ' value="'.$current_color.'" /> '.
1939: ' </span></td></tr>';
1940: }
1941: my $switchserver = &check_switchserver($dom,$confname);
1942: foreach my $img (@{$images}) {
1943: $itemcount ++;
1944: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1945: $datatable .= '<tr'.$css_class.'>'.
1946: '<td>'.$choices->{$img};
1947: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1948: if ($role eq 'login') {
1949: if ($img eq 'login') {
1950: $login_hdr_pick =
1951: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1952: $logincolors =
1953: &login_text_colors($img,$role,$logintext,$phase,$choices,
1954: $designs,$defaults);
1955: } else {
1956: if ($img ne 'domlogo') {
1957: $datatable.= &logo_display_options($img,$defaults,$designs);
1958: }
1959: if (ref($designs->{'alttext'}) eq 'HASH') {
1960: $alttext = $designs->{'alttext'}{$img};
1961: }
1962: }
1963: }
1964: $datatable .= '</td>';
1965: if ($designs->{$img} ne '') {
1966: $imgfile = $designs->{$img};
1967: $img_import = ($imgfile =~ m{^/adm/});
1968: } else {
1969: $imgfile = $defaults->{$img};
1970: }
1971: if ($imgfile) {
1972: my ($showfile,$fullsize);
1973: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1974: my $urldir = $1;
1975: my $filename = $2;
1976: my @info = &Apache::lonnet::stat_file($designs->{$img});
1977: if (@info) {
1978: my $thumbfile = 'tn-'.$filename;
1979: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1980: if (@thumb) {
1981: $showfile = $urldir.'/'.$thumbfile;
1982: } else {
1983: $showfile = $imgfile;
1984: }
1985: } else {
1986: $showfile = '';
1987: }
1988: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1989: $showfile = $imgfile;
1990: my $imgdir = $1;
1991: my $filename = $2;
1992: if (-e "$londocroot/$imgdir/tn-".$filename) {
1993: $showfile = "/$imgdir/tn-".$filename;
1994: } else {
1995: my $input = $londocroot.$imgfile;
1996: my $output = "$londocroot/$imgdir/tn-".$filename;
1997: if (!-e $output) {
1998: my ($width,$height) = &thumb_dimensions();
1999: my ($fullwidth,$fullheight) = &check_dimensions($input);
2000: if ($fullwidth ne '' && $fullheight ne '') {
2001: if ($fullwidth > $width && $fullheight > $height) {
2002: my $size = $width.'x'.$height;
2003: my @args = ('convert','-sample',$size,$input,$output);
2004: system({$args[0]} @args);
2005: $showfile = "/$imgdir/tn-".$filename;
2006: }
2007: }
2008: }
2009: }
2010: }
2011: if ($showfile) {
2012: if ($showfile =~ m{^/(adm|res)/}) {
2013: if ($showfile =~ m{^/res/}) {
2014: my $local_showfile =
2015: &Apache::lonnet::filelocation('',$showfile);
2016: &Apache::lonnet::repcopy($local_showfile);
2017: }
2018: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2019: }
2020: if ($imgfile) {
2021: if ($imgfile =~ m{^/(adm|res)/}) {
2022: if ($imgfile =~ m{^/res/}) {
2023: my $local_imgfile =
2024: &Apache::lonnet::filelocation('',$imgfile);
2025: &Apache::lonnet::repcopy($local_imgfile);
2026: }
2027: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2028: } else {
2029: $fullsize = $imgfile;
2030: }
2031: }
2032: $datatable .= '<td>';
2033: if ($img eq 'login') {
2034: $datatable .= $login_hdr_pick;
2035: }
2036: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2037: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
2038: } else {
2039: $datatable .= '<td> </td><td class="LC_left_item">'.
2040: &mt('Upload:').'<br />';
2041: }
2042: } else {
2043: $datatable .= '<td> </td><td class="LC_left_item">'.
2044: &mt('Upload:').'<br />';
2045: }
2046: if ($switchserver) {
2047: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2048: } else {
2049: if ($img ne 'login') { # suppress file selection for Log-in header
2050: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2051: }
2052: }
2053: if (($role eq 'login') && ($img ne 'login')) {
2054: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2055: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2056: '</label></span>';
2057: }
2058: $datatable .= '</td></tr>';
2059: }
2060: $itemcount ++;
2061: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2062: $datatable .= '<tr'.$css_class.'>'.
2063: '<td>'.$choices->{'bgs'}.'</td>';
2064: my $bgs_def;
2065: foreach my $item (@{$bgs}) {
2066: if (!$is_custom->{$item}) {
2067: $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>';
2068: }
2069: }
2070: if ($bgs_def) {
2071: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
2072: } else {
2073: $datatable .= '<td> </td>';
2074: }
2075: $datatable .= '<td class="LC_right_item">'.
2076: '<table border="0"><tr>';
2077:
2078: foreach my $item (@{$bgs}) {
2079: $datatable .= '<td align="center">'.$choices->{$item};
2080: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
2081: if ($designs->{'bgs'}{$item}) {
2082: $datatable .= ' ';
2083: }
2084: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2085: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
2086: }
2087: $datatable .= '</tr></table></td></tr>';
2088: $itemcount ++;
2089: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2090: $datatable .= '<tr'.$css_class.'>'.
2091: '<td>'.$choices->{'links'}.'</td>';
2092: my $links_def;
2093: foreach my $item (@{$links}) {
2094: if (!$is_custom->{$item}) {
2095: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
2096: }
2097: }
2098: if ($links_def) {
2099: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
2100: } else {
2101: $datatable .= '<td> </td>';
2102: }
2103: $datatable .= '<td class="LC_right_item">'.
2104: '<table border="0"><tr>';
2105: foreach my $item (@{$links}) {
2106: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
2107: $datatable .= '<td align="center">'.$choices->{$item}."\n";
2108: if ($designs->{'links'}{$item}) {
2109: $datatable.=' ';
2110: }
2111: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
2112: '" /></td>';
2113: }
2114: $$rowtotal += $itemcount;
2115: return $datatable;
2116: }
2117:
2118: sub logo_display_options {
2119: my ($img,$defaults,$designs) = @_;
2120: my $checkedon;
2121: if (ref($defaults) eq 'HASH') {
2122: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2123: if ($defaults->{'showlogo'}{$img}) {
2124: $checkedon = 'checked="checked" ';
2125: }
2126: }
2127: }
2128: if (ref($designs) eq 'HASH') {
2129: if (ref($designs->{'showlogo'}) eq 'HASH') {
2130: if (defined($designs->{'showlogo'}{$img})) {
2131: if ($designs->{'showlogo'}{$img} == 0) {
2132: $checkedon = '';
2133: } elsif ($designs->{'showlogo'}{$img} == 1) {
2134: $checkedon = 'checked="checked" ';
2135: }
2136: }
2137: }
2138: }
2139: return '<br /><label> <input type="checkbox" name="'.
2140: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2141: &mt('show').'</label>'."\n";
2142: }
2143:
2144: sub login_header_options {
2145: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2146: my $output = '';
2147: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
2148: $output .= &mt('Text default(s):').'<br />';
2149: if (!$is_custom->{'textcol'}) {
2150: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2151: ' ';
2152: }
2153: if (!$is_custom->{'bgcol'}) {
2154: $output .= $choices->{'bgcol'}.': '.
2155: '<span id="css_'.$role.'_font" style="background-color: '.
2156: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2157: }
2158: $output .= '<br />';
2159: }
2160: $output .='<br />';
2161: return $output;
2162: }
2163:
2164: sub login_text_colors {
2165: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
2166: my $color_menu = '<table border="0"><tr>';
2167: foreach my $item (@{$logintext}) {
2168: $color_menu .= '<td align="center">'.$choices->{$item};
2169: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2170: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2171: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
2172: }
2173: $color_menu .= '</tr></table><br />';
2174: return $color_menu;
2175: }
2176:
2177: sub image_changes {
2178: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2179: my $output;
2180: if ($img eq 'login') {
2181: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
2182: } elsif (!$is_custom) {
2183: if ($img ne 'domlogo') {
2184: $output = &mt('Default image:').'<br />';
2185: } else {
2186: $output = &mt('Default in use:').'<br />';
2187: }
2188: }
2189: if ($img ne 'login') {
2190: if ($img_import) {
2191: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2192: }
2193: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2194: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2195: if ($is_custom) {
2196: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2197: '<input type="checkbox" name="'.
2198: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2199: '</label> '.&mt('Replace:').'</span><br />';
2200: } else {
2201: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
2202: }
2203: }
2204: return $output;
2205: }
2206:
2207: sub print_quotas {
2208: my ($dom,$settings,$rowtotal,$action) = @_;
2209: my $context;
2210: if ($action eq 'quotas') {
2211: $context = 'tools';
2212: } else {
2213: $context = $action;
2214: }
2215: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
2216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2217: my $typecount = 0;
2218: my ($css_class,%titles);
2219: if ($context eq 'requestcourses') {
2220: @usertools = ('official','unofficial','community','textbook');
2221: @options =('norequest','approval','validate','autolimit');
2222: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2223: %titles = &courserequest_titles();
2224: } elsif ($context eq 'requestauthor') {
2225: @usertools = ('author');
2226: @options = ('norequest','approval','automatic');
2227: %titles = &authorrequest_titles();
2228: } else {
2229: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
2230: %titles = &tool_titles();
2231: }
2232: if (ref($types) eq 'ARRAY') {
2233: foreach my $type (@{$types}) {
2234: my ($currdefquota,$currauthorquota);
2235: unless (($context eq 'requestcourses') ||
2236: ($context eq 'requestauthor')) {
2237: if (ref($settings) eq 'HASH') {
2238: if (ref($settings->{defaultquota}) eq 'HASH') {
2239: $currdefquota = $settings->{defaultquota}->{$type};
2240: } else {
2241: $currdefquota = $settings->{$type};
2242: }
2243: if (ref($settings->{authorquota}) eq 'HASH') {
2244: $currauthorquota = $settings->{authorquota}->{$type};
2245: }
2246: }
2247: }
2248: if (defined($usertypes->{$type})) {
2249: $typecount ++;
2250: $css_class = $typecount%2?' class="LC_odd_row"':'';
2251: $datatable .= '<tr'.$css_class.'>'.
2252: '<td>'.$usertypes->{$type}.'</td>'.
2253: '<td class="LC_left_item">';
2254: if ($context eq 'requestcourses') {
2255: $datatable .= '<table><tr>';
2256: }
2257: my %cell;
2258: foreach my $item (@usertools) {
2259: if ($context eq 'requestcourses') {
2260: my ($curroption,$currlimit);
2261: if (ref($settings) eq 'HASH') {
2262: if (ref($settings->{$item}) eq 'HASH') {
2263: $curroption = $settings->{$item}->{$type};
2264: if ($curroption =~ /^autolimit=(\d*)$/) {
2265: $currlimit = $1;
2266: }
2267: }
2268: }
2269: if (!$curroption) {
2270: $curroption = 'norequest';
2271: }
2272: $datatable .= '<th>'.$titles{$item}.'</th>';
2273: foreach my $option (@options) {
2274: my $val = $option;
2275: if ($option eq 'norequest') {
2276: $val = 0;
2277: }
2278: if ($option eq 'validate') {
2279: my $canvalidate = 0;
2280: if (ref($validations{$item}) eq 'HASH') {
2281: if ($validations{$item}{$type}) {
2282: $canvalidate = 1;
2283: }
2284: }
2285: next if (!$canvalidate);
2286: }
2287: my $checked = '';
2288: if ($option eq $curroption) {
2289: $checked = ' checked="checked"';
2290: } elsif ($option eq 'autolimit') {
2291: if ($curroption =~ /^autolimit/) {
2292: $checked = ' checked="checked"';
2293: }
2294: }
2295: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2296: '<input type="radio" name="crsreq_'.$item.
2297: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
2298: $titles{$option}.'</label>';
2299: if ($option eq 'autolimit') {
2300: $cell{$item} .= ' <input type="text" name="crsreq_'.
2301: $item.'_limit_'.$type.'" size="1" '.
2302: 'value="'.$currlimit.'" />';
2303: }
2304: $cell{$item} .= '</span> ';
2305: if ($option eq 'autolimit') {
2306: $cell{$item} .= $titles{'unlimited'};
2307: }
2308: }
2309: } elsif ($context eq 'requestauthor') {
2310: my $curroption;
2311: if (ref($settings) eq 'HASH') {
2312: $curroption = $settings->{$type};
2313: }
2314: if (!$curroption) {
2315: $curroption = 'norequest';
2316: }
2317: foreach my $option (@options) {
2318: my $val = $option;
2319: if ($option eq 'norequest') {
2320: $val = 0;
2321: }
2322: my $checked = '';
2323: if ($option eq $curroption) {
2324: $checked = ' checked="checked"';
2325: }
2326: $datatable .= '<span class="LC_nobreak"><label>'.
2327: '<input type="radio" name="authorreq_'.$type.
2328: '" value="'.$val.'"'.$checked.' />'.
2329: $titles{$option}.'</label></span> ';
2330: }
2331: } else {
2332: my $checked = 'checked="checked" ';
2333: if ($item eq 'timezone') {
2334: $checked = '';
2335: }
2336: if (ref($settings) eq 'HASH') {
2337: if (ref($settings->{$item}) eq 'HASH') {
2338: if (!$settings->{$item}->{$type}) {
2339: $checked = '';
2340: } elsif ($settings->{$item}->{$type} == 1) {
2341: $checked = 'checked="checked" ';
2342: }
2343: }
2344: }
2345: $datatable .= '<span class="LC_nobreak"><label>'.
2346: '<input type="checkbox" name="'.$context.'_'.$item.
2347: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2348: '</label></span> ';
2349: }
2350: }
2351: if ($context eq 'requestcourses') {
2352: $datatable .= '</tr><tr>';
2353: foreach my $item (@usertools) {
2354: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
2355: }
2356: $datatable .= '</tr></table>';
2357: }
2358: $datatable .= '</td>';
2359: unless (($context eq 'requestcourses') ||
2360: ($context eq 'requestauthor')) {
2361: $datatable .=
2362: '<td class="LC_right_item">'.
2363: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2364: '<input type="text" name="quota_'.$type.
2365: '" value="'.$currdefquota.
2366: '" size="5" /></span>'.(' ' x 2).
2367: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2368: '<input type="text" name="authorquota_'.$type.
2369: '" value="'.$currauthorquota.
2370: '" size="5" /></span></td>';
2371: }
2372: $datatable .= '</tr>';
2373: }
2374: }
2375: }
2376: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2377: $defaultquota = '20';
2378: $authorquota = '500';
2379: if (ref($settings) eq 'HASH') {
2380: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2381: $defaultquota = $settings->{'defaultquota'}->{'default'};
2382: } elsif (defined($settings->{'default'})) {
2383: $defaultquota = $settings->{'default'};
2384: }
2385: if (ref($settings->{'authorquota'}) eq 'HASH') {
2386: $authorquota = $settings->{'authorquota'}->{'default'};
2387: }
2388: }
2389: }
2390: $typecount ++;
2391: $css_class = $typecount%2?' class="LC_odd_row"':'';
2392: $datatable .= '<tr'.$css_class.'>'.
2393: '<td>'.$othertitle.'</td>'.
2394: '<td class="LC_left_item">';
2395: if ($context eq 'requestcourses') {
2396: $datatable .= '<table><tr>';
2397: }
2398: my %defcell;
2399: foreach my $item (@usertools) {
2400: if ($context eq 'requestcourses') {
2401: my ($curroption,$currlimit);
2402: if (ref($settings) eq 'HASH') {
2403: if (ref($settings->{$item}) eq 'HASH') {
2404: $curroption = $settings->{$item}->{'default'};
2405: if ($curroption =~ /^autolimit=(\d*)$/) {
2406: $currlimit = $1;
2407: }
2408: }
2409: }
2410: if (!$curroption) {
2411: $curroption = 'norequest';
2412: }
2413: $datatable .= '<th>'.$titles{$item}.'</th>';
2414: foreach my $option (@options) {
2415: my $val = $option;
2416: if ($option eq 'norequest') {
2417: $val = 0;
2418: }
2419: if ($option eq 'validate') {
2420: my $canvalidate = 0;
2421: if (ref($validations{$item}) eq 'HASH') {
2422: if ($validations{$item}{'default'}) {
2423: $canvalidate = 1;
2424: }
2425: }
2426: next if (!$canvalidate);
2427: }
2428: my $checked = '';
2429: if ($option eq $curroption) {
2430: $checked = ' checked="checked"';
2431: } elsif ($option eq 'autolimit') {
2432: if ($curroption =~ /^autolimit/) {
2433: $checked = ' checked="checked"';
2434: }
2435: }
2436: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2437: '<input type="radio" name="crsreq_'.$item.
2438: '_default" value="'.$val.'"'.$checked.' />'.
2439: $titles{$option}.'</label>';
2440: if ($option eq 'autolimit') {
2441: $defcell{$item} .= ' <input type="text" name="crsreq_'.
2442: $item.'_limit_default" size="1" '.
2443: 'value="'.$currlimit.'" />';
2444: }
2445: $defcell{$item} .= '</span> ';
2446: if ($option eq 'autolimit') {
2447: $defcell{$item} .= $titles{'unlimited'};
2448: }
2449: }
2450: } elsif ($context eq 'requestauthor') {
2451: my $curroption;
2452: if (ref($settings) eq 'HASH') {
2453: $curroption = $settings->{'default'};
2454: }
2455: if (!$curroption) {
2456: $curroption = 'norequest';
2457: }
2458: foreach my $option (@options) {
2459: my $val = $option;
2460: if ($option eq 'norequest') {
2461: $val = 0;
2462: }
2463: my $checked = '';
2464: if ($option eq $curroption) {
2465: $checked = ' checked="checked"';
2466: }
2467: $datatable .= '<span class="LC_nobreak"><label>'.
2468: '<input type="radio" name="authorreq_default"'.
2469: ' value="'.$val.'"'.$checked.' />'.
2470: $titles{$option}.'</label></span> ';
2471: }
2472: } else {
2473: my $checked = 'checked="checked" ';
2474: if (ref($settings) eq 'HASH') {
2475: if (ref($settings->{$item}) eq 'HASH') {
2476: if ($settings->{$item}->{'default'} == 0) {
2477: $checked = '';
2478: } elsif ($settings->{$item}->{'default'} == 1) {
2479: $checked = 'checked="checked" ';
2480: }
2481: }
2482: }
2483: $datatable .= '<span class="LC_nobreak"><label>'.
2484: '<input type="checkbox" name="'.$context.'_'.$item.
2485: '" value="default" '.$checked.'/>'.$titles{$item}.
2486: '</label></span> ';
2487: }
2488: }
2489: if ($context eq 'requestcourses') {
2490: $datatable .= '</tr><tr>';
2491: foreach my $item (@usertools) {
2492: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
2493: }
2494: $datatable .= '</tr></table>';
2495: }
2496: $datatable .= '</td>';
2497: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2498: $datatable .= '<td class="LC_right_item">'.
2499: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2500: '<input type="text" name="defaultquota" value="'.
2501: $defaultquota.'" size="5" /></span>'.(' ' x2).
2502: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2503: '<input type="text" name="authorquota" value="'.
2504: $authorquota.'" size="5" /></span></td>';
2505: }
2506: $datatable .= '</tr>';
2507: $typecount ++;
2508: $css_class = $typecount%2?' class="LC_odd_row"':'';
2509: $datatable .= '<tr'.$css_class.'>'.
2510: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
2511: if ($context eq 'requestcourses') {
2512: $datatable .= &mt('(overrides affiliation, if set)').
2513: '</td>'.
2514: '<td class="LC_left_item">'.
2515: '<table><tr>';
2516: } else {
2517: $datatable .= &mt('(overrides affiliation, if checked)').
2518: '</td>'.
2519: '<td class="LC_left_item" colspan="2">'.
2520: '<br />';
2521: }
2522: my %advcell;
2523: foreach my $item (@usertools) {
2524: if ($context eq 'requestcourses') {
2525: my ($curroption,$currlimit);
2526: if (ref($settings) eq 'HASH') {
2527: if (ref($settings->{$item}) eq 'HASH') {
2528: $curroption = $settings->{$item}->{'_LC_adv'};
2529: if ($curroption =~ /^autolimit=(\d*)$/) {
2530: $currlimit = $1;
2531: }
2532: }
2533: }
2534: $datatable .= '<th>'.$titles{$item}.'</th>';
2535: my $checked = '';
2536: if ($curroption eq '') {
2537: $checked = ' checked="checked"';
2538: }
2539: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2540: '<input type="radio" name="crsreq_'.$item.
2541: '__LC_adv" value=""'.$checked.' />'.
2542: &mt('No override set').'</label></span> ';
2543: foreach my $option (@options) {
2544: my $val = $option;
2545: if ($option eq 'norequest') {
2546: $val = 0;
2547: }
2548: if ($option eq 'validate') {
2549: my $canvalidate = 0;
2550: if (ref($validations{$item}) eq 'HASH') {
2551: if ($validations{$item}{'_LC_adv'}) {
2552: $canvalidate = 1;
2553: }
2554: }
2555: next if (!$canvalidate);
2556: }
2557: my $checked = '';
2558: if ($val eq $curroption) {
2559: $checked = ' checked="checked"';
2560: } elsif ($option eq 'autolimit') {
2561: if ($curroption =~ /^autolimit/) {
2562: $checked = ' checked="checked"';
2563: }
2564: }
2565: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2566: '<input type="radio" name="crsreq_'.$item.
2567: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2568: $titles{$option}.'</label>';
2569: if ($option eq 'autolimit') {
2570: $advcell{$item} .= ' <input type="text" name="crsreq_'.
2571: $item.'_limit__LC_adv" size="1" '.
2572: 'value="'.$currlimit.'" />';
2573: }
2574: $advcell{$item} .= '</span> ';
2575: if ($option eq 'autolimit') {
2576: $advcell{$item} .= $titles{'unlimited'};
2577: }
2578: }
2579: } elsif ($context eq 'requestauthor') {
2580: my $curroption;
2581: if (ref($settings) eq 'HASH') {
2582: $curroption = $settings->{'_LC_adv'};
2583: }
2584: my $checked = '';
2585: if ($curroption eq '') {
2586: $checked = ' checked="checked"';
2587: }
2588: $datatable .= '<span class="LC_nobreak"><label>'.
2589: '<input type="radio" name="authorreq__LC_adv"'.
2590: ' value=""'.$checked.' />'.
2591: &mt('No override set').'</label></span> ';
2592: foreach my $option (@options) {
2593: my $val = $option;
2594: if ($option eq 'norequest') {
2595: $val = 0;
2596: }
2597: my $checked = '';
2598: if ($val eq $curroption) {
2599: $checked = ' checked="checked"';
2600: }
2601: $datatable .= '<span class="LC_nobreak"><label>'.
2602: '<input type="radio" name="authorreq__LC_adv"'.
2603: ' value="'.$val.'"'.$checked.' />'.
2604: $titles{$option}.'</label></span> ';
2605: }
2606: } else {
2607: my $checked = 'checked="checked" ';
2608: if (ref($settings) eq 'HASH') {
2609: if (ref($settings->{$item}) eq 'HASH') {
2610: if ($settings->{$item}->{'_LC_adv'} == 0) {
2611: $checked = '';
2612: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2613: $checked = 'checked="checked" ';
2614: }
2615: }
2616: }
2617: $datatable .= '<span class="LC_nobreak"><label>'.
2618: '<input type="checkbox" name="'.$context.'_'.$item.
2619: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2620: '</label></span> ';
2621: }
2622: }
2623: if ($context eq 'requestcourses') {
2624: $datatable .= '</tr><tr>';
2625: foreach my $item (@usertools) {
2626: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2627: }
2628: $datatable .= '</tr></table>';
2629: }
2630: $datatable .= '</td></tr>';
2631: $$rowtotal += $typecount;
2632: return $datatable;
2633: }
2634:
2635: sub print_requestmail {
2636: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
2637: my ($now,$datatable,%currapp);
2638: $now = time;
2639: if (ref($settings) eq 'HASH') {
2640: if (ref($settings->{'notify'}) eq 'HASH') {
2641: if ($settings->{'notify'}{'approval'} ne '') {
2642: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2643: }
2644: }
2645: }
2646: my $numinrow = 2;
2647: my $css_class;
2648: if ($$rowtotal%2) {
2649: $css_class = 'LC_odd_row';
2650: }
2651: if ($customcss) {
2652: $css_class .= " $customcss";
2653: }
2654: $css_class =~ s/^\s+//;
2655: if ($css_class) {
2656: $css_class = ' class="'.$css_class.'"';
2657: }
2658: if ($rowstyle) {
2659: $css_class .= ' style="'.$rowstyle.'"';
2660: }
2661: my $text;
2662: if ($action eq 'requestcourses') {
2663: $text = &mt('Receive notification of course requests requiring approval');
2664: } elsif ($action eq 'requestauthor') {
2665: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2666: } else {
2667: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2668: }
2669: $datatable = '<tr'.$css_class.'>'.
2670: ' <td>'.$text.'</td>'.
2671: ' <td class="LC_left_item">';
2672: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2673: $action.'notifyapproval',%currapp);
2674: if ($numdc > 0) {
2675: $datatable .= $table;
2676: } else {
2677: $datatable .= &mt('There are no active Domain Coordinators');
2678: }
2679: $datatable .='</td></tr>';
2680: return $datatable;
2681: }
2682:
2683: sub print_studentcode {
2684: my ($settings,$rowtotal) = @_;
2685: my $rownum = 0;
2686: my ($output,%current);
2687: my @crstypes = ('official','unofficial','community','textbook');
2688: if (ref($settings) eq 'HASH') {
2689: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2690: foreach my $type (@crstypes) {
2691: $current{$type} = $settings->{'uniquecode'}{$type};
2692: }
2693: }
2694: }
2695: $output .= '<tr>'.
2696: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2697: '<td class="LC_left_item">';
2698: foreach my $type (@crstypes) {
2699: my $check = ' ';
2700: if ($current{$type}) {
2701: $check = ' checked="checked" ';
2702: }
2703: $output .= '<span class="LC_nobreak"><label>'.
2704: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2705: &mt($type).'</label></span>'.(' 'x2).' ';
2706: }
2707: $output .= '</td></tr>';
2708: $$rowtotal ++;
2709: return $output;
2710: }
2711:
2712: sub print_textbookcourses {
2713: my ($dom,$type,$settings,$rowtotal) = @_;
2714: my $rownum = 0;
2715: my $css_class;
2716: my $itemcount = 1;
2717: my $maxnum = 0;
2718: my $bookshash;
2719: if (ref($settings) eq 'HASH') {
2720: $bookshash = $settings->{$type};
2721: }
2722: my %ordered;
2723: if (ref($bookshash) eq 'HASH') {
2724: foreach my $item (keys(%{$bookshash})) {
2725: if (ref($bookshash->{$item}) eq 'HASH') {
2726: my $num = $bookshash->{$item}{'order'};
2727: $ordered{$num} = $item;
2728: }
2729: }
2730: }
2731: my $confname = $dom.'-domainconfig';
2732: my $switchserver = &check_switchserver($dom,$confname);
2733: my $maxnum = scalar(keys(%ordered));
2734: my $datatable;
2735: if (keys(%ordered)) {
2736: my @items = sort { $a <=> $b } keys(%ordered);
2737: for (my $i=0; $i<@items; $i++) {
2738: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2739: my $key = $ordered{$items[$i]};
2740: my %coursehash=&Apache::lonnet::coursedescription($key);
2741: my $coursetitle = $coursehash{'description'};
2742: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2743: if (ref($bookshash->{$key}) eq 'HASH') {
2744: $subject = $bookshash->{$key}->{'subject'};
2745: $title = $bookshash->{$key}->{'title'};
2746: if ($type eq 'textbooks') {
2747: $publisher = $bookshash->{$key}->{'publisher'};
2748: $author = $bookshash->{$key}->{'author'};
2749: $image = $bookshash->{$key}->{'image'};
2750: if ($image ne '') {
2751: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2752: my $imagethumb = "$path/tn-".$imagefile;
2753: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2754: }
2755: }
2756: }
2757: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2758: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2759: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2760: for (my $k=0; $k<=$maxnum; $k++) {
2761: my $vpos = $k+1;
2762: my $selstr;
2763: if ($k == $i) {
2764: $selstr = ' selected="selected" ';
2765: }
2766: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2767: }
2768: $datatable .= '</select>'.(' 'x2).
2769: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2770: &mt('Delete?').'</label></span></td>'.
2771: '<td colspan="2">'.
2772: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2773: (' 'x2).
2774: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2775: if ($type eq 'textbooks') {
2776: $datatable .= (' 'x2).
2777: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2778: (' 'x2).
2779: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2780: (' 'x2).
2781: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2782: if ($image) {
2783: $datatable .= $imgsrc.
2784: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2785: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2786: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2787: }
2788: if ($switchserver) {
2789: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2790: } else {
2791: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2792: }
2793: }
2794: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2795: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2796: $coursetitle.'</span></td></tr>'."\n";
2797: $itemcount ++;
2798: }
2799: }
2800: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2801: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2802: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2803: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2804: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2805: for (my $k=0; $k<$maxnum+1; $k++) {
2806: my $vpos = $k+1;
2807: my $selstr;
2808: if ($k == $maxnum) {
2809: $selstr = ' selected="selected" ';
2810: }
2811: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2812: }
2813: $datatable .= '</select> '."\n".
2814: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
2815: '<td colspan="2">'.
2816: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2817: (' 'x2).
2818: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2819: (' 'x2);
2820: if ($type eq 'textbooks') {
2821: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2822: (' 'x2).
2823: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2824: (' 'x2).
2825: '<span class="LC_nobreak">'.&mt('Image:').' ';
2826: if ($switchserver) {
2827: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2828: } else {
2829: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2830: }
2831: $datatable .= '</span>'."\n";
2832: }
2833: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2834: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2835: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2836: &Apache::loncommon::selectcourse_link
2837: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
2838: '</span></td>'."\n".
2839: '</tr>'."\n";
2840: $itemcount ++;
2841: return $datatable;
2842: }
2843:
2844: sub textbookcourses_javascript {
2845: my ($settings) = @_;
2846: return unless(ref($settings) eq 'HASH');
2847: my (%ordered,%total,%jstext);
2848: foreach my $type ('textbooks','templates') {
2849: $total{$type} = 0;
2850: if (ref($settings->{$type}) eq 'HASH') {
2851: foreach my $item (keys(%{$settings->{$type}})) {
2852: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2853: my $num = $settings->{$type}->{$item}{'order'};
2854: $ordered{$type}{$num} = $item;
2855: }
2856: }
2857: $total{$type} = scalar(keys(%{$settings->{$type}}));
2858: }
2859: my @jsarray = ();
2860: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2861: push(@jsarray,$ordered{$type}{$item});
2862: }
2863: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2864: }
2865: return <<"ENDSCRIPT";
2866: <script type="text/javascript">
2867: // <![CDATA[
2868: function reorderBooks(form,item,caller) {
2869: var changedVal;
2870: $jstext{'textbooks'};
2871: $jstext{'templates'};
2872: var newpos;
2873: var maxh;
2874: if (caller == 'textbooks') {
2875: newpos = 'textbooks_addbook_pos';
2876: maxh = 1 + $total{'textbooks'};
2877: } else {
2878: newpos = 'templates_addbook_pos';
2879: maxh = 1 + $total{'templates'};
2880: }
2881: var current = new Array;
2882: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2883: if (item == newpos) {
2884: changedVal = newitemVal;
2885: } else {
2886: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2887: current[newitemVal] = newpos;
2888: }
2889: if (caller == 'textbooks') {
2890: for (var i=0; i<textbooks.length; i++) {
2891: var elementName = 'textbooks_'+textbooks[i];
2892: if (elementName != item) {
2893: if (form.elements[elementName]) {
2894: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2895: current[currVal] = elementName;
2896: }
2897: }
2898: }
2899: }
2900: if (caller == 'templates') {
2901: for (var i=0; i<templates.length; i++) {
2902: var elementName = 'templates_'+templates[i];
2903: if (elementName != item) {
2904: if (form.elements[elementName]) {
2905: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2906: current[currVal] = elementName;
2907: }
2908: }
2909: }
2910: }
2911: var oldVal;
2912: for (var j=0; j<maxh; j++) {
2913: if (current[j] == undefined) {
2914: oldVal = j;
2915: }
2916: }
2917: if (oldVal < changedVal) {
2918: for (var k=oldVal+1; k<=changedVal ; k++) {
2919: var elementName = current[k];
2920: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2921: }
2922: } else {
2923: for (var k=changedVal; k<oldVal; k++) {
2924: var elementName = current[k];
2925: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2926: }
2927: }
2928: return;
2929: }
2930:
2931: // ]]>
2932: </script>
2933:
2934: ENDSCRIPT
2935: }
2936:
2937: sub ltitools_javascript {
2938: my ($settings) = @_;
2939: my $togglejs = <itools_toggle_js();
2940: unless (ref($settings) eq 'HASH') {
2941: return $togglejs;
2942: }
2943: my (%ordered,$total,%jstext);
2944: $total = 0;
2945: foreach my $item (keys(%{$settings})) {
2946: if (ref($settings->{$item}) eq 'HASH') {
2947: my $num = $settings->{$item}{'order'};
2948: $ordered{$num} = $item;
2949: }
2950: }
2951: $total = scalar(keys(%{$settings}));
2952: my @jsarray = ();
2953: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2954: push(@jsarray,$ordered{$item});
2955: }
2956: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2957: return <<"ENDSCRIPT";
2958: <script type="text/javascript">
2959: // <![CDATA[
2960: function reorderLTITools(form,item) {
2961: var changedVal;
2962: $jstext
2963: var newpos = 'ltitools_add_pos';
2964: var maxh = 1 + $total;
2965: var current = new Array;
2966: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2967: if (item == newpos) {
2968: changedVal = newitemVal;
2969: } else {
2970: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2971: current[newitemVal] = newpos;
2972: }
2973: for (var i=0; i<ltitools.length; i++) {
2974: var elementName = 'ltitools_'+ltitools[i];
2975: if (elementName != item) {
2976: if (form.elements[elementName]) {
2977: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2978: current[currVal] = elementName;
2979: }
2980: }
2981: }
2982: var oldVal;
2983: for (var j=0; j<maxh; j++) {
2984: if (current[j] == undefined) {
2985: oldVal = j;
2986: }
2987: }
2988: if (oldVal < changedVal) {
2989: for (var k=oldVal+1; k<=changedVal ; k++) {
2990: var elementName = current[k];
2991: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2992: }
2993: } else {
2994: for (var k=changedVal; k<oldVal; k++) {
2995: var elementName = current[k];
2996: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2997: }
2998: }
2999: return;
3000: }
3001:
3002: // ]]>
3003: </script>
3004:
3005: $togglejs
3006:
3007: ENDSCRIPT
3008: }
3009:
3010: sub ltitools_toggle_js {
3011: return <<"ENDSCRIPT";
3012: <script type="text/javascript">
3013: // <![CDATA[
3014:
3015: function toggleLTITools(form,setting,item) {
3016: var radioname = '';
3017: var divid = '';
3018: if (setting == 'user') {
3019: divid = 'ltitools_'+setting+'_div_'+item;
3020: var checkid = 'ltitools_'+setting+'_field_'+item;
3021: if (document.getElementById(divid)) {
3022: if (document.getElementById(checkid)) {
3023: if (document.getElementById(checkid).checked) {
3024: document.getElementById(divid).style.display = 'inline-block';
3025: } else {
3026: document.getElementById(divid).style.display = 'none';
3027: }
3028: }
3029: }
3030: }
3031: return;
3032: }
3033: // ]]>
3034: </script>
3035:
3036: ENDSCRIPT
3037: }
3038:
3039: sub wafproxy_javascript {
3040: my ($dom) = @_;
3041: return <<"ENDSCRIPT";
3042: <script type="text/javascript">
3043: // <![CDATA[
3044: function updateWAF() {
3045: if (document.getElementById('wafproxy_remoteip')) {
3046: var wafremote = 0;
3047: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3048: wafremote = 1;
3049: }
3050: var fields = new Array('header','trust');
3051: for (var i=0; i<fields.length; i++) {
3052: if (document.getElementById('wafproxy_'+fields[i])) {
3053: if (wafremote == 1) {
3054: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3055: }
3056: else {
3057: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3058: }
3059: }
3060: }
3061: if (document.getElementById('wafproxyranges_$dom')) {
3062: if (wafremote == 1) {
3063: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3064: } else {
3065: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3066: if (document.display.wafproxy_vpnaccess[i].checked) {
3067: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3068: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3069: }
3070: }
3071: }
3072: }
3073: }
3074: }
3075: return;
3076: }
3077:
3078: function checkWAF() {
3079: if (document.getElementById('wafproxy_remoteip')) {
3080: var wafvpn = 0;
3081: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3082: if (document.display.wafproxy_vpnaccess[i].checked) {
3083: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3084: wafvpn = 1;
3085: }
3086: break;
3087: }
3088: }
3089: var vpn = new Array('vpnint','vpnext');
3090: for (var i=0; i<vpn.length; i++) {
3091: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3092: if (wafvpn == 1) {
3093: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3094: }
3095: else {
3096: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3097: }
3098: }
3099: }
3100: if (document.getElementById('wafproxyranges_$dom')) {
3101: if (wafvpn == 1) {
3102: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3103: }
3104: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3105: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3106: }
3107: }
3108: }
3109: return;
3110: }
3111:
3112: function toggleWAF() {
3113: if (document.getElementById('wafproxy_table')) {
3114: var wafproxy = 0;
3115: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3116: if (document.display.wafproxy_${dom}[i].checked) {
3117: if (document.display.wafproxy_${dom}[i].value == 1) {
3118: wafproxy = 1;
3119: break;
3120: }
3121: }
3122: }
3123: if (wafproxy == 1) {
3124: document.getElementById('wafproxy_table').style.display='inline';
3125: }
3126: else {
3127: document.getElementById('wafproxy_table').style.display='none';
3128: }
3129: if (document.getElementById('wafproxyrow_${dom}')) {
3130: if (wafproxy == 1) {
3131: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3132: }
3133: else {
3134: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3135: }
3136: }
3137: if (document.getElementById('nowafproxyrow_$dom')) {
3138: if (wafproxy == 1) {
3139: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3140: }
3141: else {
3142: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3143: }
3144: }
3145: }
3146: return;
3147: }
3148: // ]]>
3149: </script>
3150:
3151: ENDSCRIPT
3152: }
3153:
3154: sub lti_javascript {
3155: my ($dom,$settings) = @_;
3156: my $togglejs = <i_toggle_js($dom);
3157: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
3158: return <<"ENDSCRIPT";
3159: <script type="text/javascript">
3160: // <![CDATA[
3161:
3162: $linkprot_js
3163:
3164: // ]]>
3165: </script>
3166:
3167: $togglejs
3168:
3169: ENDSCRIPT
3170: }
3171:
3172: sub lti_toggle_js {
3173: my ($dom) = @_;
3174: my %servers = &Apache::lonnet::get_servers($dom,'library');
3175: my $primary = &Apache::lonnet::domain($dom,'primary');
3176: my $course_servers = "'".join("','",keys(%servers))."'";
3177: return <<"ENDSCRIPT";
3178: <script type="text/javascript">
3179: // <![CDATA[
3180: function toggleLTIEncKey(form) {
3181: var shownhosts = new Array();
3182: var hiddenhosts = new Array();
3183: var forcourse = new Array($course_servers);
3184: var fromdomain = '$primary';
3185: var crsradio = form.elements['ltisec_crslinkprot'];
3186: if (crsradio.length) {
3187: for (var i=0; i<crsradio.length; i++) {
3188: if (crsradio[i].checked) {
3189: if (crsradio[i].value == 1) {
3190: if (forcourse.length > 0) {
3191: for (var j=0; j<forcourse.length; j++) {
3192: if (!shownhosts.includes(forcourse[j])) {
3193: shownhosts.push(forcourse[j]);
3194: }
3195: }
3196: }
3197: } else {
3198: if (forcourse.length > 0) {
3199: for (var j=0; j<forcourse.length; j++) {
3200: if (!hiddenhosts.includes(forcourse[j])) {
3201: hiddenhosts.push(forcourse[j]);
3202: }
3203: }
3204: }
3205: }
3206: }
3207: }
3208: }
3209: var domradio = form.elements['ltisec_domlinkprot'];
3210: if (domradio.length) {
3211: for (var i=0; i<domradio.length; i++) {
3212: if (domradio[i].checked) {
3213: if (domradio[i].value == 1) {
3214: if (!shownhosts.includes(fromdomain)) {
3215: shownhosts.push(fromdomain);
3216: }
3217: } else {
3218: if (!hiddenhosts.includes(fromdomain)) {
3219: hiddenhosts.push(fromdomain);
3220: }
3221: }
3222: }
3223: }
3224: }
3225: if (shownhosts.length > 0) {
3226: for (var i=0; i<shownhosts.length; i++) {
3227: if (document.getElementById('ltisec_info_'+shownhosts[i])) {
3228: document.getElementById('ltisec_info_'+shownhosts[i]).style.display = 'block';
3229: }
3230: }
3231: if (document.getElementById('ltisec_noprivkey')) {
3232: document.getElementById('ltisec_noprivkey').style.display = 'none';
3233: }
3234: } else {
3235: if (document.getElementById('ltisec_noprivkey')) {
3236: document.getElementById('ltisec_noprivkey').style.display = 'inline-block';
3237: }
3238: }
3239: if (hiddenhosts.length > 0) {
3240: for (var i=0; i<hiddenhosts.length; i++) {
3241: if (!shownhosts.includes(hiddenhosts[i])) {
3242: if (document.getElementById('ltisec_info_'+hiddenhosts[i])) {
3243: document.getElementById('ltisec_info_'+hiddenhosts[i]).style.display = 'none';
3244: }
3245: }
3246: }
3247: }
3248: return;
3249: }
3250:
3251: function togglePrivKey(form,hostid) {
3252: var radioname = '';
3253: var currdivid = '';
3254: var newdivid = '';
3255: if ((document.getElementById('ltisec_divcurrprivkey_'+hostid)) &&
3256: (document.getElementById('ltisec_divchgprivkey_'+hostid))) {
3257: currdivid = document.getElementById('ltisec_divcurrprivkey_'+hostid);
3258: newdivid = document.getElementById('ltisec_divchgprivkey_'+hostid);
3259: radioname = form.elements['ltisec_changeprivkey_'+hostid];
3260: if (radioname) {
3261: if (radioname.length > 0) {
3262: var setvis;
3263: for (var i=0; i<radioname.length; i++) {
3264: if (radioname[i].checked == true) {
3265: if (radioname[i].value == 1) {
3266: newdivid.style.display = 'inline-block';
3267: currdivid.style.display = 'none';
3268: setvis = 1;
3269: }
3270: break;
3271: }
3272: }
3273: if (!setvis) {
3274: newdivid.style.display = 'none';
3275: currdivid.style.display = 'inline-block';
3276: }
3277: }
3278: }
3279: }
3280: }
3281:
3282: // ]]>
3283: </script>
3284:
3285: ENDSCRIPT
3286: }
3287:
3288: sub autoupdate_javascript {
3289: return <<"ENDSCRIPT";
3290: <script type="text/javascript">
3291: // <![CDATA[
3292: function toggleLastActiveDays(form) {
3293: var radioname = 'lastactive';
3294: var divid = 'lastactive_div';
3295: var num = form.elements[radioname].length;
3296: if (num) {
3297: var setvis = '';
3298: for (var i=0; i<num; i++) {
3299: if (form.elements[radioname][i].checked) {
3300: if (form.elements[radioname][i].value == '1') {
3301: if (document.getElementById(divid)) {
3302: document.getElementById(divid).style.display = 'inline-block';
3303: }
3304: setvis = 1;
3305: }
3306: break;
3307: }
3308: }
3309: if (!setvis) {
3310: if (document.getElementById(divid)) {
3311: document.getElementById(divid).style.display = 'none';
3312: }
3313: }
3314: }
3315: return;
3316: }
3317: // ]]>
3318: </script>
3319:
3320: ENDSCRIPT
3321: }
3322:
3323: sub autoenroll_javascript {
3324: return <<"ENDSCRIPT";
3325: <script type="text/javascript">
3326: // <![CDATA[
3327: function toggleFailsafe(form) {
3328: var radioname = 'autoenroll_failsafe';
3329: var divid = 'autoenroll_failsafe_div';
3330: var num = form.elements[radioname].length;
3331: if (num) {
3332: var setvis = '';
3333: for (var i=0; i<num; i++) {
3334: if (form.elements[radioname][i].checked) {
3335: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3336: if (document.getElementById(divid)) {
3337: document.getElementById(divid).style.display = 'inline-block';
3338: }
3339: setvis = 1;
3340: }
3341: break;
3342: }
3343: }
3344: if (!setvis) {
3345: if (document.getElementById(divid)) {
3346: document.getElementById(divid).style.display = 'none';
3347: }
3348: }
3349: }
3350: return;
3351: }
3352: // ]]>
3353: </script>
3354:
3355: ENDSCRIPT
3356: }
3357:
3358: sub saml_javascript {
3359: return <<"ENDSCRIPT";
3360: <script type="text/javascript">
3361: // <![CDATA[
3362: function toggleSamlOptions(form,hostid) {
3363: var radioname = 'saml_'+hostid;
3364: var tablecellon = 'samloptionson_'+hostid;
3365: var tablecelloff = 'samloptionsoff_'+hostid;
3366: var num = form.elements[radioname].length;
3367: if (num) {
3368: var setvis = '';
3369: for (var i=0; i<num; i++) {
3370: if (form.elements[radioname][i].checked) {
3371: if (form.elements[radioname][i].value == '1') {
3372: if (document.getElementById(tablecellon)) {
3373: document.getElementById(tablecellon).style.display='';
3374: }
3375: if (document.getElementById(tablecelloff)) {
3376: document.getElementById(tablecelloff).style.display='none';
3377: }
3378: setvis = 1;
3379: }
3380: break;
3381: }
3382: }
3383: if (!setvis) {
3384: if (document.getElementById(tablecellon)) {
3385: document.getElementById(tablecellon).style.display='none';
3386: }
3387: if (document.getElementById(tablecelloff)) {
3388: document.getElementById(tablecelloff).style.display='';
3389: }
3390: }
3391: }
3392: return;
3393: }
3394: // ]]>
3395: </script>
3396:
3397: ENDSCRIPT
3398: }
3399:
3400: sub ipaccess_javascript {
3401: my ($settings) = @_;
3402: my (%ordered,$total,%jstext);
3403: $total = 0;
3404: if (ref($settings) eq 'HASH') {
3405: foreach my $item (keys(%{$settings})) {
3406: if (ref($settings->{$item}) eq 'HASH') {
3407: my $num = $settings->{$item}{'order'};
3408: $ordered{$num} = $item;
3409: }
3410: }
3411: $total = scalar(keys(%{$settings}));
3412: }
3413: my @jsarray = ();
3414: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3415: push(@jsarray,$ordered{$item});
3416: }
3417: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3418: return <<"ENDSCRIPT";
3419: <script type="text/javascript">
3420: // <![CDATA[
3421: function reorderIPaccess(form,item) {
3422: var changedVal;
3423: $jstext
3424: var newpos = 'ipaccess_pos_add';
3425: var maxh = 1 + $total;
3426: var current = new Array;
3427: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3428: if (item == newpos) {
3429: changedVal = newitemVal;
3430: } else {
3431: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3432: current[newitemVal] = newpos;
3433: }
3434: for (var i=0; i<ipaccess.length; i++) {
3435: var elementName = 'ipaccess_pos_'+ipaccess[i];
3436: if (elementName != item) {
3437: if (form.elements[elementName]) {
3438: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3439: current[currVal] = elementName;
3440: }
3441: }
3442: }
3443: var oldVal;
3444: for (var j=0; j<maxh; j++) {
3445: if (current[j] == undefined) {
3446: oldVal = j;
3447: }
3448: }
3449: if (oldVal < changedVal) {
3450: for (var k=oldVal+1; k<=changedVal ; k++) {
3451: var elementName = current[k];
3452: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3453: }
3454: } else {
3455: for (var k=changedVal; k<oldVal; k++) {
3456: var elementName = current[k];
3457: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3458: }
3459: }
3460: return;
3461: }
3462: // ]]>
3463: </script>
3464:
3465: ENDSCRIPT
3466: }
3467:
3468: sub print_autoenroll {
3469: my ($dom,$settings,$rowtotal) = @_;
3470: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
3471: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3472: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3473: $failsafesty = 'none';
3474: %failsafechecked = (
3475: off => ' checked="checked"',
3476: );
3477: if (ref($settings) eq 'HASH') {
3478: if (exists($settings->{'run'})) {
3479: if ($settings->{'run'} eq '0') {
3480: $runoff = ' checked="checked" ';
3481: $runon = ' ';
3482: } else {
3483: $runon = ' checked="checked" ';
3484: $runoff = ' ';
3485: }
3486: } else {
3487: if ($autorun) {
3488: $runon = ' checked="checked" ';
3489: $runoff = ' ';
3490: } else {
3491: $runoff = ' checked="checked" ';
3492: $runon = ' ';
3493: }
3494: }
3495: if (exists($settings->{'co-owners'})) {
3496: if ($settings->{'co-owners'} eq '0') {
3497: $coownersoff = ' checked="checked" ';
3498: $coownerson = ' ';
3499: } else {
3500: $coownerson = ' checked="checked" ';
3501: $coownersoff = ' ';
3502: }
3503: } else {
3504: $coownersoff = ' checked="checked" ';
3505: $coownerson = ' ';
3506: }
3507: if (exists($settings->{'sender_domain'})) {
3508: $defdom = $settings->{'sender_domain'};
3509: }
3510: if (exists($settings->{'failsafe'})) {
3511: $failsafe = $settings->{'failsafe'};
3512: if ($failsafe eq 'zero') {
3513: $failsafechecked{'zero'} = ' checked="checked"';
3514: $failsafechecked{'off'} = '';
3515: $failsafesty = 'inline-block';
3516: } elsif ($failsafe eq 'any') {
3517: $failsafechecked{'any'} = ' checked="checked"';
3518: $failsafechecked{'off'} = '';
3519: }
3520: $autofailsafe = $settings->{'autofailsafe'};
3521: } elsif (exists($settings->{'autofailsafe'})) {
3522: $autofailsafe = $settings->{'autofailsafe'};
3523: if ($autofailsafe ne '') {
3524: $failsafechecked{'zero'} = ' checked="checked"';
3525: $failsafe = 'zero';
3526: $failsafechecked{'off'} = '';
3527: }
3528: }
3529: } else {
3530: if ($autorun) {
3531: $runon = ' checked="checked" ';
3532: $runoff = ' ';
3533: } else {
3534: $runoff = ' checked="checked" ';
3535: $runon = ' ';
3536: }
3537: }
3538: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
3539: my $notif_sender;
3540: if (ref($settings) eq 'HASH') {
3541: $notif_sender = $settings->{'sender_uname'};
3542: }
3543: my $datatable='<tr class="LC_odd_row">'.
3544: '<td>'.&mt('Auto-enrollment active?').'</td>'.
3545: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3546: '<input type="radio" name="autoenroll_run"'.
3547: $runon.' value="1" />'.&mt('Yes').'</label> '.
3548: '<label><input type="radio" name="autoenroll_run"'.
3549: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
3550: '</tr><tr>'.
3551: '<td>'.&mt('Notification messages - sender').
3552: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
3553: &mt('username').': '.
3554: '<input type="text" name="sender_uname" value="'.
3555: $notif_sender.'" size="10" /> '.&mt('domain').
3556: ': '.$domform.'</span></td></tr>'.
3557: '<tr class="LC_odd_row">'.
3558: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3559: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3560: '<input type="radio" name="autoassign_coowners"'.
3561: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3562: '<label><input type="radio" name="autoassign_coowners"'.
3563: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
3564: '</tr><tr>'.
3565: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3566: '<td class="LC_left_item"><span class="LC_nobreak">'.
3567: '<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> '.
3568: '<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 />'.
3569: '<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>'.
3570: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3571: '<span class="LC_nobreak">'.
3572: &mt('Threshold for number of students in section to drop: [_1]',
3573: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3574: '</span></div></td></tr>';
3575: $$rowtotal += 4;
3576: return $datatable;
3577: }
3578:
3579: sub print_autoupdate {
3580: my ($position,$dom,$settings,$rowtotal) = @_;
3581: my ($enable,$datatable);
3582: if ($position eq 'top') {
3583: my %choices = &Apache::lonlocal::texthash (
3584: run => 'Auto-update active?',
3585: classlists => 'Update information in classlists?',
3586: unexpired => 'Skip updates for users without active or future roles?',
3587: lastactive => 'Skip updates for inactive users?',
3588: );
3589: my $itemcount = 0;
3590: my $updateon = ' ';
3591: my $updateoff = ' checked="checked" ';
3592: if (ref($settings) eq 'HASH') {
3593: if ($settings->{'run'} eq '1') {
3594: $updateon = $updateoff;
3595: $updateoff = ' ';
3596: }
3597: }
3598: $enable = '<tr class="LC_odd_row">'.
3599: '<td>'.&mt($choices{'run'}).'</td>'.
3600: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3601: '<input type="radio" name="autoupdate_run"'.
3602: $updateoff.'value="0" />'.&mt('No').'</label> '.
3603: '<label><input type="radio" name="autoupdate_run"'.
3604: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
3605: '</tr>';
3606: my @toggles = ('classlists','unexpired');
3607: my %defaultchecked = ('classlists' => 'off',
3608: 'unexpired' => 'off'
3609: );
3610: $$rowtotal ++;
3611: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3612: \%choices,$itemcount,'','','left','no');
3613: $datatable = $enable.$datatable;
3614: $$rowtotal += $itemcount;
3615: my $lastactiveon = ' ';
3616: my $lastactiveoff = ' checked="checked" ';
3617: my $lastactivestyle = 'none';
3618: my $lastactivedays;
3619: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3620: if (ref($settings) eq 'HASH') {
3621: if ($settings->{'lastactive'} =~ /^\d+$/) {
3622: $lastactiveon = $lastactiveoff;
3623: $lastactiveoff = ' ';
3624: $lastactivestyle = 'inline-block';
3625: $lastactivedays = $settings->{'lastactive'};
3626: }
3627: }
3628: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3629: $datatable .= '<tr'.$css_class.'>'.
3630: '<td>'.$choices{'lastactive'}.'</td>'.
3631: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3632: '<input type="radio" name="lastactive"'.
3633: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3634: ' <label>'.
3635: '<input type="radio" name="lastactive"'.
3636: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3637: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3638: ': '.&mt('inactive = no activity in last [_1] days',
3639: '<input type="text" size="5" name="lastactivedays" value="'.
3640: $lastactivedays.'" />').
3641: '</span></td>'.
3642: '</tr>';
3643: $$rowtotal ++;
3644: } elsif ($position eq 'middle') {
3645: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3646: my $numinrow = 3;
3647: my $locknamesettings;
3648: $datatable .= &insttypes_row($settings,$types,$usertypes,
3649: $dom,$numinrow,$othertitle,
3650: 'lockablenames',$rowtotal);
3651: $$rowtotal ++;
3652: } else {
3653: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3654: my @fields = ('lastname','firstname','middlename','generation',
3655: 'permanentemail','id');
3656: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3657: my $numrows = 0;
3658: if (ref($types) eq 'ARRAY') {
3659: if (@{$types} > 0) {
3660: $datatable =
3661: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3662: \@fields,$types,\$numrows);
3663: $$rowtotal += @{$types};
3664: }
3665: }
3666: $datatable .=
3667: &usertype_update_row($settings,{'default' => $othertitle},
3668: \%fieldtitles,\@fields,['default'],
3669: \$numrows);
3670: $$rowtotal ++;
3671: }
3672: return $datatable;
3673: }
3674:
3675: sub print_autocreate {
3676: my ($dom,$settings,$rowtotal) = @_;
3677: my (%createon,%createoff,%currhash);
3678: my @types = ('xml','req');
3679: if (ref($settings) eq 'HASH') {
3680: foreach my $item (@types) {
3681: $createoff{$item} = ' checked="checked" ';
3682: $createon{$item} = ' ';
3683: if (exists($settings->{$item})) {
3684: if ($settings->{$item}) {
3685: $createon{$item} = ' checked="checked" ';
3686: $createoff{$item} = ' ';
3687: }
3688: }
3689: }
3690: if ($settings->{'xmldc'} ne '') {
3691: $currhash{$settings->{'xmldc'}} = 1;
3692: }
3693: } else {
3694: foreach my $item (@types) {
3695: $createoff{$item} = ' checked="checked" ';
3696: $createon{$item} = ' ';
3697: }
3698: }
3699: $$rowtotal += 2;
3700: my $numinrow = 2;
3701: my $datatable='<tr class="LC_odd_row">'.
3702: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3703: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3704: '<input type="radio" name="autocreate_xml"'.
3705: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3706: '<label><input type="radio" name="autocreate_xml"'.
3707: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3708: '</td></tr><tr>'.
3709: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3710: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3711: '<input type="radio" name="autocreate_req"'.
3712: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3713: '<label><input type="radio" name="autocreate_req"'.
3714: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
3715: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3716: 'autocreate_xmldc',%currhash);
3717: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
3718: if ($numdc > 1) {
3719: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3720: '</td><td class="LC_left_item">';
3721: } else {
3722: $datatable .= &mt('Course creation processed as:').
3723: '</td><td class="LC_right_item">';
3724: }
3725: $datatable .= $dctable.'</td></tr>';
3726: $$rowtotal += $rows;
3727: return $datatable;
3728: }
3729:
3730: sub print_directorysrch {
3731: my ($position,$dom,$settings,$rowtotal) = @_;
3732: my $datatable;
3733: if ($position eq 'top') {
3734: my $instsrchon = ' ';
3735: my $instsrchoff = ' checked="checked" ';
3736: my ($exacton,$containson,$beginson);
3737: my $instlocalon = ' ';
3738: my $instlocaloff = ' checked="checked" ';
3739: if (ref($settings) eq 'HASH') {
3740: if ($settings->{'available'} eq '1') {
3741: $instsrchon = $instsrchoff;
3742: $instsrchoff = ' ';
3743: }
3744: if ($settings->{'localonly'} eq '1') {
3745: $instlocalon = $instlocaloff;
3746: $instlocaloff = ' ';
3747: }
3748: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3749: foreach my $type (@{$settings->{'searchtypes'}}) {
3750: if ($type eq 'exact') {
3751: $exacton = ' checked="checked" ';
3752: } elsif ($type eq 'contains') {
3753: $containson = ' checked="checked" ';
3754: } elsif ($type eq 'begins') {
3755: $beginson = ' checked="checked" ';
3756: }
3757: }
3758: } else {
3759: if ($settings->{'searchtypes'} eq 'exact') {
3760: $exacton = ' checked="checked" ';
3761: } elsif ($settings->{'searchtypes'} eq 'contains') {
3762: $containson = ' checked="checked" ';
3763: } elsif ($settings->{'searchtypes'} eq 'specify') {
3764: $exacton = ' checked="checked" ';
3765: $containson = ' checked="checked" ';
3766: }
3767: }
3768: }
3769: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3770: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3771:
3772: my $numinrow = 4;
3773: my $cansrchrow = 0;
3774: $datatable='<tr class="LC_odd_row">'.
3775: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3776: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3777: '<input type="radio" name="dirsrch_available"'.
3778: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3779: '<label><input type="radio" name="dirsrch_available"'.
3780: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3781: '</tr><tr>'.
3782: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3783: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3784: '<input type="radio" name="dirsrch_instlocalonly"'.
3785: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3786: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3787: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3788: '</tr>';
3789: $$rowtotal += 2;
3790: if (ref($usertypes) eq 'HASH') {
3791: if (keys(%{$usertypes}) > 0) {
3792: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3793: $numinrow,$othertitle,'cansearch',
3794: $rowtotal);
3795: $cansrchrow = 1;
3796: }
3797: }
3798: if ($cansrchrow) {
3799: $$rowtotal ++;
3800: $datatable .= '<tr>';
3801: } else {
3802: $datatable .= '<tr class="LC_odd_row">';
3803: }
3804: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3805: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3806: foreach my $title (@{$titleorder}) {
3807: if (defined($searchtitles->{$title})) {
3808: my $check = ' ';
3809: if (ref($settings) eq 'HASH') {
3810: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3811: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3812: $check = ' checked="checked" ';
3813: }
3814: }
3815: }
3816: $datatable .= '<td class="LC_left_item">'.
3817: '<span class="LC_nobreak"><label>'.
3818: '<input type="checkbox" name="searchby" '.
3819: 'value="'.$title.'"'.$check.'/>'.
3820: $searchtitles->{$title}.'</label></span></td>';
3821: }
3822: }
3823: $datatable .= '</tr></table></td></tr>';
3824: $$rowtotal ++;
3825: if ($cansrchrow) {
3826: $datatable .= '<tr class="LC_odd_row">';
3827: } else {
3828: $datatable .= '<tr>';
3829: }
3830: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3831: '<td class="LC_left_item" colspan="2">'.
3832: '<span class="LC_nobreak"><label>'.
3833: '<input type="checkbox" name="searchtypes" '.
3834: $exacton.' value="exact" />'.&mt('Exact match').
3835: '</label> '.
3836: '<label><input type="checkbox" name="searchtypes" '.
3837: $beginson.' value="begins" />'.&mt('Begins with').
3838: '</label> '.
3839: '<label><input type="checkbox" name="searchtypes" '.
3840: $containson.' value="contains" />'.&mt('Contains').
3841: '</label></span></td></tr>';
3842: $$rowtotal ++;
3843: } else {
3844: my $domsrchon = ' checked="checked" ';
3845: my $domsrchoff = ' ';
3846: my $domlocalon = ' ';
3847: my $domlocaloff = ' checked="checked" ';
3848: if (ref($settings) eq 'HASH') {
3849: if ($settings->{'lclocalonly'} eq '1') {
3850: $domlocalon = $domlocaloff;
3851: $domlocaloff = ' ';
3852: }
3853: if ($settings->{'lcavailable'} eq '0') {
3854: $domsrchoff = $domsrchon;
3855: $domsrchon = ' ';
3856: }
3857: }
3858: $datatable='<tr class="LC_odd_row">'.
3859: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3860: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3861: '<input type="radio" name="dirsrch_domavailable"'.
3862: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3863: '<label><input type="radio" name="dirsrch_domavailable"'.
3864: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3865: '</tr><tr>'.
3866: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3867: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3868: '<input type="radio" name="dirsrch_domlocalonly"'.
3869: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3870: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3871: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3872: '</tr>';
3873: $$rowtotal += 2;
3874: }
3875: return $datatable;
3876: }
3877:
3878: sub print_contacts {
3879: my ($position,$dom,$settings,$rowtotal) = @_;
3880: my $datatable;
3881: my @contacts = ('adminemail','supportemail');
3882: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3883: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
3884: if ($position eq 'top') {
3885: if (ref($settings) eq 'HASH') {
3886: foreach my $item (@contacts) {
3887: if (exists($settings->{$item})) {
3888: $to{$item} = $settings->{$item};
3889: }
3890: }
3891: }
3892: } elsif ($position eq 'middle') {
3893: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3894: 'updatesmail','idconflictsmail','hostipmail');
3895: foreach my $type (@mailings) {
3896: $otheremails{$type} = '';
3897: }
3898: } elsif ($position eq 'lower') {
3899: if (ref($settings) eq 'HASH') {
3900: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3901: %lonstatus = %{$settings->{'lonstatus'}};
3902: }
3903: }
3904: } else {
3905: @mailings = ('helpdeskmail','otherdomsmail');
3906: foreach my $type (@mailings) {
3907: $otheremails{$type} = '';
3908: }
3909: $bccemails{'helpdeskmail'} = '';
3910: $bccemails{'otherdomsmail'} = '';
3911: $includestr{'helpdeskmail'} = '';
3912: $includestr{'otherdomsmail'} = '';
3913: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3914: }
3915: if (ref($settings) eq 'HASH') {
3916: unless (($position eq 'top') || ($position eq 'lower')) {
3917: foreach my $type (@mailings) {
3918: if (exists($settings->{$type})) {
3919: if (ref($settings->{$type}) eq 'HASH') {
3920: foreach my $item (@contacts) {
3921: if ($settings->{$type}{$item}) {
3922: $checked{$type}{$item} = ' checked="checked" ';
3923: }
3924: }
3925: $otheremails{$type} = $settings->{$type}{'others'};
3926: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3927: $bccemails{$type} = $settings->{$type}{'bcc'};
3928: if ($settings->{$type}{'include'} ne '') {
3929: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3930: $includestr{$type} = &unescape($includestr{$type});
3931: }
3932: }
3933: }
3934: } elsif ($type eq 'lonstatusmail') {
3935: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3936: }
3937: }
3938: }
3939: if ($position eq 'bottom') {
3940: foreach my $type (@mailings) {
3941: $bccemails{$type} = $settings->{$type}{'bcc'};
3942: if ($settings->{$type}{'include'} ne '') {
3943: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3944: $includestr{$type} = &unescape($includestr{$type});
3945: }
3946: }
3947: if (ref($settings->{'helpform'}) eq 'HASH') {
3948: if (ref($fields) eq 'ARRAY') {
3949: foreach my $field (@{$fields}) {
3950: $currfield{$field} = $settings->{'helpform'}{$field};
3951: }
3952: }
3953: if (exists($settings->{'helpform'}{'maxsize'})) {
3954: $maxsize = $settings->{'helpform'}{'maxsize'};
3955: } else {
3956: $maxsize = '1.0';
3957: }
3958: } else {
3959: if (ref($fields) eq 'ARRAY') {
3960: foreach my $field (@{$fields}) {
3961: $currfield{$field} = 'yes';
3962: }
3963: }
3964: $maxsize = '1.0';
3965: }
3966: }
3967: } else {
3968: if ($position eq 'top') {
3969: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3970: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3971: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3972: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3973: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3974: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3975: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3976: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3977: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
3978: } elsif ($position eq 'bottom') {
3979: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3980: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3981: if (ref($fields) eq 'ARRAY') {
3982: foreach my $field (@{$fields}) {
3983: $currfield{$field} = 'yes';
3984: }
3985: }
3986: $maxsize = '1.0';
3987: }
3988: }
3989: my ($titles,$short_titles) = &contact_titles();
3990: my $rownum = 0;
3991: my $css_class;
3992: if ($position eq 'top') {
3993: foreach my $item (@contacts) {
3994: $css_class = $rownum%2?' class="LC_odd_row"':'';
3995: $datatable .= '<tr'.$css_class.'>'.
3996: '<td><span class="LC_nobreak">'.$titles->{$item}.
3997: '</span></td><td class="LC_right_item">'.
3998: '<input type="text" name="'.$item.'" value="'.
3999: $to{$item}.'" /></td></tr>';
4000: $rownum ++;
4001: }
4002: } elsif ($position eq 'bottom') {
4003: $css_class = $rownum%2?' class="LC_odd_row"':'';
4004: $datatable .= '<tr'.$css_class.'>'.
4005: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4006: &mt('(e-mail, subject, and description always shown)').
4007: '</td><td class="LC_left_item">';
4008: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4009: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4010: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4011: foreach my $field (@{$fields}) {
4012: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4013: if (($field eq 'screenshot') || ($field eq 'cc')) {
4014: $datatable .= ' '.&mt('(logged-in users)');
4015: }
4016: $datatable .='</td><td>';
4017: my $clickaction;
4018: if ($field eq 'screenshot') {
4019: $clickaction = ' onclick="screenshotSize(this);"';
4020: }
4021: if (ref($possoptions->{$field}) eq 'ARRAY') {
4022: foreach my $option (@{$possoptions->{$field}}) {
4023: my $checked;
4024: if ($currfield{$field} eq $option) {
4025: $checked = ' checked="checked"';
4026: }
4027: $datatable .= '<span class="LC_nobreak"><label>'.
4028: '<input type="radio" name="helpform_'.$field.'" '.
4029: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4030: '</label></span>'.(' 'x2);
4031: }
4032: }
4033: if ($field eq 'screenshot') {
4034: my $display;
4035: if ($currfield{$field} eq 'no') {
4036: $display = ' style="display:none"';
4037: }
4038: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4039: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4040: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4041: }
4042: $datatable .= '</td></tr>';
4043: }
4044: $datatable .= '</table>';
4045: }
4046: $datatable .= '</td></tr>'."\n";
4047: $rownum ++;
4048: }
4049: unless (($position eq 'top') || ($position eq 'lower')) {
4050: foreach my $type (@mailings) {
4051: $css_class = $rownum%2?' class="LC_odd_row"':'';
4052: $datatable .= '<tr'.$css_class.'>'.
4053: '<td><span class="LC_nobreak">'.
4054: $titles->{$type}.': </span></td>'.
4055: '<td class="LC_left_item">';
4056: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4057: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4058: }
4059: $datatable .= '<span class="LC_nobreak">';
4060: foreach my $item (@contacts) {
4061: $datatable .= '<label>'.
4062: '<input type="checkbox" name="'.$type.'"'.
4063: $checked{$type}{$item}.
4064: ' value="'.$item.'" />'.$short_titles->{$item}.
4065: '</label> ';
4066: }
4067: $datatable .= '</span><br />'.&mt('Others').': '.
4068: '<input type="text" name="'.$type.'_others" '.
4069: 'value="'.$otheremails{$type}.'" />';
4070: my %locchecked;
4071: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4072: foreach my $loc ('s','b') {
4073: if ($includeloc{$type} eq $loc) {
4074: $locchecked{$loc} = ' checked="checked"';
4075: last;
4076: }
4077: }
4078: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4079: '<input type="text" name="'.$type.'_bcc" '.
4080: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4081: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4082: &mt('Text automatically added to e-mail:').' '.
4083: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
4084: '<span class="LC_nobreak">'.&mt('Location:').' '.
4085: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4086: (' 'x2).
4087: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4088: '</span></fieldset>';
4089: }
4090: $datatable .= '</td></tr>'."\n";
4091: $rownum ++;
4092: }
4093: }
4094: if ($position eq 'middle') {
4095: my %choices;
4096: my $corelink = &core_link_msu();
4097: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
4098: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
4099: $corelink);
4100: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4101: my @toggles = ('reporterrors','reportupdates','reportstatus');
4102: my %defaultchecked = ('reporterrors' => 'on',
4103: 'reportupdates' => 'on',
4104: 'reportstatus' => 'on');
4105: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4106: \%choices,$rownum);
4107: $datatable .= $reports;
4108: } elsif ($position eq 'lower') {
4109: my (%current,%excluded,%weights);
4110: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4111: if ($lonstatus{'threshold'} =~ /^\d+$/) {
4112: $current{'errorthreshold'} = $lonstatus{'threshold'};
4113: } else {
4114: $current{'errorthreshold'} = $defaults->{'threshold'};
4115: }
4116: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
4117: $current{'errorsysmail'} = $lonstatus{'sysmail'};
4118: } else {
4119: $current{'errorsysmail'} = $defaults->{'sysmail'};
4120: }
4121: if (ref($lonstatus{'weights'}) eq 'HASH') {
4122: foreach my $type ('E','W','N','U') {
4123: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4124: $weights{$type} = $lonstatus{'weights'}{$type};
4125: } else {
4126: $weights{$type} = $defaults->{$type};
4127: }
4128: }
4129: } else {
4130: foreach my $type ('E','W','N','U') {
4131: $weights{$type} = $defaults->{$type};
4132: }
4133: }
4134: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4135: if (@{$lonstatus{'excluded'}} > 0) {
4136: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4137: }
4138: }
4139: foreach my $item ('errorthreshold','errorsysmail') {
4140: $css_class = $rownum%2?' class="LC_odd_row"':'';
4141: $datatable .= '<tr'.$css_class.'>'.
4142: '<td class="LC_left_item"><span class="LC_nobreak">'.
4143: $titles->{$item}.
4144: '</span></td><td class="LC_left_item">'.
4145: '<input type="text" name="'.$item.'" value="'.
4146: $current{$item}.'" size="5" /></td></tr>';
4147: $rownum ++;
4148: }
4149: $css_class = $rownum%2?' class="LC_odd_row"':'';
4150: $datatable .= '<tr'.$css_class.'>'.
4151: '<td class="LC_left_item">'.
4152: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4153: '</span></td><td class="LC_left_item"><table><tr>';
4154: foreach my $type ('E','W','N','U') {
4155: $datatable .= '<td>'.$names->{$type}.'<br />'.
4156: '<input type="text" name="errorweights_'.$type.'" value="'.
4157: $weights{$type}.'" size="5" /></td>';
4158: }
4159: $datatable .= '</tr></table></tr>';
4160: $rownum ++;
4161: $css_class = $rownum%2?' class="LC_odd_row"':'';
4162: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4163: $titles->{'errorexcluded'}.'</td>'.
4164: '<td class="LC_left_item"><table>';
4165: my $numinrow = 4;
4166: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4167: for (my $i=0; $i<@ids; $i++) {
4168: my $rem = $i%($numinrow);
4169: if ($rem == 0) {
4170: if ($i > 0) {
4171: $datatable .= '</tr>';
4172: }
4173: $datatable .= '<tr>';
4174: }
4175: my $check;
4176: if ($excluded{$ids[$i]}) {
4177: $check = ' checked="checked" ';
4178: }
4179: $datatable .= '<td class="LC_left_item">'.
4180: '<span class="LC_nobreak"><label>'.
4181: '<input type="checkbox" name="errorexcluded" '.
4182: 'value="'.$ids[$i].'"'.$check.' />'.
4183: $ids[$i].'</label></span></td>';
4184: }
4185: my $colsleft = $numinrow - @ids%($numinrow);
4186: if ($colsleft > 1 ) {
4187: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4188: ' </td>';
4189: } elsif ($colsleft == 1) {
4190: $datatable .= '<td class="LC_left_item"> </td>';
4191: }
4192: $datatable .= '</tr></table></td></tr>';
4193: $rownum ++;
4194: } elsif ($position eq 'bottom') {
4195: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4196: my (@posstypes,%usertypeshash);
4197: if (ref($types) eq 'ARRAY') {
4198: @posstypes = @{$types};
4199: }
4200: if (@posstypes) {
4201: if (ref($usertypes) eq 'HASH') {
4202: %usertypeshash = %{$usertypes};
4203: }
4204: my @overridden;
4205: my $numinrow = 4;
4206: if (ref($settings) eq 'HASH') {
4207: if (ref($settings->{'overrides'}) eq 'HASH') {
4208: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4209: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4210: push(@overridden,$key);
4211: foreach my $item (@contacts) {
4212: if ($settings->{'overrides'}{$key}{$item}) {
4213: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4214: }
4215: }
4216: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4217: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4218: $includeloc{'override_'.$key} = '';
4219: $includestr{'override_'.$key} = '';
4220: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4221: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4222: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4223: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4224: }
4225: }
4226: }
4227: }
4228: }
4229: my $customclass = 'LC_helpdesk_override';
4230: my $optionsprefix = 'LC_options_helpdesk_';
4231:
4232: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4233:
4234: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4235: $numinrow,$othertitle,'overrides',
4236: \$rownum,$onclicktypes,$customclass);
4237: $rownum ++;
4238: $usertypeshash{'default'} = $othertitle;
4239: foreach my $status (@posstypes) {
4240: my $css_class;
4241: if ($rownum%2) {
4242: $css_class = 'LC_odd_row ';
4243: }
4244: $css_class .= $customclass;
4245: my $rowid = $optionsprefix.$status;
4246: my $hidden = 1;
4247: my $currstyle = 'display:none';
4248: if (grep(/^\Q$status\E$/,@overridden)) {
4249: $currstyle = 'display:table-row';
4250: $hidden = 0;
4251: }
4252: my $key = 'override_'.$status;
4253: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4254: $includeloc{$key},$includestr{$key},$status,$rowid,
4255: $usertypeshash{$status},$css_class,$currstyle,
4256: \@contacts,$short_titles);
4257: unless ($hidden) {
4258: $rownum ++;
4259: }
4260: }
4261: }
4262: }
4263: $$rowtotal += $rownum;
4264: return $datatable;
4265: }
4266:
4267: sub core_link_msu {
4268: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4269: &mt('LON-CAPA core group - MSU'),600,500);
4270: }
4271:
4272: sub overridden_helpdesk {
4273: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4274: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4275: my $class = 'LC_left_item';
4276: if ($css_class) {
4277: $css_class = ' class="'.$css_class.'"';
4278: }
4279: if ($rowid) {
4280: $rowid = ' id="'.$rowid.'"';
4281: }
4282: if ($rowstyle) {
4283: $rowstyle = ' style="'.$rowstyle.'"';
4284: }
4285: my ($output,$description);
4286: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4287: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4288: "<td>$description</td>\n".
4289: '<td class="'.$class.'" colspan="2">'.
4290: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4291: '<span class="LC_nobreak">';
4292: if (ref($contacts) eq 'ARRAY') {
4293: foreach my $item (@{$contacts}) {
4294: my $check;
4295: if (ref($checked) eq 'HASH') {
4296: $check = $checked->{$item};
4297: }
4298: my $title;
4299: if (ref($short_titles) eq 'HASH') {
4300: $title = $short_titles->{$item};
4301: }
4302: $output .= '<label>'.
4303: '<input type="checkbox" name="override_'.$type.'"'.$check.
4304: ' value="'.$item.'" />'.$title.'</label> ';
4305: }
4306: }
4307: $output .= '</span><br />'.&mt('Others').': '.
4308: '<input type="text" name="override_'.$type.'_others" '.
4309: 'value="'.$otheremails.'" />';
4310: my %locchecked;
4311: foreach my $loc ('s','b') {
4312: if ($includeloc eq $loc) {
4313: $locchecked{$loc} = ' checked="checked"';
4314: last;
4315: }
4316: }
4317: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4318: '<input type="text" name="override_'.$type.'_bcc" '.
4319: 'value="'.$bccemails.'" /></fieldset>'.
4320: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4321: &mt('Text automatically added to e-mail:').' '.
4322: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4323: '<span class="LC_nobreak">'.&mt('Location:').' '.
4324: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4325: (' 'x2).
4326: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4327: '</span></fieldset>'.
4328: '</td></tr>'."\n";
4329: return $output;
4330: }
4331:
4332: sub contacts_javascript {
4333: return <<"ENDSCRIPT";
4334:
4335: <script type="text/javascript">
4336: // <![CDATA[
4337:
4338: function screenshotSize(field) {
4339: if (document.getElementById('help_screenshotsize')) {
4340: if (field.value == 'no') {
4341: document.getElementById('help_screenshotsize').style.display="none";
4342: } else {
4343: document.getElementById('help_screenshotsize').style.display="";
4344: }
4345: }
4346: return;
4347: }
4348:
4349: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4350: if (form.elements[checkbox].length != undefined) {
4351: var count = 0;
4352: if (docount) {
4353: for (var i=0; i<form.elements[checkbox].length; i++) {
4354: if (form.elements[checkbox][i].checked) {
4355: count ++;
4356: }
4357: }
4358: }
4359: for (var i=0; i<form.elements[checkbox].length; i++) {
4360: var type = form.elements[checkbox][i].value;
4361: if (document.getElementById(prefix+type)) {
4362: if (form.elements[checkbox][i].checked) {
4363: document.getElementById(prefix+type).style.display = 'table-row';
4364: if (count % 2 == 1) {
4365: document.getElementById(prefix+type).className = target+' LC_odd_row';
4366: } else {
4367: document.getElementById(prefix+type).className = target;
4368: }
4369: count ++;
4370: } else {
4371: document.getElementById(prefix+type).style.display = 'none';
4372: }
4373: }
4374: }
4375: }
4376: return;
4377: }
4378:
4379: // ]]>
4380: </script>
4381:
4382: ENDSCRIPT
4383: }
4384:
4385: sub print_helpsettings {
4386: my ($position,$dom,$settings,$rowtotal) = @_;
4387: my $confname = $dom.'-domainconfig';
4388: my $formname = 'display';
4389: my ($datatable,$itemcount);
4390: if ($position eq 'top') {
4391: $itemcount = 1;
4392: my (%choices,%defaultchecked,@toggles);
4393: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4394: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4395: &mt('LON-CAPA bug tracker'),600,500));
4396: %defaultchecked = ('submitbugs' => 'on');
4397: @toggles = ('submitbugs');
4398: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4399: \%choices,$itemcount);
4400: $$rowtotal ++;
4401: } else {
4402: my $css_class;
4403: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
4404: my (%customroles,%ordered,%current);
4405: if (ref($settings) eq 'HASH') {
4406: if (ref($settings->{'adhoc'}) eq 'HASH') {
4407: %current = %{$settings->{'adhoc'}};
4408: }
4409: }
4410: my $count = 0;
4411: foreach my $key (sort(keys(%existing))) {
4412: if ($key=~/^rolesdef\_(\w+)$/) {
4413: my $rolename = $1;
4414: my (%privs,$order);
4415: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4416: $customroles{$rolename} = \%privs;
4417: if (ref($current{$rolename}) eq 'HASH') {
4418: $order = $current{$rolename}{'order'};
4419: }
4420: if ($order eq '') {
4421: $order = $count;
4422: }
4423: $ordered{$order} = $rolename;
4424: $count++;
4425: }
4426: }
4427: my $maxnum = scalar(keys(%ordered));
4428: my @roles_by_num = ();
4429: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4430: push(@roles_by_num,$item);
4431: }
4432: my $context = 'domprefs';
4433: my $crstype = 'Course';
4434: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4435: my @accesstypes = ('all','dh','da','none');
4436: my ($numstatustypes,@jsarray);
4437: if (ref($types) eq 'ARRAY') {
4438: if (@{$types} > 0) {
4439: $numstatustypes = scalar(@{$types});
4440: push(@accesstypes,'status');
4441: @jsarray = ('bystatus');
4442: }
4443: }
4444: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
4445: if (keys(%domhelpdesk)) {
4446: push(@accesstypes,('inc','exc'));
4447: push(@jsarray,('notinc','notexc'));
4448: }
4449: my $hiddenstr = join("','",@jsarray);
4450: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
4451: my $context = 'domprefs';
4452: my $crstype = 'Course';
4453: my $prefix = 'helproles_';
4454: my $add_class = 'LC_hidden';
4455: foreach my $num (@roles_by_num) {
4456: my $role = $ordered{$num};
4457: my ($desc,$access,@statuses);
4458: if (ref($current{$role}) eq 'HASH') {
4459: $desc = $current{$role}{'desc'};
4460: $access = $current{$role}{'access'};
4461: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4462: @statuses = @{$current{$role}{'insttypes'}};
4463: }
4464: }
4465: if ($desc eq '') {
4466: $desc = $role;
4467: }
4468: my $identifier = 'custhelp'.$num;
4469: my %full=();
4470: my %levels= (
4471: course => {},
4472: domain => {},
4473: system => {},
4474: );
4475: my %levelscurrent=(
4476: course => {},
4477: domain => {},
4478: system => {},
4479: );
4480: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4481: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4482: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4483: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4484: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4485: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4486: for (my $k=0; $k<=$maxnum; $k++) {
4487: my $vpos = $k+1;
4488: my $selstr;
4489: if ($k == $num) {
4490: $selstr = ' selected="selected" ';
4491: }
4492: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4493: }
4494: $datatable .= '</select>'.(' 'x2).
4495: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4496: '</td>'.
4497: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4498: &mt('Name shown to users:').
4499: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4500: '</fieldset>'.
4501: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4502: $othertitle,$usertypes,$types,\%domhelpdesk).
4503: '<fieldset>'.
4504: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
4505: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4506: \%levelscurrent,$identifier,
4507: 'LC_hidden',$prefix.$num.'_privs').
4508: '</fieldset></td>';
4509: $itemcount ++;
4510: }
4511: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4512: my $newcust = 'custhelp'.$count;
4513: my (%privs,%levelscurrent);
4514: my %full=();
4515: my %levels= (
4516: course => {},
4517: domain => {},
4518: system => {},
4519: );
4520: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4521: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4522: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4523: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4524: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4525: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4526: for (my $k=0; $k<$maxnum+1; $k++) {
4527: my $vpos = $k+1;
4528: my $selstr;
4529: if ($k == $maxnum) {
4530: $selstr = ' selected="selected" ';
4531: }
4532: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4533: }
4534: $datatable .= '</select> '."\n".
4535: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4536: '</label></span></td>'.
4537: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4538: '<span class="LC_nobreak">'.
4539: &mt('Internal name:').
4540: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4541: '</span>'.(' 'x4).
4542: '<span class="LC_nobreak">'.
4543: &mt('Name shown to users:').
4544: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4545: '</span></fieldset>'.
4546: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4547: $usertypes,$types,\%domhelpdesk).
4548: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
4549: &Apache::lonuserutils::custom_role_header($context,$crstype,
4550: \@templateroles,$newcust).
4551: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4552: \%levelscurrent,$newcust).
4553: '</fieldset>'.
4554: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4555: '</td></tr>';
4556: $count ++;
4557: $$rowtotal += $count;
4558: }
4559: return $datatable;
4560: }
4561:
4562: sub adhocbutton {
4563: my ($prefix,$num,$field,$visibility) = @_;
4564: my %lt = &Apache::lonlocal::texthash(
4565: show => 'Show details',
4566: hide => 'Hide details',
4567: );
4568: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4569: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4570: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4571: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4572: }
4573:
4574: sub helpsettings_javascript {
4575: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4576: return unless(ref($roles_by_num) eq 'ARRAY');
4577: my %html_js_lt = &Apache::lonlocal::texthash(
4578: show => 'Show details',
4579: hide => 'Hide details',
4580: );
4581: &html_escape(\%html_js_lt);
4582: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4583: return <<"ENDSCRIPT";
4584: <script type="text/javascript">
4585: // <![CDATA[
4586:
4587: function reorderHelpRoles(form,item) {
4588: var changedVal;
4589: $jstext
4590: var newpos = 'helproles_${total}_pos';
4591: var maxh = 1 + $total;
4592: var current = new Array();
4593: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4594: if (item == newpos) {
4595: changedVal = newitemVal;
4596: } else {
4597: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4598: current[newitemVal] = newpos;
4599: }
4600: for (var i=0; i<helproles.length; i++) {
4601: var elementName = 'helproles_'+helproles[i]+'_pos';
4602: if (elementName != item) {
4603: if (form.elements[elementName]) {
4604: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4605: current[currVal] = elementName;
4606: }
4607: }
4608: }
4609: var oldVal;
4610: for (var j=0; j<maxh; j++) {
4611: if (current[j] == undefined) {
4612: oldVal = j;
4613: }
4614: }
4615: if (oldVal < changedVal) {
4616: for (var k=oldVal+1; k<=changedVal ; k++) {
4617: var elementName = current[k];
4618: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4619: }
4620: } else {
4621: for (var k=changedVal; k<oldVal; k++) {
4622: var elementName = current[k];
4623: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4624: }
4625: }
4626: return;
4627: }
4628:
4629: function helpdeskAccess(num) {
4630: var curraccess = null;
4631: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4632: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4633: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4634: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4635: }
4636: }
4637: }
4638: var shown = Array();
4639: var hidden = Array();
4640: if (curraccess == 'none') {
4641: hidden = Array('$hiddenstr');
4642: } else {
4643: if (curraccess == 'status') {
4644: shown = Array('bystatus');
4645: hidden = Array('notinc','notexc');
4646: } else {
4647: if (curraccess == 'exc') {
4648: shown = Array('notexc');
4649: hidden = Array('notinc','bystatus');
4650: }
4651: if (curraccess == 'inc') {
4652: shown = Array('notinc');
4653: hidden = Array('notexc','bystatus');
4654: }
4655: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
4656: hidden = Array('notinc','notexc','bystatus');
4657: }
4658: }
4659: }
4660: if (hidden.length > 0) {
4661: for (var i=0; i<hidden.length; i++) {
4662: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4663: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4664: }
4665: }
4666: }
4667: if (shown.length > 0) {
4668: for (var i=0; i<shown.length; i++) {
4669: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4670: if (shown[i] == 'privs') {
4671: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4672: } else {
4673: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4674: }
4675: }
4676: }
4677: }
4678: return;
4679: }
4680:
4681: function toggleHelpdeskItem(num,field) {
4682: if (document.getElementById('helproles_'+num+'_'+field)) {
4683: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4684: document.getElementById('helproles_'+num+'_'+field).className =
4685: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4686: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4687: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4688: }
4689: } else {
4690: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4691: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4692: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4693: }
4694: }
4695: }
4696: return;
4697: }
4698:
4699: // ]]>
4700: </script>
4701:
4702: ENDSCRIPT
4703: }
4704:
4705: sub helpdeskroles_access {
4706: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4707: $usertypes,$types,$domhelpdesk) = @_;
4708: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4709: my %lt = &Apache::lonlocal::texthash(
4710: 'rou' => 'Role usage',
4711: 'whi' => 'Which helpdesk personnel may use this role?',
4712: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4713: 'dh' => 'All with domain helpdesk role',
4714: 'da' => 'All with domain helpdesk assistant role',
4715: 'none' => 'None',
4716: 'status' => 'Determined based on institutional status',
4717: 'inc' => 'Include all, but exclude specific personnel',
4718: 'exc' => 'Exclude all, but include specific personnel',
4719: );
4720: my %usecheck = (
4721: all => ' checked="checked"',
4722: );
4723: my %displaydiv = (
4724: status => 'none',
4725: inc => 'none',
4726: exc => 'none',
4727: priv => 'block',
4728: );
4729: my $output;
4730: if (ref($current) eq 'HASH') {
4731: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4732: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4733: $usecheck{$current->{access}} = $usecheck{'all'};
4734: delete($usecheck{'all'});
4735: if ($current->{access} =~ /^(status|inc|exc)$/) {
4736: my $access = $1;
4737: $displaydiv{$access} = 'inline';
4738: } elsif ($current->{access} eq 'none') {
4739: $displaydiv{'priv'} = 'none';
4740: }
4741: }
4742: }
4743: }
4744: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4745: '<p>'.$lt{'whi'}.'</p>';
4746: foreach my $access (@{$accesstypes}) {
4747: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4748: ' onclick="helpdeskAccess('."'$num'".');" />'.
4749: $lt{$access}.'</label>';
4750: if ($access eq 'status') {
4751: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4752: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4753: $othertitle,$usertypes,$types).
4754: '</div>';
4755: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4756: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4757: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4758: '</div>';
4759: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4760: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4761: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4762: '</div>';
4763: }
4764: $output .= '</p>';
4765: }
4766: $output .= '</fieldset>';
4767: return $output;
4768: }
4769:
4770: sub radiobutton_prefs {
4771: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
4772: $additional,$align,$firstval) = @_;
4773: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4774: (ref($choices) eq 'HASH'));
4775:
4776: my (%checkedon,%checkedoff,$datatable,$css_class);
4777:
4778: foreach my $item (@{$toggles}) {
4779: if ($defaultchecked->{$item} eq 'on') {
4780: $checkedon{$item} = ' checked="checked" ';
4781: $checkedoff{$item} = ' ';
4782: } elsif ($defaultchecked->{$item} eq 'off') {
4783: $checkedoff{$item} = ' checked="checked" ';
4784: $checkedon{$item} = ' ';
4785: }
4786: }
4787: if (ref($settings) eq 'HASH') {
4788: foreach my $item (@{$toggles}) {
4789: if ($settings->{$item} eq '1') {
4790: $checkedon{$item} = ' checked="checked" ';
4791: $checkedoff{$item} = ' ';
4792: } elsif ($settings->{$item} eq '0') {
4793: $checkedoff{$item} = ' checked="checked" ';
4794: $checkedon{$item} = ' ';
4795: }
4796: }
4797: }
4798: if ($onclick) {
4799: $onclick = ' onclick="'.$onclick.'"';
4800: }
4801: foreach my $item (@{$toggles}) {
4802: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4803: $datatable .=
4804: '<tr'.$css_class.'><td valign="top">'.
4805: '<span class="LC_nobreak">'.$choices->{$item}.
4806: '</span></td>';
4807: if ($align eq 'left') {
4808: $datatable .= '<td class="LC_left_item">';
4809: } else {
4810: $datatable .= '<td class="LC_right_item">';
4811: }
4812: $datatable .= '<span class="LC_nobreak">';
4813: if ($firstval eq 'no') {
4814: $datatable .=
4815: '<label><input type="radio" name="'.
4816: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4817: '</label> <label><input type="radio" name="'.$item.'" '.
4818: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4819: } else {
4820: $datatable .=
4821: '<label><input type="radio" name="'.
4822: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
4823: '</label> <label><input type="radio" name="'.$item.'" '.
4824: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4825: }
4826: $datatable .= '</span>'.$additional.'</td></tr>';
4827: $itemcount ++;
4828: }
4829: return ($datatable,$itemcount);
4830: }
4831:
4832: sub print_ltitools {
4833: my ($dom,$settings,$rowtotal) = @_;
4834: my $rownum = 0;
4835: my $css_class;
4836: my $itemcount = 1;
4837: my $maxnum = 0;
4838: my %ordered;
4839: if (ref($settings) eq 'HASH') {
4840: foreach my $item (keys(%{$settings})) {
4841: if (ref($settings->{$item}) eq 'HASH') {
4842: my $num = $settings->{$item}{'order'};
4843: $ordered{$num} = $item;
4844: }
4845: }
4846: }
4847: my $confname = $dom.'-domainconfig';
4848: my $switchserver = &check_switchserver($dom,$confname);
4849: my $maxnum = scalar(keys(%ordered));
4850: my $datatable;
4851: my %lt = <itools_names();
4852: my @courseroles = ('cc','in','ta','ep','st');
4853: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
4854: my @fields = ('fullname','firstname','lastname','email','roles','user');
4855: if (keys(%ordered)) {
4856: my @items = sort { $a <=> $b } keys(%ordered);
4857: for (my $i=0; $i<@items; $i++) {
4858: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4859: my $item = $ordered{$items[$i]};
4860: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
4861: if (ref($settings->{$item}) eq 'HASH') {
4862: $title = $settings->{$item}->{'title'};
4863: $url = $settings->{$item}->{'url'};
4864: $key = $settings->{$item}->{'key'};
4865: $secret = $settings->{$item}->{'secret'};
4866: $lifetime = $settings->{$item}->{'lifetime'};
4867: my $image = $settings->{$item}->{'image'};
4868: if ($image ne '') {
4869: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4870: }
4871: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4872: $sigsel{'HMAC-256'} = ' selected="selected"';
4873: } else {
4874: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4875: }
4876: }
4877: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
4878: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4879: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4880: for (my $k=0; $k<=$maxnum; $k++) {
4881: my $vpos = $k+1;
4882: my $selstr;
4883: if ($k == $i) {
4884: $selstr = ' selected="selected" ';
4885: }
4886: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4887: }
4888: $datatable .= '</select>'.(' 'x2).
4889: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4890: &mt('Delete?').'</label></span></td>'.
4891: '<td colspan="2">'.
4892: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4893: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
4894: (' 'x2).
4895: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4896: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4897: (' 'x2).
4898: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4899: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4900: (' 'x2).
4901: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4902: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4903: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
4904: '<br /><br />'.
4905: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
4906: ' value="'.$url.'" /></span>'.
4907: (' 'x2).
4908: '<span class="LC_nobreak">'.$lt{'key'}.':'.
4909: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4910: (' 'x2).
4911: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4912: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4913: (' 'x2).
4914: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4915: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4916: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4917: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4918: '</fieldset>'.
4919: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4920: '<span class="LC_nobreak">'.&mt('Display target:');
4921: my %currdisp;
4922: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4923: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4924: $currdisp{'window'} = ' checked="checked"';
4925: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4926: $currdisp{'tab'} = ' checked="checked"';
4927: } else {
4928: $currdisp{'iframe'} = ' checked="checked"';
4929: }
4930: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4931: $currdisp{'width'} = $1;
4932: }
4933: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4934: $currdisp{'height'} = $1;
4935: }
4936: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4937: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
4938: } else {
4939: $currdisp{'iframe'} = ' checked="checked"';
4940: }
4941: foreach my $disp ('iframe','tab','window') {
4942: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4943: $lt{$disp}.'</label>'.(' 'x2);
4944: }
4945: $datatable .= (' 'x4);
4946: foreach my $dimen ('width','height') {
4947: $datatable .= '<label>'.$lt{$dimen}.' '.
4948: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4949: (' 'x2);
4950: }
4951: $datatable .= '</span><br />'.
4952: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4953: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
4954: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4955: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4956: '</textarea></div><div style=""></div>'.
4957: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4958: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
4959: if ($imgsrc) {
4960: $datatable .= $imgsrc.
4961: '<label><input type="checkbox" name="ltitools_image_del"'.
4962: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4963: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4964: } else {
4965: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4966: }
4967: if ($switchserver) {
4968: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4969: } else {
4970: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4971: }
4972: $datatable .= '</span></fieldset>';
4973: my (%checkedfields,%rolemaps,$userincdom);
4974: if (ref($settings->{$item}) eq 'HASH') {
4975: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4976: %checkedfields = %{$settings->{$item}->{'fields'}};
4977: }
4978: $userincdom = $settings->{$item}->{'incdom'};
4979: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4980: %rolemaps = %{$settings->{$item}->{'roles'}};
4981: $checkedfields{'roles'} = 1;
4982: }
4983: }
4984: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4985: '<span class="LC_nobreak">';
4986: my $userfieldstyle = 'display:none;';
4987: my $seluserdom = '';
4988: my $unseluserdom = ' selected="selected"';
4989: foreach my $field (@fields) {
4990: my ($checked,$onclick,$id,$spacer);
4991: if ($checkedfields{$field}) {
4992: $checked = ' checked="checked"';
4993: }
4994: if ($field eq 'user') {
4995: $id = ' id="ltitools_user_field_'.$i.'"';
4996: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4997: if ($checked) {
4998: $userfieldstyle = 'display:inline-block';
4999: if ($userincdom) {
5000: $seluserdom = $unseluserdom;
5001: $unseluserdom = '';
5002: }
5003: }
5004: } else {
5005: $spacer = (' ' x2);
5006: }
5007: $datatable .= '<label>'.
5008: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5009: $lt{$field}.'</label>'.$spacer;
5010: }
5011: $datatable .= '</span>';
5012: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5013: '<span class="LC_nobreak"> : '.
5014: '<select name="ltitools_userincdom_'.$i.'">'.
5015: '<option value="">'.&mt('Select').'</option>'.
5016: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5017: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5018: '</select></span></div>';
5019: $datatable .= '</fieldset>'.
5020: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5021: foreach my $role (@courseroles) {
5022: my ($selected,$selectnone);
5023: if (!$rolemaps{$role}) {
5024: $selectnone = ' selected="selected"';
5025: }
5026: $datatable .= '<td align="center">'.
5027: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5028: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5029: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5030: foreach my $ltirole (@ltiroles) {
5031: unless ($selectnone) {
5032: if ($rolemaps{$role} eq $ltirole) {
5033: $selected = ' selected="selected"';
5034: } else {
5035: $selected = '';
5036: }
5037: }
5038: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5039: }
5040: $datatable .= '</select></td>';
5041: }
5042: $datatable .= '</tr></table></fieldset>';
5043: my %courseconfig;
5044: if (ref($settings->{$item}) eq 'HASH') {
5045: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5046: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5047: }
5048: }
5049: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5050: foreach my $item ('label','title','target','linktext','explanation','append') {
5051: my $checked;
5052: if ($courseconfig{$item}) {
5053: $checked = ' checked="checked"';
5054: }
5055: $datatable .= '<label>'.
5056: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
5057: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5058: }
5059: $datatable .= '</span></fieldset>'.
5060: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5061: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5062: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5063: my %custom = %{$settings->{$item}->{'custom'}};
5064: if (keys(%custom) > 0) {
5065: foreach my $key (sort(keys(%custom))) {
5066: $datatable .= '<tr><td><span class="LC_nobreak">'.
5067: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5068: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5069: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5070: ' value="'.$custom{$key}.'" /></td></tr>';
5071: }
5072: }
5073: }
5074: $datatable .= '<tr><td><span class="LC_nobreak">'.
5075: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5076: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5077: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5078: $datatable .= '</table></fieldset></td></tr>'."\n";
5079: $itemcount ++;
5080: }
5081: }
5082: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5083: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
5084: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5085: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5086: '<select name="ltitools_add_pos"'.$chgstr.'>';
5087: for (my $k=0; $k<$maxnum+1; $k++) {
5088: my $vpos = $k+1;
5089: my $selstr;
5090: if ($k == $maxnum) {
5091: $selstr = ' selected="selected" ';
5092: }
5093: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5094: }
5095: $datatable .= '</select> '."\n".
5096: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5097: '<td colspan="2">'.
5098: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5099: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
5100: (' 'x2).
5101: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5102: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5103: (' 'x2).
5104: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5105: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
5106: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5107: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5108: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5109: '<br />'.
5110: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
5111: (' 'x2).
5112: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5113: (' 'x2).
5114: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5115: (' 'x2).
5116: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5117: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
5118: '</fieldset>'.
5119: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5120: '<span class="LC_nobreak">'.&mt('Display target:');
5121: my %defaultdisp;
5122: $defaultdisp{'iframe'} = ' checked="checked"';
5123: foreach my $disp ('iframe','tab','window') {
5124: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5125: $lt{$disp}.'</label>'.(' 'x2);
5126: }
5127: $datatable .= (' 'x4);
5128: foreach my $dimen ('width','height') {
5129: $datatable .= '<label>'.$lt{$dimen}.' '.
5130: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5131: (' 'x2);
5132: }
5133: $datatable .= '</span><br />'.
5134: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
5135: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
5136: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5137: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
5138: '</div><div style=""></div>'.
5139: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
5140: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
5141: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5142: if ($switchserver) {
5143: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5144: } else {
5145: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5146: }
5147: $datatable .= '</span></fieldset>'.
5148: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5149: '<span class="LC_nobreak">';
5150: foreach my $field (@fields) {
5151: my ($id,$onclick,$spacer);
5152: if ($field eq 'user') {
5153: $id = ' id="ltitools_user_field_add"';
5154: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5155: } else {
5156: $spacer = (' ' x2);
5157: }
5158: $datatable .= '<label>'.
5159: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5160: $lt{$field}.'</label>'.$spacer;
5161: }
5162: $datatable .= '</span>'.
5163: '<div style="display:none;" id="ltitools_user_div_add">'.
5164: '<span class="LC_nobreak"> : '.
5165: '<select name="ltitools_userincdom_add">'.
5166: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5167: '<option value="0">'.&mt('username').'</option>'.
5168: '<option value="1">'.&mt('username:domain').'</option>'.
5169: '</select></span></div></fieldset>';
5170: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5171: foreach my $role (@courseroles) {
5172: my ($checked,$checkednone);
5173: $datatable .= '<td align="center">'.
5174: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5175: '<select name="ltitools_add_roles_'.$role.'">'.
5176: '<option value="" selected="selected">'.&mt('Select').'</option>';
5177: foreach my $ltirole (@ltiroles) {
5178: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5179: }
5180: $datatable .= '</select></td>';
5181: }
5182: $datatable .= '</tr></table></fieldset>'.
5183: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5184: foreach my $item ('label','title','target','linktext','explanation','append') {
5185: $datatable .= '<label>'.
5186: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5187: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5188: }
5189: $datatable .= '</span></fieldset>'.
5190: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5191: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5192: '<tr><td><span class="LC_nobreak">'.
5193: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5194: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5195: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
5196: '</table></fieldset>'."\n".
5197: '</td>'."\n".
5198: '</tr>'."\n";
5199: $itemcount ++;
5200: return $datatable;
5201: }
5202:
5203: sub ltitools_names {
5204: my %lt = &Apache::lonlocal::texthash(
5205: 'title' => 'Title',
5206: 'version' => 'Version',
5207: 'msgtype' => 'Message Type',
5208: 'sigmethod' => 'Signature Method',
5209: 'url' => 'URL',
5210: 'key' => 'Key',
5211: 'lifetime' => 'Nonce lifetime (s)',
5212: 'secret' => 'Secret',
5213: 'icon' => 'Icon',
5214: 'user' => 'User',
5215: 'fullname' => 'Full Name',
5216: 'firstname' => 'First Name',
5217: 'lastname' => 'Last Name',
5218: 'email' => 'E-mail',
5219: 'roles' => 'Role',
5220: 'window' => 'Window',
5221: 'tab' => 'Tab',
5222: 'iframe' => 'iFrame',
5223: 'height' => 'Height',
5224: 'width' => 'Width',
5225: 'linktext' => 'Default Link Text',
5226: 'explanation' => 'Default Explanation',
5227: 'crstarget' => 'Display target',
5228: 'crslabel' => 'Course label',
5229: 'crstitle' => 'Course title',
5230: 'crslinktext' => 'Link Text',
5231: 'crsexplanation' => 'Explanation',
5232: 'crsappend' => 'Provider URL',
5233: );
5234:
5235: return %lt;
5236: }
5237:
5238: sub print_lti {
5239: my ($position,$dom,$settings,$rowtotal) = @_;
5240: my $itemcount = 1;
5241: my ($datatable,$css_class);
5242: my (%rules,%encrypt,%privkeys,%linkprot);
5243: if (ref($settings) eq 'HASH') {
5244: if ($position eq 'top') {
5245: if (exists($settings->{'encrypt'})) {
5246: if (ref($settings->{'encrypt'}) eq 'HASH') {
5247: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5248: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5249: }
5250: }
5251: }
5252: if (exists($settings->{'private'})) {
5253: if (ref($settings->{'private'}) eq 'HASH') {
5254: if (ref($settings->{'private'}) eq 'HASH') {
5255: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5256: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5257: }
5258: }
5259: }
5260: }
5261: } elsif ($position eq 'middle') {
5262: if (exists($settings->{'rules'})) {
5263: if (ref($settings->{'rules'}) eq 'HASH') {
5264: %rules = %{$settings->{'rules'}};
5265: }
5266: }
5267: } elsif ($position eq 'bottom') {
5268: if (exists($settings->{'linkprot'})) {
5269: if (ref($settings->{'linkprot'}) eq 'HASH') {
5270: %linkprot = %{$settings->{'linkprot'}};
5271: if ($linkprot{'lock'}) {
5272: delete($linkprot{'lock'});
5273: }
5274: }
5275: }
5276: }
5277: }
5278: if ($position eq 'top') {
5279: my @ids=&Apache::lonnet::current_machine_ids();
5280: my %servers = &Apache::lonnet::get_servers($dom,'library');
5281: my $primary = &Apache::lonnet::domain($dom,'primary');
5282: my ($extra,$numshown);
5283: foreach my $hostid (sort(keys(%servers))) {
5284: my ($showextra,$divsty,$switch);
5285: if ($hostid eq $primary) {
5286: if ($encrypt{'ltisec_domlinkprot'}) {
5287: $showextra = 1;
5288: }
5289: }
5290: if ($encrypt{'ltisec_crslinkprot'}) {
5291: $showextra = 1;
5292: }
5293: unless (grep(/^\Q$hostid\E$/,@ids)) {
5294: $switch = 1;
5295: }
5296: if ($showextra) {
5297: $numshown ++;
5298: $divsty = 'display:inline-block';
5299: } else {
5300: $divsty = 'display:none';
5301: }
5302: $extra .= '<fieldset id="ltisec_info_'.$hostid.'" style="'.$divsty.'">'.
5303: '<legend>'.$hostid.'</legend>';
5304: if ($switch) {
5305: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5306: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5307: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5308: if (exists($privkeys{$hostid})) {
5309: $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5310: '<span class="LC_nobreak">'.
5311: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5312: '<span class="LC_nobreak">'.&mt('Change?').
5313: '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5314: (' 'x2).
5315: '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
5316: '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
5317: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5318: '</span></div>';
5319: } else {
5320: $extra .= '<span class="LC_nobreak">'.
5321: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5322: '</span>'."\n";
5323: }
5324: } elsif (exists($privkeys{$hostid})) {
5325: $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5326: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5327: '<span class="LC_nobreak">'.&mt('Change?').
5328: '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5329: (' 'x2).
5330: '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
5331: '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
5332: '<span class="LC_nobreak">'.&mt('New Key').':'.
5333: '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
5334: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5335: '</span></div>';
5336: } else {
5337: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5338: '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
5339: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5340: }
5341: $extra .= '</fieldset>';
5342: }
5343: my %choices = &Apache::lonlocal::texthash (
5344: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5345: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5346: );
5347: my @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot);
5348: my %defaultchecked = (
5349: 'ltisec_crslinkprot' => 'off',
5350: 'ltisec_domlinkprot' => 'off',
5351: );
5352: my ($onclick,$itemcount);
5353: $onclick = 'javascript:toggleLTIEncKey(this.form);';
5354: ($datatable,$itemcount) = &radiobutton_prefs(\%encrypt,\@toggles,\%defaultchecked,
5355: \%choices,$itemcount,$onclick,'','left','no');
5356:
5357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5358: my $noprivkeysty = 'display:inline-block';
5359: if ($numshown) {
5360: $noprivkeysty = 'display:none';
5361: }
5362: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5363: '<td><div id="ltisec_noprivkey" style="'.$noprivkeysty.'" >'.
5364: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5365: $extra.
5366: '</td></tr>';
5367: $itemcount ++;
5368: $$rowtotal += $itemcount;
5369: } elsif ($position eq 'middle') {
5370: $datatable = &password_rules('secrets',\$itemcount,\%rules);
5371: $$rowtotal += $itemcount;
5372: } elsif ($position eq 'bottom') {
5373: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
5374: }
5375: return $datatable;
5376: }
5377:
5378: sub print_coursedefaults {
5379: my ($position,$dom,$settings,$rowtotal) = @_;
5380: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
5381: my $itemcount = 1;
5382: my %choices = &Apache::lonlocal::texthash (
5383: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
5384: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5385: coursecredits => 'Credits can be specified for courses',
5386: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5387: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
5388: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
5389: texengine => 'Default method to display mathematics',
5390: postsubmit => 'Disable submit button/keypress following student submission',
5391: canclone => "People who may clone a course (besides course's owner and coordinators)",
5392: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
5393: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
5394: );
5395: my %staticdefaults = (
5396: anonsurvey_threshold => 10,
5397: uploadquota => 500,
5398: postsubmit => 60,
5399: mysqltables => 172800,
5400: );
5401: if ($position eq 'top') {
5402: %defaultchecked = (
5403: 'uselcmath' => 'on',
5404: 'usejsme' => 'on',
5405: 'inline_chem' => 'on',
5406: 'canclone' => 'none',
5407: );
5408: @toggles = ('uselcmath','usejsme','inline_chem');
5409: my $deftex = $Apache::lonnet::deftex;
5410: if (ref($settings) eq 'HASH') {
5411: if ($settings->{'texengine'}) {
5412: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5413: $deftex = $settings->{'texengine'};
5414: }
5415: }
5416: }
5417: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5418: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5419: '<span class="LC_nobreak">'.$choices{'texengine'}.
5420: '</span></td><td class="LC_right_item">'.
5421: '<select name="texengine">'."\n";
5422: my %texoptions = (
5423: MathJax => 'MathJax',
5424: mimetex => &mt('Convert to Images'),
5425: tth => &mt('TeX to HTML'),
5426: );
5427: foreach my $renderer ('MathJax','mimetex','tth') {
5428: my $selected = '';
5429: if ($renderer eq $deftex) {
5430: $selected = ' selected="selected"';
5431: }
5432: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5433: }
5434: $mathdisp .= '</select></td></tr>'."\n";
5435: $itemcount ++;
5436: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
5437: \%choices,$itemcount);
5438: $datatable = $mathdisp.$datatable;
5439: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5440: $datatable .=
5441: '<tr'.$css_class.'><td valign="top">'.
5442: '<span class="LC_nobreak">'.$choices{'canclone'}.
5443: '</span></td><td class="LC_left_item">';
5444: my $currcanclone = 'none';
5445: my $onclick;
5446: my @cloneoptions = ('none','domain');
5447: my %clonetitles = &Apache::lonlocal::texthash (
5448: none => 'No additional course requesters',
5449: domain => "Any course requester in course's domain",
5450: instcode => 'Course requests for official courses ...',
5451: );
5452: my (%codedefaults,@code_order,@posscodes);
5453: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5454: \@code_order) eq 'ok') {
5455: if (@code_order > 0) {
5456: push(@cloneoptions,'instcode');
5457: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5458: }
5459: }
5460: if (ref($settings) eq 'HASH') {
5461: if ($settings->{'canclone'}) {
5462: if (ref($settings->{'canclone'}) eq 'HASH') {
5463: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5464: if (@code_order > 0) {
5465: $currcanclone = 'instcode';
5466: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5467: }
5468: }
5469: } elsif ($settings->{'canclone'} eq 'domain') {
5470: $currcanclone = $settings->{'canclone'};
5471: }
5472: }
5473: }
5474: foreach my $option (@cloneoptions) {
5475: my ($checked,$additional);
5476: if ($currcanclone eq $option) {
5477: $checked = ' checked="checked"';
5478: }
5479: if ($option eq 'instcode') {
5480: if (@code_order) {
5481: my $show = 'none';
5482: if ($checked) {
5483: $show = 'block';
5484: }
5485: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
5486: &mt('Institutional codes for new and cloned course have identical:').
5487: '<br />';
5488: foreach my $item (@code_order) {
5489: my $codechk;
5490: if ($checked) {
5491: if (grep(/^\Q$item\E$/,@posscodes)) {
5492: $codechk = ' checked="checked"';
5493: }
5494: }
5495: $additional .= '<label>'.
5496: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5497: $item.'</label>';
5498: }
5499: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5500: }
5501: }
5502: $datatable .=
5503: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5504: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5505: '</label> '.$additional.'</span><br />';
5506: }
5507: $datatable .= '</td>'.
5508: '</tr>';
5509: $itemcount ++;
5510: } else {
5511: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5512: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
5513: my $currusecredits = 0;
5514: my $postsubmitclient = 1;
5515: my $ltiauth = 0;
5516: my @types = ('official','unofficial','community','textbook');
5517: if (ref($settings) eq 'HASH') {
5518: if ($settings->{'ltiauth'}) {
5519: $ltiauth = 1;
5520: }
5521: $currdefresponder = $settings->{'anonsurvey_threshold'};
5522: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5523: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5524: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5525: }
5526: }
5527: if (ref($settings->{'coursecredits'}) eq 'HASH') {
5528: foreach my $type (@types) {
5529: next if ($type eq 'community');
5530: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5531: if ($defcredits{$type} ne '') {
5532: $currusecredits = 1;
5533: }
5534: }
5535: }
5536: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5537: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5538: $postsubmitclient = 0;
5539: foreach my $type (@types) {
5540: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5541: }
5542: } else {
5543: foreach my $type (@types) {
5544: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5545: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
5546: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
5547: } else {
5548: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5549: }
5550: } else {
5551: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5552: }
5553: }
5554: }
5555: } else {
5556: foreach my $type (@types) {
5557: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5558: }
5559: }
5560: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5561: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5562: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5563: }
5564: } else {
5565: foreach my $type (@types) {
5566: $currmysql{$type} = $staticdefaults{'mysqltables'};
5567: }
5568: }
5569: } else {
5570: foreach my $type (@types) {
5571: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5572: }
5573: }
5574: if (!$currdefresponder) {
5575: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
5576: } elsif ($currdefresponder < 1) {
5577: $currdefresponder = 1;
5578: }
5579: foreach my $type (@types) {
5580: if ($curruploadquota{$type} eq '') {
5581: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5582: }
5583: }
5584: $datatable .=
5585: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5586: $choices{'anonsurvey_threshold'}.
5587: '</span></td>'.
5588: '<td class="LC_right_item"><span class="LC_nobreak">'.
5589: '<input type="text" name="anonsurvey_threshold"'.
5590: ' value="'.$currdefresponder.'" size="5" /></span>'.
5591: '</td></tr>'."\n";
5592: $itemcount ++;
5593: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5594: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5595: $choices{'uploadquota'}.
5596: '</span></td>'.
5597: '<td align="right" class="LC_right_item">'.
5598: '<table><tr>';
5599: foreach my $type (@types) {
5600: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5601: '<input type="text" name="uploadquota_'.$type.'"'.
5602: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5603: }
5604: $datatable .= '</tr></table></td></tr>'."\n";
5605: $itemcount ++;
5606: my $onclick = "toggleDisplay(this.form,'credits');";
5607: my $display = 'none';
5608: if ($currusecredits) {
5609: $display = 'block';
5610: }
5611: my $additional = '<div id="credits" style="display: '.$display.'">'.
5612: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5613: foreach my $type (@types) {
5614: next if ($type eq 'community');
5615: $additional .= '<td align="center">'.&mt($type).'<br />'.
5616: '<input type="text" name="'.$type.'_credits"'.
5617: ' value="'.$defcredits{$type}.'" size="3" /></td>';
5618: }
5619: $additional .= '</tr></table></div>'."\n";
5620: %defaultchecked = ('coursecredits' => 'off');
5621: @toggles = ('coursecredits');
5622: my $current = {
5623: 'coursecredits' => $currusecredits,
5624: };
5625: (my $table,$itemcount) =
5626: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5627: \%choices,$itemcount,$onclick,$additional,'left');
5628: $datatable .= $table;
5629: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5630: my $display = 'none';
5631: if ($postsubmitclient) {
5632: $display = 'block';
5633: }
5634: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
5635: &mt('Number of seconds submit is disabled').'<br />'.
5636: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5637: '<table><tr>';
5638: foreach my $type (@types) {
5639: $additional .= '<td align="center">'.&mt($type).'<br />'.
5640: '<input type="text" name="'.$type.'_timeout" value="'.
5641: $deftimeout{$type}.'" size="5" /></td>';
5642: }
5643: $additional .= '</tr></table></div>'."\n";
5644: %defaultchecked = ('postsubmit' => 'on');
5645: @toggles = ('postsubmit');
5646: $current = {
5647: 'postsubmit' => $postsubmitclient,
5648: };
5649: ($table,$itemcount) =
5650: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5651: \%choices,$itemcount,$onclick,$additional,'left');
5652: $datatable .= $table;
5653: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5654: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5655: $choices{'mysqltables'}.
5656: '</span></td>'.
5657: '<td align="right" class="LC_right_item">'.
5658: '<table><tr>';
5659: foreach my $type (@types) {
5660: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5661: '<input type="text" name="mysqltables_'.$type.'"'.
5662: ' value="'.$currmysql{$type}.'" size="8" /></td>';
5663: }
5664: $datatable .= '</tr></table></td></tr>'."\n";
5665: $itemcount ++;
5666: %defaultchecked = ('ltiauth' => 'off');
5667: @toggles = ('ltiauth');
5668: $current = {
5669: 'ltiauth' => $ltiauth,
5670: };
5671: ($table,$itemcount) =
5672: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5673: \%choices,$itemcount,undef,undef,'left');
5674: $datatable .= $table;
5675: $itemcount ++;
5676: }
5677: $$rowtotal += $itemcount;
5678: return $datatable;
5679: }
5680:
5681: sub print_selfenrollment {
5682: my ($position,$dom,$settings,$rowtotal) = @_;
5683: my ($css_class,$datatable);
5684: my $itemcount = 1;
5685: my @types = ('official','unofficial','community','textbook');
5686: if (($position eq 'top') || ($position eq 'middle')) {
5687: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5688: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
5689: my @rows;
5690: my $key;
5691: if ($position eq 'top') {
5692: $key = 'admin';
5693: if (ref($rowsref) eq 'ARRAY') {
5694: @rows = @{$rowsref};
5695: }
5696: } elsif ($position eq 'middle') {
5697: $key = 'default';
5698: @rows = ('types','registered','approval','limit');
5699: }
5700: foreach my $row (@rows) {
5701: if (defined($titlesref->{$row})) {
5702: $itemcount ++;
5703: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5704: $datatable .= '<tr'.$css_class.'>'.
5705: '<td>'.$titlesref->{$row}.'</td>'.
5706: '<td class="LC_left_item">'.
5707: '<table><tr>';
5708: my (%current,%currentcap);
5709: if (ref($settings) eq 'HASH') {
5710: if (ref($settings->{$key}) eq 'HASH') {
5711: foreach my $type (@types) {
5712: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5713: $current{$type} = $settings->{$key}->{$type}->{$row};
5714: }
5715: if (($row eq 'limit') && ($key eq 'default')) {
5716: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5717: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5718: }
5719: }
5720: }
5721: }
5722: }
5723: my %roles = (
5724: '0' => &Apache::lonnet::plaintext('dc'),
5725: );
5726:
5727: foreach my $type (@types) {
5728: unless (($row eq 'registered') && ($key eq 'default')) {
5729: $datatable .= '<th>'.&mt($type).'</th>';
5730: }
5731: }
5732: unless (($row eq 'registered') && ($key eq 'default')) {
5733: $datatable .= '</tr><tr>';
5734: }
5735: foreach my $type (@types) {
5736: if ($type eq 'community') {
5737: $roles{'1'} = &mt('Community personnel');
5738: } else {
5739: $roles{'1'} = &mt('Course personnel');
5740: }
5741: $datatable .= '<td style="vertical-align: top">';
5742: if ($position eq 'top') {
5743: my %checked;
5744: if ($current{$type} eq '0') {
5745: $checked{'0'} = ' checked="checked"';
5746: } else {
5747: $checked{'1'} = ' checked="checked"';
5748: }
5749: foreach my $role ('1','0') {
5750: $datatable .= '<span class="LC_nobreak"><label>'.
5751: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5752: 'value="'.$role.'"'.$checked{$role}.' />'.
5753: $roles{$role}.'</label></span> ';
5754: }
5755: } else {
5756: if ($row eq 'types') {
5757: my %checked;
5758: if ($current{$type} =~ /^(all|dom)$/) {
5759: $checked{$1} = ' checked="checked"';
5760: } else {
5761: $checked{''} = ' checked="checked"';
5762: }
5763: foreach my $val ('','dom','all') {
5764: $datatable .= '<span class="LC_nobreak"><label>'.
5765: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5766: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5767: }
5768: } elsif ($row eq 'registered') {
5769: my %checked;
5770: if ($current{$type} eq '1') {
5771: $checked{'1'} = ' checked="checked"';
5772: } else {
5773: $checked{'0'} = ' checked="checked"';
5774: }
5775: foreach my $val ('0','1') {
5776: $datatable .= '<span class="LC_nobreak"><label>'.
5777: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5778: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5779: }
5780: } elsif ($row eq 'approval') {
5781: my %checked;
5782: if ($current{$type} =~ /^([12])$/) {
5783: $checked{$1} = ' checked="checked"';
5784: } else {
5785: $checked{'0'} = ' checked="checked"';
5786: }
5787: for my $val (0..2) {
5788: $datatable .= '<span class="LC_nobreak"><label>'.
5789: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5790: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5791: }
5792: } elsif ($row eq 'limit') {
5793: my %checked;
5794: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5795: $checked{$1} = ' checked="checked"';
5796: } else {
5797: $checked{'none'} = ' checked="checked"';
5798: }
5799: my $cap;
5800: if ($currentcap{$type} =~ /^\d+$/) {
5801: $cap = $currentcap{$type};
5802: }
5803: foreach my $val ('none','allstudents','selfenrolled') {
5804: $datatable .= '<span class="LC_nobreak"><label>'.
5805: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5806: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5807: }
5808: $datatable .= '<br />'.
5809: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5810: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5811: '</span>';
5812: }
5813: }
5814: $datatable .= '</td>';
5815: }
5816: $datatable .= '</tr>';
5817: }
5818: $datatable .= '</table></td></tr>';
5819: }
5820: } elsif ($position eq 'bottom') {
5821: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5822: }
5823: $$rowtotal += $itemcount;
5824: return $datatable;
5825: }
5826:
5827: sub print_validation_rows {
5828: my ($caller,$dom,$settings,$rowtotal) = @_;
5829: my ($itemsref,$namesref,$fieldsref);
5830: if ($caller eq 'selfenroll') {
5831: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5832: } elsif ($caller eq 'requestcourses') {
5833: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5834: }
5835: my %currvalidation;
5836: if (ref($settings) eq 'HASH') {
5837: if (ref($settings->{'validation'}) eq 'HASH') {
5838: %currvalidation = %{$settings->{'validation'}};
5839: }
5840: }
5841: my $datatable;
5842: my $itemcount = 0;
5843: foreach my $item (@{$itemsref}) {
5844: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5845: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5846: $namesref->{$item}.
5847: '</span></td>'.
5848: '<td class="LC_left_item">';
5849: if (($item eq 'url') || ($item eq 'button')) {
5850: $datatable .= '<span class="LC_nobreak">'.
5851: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5852: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5853: } elsif ($item eq 'fields') {
5854: my @currfields;
5855: if (ref($currvalidation{$item}) eq 'ARRAY') {
5856: @currfields = @{$currvalidation{$item}};
5857: }
5858: foreach my $field (@{$fieldsref}) {
5859: my $check = '';
5860: if (grep(/^\Q$field\E$/,@currfields)) {
5861: $check = ' checked="checked"';
5862: }
5863: $datatable .= '<span class="LC_nobreak"><label>'.
5864: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5865: ' value="'.$field.'"'.$check.' />'.$field.
5866: '</label></span> ';
5867: }
5868: } elsif ($item eq 'markup') {
5869: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
5870: $currvalidation{$item}.
5871: '</textarea>';
5872: }
5873: $datatable .= '</td></tr>'."\n";
5874: if (ref($rowtotal)) {
5875: $itemcount ++;
5876: }
5877: }
5878: if ($caller eq 'requestcourses') {
5879: my %currhash;
5880: if (ref($settings) eq 'HASH') {
5881: if (ref($settings->{'validation'}) eq 'HASH') {
5882: if ($settings->{'validation'}{'dc'} ne '') {
5883: $currhash{$settings->{'validation'}{'dc'}} = 1;
5884: }
5885: }
5886: }
5887: my $numinrow = 2;
5888: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5889: 'validationdc',%currhash);
5890: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5891: $datatable .= '<tr'.$css_class.'><td>';
5892: if ($numdc > 1) {
5893: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
5894: } else {
5895: $datatable .= &mt('Course creation processed as: ');
5896: }
5897: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
5898: $itemcount ++;
5899: }
5900: if (ref($rowtotal)) {
5901: $$rowtotal += $itemcount;
5902: }
5903: return $datatable;
5904: }
5905:
5906: sub print_passwords {
5907: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5908: my ($datatable,$css_class);
5909: my $itemcount = 0;
5910: my %titles = &Apache::lonlocal::texthash (
5911: captcha => '"Forgot Password" CAPTCHA validation',
5912: link => 'Reset link expiration (hours)',
5913: case => 'Case-sensitive usernames/e-mail',
5914: prelink => 'Information required (form 1)',
5915: postlink => 'Information required (form 2)',
5916: emailsrc => 'LON-CAPA e-mail address type(s)',
5917: customtext => 'Domain specific text (HTML)',
5918: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5919: intauth_check => 'Check bcrypt cost if authenticated',
5920: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5921: permanent => 'Permanent e-mail address',
5922: critical => 'Critical notification address',
5923: notify => 'Notification address',
5924: min => 'Minimum password length',
5925: max => 'Maximum password length',
5926: chars => 'Required characters',
5927: numsaved => 'Number of previous passwords to save and disallow reuse',
5928: );
5929: if ($position eq 'top') {
5930: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5931: my $shownlinklife = 2;
5932: my $prelink = 'both';
5933: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5934: if (ref($settings) eq 'HASH') {
5935: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5936: $shownlinklife = $settings->{resetlink};
5937: }
5938: if (ref($settings->{resetcase}) eq 'ARRAY') {
5939: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5940: }
5941: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5942: $prelink = $settings->{resetprelink};
5943: }
5944: if (ref($settings->{resetpostlink}) eq 'HASH') {
5945: %postlink = %{$settings->{resetpostlink}};
5946: }
5947: if (ref($settings->{resetemail}) eq 'ARRAY') {
5948: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5949: }
5950: if ($settings->{resetremove}) {
5951: $nostdtext = 1;
5952: }
5953: if ($settings->{resetcustom}) {
5954: $customurl = $settings->{resetcustom};
5955: }
5956: } else {
5957: if (ref($types) eq 'ARRAY') {
5958: foreach my $item (@{$types}) {
5959: $casesens{$item} = 1;
5960: $postlink{$item} = ['username','email'];
5961: }
5962: }
5963: $casesens{'default'} = 1;
5964: $postlink{'default'} = ['username','email'];
5965: $prelink = 'both';
5966: %emailsrc = (
5967: permanent => 1,
5968: critical => 1,
5969: notify => 1,
5970: );
5971: }
5972: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5973: $itemcount ++;
5974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5975: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5976: '<td class="LC_left_item">'.
5977: '<input type="textbox" value="'.$shownlinklife.'" '.
5978: 'name="passwords_link" size="3" /></td></tr>';
5979: $itemcount ++;
5980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5981: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5982: '<td class="LC_left_item">';
5983: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5984: foreach my $item (@{$types}) {
5985: my $checkedcase;
5986: if ($casesens{$item}) {
5987: $checkedcase = ' checked="checked"';
5988: }
5989: $datatable .= '<span class="LC_nobreak"><label>'.
5990: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5991: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
5992: '</span> ';
5993: }
5994: }
5995: my $checkedcase;
5996: if ($casesens{'default'}) {
5997: $checkedcase = ' checked="checked"';
5998: }
5999: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6000: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6001: $othertitle.'</label></span></td>';
6002: $itemcount ++;
6003: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6004: my %checkedpre = (
6005: both => ' checked="checked"',
6006: either => '',
6007: );
6008: if ($prelink eq 'either') {
6009: $checkedpre{either} = ' checked="checked"';
6010: $checkedpre{both} = '';
6011: }
6012: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6013: '<td class="LC_left_item"><span class="LC_nobreak">'.
6014: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6015: &mt('Both username and e-mail address').'</label></span> '.
6016: '<span class="LC_nobreak"><label>'.
6017: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6018: &mt('Either username or e-mail address').'</label></span></td></tr>';
6019: $itemcount ++;
6020: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6021: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6022: '<td class="LC_left_item">';
6023: my %postlinked;
6024: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6025: foreach my $item (@{$types}) {
6026: undef(%postlinked);
6027: $datatable .= '<fieldset style="display: inline-block;">'.
6028: '<legend>'.$usertypes->{$item}.'</legend>';
6029: if (ref($postlink{$item}) eq 'ARRAY') {
6030: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6031: }
6032: foreach my $field ('email','username') {
6033: my $checked;
6034: if ($postlinked{$field}) {
6035: $checked = ' checked="checked"';
6036: }
6037: $datatable .= '<span class="LC_nobreak"><label>'.
6038: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6039: $field.'"'.$checked.' />'.$field.'</label>'.
6040: '<span> ';
6041: }
6042: $datatable .= '</fieldset>';
6043: }
6044: }
6045: if (ref($postlink{'default'}) eq 'ARRAY') {
6046: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6047: }
6048: $datatable .= '<fieldset style="display: inline-block;">'.
6049: '<legend>'.$othertitle.'</legend>';
6050: foreach my $field ('email','username') {
6051: my $checked;
6052: if ($postlinked{$field}) {
6053: $checked = ' checked="checked"';
6054: }
6055: $datatable .= '<span class="LC_nobreak"><label>'.
6056: '<input type="checkbox" name="passwords_postlink_default" value="'.
6057: $field.'"'.$checked.' />'.$field.'</label>'.
6058: '<span> ';
6059: }
6060: $datatable .= '</fieldset></td></tr>';
6061: $itemcount ++;
6062: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6063: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6064: '<td class="LC_left_item">';
6065: foreach my $type ('permanent','critical','notify') {
6066: my $checkedemail;
6067: if ($emailsrc{$type}) {
6068: $checkedemail = ' checked="checked"';
6069: }
6070: $datatable .= '<span class="LC_nobreak"><label>'.
6071: '<input type="checkbox" name="passwords_emailsrc" value="'.
6072: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6073: '<span> ';
6074: }
6075: $datatable .= '</td></tr>';
6076: $itemcount ++;
6077: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6078: my $switchserver = &check_switchserver($dom,$confname);
6079: my ($showstd,$noshowstd);
6080: if ($nostdtext) {
6081: $noshowstd = ' checked="checked"';
6082: } else {
6083: $showstd = ' checked="checked"';
6084: }
6085: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6086: '<td class="LC_left_item"><span class="LC_nobreak">'.
6087: &mt('Retain standard text:').
6088: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6089: &mt('Yes').'</label>'.' '.
6090: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6091: &mt('No').'</label></span><br />'.
6092: '<span class="LC_fontsize_small">'.
6093: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6094: &mt('Include custom text:');
6095: if ($customurl) {
6096: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
6097: undef,undef,undef,undef,'background-color:#ffffff');
6098: $datatable .= '<span class="LC_nobreak"> '.$link.
6099: '<label><input type="checkbox" name="passwords_custom_del"'.
6100: ' value="1" />'.&mt('Delete?').'</label></span>'.
6101: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6102: }
6103: if ($switchserver) {
6104: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6105: } else {
6106: $datatable .='<span class="LC_nobreak"> '.
6107: '<input type="file" name="passwords_customfile" /></span>';
6108: }
6109: $datatable .= '</td></tr>';
6110: } elsif ($position eq 'middle') {
6111: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6112: my @items = ('intauth_cost','intauth_check','intauth_switch');
6113: my %defaults;
6114: if (ref($domconf{'defaults'}) eq 'HASH') {
6115: %defaults = %{$domconf{'defaults'}};
6116: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6117: $defaults{'intauth_cost'} = 10;
6118: }
6119: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6120: $defaults{'intauth_check'} = 0;
6121: }
6122: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6123: $defaults{'intauth_switch'} = 0;
6124: }
6125: } else {
6126: %defaults = (
6127: 'intauth_cost' => 10,
6128: 'intauth_check' => 0,
6129: 'intauth_switch' => 0,
6130: );
6131: }
6132: foreach my $item (@items) {
6133: if ($itemcount%2) {
6134: $css_class = '';
6135: } else {
6136: $css_class = ' class="LC_odd_row" ';
6137: }
6138: $datatable .= '<tr'.$css_class.'>'.
6139: '<td><span class="LC_nobreak">'.$titles{$item}.
6140: '</span></td><td class="LC_left_item" colspan="3">';
6141: if ($item eq 'intauth_switch') {
6142: my @options = (0,1,2);
6143: my %optiondesc = &Apache::lonlocal::texthash (
6144: 0 => 'No',
6145: 1 => 'Yes',
6146: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6147: );
6148: $datatable .= '<table width="100%">';
6149: foreach my $option (@options) {
6150: my $checked = ' ';
6151: if ($defaults{$item} eq $option) {
6152: $checked = ' checked="checked"';
6153: }
6154: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6155: '<label><input type="radio" name="'.$item.
6156: '" value="'.$option.'"'.$checked.' />'.
6157: $optiondesc{$option}.'</label></span></td></tr>';
6158: }
6159: $datatable .= '</table>';
6160: } elsif ($item eq 'intauth_check') {
6161: my @options = (0,1,2);
6162: my %optiondesc = &Apache::lonlocal::texthash (
6163: 0 => 'No',
6164: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6165: 2 => 'Yes, disallow login if stored cost is less than domain default',
6166: );
6167: $datatable .= '<table width="100%">';
6168: foreach my $option (@options) {
6169: my $checked = ' ';
6170: my $onclick;
6171: if ($defaults{$item} eq $option) {
6172: $checked = ' checked="checked"';
6173: }
6174: if ($option == 2) {
6175: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6176: }
6177: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6178: '<label><input type="radio" name="'.$item.
6179: '" value="'.$option.'"'.$checked.$onclick.' />'.
6180: $optiondesc{$option}.'</label></span></td></tr>';
6181: }
6182: $datatable .= '</table>';
6183: } else {
6184: $datatable .= '<input type="text" name="'.$item.'" value="'.
6185: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6186: }
6187: $datatable .= '</td></tr>';
6188: $itemcount ++;
6189: }
6190: } elsif ($position eq 'lower') {
6191: $datatable .= &password_rules('passwords',\$itemcount,$settings);
6192: } else {
6193: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6194: my %ownerchg = (
6195: by => {},
6196: for => {},
6197: );
6198: my %ownertitles = &Apache::lonlocal::texthash (
6199: by => 'Course owner status(es) allowed',
6200: for => 'Student status(es) allowed',
6201: );
6202: if (ref($settings) eq 'HASH') {
6203: if (ref($settings->{crsownerchg}) eq 'HASH') {
6204: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6205: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6206: }
6207: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6208: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6209: }
6210: }
6211: }
6212: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6213: $datatable .= '<tr '.$css_class.'>'.
6214: '<td>'.
6215: &mt('Requirements').'<ul>'.
6216: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6217: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6218: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6219: '<li>'.&mt('User, course, and student share same domain').'</li>'.
6220: '</ul>'.
6221: '</td>'.
6222: '<td class="LC_left_item">';
6223: foreach my $item ('by','for') {
6224: $datatable .= '<fieldset style="display: inline-block;">'.
6225: '<legend>'.$ownertitles{$item}.'</legend>';
6226: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6227: foreach my $type (@{$types}) {
6228: my $checked;
6229: if ($ownerchg{$item}{$type}) {
6230: $checked = ' checked="checked"';
6231: }
6232: $datatable .= '<span class="LC_nobreak"><label>'.
6233: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6234: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
6235: '</span> ';
6236: }
6237: }
6238: my $checked;
6239: if ($ownerchg{$item}{'default'}) {
6240: $checked = ' checked="checked"';
6241: }
6242: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6243: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6244: $othertitle.'</label></span></fieldset>';
6245: }
6246: $datatable .= '</td></tr>';
6247: }
6248: return $datatable;
6249: }
6250:
6251: sub password_rules {
6252: my ($prefix,$itemcountref,$settings) = @_;
6253: my ($min,$max,%chars,$numsaved,$numinrow);
6254: my %titles;
6255: if ($prefix eq 'passwords') {
6256: %titles = &Apache::lonlocal::texthash (
6257: min => 'Minimum password length',
6258: max => 'Maximum password length',
6259: chars => 'Required characters',
6260: );
6261: } elsif ($prefix eq 'secrets') {
6262: %titles = &Apache::lonlocal::texthash (
6263: min => 'Minimum secret length',
6264: max => 'Maximum secret length',
6265: chars => 'Required characters',
6266: );
6267: }
6268: $min = $Apache::lonnet::passwdmin;
6269: my $datatable;
6270: my $itemcount;
6271: if (ref($itemcountref)) {
6272: $itemcount = $$itemcountref;
6273: }
6274: if (ref($settings) eq 'HASH') {
6275: if ($settings->{min}) {
6276: $min = $settings->{min};
6277: }
6278: if ($settings->{max}) {
6279: $max = $settings->{max};
6280: }
6281: if (ref($settings->{chars}) eq 'ARRAY') {
6282: map { $chars{$_} = 1; } (@{$settings->{chars}});
6283: }
6284: if ($prefix eq 'passwords') {
6285: if ($settings->{numsaved}) {
6286: $numsaved = $settings->{numsaved};
6287: }
6288: }
6289: }
6290: my %rulenames = &Apache::lonlocal::texthash(
6291: uc => 'At least one upper case letter',
6292: lc => 'At least one lower case letter',
6293: num => 'At least one number',
6294: spec => 'At least one non-alphanumeric',
6295: );
6296: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6297: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6298: '<td class="LC_left_item"><span class="LC_nobreak">'.
6299: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
6300: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6301: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
6302: '</span></td></tr>';
6303: $itemcount ++;
6304: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6305: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6306: '<td class="LC_left_item"><span class="LC_nobreak">'.
6307: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
6308: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6309: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6310: '</span></td></tr>';
6311: $itemcount ++;
6312: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6313: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6314: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6315: '</span></td>';
6316: my $numinrow = 2;
6317: my @possrules = ('uc','lc','num','spec');
6318: $datatable .= '<td class="LC_left_item"><table>';
6319: for (my $i=0; $i<@possrules; $i++) {
6320: my ($rem,$checked);
6321: if ($chars{$possrules[$i]}) {
6322: $checked = ' checked="checked"';
6323: }
6324: $rem = $i%($numinrow);
6325: if ($rem == 0) {
6326: if ($i > 0) {
6327: $datatable .= '</tr>';
6328: }
6329: $datatable .= '<tr>';
6330: }
6331: $datatable .= '<td><span class="LC_nobreak"><label>'.
6332: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6333: $rulenames{$possrules[$i]}.'</label></span></td>';
6334: }
6335: my $rem = @possrules%($numinrow);
6336: my $colsleft = $numinrow - $rem;
6337: if ($colsleft > 1 ) {
6338: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6339: ' </td>';
6340: } elsif ($colsleft == 1) {
6341: $datatable .= '<td class="LC_left_item"> </td>';
6342: }
6343: $datatable .='</table></td></tr>';
6344: $itemcount ++;
6345: if ($prefix eq 'passwords') {
6346: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
6347: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6348: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6349: '<td class="LC_left_item"><span class="LC_nobreak">'.
6350: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
6351: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6352: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6353: '</span></td></tr>';
6354: $itemcount ++;
6355: }
6356: if (ref($itemcountref)) {
6357: $$itemcountref += $itemcount;
6358: }
6359: return $datatable;
6360: }
6361:
6362: sub print_wafproxy {
6363: my ($position,$dom,$settings,$rowtotal) = @_;
6364: my $css_class;
6365: my $itemcount = 0;
6366: my $datatable;
6367: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6368: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
6369: my %lt = &wafproxy_titles();
6370: foreach my $server (sort(keys(%servers))) {
6371: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
6372: next if ($serverhome eq '');
6373: my $serverdom;
6374: if ($serverhome ne $server) {
6375: $serverdom = &Apache::lonnet::host_domain($serverhome);
6376: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
6377: $othercontrol{$server} = $serverdom;
6378: }
6379: } else {
6380: $serverdom = &Apache::lonnet::host_domain($server);
6381: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
6382: if ($serverdom ne $dom) {
6383: $othercontrol{$server} = $serverdom;
6384: } else {
6385: $setdom = 1;
6386: if (ref($settings) eq 'HASH') {
6387: if (ref($settings->{'alias'}) eq 'HASH') {
6388: $aliases{$dom} = $settings->{'alias'};
6389: if ($aliases{$dom} ne '') {
6390: $showdom = 1;
6391: }
6392: }
6393: if (ref($settings->{'saml'}) eq 'HASH') {
6394: $saml{$dom} = $settings->{'saml'};
6395: }
6396: }
6397: }
6398: }
6399: }
6400: if ($setdom) {
6401: %{$values{$dom}} = ();
6402: if (ref($settings) eq 'HASH') {
6403: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6404: $values{$dom}{$item} = $settings->{$item};
6405: }
6406: }
6407: }
6408: if (keys(%othercontrol)) {
6409: %otherdoms = reverse(%othercontrol);
6410: foreach my $domain (keys(%otherdoms)) {
6411: %{$values{$domain}} = ();
6412: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
6413: if (ref($config{'wafproxy'}) eq 'HASH') {
6414: $aliases{$domain} = $config{'wafproxy'}{'alias'};
6415: if (exists($config{'wafproxy'}{'saml'})) {
6416: $saml{$domain} = $config{'wafproxy'}{'saml'};
6417: }
6418: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6419: $values{$domain}{$item} = $config{'wafproxy'}{$item};
6420: }
6421: }
6422: }
6423: }
6424: if ($position eq 'top') {
6425: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6426: my %aliasinfo;
6427: foreach my $server (sort(keys(%servers))) {
6428: $itemcount ++;
6429: my $dom_in_effect;
6430: my $aliasrows = '<tr>'.
6431: '<td class="LC_left_item" style="vertical-align: baseline;">'.
6432: &mt('Hostname').': '.
6433: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
6434: if ($othercontrol{$server}) {
6435: $dom_in_effect = $othercontrol{$server};
6436: my ($current,$forsaml);
6437: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
6438: $current = $aliases{$dom_in_effect}{$server};
6439: }
6440: if (ref($saml{$dom_in_effect}) eq 'HASH') {
6441: if ($saml{$dom_in_effect}{$server}) {
6442: $forsaml = 1;
6443: }
6444: }
6445: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6446: &mt('Alias').': ';
6447: if ($current) {
6448: $aliasrows .= $current;
6449: if ($forsaml) {
6450: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
6451: }
6452: } else {
6453: $aliasrows .= &mt('None');
6454: }
6455: $aliasrows .= ' <span class="LC_small">('.
6456: &mt('controlled by domain: [_1]',
6457: '<b>'.$dom_in_effect.'</b>').')</span></td>';
6458: } else {
6459: $dom_in_effect = $dom;
6460: my ($current,$samlon,$samloff);
6461: $samloff = ' checked="checked"';
6462: if (ref($aliases{$dom}) eq 'HASH') {
6463: if ($aliases{$dom}{$server}) {
6464: $current = $aliases{$dom}{$server};
6465: }
6466: }
6467: if (ref($saml{$dom}) eq 'HASH') {
6468: if ($saml{$dom}{$server}) {
6469: $samlon = $samloff;
6470: undef($samloff);
6471: }
6472: }
6473: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6474: &mt('Alias').': '.
6475: '<input type="text" name="wafproxy_alias_'.$server.'" '.
6476: 'value="'.$current.'" size="30" />'.
6477: (' 'x2).'<span class="LC_nobreak">'.
6478: &mt('Alias used for SSO Auth').': <label>'.
6479: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
6480: &mt('No').'</label> <label>'.
6481: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
6482: &mt('Yes').'</label></span>'.
6483: '</td>';
6484: }
6485: $aliasrows .= '</tr>';
6486: $aliasinfo{$dom_in_effect} .= $aliasrows;
6487: }
6488: if ($aliasinfo{$dom}) {
6489: my ($onclick,$wafon,$wafoff,$showtable);
6490: $onclick = ' onclick="javascript:toggleWAF();"';
6491: $wafoff = ' checked="checked"';
6492: $showtable = ' style="display:none";';
6493: if ($showdom) {
6494: $wafon = $wafoff;
6495: $wafoff = '';
6496: $showtable = ' style="display:inline;"';
6497: }
6498: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6499: $datatable = '<tr'.$css_class.'>'.
6500: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
6501: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
6502: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
6503: &mt('Yes').'</label>'.(' 'x2).'<label>'.
6504: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
6505: &mt('No').'</label></span></td>'.
6506: '<td class="LC_left_item">'.
6507: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
6508: '</table></td></tr>';
6509: $itemcount++;
6510: }
6511: if (keys(%otherdoms)) {
6512: foreach my $key (sort(keys(%otherdoms))) {
6513: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6514: $datatable .= '<tr'.$css_class.'>'.
6515: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
6516: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
6517: '</table></td></tr>';
6518: $itemcount++;
6519: }
6520: }
6521: } else {
6522: my %ip_methods = &remoteip_methods();
6523: if ($setdom) {
6524: $itemcount ++;
6525: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6526: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
6527: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
6528: $wafstyle = ' style="display:none;"';
6529: $nowafstyle = ' style="display:table-row;"';
6530: $currwafdisplay = ' style="display: none"';
6531: $wafrangestyle = ' style="display: none"';
6532: $curr_remotip = 'n';
6533: $ssltossl = ' checked="checked"';
6534: if ($showdom) {
6535: $wafstyle = ' style="display:table-row;"';
6536: $nowafstyle = ' style="display:none;"';
6537: if (keys(%{$values{$dom}})) {
6538: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
6539: $curr_remotip = $values{$dom}{remoteip};
6540: }
6541: if ($curr_remotip eq 'h') {
6542: $currwafdisplay = ' style="display:table-row"';
6543: $wafrangestyle = ' style="display:inline-block;"';
6544: }
6545: if ($values{$dom}{'sslopt'}) {
6546: $alltossl = ' checked="checked"';
6547: $ssltossl = '';
6548: }
6549: }
6550: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
6551: $vpndircheck = ' checked="checked"';
6552: $currwafvpn = ' style="display:table-row;"';
6553: $wafrangestyle = ' style="display:inline-block;"';
6554: } else {
6555: $vpnaliascheck = ' checked="checked"';
6556: $currwafvpn = ' style="display:none;"';
6557: }
6558: }
6559: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6560: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
6561: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
6562: '</tr>'.
6563: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6564: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
6565: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
6566: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
6567: &mt('Range(s) stored in CIDR notation').'</div></td>'.
6568: '<td class="LC_left_item"><table>'.
6569: '<tr>'.
6570: '<td valign="top">'.$lt{'remoteip'}.': '.
6571: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
6572: foreach my $option ('m','h','n') {
6573: my $sel;
6574: if ($option eq $curr_remotip) {
6575: $sel = ' selected="selected"';
6576: }
6577: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
6578: $ip_methods{$option}.'</option>';
6579: }
6580: $datatable .= '</select></td></tr>'."\n".
6581: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
6582: $lt{'ipheader'}.': '.
6583: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
6584: 'name="wafproxy_ipheader" />'.
6585: '</td></tr>'."\n".
6586: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
6587: $lt{'trusted'}.':<br />'.
6588: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
6589: $values{$dom}{'trusted'}.'</textarea>'.
6590: '</td></tr>'."\n".
6591: '<tr><td><hr /></td></tr>'."\n".
6592: '<tr>'.
6593: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
6594: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
6595: $lt{'vpndirect'}.'</label>'.(' 'x2).
6596: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
6597: $lt{'vpnaliased'}.'</label></span></td></tr>';
6598: foreach my $item ('vpnint','vpnext') {
6599: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
6600: '<td valign="top">'.$lt{$item}.':<br />'.
6601: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
6602: $values{$dom}{$item}.'</textarea>'.
6603: '</td></tr>'."\n";
6604: }
6605: $datatable .= '<tr><td><hr /></td></tr>'."\n".
6606: '<tr>'.
6607: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
6608: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
6609: $lt{'alltossl'}.'</label>'.(' 'x2).
6610: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
6611: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
6612: '</table></td></tr>';
6613: }
6614: if (keys(%otherdoms)) {
6615: foreach my $domain (sort(keys(%otherdoms))) {
6616: $itemcount ++;
6617: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6618: $datatable .= '<tr'.$css_class.'>'.
6619: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
6620: '<td class="LC_left_item"><table>';
6621: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
6622: my $showval = &mt('None');
6623: if ($item eq 'ssl') {
6624: $showval = $lt{'ssltossl'};
6625: }
6626: if ($values{$domain}{$item}) {
6627: $showval = $values{$domain}{$item};
6628: if ($item eq 'ssl') {
6629: $showval = $lt{'alltossl'};
6630: } elsif ($item eq 'remoteip') {
6631: $showval = $ip_methods{$values{$domain}{$item}};
6632: }
6633: }
6634: $datatable .= '<tr>'.
6635: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
6636: }
6637: $datatable .= '</table></td></tr>';
6638: }
6639: }
6640: }
6641: $$rowtotal += $itemcount;
6642: return $datatable;
6643: }
6644:
6645: sub wafproxy_titles {
6646: return &Apache::lonlocal::texthash(
6647: remoteip => "Method for determining user's IP",
6648: ipheader => 'Request header containing remote IP',
6649: trusted => 'Trusted IP range(s)',
6650: vpnaccess => 'Access from institutional VPN',
6651: vpndirect => 'via regular hostname (no WAF)',
6652: vpnaliased => 'via aliased hostname (WAF)',
6653: vpnint => 'Internal IP Range(s) for VPN sessions',
6654: vpnext => 'IP Range(s) for backend WAF connections',
6655: sslopt => 'Forwarding http/https',
6656: alltossl => 'WAF forwards both http and https requests to https',
6657: ssltossl => 'WAF forwards http requests to http and https to https',
6658: );
6659: }
6660:
6661: sub remoteip_methods {
6662: return &Apache::lonlocal::texthash(
6663: m => 'Use Apache mod_remoteip',
6664: h => 'Use headers parsed by LON-CAPA',
6665: n => 'Not in use',
6666: );
6667: }
6668:
6669: sub print_usersessions {
6670: my ($position,$dom,$settings,$rowtotal) = @_;
6671: my ($css_class,$datatable,%checked,%choices);
6672: my (%by_ip,%by_location,@intdoms);
6673: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
6674:
6675: my @alldoms = &Apache::lonnet::all_domains();
6676: my %serverhomes = %Apache::lonnet::serverhomeIDs;
6677: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6678: my %altids = &id_for_thisdom(%servers);
6679: my $itemcount = 1;
6680: if ($position eq 'top') {
6681: if (keys(%serverhomes) > 1) {
6682: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
6683: my ($curroffloadnow,$curroffloadoth);
6684: if (ref($settings) eq 'HASH') {
6685: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6686: $curroffloadnow = $settings->{'offloadnow'};
6687: }
6688: if (ref($settings->{'offloadoth'}) eq 'HASH') {
6689: $curroffloadoth = $settings->{'offloadoth'};
6690: }
6691: }
6692: my $other_insts = scalar(keys(%by_location));
6693: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
6694: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
6695: } else {
6696: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
6697: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
6698: }
6699: } else {
6700: if (keys(%by_location) == 0) {
6701: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
6702: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
6703: } else {
6704: my %lt = &usersession_titles();
6705: my $numinrow = 5;
6706: my $prefix;
6707: my @types;
6708: if ($position eq 'bottom') {
6709: $prefix = 'remote';
6710: @types = ('version','excludedomain','includedomain');
6711: } else {
6712: $prefix = 'hosted';
6713: @types = ('excludedomain','includedomain');
6714: }
6715: my (%current,%checkedon,%checkedoff);
6716: my @lcversions = &Apache::lonnet::all_loncaparevs();
6717: my @locations = sort(keys(%by_location));
6718: foreach my $type (@types) {
6719: $checkedon{$type} = '';
6720: $checkedoff{$type} = ' checked="checked"';
6721: }
6722: if (ref($settings) eq 'HASH') {
6723: if (ref($settings->{$prefix}) eq 'HASH') {
6724: foreach my $key (keys(%{$settings->{$prefix}})) {
6725: $current{$key} = $settings->{$prefix}{$key};
6726: if ($key eq 'version') {
6727: if ($current{$key} ne '') {
6728: $checkedon{$key} = ' checked="checked"';
6729: $checkedoff{$key} = '';
6730: }
6731: } elsif (ref($current{$key}) eq 'ARRAY') {
6732: $checkedon{$key} = ' checked="checked"';
6733: $checkedoff{$key} = '';
6734: }
6735: }
6736: }
6737: }
6738: foreach my $type (@types) {
6739: next if ($type ne 'version' && !@locations);
6740: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6741: $datatable .= '<tr'.$css_class.'>
6742: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
6743: <span class="LC_nobreak">
6744: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6745: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6746: if ($type eq 'version') {
6747: my $selector = '<select name="'.$prefix.'_version">';
6748: foreach my $version (@lcversions) {
6749: my $selected = '';
6750: if ($current{'version'} eq $version) {
6751: $selected = ' selected="selected"';
6752: }
6753: $selector .= ' <option value="'.$version.'"'.
6754: $selected.'>'.$version.'</option>';
6755: }
6756: $selector .= '</select> ';
6757: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6758: } else {
6759: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6760: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6761: ' />'.(' 'x2).
6762: '<input type="button" value="'.&mt('uncheck all').'" '.
6763: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6764: "\n".
6765: '</div><div><table>';
6766: my $rem;
6767: for (my $i=0; $i<@locations; $i++) {
6768: my ($showloc,$value,$checkedtype);
6769: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
6770: my $ip = $by_location{$locations[$i]}->[0];
6771: if (ref($by_ip{$ip}) eq 'ARRAY') {
6772: $value = join(':',@{$by_ip{$ip}});
6773: $showloc = join(', ',@{$by_ip{$ip}});
6774: if (ref($current{$type}) eq 'ARRAY') {
6775: foreach my $loc (@{$by_ip{$ip}}) {
6776: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6777: $checkedtype = ' checked="checked"';
6778: last;
6779: }
6780: }
6781: }
6782: }
6783: }
6784: $rem = $i%($numinrow);
6785: if ($rem == 0) {
6786: if ($i > 0) {
6787: $datatable .= '</tr>';
6788: }
6789: $datatable .= '<tr>';
6790: }
6791: $datatable .= '<td class="LC_left_item">'.
6792: '<span class="LC_nobreak"><label>'.
6793: '<input type="checkbox" name="'.$prefix.'_'.$type.
6794: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6795: '</label></span></td>';
6796: }
6797: $rem = @locations%($numinrow);
6798: my $colsleft = $numinrow - $rem;
6799: if ($colsleft > 1 ) {
6800: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6801: ' </td>';
6802: } elsif ($colsleft == 1) {
6803: $datatable .= '<td class="LC_left_item"> </td>';
6804: }
6805: $datatable .= '</tr></table>';
6806: }
6807: $datatable .= '</td></tr>';
6808: $itemcount ++;
6809: }
6810: }
6811: }
6812: $$rowtotal += $itemcount;
6813: return $datatable;
6814: }
6815:
6816: sub build_location_hashes {
6817: my ($intdoms,$by_ip,$by_location) = @_;
6818: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
6819: (ref($by_location) eq 'HASH'));
6820: my %iphost = &Apache::lonnet::get_iphost();
6821: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6822: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6823: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6824: foreach my $id (@{$iphost{$primary_ip}}) {
6825: my $intdom = &Apache::lonnet::internet_dom($id);
6826: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6827: push(@{$intdoms},$intdom);
6828: }
6829: }
6830: }
6831: foreach my $ip (keys(%iphost)) {
6832: if (ref($iphost{$ip}) eq 'ARRAY') {
6833: foreach my $id (@{$iphost{$ip}}) {
6834: my $location = &Apache::lonnet::internet_dom($id);
6835: if ($location) {
6836: next if (grep(/^\Q$location\E$/,@{$intdoms}));
6837: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6838: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6839: push(@{$by_ip->{$ip}},$location);
6840: }
6841: } else {
6842: $by_ip->{$ip} = [$location];
6843: }
6844: }
6845: }
6846: }
6847: }
6848: foreach my $ip (sort(keys(%{$by_ip}))) {
6849: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6850: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6851: my $first = $by_ip->{$ip}->[0];
6852: if (ref($by_location->{$first}) eq 'ARRAY') {
6853: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6854: push(@{$by_location->{$first}},$ip);
6855: }
6856: } else {
6857: $by_location->{$first} = [$ip];
6858: }
6859: }
6860: }
6861: return;
6862: }
6863:
6864: sub current_offloads_to {
6865: my ($dom,$settings,$servers) = @_;
6866: my (%spareid,%otherdomconfigs);
6867: if (ref($servers) eq 'HASH') {
6868: foreach my $lonhost (sort(keys(%{$servers}))) {
6869: my $gotspares;
6870: if (ref($settings) eq 'HASH') {
6871: if (ref($settings->{'spares'}) eq 'HASH') {
6872: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6873: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6874: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6875: $gotspares = 1;
6876: }
6877: }
6878: }
6879: unless ($gotspares) {
6880: my $gotspares;
6881: my $serverhomeID =
6882: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6883: my $serverhomedom =
6884: &Apache::lonnet::host_domain($serverhomeID);
6885: if ($serverhomedom ne $dom) {
6886: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6887: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6888: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6889: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6890: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6891: $gotspares = 1;
6892: }
6893: }
6894: } else {
6895: $otherdomconfigs{$serverhomedom} =
6896: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6897: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6898: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6899: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6900: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6901: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6902: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6903: $gotspares = 1;
6904: }
6905: }
6906: }
6907: }
6908: }
6909: }
6910: }
6911: unless ($gotspares) {
6912: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6913: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6914: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6915: } else {
6916: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6917: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6918: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6919: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6920: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6921: } else {
6922: my %what = (
6923: spareid => 1,
6924: );
6925: my ($result,$returnhash) =
6926: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6927: if ($result eq 'ok') {
6928: if (ref($returnhash) eq 'HASH') {
6929: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6930: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6931: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6932: }
6933: }
6934: }
6935: }
6936: }
6937: }
6938: }
6939: }
6940: return %spareid;
6941: }
6942:
6943: sub spares_row {
6944: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6945: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
6946: my $css_class;
6947: my $numinrow = 4;
6948: my $itemcount = 1;
6949: my $datatable;
6950: my %typetitles = &sparestype_titles();
6951: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
6952: foreach my $server (sort(keys(%{$servers}))) {
6953: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6954: my ($othercontrol,$serverdom);
6955: if ($serverhome ne $server) {
6956: $serverdom = &Apache::lonnet::host_domain($serverhome);
6957: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6958: } else {
6959: $serverdom = &Apache::lonnet::host_domain($server);
6960: if ($serverdom ne $dom) {
6961: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6962: }
6963: }
6964: next unless (ref($spareid->{$server}) eq 'HASH');
6965: my ($checkednow,$checkedoth);
6966: if (ref($curroffloadnow) eq 'HASH') {
6967: if ($curroffloadnow->{$server}) {
6968: $checkednow = ' checked="checked"';
6969: }
6970: }
6971: if (ref($curroffloadoth) eq 'HASH') {
6972: if ($curroffloadoth->{$server}) {
6973: $checkedoth = ' checked="checked"';
6974: }
6975: }
6976: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6977: $datatable .= '<tr'.$css_class.'>
6978: <td rowspan="2">
6979: <span class="LC_nobreak">'.
6980: &mt('[_1] when busy, offloads to:'
6981: ,'<b>'.$server.'</b>').'</span><br />'.
6982: '<span class="LC_nobreak">'."\n".
6983: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6984: ' '.&mt('Switch any active user on next access').'</label></span>'.
6985: "\n";
6986: if ($other_insts) {
6987: $datatable .= '<br />'.
6988: '<span class="LC_nobreak">'."\n".
6989: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6990: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6991: "\n";
6992: }
6993: my (%current,%canselect);
6994: my @choices =
6995: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6996: foreach my $type ('primary','default') {
6997: if (ref($spareid->{$server}) eq 'HASH') {
6998: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6999: my @spares = @{$spareid->{$server}{$type}};
7000: if (@spares > 0) {
7001: if ($othercontrol) {
7002: $current{$type} = join(', ',@spares);
7003: } else {
7004: $current{$type} .= '<table>';
7005: my $numspares = scalar(@spares);
7006: for (my $i=0; $i<@spares; $i++) {
7007: my $rem = $i%($numinrow);
7008: if ($rem == 0) {
7009: if ($i > 0) {
7010: $current{$type} .= '</tr>';
7011: }
7012: $current{$type} .= '<tr>';
7013: }
7014: $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'".');" /> '.
7015: $spareid->{$server}{$type}[$i].
7016: '</label></td>'."\n";
7017: }
7018: my $rem = @spares%($numinrow);
7019: my $colsleft = $numinrow - $rem;
7020: if ($colsleft > 1 ) {
7021: $current{$type} .= '<td colspan="'.$colsleft.
7022: '" class="LC_left_item">'.
7023: ' </td>';
7024: } elsif ($colsleft == 1) {
7025: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
7026: }
7027: $current{$type} .= '</tr></table>';
7028: }
7029: }
7030: }
7031: if ($current{$type} eq '') {
7032: $current{$type} = &mt('None specified');
7033: }
7034: if ($othercontrol) {
7035: if ($type eq 'primary') {
7036: $canselect{$type} = $othercontrol;
7037: }
7038: } else {
7039: $canselect{$type} =
7040: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7041: '<select name="newspare_'.$type.'_'.$server.'" '.
7042: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7043: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7044: if (@choices > 0) {
7045: foreach my $lonhost (@choices) {
7046: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7047: }
7048: }
7049: $canselect{$type} .= '</select>'."\n";
7050: }
7051: } else {
7052: $current{$type} = &mt('Could not be determined');
7053: if ($type eq 'primary') {
7054: $canselect{$type} = $othercontrol;
7055: }
7056: }
7057: if ($type eq 'default') {
7058: $datatable .= '<tr'.$css_class.'>';
7059: }
7060: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7061: '<td>'.$current{$type}.'</td>'."\n".
7062: '<td>'.$canselect{$type}.'</td></tr>'."\n";
7063: }
7064: $itemcount ++;
7065: }
7066: }
7067: $$rowtotal += $itemcount;
7068: return $datatable;
7069: }
7070:
7071: sub possible_newspares {
7072: my ($server,$currspares,$serverhomes,$altids) = @_;
7073: my $serverhostname = &Apache::lonnet::hostname($server);
7074: my %excluded;
7075: if ($serverhostname ne '') {
7076: %excluded = (
7077: $serverhostname => 1,
7078: );
7079: }
7080: if (ref($currspares) eq 'HASH') {
7081: foreach my $type (keys(%{$currspares})) {
7082: if (ref($currspares->{$type}) eq 'ARRAY') {
7083: if (@{$currspares->{$type}} > 0) {
7084: foreach my $curr (@{$currspares->{$type}}) {
7085: my $hostname = &Apache::lonnet::hostname($curr);
7086: $excluded{$hostname} = 1;
7087: }
7088: }
7089: }
7090: }
7091: }
7092: my @choices;
7093: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7094: if (keys(%{$serverhomes}) > 1) {
7095: foreach my $name (sort(keys(%{$serverhomes}))) {
7096: unless ($excluded{$name}) {
7097: if (exists($altids->{$serverhomes->{$name}})) {
7098: push(@choices,$altids->{$serverhomes->{$name}});
7099: } else {
7100: push(@choices,$serverhomes->{$name});
7101: }
7102: }
7103: }
7104: }
7105: }
7106: return sort(@choices);
7107: }
7108:
7109: sub print_loadbalancing {
7110: my ($dom,$settings,$rowtotal) = @_;
7111: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7112: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7113: my $numinrow = 1;
7114: my $datatable;
7115: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7116: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
7117: if (ref($settings) eq 'HASH') {
7118: %existing = %{$settings};
7119: }
7120: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7121: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
7122: \%currtargets,\%currrules,\%currcookies);
7123: } else {
7124: return;
7125: }
7126: my ($othertitle,$usertypes,$types) =
7127: &Apache::loncommon::sorted_inst_types($dom);
7128: my $rownum = 8;
7129: if (ref($types) eq 'ARRAY') {
7130: $rownum += scalar(@{$types});
7131: }
7132: my @css_class = ('LC_odd_row','LC_even_row');
7133: my $balnum = 0;
7134: my $islast;
7135: my (@toshow,$disabledtext);
7136: if (keys(%currbalancer) > 0) {
7137: @toshow = sort(keys(%currbalancer));
7138: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7139: push(@toshow,'');
7140: }
7141: } else {
7142: @toshow = ('');
7143: $disabledtext = &mt('No existing load balancer');
7144: }
7145: foreach my $lonhost (@toshow) {
7146: if ($balnum == scalar(@toshow)-1) {
7147: $islast = 1;
7148: } else {
7149: $islast = 0;
7150: }
7151: my $cssidx = $balnum%2;
7152: my $targets_div_style = 'display: none';
7153: my $disabled_div_style = 'display: block';
7154: my $homedom_div_style = 'display: none';
7155: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
7156: '<td rowspan="'.$rownum.'" valign="top">'.
7157: '<p>';
7158: if ($lonhost eq '') {
7159: $datatable .= '<span class="LC_nobreak">';
7160: if (keys(%currbalancer) > 0) {
7161: $datatable .= &mt('Add balancer:');
7162: } else {
7163: $datatable .= &mt('Enable balancer:');
7164: }
7165: $datatable .= ' '.
7166: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7167: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7168: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7169: '<option value="" selected="selected">'.&mt('None').
7170: '</option>'."\n";
7171: foreach my $server (sort(keys(%servers))) {
7172: next if ($currbalancer{$server});
7173: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7174: }
7175: $datatable .=
7176: '</select>'."\n".
7177: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7178: } else {
7179: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7180: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7181: &mt('Stop balancing').'</label>'.
7182: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7183: $targets_div_style = 'display: block';
7184: $disabled_div_style = 'display: none';
7185: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7186: $homedom_div_style = 'display: block';
7187: }
7188: }
7189: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
7190: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7191: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7192: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7193: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7194: my @sparestypes = ('primary','default');
7195: my %typetitles = &sparestype_titles();
7196: my %hostherechecked = (
7197: no => ' checked="checked"',
7198: );
7199: my %balcookiechecked = (
7200: no => ' checked="checked"',
7201: );
7202: foreach my $sparetype (@sparestypes) {
7203: my $targettable;
7204: for (my $i=0; $i<$numspares; $i++) {
7205: my $checked;
7206: if (ref($currtargets{$lonhost}) eq 'HASH') {
7207: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7208: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7209: $checked = ' checked="checked"';
7210: }
7211: }
7212: }
7213: my ($chkboxval,$disabled);
7214: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7215: $chkboxval = $spares[$i];
7216: }
7217: if (exists($currbalancer{$spares[$i]})) {
7218: $disabled = ' disabled="disabled"';
7219: }
7220: $targettable .=
7221: '<td><span class="LC_nobreak"><label>'.
7222: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
7223: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
7224: '</span></label></span></td>';
7225: my $rem = $i%($numinrow);
7226: if ($rem == 0) {
7227: if (($i > 0) && ($i < $numspares-1)) {
7228: $targettable .= '</tr>';
7229: }
7230: if ($i < $numspares-1) {
7231: $targettable .= '<tr>';
7232: }
7233: }
7234: }
7235: if ($targettable ne '') {
7236: my $rem = $numspares%($numinrow);
7237: my $colsleft = $numinrow - $rem;
7238: if ($colsleft > 1 ) {
7239: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7240: ' </td>';
7241: } elsif ($colsleft == 1) {
7242: $targettable .= '<td class="LC_left_item"> </td>';
7243: }
7244: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7245: '<table><tr>'.$targettable.'</tr></table><br />';
7246: }
7247: $hostherechecked{$sparetype} = '';
7248: if (ref($currtargets{$lonhost}) eq 'HASH') {
7249: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7250: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7251: $hostherechecked{$sparetype} = ' checked="checked"';
7252: $hostherechecked{'no'} = '';
7253: }
7254: }
7255: }
7256: }
7257: if ($currcookies{$lonhost}) {
7258: %balcookiechecked = (
7259: yes => ' checked="checked"',
7260: );
7261: }
7262: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7263: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7264: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7265: foreach my $sparetype (@sparestypes) {
7266: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7267: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7268: '</i></label><br />';
7269: }
7270: $datatable .= &mt('Use balancer cookie').'<br />'.
7271: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7272: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7273: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7274: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7275: '</div></td></tr>'.
7276: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7277: $othertitle,$usertypes,$types,\%servers,
7278: \%currbalancer,$lonhost,
7279: $targets_div_style,$homedom_div_style,
7280: $css_class[$cssidx],$balnum,$islast);
7281: $$rowtotal += $rownum;
7282: $balnum ++;
7283: }
7284: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7285: return $datatable;
7286: }
7287:
7288: sub get_loadbalancers_config {
7289: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
7290: return unless ((ref($servers) eq 'HASH') &&
7291: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
7292: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7293: (ref($currcookies) eq 'HASH'));
7294: if (keys(%{$existing}) > 0) {
7295: my $oldlonhost;
7296: foreach my $key (sort(keys(%{$existing}))) {
7297: if ($key eq 'lonhost') {
7298: $oldlonhost = $existing->{'lonhost'};
7299: $currbalancer->{$oldlonhost} = 1;
7300: } elsif ($key eq 'targets') {
7301: if ($oldlonhost) {
7302: $currtargets->{$oldlonhost} = $existing->{'targets'};
7303: }
7304: } elsif ($key eq 'rules') {
7305: if ($oldlonhost) {
7306: $currrules->{$oldlonhost} = $existing->{'rules'};
7307: }
7308: } elsif (ref($existing->{$key}) eq 'HASH') {
7309: $currbalancer->{$key} = 1;
7310: $currtargets->{$key} = $existing->{$key}{'targets'};
7311: $currrules->{$key} = $existing->{$key}{'rules'};
7312: if ($existing->{$key}{'cookie'}) {
7313: $currcookies->{$key} = 1;
7314: }
7315: }
7316: }
7317: } else {
7318: my ($balancerref,$targetsref) =
7319: &Apache::lonnet::get_lonbalancer_config($servers);
7320: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7321: foreach my $server (sort(keys(%{$balancerref}))) {
7322: $currbalancer->{$server} = 1;
7323: $currtargets->{$server} = $targetsref->{$server};
7324: }
7325: }
7326: }
7327: return;
7328: }
7329:
7330: sub loadbalancing_rules {
7331: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
7332: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7333: $css_class,$balnum,$islast) = @_;
7334: my $output;
7335: my $num = 0;
7336: my ($alltypes,$othertypes,$titles) =
7337: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7338: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7339: foreach my $type (@{$alltypes}) {
7340: $num ++;
7341: my $current;
7342: if (ref($currrules) eq 'HASH') {
7343: $current = $currrules->{$type};
7344: }
7345: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
7346: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
7347: $current = '';
7348: }
7349: }
7350: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
7351: $servers,$currbalancer,$lonhost,$dom,
7352: $targets_div_style,$homedom_div_style,
7353: $css_class,$balnum,$num,$islast);
7354: }
7355: }
7356: return $output;
7357: }
7358:
7359: sub loadbalancing_titles {
7360: my ($dom,$intdom,$usertypes,$types) = @_;
7361: my %othertypes = (
7362: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7363: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7364: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7365: '_LC_external' => &mt('Users not from [_1]',$intdom),
7366: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7367: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
7368: );
7369: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
7370: my @available;
7371: if (ref($types) eq 'ARRAY') {
7372: @available = @{$types};
7373: }
7374: unless (grep(/^default$/,@available)) {
7375: push(@available,'default');
7376: }
7377: unshift(@alltypes,@available);
7378: my %titles;
7379: foreach my $type (@alltypes) {
7380: if ($type =~ /^_LC_/) {
7381: $titles{$type} = $othertypes{$type};
7382: } elsif ($type eq 'default') {
7383: $titles{$type} = &mt('All users from [_1]',$dom);
7384: if (ref($types) eq 'ARRAY') {
7385: if (@{$types} > 0) {
7386: $titles{$type} = &mt('Other users from [_1]',$dom);
7387: }
7388: }
7389: } elsif (ref($usertypes) eq 'HASH') {
7390: $titles{$type} = $usertypes->{$type};
7391: }
7392: }
7393: return (\@alltypes,\%othertypes,\%titles);
7394: }
7395:
7396: sub loadbalance_rule_row {
7397: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7398: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
7399: my @rulenames;
7400: my %ruletitles = &offloadtype_text();
7401: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
7402: @rulenames = ('balancer','offloadedto','specific');
7403: } else {
7404: @rulenames = ('default','homeserver');
7405: if ($type eq '_LC_external') {
7406: push(@rulenames,'externalbalancer');
7407: } else {
7408: push(@rulenames,'specific');
7409: }
7410: push(@rulenames,'none');
7411: }
7412: my $style = $targets_div_style;
7413: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
7414: $style = $homedom_div_style;
7415: }
7416: my $space;
7417: if ($islast && $num == 1) {
7418: $space = '<div display="inline-block"> </div>';
7419: }
7420: my $output =
7421: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
7422: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7423: '<td valaign="top">'.$space.
7424: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
7425: for (my $i=0; $i<@rulenames; $i++) {
7426: my $rule = $rulenames[$i];
7427: my ($checked,$extra);
7428: if ($rulenames[$i] eq 'default') {
7429: $rule = '';
7430: }
7431: if ($rulenames[$i] eq 'specific') {
7432: if (ref($servers) eq 'HASH') {
7433: my $default;
7434: if (($current ne '') && (exists($servers->{$current}))) {
7435: $checked = ' checked="checked"';
7436: }
7437: unless ($checked) {
7438: $default = ' selected="selected"';
7439: }
7440: $extra =
7441: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7442: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7443: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7444: '<option value=""'.$default.'></option>'."\n";
7445: foreach my $server (sort(keys(%{$servers}))) {
7446: if (ref($currbalancer) eq 'HASH') {
7447: next if (exists($currbalancer->{$server}));
7448: }
7449: my $selected;
7450: if ($server eq $current) {
7451: $selected = ' selected="selected"';
7452: }
7453: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
7454: }
7455: $extra .= '</select>';
7456: }
7457: } elsif ($rule eq $current) {
7458: $checked = ' checked="checked"';
7459: }
7460: $output .= '<span class="LC_nobreak"><label>'.
7461: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7462: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7463: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
7464: ')"'.$checked.' /> ';
7465: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
7466: $output .= $ruletitles{'particular'};
7467: } else {
7468: $output .= $ruletitles{$rulenames[$i]};
7469: }
7470: $output .= '</label>'.$extra.'</span><br />'."\n";
7471: }
7472: $output .= '</div></td></tr>'."\n";
7473: return $output;
7474: }
7475:
7476: sub offloadtype_text {
7477: my %ruletitles = &Apache::lonlocal::texthash (
7478: 'default' => 'Offloads to default destinations',
7479: 'homeserver' => "Offloads to user's home server",
7480: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7481: 'specific' => 'Offloads to specific server',
7482: 'none' => 'No offload',
7483: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7484: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
7485: 'particular' => 'Session hosted (after re-auth) on server:',
7486: );
7487: return %ruletitles;
7488: }
7489:
7490: sub sparestype_titles {
7491: my %typestitles = &Apache::lonlocal::texthash (
7492: 'primary' => 'primary',
7493: 'default' => 'default',
7494: );
7495: return %typestitles;
7496: }
7497:
7498: sub contact_titles {
7499: my %titles = &Apache::lonlocal::texthash (
7500: 'supportemail' => 'Support E-mail address',
7501: 'adminemail' => 'Default Server Admin E-mail address',
7502: 'errormail' => 'Error reports to be e-mailed to',
7503: 'packagesmail' => 'Package update alerts to be e-mailed to',
7504: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7505: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
7506: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7507: 'requestsmail' => 'E-mail from course requests requiring approval',
7508: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
7509: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
7510: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
7511: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
7512: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
7513: 'errorweights' => 'Weights used to compute error count',
7514: 'errorexcluded' => 'Servers with unsent updates excluded from count',
7515: );
7516: my %short_titles = &Apache::lonlocal::texthash (
7517: adminemail => 'Admin E-mail address',
7518: supportemail => 'Support E-mail',
7519: );
7520: return (\%titles,\%short_titles);
7521: }
7522:
7523: sub helpform_fields {
7524: my %titles = &Apache::lonlocal::texthash (
7525: 'username' => 'Name',
7526: 'user' => 'Username/domain',
7527: 'phone' => 'Phone',
7528: 'cc' => 'Cc e-mail',
7529: 'course' => 'Course Details',
7530: 'section' => 'Sections',
7531: 'screenshot' => 'File upload',
7532: );
7533: my @fields = ('username','phone','user','course','section','cc','screenshot');
7534: my %possoptions = (
7535: username => ['yes','no','req'],
7536: phone => ['yes','no','req'],
7537: user => ['yes','no'],
7538: cc => ['yes','no'],
7539: course => ['yes','no'],
7540: section => ['yes','no'],
7541: screenshot => ['yes','no'],
7542: );
7543: my %fieldoptions = &Apache::lonlocal::texthash (
7544: 'yes' => 'Optional',
7545: 'req' => 'Required',
7546: 'no' => "Not shown",
7547: );
7548: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7549: }
7550:
7551: sub tool_titles {
7552: my %titles = &Apache::lonlocal::texthash (
7553: aboutme => 'Personal web page',
7554: blog => 'Blog',
7555: webdav => 'WebDAV',
7556: portfolio => 'Portfolio',
7557: timezone => 'Can set time zone',
7558: official => 'Official courses (with institutional codes)',
7559: unofficial => 'Unofficial courses',
7560: community => 'Communities',
7561: textbook => 'Textbook courses',
7562: );
7563: return %titles;
7564: }
7565:
7566: sub courserequest_titles {
7567: my %titles = &Apache::lonlocal::texthash (
7568: official => 'Official',
7569: unofficial => 'Unofficial',
7570: community => 'Communities',
7571: textbook => 'Textbook',
7572: norequest => 'Not allowed',
7573: approval => 'Approval by Dom. Coord.',
7574: validate => 'With validation',
7575: autolimit => 'Numerical limit',
7576: unlimited => '(blank for unlimited)',
7577: );
7578: return %titles;
7579: }
7580:
7581: sub authorrequest_titles {
7582: my %titles = &Apache::lonlocal::texthash (
7583: norequest => 'Not allowed',
7584: approval => 'Approval by Dom. Coord.',
7585: automatic => 'Automatic approval',
7586: );
7587: return %titles;
7588: }
7589:
7590: sub courserequest_conditions {
7591: my %conditions = &Apache::lonlocal::texthash (
7592: approval => '(Processing of request subject to approval by Domain Coordinator).',
7593: validate => '(Processing of request subject to institutional validation).',
7594: );
7595: return %conditions;
7596: }
7597:
7598:
7599: sub print_usercreation {
7600: my ($position,$dom,$settings,$rowtotal) = @_;
7601: my $numinrow = 4;
7602: my $datatable;
7603: if ($position eq 'top') {
7604: $$rowtotal ++;
7605: my $rowcount = 0;
7606: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
7607: if (ref($rules) eq 'HASH') {
7608: if (keys(%{$rules}) > 0) {
7609: $datatable .= &user_formats_row('username',$settings,$rules,
7610: $ruleorder,$numinrow,$rowcount);
7611: $$rowtotal ++;
7612: $rowcount ++;
7613: }
7614: }
7615: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7616: if (ref($idrules) eq 'HASH') {
7617: if (keys(%{$idrules}) > 0) {
7618: $datatable .= &user_formats_row('id',$settings,$idrules,
7619: $idruleorder,$numinrow,$rowcount);
7620: $$rowtotal ++;
7621: $rowcount ++;
7622: }
7623: }
7624: if ($rowcount == 0) {
7625: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7626: $$rowtotal ++;
7627: $rowcount ++;
7628: }
7629: } elsif ($position eq 'middle') {
7630: my @creators = ('author','course','requestcrs');
7631: my ($rules,$ruleorder) =
7632: &Apache::lonnet::inst_userrules($dom,'username');
7633: my %lt = &usercreation_types();
7634: my %checked;
7635: if (ref($settings) eq 'HASH') {
7636: if (ref($settings->{'cancreate'}) eq 'HASH') {
7637: foreach my $item (@creators) {
7638: $checked{$item} = $settings->{'cancreate'}{$item};
7639: }
7640: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7641: foreach my $item (@creators) {
7642: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7643: $checked{$item} = 'none';
7644: }
7645: }
7646: }
7647: }
7648: my $rownum = 0;
7649: foreach my $item (@creators) {
7650: $rownum ++;
7651: if ($checked{$item} eq '') {
7652: $checked{$item} = 'any';
7653: }
7654: my $css_class;
7655: if ($rownum%2) {
7656: $css_class = '';
7657: } else {
7658: $css_class = ' class="LC_odd_row" ';
7659: }
7660: $datatable .= '<tr'.$css_class.'>'.
7661: '<td><span class="LC_nobreak">'.$lt{$item}.
7662: '</span></td><td align="right">';
7663: my @options = ('any');
7664: if (ref($rules) eq 'HASH') {
7665: if (keys(%{$rules}) > 0) {
7666: push(@options,('official','unofficial'));
7667: }
7668: }
7669: push(@options,'none');
7670: foreach my $option (@options) {
7671: my $type = 'radio';
7672: my $check = ' ';
7673: if ($checked{$item} eq $option) {
7674: $check = ' checked="checked" ';
7675: }
7676: $datatable .= '<span class="LC_nobreak"><label>'.
7677: '<input type="'.$type.'" name="can_createuser_'.
7678: $item.'" value="'.$option.'"'.$check.'/> '.
7679: $lt{$option}.'</label> </span>';
7680: }
7681: $datatable .= '</td></tr>';
7682: }
7683: } else {
7684: my @contexts = ('author','course','domain');
7685: my @authtypes = ('int','krb4','krb5','loc');
7686: my %checked;
7687: if (ref($settings) eq 'HASH') {
7688: if (ref($settings->{'authtypes'}) eq 'HASH') {
7689: foreach my $item (@contexts) {
7690: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7691: foreach my $auth (@authtypes) {
7692: if ($settings->{'authtypes'}{$item}{$auth}) {
7693: $checked{$item}{$auth} = ' checked="checked" ';
7694: }
7695: }
7696: }
7697: }
7698: }
7699: } else {
7700: foreach my $item (@contexts) {
7701: foreach my $auth (@authtypes) {
7702: $checked{$item}{$auth} = ' checked="checked" ';
7703: }
7704: }
7705: }
7706: my %title = &context_names();
7707: my %authname = &authtype_names();
7708: my $rownum = 0;
7709: my $css_class;
7710: foreach my $item (@contexts) {
7711: if ($rownum%2) {
7712: $css_class = '';
7713: } else {
7714: $css_class = ' class="LC_odd_row" ';
7715: }
7716: $datatable .= '<tr'.$css_class.'>'.
7717: '<td>'.$title{$item}.
7718: '</td><td class="LC_left_item">'.
7719: '<span class="LC_nobreak">';
7720: foreach my $auth (@authtypes) {
7721: $datatable .= '<label>'.
7722: '<input type="checkbox" name="'.$item.'_auth" '.
7723: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7724: $authname{$auth}.'</label> ';
7725: }
7726: $datatable .= '</span></td></tr>';
7727: $rownum ++;
7728: }
7729: $$rowtotal += $rownum;
7730: }
7731: return $datatable;
7732: }
7733:
7734: sub print_selfcreation {
7735: my ($position,$dom,$settings,$rowtotal) = @_;
7736: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7737: $emaildomain,$datatable);
7738: if (ref($settings) eq 'HASH') {
7739: if (ref($settings->{'cancreate'}) eq 'HASH') {
7740: $createsettings = $settings->{'cancreate'};
7741: if (ref($createsettings) eq 'HASH') {
7742: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7743: @selfcreate = @{$createsettings->{'selfcreate'}};
7744: } elsif ($createsettings->{'selfcreate'} ne '') {
7745: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7746: @selfcreate = ('email','login','sso');
7747: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7748: @selfcreate = ($createsettings->{'selfcreate'});
7749: }
7750: }
7751: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7752: $processing = $createsettings->{'selfcreateprocessing'};
7753: }
7754: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7755: $emailoptions = $createsettings->{'emailoptions'};
7756: }
7757: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7758: $emailverified = $createsettings->{'emailverified'};
7759: }
7760: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7761: $emaildomain = $createsettings->{'emaildomain'};
7762: }
7763: }
7764: }
7765: }
7766: my %radiohash;
7767: my $numinrow = 4;
7768: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
7769: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7770: if ($position eq 'top') {
7771: my %choices = &Apache::lonlocal::texthash (
7772: cancreate_login => 'Institutional Login',
7773: cancreate_sso => 'Institutional Single Sign On',
7774: );
7775: my @toggles = sort(keys(%choices));
7776: my %defaultchecked = (
7777: 'cancreate_login' => 'off',
7778: 'cancreate_sso' => 'off',
7779: );
7780: my ($onclick,$itemcount);
7781: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7782: \%choices,$itemcount,$onclick);
7783: $$rowtotal += $itemcount;
7784:
7785: if (ref($usertypes) eq 'HASH') {
7786: if (keys(%{$usertypes}) > 0) {
7787: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7788: $dom,$numinrow,$othertitle,
7789: 'statustocreate',$rowtotal);
7790: $$rowtotal ++;
7791: }
7792: }
7793: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7794: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7795: $fieldtitles{'inststatus'} = &mt('Institutional status');
7796: my $rem;
7797: my $numperrow = 2;
7798: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7799: $datatable .= '<tr'.$css_class.'>'.
7800: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
7801: '<td class="LC_left_item">'."\n".
7802: '<table>'."\n";
7803: for (my $i=0; $i<@fields; $i++) {
7804: $rem = $i%($numperrow);
7805: if ($rem == 0) {
7806: if ($i > 0) {
7807: $datatable .= '</tr>';
7808: }
7809: $datatable .= '<tr>';
7810: }
7811: my $currval;
7812: if (ref($createsettings) eq 'HASH') {
7813: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7814: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7815: }
7816: }
7817: $datatable .= '<td class="LC_left_item">'.
7818: '<span class="LC_nobreak">'.
7819: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7820: 'value="'.$currval.'" size="10" /> '.
7821: $fieldtitles{$fields[$i]}.'</span></td>';
7822: }
7823: my $colsleft = $numperrow - $rem;
7824: if ($colsleft > 1 ) {
7825: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7826: ' </td>';
7827: } elsif ($colsleft == 1) {
7828: $datatable .= '<td class="LC_left_item"> </td>';
7829: }
7830: $datatable .= '</tr></table></td></tr>';
7831: $$rowtotal ++;
7832: } elsif ($position eq 'middle') {
7833: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
7834: my @posstypes;
7835: if (ref($types) eq 'ARRAY') {
7836: @posstypes = @{$types};
7837: }
7838: unless (grep(/^default$/,@posstypes)) {
7839: push(@posstypes,'default');
7840: }
7841: my %usertypeshash;
7842: if (ref($usertypes) eq 'HASH') {
7843: %usertypeshash = %{$usertypes};
7844: }
7845: $usertypeshash{'default'} = $othertitle;
7846: foreach my $status (@posstypes) {
7847: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7848: $numinrow,$$rowtotal,\%usertypeshash);
7849: $$rowtotal ++;
7850: }
7851: } else {
7852: my %choices = &Apache::lonlocal::texthash (
7853: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
7854: );
7855: my @toggles = sort(keys(%choices));
7856: my %defaultchecked = (
7857: 'cancreate_email' => 'off',
7858: );
7859: my $customclass = 'LC_selfcreate_email';
7860: my $classprefix = 'LC_canmodify_emailusername_';
7861: my $optionsprefix = 'LC_options_emailusername_';
7862: my $display = 'none';
7863: my $rowstyle = 'display:none';
7864: if (grep(/^\Qemail\E$/,@selfcreate)) {
7865: $display = 'block';
7866: $rowstyle = 'display:table-row';
7867: }
7868: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7869: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7870: \%choices,$$rowtotal,$onclick);
7871: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7872: $rowstyle);
7873: $$rowtotal ++;
7874: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7875: $rowstyle);
7876: $$rowtotal ++;
7877: my (@ordered,@posstypes,%usertypeshash);
7878: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7879: my ($emailrules,$emailruleorder) =
7880: &Apache::lonnet::inst_userrules($dom,'email');
7881: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7882: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7883: if (ref($types) eq 'ARRAY') {
7884: @posstypes = @{$types};
7885: }
7886: if (@posstypes) {
7887: unless (grep(/^default$/,@posstypes)) {
7888: push(@posstypes,'default');
7889: }
7890: if (ref($usertypes) eq 'HASH') {
7891: %usertypeshash = %{$usertypes};
7892: }
7893: my $currassign;
7894: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7895: $currassign = {
7896: selfassign => $domdefaults{'inststatusguest'},
7897: };
7898: @ordered = @{$domdefaults{'inststatusguest'}};
7899: } else {
7900: $currassign = { selfassign => [] };
7901: }
7902: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7903: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7904: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7905: $numinrow,$othertitle,'selfassign',
7906: $rowtotal,$onclicktypes,$customclass,
7907: $rowstyle);
7908: $$rowtotal ++;
7909: $usertypeshash{'default'} = $othertitle;
7910: foreach my $status (@posstypes) {
7911: my $css_class;
7912: if ($$rowtotal%2) {
7913: $css_class = 'LC_odd_row ';
7914: }
7915: $css_class .= $customclass;
7916: my $rowid = $optionsprefix.$status;
7917: my $hidden = 1;
7918: my $currstyle = 'display:none';
7919: if (grep(/^\Q$status\E$/,@ordered)) {
7920: $currstyle = $rowstyle;
7921: $hidden = 0;
7922: }
7923: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7924: $emailrules,$emailruleorder,$settings,$status,$rowid,
7925: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7926: unless ($hidden) {
7927: $$rowtotal ++;
7928: }
7929: }
7930: } else {
7931: my $css_class;
7932: if ($$rowtotal%2) {
7933: $css_class = 'LC_odd_row ';
7934: }
7935: $css_class .= $customclass;
7936: $usertypeshash{'default'} = $othertitle;
7937: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7938: $emailrules,$emailruleorder,$settings,'default','',
7939: $othertitle,$css_class,$rowstyle,$intdom);
7940: $$rowtotal ++;
7941: }
7942: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7943: $numinrow = 1;
7944: if (@posstypes) {
7945: foreach my $status (@posstypes) {
7946: my $rowid = $classprefix.$status;
7947: my $datarowstyle = 'display:none';
7948: if (grep(/^\Q$status\E$/,@ordered)) {
7949: $datarowstyle = $rowstyle;
7950: }
7951: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7952: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7953: $infotitles,$rowid,$customclass,$datarowstyle);
7954: unless ($datarowstyle eq 'display:none') {
7955: $$rowtotal ++;
7956: }
7957: }
7958: } else {
7959: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7960: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7961: $infotitles,'',$customclass,$rowstyle);
7962: }
7963: }
7964: return $datatable;
7965: }
7966:
7967: sub selfcreate_javascript {
7968: return <<"ENDSCRIPT";
7969:
7970: <script type="text/javascript">
7971: // <![CDATA[
7972:
7973: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7974: var x = document.getElementsByClassName(target);
7975: var insttypes = 0;
7976: var insttypeRegExp = new RegExp(prefix);
7977: if ((x.length != undefined) && (x.length > 0)) {
7978: if (form.elements[radio].length != undefined) {
7979: for (var i=0; i<form.elements[radio].length; i++) {
7980: if (form.elements[radio][i].checked) {
7981: if (form.elements[radio][i].value == 1) {
7982: for (var j=0; j<x.length; j++) {
7983: if (x[j].id == 'undefined') {
7984: x[j].style.display = 'table-row';
7985: } else if (insttypeRegExp.test(x[j].id)) {
7986: insttypes ++;
7987: } else {
7988: x[j].style.display = 'table-row';
7989: }
7990: }
7991: } else {
7992: for (var j=0; j<x.length; j++) {
7993: x[j].style.display = 'none';
7994: }
7995: }
7996: break;
7997: }
7998: }
7999: if (insttypes > 0) {
8000: toggleDataRow(form,checkbox,target,altprefix);
8001: toggleDataRow(form,checkbox,target,prefix,1);
8002: }
8003: }
8004: }
8005: return;
8006: }
8007:
8008: function toggleDataRow(form,checkbox,target,prefix,docount) {
8009: if (form.elements[checkbox].length != undefined) {
8010: var count = 0;
8011: if (docount) {
8012: for (var i=0; i<form.elements[checkbox].length; i++) {
8013: if (form.elements[checkbox][i].checked) {
8014: count ++;
8015: }
8016: }
8017: }
8018: for (var i=0; i<form.elements[checkbox].length; i++) {
8019: var type = form.elements[checkbox][i].value;
8020: if (document.getElementById(prefix+type)) {
8021: if (form.elements[checkbox][i].checked) {
8022: document.getElementById(prefix+type).style.display = 'table-row';
8023: if (count % 2 == 1) {
8024: document.getElementById(prefix+type).className = target+' LC_odd_row';
8025: } else {
8026: document.getElementById(prefix+type).className = target;
8027: }
8028: count ++;
8029: } else {
8030: document.getElementById(prefix+type).style.display = 'none';
8031: }
8032: }
8033: }
8034: }
8035: return;
8036: }
8037:
8038: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8039: var caller = radio+'_'+status;
8040: if (form.elements[caller].length != undefined) {
8041: for (var i=0; i<form.elements[caller].length; i++) {
8042: if (form.elements[caller][i].checked) {
8043: if (document.getElementById(altprefix+'_inst_'+status)) {
8044: var curr = form.elements[caller][i].value;
8045: if (prefix) {
8046: document.getElementById(prefix+'_'+status).style.display = 'none';
8047: }
8048: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8049: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8050: if (curr == 'custom') {
8051: if (prefix) {
8052: document.getElementById(prefix+'_'+status).style.display = 'inline';
8053: }
8054: } else if (curr == 'inst') {
8055: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8056: } else if (curr == 'noninst') {
8057: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
8058: }
8059: break;
8060: }
8061: }
8062: }
8063: }
8064: }
8065:
8066: // ]]>
8067: </script>
8068:
8069: ENDSCRIPT
8070: }
8071:
8072: sub noninst_users {
8073: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8074: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8075: my $class = 'LC_left_item';
8076: if ($css_class) {
8077: $css_class = ' class="'.$css_class.'"';
8078: }
8079: if ($rowid) {
8080: $rowid = ' id="'.$rowid.'"';
8081: }
8082: if ($rowstyle) {
8083: $rowstyle = ' style="'.$rowstyle.'"';
8084: }
8085: my ($output,$description);
8086: if ($type eq 'default') {
8087: $description = &mt('Requests for: [_1]',$typetitle);
8088: } else {
8089: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8090: }
8091: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8092: "<td>$description</td>\n".
8093: '<td class="'.$class.'" colspan="2">'.
8094: '<table><tr>';
8095: my %headers = &Apache::lonlocal::texthash(
8096: approve => 'Processing',
8097: email => 'E-mail',
8098: username => 'Username',
8099: );
8100: foreach my $item ('approve','email','username') {
8101: $output .= '<th>'.$headers{$item}.'</th>';
8102: }
8103: $output .= '</tr><tr>';
8104: foreach my $item ('approve','email','username') {
8105: $output .= '<td valign="top">';
8106: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8107: if ($item eq 'approve') {
8108: %choices = &Apache::lonlocal::texthash (
8109: automatic => 'Automatically approved',
8110: approval => 'Queued for approval',
8111: );
8112: @options = ('automatic','approval');
8113: $hashref = $processing;
8114: $defoption = 'automatic';
8115: $name = 'cancreate_emailprocess_'.$type;
8116: } elsif ($item eq 'email') {
8117: %choices = &Apache::lonlocal::texthash (
8118: any => 'Any e-mail',
8119: inst => 'Institutional only',
8120: noninst => 'Non-institutional only',
8121: custom => 'Custom restrictions',
8122: );
8123: @options = ('any','inst','noninst');
8124: my $showcustom;
8125: if (ref($emailrules) eq 'HASH') {
8126: if (keys(%{$emailrules}) > 0) {
8127: push(@options,'custom');
8128: $showcustom = 'cancreate_emailrule';
8129: if (ref($settings) eq 'HASH') {
8130: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8131: foreach my $rule (@{$settings->{'email_rule'}}) {
8132: if (exists($emailrules->{$rule})) {
8133: $hascustom ++;
8134: }
8135: }
8136: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8137: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8138: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8139: if (exists($emailrules->{$rule})) {
8140: $hascustom ++;
8141: }
8142: }
8143: }
8144: }
8145: }
8146: }
8147: }
8148: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8149: "'cancreate_emaildomain','$type'".');"';
8150: $hashref = $emailoptions;
8151: $defoption = 'any';
8152: $name = 'cancreate_emailoptions_'.$type;
8153: } elsif ($item eq 'username') {
8154: %choices = &Apache::lonlocal::texthash (
8155: all => 'Same as e-mail',
8156: first => 'Omit @domain',
8157: free => 'Free to choose',
8158: );
8159: @options = ('all','first','free');
8160: $hashref = $emailverified;
8161: $defoption = 'all';
8162: $name = 'cancreate_usernameoptions_'.$type;
8163: }
8164: foreach my $option (@options) {
8165: my $checked;
8166: if (ref($hashref) eq 'HASH') {
8167: if ($type eq '') {
8168: if (!exists($hashref->{'default'})) {
8169: if ($option eq $defoption) {
8170: $checked = ' checked="checked"';
8171: }
8172: } else {
8173: if ($hashref->{'default'} eq $option) {
8174: $checked = ' checked="checked"';
8175: }
8176: }
8177: } else {
8178: if (!exists($hashref->{$type})) {
8179: if ($option eq $defoption) {
8180: $checked = ' checked="checked"';
8181: }
8182: } else {
8183: if ($hashref->{$type} eq $option) {
8184: $checked = ' checked="checked"';
8185: }
8186: }
8187: }
8188: } elsif (($item eq 'email') && ($hascustom)) {
8189: if ($option eq 'custom') {
8190: $checked = ' checked="checked"';
8191: }
8192: } elsif ($option eq $defoption) {
8193: $checked = ' checked="checked"';
8194: }
8195: $output .= '<span class="LC_nobreak"><label>'.
8196: '<input type="radio" name="'.$name.'"'.
8197: $checked.' value="'.$option.'"'.$onclick.' />'.
8198: $choices{$option}.'</label></span><br />';
8199: if ($item eq 'email') {
8200: if ($option eq 'custom') {
8201: my $id = 'cancreate_emailrule_'.$type;
8202: my $display = 'none';
8203: if ($checked) {
8204: $display = 'inline';
8205: }
8206: my $numinrow = 2;
8207: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8208: '<legend>'.&mt('Disallow').'</legend><table>'.
8209: &user_formats_row('email',$settings,$emailrules,
8210: $emailruleorder,$numinrow,'',$type);
8211: '</table></fieldset>';
8212: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8213: my %text = &Apache::lonlocal::texthash (
8214: inst => 'must end:',
8215: noninst => 'cannot end:',
8216: );
8217: my $value;
8218: if (ref($emaildomain) eq 'HASH') {
8219: if (ref($emaildomain->{$type}) eq 'HASH') {
8220: $value = $emaildomain->{$type}->{$option};
8221: }
8222: }
8223: if ($value eq '') {
8224: $value = '@'.$intdom;
8225: }
8226: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8227: my $display = 'none';
8228: if ($checked) {
8229: $display = 'inline';
8230: }
8231: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8232: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8233: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8234: '</div>';
8235: }
8236: }
8237: }
8238: $output .= '</td>'."\n";
8239: }
8240: $output .= "</tr></table></td></tr>\n";
8241: return $output;
8242: }
8243:
8244: sub captcha_choice {
8245: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
8246: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
8247: $vertext,$currver);
8248: my %lt = &captcha_phrases();
8249: $keyentry = 'hidden';
8250: my $colspan=2;
8251: if ($context eq 'cancreate') {
8252: $rowname = &mt('CAPTCHA validation');
8253: } elsif ($context eq 'login') {
8254: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
8255: } elsif ($context eq 'passwords') {
8256: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8257: $colspan=1;
8258: }
8259: if (ref($settings) eq 'HASH') {
8260: if ($settings->{'captcha'}) {
8261: $checked{$settings->{'captcha'}} = ' checked="checked"';
8262: } else {
8263: $checked{'original'} = ' checked="checked"';
8264: }
8265: if ($settings->{'captcha'} eq 'recaptcha') {
8266: $pubtext = $lt{'pub'};
8267: $privtext = $lt{'priv'};
8268: $keyentry = 'text';
8269: $vertext = $lt{'ver'};
8270: $currver = $settings->{'recaptchaversion'};
8271: if ($currver ne '2') {
8272: $currver = 1;
8273: }
8274: }
8275: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8276: $currpub = $settings->{'recaptchakeys'}{'public'};
8277: $currpriv = $settings->{'recaptchakeys'}{'private'};
8278: }
8279: } else {
8280: $checked{'original'} = ' checked="checked"';
8281: }
8282: my $css_class;
8283: if ($itemcount%2) {
8284: $css_class = 'LC_odd_row';
8285: }
8286: if ($customcss) {
8287: $css_class .= " $customcss";
8288: }
8289: $css_class =~ s/^\s+//;
8290: if ($css_class) {
8291: $css_class = ' class="'.$css_class.'"';
8292: }
8293: if ($rowstyle) {
8294: $css_class .= ' style="'.$rowstyle.'"';
8295: }
8296: my $output = '<tr'.$css_class.'>'.
8297: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
8298: '<table><tr><td>'."\n";
8299: foreach my $option ('original','recaptcha','notused') {
8300: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8301: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8302: $lt{$option}.'</label></span>';
8303: unless ($option eq 'notused') {
8304: $output .= (' 'x2)."\n";
8305: }
8306: }
8307: #
8308: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8309: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
8310: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
8311: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
8312: #
8313: $output .= '</td></tr>'."\n".
8314: '<tr><td class="LC_zero_height">'."\n".
8315: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8316: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8317: $currpub.'" size="40" /></span><br />'."\n".
8318: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8319: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
8320: $currpriv.'" size="40" /></span><br />'.
8321: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8322: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8323: $currver.'" size="3" /></span><br />'.
8324: '</td></tr></table>'."\n".
8325: '</td></tr>';
8326: return $output;
8327: }
8328:
8329: sub user_formats_row {
8330: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
8331: my $output;
8332: my %text = (
8333: 'username' => 'new usernames',
8334: 'id' => 'IDs',
8335: );
8336: unless (($type eq 'email') || ($type eq 'unamemap')) {
8337: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8338: $output = '<tr '.$css_class.'>'.
8339: '<td><span class="LC_nobreak">'.
8340: &mt("Format rules to check for $text{$type}: ").
8341: '</td><td class="LC_left_item" colspan="2"><table>';
8342: }
8343: my $rem;
8344: if (ref($ruleorder) eq 'ARRAY') {
8345: for (my $i=0; $i<@{$ruleorder}; $i++) {
8346: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8347: my $rem = $i%($numinrow);
8348: if ($rem == 0) {
8349: if ($i > 0) {
8350: $output .= '</tr>';
8351: }
8352: $output .= '<tr>';
8353: }
8354: my $check = ' ';
8355: if (ref($settings) eq 'HASH') {
8356: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8357: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8358: $check = ' checked="checked" ';
8359: }
8360: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8361: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8362: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8363: $check = ' checked="checked" ';
8364: }
8365: }
8366: }
8367: }
8368: my $name = $type.'_rule';
8369: if ($type eq 'email') {
8370: $name .= '_'.$status;
8371: }
8372: $output .= '<td class="LC_left_item">'.
8373: '<span class="LC_nobreak"><label>'.
8374: '<input type="checkbox" name="'.$name.'" '.
8375: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8376: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8377: }
8378: }
8379: $rem = @{$ruleorder}%($numinrow);
8380: }
8381: my $colsleft;
8382: if ($rem) {
8383: $colsleft = $numinrow - $rem;
8384: }
8385: if ($colsleft > 1 ) {
8386: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8387: ' </td>';
8388: } elsif ($colsleft == 1) {
8389: $output .= '<td class="LC_left_item"> </td>';
8390: }
8391: $output .= '</tr>';
8392: unless (($type eq 'email') || ($type eq 'unamemap')) {
8393: $output .= '</table></td></tr>';
8394: }
8395: return $output;
8396: }
8397:
8398: sub usercreation_types {
8399: my %lt = &Apache::lonlocal::texthash (
8400: author => 'When adding a co-author',
8401: course => 'When adding a user to a course',
8402: requestcrs => 'When requesting a course',
8403: any => 'Any',
8404: official => 'Institutional only ',
8405: unofficial => 'Non-institutional only',
8406: none => 'None',
8407: );
8408: return %lt;
8409: }
8410:
8411: sub selfcreation_types {
8412: my %lt = &Apache::lonlocal::texthash (
8413: selfcreate => 'User creates own account',
8414: any => 'Any',
8415: official => 'Institutional only ',
8416: unofficial => 'Non-institutional only',
8417: email => 'E-mail address',
8418: login => 'Institutional Login',
8419: sso => 'SSO',
8420: );
8421: }
8422:
8423: sub authtype_names {
8424: my %lt = &Apache::lonlocal::texthash(
8425: int => 'Internal',
8426: krb4 => 'Kerberos 4',
8427: krb5 => 'Kerberos 5',
8428: loc => 'Local',
8429: );
8430: return %lt;
8431: }
8432:
8433: sub context_names {
8434: my %context_title = &Apache::lonlocal::texthash(
8435: author => 'Creating users when an Author',
8436: course => 'Creating users when in a course',
8437: domain => 'Creating users when a Domain Coordinator',
8438: );
8439: return %context_title;
8440: }
8441:
8442: sub print_usermodification {
8443: my ($position,$dom,$settings,$rowtotal) = @_;
8444: my $numinrow = 4;
8445: my ($context,$datatable,$rowcount);
8446: if ($position eq 'top') {
8447: $rowcount = 0;
8448: $context = 'author';
8449: foreach my $role ('ca','aa') {
8450: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8451: $numinrow,$rowcount);
8452: $$rowtotal ++;
8453: $rowcount ++;
8454: }
8455: } elsif ($position eq 'bottom') {
8456: $context = 'course';
8457: $rowcount = 0;
8458: foreach my $role ('st','ep','ta','in','cr') {
8459: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8460: $numinrow,$rowcount);
8461: $$rowtotal ++;
8462: $rowcount ++;
8463: }
8464: }
8465: return $datatable;
8466: }
8467:
8468: sub print_defaults {
8469: my ($position,$dom,$settings,$rowtotal) = @_;
8470: my $rownum = 0;
8471: my ($datatable,$css_class,$titles);
8472: unless ($position eq 'bottom') {
8473: $titles = &defaults_titles($dom);
8474: }
8475: if ($position eq 'top') {
8476: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8477: 'datelocale_def','portal_def');
8478: my %defaults;
8479: if (ref($settings) eq 'HASH') {
8480: %defaults = %{$settings};
8481: } else {
8482: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8483: foreach my $item (@items) {
8484: $defaults{$item} = $domdefaults{$item};
8485: }
8486: }
8487: foreach my $item (@items) {
8488: if ($rownum%2) {
8489: $css_class = '';
8490: } else {
8491: $css_class = ' class="LC_odd_row" ';
8492: }
8493: $datatable .= '<tr'.$css_class.'>'.
8494: '<td><span class="LC_nobreak">'.$titles->{$item}.
8495: '</span></td><td class="LC_right_item" colspan="3">';
8496: if ($item eq 'auth_def') {
8497: my @authtypes = ('internal','krb4','krb5','localauth');
8498: my %shortauth = (
8499: internal => 'int',
8500: krb4 => 'krb4',
8501: krb5 => 'krb5',
8502: localauth => 'loc'
8503: );
8504: my %authnames = &authtype_names();
8505: foreach my $auth (@authtypes) {
8506: my $checked = ' ';
8507: if ($defaults{$item} eq $auth) {
8508: $checked = ' checked="checked" ';
8509: }
8510: $datatable .= '<label><input type="radio" name="'.$item.
8511: '" value="'.$auth.'"'.$checked.'/>'.
8512: $authnames{$shortauth{$auth}}.'</label> ';
8513: }
8514: } elsif ($item eq 'timezone_def') {
8515: my $includeempty = 1;
8516: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8517: } elsif ($item eq 'datelocale_def') {
8518: my $includeempty = 1;
8519: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8520: } elsif ($item eq 'lang_def') {
8521: my $includeempty = 1;
8522: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
8523: } else {
8524: my $size;
8525: if ($item eq 'portal_def') {
8526: $size = ' size="25"';
8527: }
8528: $datatable .= '<input type="text" name="'.$item.'" value="'.
8529: $defaults{$item}.'"'.$size.' />';
8530: }
8531: $datatable .= '</td></tr>';
8532: $rownum ++;
8533: }
8534: } elsif ($position eq 'middle') {
8535: my %defaults;
8536: if (ref($settings) eq 'HASH') {
8537: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8538: my $maxnum = @{$settings->{'inststatusorder'}};
8539: for (my $i=0; $i<$maxnum; $i++) {
8540: $css_class = $rownum%2?' class="LC_odd_row"':'';
8541: my $item = $settings->{'inststatusorder'}->[$i];
8542: my $title = $settings->{'inststatustypes'}->{$item};
8543: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8544: $datatable .= '<tr'.$css_class.'>'.
8545: '<td><span class="LC_nobreak">'.
8546: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8547: for (my $k=0; $k<=$maxnum; $k++) {
8548: my $vpos = $k+1;
8549: my $selstr;
8550: if ($k == $i) {
8551: $selstr = ' selected="selected" ';
8552: }
8553: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8554: }
8555: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8556: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8557: &mt('delete').'</span></td>'.
8558: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
8559: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
8560: '</span></td></tr>';
8561: }
8562: $css_class = $rownum%2?' class="LC_odd_row"':'';
8563: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8564: $datatable .= '<tr '.$css_class.'>'.
8565: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8566: for (my $k=0; $k<=$maxnum; $k++) {
8567: my $vpos = $k+1;
8568: my $selstr;
8569: if ($k == $maxnum) {
8570: $selstr = ' selected="selected" ';
8571: }
8572: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8573: }
8574: $datatable .= '</select> '.&mt('Internal ID:').
8575: '<input type="text" size="10" name="addinststatus" value="" />'.
8576: ' '.&mt('(new)').
8577: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
8578: &mt('Name displayed').':'.
8579: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8580: '</tr>'."\n";
8581: $rownum ++;
8582: }
8583: }
8584: } else {
8585: my ($unamemaprules,$ruleorder) =
8586: &Apache::lonnet::inst_userrules($dom,'unamemap');
8587: $css_class = $rownum%2?' class="LC_odd_row"':'';
8588: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8589: my $numinrow = 2;
8590: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
8591: &user_formats_row('unamemap',$settings,$unamemaprules,
8592: $ruleorder,$numinrow).
8593: '</table></td></tr>';
8594: }
8595: if ($datatable eq '') {
8596: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
8597: &mt('No rules set for domain in customized localenroll.pm').
8598: '</td></tr>';
8599: }
8600: }
8601: $$rowtotal += $rownum;
8602: return $datatable;
8603: }
8604:
8605: sub get_languages_hash {
8606: my %langchoices;
8607: foreach my $id (&Apache::loncommon::languageids()) {
8608: my $code = &Apache::loncommon::supportedlanguagecode($id);
8609: if ($code ne '') {
8610: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8611: }
8612: }
8613: return %langchoices;
8614: }
8615:
8616: sub defaults_titles {
8617: my ($dom) = @_;
8618: my %titles = &Apache::lonlocal::texthash (
8619: 'auth_def' => 'Default authentication type',
8620: 'auth_arg_def' => 'Default authentication argument',
8621: 'lang_def' => 'Default language',
8622: 'timezone_def' => 'Default timezone',
8623: 'datelocale_def' => 'Default locale for dates',
8624: 'portal_def' => 'Portal/Default URL',
8625: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8626: 'intauth_check' => 'Check bcrypt cost if authenticated',
8627: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
8628: );
8629: if ($dom) {
8630: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8631: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8632: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8633: $protocol = 'http' if ($protocol ne 'https');
8634: if ($uint_dom) {
8635: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8636: $uint_dom);
8637: }
8638: }
8639: return (\%titles);
8640: }
8641:
8642: sub print_scantron {
8643: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8644: if ($position eq 'top') {
8645: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8646: } else {
8647: return &print_scantronconfig($dom,$settings,\$rowtotal);
8648: }
8649: }
8650:
8651: sub scantron_javascript {
8652: return <<"ENDSCRIPT";
8653:
8654: <script type="text/javascript">
8655: // <![CDATA[
8656:
8657: function toggleScantron(form) {
8658: var csvfieldset = new Array();
8659: if (document.getElementById('scantroncsv_cols')) {
8660: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8661: }
8662: if (document.getElementById('scantroncsv_options')) {
8663: csvfieldset.push(document.getElementById('scantroncsv_options'));
8664: }
8665: if (csvfieldset.length) {
8666: if (document.getElementById('scantronconfcsv')) {
8667: var scantroncsv = document.getElementById('scantronconfcsv');
8668: if (scantroncsv.checked) {
8669: for (var i=0; i<csvfieldset.length; i++) {
8670: csvfieldset[i].style.display = 'block';
8671: }
8672: } else {
8673: for (var i=0; i<csvfieldset.length; i++) {
8674: csvfieldset[i].style.display = 'none';
8675: }
8676: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8677: if (csvselects.length) {
8678: for (var j=0; j<csvselects.length; j++) {
8679: csvselects[j].selectedIndex = 0;
8680: }
8681: }
8682: }
8683: }
8684: }
8685: return;
8686: }
8687: // ]]>
8688: </script>
8689:
8690: ENDSCRIPT
8691:
8692: }
8693:
8694: sub print_scantronformat {
8695: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8696: my $itemcount = 1;
8697: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8698: %confhash);
8699: my $switchserver = &check_switchserver($dom,$confname);
8700: my %lt = &Apache::lonlocal::texthash (
8701: default => 'Default bubblesheet format file error',
8702: custom => 'Custom bubblesheet format file error',
8703: );
8704: my %scantronfiles = (
8705: default => 'default.tab',
8706: custom => 'custom.tab',
8707: );
8708: foreach my $key (keys(%scantronfiles)) {
8709: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8710: .$scantronfiles{$key};
8711: }
8712: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8713: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8714: if (!$switchserver) {
8715: my $servadm = $r->dir_config('lonAdmEMail');
8716: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8717: if ($configuserok eq 'ok') {
8718: if ($author_ok eq 'ok') {
8719: my %legacyfile = (
8720: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8721: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
8722: );
8723: my %md5chk;
8724: foreach my $type (keys(%legacyfile)) {
8725: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8726: chomp($md5chk{$type});
8727: }
8728: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8729: foreach my $type (keys(%legacyfile)) {
8730: ($scantronurls{$type},my $error) =
8731: &legacy_scantronformat($r,$dom,$confname,
8732: $type,$legacyfile{$type},
8733: $scantronurls{$type},
8734: $scantronfiles{$type});
8735: if ($error ne '') {
8736: $error{$type} = $error;
8737: }
8738: }
8739: if (keys(%error) == 0) {
8740: $is_custom = 1;
8741: $confhash{'scantron'}{'scantronformat'} =
8742: $scantronurls{'custom'};
8743: my $putresult =
8744: &Apache::lonnet::put_dom('configuration',
8745: \%confhash,$dom);
8746: if ($putresult ne 'ok') {
8747: $error{'custom'} =
8748: '<span class="LC_error">'.
8749: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8750: }
8751: }
8752: } else {
8753: ($scantronurls{'default'},my $error) =
8754: &legacy_scantronformat($r,$dom,$confname,
8755: 'default',$legacyfile{'default'},
8756: $scantronurls{'default'},
8757: $scantronfiles{'default'});
8758: if ($error eq '') {
8759: $confhash{'scantron'}{'scantronformat'} = '';
8760: my $putresult =
8761: &Apache::lonnet::put_dom('configuration',
8762: \%confhash,$dom);
8763: if ($putresult ne 'ok') {
8764: $error{'default'} =
8765: '<span class="LC_error">'.
8766: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8767: }
8768: } else {
8769: $error{'default'} = $error;
8770: }
8771: }
8772: }
8773: }
8774: } else {
8775: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
8776: }
8777: }
8778: if (ref($settings) eq 'HASH') {
8779: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8780: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8781: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8782: $scantronurl = '';
8783: } else {
8784: $scantronurl = $settings->{'scantronformat'};
8785: }
8786: $is_custom = 1;
8787: } else {
8788: $scantronurl = $scantronurls{'default'};
8789: }
8790: } else {
8791: if ($is_custom) {
8792: $scantronurl = $scantronurls{'custom'};
8793: } else {
8794: $scantronurl = $scantronurls{'default'};
8795: }
8796: }
8797: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8798: $datatable .= '<tr'.$css_class.'>';
8799: if (!$is_custom) {
8800: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8801: '<span class="LC_nobreak">';
8802: if ($scantronurl) {
8803: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8804: undef,undef,undef,undef,'background-color:#ffffff');
8805: } else {
8806: $datatable = &mt('File unavailable for display');
8807: }
8808: $datatable .= '</span></td>';
8809: if (keys(%error) == 0) {
8810: $datatable .= '<td valign="bottom">';
8811: if (!$switchserver) {
8812: $datatable .= &mt('Upload:').'<br />';
8813: }
8814: } else {
8815: my $errorstr;
8816: foreach my $key (sort(keys(%error))) {
8817: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8818: }
8819: $datatable .= '<td>'.$errorstr;
8820: }
8821: } else {
8822: if (keys(%error) > 0) {
8823: my $errorstr;
8824: foreach my $key (sort(keys(%error))) {
8825: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8826: }
8827: $datatable .= '<td>'.$errorstr.'</td><td> ';
8828: } elsif ($scantronurl) {
8829: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8830: undef,undef,undef,undef,'background-color:#ffffff');
8831: $datatable .= '<td><span class="LC_nobreak">'.
8832: $link.
8833: '<label><input type="checkbox" name="scantronformat_del"'.
8834: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
8835: '<td><span class="LC_nobreak"> '.
8836: &mt('Replace:').'</span><br />';
8837: }
8838: }
8839: if (keys(%error) == 0) {
8840: if ($switchserver) {
8841: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8842: } else {
8843: $datatable .='<span class="LC_nobreak"> '.
8844: '<input type="file" name="scantronformat" /></span>';
8845: }
8846: }
8847: $datatable .= '</td></tr>';
8848: $$rowtotal ++;
8849: return $datatable;
8850: }
8851:
8852: sub legacy_scantronformat {
8853: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8854: my ($url,$error);
8855: my @statinfo = &Apache::lonnet::stat_file($newurl);
8856: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8857: (my $result,$url) =
8858: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8859: '','',$newfile);
8860: if ($result ne 'ok') {
8861: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
8862: }
8863: }
8864: return ($url,$error);
8865: }
8866:
8867: sub print_scantronconfig {
8868: my ($dom,$settings,$rowtotal) = @_;
8869: my $itemcount = 2;
8870: my $is_checked = ' checked="checked"';
8871: my %optionson = (
8872: hdr => ' checked="checked"',
8873: pad => ' checked="checked"',
8874: rem => ' checked="checked"',
8875: );
8876: my %optionsoff = (
8877: hdr => '',
8878: pad => '',
8879: rem => '',
8880: );
8881: my $currcsvsty = 'none';
8882: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
8883: my @fields = &scantroncsv_fields();
8884: my %titles = &scantronconfig_titles();
8885: if (ref($settings) eq 'HASH') {
8886: if (ref($settings->{config}) eq 'HASH') {
8887: if ($settings->{config}->{dat}) {
8888: $checked{'dat'} = $is_checked;
8889: }
8890: if (ref($settings->{config}->{csv}) eq 'HASH') {
8891: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8892: %csvfields = %{$settings->{config}->{csv}->{fields}};
8893: if (keys(%csvfields) > 0) {
8894: $checked{'csv'} = $is_checked;
8895: $currcsvsty = 'block';
8896: }
8897: }
8898: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8899: %csvoptions = %{$settings->{config}->{csv}->{options}};
8900: foreach my $option (keys(%optionson)) {
8901: unless ($csvoptions{$option}) {
8902: $optionsoff{$option} = $optionson{$option};
8903: $optionson{$option} = '';
8904: }
8905: }
8906: }
8907: }
8908: } else {
8909: $checked{'dat'} = $is_checked;
8910: }
8911: } else {
8912: $checked{'dat'} = $is_checked;
8913: }
8914: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8915: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8916: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8917: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8918: foreach my $item ('dat','csv') {
8919: my $id;
8920: if ($item eq 'csv') {
8921: $id = 'id="scantronconfcsv" ';
8922: }
8923: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8924: $titles{$item}.'</label>'.(' 'x3);
8925: if ($item eq 'csv') {
8926: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8927: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8928: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8929: foreach my $col (@fields) {
8930: my $selnone;
8931: if ($csvfields{$col} eq '') {
8932: $selnone = ' selected="selected"';
8933: }
8934: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8935: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8936: '<option value=""'.$selnone.'></option>';
8937: for (my $i=0; $i<20; $i++) {
8938: my $shown = $i+1;
8939: my $sel;
8940: unless ($selnone) {
8941: if (exists($csvfields{$col})) {
8942: if ($csvfields{$col} == $i) {
8943: $sel = ' selected="selected"';
8944: }
8945: }
8946: }
8947: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8948: }
8949: $datatable .= '</select></td></tr>';
8950: }
8951: $datatable .= '</table></fieldset>'.
8952: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8953: '<legend>'.&mt('CSV Options').'</legend>';
8954: foreach my $option ('hdr','pad','rem') {
8955: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8956: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8957: &mt('Yes').'</label>'.(' 'x2)."\n".
8958: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8959: }
8960: $datatable .= '</fieldset>';
8961: $itemcount ++;
8962: }
8963: }
8964: $datatable .= '</td></tr>';
8965: $$rowtotal ++;
8966: return $datatable;
8967: }
8968:
8969: sub scantronconfig_titles {
8970: return &Apache::lonlocal::texthash(
8971: dat => 'Standard format (.dat)',
8972: csv => 'Comma separated values (.csv)',
8973: hdr => 'Remove first line in file (contains column titles)',
8974: pad => 'Prepend 0s to PaperID',
8975: rem => 'Remove leading spaces (except Question Response columns)',
8976: CODE => 'CODE',
8977: ID => 'Student ID',
8978: PaperID => 'Paper ID',
8979: FirstName => 'First Name',
8980: LastName => 'Last Name',
8981: FirstQuestion => 'First Question Response',
8982: Section => 'Section',
8983: );
8984: }
8985:
8986: sub scantroncsv_fields {
8987: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8988: }
8989:
8990: sub print_coursecategories {
8991: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8992: my $datatable;
8993: if ($position eq 'top') {
8994: my (%checked);
8995: my @catitems = ('unauth','auth');
8996: my @cattypes = ('std','domonly','codesrch','none');
8997: $checked{'unauth'} = 'std';
8998: $checked{'auth'} = 'std';
8999: if (ref($settings) eq 'HASH') {
9000: foreach my $type (@cattypes) {
9001: if ($type eq $settings->{'unauth'}) {
9002: $checked{'unauth'} = $type;
9003: }
9004: if ($type eq $settings->{'auth'}) {
9005: $checked{'auth'} = $type;
9006: }
9007: }
9008: }
9009: my %lt = &Apache::lonlocal::texthash (
9010: unauth => 'Catalog type for unauthenticated users',
9011: auth => 'Catalog type for authenticated users',
9012: none => 'No catalog',
9013: std => 'Standard catalog',
9014: domonly => 'Domain-only catalog',
9015: codesrch => "Code search form",
9016: );
9017: my $itemcount = 0;
9018: foreach my $item (@catitems) {
9019: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9020: $datatable .= '<tr '.$css_class.'>'.
9021: '<td>'.$lt{$item}.'</td>'.
9022: '<td class="LC_right_item"><span class="LC_nobreak">';
9023: foreach my $type (@cattypes) {
9024: my $ischecked;
9025: if ($checked{$item} eq $type) {
9026: $ischecked=' checked="checked"';
9027: }
9028: $datatable .= '<label>'.
9029: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9030: ' />'.$lt{$type}.'</label> ';
9031: }
9032: $datatable .= '</span></td></tr>';
9033: $itemcount ++;
9034: }
9035: $$rowtotal += $itemcount;
9036: } elsif ($position eq 'middle') {
9037: my $toggle_cats_crs = ' ';
9038: my $toggle_cats_dom = ' checked="checked" ';
9039: my $can_cat_crs = ' ';
9040: my $can_cat_dom = ' checked="checked" ';
9041: my $toggle_catscomm_comm = ' ';
9042: my $toggle_catscomm_dom = ' checked="checked" ';
9043: my $can_catcomm_comm = ' ';
9044: my $can_catcomm_dom = ' checked="checked" ';
9045:
9046: if (ref($settings) eq 'HASH') {
9047: if ($settings->{'togglecats'} eq 'crs') {
9048: $toggle_cats_crs = $toggle_cats_dom;
9049: $toggle_cats_dom = ' ';
9050: }
9051: if ($settings->{'categorize'} eq 'crs') {
9052: $can_cat_crs = $can_cat_dom;
9053: $can_cat_dom = ' ';
9054: }
9055: if ($settings->{'togglecatscomm'} eq 'comm') {
9056: $toggle_catscomm_comm = $toggle_catscomm_dom;
9057: $toggle_catscomm_dom = ' ';
9058: }
9059: if ($settings->{'categorizecomm'} eq 'comm') {
9060: $can_catcomm_comm = $can_catcomm_dom;
9061: $can_catcomm_dom = ' ';
9062: }
9063: }
9064: my %title = &Apache::lonlocal::texthash (
9065: togglecats => 'Show/Hide a course in catalog',
9066: togglecatscomm => 'Show/Hide a community in catalog',
9067: categorize => 'Assign a category to a course',
9068: categorizecomm => 'Assign a category to a community',
9069: );
9070: my %level = &Apache::lonlocal::texthash (
9071: dom => 'Set in Domain',
9072: crs => 'Set in Course',
9073: comm => 'Set in Community',
9074: );
9075: $datatable = '<tr class="LC_odd_row">'.
9076: '<td>'.$title{'togglecats'}.'</td>'.
9077: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9078: '<input type="radio" name="togglecats"'.
9079: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9080: '<label><input type="radio" name="togglecats"'.
9081: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9082: '</tr><tr>'.
9083: '<td>'.$title{'categorize'}.'</td>'.
9084: '<td class="LC_right_item"><span class="LC_nobreak">'.
9085: '<label><input type="radio" name="categorize"'.
9086: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9087: '<label><input type="radio" name="categorize"'.
9088: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
9089: '</tr><tr class="LC_odd_row">'.
9090: '<td>'.$title{'togglecatscomm'}.'</td>'.
9091: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9092: '<input type="radio" name="togglecatscomm"'.
9093: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9094: '<label><input type="radio" name="togglecatscomm"'.
9095: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9096: '</tr><tr>'.
9097: '<td>'.$title{'categorizecomm'}.'</td>'.
9098: '<td class="LC_right_item"><span class="LC_nobreak">'.
9099: '<label><input type="radio" name="categorizecomm"'.
9100: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9101: '<label><input type="radio" name="categorizecomm"'.
9102: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
9103: '</tr>';
9104: $$rowtotal += 4;
9105: } else {
9106: my $css_class;
9107: my $itemcount = 1;
9108: my $cathash;
9109: if (ref($settings) eq 'HASH') {
9110: $cathash = $settings->{'cats'};
9111: }
9112: if (ref($cathash) eq 'HASH') {
9113: my (@cats,@trails,%allitems,%idx,@jsarray);
9114: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9115: \%allitems,\%idx,\@jsarray);
9116: my $maxdepth = scalar(@cats);
9117: my $colattrib = '';
9118: if ($maxdepth > 2) {
9119: $colattrib = ' colspan="2" ';
9120: }
9121: my @path;
9122: if (@cats > 0) {
9123: if (ref($cats[0]) eq 'ARRAY') {
9124: my $numtop = @{$cats[0]};
9125: my $maxnum = $numtop;
9126: my %default_names = (
9127: instcode => &mt('Official courses'),
9128: communities => &mt('Communities'),
9129: );
9130:
9131: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9132: ($cathash->{'instcode::0'} eq '') ||
9133: (!grep(/^communities$/,@{$cats[0]})) ||
9134: ($cathash->{'communities::0'} eq '')) {
9135: $maxnum ++;
9136: }
9137: my $lastidx;
9138: for (my $i=0; $i<$numtop; $i++) {
9139: my $parent = $cats[0][$i];
9140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9141: my $item = &escape($parent).'::0';
9142: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9143: $lastidx = $idx{$item};
9144: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9145: .'<select name="'.$item.'"'.$chgstr.'>';
9146: for (my $k=0; $k<=$maxnum; $k++) {
9147: my $vpos = $k+1;
9148: my $selstr;
9149: if ($k == $i) {
9150: $selstr = ' selected="selected" ';
9151: }
9152: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9153: }
9154: $datatable .= '</select></span></td><td>';
9155: if ($parent eq 'instcode' || $parent eq 'communities') {
9156: $datatable .= '<span class="LC_nobreak">'
9157: .$default_names{$parent}.'</span>';
9158: if ($parent eq 'instcode') {
9159: $datatable .= '<br /><span class="LC_nobreak">('
9160: .&mt('with institutional codes')
9161: .')</span></td><td'.$colattrib.'>';
9162: } else {
9163: $datatable .= '<table><tr><td>';
9164: }
9165: $datatable .= '<span class="LC_nobreak">'
9166: .'<label><input type="radio" name="'
9167: .$parent.'" value="1" checked="checked" />'
9168: .&mt('Display').'</label>';
9169: if ($parent eq 'instcode') {
9170: $datatable .= ' ';
9171: } else {
9172: $datatable .= '</span></td></tr><tr><td>'
9173: .'<span class="LC_nobreak">';
9174: }
9175: $datatable .= '<label><input type="radio" name="'
9176: .$parent.'" value="0" />'
9177: .&mt('Do not display').'</label></span>';
9178: if ($parent eq 'communities') {
9179: $datatable .= '</td></tr></table>';
9180: }
9181: $datatable .= '</td>';
9182: } else {
9183: $datatable .= $parent
9184: .' <span class="LC_nobreak"><label>'
9185: .'<input type="checkbox" name="deletecategory" '
9186: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9187: }
9188: my $depth = 1;
9189: push(@path,$parent);
9190: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9191: pop(@path);
9192: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9193: $itemcount ++;
9194: }
9195: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9196: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9197: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
9198: for (my $k=0; $k<=$maxnum; $k++) {
9199: my $vpos = $k+1;
9200: my $selstr;
9201: if ($k == $numtop) {
9202: $selstr = ' selected="selected" ';
9203: }
9204: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9205: }
9206: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
9207: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9208: .'</tr>'."\n";
9209: $itemcount ++;
9210: foreach my $default ('instcode','communities') {
9211: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9212: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9213: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9214: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9215: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9216: for (my $k=0; $k<=$maxnum; $k++) {
9217: my $vpos = $k+1;
9218: my $selstr;
9219: if ($k == $maxnum) {
9220: $selstr = ' selected="selected" ';
9221: }
9222: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9223: }
9224: $datatable .= '</select></span></td>'.
9225: '<td><span class="LC_nobreak">'.
9226: $default_names{$default}.'</span>';
9227: if ($default eq 'instcode') {
9228: $datatable .= '<br /><span class="LC_nobreak">('
9229: .&mt('with institutional codes').')</span>';
9230: }
9231: $datatable .= '</td>'
9232: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9233: .&mt('Display').'</label> '
9234: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9235: .&mt('Do not display').'</label></span></td></tr>';
9236: }
9237: }
9238: }
9239: } else {
9240: $datatable .= &initialize_categories($itemcount);
9241: }
9242: } else {
9243: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
9244: .&initialize_categories($itemcount);
9245: }
9246: $$rowtotal += $itemcount;
9247: }
9248: return $datatable;
9249: }
9250:
9251: sub print_serverstatuses {
9252: my ($dom,$settings,$rowtotal) = @_;
9253: my $datatable;
9254: my @pages = &serverstatus_pages();
9255: my (%namedaccess,%machineaccess);
9256: foreach my $type (@pages) {
9257: $namedaccess{$type} = '';
9258: $machineaccess{$type}= '';
9259: }
9260: if (ref($settings) eq 'HASH') {
9261: foreach my $type (@pages) {
9262: if (exists($settings->{$type})) {
9263: if (ref($settings->{$type}) eq 'HASH') {
9264: foreach my $key (keys(%{$settings->{$type}})) {
9265: if ($key eq 'namedusers') {
9266: $namedaccess{$type} = $settings->{$type}->{$key};
9267: } elsif ($key eq 'machines') {
9268: $machineaccess{$type} = $settings->{$type}->{$key};
9269: }
9270: }
9271: }
9272: }
9273: }
9274: }
9275: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
9276: my $rownum = 0;
9277: my $css_class;
9278: foreach my $type (@pages) {
9279: $rownum ++;
9280: $css_class = $rownum%2?' class="LC_odd_row"':'';
9281: $datatable .= '<tr'.$css_class.'>'.
9282: '<td><span class="LC_nobreak">'.
9283: $titles->{$type}.'</span></td>'.
9284: '<td class="LC_left_item">'.
9285: '<input type="text" name="'.$type.'_namedusers" '.
9286: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9287: '<td class="LC_right_item">'.
9288: '<span class="LC_nobreak">'.
9289: '<input type="text" name="'.$type.'_machines" '.
9290: 'value="'.$machineaccess{$type}.'" size="10" />'.
9291: '</span></td></tr>'."\n";
9292: }
9293: $$rowtotal += $rownum;
9294: return $datatable;
9295: }
9296:
9297: sub serverstatus_pages {
9298: return ('userstatus','lonstatus','loncron','server-status','codeversions',
9299: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
9300: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
9301: 'uniquecodes','diskusage','coursecatalog');
9302: }
9303:
9304: sub defaults_javascript {
9305: my ($settings) = @_;
9306: return unless (ref($settings) eq 'HASH');
9307: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9308: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9309: if ($maxnum eq '') {
9310: $maxnum = 0;
9311: }
9312: $maxnum ++;
9313: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
9314: return <<"ENDSCRIPT";
9315: <script type="text/javascript">
9316: // <![CDATA[
9317: function reorderTypes(form,caller) {
9318: var changedVal;
9319: $jstext
9320: var newpos = 'addinststatus_pos';
9321: var current = new Array;
9322: var maxh = $maxnum;
9323: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9324: var oldVal;
9325: if (caller == newpos) {
9326: changedVal = newitemVal;
9327: } else {
9328: var curritem = 'inststatus_pos_'+caller;
9329: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9330: current[newitemVal] = newpos;
9331: }
9332: for (var i=0; i<inststatuses.length; i++) {
9333: if (inststatuses[i] != caller) {
9334: var elementName = 'inststatus_pos_'+inststatuses[i];
9335: if (form.elements[elementName]) {
9336: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9337: current[currVal] = elementName;
9338: }
9339: }
9340: }
9341: for (var j=0; j<maxh; j++) {
9342: if (current[j] == undefined) {
9343: oldVal = j;
9344: }
9345: }
9346: if (oldVal < changedVal) {
9347: for (var k=oldVal+1; k<=changedVal ; k++) {
9348: var elementName = current[k];
9349: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9350: }
9351: } else {
9352: for (var k=changedVal; k<oldVal; k++) {
9353: var elementName = current[k];
9354: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9355: }
9356: }
9357: return;
9358: }
9359:
9360: // ]]>
9361: </script>
9362:
9363: ENDSCRIPT
9364: }
9365: }
9366:
9367: sub passwords_javascript {
9368: my ($prefix) = @_;
9369: my %intalert;
9370: if ($prefix eq 'passwords') {
9371: %intalert = &Apache::lonlocal::texthash (
9372: 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.',
9373: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
9374: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
9375: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
9376: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
9377: );
9378: } elsif ($prefix eq 'secrets') {
9379: %intalert = &Apache::lonlocal::texthash (
9380: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
9381: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
9382: );
9383: }
9384: &js_escape(\%intalert);
9385: my $defmin = $Apache::lonnet::passwdmin;
9386: my $intauthjs;
9387: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
9388:
9389: function warnIntAuth(field) {
9390: if (field.name == 'intauth_check') {
9391: if (field.value == '2') {
9392: alert('$intalert{authcheck}');
9393: }
9394: }
9395: if (field.name == 'intauth_cost') {
9396: field.value.replace(/\s/g,'');
9397: if (field.value != '') {
9398: var regexdigit=/^\\d+\$/;
9399: if (!regexdigit.test(field.value)) {
9400: alert('$intalert{authcost}');
9401: }
9402: }
9403: }
9404: return;
9405: }
9406:
9407: ENDSCRIPT
9408:
9409: }
9410:
9411: $intauthjs .= <<"ENDSCRIPT";
9412:
9413: function warnInt$prefix(field) {
9414: field.value.replace(/^\s+/,'');
9415: field.value.replace(/\s+\$/,'');
9416: var regexdigit=/^\\d+\$/;
9417: if (field.name == '${prefix}_min') {
9418: if (field.value == '') {
9419: alert('$intalert{passmin}');
9420: field.value = '$defmin';
9421: } else {
9422: if (!regexdigit.test(field.value)) {
9423: alert('$intalert{passmin}');
9424: field.value = '$defmin';
9425: }
9426: var minval = parseInt(field.value,10);
9427: if (minval < $defmin) {
9428: alert('$intalert{passmin}');
9429: field.value = '$defmin';
9430: }
9431: }
9432: } else {
9433: if (field.value == '0') {
9434: field.value = '';
9435: }
9436: if (field.value != '') {
9437: if (!regexdigit.test(field.value)) {
9438: if (field.name == '${prefix}_max') {
9439: alert('$intalert{passmax}');
9440: } else {
9441: if (field.name == '${prefix}_numsaved') {
9442: alert('$intalert{passnum}');
9443: }
9444: }
9445: field.value = '';
9446: }
9447: }
9448: }
9449: return;
9450: }
9451:
9452: ENDSCRIPT
9453: return &Apache::lonhtmlcommon::scripttag($intauthjs);
9454: }
9455:
9456: sub coursecategories_javascript {
9457: my ($settings) = @_;
9458: my ($output,$jstext,$cathash);
9459: if (ref($settings) eq 'HASH') {
9460: $cathash = $settings->{'cats'};
9461: }
9462: if (ref($cathash) eq 'HASH') {
9463: my (@cats,@jsarray,%idx);
9464: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
9465: if (@jsarray > 0) {
9466: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9467: for (my $i=0; $i<@jsarray; $i++) {
9468: if (ref($jsarray[$i]) eq 'ARRAY') {
9469: my $catstr = join('","',@{$jsarray[$i]});
9470: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9471: }
9472: }
9473: }
9474: } else {
9475: $jstext = ' var categories = Array(1);'."\n".
9476: ' categories[0] = Array("instcode_pos");'."\n";
9477: }
9478: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9479: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
9480: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9481: &js_escape(\$instcode_reserved);
9482: &js_escape(\$communities_reserved);
9483: &js_escape(\$choose_again);
9484: $output = <<"ENDSCRIPT";
9485: <script type="text/javascript">
9486: // <![CDATA[
9487: function reorderCats(form,parent,item,idx) {
9488: var changedVal;
9489: $jstext
9490: var newpos = 'addcategory_pos';
9491: if (parent == '') {
9492: var has_instcode = 0;
9493: var maxtop = categories[idx].length;
9494: for (var j=0; j<maxtop; j++) {
9495: if (categories[idx][j] == 'instcode::0') {
9496: has_instcode == 1;
9497: }
9498: }
9499: if (has_instcode == 0) {
9500: categories[idx][maxtop] = 'instcode_pos';
9501: }
9502: } else {
9503: newpos += '_'+parent;
9504: }
9505: var maxh = 1 + categories[idx].length;
9506: var current = new Array;
9507: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9508: if (item == newpos) {
9509: changedVal = newitemVal;
9510: } else {
9511: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9512: current[newitemVal] = newpos;
9513: }
9514: for (var i=0; i<categories[idx].length; i++) {
9515: var elementName = categories[idx][i];
9516: if (elementName != item) {
9517: if (form.elements[elementName]) {
9518: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9519: current[currVal] = elementName;
9520: }
9521: }
9522: }
9523: var oldVal;
9524: for (var j=0; j<maxh; j++) {
9525: if (current[j] == undefined) {
9526: oldVal = j;
9527: }
9528: }
9529: if (oldVal < changedVal) {
9530: for (var k=oldVal+1; k<=changedVal ; k++) {
9531: var elementName = current[k];
9532: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9533: }
9534: } else {
9535: for (var k=changedVal; k<oldVal; k++) {
9536: var elementName = current[k];
9537: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9538: }
9539: }
9540: return;
9541: }
9542:
9543: function categoryCheck(form) {
9544: if (form.elements['addcategory_name'].value == 'instcode') {
9545: alert('$instcode_reserved\\n$choose_again');
9546: return false;
9547: }
9548: if (form.elements['addcategory_name'].value == 'communities') {
9549: alert('$communities_reserved\\n$choose_again');
9550: return false;
9551: }
9552: return true;
9553: }
9554:
9555: // ]]>
9556: </script>
9557:
9558: ENDSCRIPT
9559: return $output;
9560: }
9561:
9562: sub initialize_categories {
9563: my ($itemcount) = @_;
9564: my ($datatable,$css_class,$chgstr);
9565: my %default_names = &Apache::lonlocal::texthash (
9566: instcode => 'Official courses (with institutional codes)',
9567: communities => 'Communities',
9568: );
9569: my $select0 = ' selected="selected"';
9570: my $select1 = '';
9571: foreach my $default ('instcode','communities') {
9572: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9573: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
9574: if ($default eq 'communities') {
9575: $select1 = $select0;
9576: $select0 = '';
9577: }
9578: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9579: .'<select name="'.$default.'_pos">'
9580: .'<option value="0"'.$select0.'>1</option>'
9581: .'<option value="1"'.$select1.'>2</option>'
9582: .'<option value="2">3</option></select> '
9583: .$default_names{$default}
9584: .'</span></td><td><span class="LC_nobreak">'
9585: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9586: .&mt('Display').'</label> <label>'
9587: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
9588: .'</label></span></td></tr>';
9589: $itemcount ++;
9590: }
9591: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9592: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
9593: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9594: .'<select name="addcategory_pos"'.$chgstr.'>'
9595: .'<option value="0">1</option>'
9596: .'<option value="1">2</option>'
9597: .'<option value="2" selected="selected">3</option></select> '
9598: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
9599: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9600: .'</td></tr>';
9601: return $datatable;
9602: }
9603:
9604: sub build_category_rows {
9605: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9606: my ($text,$name,$item,$chgstr);
9607: if (ref($cats) eq 'ARRAY') {
9608: my $maxdepth = scalar(@{$cats});
9609: if (ref($cats->[$depth]) eq 'HASH') {
9610: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9611: my $numchildren = @{$cats->[$depth]{$parent}};
9612: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9613: $text .= '<td><table class="LC_data_table">';
9614: my ($idxnum,$parent_name,$parent_item);
9615: my $higher = $depth - 1;
9616: if ($higher == 0) {
9617: $parent_name = &escape($parent).'::'.$higher;
9618: } else {
9619: if (ref($path) eq 'ARRAY') {
9620: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9621: }
9622: }
9623: $parent_item = 'addcategory_pos_'.$parent_name;
9624: for (my $j=0; $j<=$numchildren; $j++) {
9625: if ($j < $numchildren) {
9626: $name = $cats->[$depth]{$parent}[$j];
9627: $item = &escape($name).':'.&escape($parent).':'.$depth;
9628: $idxnum = $idx->{$item};
9629: } else {
9630: $name = $parent_name;
9631: $item = $parent_item;
9632: }
9633: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9634: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
9635: for (my $i=0; $i<=$numchildren; $i++) {
9636: my $vpos = $i+1;
9637: my $selstr;
9638: if ($j == $i) {
9639: $selstr = ' selected="selected" ';
9640: }
9641: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9642: }
9643: $text .= '</select> ';
9644: if ($j < $numchildren) {
9645: my $deeper = $depth+1;
9646: $text .= $name.' '
9647: .'<label><input type="checkbox" name="deletecategory" value="'
9648: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9649: if(ref($path) eq 'ARRAY') {
9650: push(@{$path},$name);
9651: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
9652: pop(@{$path});
9653: }
9654: } else {
9655: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
9656: if ($j == $numchildren) {
9657: $text .= $name;
9658: } else {
9659: $text .= $item;
9660: }
9661: $text .= '" value="" />';
9662: }
9663: $text .= '</td></tr>';
9664: }
9665: $text .= '</table></td>';
9666: } else {
9667: my $higher = $depth-1;
9668: if ($higher == 0) {
9669: $name = &escape($parent).'::'.$higher;
9670: } else {
9671: if (ref($path) eq 'ARRAY') {
9672: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9673: }
9674: }
9675: my $colspan;
9676: if ($parent ne 'instcode') {
9677: $colspan = $maxdepth - $depth - 1;
9678: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
9679: }
9680: }
9681: }
9682: }
9683: return $text;
9684: }
9685:
9686: sub modifiable_userdata_row {
9687: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9688: $rowid,$customcss,$rowstyle) = @_;
9689: my ($role,$rolename,$statustype);
9690: $role = $item;
9691: if ($context eq 'cancreate') {
9692: if ($item =~ /^(emailusername)_(.+)$/) {
9693: $role = $1;
9694: $statustype = $2;
9695: if (ref($usertypes) eq 'HASH') {
9696: if ($usertypes->{$statustype}) {
9697: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9698: } else {
9699: $rolename = &mt('Data provided by user');
9700: }
9701: }
9702: }
9703: } elsif ($context eq 'selfcreate') {
9704: if (ref($usertypes) eq 'HASH') {
9705: $rolename = $usertypes->{$role};
9706: } else {
9707: $rolename = $role;
9708: }
9709: } else {
9710: if ($role eq 'cr') {
9711: $rolename = &mt('Custom role');
9712: } else {
9713: $rolename = &Apache::lonnet::plaintext($role);
9714: }
9715: }
9716: my (@fields,%fieldtitles);
9717: if (ref($fieldsref) eq 'ARRAY') {
9718: @fields = @{$fieldsref};
9719: } else {
9720: @fields = ('lastname','firstname','middlename','generation',
9721: 'permanentemail','id');
9722: }
9723: if ((ref($titlesref) eq 'HASH')) {
9724: %fieldtitles = %{$titlesref};
9725: } else {
9726: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9727: }
9728: my $output;
9729: my $css_class;
9730: if ($rowcount%2) {
9731: $css_class = 'LC_odd_row';
9732: }
9733: if ($customcss) {
9734: $css_class .= " $customcss";
9735: }
9736: $css_class =~ s/^\s+//;
9737: if ($css_class) {
9738: $css_class = ' class="'.$css_class.'"';
9739: }
9740: if ($rowstyle) {
9741: $css_class .= ' style="'.$rowstyle.'"';
9742: }
9743: if ($rowid) {
9744: $rowid = ' id="'.$rowid.'"';
9745: }
9746:
9747: $output = '<tr '.$css_class.$rowid.'>'.
9748: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9749: '<td class="LC_left_item" colspan="2"><table>';
9750: my $rem;
9751: my %checks;
9752: if (ref($settings) eq 'HASH') {
9753: if (ref($settings->{$context}) eq 'HASH') {
9754: if (ref($settings->{$context}->{$role}) eq 'HASH') {
9755: my $hashref = $settings->{$context}->{$role};
9756: if ($role eq 'emailusername') {
9757: if ($statustype) {
9758: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9759: $hashref = $settings->{$context}->{$role}->{$statustype};
9760: if (ref($hashref) eq 'HASH') {
9761: foreach my $field (@fields) {
9762: if ($hashref->{$field}) {
9763: $checks{$field} = $hashref->{$field};
9764: }
9765: }
9766: }
9767: }
9768: }
9769: } else {
9770: if (ref($hashref) eq 'HASH') {
9771: foreach my $field (@fields) {
9772: if ($hashref->{$field}) {
9773: $checks{$field} = ' checked="checked" ';
9774: }
9775: }
9776: }
9777: }
9778: }
9779: }
9780: }
9781:
9782: my $total = scalar(@fields);
9783: for (my $i=0; $i<$total; $i++) {
9784: $rem = $i%($numinrow);
9785: if ($rem == 0) {
9786: if ($i > 0) {
9787: $output .= '</tr>';
9788: }
9789: $output .= '<tr>';
9790: }
9791: my $check = ' ';
9792: unless ($role eq 'emailusername') {
9793: if (exists($checks{$fields[$i]})) {
9794: $check = $checks{$fields[$i]};
9795: } else {
9796: if ($role eq 'st') {
9797: if (ref($settings) ne 'HASH') {
9798: $check = ' checked="checked" ';
9799: }
9800: }
9801: }
9802: }
9803: $output .= '<td class="LC_left_item">'.
9804: '<span class="LC_nobreak">';
9805: if ($role eq 'emailusername') {
9806: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9807: $checks{$fields[$i]} = 'omit';
9808: }
9809: foreach my $option ('required','optional','omit') {
9810: my $checked='';
9811: if ($checks{$fields[$i]} eq $option) {
9812: $checked='checked="checked" ';
9813: }
9814: $output .= '<label>'.
9815: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
9816: &mt($option).'</label>'.(' ' x2);
9817: }
9818: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9819: } else {
9820: $output .= '<label>'.
9821: '<input type="checkbox" name="canmodify_'.$role.'" '.
9822: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9823: '</label>';
9824: }
9825: $output .= '</span></td>';
9826: }
9827: $rem = $total%$numinrow;
9828: my $colsleft;
9829: if ($rem) {
9830: $colsleft = $numinrow - $rem;
9831: }
9832: if ($colsleft > 1) {
9833: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9834: ' </td>';
9835: } elsif ($colsleft == 1) {
9836: $output .= '<td class="LC_left_item"> </td>';
9837: }
9838: $output .= '</tr></table></td></tr>';
9839: return $output;
9840: }
9841:
9842: sub insttypes_row {
9843: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9844: $customcss,$rowstyle) = @_;
9845: my %lt = &Apache::lonlocal::texthash (
9846: cansearch => 'Users allowed to search',
9847: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
9848: lockablenames => 'User preference to lock name',
9849: selfassign => 'Self-reportable affiliations',
9850: overrides => "Override domain's helpdesk settings based on requester's affiliation",
9851: );
9852: my $showdom;
9853: if ($context eq 'cansearch') {
9854: $showdom = ' ('.$dom.')';
9855: }
9856: my $class = 'LC_left_item';
9857: if ($context eq 'statustocreate') {
9858: $class = 'LC_right_item';
9859: }
9860: my $css_class;
9861: if ($$rowtotal%2) {
9862: $css_class = 'LC_odd_row';
9863: }
9864: if ($customcss) {
9865: $css_class .= ' '.$customcss;
9866: }
9867: $css_class =~ s/^\s+//;
9868: if ($css_class) {
9869: $css_class = ' class="'.$css_class.'"';
9870: }
9871: if ($rowstyle) {
9872: $css_class .= ' style="'.$rowstyle.'"';
9873: }
9874: if ($onclick) {
9875: $onclick = 'onclick="'.$onclick.'" ';
9876: }
9877: my $output = '<tr'.$css_class.'>'.
9878: '<td>'.$lt{$context}.$showdom.
9879: '</td><td class="'.$class.'" colspan="2"><table>';
9880: my $rem;
9881: if (ref($types) eq 'ARRAY') {
9882: for (my $i=0; $i<@{$types}; $i++) {
9883: if (defined($usertypes->{$types->[$i]})) {
9884: my $rem = $i%($numinrow);
9885: if ($rem == 0) {
9886: if ($i > 0) {
9887: $output .= '</tr>';
9888: }
9889: $output .= '<tr>';
9890: }
9891: my $check = ' ';
9892: if (ref($settings) eq 'HASH') {
9893: if (ref($settings->{$context}) eq 'ARRAY') {
9894: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9895: $check = ' checked="checked" ';
9896: }
9897: } elsif (ref($settings->{$context}) eq 'HASH') {
9898: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9899: $check = ' checked="checked" ';
9900: }
9901: } elsif ($context eq 'statustocreate') {
9902: $check = ' checked="checked" ';
9903: }
9904: }
9905: $output .= '<td class="LC_left_item">'.
9906: '<span class="LC_nobreak"><label>'.
9907: '<input type="checkbox" name="'.$context.'" '.
9908: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
9909: $usertypes->{$types->[$i]}.'</label></span></td>';
9910: }
9911: }
9912: $rem = @{$types}%($numinrow);
9913: }
9914: my $colsleft = $numinrow - $rem;
9915: if ($context eq 'overrides') {
9916: if ($colsleft > 1) {
9917: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9918: } else {
9919: $output .= '<td class="LC_left_item">';
9920: }
9921: $output .= ' ';
9922: } else {
9923: if ($rem == 0) {
9924: $output .= '<tr>';
9925: }
9926: if ($colsleft > 1) {
9927: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9928: } else {
9929: $output .= '<td class="LC_left_item">';
9930: }
9931: my $defcheck = ' ';
9932: if (ref($settings) eq 'HASH') {
9933: if (ref($settings->{$context}) eq 'ARRAY') {
9934: if (grep(/^default$/,@{$settings->{$context}})) {
9935: $defcheck = ' checked="checked" ';
9936: }
9937: } elsif ($context eq 'statustocreate') {
9938: $defcheck = ' checked="checked" ';
9939: }
9940: }
9941: $output .= '<span class="LC_nobreak"><label>'.
9942: '<input type="checkbox" name="'.$context.'" '.
9943: 'value="default"'.$defcheck.$onclick.' />'.
9944: $othertitle.'</label></span>';
9945: }
9946: $output .= '</td></tr></table></td></tr>';
9947: return $output;
9948: }
9949:
9950: sub sorted_searchtitles {
9951: my %searchtitles = &Apache::lonlocal::texthash(
9952: 'uname' => 'username',
9953: 'lastname' => 'last name',
9954: 'lastfirst' => 'last name, first name',
9955: );
9956: my @titleorder = ('uname','lastname','lastfirst');
9957: return (\%searchtitles,\@titleorder);
9958: }
9959:
9960: sub sorted_searchtypes {
9961: my %srchtypes_desc = (
9962: exact => 'is exact match',
9963: contains => 'contains ..',
9964: begins => 'begins with ..',
9965: );
9966: my @srchtypeorder = ('exact','begins','contains');
9967: return (\%srchtypes_desc,\@srchtypeorder);
9968: }
9969:
9970: sub usertype_update_row {
9971: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9972: my $datatable;
9973: my $numinrow = 4;
9974: foreach my $type (@{$types}) {
9975: if (defined($usertypes->{$type})) {
9976: $$rownums ++;
9977: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9978: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9979: '</td><td class="LC_left_item"><table>';
9980: for (my $i=0; $i<@{$fields}; $i++) {
9981: my $rem = $i%($numinrow);
9982: if ($rem == 0) {
9983: if ($i > 0) {
9984: $datatable .= '</tr>';
9985: }
9986: $datatable .= '<tr>';
9987: }
9988: my $check = ' ';
9989: if (ref($settings) eq 'HASH') {
9990: if (ref($settings->{'fields'}) eq 'HASH') {
9991: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9992: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9993: $check = ' checked="checked" ';
9994: }
9995: }
9996: }
9997: }
9998:
9999: if ($i == @{$fields}-1) {
10000: my $colsleft = $numinrow - $rem;
10001: if ($colsleft > 1) {
10002: $datatable .= '<td colspan="'.$colsleft.'">';
10003: } else {
10004: $datatable .= '<td>';
10005: }
10006: } else {
10007: $datatable .= '<td>';
10008: }
10009: $datatable .= '<span class="LC_nobreak"><label>'.
10010: '<input type="checkbox" name="updateable_'.$type.
10011: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
10012: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
10013: }
10014: $datatable .= '</tr></table></td></tr>';
10015: }
10016: }
10017: return $datatable;
10018: }
10019:
10020: sub modify_login {
10021: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
10022: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
10023: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
10024: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
10025: %title = ( coursecatalog => 'Display course catalog',
10026: adminmail => 'Display administrator E-mail address',
10027: helpdesk => 'Display "Contact Helpdesk" link',
10028: newuser => 'Link for visitors to create a user account',
10029: loginheader => 'Log-in box header',
10030: saml => 'Dual SSO and non-SSO login');
10031: @offon = ('off','on');
10032: if (ref($domconfig{login}) eq 'HASH') {
10033: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10034: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10035: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10036: }
10037: }
10038: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
10039: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
10040: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
10041: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
10042: $saml{$lonhost} = 1;
10043: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
10044: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
10045: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
10046: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
10047: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
10048: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
10049: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
10050: }
10051: }
10052: }
10053: }
10054: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10055: \%domconfig,\%loginhash);
10056: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
10057: foreach my $item (@toggles) {
10058: $loginhash{login}{$item} = $env{'form.'.$item};
10059: }
10060: $loginhash{login}{loginheader} = $env{'form.loginheader'};
10061: if (ref($colchanges{'login'}) eq 'HASH') {
10062: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10063: \%loginhash);
10064: }
10065:
10066: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10067: my %domservers = &Apache::lonnet::get_servers($dom);
10068: my @loginvia_attribs = ('serverpath','custompath','exempt');
10069: if (keys(%servers) > 1) {
10070: foreach my $lonhost (keys(%servers)) {
10071: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10072: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10073: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10074: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10075: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10076: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10077: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10078: $changes{'loginvia'}{$lonhost} = 1;
10079: } else {
10080: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10081: $changes{'loginvia'}{$lonhost} = 1;
10082: }
10083: } else {
10084: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10085: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10086: $changes{'loginvia'}{$lonhost} = 1;
10087: }
10088: }
10089: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10090: foreach my $item (@loginvia_attribs) {
10091: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10092: }
10093: } else {
10094: foreach my $item (@loginvia_attribs) {
10095: my $new = $env{'form.'.$lonhost.'_'.$item};
10096: if (($item eq 'serverpath') && ($new eq 'custom')) {
10097: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10098: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10099: $new = '/';
10100: }
10101: }
10102: if (($item eq 'custompath') &&
10103: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10104: $new = '';
10105: }
10106: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10107: $changes{'loginvia'}{$lonhost} = 1;
10108: }
10109: if ($item eq 'exempt') {
10110: $new = &check_exempt_addresses($new);
10111: }
10112: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10113: }
10114: }
10115: } else {
10116: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10117: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10118: $changes{'loginvia'}{$lonhost} = 1;
10119: foreach my $item (@loginvia_attribs) {
10120: my $new = $env{'form.'.$lonhost.'_'.$item};
10121: if (($item eq 'serverpath') && ($new eq 'custom')) {
10122: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10123: $new = '/';
10124: }
10125: }
10126: if (($item eq 'custompath') &&
10127: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10128: $new = '';
10129: }
10130: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10131: }
10132: }
10133: }
10134: }
10135: }
10136:
10137: my $servadm = $r->dir_config('lonAdmEMail');
10138: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10139: if (ref($domconfig{'login'}) eq 'HASH') {
10140: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10141: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10142: if ($lang eq 'nolang') {
10143: push(@currlangs,$lang);
10144: } elsif (defined($langchoices{$lang})) {
10145: push(@currlangs,$lang);
10146: } else {
10147: next;
10148: }
10149: }
10150: }
10151: }
10152: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10153: if (@currlangs > 0) {
10154: foreach my $lang (@currlangs) {
10155: if (grep(/^\Q$lang\E$/,@delurls)) {
10156: $changes{'helpurl'}{$lang} = 1;
10157: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10158: $changes{'helpurl'}{$lang} = 1;
10159: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10160: push(@newlangs,$lang);
10161: } else {
10162: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10163: }
10164: }
10165: }
10166: unless (grep(/^nolang$/,@currlangs)) {
10167: if ($env{'form.loginhelpurl_nolang.filename'}) {
10168: $changes{'helpurl'}{'nolang'} = 1;
10169: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10170: push(@newlangs,'nolang');
10171: }
10172: }
10173: if ($env{'form.loginhelpurl_add_lang'}) {
10174: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10175: ($env{'form.loginhelpurl_add_file.filename'})) {
10176: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10177: $addedfile = $env{'form.loginhelpurl_add_lang'};
10178: }
10179: }
10180: if ((@newlangs > 0) || ($addedfile)) {
10181: my $error;
10182: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10183: if ($configuserok eq 'ok') {
10184: if ($switchserver) {
10185: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10186: } elsif ($author_ok eq 'ok') {
10187: my @allnew = @newlangs;
10188: if ($addedfile ne '') {
10189: push(@allnew,$addedfile);
10190: }
10191: foreach my $lang (@allnew) {
10192: my $formelem = 'loginhelpurl_'.$lang;
10193: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10194: $formelem = 'loginhelpurl_add_file';
10195: }
10196: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10197: "help/$lang",'','',$newfile{$lang});
10198: if ($result eq 'ok') {
10199: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10200: $changes{'helpurl'}{$lang} = 1;
10201: } else {
10202: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10203: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10204: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
10205: (!grep(/^\Q$lang\E$/,@delurls))) {
10206: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10207: }
10208: }
10209: }
10210: } else {
10211: $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);
10212: }
10213: } else {
10214: $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);
10215: }
10216: if ($error) {
10217: &Apache::lonnet::logthis($error);
10218: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10219: }
10220: }
10221:
10222: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10223: if (ref($domconfig{'login'}) eq 'HASH') {
10224: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10225: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10226: if ($domservers{$lonhost}) {
10227: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10228: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
10229: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
10230: }
10231: }
10232: }
10233: }
10234: }
10235: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10236: foreach my $lonhost (sort(keys(%domservers))) {
10237: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10238: $changes{'headtag'}{$lonhost} = 1;
10239: } else {
10240: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10241: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10242: }
10243: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10244: push(@newhosts,$lonhost);
10245: } elsif ($currheadtagurls{$lonhost}) {
10246: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10247: if ($currexempt{$lonhost}) {
10248: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
10249: $changes{'headtag'}{$lonhost} = 1;
10250: }
10251: } elsif ($possexempt{$lonhost}) {
10252: $changes{'headtag'}{$lonhost} = 1;
10253: }
10254: if ($possexempt{$lonhost}) {
10255: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10256: }
10257: }
10258: }
10259: }
10260: if (@newhosts) {
10261: my $error;
10262: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10263: if ($configuserok eq 'ok') {
10264: if ($switchserver) {
10265: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10266: } elsif ($author_ok eq 'ok') {
10267: foreach my $lonhost (@newhosts) {
10268: my $formelem = 'loginheadtag_'.$lonhost;
10269: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10270: "login/headtag/$lonhost",'','',
10271: $env{'form.loginheadtag_'.$lonhost.'.filename'});
10272: if ($result eq 'ok') {
10273: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10274: $changes{'headtag'}{$lonhost} = 1;
10275: if ($possexempt{$lonhost}) {
10276: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10277: }
10278: } else {
10279: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10280: $newheadtagurls{$lonhost},$result);
10281: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10282: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10283: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10284: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10285: }
10286: }
10287: }
10288: } else {
10289: $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);
10290: }
10291: } else {
10292: $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);
10293: }
10294: if ($error) {
10295: &Apache::lonnet::logthis($error);
10296: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10297: }
10298: }
10299: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
10300: my @newsamlimgs;
10301: foreach my $lonhost (keys(%domservers)) {
10302: if ($env{'form.saml_'.$lonhost}) {
10303: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
10304: push(@newsamlimgs,$lonhost);
10305: }
10306: foreach my $item ('text','alt','url','title','window','notsso') {
10307: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
10308: }
10309: if ($saml{$lonhost}) {
10310: if ($env{'form.saml_window_'.$lonhost} ne '1') {
10311: $env{'form.saml_window_'.$lonhost} = '';
10312: }
10313: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
10314: #FIXME Need to obsolete published image
10315: delete($currsaml{$lonhost}{'img'});
10316: $changes{'saml'}{$lonhost} = 1;
10317: }
10318: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
10319: $changes{'saml'}{$lonhost} = 1;
10320: }
10321: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
10322: $changes{'saml'}{$lonhost} = 1;
10323: }
10324: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
10325: $changes{'saml'}{$lonhost} = 1;
10326: }
10327: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
10328: $changes{'saml'}{$lonhost} = 1;
10329: }
10330: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
10331: $changes{'saml'}{$lonhost} = 1;
10332: }
10333: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
10334: $changes{'saml'}{$lonhost} = 1;
10335: }
10336: } else {
10337: $changes{'saml'}{$lonhost} = 1;
10338: }
10339: foreach my $item ('text','alt','url','title','window','notsso') {
10340: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
10341: }
10342: } else {
10343: if ($saml{$lonhost}) {
10344: $changes{'saml'}{$lonhost} = 1;
10345: delete($currsaml{$lonhost});
10346: }
10347: }
10348: }
10349: foreach my $posshost (keys(%currsaml)) {
10350: unless (exists($domservers{$posshost})) {
10351: delete($currsaml{$posshost});
10352: }
10353: }
10354: %{$loginhash{'login'}{'saml'}} = %currsaml;
10355: if (@newsamlimgs) {
10356: my $error;
10357: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10358: if ($configuserok eq 'ok') {
10359: if ($switchserver) {
10360: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
10361: } elsif ($author_ok eq 'ok') {
10362: foreach my $lonhost (@newsamlimgs) {
10363: my $formelem = 'saml_img_'.$lonhost;
10364: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10365: "login/saml/$lonhost",'','',
10366: $env{'form.saml_img_'.$lonhost.'.filename'});
10367: if ($result eq 'ok') {
10368: $currsaml{$lonhost}{'img'} = $imgurl;
10369: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
10370: $changes{'saml'}{$lonhost} = 1;
10371: } else {
10372: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
10373: $lonhost,$result);
10374: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10375: }
10376: }
10377: } else {
10378: $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);
10379: }
10380: } else {
10381: $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);
10382: }
10383: if ($error) {
10384: &Apache::lonnet::logthis($error);
10385: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10386: }
10387: }
10388: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
10389:
10390: my $defaulthelpfile = '/adm/loginproblems.html';
10391: my $defaulttext = &mt('Default in use');
10392:
10393: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
10394: $dom);
10395: if ($putresult eq 'ok') {
10396: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
10397: my %defaultchecked = (
10398: 'coursecatalog' => 'on',
10399: 'helpdesk' => 'on',
10400: 'adminmail' => 'off',
10401: 'newuser' => 'off',
10402: );
10403: if (ref($domconfig{'login'}) eq 'HASH') {
10404: foreach my $item (@toggles) {
10405: if ($defaultchecked{$item} eq 'on') {
10406: if (($domconfig{'login'}{$item} eq '0') &&
10407: ($env{'form.'.$item} eq '1')) {
10408: $changes{$item} = 1;
10409: } elsif (($domconfig{'login'}{$item} eq '' ||
10410: $domconfig{'login'}{$item} eq '1') &&
10411: ($env{'form.'.$item} eq '0')) {
10412: $changes{$item} = 1;
10413: }
10414: } elsif ($defaultchecked{$item} eq 'off') {
10415: if (($domconfig{'login'}{$item} eq '1') &&
10416: ($env{'form.'.$item} eq '0')) {
10417: $changes{$item} = 1;
10418: } elsif (($domconfig{'login'}{$item} eq '' ||
10419: $domconfig{'login'}{$item} eq '0') &&
10420: ($env{'form.'.$item} eq '1')) {
10421: $changes{$item} = 1;
10422: }
10423: }
10424: }
10425: }
10426: if (keys(%changes) > 0 || $colchgtext) {
10427: &Apache::loncommon::devalidate_domconfig_cache($dom);
10428: if (exists($changes{'saml'})) {
10429: my $hostid_in_use;
10430: my @hosts = &Apache::lonnet::current_machine_ids();
10431: if (@hosts > 1) {
10432: foreach my $hostid (@hosts) {
10433: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
10434: $hostid_in_use = $hostid;
10435: last;
10436: }
10437: }
10438: } else {
10439: $hostid_in_use = $r->dir_config('lonHostID');
10440: }
10441: if (($hostid_in_use) &&
10442: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
10443: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
10444: }
10445: if (ref($lastactref) eq 'HASH') {
10446: if (ref($changes{'saml'}) eq 'HASH') {
10447: my %updates;
10448: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
10449: $lastactref->{'samllanding'} = \%updates;
10450: }
10451: }
10452: }
10453: if (ref($lastactref) eq 'HASH') {
10454: $lastactref->{'domainconfig'} = 1;
10455: }
10456: $resulttext = &mt('Changes made:').'<ul>';
10457: foreach my $item (sort(keys(%changes))) {
10458: if ($item eq 'loginvia') {
10459: if (ref($changes{$item}) eq 'HASH') {
10460: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10461: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10462: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10463: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10464: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10465: $protocol = 'http' if ($protocol ne 'https');
10466: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10467:
10468: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10469: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10470: } else {
10471: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10472: }
10473: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10474: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10475: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10476: }
10477: $resulttext .= '</li>';
10478: } else {
10479: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10480: }
10481: } else {
10482: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
10483: }
10484: }
10485: $resulttext .= '</ul></li>';
10486: }
10487: } elsif ($item eq 'helpurl') {
10488: if (ref($changes{$item}) eq 'HASH') {
10489: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10490: if (grep(/^\Q$lang\E$/,@delurls)) {
10491: my ($chg,$link);
10492: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10493: if ($lang eq 'nolang') {
10494: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10495: } else {
10496: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10497: }
10498: $resulttext .= '<li>'.$chg.'</li>';
10499: } else {
10500: my $chg;
10501: if ($lang eq 'nolang') {
10502: $chg = &mt('custom log-in help file for no preferred language');
10503: } else {
10504: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10505: }
10506: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10507: $loginhash{'login'}{'helpurl'}{$lang}.
10508: '?inhibitmenu=yes',$chg,600,500).
10509: '</li>';
10510: }
10511: }
10512: }
10513: } elsif ($item eq 'headtag') {
10514: if (ref($changes{$item}) eq 'HASH') {
10515: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10516: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10517: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10518: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10519: $resulttext .= '<li><a href="'.
10520: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10521: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10522: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10523: if ($possexempt{$lonhost}) {
10524: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10525: } else {
10526: $resulttext .= &mt('included for any client IP');
10527: }
10528: $resulttext .= '</li>';
10529: }
10530: }
10531: }
10532: } elsif ($item eq 'saml') {
10533: if (ref($changes{$item}) eq 'HASH') {
10534: my %notlt = (
10535: text => 'Text for log-in by SSO',
10536: img => 'SSO button image',
10537: alt => 'Alt text for button image',
10538: url => 'SSO URL',
10539: title => 'Tooltip for SSO link',
10540: window => 'Pop-up window if iframe',
10541: notsso => 'Text for non-SSO log-in',
10542: );
10543: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10544: if (ref($currsaml{$lonhost}) eq 'HASH') {
10545: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
10546: '<ul>';
10547: foreach my $key ('text','img','alt','url','title','window','notsso') {
10548: if ($currsaml{$lonhost}{$key} eq '') {
10549: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
10550: } else {
10551: my $value = "'$currsaml{$lonhost}{$key}'";
10552: if ($key eq 'img') {
10553: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
10554: } elsif ($key eq 'window') {
10555: $value = 'On';
10556: }
10557: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
10558: $value).'</li>';
10559: }
10560: }
10561: $resulttext .= '</ul></li>';
10562: } else {
10563: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
10564: }
10565: }
10566: }
10567: } elsif ($item eq 'captcha') {
10568: if (ref($loginhash{'login'}) eq 'HASH') {
10569: my $chgtxt;
10570: if ($loginhash{'login'}{$item} eq 'notused') {
10571: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10572: } else {
10573: my %captchas = &captcha_phrases();
10574: if ($captchas{$loginhash{'login'}{$item}}) {
10575: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10576: } else {
10577: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10578: }
10579: }
10580: $resulttext .= '<li>'.$chgtxt.'</li>';
10581: }
10582: } elsif ($item eq 'recaptchakeys') {
10583: if (ref($loginhash{'login'}) eq 'HASH') {
10584: my ($privkey,$pubkey);
10585: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10586: $pubkey = $loginhash{'login'}{$item}{'public'};
10587: $privkey = $loginhash{'login'}{$item}{'private'};
10588: }
10589: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10590: if (!$pubkey) {
10591: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10592: } else {
10593: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10594: }
10595: if (!$privkey) {
10596: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10597: } else {
10598: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
10599: }
10600: $chgtxt .= '</ul>';
10601: $resulttext .= '<li>'.$chgtxt.'</li>';
10602: }
10603: } elsif ($item eq 'recaptchaversion') {
10604: if (ref($loginhash{'login'}) eq 'HASH') {
10605: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
10606: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
10607: '</li>';
10608: }
10609: }
10610: } else {
10611: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10612: }
10613: }
10614: $resulttext .= $colchgtext.'</ul>';
10615: } else {
10616: $resulttext = &mt('No changes made to log-in page settings');
10617: }
10618: } else {
10619: $resulttext = '<span class="LC_error">'.
10620: &mt('An error occurred: [_1]',$putresult).'</span>';
10621: }
10622: if ($errors) {
10623: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
10624: $errors.'</ul>';
10625: }
10626: return $resulttext;
10627: }
10628:
10629: sub check_exempt_addresses {
10630: my ($iplist) = @_;
10631: $iplist =~ s/^\s+//;
10632: $iplist =~ s/\s+$//;
10633: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10634: my (@okips,$new);
10635: foreach my $ip (@poss_ips) {
10636: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10637: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10638: push(@okips,$ip);
10639: }
10640: }
10641: }
10642: if (@okips > 0) {
10643: $new = join(',',@okips);
10644: } else {
10645: $new = '';
10646: }
10647: return $new;
10648: }
10649:
10650: sub color_font_choices {
10651: my %choices =
10652: &Apache::lonlocal::texthash (
10653: img => "Header",
10654: bgs => "Background colors",
10655: links => "Link colors",
10656: images => "Images",
10657: font => "Font color",
10658: fontmenu => "Font menu",
10659: pgbg => "Page",
10660: tabbg => "Header",
10661: sidebg => "Border",
10662: link => "Link",
10663: alink => "Active link",
10664: vlink => "Visited link",
10665: );
10666: return %choices;
10667: }
10668:
10669: sub modify_ipaccess {
10670: my ($dom,$lastactref,%domconfig) = @_;
10671: my (@allpos,%changes,%confhash,$errors,$resulttext);
10672: my (@items,%deletions,%itemids,@warnings);
10673: my ($typeorder,$types) = &commblocktype_text();
10674: if ($env{'form.ipaccess_add'}) {
10675: my $name = $env{'form.ipaccess_name_add'};
10676: my ($newid,$error) = &get_ipaccess_id($dom,$name);
10677: if ($newid) {
10678: $itemids{'add'} = $newid;
10679: push(@items,'add');
10680: $changes{$newid} = 1;
10681: } else {
10682: $error = &mt('Failed to acquire unique ID for new IP access control item');
10683: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10684: }
10685: }
10686: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10687: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
10688: if (@todelete) {
10689: map { $deletions{$_} = 1; } @todelete;
10690: }
10691: my $maxnum = $env{'form.ipaccess_maxnum'};
10692: for (my $i=0; $i<$maxnum; $i++) {
10693: my $itemid = $env{'form.ipaccess_id_'.$i};
10694: $itemid =~ s/\D+//g;
10695: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10696: if ($deletions{$itemid}) {
10697: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
10698: } else {
10699: push(@items,$i);
10700: $itemids{$i} = $itemid;
10701: }
10702: }
10703: }
10704: }
10705: foreach my $idx (@items) {
10706: my $itemid = $itemids{$idx};
10707: next unless ($itemid);
10708: my %current;
10709: unless ($idx eq 'add') {
10710: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10711: %current = %{$domconfig{'ipaccess'}{$itemid}};
10712: }
10713: }
10714: my $position = $env{'form.ipaccess_pos_'.$itemid};
10715: $position =~ s/\D+//g;
10716: if ($position ne '') {
10717: $allpos[$position] = $itemid;
10718: }
10719: my $name = $env{'form.ipaccess_name_'.$idx};
10720: $name =~ s/^\s+|\s+$//g;
10721: $confhash{$itemid}{'name'} = $name;
10722: my $possrange = $env{'form.ipaccess_range_'.$idx};
10723: $possrange =~ s/^\s+|\s+$//g;
10724: unless ($possrange eq '') {
10725: $possrange =~ s/[\r\n]+/\s/g;
10726: $possrange =~ s/\s*-\s*/-/g;
10727: $possrange =~ s/\s+/,/g;
10728: $possrange =~ s/,+/,/g;
10729: if ($possrange ne '') {
10730: my (@ok,$count);
10731: $count = 0;
10732: foreach my $poss (split(/\,/,$possrange)) {
10733: $count ++;
10734: $poss = &validate_ip_pattern($poss);
10735: if ($poss ne '') {
10736: push(@ok,$poss);
10737: }
10738: }
10739: my $diff = $count - scalar(@ok);
10740: if ($diff) {
10741: $errors .= '<li><span class="LC_error">'.
10742: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
10743: $diff,$name).
10744: '</span></li>';
10745: }
10746: if (@ok) {
10747: my @cidr_list;
10748: foreach my $item (@ok) {
10749: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
10750: }
10751: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
10752: }
10753: }
10754: }
10755: foreach my $field ('name','ip') {
10756: unless (($idx eq 'add') || ($changes{$itemid})) {
10757: if ($current{$field} ne $confhash{$itemid}{$field}) {
10758: $changes{$itemid} = 1;
10759: last;
10760: }
10761: }
10762: }
10763: $confhash{$itemid}{'commblocks'} = {};
10764:
10765: my %commblocks;
10766: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
10767: foreach my $type (@{$typeorder}) {
10768: if ($commblocks{$type}) {
10769: $confhash{$itemid}{'commblocks'}{$type} = 'on';
10770: }
10771: unless (($idx eq 'add') || ($changes{$itemid})) {
10772: if (ref($current{'commblocks'}) eq 'HASH') {
10773: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
10774: $changes{$itemid} = 1;
10775: }
10776: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
10777: $changes{$itemid} = 1;
10778: }
10779: }
10780: }
10781: $confhash{$itemid}{'courses'} = {};
10782: my %crsdeletions;
10783: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
10784: if (@delcrs) {
10785: map { $crsdeletions{$_} = 1; } @delcrs;
10786: }
10787: if (ref($current{'courses'}) eq 'HASH') {
10788: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
10789: if ($crsdeletions{$cid}) {
10790: $changes{$itemid} = 1;
10791: } else {
10792: $confhash{$itemid}{'courses'}{$cid} = 1;
10793: }
10794: }
10795: }
10796: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
10797: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
10798: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
10799: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
10800: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
10801: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
10802: $errors .= '<li><span class="LC_error">'.
10803: &mt('Invalid courseID [_1] omitted from list of allowed courses',
10804: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
10805: '</span></li>';
10806: } else {
10807: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
10808: $changes{$itemid} = 1;
10809: }
10810: }
10811: }
10812: if (@allpos > 0) {
10813: my $idx = 0;
10814: foreach my $itemid (@allpos) {
10815: if ($itemid ne '') {
10816: $confhash{$itemid}{'order'} = $idx;
10817: unless ($changes{$itemid}) {
10818: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10819: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10820: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
10821: $changes{$itemid} = 1;
10822: }
10823: }
10824: }
10825: }
10826: $idx ++;
10827: }
10828: }
10829: }
10830: if (keys(%changes)) {
10831: my %defaultshash = (
10832: ipaccess => \%confhash,
10833: );
10834: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10835: $dom);
10836: if ($putresult eq 'ok') {
10837: my $cachetime = 1800;
10838: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
10839: if (ref($lastactref) eq 'HASH') {
10840: $lastactref->{'ipaccess'} = 1;
10841: }
10842: $resulttext = &mt('Changes made:').'<ul>';
10843: my %bynum;
10844: foreach my $itemid (sort(keys(%changes))) {
10845: if (ref($confhash{$itemid}) eq 'HASH') {
10846: my $position = $confhash{$itemid}{'order'};
10847: if ($position =~ /^\d+$/) {
10848: $bynum{$position} = $itemid;
10849: }
10850: }
10851: }
10852: if (keys(%deletions)) {
10853: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
10854: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10855: }
10856: }
10857: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10858: my $itemid = $bynum{$pos};
10859: if (ref($confhash{$itemid}) eq 'HASH') {
10860: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
10861: my $position = $pos + 1;
10862: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10863: if ($confhash{$itemid}{'ip'} eq '') {
10864: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
10865: } else {
10866: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
10867: }
10868: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
10869: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
10870: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
10871: '</li>';
10872: } else {
10873: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
10874: }
10875: if (keys(%{$confhash{$itemid}{'courses'}})) {
10876: my @courses;
10877: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
10878: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
10879: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
10880: }
10881: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
10882: join('</li><li>',@courses).'</li></ul>';
10883: } else {
10884: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
10885: }
10886: $resulttext .= '</ul></li>';
10887: }
10888: }
10889: $resulttext .= '</ul>';
10890: } else {
10891: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10892: }
10893: } else {
10894: $resulttext = &mt('No changes made');
10895: }
10896: if ($errors) {
10897: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
10898: $errors.'</ul></p>';
10899: }
10900: return $resulttext;
10901: }
10902:
10903: sub get_ipaccess_id {
10904: my ($domain,$location) = @_;
10905: # get lock on ipaccess db
10906: my $lockhash = {
10907: lock => $env{'user.name'}.
10908: ':'.$env{'user.domain'},
10909: };
10910: my $tries = 0;
10911: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10912: my ($id,$error);
10913:
10914: while (($gotlock ne 'ok') && ($tries<10)) {
10915: $tries ++;
10916: sleep (0.1);
10917: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10918: }
10919: if ($gotlock eq 'ok') {
10920: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
10921: if ($currids{'lock'}) {
10922: delete($currids{'lock'});
10923: if (keys(%currids)) {
10924: my @curr = sort { $a <=> $b } keys(%currids);
10925: if ($curr[-1] =~ /^\d+$/) {
10926: $id = 1 + $curr[-1];
10927: }
10928: } else {
10929: $id = 1;
10930: }
10931: if ($id) {
10932: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10933: $error = 'nostore';
10934: }
10935: } else {
10936: $error = 'nonumber';
10937: }
10938: }
10939: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10940: } else {
10941: $error = 'nolock';
10942: }
10943: return ($id,$error);
10944: }
10945:
10946: sub modify_rolecolors {
10947: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
10948: my ($resulttext,%rolehash);
10949: $rolehash{'rolecolors'} = {};
10950: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10951: if ($domconfig{'rolecolors'} eq '') {
10952: $domconfig{'rolecolors'} = {};
10953: }
10954: }
10955: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
10956: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10957: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10958: $dom);
10959: if ($putresult eq 'ok') {
10960: if (keys(%changes) > 0) {
10961: &Apache::loncommon::devalidate_domconfig_cache($dom);
10962: if (ref($lastactref) eq 'HASH') {
10963: $lastactref->{'domainconfig'} = 1;
10964: }
10965: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10966: $rolehash{'rolecolors'});
10967: } else {
10968: $resulttext = &mt('No changes made to default color schemes');
10969: }
10970: } else {
10971: $resulttext = '<span class="LC_error">'.
10972: &mt('An error occurred: [_1]',$putresult).'</span>';
10973: }
10974: if ($errors) {
10975: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10976: $errors.'</ul>';
10977: }
10978: return $resulttext;
10979: }
10980:
10981: sub modify_colors {
10982: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
10983: my (%changes,%choices);
10984: my @bgs;
10985: my @links = ('link','alink','vlink');
10986: my @logintext;
10987: my @images;
10988: my $servadm = $r->dir_config('lonAdmEMail');
10989: my $errors;
10990: my %defaults;
10991: foreach my $role (@{$roles}) {
10992: if ($role eq 'login') {
10993: %choices = &login_choices();
10994: @logintext = ('textcol','bgcol');
10995: } else {
10996: %choices = &color_font_choices();
10997: }
10998: if ($role eq 'login') {
10999: @images = ('img','logo','domlogo','login');
11000: @bgs = ('pgbg','mainbg','sidebg');
11001: } else {
11002: @images = ('img');
11003: @bgs = ('pgbg','tabbg','sidebg');
11004: }
11005: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11006: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11007: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11008: }
11009: if ($role eq 'login') {
11010: foreach my $item (@logintext) {
11011: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11012: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11013: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11014: }
11015: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
11016: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11017: }
11018: }
11019: } else {
11020: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11021: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11022: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11023: }
11024: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
11025: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11026: }
11027: }
11028: foreach my $item (@bgs) {
11029: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11030: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11031: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11032: }
11033: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
11034: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11035: }
11036: }
11037: foreach my $item (@links) {
11038: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11039: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11040: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11041: }
11042: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
11043: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11044: }
11045: }
11046: my ($configuserok,$author_ok,$switchserver) =
11047: &config_check($dom,$confname,$servadm);
11048: my ($width,$height) = &thumb_dimensions();
11049: if (ref($domconfig->{$role}) ne 'HASH') {
11050: $domconfig->{$role} = {};
11051: }
11052: foreach my $img (@images) {
11053: if ($role eq 'login') {
11054: if (($img eq 'img') || ($img eq 'logo')) {
11055: if (defined($env{'form.login_showlogo_'.$img})) {
11056: $confhash->{$role}{'showlogo'}{$img} = 1;
11057: } else {
11058: $confhash->{$role}{'showlogo'}{$img} = 0;
11059: }
11060: }
11061: if ($env{'form.login_alt_'.$img} ne '') {
11062: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
11063: }
11064: }
11065: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11066: && !defined($domconfig->{$role}{$img})
11067: && !$env{'form.'.$role.'_del_'.$img}
11068: && $env{'form.'.$role.'_import_'.$img}) {
11069: # import the old configured image from the .tab setting
11070: # if they haven't provided a new one
11071: $domconfig->{$role}{$img} =
11072: $env{'form.'.$role.'_import_'.$img};
11073: }
11074: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
11075: my $error;
11076: if ($configuserok eq 'ok') {
11077: if ($switchserver) {
11078: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
11079: } else {
11080: if ($author_ok eq 'ok') {
11081: my ($result,$logourl) =
11082: &publishlogo($r,'upload',$role.'_'.$img,
11083: $dom,$confname,$img,$width,$height);
11084: if ($result eq 'ok') {
11085: $confhash->{$role}{$img} = $logourl;
11086: $changes{$role}{'images'}{$img} = 1;
11087: } else {
11088: $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);
11089: }
11090: } else {
11091: $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);
11092: }
11093: }
11094: } else {
11095: $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);
11096: }
11097: if ($error) {
11098: &Apache::lonnet::logthis($error);
11099: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11100: }
11101: } elsif ($domconfig->{$role}{$img} ne '') {
11102: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11103: my $error;
11104: if ($configuserok eq 'ok') {
11105: # is confname an author?
11106: if ($switchserver eq '') {
11107: if ($author_ok eq 'ok') {
11108: my ($result,$logourl) =
11109: &publishlogo($r,'copy',$domconfig->{$role}{$img},
11110: $dom,$confname,$img,$width,$height);
11111: if ($result eq 'ok') {
11112: $confhash->{$role}{$img} = $logourl;
11113: $changes{$role}{'images'}{$img} = 1;
11114: }
11115: }
11116: }
11117: }
11118: }
11119: }
11120: }
11121: if (ref($domconfig) eq 'HASH') {
11122: if (ref($domconfig->{$role}) eq 'HASH') {
11123: foreach my $img (@images) {
11124: if ($domconfig->{$role}{$img} ne '') {
11125: if ($env{'form.'.$role.'_del_'.$img}) {
11126: $confhash->{$role}{$img} = '';
11127: $changes{$role}{'images'}{$img} = 1;
11128: } else {
11129: if ($confhash->{$role}{$img} eq '') {
11130: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11131: }
11132: }
11133: } else {
11134: if ($env{'form.'.$role.'_del_'.$img}) {
11135: $confhash->{$role}{$img} = '';
11136: $changes{$role}{'images'}{$img} = 1;
11137: }
11138: }
11139: if ($role eq 'login') {
11140: if (($img eq 'logo') || ($img eq 'img')) {
11141: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11142: if ($confhash->{$role}{'showlogo'}{$img} ne
11143: $domconfig->{$role}{'showlogo'}{$img}) {
11144: $changes{$role}{'showlogo'}{$img} = 1;
11145: }
11146: } else {
11147: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11148: $changes{$role}{'showlogo'}{$img} = 1;
11149: }
11150: }
11151: }
11152: if ($img ne 'login') {
11153: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
11154: if ($confhash->{$role}{'alttext'}{$img} ne
11155: $domconfig->{$role}{'alttext'}{$img}) {
11156: $changes{$role}{'alttext'}{$img} = 1;
11157: }
11158: } else {
11159: if ($confhash->{$role}{'alttext'}{$img} ne '') {
11160: $changes{$role}{'alttext'}{$img} = 1;
11161: }
11162: }
11163: }
11164: }
11165: }
11166: if ($domconfig->{$role}{'font'} ne '') {
11167: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11168: $changes{$role}{'font'} = 1;
11169: }
11170: } else {
11171: if ($confhash->{$role}{'font'}) {
11172: $changes{$role}{'font'} = 1;
11173: }
11174: }
11175: if ($role ne 'login') {
11176: if ($domconfig->{$role}{'fontmenu'} ne '') {
11177: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11178: $changes{$role}{'fontmenu'} = 1;
11179: }
11180: } else {
11181: if ($confhash->{$role}{'fontmenu'}) {
11182: $changes{$role}{'fontmenu'} = 1;
11183: }
11184: }
11185: }
11186: foreach my $item (@bgs) {
11187: if ($domconfig->{$role}{$item} ne '') {
11188: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11189: $changes{$role}{'bgs'}{$item} = 1;
11190: }
11191: } else {
11192: if ($confhash->{$role}{$item}) {
11193: $changes{$role}{'bgs'}{$item} = 1;
11194: }
11195: }
11196: }
11197: foreach my $item (@links) {
11198: if ($domconfig->{$role}{$item} ne '') {
11199: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11200: $changes{$role}{'links'}{$item} = 1;
11201: }
11202: } else {
11203: if ($confhash->{$role}{$item}) {
11204: $changes{$role}{'links'}{$item} = 1;
11205: }
11206: }
11207: }
11208: foreach my $item (@logintext) {
11209: if ($domconfig->{$role}{$item} ne '') {
11210: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11211: $changes{$role}{'logintext'}{$item} = 1;
11212: }
11213: } else {
11214: if ($confhash->{$role}{$item}) {
11215: $changes{$role}{'logintext'}{$item} = 1;
11216: }
11217: }
11218: }
11219: } else {
11220: &default_change_checker($role,\@images,\@links,\@bgs,
11221: \@logintext,$confhash,\%changes);
11222: }
11223: } else {
11224: &default_change_checker($role,\@images,\@links,\@bgs,
11225: \@logintext,$confhash,\%changes);
11226: }
11227: }
11228: return ($errors,%changes);
11229: }
11230:
11231: sub config_check {
11232: my ($dom,$confname,$servadm) = @_;
11233: my ($configuserok,$author_ok,$switchserver,%currroles);
11234: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11235: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11236: $confname,$servadm);
11237: if ($configuserok eq 'ok') {
11238: $switchserver = &check_switchserver($dom,$confname);
11239: if ($switchserver eq '') {
11240: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11241: }
11242: }
11243: return ($configuserok,$author_ok,$switchserver);
11244: }
11245:
11246: sub default_change_checker {
11247: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
11248: foreach my $item (@{$links}) {
11249: if ($confhash->{$role}{$item}) {
11250: $changes->{$role}{'links'}{$item} = 1;
11251: }
11252: }
11253: foreach my $item (@{$bgs}) {
11254: if ($confhash->{$role}{$item}) {
11255: $changes->{$role}{'bgs'}{$item} = 1;
11256: }
11257: }
11258: foreach my $item (@{$logintext}) {
11259: if ($confhash->{$role}{$item}) {
11260: $changes->{$role}{'logintext'}{$item} = 1;
11261: }
11262: }
11263: foreach my $img (@{$images}) {
11264: if ($env{'form.'.$role.'_del_'.$img}) {
11265: $confhash->{$role}{$img} = '';
11266: $changes->{$role}{'images'}{$img} = 1;
11267: }
11268: if ($role eq 'login') {
11269: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11270: $changes->{$role}{'showlogo'}{$img} = 1;
11271: }
11272: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
11273: if ($confhash->{$role}{'alttext'}{$img} ne '') {
11274: $changes->{$role}{'alttext'}{$img} = 1;
11275: }
11276: }
11277: }
11278: }
11279: if ($confhash->{$role}{'font'}) {
11280: $changes->{$role}{'font'} = 1;
11281: }
11282: }
11283:
11284: sub display_colorchgs {
11285: my ($dom,$changes,$roles,$confhash) = @_;
11286: my (%choices,$resulttext);
11287: if (!grep(/^login$/,@{$roles})) {
11288: $resulttext = &mt('Changes made:').'<br />';
11289: }
11290: foreach my $role (@{$roles}) {
11291: if ($role eq 'login') {
11292: %choices = &login_choices();
11293: } else {
11294: %choices = &color_font_choices();
11295: }
11296: if (ref($changes->{$role}) eq 'HASH') {
11297: if ($role ne 'login') {
11298: $resulttext .= '<h4>'.&mt($role).'</h4>';
11299: }
11300: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11301: if ($role ne 'login') {
11302: $resulttext .= '<ul>';
11303: }
11304: if (ref($changes->{$role}{$key}) eq 'HASH') {
11305: if ($role ne 'login') {
11306: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
11307: }
11308: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
11309: if (($role eq 'login') && ($key eq 'showlogo')) {
11310: if ($confhash->{$role}{$key}{$item}) {
11311: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
11312: } else {
11313: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
11314: }
11315: } elsif (($role eq 'login') && ($key eq 'alttext')) {
11316: if ($confhash->{$role}{$key}{$item} ne '') {
11317: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
11318: $confhash->{$role}{$key}{$item}).'</li>';
11319: } else {
11320: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
11321: }
11322: } elsif ($confhash->{$role}{$item} eq '') {
11323: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
11324: } else {
11325: my $newitem = $confhash->{$role}{$item};
11326: if ($key eq 'images') {
11327: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
11328: }
11329: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
11330: }
11331: }
11332: if ($role ne 'login') {
11333: $resulttext .= '</ul></li>';
11334: }
11335: } else {
11336: if ($confhash->{$role}{$key} eq '') {
11337: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
11338: } else {
11339: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
11340: }
11341: }
11342: if ($role ne 'login') {
11343: $resulttext .= '</ul>';
11344: }
11345: }
11346: }
11347: }
11348: return $resulttext;
11349: }
11350:
11351: sub thumb_dimensions {
11352: return ('200','50');
11353: }
11354:
11355: sub check_dimensions {
11356: my ($inputfile) = @_;
11357: my ($fullwidth,$fullheight);
11358: if ($inputfile =~ m|^[/\w.\-]+$|) {
11359: if (open(PIPE,"identify $inputfile 2>&1 |")) {
11360: my $imageinfo = <PIPE>;
11361: if (!close(PIPE)) {
11362: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
11363: }
11364: chomp($imageinfo);
11365: my ($fullsize) =
11366: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
11367: if ($fullsize) {
11368: ($fullwidth,$fullheight) = split(/x/,$fullsize);
11369: }
11370: }
11371: }
11372: return ($fullwidth,$fullheight);
11373: }
11374:
11375: sub check_configuser {
11376: my ($uhome,$dom,$confname,$servadm) = @_;
11377: my ($configuserok,%currroles);
11378: if ($uhome eq 'no_host') {
11379: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
11380: my $configpass = &LONCAPA::Enrollment::create_password($dom);
11381: $configuserok =
11382: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
11383: $configpass,'','','','','',undef,$servadm);
11384: } else {
11385: $configuserok = 'ok';
11386: %currroles =
11387: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
11388: }
11389: return ($configuserok,%currroles);
11390: }
11391:
11392: sub check_authorstatus {
11393: my ($dom,$confname,%currroles) = @_;
11394: my $author_ok;
11395: if (!$currroles{':'.$dom.':au'}) {
11396: my $start = time;
11397: my $end = 0;
11398: $author_ok =
11399: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
11400: 'au',$end,$start,'','','domconfig');
11401: } else {
11402: $author_ok = 'ok';
11403: }
11404: return $author_ok;
11405: }
11406:
11407: sub publishlogo {
11408: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
11409: my ($output,$fname,$logourl);
11410: if ($action eq 'upload') {
11411: $fname=$env{'form.'.$formname.'.filename'};
11412: chop($env{'form.'.$formname});
11413: } else {
11414: ($fname) = ($formname =~ /([^\/]+)$/);
11415: }
11416: if ($savefileas ne '') {
11417: $fname = $savefileas;
11418: }
11419: $fname=&Apache::lonnet::clean_filename($fname);
11420: # See if there is anything left
11421: unless ($fname) { return ('error: no uploaded file'); }
11422: $fname="$subdir/$fname";
11423: my $docroot=$r->dir_config('lonDocRoot');
11424: my $filepath="$docroot/priv";
11425: my $relpath = "$dom/$confname";
11426: my ($fnamepath,$file,$fetchthumb);
11427: $file=$fname;
11428: if ($fname=~m|/|) {
11429: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11430: }
11431: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
11432: my $count;
11433: for ($count=5;$count<=$#parts;$count++) {
11434: $filepath.="/$parts[$count]";
11435: if ((-e $filepath)!=1) {
11436: mkdir($filepath,02770);
11437: }
11438: }
11439: # Check for bad extension and disallow upload
11440: if ($file=~/\.(\w+)$/ &&
11441: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11442: $output =
11443: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
11444: } elsif ($file=~/\.(\w+)$/ &&
11445: !defined(&Apache::loncommon::fileembstyle($1))) {
11446: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11447: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
11448: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
11449: } elsif (-d "$filepath/$file") {
11450: $output = &mt('Filename is a directory name - rename the file and re-upload');
11451: } else {
11452: my $source = $filepath.'/'.$file;
11453: my $logfile;
11454: if (!open($logfile,">>",$source.'.log')) {
11455: return (&mt('No write permission to Authoring Space'));
11456: }
11457: print $logfile
11458: "\n================= Publish ".localtime()." ================\n".
11459: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11460: # Save the file
11461: if (!open(FH,">",$source)) {
11462: &Apache::lonnet::logthis('Failed to create '.$source);
11463: return (&mt('Failed to create file'));
11464: }
11465: if ($action eq 'upload') {
11466: if (!print FH ($env{'form.'.$formname})) {
11467: &Apache::lonnet::logthis('Failed to write to '.$source);
11468: return (&mt('Failed to write file'));
11469: }
11470: } else {
11471: my $original = &Apache::lonnet::filelocation('',$formname);
11472: if(!copy($original,$source)) {
11473: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11474: return (&mt('Failed to write file'));
11475: }
11476: }
11477: close(FH);
11478: chmod(0660, $source); # Permissions to rw-rw---.
11479:
11480: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11481: my $copyfile=$targetdir.'/'.$file;
11482:
11483: my @parts=split(/\//,$targetdir);
11484: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11485: for (my $count=5;$count<=$#parts;$count++) {
11486: $path.="/$parts[$count]";
11487: if (!-e $path) {
11488: print $logfile "\nCreating directory ".$path;
11489: mkdir($path,02770);
11490: }
11491: }
11492: my $versionresult;
11493: if (-e $copyfile) {
11494: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11495: } else {
11496: $versionresult = 'ok';
11497: }
11498: if ($versionresult eq 'ok') {
11499: if (copy($source,$copyfile)) {
11500: print $logfile "\nCopied original source to ".$copyfile."\n";
11501: $output = 'ok';
11502: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
11503: push(@{$modified_urls},[$copyfile,$source]);
11504: my $metaoutput =
11505: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11506: unless ($registered_cleanup) {
11507: my $handlers = $r->get_handlers('PerlCleanupHandler');
11508: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11509: $registered_cleanup=1;
11510: }
11511: } else {
11512: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11513: $output = &mt('Failed to copy file to RES space').", $!";
11514: }
11515: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11516: my $inputfile = $filepath.'/'.$file;
11517: my $outfile = $filepath.'/'.'tn-'.$file;
11518: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11519: if ($fullwidth ne '' && $fullheight ne '') {
11520: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11521: my $thumbsize = $thumbwidth.'x'.$thumbheight;
11522: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11523: system({$args[0]} @args);
11524: chmod(0660, $filepath.'/tn-'.$file);
11525: if (-e $outfile) {
11526: my $copyfile=$targetdir.'/tn-'.$file;
11527: if (copy($outfile,$copyfile)) {
11528: print $logfile "\nCopied source to ".$copyfile."\n";
11529: my $thumb_metaoutput =
11530: &write_metadata($dom,$confname,$formname,
11531: $targetdir,'tn-'.$file,$logfile);
11532: push(@{$modified_urls},[$copyfile,$outfile]);
11533: unless ($registered_cleanup) {
11534: my $handlers = $r->get_handlers('PerlCleanupHandler');
11535: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11536: $registered_cleanup=1;
11537: }
11538: } else {
11539: print $logfile "\nUnable to write ".$copyfile.
11540: ':'.$!."\n";
11541: }
11542: }
11543: }
11544: }
11545: }
11546: } else {
11547: $output = $versionresult;
11548: }
11549: }
11550: return ($output,$logourl);
11551: }
11552:
11553: sub logo_versioning {
11554: my ($targetdir,$file,$logfile) = @_;
11555: my $target = $targetdir.'/'.$file;
11556: my ($maxversion,$fn,$extn,$output);
11557: $maxversion = 0;
11558: if ($file =~ /^(.+)\.(\w+)$/) {
11559: $fn=$1;
11560: $extn=$2;
11561: }
11562: opendir(DIR,$targetdir);
11563: while (my $filename=readdir(DIR)) {
11564: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11565: $maxversion=($1>$maxversion)?$1:$maxversion;
11566: }
11567: }
11568: $maxversion++;
11569: print $logfile "\nCreating old version ".$maxversion."\n";
11570: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
11571: if (copy($target,$copyfile)) {
11572: print $logfile "Copied old target to ".$copyfile."\n";
11573: $copyfile=$copyfile.'.meta';
11574: if (copy($target.'.meta',$copyfile)) {
11575: print $logfile "Copied old target metadata to ".$copyfile."\n";
11576: $output = 'ok';
11577: } else {
11578: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
11579: $output = &mt('Failed to copy old meta').", $!, ";
11580: }
11581: } else {
11582: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
11583: $output = &mt('Failed to copy old target').", $!, ";
11584: }
11585: return $output;
11586: }
11587:
11588: sub write_metadata {
11589: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
11590: my (%metadatafields,%metadatakeys,$output);
11591: $metadatafields{'title'}=$formname;
11592: $metadatafields{'creationdate'}=time;
11593: $metadatafields{'lastrevisiondate'}=time;
11594: $metadatafields{'copyright'}='public';
11595: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
11596: $env{'user.domain'};
11597: $metadatafields{'authorspace'}=$confname.':'.$dom;
11598: $metadatafields{'domain'}=$dom;
11599: {
11600: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11601: my $mfh;
11602: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
11603: foreach (sort(keys(%metadatafields))) {
11604: unless ($_=~/\./) {
11605: my $unikey=$_;
11606: $unikey=~/^([A-Za-z]+)/;
11607: my $tag=$1;
11608: $tag=~tr/A-Z/a-z/;
11609: print $mfh "\n\<$tag";
11610: foreach (split(/\,/,$metadatakeys{$unikey})) {
11611: my $value=$metadatafields{$unikey.'.'.$_};
11612: $value=~s/\"/\'\'/g;
11613: print $mfh ' '.$_.'="'.$value.'"';
11614: }
11615: print $mfh '>'.
11616: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11617: .'</'.$tag.'>';
11618: }
11619: }
11620: $output = 'ok';
11621: print $logfile "\nWrote metadata";
11622: close($mfh);
11623: } else {
11624: print $logfile "\nFailed to open metadata file";
11625: $output = &mt('Could not write metadata');
11626: }
11627: }
11628: return $output;
11629: }
11630:
11631: sub notifysubscribed {
11632: foreach my $targetsource (@{$modified_urls}){
11633: next unless (ref($targetsource) eq 'ARRAY');
11634: my ($target,$source)=@{$targetsource};
11635: if ($source ne '') {
11636: if (open(my $logfh,">>",$source.'.log')) {
11637: print $logfh "\nCleanup phase: Notifications\n";
11638: my @subscribed=&subscribed_hosts($target);
11639: foreach my $subhost (@subscribed) {
11640: print $logfh "\nNotifying host ".$subhost.':';
11641: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11642: print $logfh $reply;
11643: }
11644: my @subscribedmeta=&subscribed_hosts("$target.meta");
11645: foreach my $subhost (@subscribedmeta) {
11646: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11647: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11648: $subhost);
11649: print $logfh $reply;
11650: }
11651: print $logfh "\n============ Done ============\n";
11652: close($logfh);
11653: }
11654: }
11655: }
11656: return OK;
11657: }
11658:
11659: sub subscribed_hosts {
11660: my ($target) = @_;
11661: my @subscribed;
11662: if (open(my $fh,"<","$target.subscription")) {
11663: while (my $subline=<$fh>) {
11664: if ($subline =~ /^($match_lonid):/) {
11665: my $host = $1;
11666: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11667: unless (grep(/^\Q$host\E$/,@subscribed)) {
11668: push(@subscribed,$host);
11669: }
11670: }
11671: }
11672: }
11673: }
11674: return @subscribed;
11675: }
11676:
11677: sub check_switchserver {
11678: my ($dom,$confname) = @_;
11679: my ($allowed,$switchserver);
11680: my $home = &Apache::lonnet::homeserver($confname,$dom);
11681: if ($home eq 'no_host') {
11682: $home = &Apache::lonnet::domain($dom,'primary');
11683: }
11684: my @ids=&Apache::lonnet::current_machine_ids();
11685: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11686: if (!$allowed) {
11687: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
11688: }
11689: return $switchserver;
11690: }
11691:
11692: sub modify_quotas {
11693: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11694: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
11695: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
11696: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11697: $validationfieldsref);
11698: if ($action eq 'quotas') {
11699: $context = 'tools';
11700: } else {
11701: $context = $action;
11702: }
11703: if ($context eq 'requestcourses') {
11704: @usertools = ('official','unofficial','community','textbook');
11705: @options =('norequest','approval','validate','autolimit');
11706: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11707: %titles = &courserequest_titles();
11708: $toolregexp = join('|',@usertools);
11709: %conditions = &courserequest_conditions();
11710: $confname = $dom.'-domainconfig';
11711: my $servadm = $r->dir_config('lonAdmEMail');
11712: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11713: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11714: &Apache::loncoursequeueadmin::requestcourses_validation_types();
11715: } elsif ($context eq 'requestauthor') {
11716: @usertools = ('author');
11717: %titles = &authorrequest_titles();
11718: } else {
11719: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
11720: %titles = &tool_titles();
11721: }
11722: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11723: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11724: foreach my $key (keys(%env)) {
11725: if ($context eq 'requestcourses') {
11726: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11727: my $item = $1;
11728: my $type = $2;
11729: if ($type =~ /^limit_(.+)/) {
11730: $limithash{$item}{$1} = $env{$key};
11731: } else {
11732: $confhash{$item}{$type} = $env{$key};
11733: }
11734: }
11735: } elsif ($context eq 'requestauthor') {
11736: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11737: $confhash{$1} = $env{$key};
11738: }
11739: } else {
11740: if ($key =~ /^form\.quota_(.+)$/) {
11741: $confhash{'defaultquota'}{$1} = $env{$key};
11742: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11743: $confhash{'authorquota'}{$1} = $env{$key};
11744: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
11745: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11746: }
11747: }
11748: }
11749: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
11750: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
11751: @approvalnotify = sort(@approvalnotify);
11752: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
11753: my @crstypes = ('official','unofficial','community','textbook');
11754: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11755: foreach my $type (@hasuniquecode) {
11756: if (grep(/^\Q$type\E$/,@crstypes)) {
11757: $confhash{'uniquecode'}{$type} = 1;
11758: }
11759: }
11760: my (%newbook,%allpos);
11761: if ($context eq 'requestcourses') {
11762: foreach my $type ('textbooks','templates') {
11763: @{$allpos{$type}} = ();
11764: my $invalid;
11765: if ($type eq 'textbooks') {
11766: $invalid = &mt('Invalid LON-CAPA course for textbook');
11767: } else {
11768: $invalid = &mt('Invalid LON-CAPA course for template');
11769: }
11770: if ($env{'form.'.$type.'_addbook'}) {
11771: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11772: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11773: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11774: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11775: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11776: } else {
11777: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11778: my $position = $env{'form.'.$type.'_addbook_pos'};
11779: $position =~ s/\D+//g;
11780: if ($position ne '') {
11781: $allpos{$type}[$position] = $newbook{$type};
11782: }
11783: }
11784: } else {
11785: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11786: }
11787: }
11788: }
11789: }
11790: if (ref($domconfig{$action}) eq 'HASH') {
11791: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11792: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11793: $changes{'notify'}{'approval'} = 1;
11794: }
11795: } else {
11796: if ($confhash{'notify'}{'approval'}) {
11797: $changes{'notify'}{'approval'} = 1;
11798: }
11799: }
11800: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11801: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11802: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11803: unless ($confhash{'uniquecode'}{$crstype}) {
11804: $changes{'uniquecode'} = 1;
11805: }
11806: }
11807: unless ($changes{'uniquecode'}) {
11808: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11809: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11810: $changes{'uniquecode'} = 1;
11811: }
11812: }
11813: }
11814: } else {
11815: $changes{'uniquecode'} = 1;
11816: }
11817: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11818: $changes{'uniquecode'} = 1;
11819: }
11820: if ($context eq 'requestcourses') {
11821: foreach my $type ('textbooks','templates') {
11822: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11823: my %deletions;
11824: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11825: if (@todelete) {
11826: map { $deletions{$_} = 1; } @todelete;
11827: }
11828: my %imgdeletions;
11829: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11830: if (@todeleteimages) {
11831: map { $imgdeletions{$_} = 1; } @todeleteimages;
11832: }
11833: my $maxnum = $env{'form.'.$type.'_maxnum'};
11834: for (my $i=0; $i<=$maxnum; $i++) {
11835: my $itemid = $env{'form.'.$type.'_id_'.$i};
11836: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11837: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11838: if ($deletions{$key}) {
11839: if ($domconfig{$action}{$type}{$key}{'image'}) {
11840: #FIXME need to obsolete item in RES space
11841: }
11842: next;
11843: } else {
11844: my $newpos = $env{'form.'.$itemid};
11845: $newpos =~ s/\D+//g;
11846: foreach my $item ('subject','title','publisher','author') {
11847: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11848: ($type eq 'templates'));
11849: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11850: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11851: $changes{$type}{$key} = 1;
11852: }
11853: }
11854: $allpos{$type}[$newpos] = $key;
11855: }
11856: if ($imgdeletions{$key}) {
11857: $changes{$type}{$key} = 1;
11858: #FIXME need to obsolete item in RES space
11859: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11860: my ($cdom,$cnum) = split(/_/,$key);
11861: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11862: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11863: } else {
11864: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11865: $cdom,$cnum,$type,$configuserok,
11866: $switchserver,$author_ok);
11867: if ($imgurl) {
11868: $confhash{$type}{$key}{'image'} = $imgurl;
11869: $changes{$type}{$key} = 1;
11870: }
11871: if ($error) {
11872: &Apache::lonnet::logthis($error);
11873: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11874: }
11875: }
11876: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11877: $confhash{$type}{$key}{'image'} =
11878: $domconfig{$action}{$type}{$key}{'image'};
11879: }
11880: }
11881: }
11882: }
11883: }
11884: }
11885: } else {
11886: if ($confhash{'notify'}{'approval'}) {
11887: $changes{'notify'}{'approval'} = 1;
11888: }
11889: if (ref($confhash{'uniquecode'} eq 'HASH')) {
11890: $changes{'uniquecode'} = 1;
11891: }
11892: }
11893: if ($context eq 'requestcourses') {
11894: foreach my $type ('textbooks','templates') {
11895: if ($newbook{$type}) {
11896: $changes{$type}{$newbook{$type}} = 1;
11897: foreach my $item ('subject','title','publisher','author') {
11898: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11899: ($type eq 'template'));
11900: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11901: if ($env{'form.'.$type.'_addbook_'.$item}) {
11902: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11903: }
11904: }
11905: if ($type eq 'textbooks') {
11906: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11907: my ($cdom,$cnum) = split(/_/,$newbook{$type});
11908: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11909: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11910: } else {
11911: my ($imageurl,$error) =
11912: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11913: $configuserok,$switchserver,$author_ok);
11914: if ($imageurl) {
11915: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11916: }
11917: if ($error) {
11918: &Apache::lonnet::logthis($error);
11919: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11920: }
11921: }
11922: }
11923: }
11924: }
11925: if (@{$allpos{$type}} > 0) {
11926: my $idx = 0;
11927: foreach my $item (@{$allpos{$type}}) {
11928: if ($item ne '') {
11929: $confhash{$type}{$item}{'order'} = $idx;
11930: if (ref($domconfig{$action}) eq 'HASH') {
11931: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11932: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11933: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11934: $changes{$type}{$item} = 1;
11935: }
11936: }
11937: }
11938: }
11939: $idx ++;
11940: }
11941: }
11942: }
11943: }
11944: if (ref($validationitemsref) eq 'ARRAY') {
11945: foreach my $item (@{$validationitemsref}) {
11946: if ($item eq 'fields') {
11947: my @changed;
11948: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11949: if (@{$confhash{'validation'}{$item}} > 0) {
11950: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11951: }
11952: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11953: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11954: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11955: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11956: $domconfig{'requestcourses'}{'validation'}{$item});
11957: } else {
11958: @changed = @{$confhash{'validation'}{$item}};
11959: }
11960: } else {
11961: @changed = @{$confhash{'validation'}{$item}};
11962: }
11963: } else {
11964: @changed = @{$confhash{'validation'}{$item}};
11965: }
11966: if (@changed) {
11967: if ($confhash{'validation'}{$item}) {
11968: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11969: } else {
11970: $changes{'validation'}{$item} = &mt('None');
11971: }
11972: }
11973: } else {
11974: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11975: if ($item eq 'markup') {
11976: if ($env{'form.requestcourses_validation_'.$item}) {
11977: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11978: }
11979: }
11980: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11981: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11982: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11983: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11984: }
11985: } else {
11986: if ($confhash{'validation'}{$item} ne '') {
11987: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11988: }
11989: }
11990: } else {
11991: if ($confhash{'validation'}{$item} ne '') {
11992: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11993: }
11994: }
11995: }
11996: }
11997: }
11998: if ($env{'form.validationdc'}) {
11999: my $newval = $env{'form.validationdc'};
12000: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
12001: if (exists($domcoords{$newval})) {
12002: $confhash{'validation'}{'dc'} = $newval;
12003: }
12004: }
12005: if (ref($confhash{'validation'}) eq 'HASH') {
12006: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12007: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12008: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12009: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12010: if ($confhash{'validation'}{'dc'} eq '') {
12011: $changes{'validation'}{'dc'} = &mt('None');
12012: } else {
12013: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12014: }
12015: }
12016: } elsif ($confhash{'validation'}{'dc'} ne '') {
12017: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12018: }
12019: } elsif ($confhash{'validation'}{'dc'} ne '') {
12020: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12021: }
12022: } elsif ($confhash{'validation'}{'dc'} ne '') {
12023: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12024: }
12025: } else {
12026: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12027: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12028: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12029: $changes{'validation'}{'dc'} = &mt('None');
12030: }
12031: }
12032: }
12033: }
12034: }
12035: } else {
12036: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
12037: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
12038: }
12039: foreach my $item (@usertools) {
12040: foreach my $type (@{$types},'default','_LC_adv') {
12041: my $unset;
12042: if ($context eq 'requestcourses') {
12043: $unset = '0';
12044: if ($type eq '_LC_adv') {
12045: $unset = '';
12046: }
12047: if ($confhash{$item}{$type} eq 'autolimit') {
12048: $confhash{$item}{$type} .= '=';
12049: unless ($limithash{$item}{$type} =~ /\D/) {
12050: $confhash{$item}{$type} .= $limithash{$item}{$type};
12051: }
12052: }
12053: } elsif ($context eq 'requestauthor') {
12054: $unset = '0';
12055: if ($type eq '_LC_adv') {
12056: $unset = '';
12057: }
12058: } else {
12059: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12060: $confhash{$item}{$type} = 1;
12061: } else {
12062: $confhash{$item}{$type} = 0;
12063: }
12064: }
12065: if (ref($domconfig{$action}) eq 'HASH') {
12066: if ($action eq 'requestauthor') {
12067: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12068: $changes{$type} = 1;
12069: }
12070: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
12071: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12072: $changes{$item}{$type} = 1;
12073: }
12074: } else {
12075: if ($context eq 'requestcourses') {
12076: if ($confhash{$item}{$type} ne $unset) {
12077: $changes{$item}{$type} = 1;
12078: }
12079: } else {
12080: if (!$confhash{$item}{$type}) {
12081: $changes{$item}{$type} = 1;
12082: }
12083: }
12084: }
12085: } else {
12086: if ($context eq 'requestcourses') {
12087: if ($confhash{$item}{$type} ne $unset) {
12088: $changes{$item}{$type} = 1;
12089: }
12090: } elsif ($context eq 'requestauthor') {
12091: if ($confhash{$type} ne $unset) {
12092: $changes{$type} = 1;
12093: }
12094: } else {
12095: if (!$confhash{$item}{$type}) {
12096: $changes{$item}{$type} = 1;
12097: }
12098: }
12099: }
12100: }
12101: }
12102: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
12103: if (ref($domconfig{'quotas'}) eq 'HASH') {
12104: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12105: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12106: if (exists($confhash{'defaultquota'}{$key})) {
12107: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12108: $changes{'defaultquota'}{$key} = 1;
12109: }
12110: } else {
12111: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
12112: }
12113: }
12114: } else {
12115: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12116: if (exists($confhash{'defaultquota'}{$key})) {
12117: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12118: $changes{'defaultquota'}{$key} = 1;
12119: }
12120: } else {
12121: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
12122: }
12123: }
12124: }
12125: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12126: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12127: if (exists($confhash{'authorquota'}{$key})) {
12128: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12129: $changes{'authorquota'}{$key} = 1;
12130: }
12131: } else {
12132: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12133: }
12134: }
12135: }
12136: }
12137: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12138: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12139: if (ref($domconfig{'quotas'}) eq 'HASH') {
12140: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12141: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12142: $changes{'defaultquota'}{$key} = 1;
12143: }
12144: } else {
12145: if (!exists($domconfig{'quotas'}{$key})) {
12146: $changes{'defaultquota'}{$key} = 1;
12147: }
12148: }
12149: } else {
12150: $changes{'defaultquota'}{$key} = 1;
12151: }
12152: }
12153: }
12154: if (ref($confhash{'authorquota'}) eq 'HASH') {
12155: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12156: if (ref($domconfig{'quotas'}) eq 'HASH') {
12157: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12158: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12159: $changes{'authorquota'}{$key} = 1;
12160: }
12161: } else {
12162: $changes{'authorquota'}{$key} = 1;
12163: }
12164: } else {
12165: $changes{'authorquota'}{$key} = 1;
12166: }
12167: }
12168: }
12169: }
12170:
12171: if ($context eq 'requestauthor') {
12172: $domdefaults{'requestauthor'} = \%confhash;
12173: } else {
12174: foreach my $key (keys(%confhash)) {
12175: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
12176: $domdefaults{$key} = $confhash{$key};
12177: }
12178: }
12179: }
12180:
12181: my %quotahash = (
12182: $action => { %confhash }
12183: );
12184: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12185: $dom);
12186: if ($putresult eq 'ok') {
12187: if (keys(%changes) > 0) {
12188: my $cachetime = 24*60*60;
12189: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12190: if (ref($lastactref) eq 'HASH') {
12191: $lastactref->{'domdefaults'} = 1;
12192: }
12193: $resulttext = &mt('Changes made:').'<ul>';
12194: unless (($context eq 'requestcourses') ||
12195: ($context eq 'requestauthor')) {
12196: if (ref($changes{'defaultquota'}) eq 'HASH') {
12197: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12198: foreach my $type (@{$types},'default') {
12199: if (defined($changes{'defaultquota'}{$type})) {
12200: my $typetitle = $usertypes->{$type};
12201: if ($type eq 'default') {
12202: $typetitle = $othertitle;
12203: }
12204: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
12205: }
12206: }
12207: $resulttext .= '</ul></li>';
12208: }
12209: if (ref($changes{'authorquota'}) eq 'HASH') {
12210: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
12211: foreach my $type (@{$types},'default') {
12212: if (defined($changes{'authorquota'}{$type})) {
12213: my $typetitle = $usertypes->{$type};
12214: if ($type eq 'default') {
12215: $typetitle = $othertitle;
12216: }
12217: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
12218: }
12219: }
12220: $resulttext .= '</ul></li>';
12221: }
12222: }
12223: my %newenv;
12224: foreach my $item (@usertools) {
12225: my (%haschgs,%inconf);
12226: if ($context eq 'requestauthor') {
12227: %haschgs = %changes;
12228: %inconf = %confhash;
12229: } else {
12230: if (ref($changes{$item}) eq 'HASH') {
12231: %haschgs = %{$changes{$item}};
12232: }
12233: if (ref($confhash{$item}) eq 'HASH') {
12234: %inconf = %{$confhash{$item}};
12235: }
12236: }
12237: if (keys(%haschgs) > 0) {
12238: my $newacc =
12239: &Apache::lonnet::usertools_access($env{'user.name'},
12240: $env{'user.domain'},
12241: $item,'reload',$context);
12242: if (($context eq 'requestcourses') ||
12243: ($context eq 'requestauthor')) {
12244: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12245: $newenv{'environment.canrequest.'.$item} = $newacc;
12246: }
12247: } else {
12248: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12249: $newenv{'environment.availabletools.'.$item} = $newacc;
12250: }
12251: }
12252: unless ($context eq 'requestauthor') {
12253: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12254: }
12255: foreach my $type (@{$types},'default','_LC_adv') {
12256: if ($haschgs{$type}) {
12257: my $typetitle = $usertypes->{$type};
12258: if ($type eq 'default') {
12259: $typetitle = $othertitle;
12260: } elsif ($type eq '_LC_adv') {
12261: $typetitle = 'LON-CAPA Advanced Users';
12262: }
12263: if ($inconf{$type}) {
12264: if ($context eq 'requestcourses') {
12265: my $cond;
12266: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
12267: if ($1 eq '') {
12268: $cond = &mt('(Automatic processing of any request).');
12269: } else {
12270: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12271: }
12272: } else {
12273: $cond = $conditions{$inconf{$type}};
12274: }
12275: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
12276: } elsif ($context eq 'requestauthor') {
12277: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12278: $titles{$inconf{$type}},$typetitle);
12279:
12280: } else {
12281: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12282: }
12283: } else {
12284: if ($type eq '_LC_adv') {
12285: if ($inconf{$type} eq '0') {
12286: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12287: } else {
12288: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12289: }
12290: } else {
12291: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12292: }
12293: }
12294: }
12295: }
12296: unless ($context eq 'requestauthor') {
12297: $resulttext .= '</ul></li>';
12298: }
12299: }
12300: }
12301: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
12302: if (ref($changes{'notify'}) eq 'HASH') {
12303: if ($changes{'notify'}{'approval'}) {
12304: if (ref($confhash{'notify'}) eq 'HASH') {
12305: if ($confhash{'notify'}{'approval'}) {
12306: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12307: } else {
12308: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
12309: }
12310: }
12311: }
12312: }
12313: }
12314: if ($action eq 'requestcourses') {
12315: my @offon = ('off','on');
12316: if ($changes{'uniquecode'}) {
12317: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12318: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12319: $resulttext .= '<li>'.
12320: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12321: '</li>';
12322: } else {
12323: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12324: '</li>';
12325: }
12326: }
12327: foreach my $type ('textbooks','templates') {
12328: if (ref($changes{$type}) eq 'HASH') {
12329: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12330: foreach my $key (sort(keys(%{$changes{$type}}))) {
12331: my %coursehash = &Apache::lonnet::coursedescription($key);
12332: my $coursetitle = $coursehash{'description'};
12333: my $position = $confhash{$type}{$key}{'order'} + 1;
12334: $resulttext .= '<li>';
12335: foreach my $item ('subject','title','publisher','author') {
12336: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12337: ($type eq 'templates'));
12338: my $name = $item.':';
12339: $name =~ s/^(\w)/\U$1/;
12340: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12341: }
12342: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12343: if ($type eq 'textbooks') {
12344: if ($confhash{$type}{$key}{'image'}) {
12345: $resulttext .= ' '.&mt('Image: [_1]',
12346: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12347: ' alt="Textbook cover" />').'<br />';
12348: }
12349: }
12350: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
12351: }
12352: $resulttext .= '</ul></li>';
12353: }
12354: }
12355: if (ref($changes{'validation'}) eq 'HASH') {
12356: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12357: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12358: foreach my $item (@{$validationitemsref}) {
12359: if (exists($changes{'validation'}{$item})) {
12360: if ($item eq 'markup') {
12361: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12362: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12363: } else {
12364: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12365: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12366: }
12367: }
12368: }
12369: if (exists($changes{'validation'}{'dc'})) {
12370: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12371: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12372: }
12373: }
12374: }
12375: }
12376: $resulttext .= '</ul>';
12377: if (keys(%newenv)) {
12378: &Apache::lonnet::appenv(\%newenv);
12379: }
12380: } else {
12381: if ($context eq 'requestcourses') {
12382: $resulttext = &mt('No changes made to rights to request creation of courses.');
12383: } elsif ($context eq 'requestauthor') {
12384: $resulttext = &mt('No changes made to rights to request author space.');
12385: } else {
12386: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
12387: }
12388: }
12389: } else {
12390: $resulttext = '<span class="LC_error">'.
12391: &mt('An error occurred: [_1]',$putresult).'</span>';
12392: }
12393: if ($errors) {
12394: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12395: '<ul>'.$errors.'</ul></p>';
12396: }
12397: return $resulttext;
12398: }
12399:
12400: sub process_textbook_image {
12401: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
12402: my $filename = $env{'form.'.$caller.'.filename'};
12403: my ($error,$url);
12404: my ($width,$height) = (50,50);
12405: if ($configuserok eq 'ok') {
12406: if ($switchserver) {
12407: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12408: $switchserver);
12409: } elsif ($author_ok eq 'ok') {
12410: my ($result,$imageurl) =
12411: &publishlogo($r,'upload',$caller,$dom,$confname,
12412: "$type/$cdom/$cnum/cover",$width,$height);
12413: if ($result eq 'ok') {
12414: $url = $imageurl;
12415: } else {
12416: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12417: }
12418: } else {
12419: $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);
12420: }
12421: } else {
12422: $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);
12423: }
12424: return ($url,$error);
12425: }
12426:
12427: sub modify_ltitools {
12428: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12429: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12430: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12431: my $confname = $dom.'-domainconfig';
12432: my $servadm = $r->dir_config('lonAdmEMail');
12433: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12434: my (%posslti,%possfield);
12435: my @courseroles = ('cc','in','ta','ep','st');
12436: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12437: map { $posslti{$_} = 1; } @ltiroles;
12438: my @allfields = ('fullname','firstname','lastname','email','user','roles');
12439: map { $possfield{$_} = 1; } @allfields;
12440: my %lt = <itools_names();
12441: if ($env{'form.ltitools_add'}) {
12442: my $title = $env{'form.ltitools_add_title'};
12443: $title =~ s/(`)/'/g;
12444: ($newid,my $error) = &get_ltitools_id($dom,$title);
12445: if ($newid) {
12446: my $position = $env{'form.ltitools_add_pos'};
12447: $position =~ s/\D+//g;
12448: if ($position ne '') {
12449: $allpos[$position] = $newid;
12450: }
12451: $changes{$newid} = 1;
12452: foreach my $item ('title','url','key','secret','lifetime') {
12453: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
12454: if ($item eq 'lifetime') {
12455: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12456: }
12457: if ($env{'form.ltitools_add_'.$item}) {
12458: if (($item eq 'key') || ($item eq 'secret')) {
12459: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12460: } else {
12461: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12462: }
12463: }
12464: }
12465: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12466: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12467: }
12468: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12469: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12470: }
12471: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12472: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12473: } else {
12474: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12475: }
12476: foreach my $item ('width','height','linktext','explanation') {
12477: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12478: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
12479: if (($item eq 'width') || ($item eq 'height')) {
12480: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12481: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12482: }
12483: } else {
12484: if ($env{'form.ltitools_add_'.$item} ne '') {
12485: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12486: }
12487: }
12488: }
12489: if ($env{'form.ltitools_add_target'} eq 'window') {
12490: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12491: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12492: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12493: } else {
12494: $confhash{$newid}{'display'}{'target'} = 'iframe';
12495: }
12496: if ($env{'form.ltitools_add_image.filename'} ne '') {
12497: my ($imageurl,$error) =
12498: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
12499: $configuserok,$switchserver,$author_ok);
12500: if ($imageurl) {
12501: $confhash{$newid}{'image'} = $imageurl;
12502: }
12503: if ($error) {
12504: &Apache::lonnet::logthis($error);
12505: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12506: }
12507: }
12508: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12509: foreach my $field (@fields) {
12510: if ($possfield{$field}) {
12511: if ($field eq 'roles') {
12512: foreach my $role (@courseroles) {
12513: my $choice = $env{'form.ltitools_add_roles_'.$role};
12514: if (($choice ne '') && ($posslti{$choice})) {
12515: $confhash{$newid}{'roles'}{$role} = $choice;
12516: if ($role eq 'cc') {
12517: $confhash{$newid}{'roles'}{'co'} = $choice;
12518: }
12519: }
12520: }
12521: } else {
12522: $confhash{$newid}{'fields'}{$field} = 1;
12523: }
12524: }
12525: }
12526: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12527: if ($confhash{$newid}{'fields'}{'user'}) {
12528: if ($env{'form.ltitools_userincdom_add'}) {
12529: $confhash{$newid}{'incdom'} = 1;
12530: }
12531: }
12532: }
12533: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12534: foreach my $item (@courseconfig) {
12535: $confhash{$newid}{'crsconf'}{$item} = 1;
12536: }
12537: if ($env{'form.ltitools_add_custom'}) {
12538: my $name = $env{'form.ltitools_add_custom_name'};
12539: my $value = $env{'form.ltitools_add_custom_value'};
12540: $value =~ s/(`)/'/g;
12541: $name =~ s/(`)/'/g;
12542: $confhash{$newid}{'custom'}{$name} = $value;
12543: }
12544: } else {
12545: my $error = &mt('Failed to acquire unique ID for new external tool');
12546: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12547: }
12548: }
12549: if (ref($domconfig{$action}) eq 'HASH') {
12550: my %deletions;
12551: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12552: if (@todelete) {
12553: map { $deletions{$_} = 1; } @todelete;
12554: }
12555: my %customadds;
12556: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12557: if (@newcustom) {
12558: map { $customadds{$_} = 1; } @newcustom;
12559: }
12560: my %imgdeletions;
12561: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
12562: if (@todeleteimages) {
12563: map { $imgdeletions{$_} = 1; } @todeleteimages;
12564: }
12565: my $maxnum = $env{'form.ltitools_maxnum'};
12566: for (my $i=0; $i<=$maxnum; $i++) {
12567: my $itemid = $env{'form.ltitools_id_'.$i};
12568: $itemid =~ s/\D+//g;
12569: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12570: if ($deletions{$itemid}) {
12571: if ($domconfig{$action}{$itemid}{'image'}) {
12572: #FIXME need to obsolete item in RES space
12573: }
12574: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
12575: next;
12576: } else {
12577: my $newpos = $env{'form.ltitools_'.$itemid};
12578: $newpos =~ s/\D+//g;
12579: foreach my $item ('title','url','lifetime') {
12580: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12581: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12582: $changes{$itemid} = 1;
12583: }
12584: }
12585: foreach my $item ('key','secret') {
12586: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12587: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12588: $changes{$itemid} = 1;
12589: }
12590: }
12591: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12592: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12593: }
12594: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12595: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12596: }
12597: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12598: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12599: } else {
12600: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12601: }
12602: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12603: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12604: $changes{$itemid} = 1;
12605: }
12606: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12607: $changes{$itemid} = 1;
12608: }
12609: foreach my $size ('width','height') {
12610: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12611: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12612: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12613: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12614: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12615: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12616: $changes{$itemid} = 1;
12617: }
12618: } else {
12619: $changes{$itemid} = 1;
12620: }
12621: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12622: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12623: $changes{$itemid} = 1;
12624: }
12625: }
12626: }
12627: foreach my $item ('linktext','explanation') {
12628: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12629: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12630: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12631: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12632: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12633: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12634: $changes{$itemid} = 1;
12635: }
12636: } else {
12637: $changes{$itemid} = 1;
12638: }
12639: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12640: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12641: $changes{$itemid} = 1;
12642: }
12643: }
12644: }
12645: if ($env{'form.ltitools_target_'.$i} eq 'window') {
12646: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12647: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12648: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12649: } else {
12650: $confhash{$itemid}{'display'}{'target'} = 'iframe';
12651: }
12652: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12653: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12654: $changes{$itemid} = 1;
12655: }
12656: } else {
12657: $changes{$itemid} = 1;
12658: }
12659: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
12660: foreach my $item ('label','title','target','linktext','explanation','append') {
12661: if (grep(/^\Q$item\E$/,@courseconfig)) {
12662: $confhash{$itemid}{'crsconf'}{$item} = 1;
12663: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12664: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12665: $changes{$itemid} = 1;
12666: }
12667: } else {
12668: $changes{$itemid} = 1;
12669: }
12670: }
12671: }
12672: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12673: foreach my $field (@fields) {
12674: if ($possfield{$field}) {
12675: if ($field eq 'roles') {
12676: foreach my $role (@courseroles) {
12677: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12678: if (($choice ne '') && ($posslti{$choice})) {
12679: $confhash{$itemid}{'roles'}{$role} = $choice;
12680: if ($role eq 'cc') {
12681: $confhash{$itemid}{'roles'}{'co'} = $choice;
12682: }
12683: }
12684: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12685: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12686: $changes{$itemid} = 1;
12687: }
12688: } elsif ($confhash{$itemid}{'roles'}{$role}) {
12689: $changes{$itemid} = 1;
12690: }
12691: }
12692: } else {
12693: $confhash{$itemid}{'fields'}{$field} = 1;
12694: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12695: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12696: $changes{$itemid} = 1;
12697: }
12698: } else {
12699: $changes{$itemid} = 1;
12700: }
12701: }
12702: }
12703: }
12704: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12705: if ($confhash{$itemid}{'fields'}{'user'}) {
12706: if ($env{'form.ltitools_userincdom_'.$i}) {
12707: $confhash{$itemid}{'incdom'} = 1;
12708: }
12709: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12710: $changes{$itemid} = 1;
12711: }
12712: }
12713: }
12714: $allpos[$newpos] = $itemid;
12715: }
12716: if ($imgdeletions{$itemid}) {
12717: $changes{$itemid} = 1;
12718: #FIXME need to obsolete item in RES space
12719: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12720: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12721: $itemid,$configuserok,$switchserver,
12722: $author_ok);
12723: if ($imgurl) {
12724: $confhash{$itemid}{'image'} = $imgurl;
12725: $changes{$itemid} = 1;
12726: }
12727: if ($error) {
12728: &Apache::lonnet::logthis($error);
12729: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12730: }
12731: } elsif ($domconfig{$action}{$itemid}{'image'}) {
12732: $confhash{$itemid}{'image'} =
12733: $domconfig{$action}{$itemid}{'image'};
12734: }
12735: if ($customadds{$i}) {
12736: my $name = $env{'form.ltitools_custom_name_'.$i};
12737: $name =~ s/(`)/'/g;
12738: $name =~ s/^\s+//;
12739: $name =~ s/\s+$//;
12740: my $value = $env{'form.ltitools_custom_value_'.$i};
12741: $value =~ s/(`)/'/g;
12742: $value =~ s/^\s+//;
12743: $value =~ s/\s+$//;
12744: if ($name ne '') {
12745: $confhash{$itemid}{'custom'}{$name} = $value;
12746: $changes{$itemid} = 1;
12747: }
12748: }
12749: my %customdels;
12750: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12751: if (@customdeletions) {
12752: $changes{$itemid} = 1;
12753: }
12754: map { $customdels{$_} = 1; } @customdeletions;
12755: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12756: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12757: unless ($customdels{$key}) {
12758: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12759: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12760: }
12761: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12762: $changes{$itemid} = 1;
12763: }
12764: }
12765: }
12766: }
12767: unless ($changes{$itemid}) {
12768: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12769: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12770: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12771: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12772: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12773: $changes{$itemid} = 1;
12774: last;
12775: }
12776: }
12777: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12778: $changes{$itemid} = 1;
12779: }
12780: }
12781: last if ($changes{$itemid});
12782: }
12783: }
12784: }
12785: }
12786: }
12787: if (@allpos > 0) {
12788: my $idx = 0;
12789: foreach my $itemid (@allpos) {
12790: if ($itemid ne '') {
12791: $confhash{$itemid}{'order'} = $idx;
12792: if (ref($domconfig{$action}) eq 'HASH') {
12793: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12794: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12795: $changes{$itemid} = 1;
12796: }
12797: }
12798: }
12799: $idx ++;
12800: }
12801: }
12802: }
12803: my %ltitoolshash = (
12804: $action => { %confhash }
12805: );
12806: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12807: $dom);
12808: if ($putresult eq 'ok') {
12809: my %ltienchash = (
12810: $action => { %encconfig }
12811: );
12812: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
12813: if (keys(%changes) > 0) {
12814: my $cachetime = 24*60*60;
12815: my %ltiall = %confhash;
12816: foreach my $id (keys(%ltiall)) {
12817: if (ref($encconfig{$id}) eq 'HASH') {
12818: foreach my $item ('key','secret') {
12819: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12820: }
12821: }
12822: }
12823: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
12824: if (ref($lastactref) eq 'HASH') {
12825: $lastactref->{'ltitools'} = 1;
12826: }
12827: $resulttext = &mt('Changes made:').'<ul>';
12828: my %bynum;
12829: foreach my $itemid (sort(keys(%changes))) {
12830: my $position = $confhash{$itemid}{'order'};
12831: $bynum{$position} = $itemid;
12832: }
12833: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12834: my $itemid = $bynum{$pos};
12835: if (ref($confhash{$itemid}) ne 'HASH') {
12836: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12837: } else {
12838: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12839: if ($confhash{$itemid}{'image'}) {
12840: $resulttext .= ' '.
12841: '<img src="'.$confhash{$itemid}{'image'}.'"'.
12842: ' alt="'.&mt('Tool Provider icon').'" />';
12843: }
12844: $resulttext .= '</li><ul>';
12845: my $position = $pos + 1;
12846: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12847: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
12848: if ($confhash{$itemid}{$item} ne '') {
12849: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12850: }
12851: }
12852: if ($encconfig{$itemid}{'key'} ne '') {
12853: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12854: }
12855: if ($encconfig{$itemid}{'secret'} ne '') {
12856: $resulttext .= '<li>'.$lt{'secret'}.': ';
12857: my $num = length($encconfig{$itemid}{'secret'});
12858: $resulttext .= ('*'x$num).'</li>';
12859: }
12860: $resulttext .= '<li>'.&mt('Configurable in course:');
12861: my @possconfig = ('label','title','target','linktext','explanation','append');
12862: my $numconfig = 0;
12863: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12864: foreach my $item (@possconfig) {
12865: if ($confhash{$itemid}{'crsconf'}{$item}) {
12866: $numconfig ++;
12867: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
12868: }
12869: }
12870: }
12871: if (!$numconfig) {
12872: $resulttext .= &mt('None');
12873: }
12874: $resulttext .= '</li>';
12875: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12876: my $displaylist;
12877: if ($confhash{$itemid}{'display'}{'target'}) {
12878: $displaylist = &mt('Display target').': '.
12879: $confhash{$itemid}{'display'}{'target'}.',';
12880: }
12881: foreach my $size ('width','height') {
12882: if ($confhash{$itemid}{'display'}{$size}) {
12883: $displaylist .= (' 'x2).$lt{$size}.': '.
12884: $confhash{$itemid}{'display'}{$size}.',';
12885: }
12886: }
12887: if ($displaylist) {
12888: $displaylist =~ s/,$//;
12889: $resulttext .= '<li>'.$displaylist.'</li>';
12890: }
12891: foreach my $item ('linktext','explanation') {
12892: if ($confhash{$itemid}{'display'}{$item}) {
12893: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12894: }
12895: }
12896: }
12897: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12898: my $fieldlist;
12899: foreach my $field (@allfields) {
12900: if ($confhash{$itemid}{'fields'}{$field}) {
12901: $fieldlist .= (' 'x2).$lt{$field}.',';
12902: }
12903: }
12904: if ($fieldlist) {
12905: $fieldlist =~ s/,$//;
12906: if ($confhash{$itemid}{'fields'}{'user'}) {
12907: if ($confhash{$itemid}{'incdom'}) {
12908: $fieldlist .= ' ('.&mt('username:domain').')';
12909: } else {
12910: $fieldlist .= ' ('.&mt('username').')';
12911: }
12912: }
12913: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12914: }
12915: }
12916: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12917: my $rolemaps;
12918: foreach my $role (@courseroles) {
12919: if ($confhash{$itemid}{'roles'}{$role}) {
12920: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12921: $confhash{$itemid}{'roles'}{$role}.',';
12922: }
12923: }
12924: if ($rolemaps) {
12925: $rolemaps =~ s/,$//;
12926: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12927: }
12928: }
12929: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12930: my $customlist;
12931: if (keys(%{$confhash{$itemid}{'custom'}})) {
12932: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12933: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12934: }
12935: }
12936: if ($customlist) {
12937: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
12938: }
12939: }
12940: $resulttext .= '</ul></li>';
12941: }
12942: }
12943: $resulttext .= '</ul>';
12944: } else {
12945: $resulttext = &mt('No changes made.');
12946: }
12947: } else {
12948: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12949: }
12950: if ($errors) {
12951: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12952: $errors.'</ul>';
12953: }
12954: return $resulttext;
12955: }
12956:
12957: sub process_ltitools_image {
12958: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12959: my $filename = $env{'form.'.$caller.'.filename'};
12960: my ($error,$url);
12961: my ($width,$height) = (21,21);
12962: if ($configuserok eq 'ok') {
12963: if ($switchserver) {
12964: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12965: $switchserver);
12966: } elsif ($author_ok eq 'ok') {
12967: my ($result,$imageurl,$madethumb) =
12968: &publishlogo($r,'upload',$caller,$dom,$confname,
12969: "ltitools/$itemid/icon",$width,$height);
12970: if ($result eq 'ok') {
12971: if ($madethumb) {
12972: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12973: my $imagethumb = "$path/tn-".$imagefile;
12974: $url = $imagethumb;
12975: } else {
12976: $url = $imageurl;
12977: }
12978: } else {
12979: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12980: }
12981: } else {
12982: $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);
12983: }
12984: } else {
12985: $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);
12986: }
12987: return ($url,$error);
12988: }
12989:
12990: sub get_ltitools_id {
12991: my ($cdom,$title) = @_;
12992: # get lock on ltitools db
12993: my $lockhash = {
12994: lock => $env{'user.name'}.
12995: ':'.$env{'user.domain'},
12996: };
12997: my $tries = 0;
12998: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12999: my ($id,$error);
13000:
13001: while (($gotlock ne 'ok') && ($tries<10)) {
13002: $tries ++;
13003: sleep (0.1);
13004: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13005: }
13006: if ($gotlock eq 'ok') {
13007: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
13008: if ($currids{'lock'}) {
13009: delete($currids{'lock'});
13010: if (keys(%currids)) {
13011: my @curr = sort { $a <=> $b } keys(%currids);
13012: if ($curr[-1] =~ /^\d+$/) {
13013: $id = 1 + $curr[-1];
13014: }
13015: } else {
13016: $id = 1;
13017: }
13018: if ($id) {
13019: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
13020: $error = 'nostore';
13021: }
13022: } else {
13023: $error = 'nonumber';
13024: }
13025: }
13026: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
13027: } else {
13028: $error = 'nolock';
13029: }
13030: return ($id,$error);
13031: }
13032:
13033: sub modify_lti {
13034: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13035: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13036: my (%encconfig,$errors,$resulttext);
13037:
13038: my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
13039: $newltisec{'private'}{'keys'} = [];
13040: $newltisec{'encrypt'} = {};
13041: $newltisec{'rules'} = {};
13042: $newltisec{'linkprot'} = {};
13043: if (ref($domconfig{'ltisec'}) eq 'HASH') {
13044: %currltisec = %{$domconfig{'ltisec'}};
13045: if (ref($currltisec{'linkprot'}) eq 'HASH') {
13046: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
13047: unless ($id =~ /^\d+$/) {
13048: delete($currltisec{'linkprot'}{$id});
13049: }
13050: }
13051: }
13052: if (ref($currltisec{'private'}) eq 'HASH') {
13053: if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
13054: $newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
13055: map { $keyset{$_} = 1; } @{$currltisec{'private'}{'keys'}};
13056: }
13057: }
13058: }
13059: foreach my $item ('crs','dom') {
13060: my $formelement = 'form.ltisec_'.$item.'linkprot';
13061: if ($env{$formelement}) {
13062: $newltisec{'encrypt'}{$item} = 1;
13063: if (ref($currltisec{'encrypt'}) eq 'HASH') {
13064: unless ($currltisec{'encrypt'}{$item}) {
13065: $secchanges{'encrypt'} = 1;
13066: }
13067: } else {
13068: $secchanges{'encrypt'} = 1;
13069: }
13070: } elsif (ref($currltisec{'encrypt'}) eq 'HASH') {
13071: if ($currltisec{'encrypt'}{$item}) {
13072: $secchanges{'encrypt'} = 1;
13073: }
13074: }
13075: }
13076: unless (exists($currltisec{'rules'})) {
13077: $currltisec{'rules'} = {};
13078: }
13079: &password_rule_changes('secrets',$newltisec{'rules'},$currltisec{'rules'},\%secchanges);
13080:
13081: my @ids=&Apache::lonnet::current_machine_ids();
13082: my %servers = &Apache::lonnet::get_servers($dom,'library');
13083:
13084: foreach my $hostid (keys(%servers)) {
13085: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13086: my $newkey;
13087: my $keyitem = 'form.ltisec_privkey_'.$hostid;
13088: if (exists($env{$keyitem})) {
13089: $env{$keyitem} =~ s/(`)/'/g;
13090: if ($keyset{$hostid}) {
13091: if ($env{'form.ltisec_changeprivkey_'.$hostid}) {
13092: if ($env{$keyitem} ne '') {
13093: $secchanges{'private'} = 1;
13094: $newkeyset{$hostid} = $env{$keyitem};
13095: }
13096: }
13097: } elsif ($env{$keyitem} ne '') {
13098: unless (grep(/^\Q$hostid\E$/,@{$newltisec{'private'}{'keys'}})) {
13099: push(@{$newltisec{'private'}{'keys'}},$hostid);
13100: }
13101: $secchanges{'private'} = 1;
13102: $newkeyset{$hostid} = $env{$keyitem};
13103: }
13104: }
13105: }
13106: }
13107:
13108: my (%linkprotchg,$linkprotoutput,$is_home);
13109: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13110: \%linkprotchg,'domain');
13111: my $home = &Apache::lonnet::domain($dom,'primary');
13112: unless (($home eq 'no_host') || ($home eq '')) {
13113: my @ids=&Apache::lonnet::current_machine_ids();
13114: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13115: }
13116:
13117: if (keys(%linkprotchg)) {
13118: $secchanges{'linkprot'} = 1;
13119: my %oldlinkprot;
13120: if (ref($currltisec{'linkprot'}) eq 'HASH') {
13121: %oldlinkprot = %{$currltisec{'linkprot'}};
13122: }
13123: foreach my $id (keys(%linkprotchg)) {
13124: if (ref($linkprotchg{$id}) eq 'HASH') {
13125: foreach my $inner (keys(%{$linkprotchg{$id}})) {
13126: if (($inner eq 'secret') || ($inner eq 'key')) {
13127: if ($is_home) {
13128: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13129: }
13130: }
13131: }
13132: } else {
13133: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
13134: }
13135: }
13136: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13137: if (keys(%linkprotchg)) {
13138: %{$newltisec{'linkprot'}} = %linkprotchg;
13139: }
13140: }
13141: if (ref($currltisec{'linkprot'}) eq 'HASH') {
13142: foreach my $id (%{$currltisec{'linkprot'}}) {
13143: next if ($id !~ /^\d+$/);
13144: unless (exists($linkprotchg{$id})) {
13145: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13146: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13147: if (($inner eq 'secret') || ($inner eq 'key')) {
13148: if ($is_home) {
13149: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13150: }
13151: } else {
13152: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13153: }
13154: }
13155: } else {
13156: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
13157: }
13158: }
13159: }
13160: }
13161: if ($proterror) {
13162: $errors .= '<li>'.$proterror.'</li>';
13163: }
13164:
13165: my ($putresult,%keystore);
13166: if (keys(%secchanges)) {
13167: my %ltienchash;
13168: my %ltihash = (
13169: 'ltisec' => { %newltisec }
13170: );
13171: $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
13172: if ($putresult eq 'ok') {
13173: if ($secchanges{'private'}) {
13174: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13175: foreach my $hostid (keys(%newkeyset)) {
13176: my $storehash = {
13177: key => $newkeyset{$hostid},
13178: who => $env{'user.name'}.':'.$env{'user.domain'},
13179: };
13180: $keystore{$hostid} = &Apache::lonnet::store_dom($storehash,'lti','private',
13181: $dom,$hostid);
13182: }
13183: }
13184: if (ref($lastactref) eq 'HASH') {
13185: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
13186: $lastactref->{'domdefaults'} = 1;
13187: }
13188: }
13189: if (($secchanges{'linkprot'}) && ($is_home)) {
13190: my %ltienchash = (
13191: 'linkprot' => { %newltienc }
13192: );
13193: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
13194: }
13195: }
13196: } else {
13197: return &mt('No changes made.');
13198: }
13199: if ($putresult eq 'ok') {
13200: $resulttext = &mt('Changes made:').'<ul>';
13201: foreach my $item (keys(%secchanges)) {
13202: if ($item eq 'encrypt') {
13203: my %encrypted = (
13204: crs => {
13205: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13206: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13207: },
13208: dom => {
13209: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13210: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13211: },
13212: );
13213: foreach my $type ('crs','dom') {
13214: my $shown = $encrypted{$type}{'off'};
13215: if (ref($newltisec{$item}) eq 'HASH') {
13216: if ($newltisec{$item}{$type}) {
13217: $shown = $encrypted{$type}{'on'};
13218: }
13219: }
13220: $resulttext .= '<li>'.$shown.'</li>';
13221: }
13222: } elsif ($item eq 'rules') {
13223: my %titles = &Apache::lonlocal::texthash(
13224: min => 'Minimum password length',
13225: max => 'Maximum password length',
13226: chars => 'Required characters',
13227: );
13228: foreach my $rule ('min','max') {
13229: if ($newltisec{rules}{$rule} eq '') {
13230: if ($rule eq 'min') {
13231: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13232: ' '.&mt('Default of [_1] will be used',
13233: $Apache::lonnet::passwdmin).'</li>';
13234: } else {
13235: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13236: }
13237: } else {
13238: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newltisec{rules}{$rule}).'</li>';
13239: }
13240: }
13241: if (ref($newltisec{'rules'}{'chars'}) eq 'ARRAY') {
13242: if (@{$newltisec{'rules'}{'chars'}} > 0) {
13243: my %rulenames = &Apache::lonlocal::texthash(
13244: uc => 'At least one upper case letter',
13245: lc => 'At least one lower case letter',
13246: num => 'At least one number',
13247: spec => 'At least one non-alphanumeric',
13248: );
13249: my $needed = '<ul><li>'.
13250: join('</li><li>',map {$rulenames{$_} } @{$newltisec{'rules'}{'chars'}}).
13251: '</li></ul>';
13252: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13253: } else {
13254: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13255: }
13256: } else {
13257: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13258: }
13259: } elsif ($item eq 'private') {
13260: if (keys(%newkeyset)) {
13261: foreach my $hostid (sort(keys(%newkeyset))) {
13262: if ($keystore{$hostid} eq 'ok') {
13263: $resulttext .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13264: }
13265: }
13266: }
13267: } elsif ($item eq 'linkprot') {
13268: $resulttext .= $linkprotoutput;
13269: }
13270: }
13271: $resulttext .= '</ul>';
13272: } else {
13273: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13274: }
13275: if ($errors) {
13276: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13277: $errors.'</ul>';
13278: }
13279: return $resulttext;
13280: }
13281:
13282: sub modify_autoenroll {
13283: my ($dom,$lastactref,%domconfig) = @_;
13284: my ($resulttext,%changes);
13285: my %currautoenroll;
13286: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
13287: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
13288: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
13289: }
13290: }
13291: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
13292: my %title = ( run => 'Auto-enrollment active',
13293: sender => 'Sender for notification messages',
13294: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
13295: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
13296: my @offon = ('off','on');
13297: my $sender_uname = $env{'form.sender_uname'};
13298: my $sender_domain = $env{'form.sender_domain'};
13299: if ($sender_domain eq '') {
13300: $sender_uname = '';
13301: } elsif ($sender_uname eq '') {
13302: $sender_domain = '';
13303: }
13304: my $coowners = $env{'form.autoassign_coowners'};
13305: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
13306: $autofailsafe =~ s{^\s+|\s+$}{}g;
13307: if ($autofailsafe =~ /\D/) {
13308: undef($autofailsafe);
13309: }
13310: my $failsafe = $env{'form.autoenroll_failsafe'};
13311: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
13312: $failsafe = 'off';
13313: undef($autofailsafe);
13314: }
13315: my %autoenrollhash = (
13316: autoenroll => { 'run' => $env{'form.autoenroll_run'},
13317: 'sender_uname' => $sender_uname,
13318: 'sender_domain' => $sender_domain,
13319: 'co-owners' => $coowners,
13320: 'autofailsafe' => $autofailsafe,
13321: 'failsafe' => $failsafe,
13322: }
13323: );
13324: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
13325: $dom);
13326: if ($putresult eq 'ok') {
13327: if (exists($currautoenroll{'run'})) {
13328: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
13329: $changes{'run'} = 1;
13330: }
13331: } elsif ($autorun) {
13332: if ($env{'form.autoenroll_run'} ne '1') {
13333: $changes{'run'} = 1;
13334: }
13335: }
13336: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
13337: $changes{'sender'} = 1;
13338: }
13339: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
13340: $changes{'sender'} = 1;
13341: }
13342: if ($currautoenroll{'co-owners'} ne '') {
13343: if ($currautoenroll{'co-owners'} ne $coowners) {
13344: $changes{'coowners'} = 1;
13345: }
13346: } elsif ($coowners) {
13347: $changes{'coowners'} = 1;
13348: }
13349: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
13350: $changes{'autofailsafe'} = 1;
13351: }
13352: if ($currautoenroll{'failsafe'} ne $failsafe) {
13353: $changes{'failsafe'} = 1;
13354: }
13355: if (keys(%changes) > 0) {
13356: $resulttext = &mt('Changes made:').'<ul>';
13357: if ($changes{'run'}) {
13358: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
13359: }
13360: if ($changes{'sender'}) {
13361: if ($sender_uname eq '' || $sender_domain eq '') {
13362: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
13363: } else {
13364: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
13365: }
13366: }
13367: if ($changes{'coowners'}) {
13368: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
13369: &Apache::loncommon::devalidate_domconfig_cache($dom);
13370: if (ref($lastactref) eq 'HASH') {
13371: $lastactref->{'domainconfig'} = 1;
13372: }
13373: }
13374: if ($changes{'autofailsafe'}) {
13375: if ($autofailsafe ne '') {
13376: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
13377: } else {
13378: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
13379: }
13380: }
13381: if ($changes{'failsafe'}) {
13382: if ($failsafe eq 'off') {
13383: unless ($changes{'autofailsafe'}) {
13384: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
13385: }
13386: } elsif ($failsafe eq 'zero') {
13387: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
13388: } else {
13389: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
13390: }
13391: }
13392: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
13393: &Apache::lonnet::get_domain_defaults($dom,1);
13394: if (ref($lastactref) eq 'HASH') {
13395: $lastactref->{'domdefaults'} = 1;
13396: }
13397: }
13398: $resulttext .= '</ul>';
13399: } else {
13400: $resulttext = &mt('No changes made to auto-enrollment settings');
13401: }
13402: } else {
13403: $resulttext = '<span class="LC_error">'.
13404: &mt('An error occurred: [_1]',$putresult).'</span>';
13405: }
13406: return $resulttext;
13407: }
13408:
13409: sub modify_autoupdate {
13410: my ($dom,%domconfig) = @_;
13411: my ($resulttext,%currautoupdate,%fields,%changes);
13412: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
13413: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
13414: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
13415: }
13416: }
13417: my @offon = ('off','on');
13418: my %title = &Apache::lonlocal::texthash (
13419: run => 'Auto-update:',
13420: classlists => 'Updates to user information in classlists?',
13421: unexpired => 'Skip updates for users without active or future roles?',
13422: lastactive => 'Skip updates for inactive users?',
13423: );
13424: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13425: my %fieldtitles = &Apache::lonlocal::texthash (
13426: id => 'Student/Employee ID',
13427: permanentemail => 'E-mail address',
13428: lastname => 'Last Name',
13429: firstname => 'First Name',
13430: middlename => 'Middle Name',
13431: generation => 'Generation',
13432: );
13433: $othertitle = &mt('All users');
13434: if (keys(%{$usertypes}) > 0) {
13435: $othertitle = &mt('Other users');
13436: }
13437: foreach my $key (keys(%env)) {
13438: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
13439: my ($usertype,$item) = ($1,$2);
13440: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
13441: if ($usertype eq 'default') {
13442: push(@{$fields{$1}},$2);
13443: } elsif (ref($types) eq 'ARRAY') {
13444: if (grep(/^\Q$usertype\E$/,@{$types})) {
13445: push(@{$fields{$1}},$2);
13446: }
13447: }
13448: }
13449: }
13450: }
13451: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
13452: @lockablenames = sort(@lockablenames);
13453: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
13454: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13455: if (@changed) {
13456: $changes{'lockablenames'} = 1;
13457: }
13458: } else {
13459: if (@lockablenames) {
13460: $changes{'lockablenames'} = 1;
13461: }
13462: }
13463: my %updatehash = (
13464: autoupdate => { run => $env{'form.autoupdate_run'},
13465: classlists => $env{'form.classlists'},
13466: unexpired => $env{'form.unexpired'},
13467: fields => {%fields},
13468: lockablenames => \@lockablenames,
13469: }
13470: );
13471: my $lastactivedays;
13472: if ($env{'form.lastactive'}) {
13473: $lastactivedays = $env{'form.lastactivedays'};
13474: $lastactivedays =~ s/^\s+|\s+$//g;
13475: unless ($lastactivedays =~ /^\d+$/) {
13476: undef($lastactivedays);
13477: $env{'form.lastactive'} = 0;
13478: }
13479: }
13480: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
13481: foreach my $key (keys(%currautoupdate)) {
13482: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
13483: if (exists($updatehash{autoupdate}{$key})) {
13484: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
13485: $changes{$key} = 1;
13486: }
13487: }
13488: } elsif ($key eq 'fields') {
13489: if (ref($currautoupdate{$key}) eq 'HASH') {
13490: foreach my $item (@{$types},'default') {
13491: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
13492: my $change = 0;
13493: foreach my $type (@{$currautoupdate{$key}{$item}}) {
13494: if (!exists($fields{$item})) {
13495: $change = 1;
13496: last;
13497: } elsif (ref($fields{$item}) eq 'ARRAY') {
13498: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
13499: $change = 1;
13500: last;
13501: }
13502: }
13503: }
13504: if ($change) {
13505: push(@{$changes{$key}},$item);
13506: }
13507: }
13508: }
13509: }
13510: } elsif ($key eq 'lockablenames') {
13511: if (ref($currautoupdate{$key}) eq 'ARRAY') {
13512: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13513: if (@changed) {
13514: $changes{'lockablenames'} = 1;
13515: }
13516: } else {
13517: if (@lockablenames) {
13518: $changes{'lockablenames'} = 1;
13519: }
13520: }
13521: }
13522: }
13523: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13524: if (@lockablenames) {
13525: $changes{'lockablenames'} = 1;
13526: }
13527: }
13528: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
13529: if ($updatehash{'autoupdate'}{'unexpired'}) {
13530: $changes{'unexpired'} = 1;
13531: }
13532: }
13533: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
13534: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
13535: $changes{'lastactive'} = 1;
13536: }
13537: }
13538: foreach my $item (@{$types},'default') {
13539: if (defined($fields{$item})) {
13540: if (ref($currautoupdate{'fields'}) eq 'HASH') {
13541: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13542: my $change = 0;
13543: if (ref($fields{$item}) eq 'ARRAY') {
13544: foreach my $type (@{$fields{$item}}) {
13545: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13546: $change = 1;
13547: last;
13548: }
13549: }
13550: }
13551: if ($change) {
13552: push(@{$changes{'fields'}},$item);
13553: }
13554: } else {
13555: push(@{$changes{'fields'}},$item);
13556: }
13557: } else {
13558: push(@{$changes{'fields'}},$item);
13559: }
13560: }
13561: }
13562: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13563: $dom);
13564: if ($putresult eq 'ok') {
13565: if (keys(%changes) > 0) {
13566: $resulttext = &mt('Changes made:').'<ul>';
13567: foreach my $key (sort(keys(%changes))) {
13568: if ($key eq 'lockablenames') {
13569: $resulttext .= '<li>';
13570: if (@lockablenames) {
13571: $usertypes->{'default'} = $othertitle;
13572: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13573: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13574: } else {
13575: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13576: }
13577: $resulttext .= '</li>';
13578: } elsif (ref($changes{$key}) eq 'ARRAY') {
13579: foreach my $item (@{$changes{$key}}) {
13580: my @newvalues;
13581: foreach my $type (@{$fields{$item}}) {
13582: push(@newvalues,$fieldtitles{$type});
13583: }
13584: my $newvaluestr;
13585: if (@newvalues > 0) {
13586: $newvaluestr = join(', ',@newvalues);
13587: } else {
13588: $newvaluestr = &mt('none');
13589: }
13590: if ($item eq 'default') {
13591: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
13592: } else {
13593: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
13594: }
13595: }
13596: } else {
13597: my $newvalue;
13598: if ($key eq 'run') {
13599: $newvalue = $offon[$env{'form.autoupdate_run'}];
13600: } elsif ($key eq 'lastactive') {
13601: $newvalue = $offon[$env{'form.lastactive'}];
13602: unless ($lastactivedays eq '') {
13603: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
13604: }
13605: } else {
13606: $newvalue = $offon[$env{'form.'.$key}];
13607: }
13608: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13609: }
13610: }
13611: $resulttext .= '</ul>';
13612: } else {
13613: $resulttext = &mt('No changes made to autoupdates');
13614: }
13615: } else {
13616: $resulttext = '<span class="LC_error">'.
13617: &mt('An error occurred: [_1]',$putresult).'</span>';
13618: }
13619: return $resulttext;
13620: }
13621:
13622: sub modify_autocreate {
13623: my ($dom,%domconfig) = @_;
13624: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13625: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13626: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13627: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13628: }
13629: }
13630: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13631: req => 'Auto-creation of validated requests for official courses',
13632: xmldc => 'Identity of course creator of courses from XML files',
13633: );
13634: my @types = ('xml','req');
13635: foreach my $item (@types) {
13636: $newvals{$item} = $env{'form.autocreate_'.$item};
13637: $newvals{$item} =~ s/\D//g;
13638: $newvals{$item} = 0 if ($newvals{$item} eq '');
13639: }
13640: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
13641: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
13642: unless (exists($domcoords{$newvals{'xmldc'}})) {
13643: $newvals{'xmldc'} = '';
13644: }
13645: %autocreatehash = (
13646: autocreate => { xml => $newvals{'xml'},
13647: req => $newvals{'req'},
13648: }
13649: );
13650: if ($newvals{'xmldc'} ne '') {
13651: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13652: }
13653: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13654: $dom);
13655: if ($putresult eq 'ok') {
13656: my @items = @types;
13657: if ($newvals{'xml'}) {
13658: push(@items,'xmldc');
13659: }
13660: foreach my $item (@items) {
13661: if (exists($currautocreate{$item})) {
13662: if ($currautocreate{$item} ne $newvals{$item}) {
13663: $changes{$item} = 1;
13664: }
13665: } elsif ($newvals{$item}) {
13666: $changes{$item} = 1;
13667: }
13668: }
13669: if (keys(%changes) > 0) {
13670: my @offon = ('off','on');
13671: $resulttext = &mt('Changes made:').'<ul>';
13672: foreach my $item (@types) {
13673: if ($changes{$item}) {
13674: my $newtxt = $offon[$newvals{$item}];
13675: $resulttext .= '<li>'.
13676: &mt("$title{$item} set to [_1]$newtxt [_2]",
13677: '<b>','</b>').
13678: '</li>';
13679: }
13680: }
13681: if ($changes{'xmldc'}) {
13682: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13683: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
13684: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
13685: }
13686: $resulttext .= '</ul>';
13687: } else {
13688: $resulttext = &mt('No changes made to auto-creation settings');
13689: }
13690: } else {
13691: $resulttext = '<span class="LC_error">'.
13692: &mt('An error occurred: [_1]',$putresult).'</span>';
13693: }
13694: return $resulttext;
13695: }
13696:
13697: sub modify_directorysrch {
13698: my ($dom,$lastactref,%domconfig) = @_;
13699: my ($resulttext,%changes);
13700: my %currdirsrch;
13701: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13702: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13703: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13704: }
13705: }
13706: my %title = ( available => 'Institutional directory search available',
13707: localonly => 'Other domains can search institution',
13708: lcavailable => 'LON-CAPA directory search available',
13709: lclocalonly => 'Other domains can search LON-CAPA domain',
13710: searchby => 'Search types',
13711: searchtypes => 'Search latitude');
13712: my @offon = ('off','on');
13713: my @otherdoms = ('Yes','No');
13714:
13715: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
13716: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13717: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13718:
13719: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13720: if (keys(%{$usertypes}) == 0) {
13721: @cansearch = ('default');
13722: } else {
13723: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13724: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13725: if (!grep(/^\Q$type\E$/,@cansearch)) {
13726: push(@{$changes{'cansearch'}},$type);
13727: }
13728: }
13729: foreach my $type (@cansearch) {
13730: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13731: push(@{$changes{'cansearch'}},$type);
13732: }
13733: }
13734: } else {
13735: push(@{$changes{'cansearch'}},@cansearch);
13736: }
13737: }
13738:
13739: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13740: foreach my $by (@{$currdirsrch{'searchby'}}) {
13741: if (!grep(/^\Q$by\E$/,@searchby)) {
13742: push(@{$changes{'searchby'}},$by);
13743: }
13744: }
13745: foreach my $by (@searchby) {
13746: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13747: push(@{$changes{'searchby'}},$by);
13748: }
13749: }
13750: } else {
13751: push(@{$changes{'searchby'}},@searchby);
13752: }
13753:
13754: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13755: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13756: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13757: push(@{$changes{'searchtypes'}},$type);
13758: }
13759: }
13760: foreach my $type (@searchtypes) {
13761: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13762: push(@{$changes{'searchtypes'}},$type);
13763: }
13764: }
13765: } else {
13766: if (exists($currdirsrch{'searchtypes'})) {
13767: foreach my $type (@searchtypes) {
13768: if ($type ne $currdirsrch{'searchtypes'}) {
13769: push(@{$changes{'searchtypes'}},$type);
13770: }
13771: }
13772: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13773: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13774: }
13775: } else {
13776: push(@{$changes{'searchtypes'}},@searchtypes);
13777: }
13778: }
13779:
13780: my %dirsrch_hash = (
13781: directorysrch => { available => $env{'form.dirsrch_available'},
13782: cansearch => \@cansearch,
13783: localonly => $env{'form.dirsrch_instlocalonly'},
13784: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13785: lcavailable => $env{'form.dirsrch_domavailable'},
13786: searchby => \@searchby,
13787: searchtypes => \@searchtypes,
13788: }
13789: );
13790: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13791: $dom);
13792: if ($putresult eq 'ok') {
13793: if (exists($currdirsrch{'available'})) {
13794: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13795: $changes{'available'} = 1;
13796: }
13797: } else {
13798: if ($env{'form.dirsrch_available'} eq '1') {
13799: $changes{'available'} = 1;
13800: }
13801: }
13802: if (exists($currdirsrch{'lcavailable'})) {
13803: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13804: $changes{'lcavailable'} = 1;
13805: }
13806: } else {
13807: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13808: $changes{'lcavailable'} = 1;
13809: }
13810: }
13811: if (exists($currdirsrch{'localonly'})) {
13812: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
13813: $changes{'localonly'} = 1;
13814: }
13815: } else {
13816: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
13817: $changes{'localonly'} = 1;
13818: }
13819: }
13820: if (exists($currdirsrch{'lclocalonly'})) {
13821: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13822: $changes{'lclocalonly'} = 1;
13823: }
13824: } else {
13825: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13826: $changes{'lclocalonly'} = 1;
13827: }
13828: }
13829: if (keys(%changes) > 0) {
13830: $resulttext = &mt('Changes made:').'<ul>';
13831: if ($changes{'available'}) {
13832: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13833: }
13834: if ($changes{'lcavailable'}) {
13835: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13836: }
13837: if ($changes{'localonly'}) {
13838: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
13839: }
13840: if ($changes{'lclocalonly'}) {
13841: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
13842: }
13843: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13844: my $chgtext;
13845: if (ref($usertypes) eq 'HASH') {
13846: if (keys(%{$usertypes}) > 0) {
13847: foreach my $type (@{$types}) {
13848: if (grep(/^\Q$type\E$/,@cansearch)) {
13849: $chgtext .= $usertypes->{$type}.'; ';
13850: }
13851: }
13852: if (grep(/^default$/,@cansearch)) {
13853: $chgtext .= $othertitle;
13854: } else {
13855: $chgtext =~ s/\; $//;
13856: }
13857: $resulttext .=
13858: '<li>'.
13859: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13860: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13861: '</li>';
13862: }
13863: }
13864: }
13865: if (ref($changes{'searchby'}) eq 'ARRAY') {
13866: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13867: my $chgtext;
13868: foreach my $type (@{$titleorder}) {
13869: if (grep(/^\Q$type\E$/,@searchby)) {
13870: if (defined($searchtitles->{$type})) {
13871: $chgtext .= $searchtitles->{$type}.'; ';
13872: }
13873: }
13874: }
13875: $chgtext =~ s/\; $//;
13876: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13877: }
13878: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13879: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13880: my $chgtext;
13881: foreach my $type (@{$srchtypeorder}) {
13882: if (grep(/^\Q$type\E$/,@searchtypes)) {
13883: if (defined($srchtypes_desc->{$type})) {
13884: $chgtext .= $srchtypes_desc->{$type}.'; ';
13885: }
13886: }
13887: }
13888: $chgtext =~ s/\; $//;
13889: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
13890: }
13891: $resulttext .= '</ul>';
13892: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13893: if (ref($lastactref) eq 'HASH') {
13894: $lastactref->{'directorysrch'} = 1;
13895: }
13896: } else {
13897: $resulttext = &mt('No changes made to directory search settings');
13898: }
13899: } else {
13900: $resulttext = '<span class="LC_error">'.
13901: &mt('An error occurred: [_1]',$putresult).'</span>';
13902: }
13903: return $resulttext;
13904: }
13905:
13906: sub modify_contacts {
13907: my ($dom,$lastactref,%domconfig) = @_;
13908: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13909: if (ref($domconfig{'contacts'}) eq 'HASH') {
13910: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13911: $currsetting{$key} = $domconfig{'contacts'}{$key};
13912: }
13913: }
13914: my (%others,%to,%bcc,%includestr,%includeloc);
13915: my @contacts = ('supportemail','adminemail');
13916: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
13917: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
13918: my @toggles = ('reporterrors','reportupdates','reportstatus');
13919: my @lonstatus = ('threshold','sysmail','weights','excluded');
13920: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
13921: foreach my $type (@mailings) {
13922: @{$newsetting{$type}} =
13923: &Apache::loncommon::get_env_multiple('form.'.$type);
13924: foreach my $item (@contacts) {
13925: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13926: $contacts_hash{contacts}{$type}{$item} = 1;
13927: } else {
13928: $contacts_hash{contacts}{$type}{$item} = 0;
13929: }
13930: }
13931: $others{$type} = $env{'form.'.$type.'_others'};
13932: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
13933: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
13934: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13935: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
13936: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13937: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13938: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13939: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13940: }
13941: }
13942: }
13943: foreach my $item (@contacts) {
13944: $to{$item} = $env{'form.'.$item};
13945: $contacts_hash{'contacts'}{$item} = $to{$item};
13946: }
13947: foreach my $item (@toggles) {
13948: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13949: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13950: }
13951: }
13952: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13953: foreach my $item (@lonstatus) {
13954: if ($item eq 'excluded') {
13955: my (%serverhomes,@excluded);
13956: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13957: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13958: if (@possexcluded) {
13959: foreach my $id (sort(@possexcluded)) {
13960: if ($serverhomes{$id}) {
13961: push(@excluded,$id);
13962: }
13963: }
13964: }
13965: if (@excluded) {
13966: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13967: }
13968: } elsif ($item eq 'weights') {
13969: foreach my $type ('E','W','N','U') {
13970: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13971: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13972: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13973: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13974: $env{'form.error'.$item.'_'.$type};
13975: }
13976: }
13977: }
13978: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13979: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13980: if ($env{'form.error'.$item} =~ /^\d+$/) {
13981: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13982: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13983: }
13984: }
13985: }
13986: }
13987: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13988: foreach my $field (@{$fields}) {
13989: if (ref($possoptions->{$field}) eq 'ARRAY') {
13990: my $value = $env{'form.helpform_'.$field};
13991: $value =~ s/^\s+|\s+$//g;
13992: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
13993: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
13994: if ($field eq 'screenshot') {
13995: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13996: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
13997: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
13998: }
13999: }
14000: }
14001: }
14002: }
14003: }
14004: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14005: my (@statuses,%usertypeshash,@overrides);
14006: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
14007: @statuses = @{$types};
14008: if (ref($usertypes) eq 'HASH') {
14009: %usertypeshash = %{$usertypes};
14010: }
14011: }
14012: if (@statuses) {
14013: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
14014: foreach my $type (@possoverrides) {
14015: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
14016: push(@overrides,$type);
14017: }
14018: }
14019: if (@overrides) {
14020: foreach my $type (@overrides) {
14021: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
14022: foreach my $item (@contacts) {
14023: if (grep(/^\Q$item\E$/,@standard)) {
14024: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
14025: $newsetting{'override_'.$type}{$item} = 1;
14026: } else {
14027: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
14028: $newsetting{'override_'.$type}{$item} = 0;
14029: }
14030: }
14031: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
14032: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14033: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
14034: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14035: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
14036: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
14037: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
14038: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14039: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
14040: }
14041: }
14042: }
14043: }
14044: if (keys(%currsetting) > 0) {
14045: foreach my $item (@contacts) {
14046: if ($to{$item} ne $currsetting{$item}) {
14047: $changes{$item} = 1;
14048: }
14049: }
14050: foreach my $type (@mailings) {
14051: foreach my $item (@contacts) {
14052: if (ref($currsetting{$type}) eq 'HASH') {
14053: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
14054: push(@{$changes{$type}},$item);
14055: }
14056: } else {
14057: push(@{$changes{$type}},@{$newsetting{$type}});
14058: }
14059: }
14060: if ($others{$type} ne $currsetting{$type}{'others'}) {
14061: push(@{$changes{$type}},'others');
14062: }
14063: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14064: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
14065: push(@{$changes{$type}},'bcc');
14066: }
14067: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
14068: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
14069: push(@{$changes{$type}},'include');
14070: }
14071: }
14072: }
14073: if (ref($fields) eq 'ARRAY') {
14074: if (ref($currsetting{'helpform'}) eq 'HASH') {
14075: foreach my $field (@{$fields}) {
14076: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
14077: push(@{$changes{'helpform'}},$field);
14078: }
14079: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14080: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
14081: push(@{$changes{'helpform'}},'maxsize');
14082: }
14083: }
14084: }
14085: } else {
14086: foreach my $field (@{$fields}) {
14087: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14088: push(@{$changes{'helpform'}},$field);
14089: }
14090: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14091: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14092: push(@{$changes{'helpform'}},'maxsize');
14093: }
14094: }
14095: }
14096: }
14097: }
14098: if (@statuses) {
14099: if (ref($currsetting{'overrides'}) eq 'HASH') {
14100: foreach my $key (keys(%{$currsetting{'overrides'}})) {
14101: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
14102: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
14103: foreach my $item (@contacts,'bcc','others','include') {
14104: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
14105: push(@{$changes{'overrides'}},$key);
14106: last;
14107: }
14108: }
14109: } else {
14110: push(@{$changes{'overrides'}},$key);
14111: }
14112: }
14113: }
14114: foreach my $key (@overrides) {
14115: unless (exists($currsetting{'overrides'}{$key})) {
14116: push(@{$changes{'overrides'}},$key);
14117: }
14118: }
14119: } else {
14120: foreach my $key (@overrides) {
14121: push(@{$changes{'overrides'}},$key);
14122: }
14123: }
14124: }
14125: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
14126: foreach my $key ('excluded','weights','threshold','sysmail') {
14127: if ($key eq 'excluded') {
14128: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14129: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
14130: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14131: (@{$currsetting{'lonstatus'}{$key}})) {
14132: my @diffs =
14133: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
14134: $currsetting{'lonstatus'}{$key});
14135: if (@diffs) {
14136: push(@{$changes{'lonstatus'}},$key);
14137: }
14138: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
14139: push(@{$changes{'lonstatus'}},$key);
14140: }
14141: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14142: (@{$currsetting{'lonstatus'}{$key}})) {
14143: push(@{$changes{'lonstatus'}},$key);
14144: }
14145: } elsif ($key eq 'weights') {
14146: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14147: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
14148: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14149: foreach my $type ('E','W','N','U') {
14150: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
14151: $currsetting{'lonstatus'}{$key}{$type}) {
14152: push(@{$changes{'lonstatus'}},$key);
14153: last;
14154: }
14155: }
14156: } else {
14157: foreach my $type ('E','W','N','U') {
14158: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
14159: push(@{$changes{'lonstatus'}},$key);
14160: last;
14161: }
14162: }
14163: }
14164: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14165: foreach my $type ('E','W','N','U') {
14166: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
14167: push(@{$changes{'lonstatus'}},$key);
14168: last;
14169: }
14170: }
14171: }
14172: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
14173: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14174: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14175: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
14176: push(@{$changes{'lonstatus'}},$key);
14177: }
14178: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
14179: push(@{$changes{'lonstatus'}},$key);
14180: }
14181: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14182: push(@{$changes{'lonstatus'}},$key);
14183: }
14184: }
14185: }
14186: } else {
14187: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14188: foreach my $key ('excluded','weights','threshold','sysmail') {
14189: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14190: push(@{$changes{'lonstatus'}},$key);
14191: }
14192: }
14193: }
14194: }
14195: } else {
14196: my %default;
14197: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
14198: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
14199: $default{'errormail'} = 'adminemail';
14200: $default{'packagesmail'} = 'adminemail';
14201: $default{'helpdeskmail'} = 'supportemail';
14202: $default{'otherdomsmail'} = 'supportemail';
14203: $default{'lonstatusmail'} = 'adminemail';
14204: $default{'requestsmail'} = 'adminemail';
14205: $default{'updatesmail'} = 'adminemail';
14206: $default{'hostipmail'} = 'adminemail';
14207: foreach my $item (@contacts) {
14208: if ($to{$item} ne $default{$item}) {
14209: $changes{$item} = 1;
14210: }
14211: }
14212: foreach my $type (@mailings) {
14213: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
14214: push(@{$changes{$type}},@{$newsetting{$type}});
14215: }
14216: if ($others{$type} ne '') {
14217: push(@{$changes{$type}},'others');
14218: }
14219: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14220: if ($bcc{$type} ne '') {
14221: push(@{$changes{$type}},'bcc');
14222: }
14223: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
14224: push(@{$changes{$type}},'include');
14225: }
14226: }
14227: }
14228: if (ref($fields) eq 'ARRAY') {
14229: foreach my $field (@{$fields}) {
14230: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14231: push(@{$changes{'helpform'}},$field);
14232: }
14233: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14234: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14235: push(@{$changes{'helpform'}},'maxsize');
14236: }
14237: }
14238: }
14239: }
14240: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14241: foreach my $key ('excluded','weights','threshold','sysmail') {
14242: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14243: push(@{$changes{'lonstatus'}},$key);
14244: }
14245: }
14246: }
14247: }
14248: foreach my $item (@toggles) {
14249: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
14250: $changes{$item} = 1;
14251: } elsif ((!$env{'form.'.$item}) &&
14252: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
14253: $changes{$item} = 1;
14254: }
14255: }
14256: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
14257: $dom);
14258: if ($putresult eq 'ok') {
14259: if (keys(%changes) > 0) {
14260: &Apache::loncommon::devalidate_domconfig_cache($dom);
14261: if (ref($lastactref) eq 'HASH') {
14262: $lastactref->{'domainconfig'} = 1;
14263: }
14264: my ($titles,$short_titles) = &contact_titles();
14265: $resulttext = &mt('Changes made:').'<ul>';
14266: foreach my $item (@contacts) {
14267: if ($changes{$item}) {
14268: $resulttext .= '<li>'.$titles->{$item}.
14269: &mt(' set to: ').
14270: '<span class="LC_cusr_emph">'.
14271: $to{$item}.'</span></li>';
14272: }
14273: }
14274: foreach my $type (@mailings) {
14275: if (ref($changes{$type}) eq 'ARRAY') {
14276: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14277: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
14278: } else {
14279: $resulttext .= '<li>'.$titles->{$type}.': ';
14280: }
14281: my @text;
14282: foreach my $item (@{$newsetting{$type}}) {
14283: push(@text,$short_titles->{$item});
14284: }
14285: if ($others{$type} ne '') {
14286: push(@text,$others{$type});
14287: }
14288: if (@text) {
14289: $resulttext .= '<span class="LC_cusr_emph">'.
14290: join(', ',@text).'</span>';
14291: }
14292: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14293: if ($bcc{$type} ne '') {
14294: my $bcctext;
14295: if (@text) {
14296: $bcctext = ' '.&mt('with Bcc to');
14297: } else {
14298: $bcctext = '(Bcc)';
14299: }
14300: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
14301: } elsif (!@text) {
14302: $resulttext .= &mt('No one');
14303: }
14304: if ($includestr{$type} ne '') {
14305: if ($includeloc{$type} eq 'b') {
14306: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
14307: } elsif ($includeloc{$type} eq 's') {
14308: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
14309: }
14310: }
14311: } elsif (!@text) {
14312: $resulttext .= &mt('No recipients');
14313: }
14314: $resulttext .= '</li>';
14315: }
14316: }
14317: if (ref($changes{'overrides'}) eq 'ARRAY') {
14318: my @deletions;
14319: foreach my $type (@{$changes{'overrides'}}) {
14320: if ($usertypeshash{$type}) {
14321: if (grep(/^\Q$type\E/,@overrides)) {
14322: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
14323: $usertypeshash{$type}).'<ul><li>';
14324: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
14325: my @text;
14326: foreach my $item (@contacts) {
14327: if ($newsetting{'override_'.$type}{$item}) {
14328: push(@text,$short_titles->{$item});
14329: }
14330: }
14331: if ($newsetting{'override_'.$type}{'others'} ne '') {
14332: push(@text,$newsetting{'override_'.$type}{'others'});
14333: }
14334:
14335: if (@text) {
14336: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
14337: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
14338: }
14339: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
14340: my $bcctext;
14341: if (@text) {
14342: $bcctext = ' '.&mt('with Bcc to');
14343: } else {
14344: $bcctext = '(Bcc)';
14345: }
14346: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
14347: } elsif (!@text) {
14348: $resulttext .= &mt('Helpdesk e-mail sent to no one');
14349: }
14350: $resulttext .= '</li>';
14351: if ($newsetting{'override_'.$type}{'include'} ne '') {
14352: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
14353: if ($loc eq 'b') {
14354: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
14355: } elsif ($loc eq 's') {
14356: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
14357: }
14358: }
14359: }
14360: $resulttext .= '</li></ul></li>';
14361: } else {
14362: push(@deletions,$usertypeshash{$type});
14363: }
14364: }
14365: }
14366: if (@deletions) {
14367: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
14368: join(', ',@deletions)).'</li>';
14369: }
14370: }
14371: my @offon = ('off','on');
14372: my $corelink = &core_link_msu();
14373: if ($changes{'reporterrors'}) {
14374: $resulttext .= '<li>'.
14375: &mt('E-mail error reports to [_1] set to "'.
14376: $offon[$env{'form.reporterrors'}].'".',
14377: $corelink).
14378: '</li>';
14379: }
14380: if ($changes{'reportupdates'}) {
14381: $resulttext .= '<li>'.
14382: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
14383: $offon[$env{'form.reportupdates'}].'".',
14384: $corelink).
14385: '</li>';
14386: }
14387: if ($changes{'reportstatus'}) {
14388: $resulttext .= '<li>'.
14389: &mt('E-mail status if errors above threshold to [_1] set to "'.
14390: $offon[$env{'form.reportstatus'}].'".',
14391: $corelink).
14392: '</li>';
14393: }
14394: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
14395: $resulttext .= '<li>'.
14396: &mt('Nightly status check e-mail settings').':<ul>';
14397: my (%defval,%use_def,%shown);
14398: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
14399: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
14400: $defval{'weights'} =
14401: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
14402: $defval{'excluded'} = &mt('None');
14403: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
14404: foreach my $item ('threshold','sysmail','weights','excluded') {
14405: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
14406: if (($item eq 'threshold') || ($item eq 'sysmail')) {
14407: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
14408: } elsif ($item eq 'weights') {
14409: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
14410: foreach my $type ('E','W','N','U') {
14411: $shown{$item} .= $lonstatus_names->{$type}.'=';
14412: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
14413: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
14414: } else {
14415: $shown{$item} .= $lonstatus_defs->{$type};
14416: }
14417: $shown{$item} .= ', ';
14418: }
14419: $shown{$item} =~ s/, $//;
14420: } else {
14421: $shown{$item} = $defval{$item};
14422: }
14423: } elsif ($item eq 'excluded') {
14424: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
14425: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
14426: } else {
14427: $shown{$item} = $defval{$item};
14428: }
14429: }
14430: } else {
14431: $shown{$item} = $defval{$item};
14432: }
14433: }
14434: } else {
14435: foreach my $item ('threshold','weights','excluded','sysmail') {
14436: $shown{$item} = $defval{$item};
14437: }
14438: }
14439: foreach my $item ('threshold','weights','excluded','sysmail') {
14440: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
14441: $shown{$item}).'</li>';
14442: }
14443: $resulttext .= '</ul></li>';
14444: }
14445: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
14446: my (@optional,@required,@unused,$maxsizechg);
14447: foreach my $field (@{$changes{'helpform'}}) {
14448: if ($field eq 'maxsize') {
14449: $maxsizechg = 1;
14450: next;
14451: }
14452: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
14453: push(@optional,$field);
14454: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
14455: push(@unused,$field);
14456: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
14457: push(@required,$field);
14458: }
14459: }
14460: if (@optional) {
14461: $resulttext .= '<li>'.
14462: &mt('Help form fields changed to "Optional": [_1].',
14463: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
14464: '</li>';
14465: }
14466: if (@required) {
14467: $resulttext .= '<li>'.
14468: &mt('Help form fields changed to "Required": [_1].',
14469: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
14470: '</li>';
14471: }
14472: if (@unused) {
14473: $resulttext .= '<li>'.
14474: &mt('Help form fields changed to "Not shown": [_1].',
14475: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
14476: '</li>';
14477: }
14478: if ($maxsizechg) {
14479: $resulttext .= '<li>'.
14480: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
14481: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
14482: '</li>';
14483: }
14484: }
14485: $resulttext .= '</ul>';
14486: } else {
14487: $resulttext = &mt('No changes made to contacts and form settings');
14488: }
14489: } else {
14490: $resulttext = '<span class="LC_error">'.
14491: &mt('An error occurred: [_1].',$putresult).'</span>';
14492: }
14493: return $resulttext;
14494: }
14495:
14496: sub modify_passwords {
14497: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
14498: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
14499: $updatedefaults,$updateconf);
14500: my $customfn = 'resetpw.html';
14501: if (ref($domconfig{'passwords'}) eq 'HASH') {
14502: %current = %{$domconfig{'passwords'}};
14503: }
14504: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14505: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14506: if (ref($types) eq 'ARRAY') {
14507: @oktypes = @{$types};
14508: }
14509: push(@oktypes,'default');
14510:
14511: my %titles = &Apache::lonlocal::texthash (
14512: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
14513: intauth_check => 'Check bcrypt cost if authenticated',
14514: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
14515: permanent => 'Permanent e-mail address',
14516: critical => 'Critical notification address',
14517: notify => 'Notification address',
14518: min => 'Minimum password length',
14519: max => 'Maximum password length',
14520: chars => 'Required characters',
14521: numsaved => 'Number of previous passwords to save',
14522: reset => 'Resetting Forgotten Password',
14523: intauth => 'Encryption of Stored Passwords (Internal Auth)',
14524: rules => 'Rules for LON-CAPA Passwords',
14525: crsownerchg => 'Course Owner Changing Student Passwords',
14526: username => 'Username',
14527: email => 'E-mail address',
14528: );
14529:
14530: #
14531: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
14532: #
14533: my (%curr_defaults,%save_defaults);
14534: if (ref($domconfig{'defaults'}) eq 'HASH') {
14535: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14536: if ($key =~ /^intauth_(cost|check|switch)$/) {
14537: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14538: } else {
14539: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14540: }
14541: }
14542: }
14543: my %staticdefaults = (
14544: 'resetlink' => 2,
14545: 'resetcase' => \@oktypes,
14546: 'resetprelink' => 'both',
14547: 'resetemail' => ['critical','notify','permanent'],
14548: 'intauth_cost' => 10,
14549: 'intauth_check' => 0,
14550: 'intauth_switch' => 0,
14551: );
14552: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
14553: foreach my $type (@oktypes) {
14554: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14555: }
14556: my $linklife = $env{'form.passwords_link'};
14557: $linklife =~ s/^\s+|\s+$//g;
14558: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14559: $newvalues{'resetlink'} = $linklife;
14560: if ($current{'resetlink'}) {
14561: if ($current{'resetlink'} ne $linklife) {
14562: $changes{'reset'} = 1;
14563: }
14564: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
14565: if ($staticdefaults{'resetlink'} ne $linklife) {
14566: $changes{'reset'} = 1;
14567: }
14568: }
14569: } elsif ($current{'resetlink'}) {
14570: $changes{'reset'} = 1;
14571: }
14572: my @casesens;
14573: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14574: foreach my $case (sort(@posscase)) {
14575: if (grep(/^\Q$case\E$/,@oktypes)) {
14576: push(@casesens,$case);
14577: }
14578: }
14579: $newvalues{'resetcase'} = \@casesens;
14580: if (ref($current{'resetcase'}) eq 'ARRAY') {
14581: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14582: if (@diffs > 0) {
14583: $changes{'reset'} = 1;
14584: }
14585: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
14586: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14587: if (@diffs > 0) {
14588: $changes{'reset'} = 1;
14589: }
14590: }
14591: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14592: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14593: if (exists($current{'resetprelink'})) {
14594: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14595: $changes{'reset'} = 1;
14596: }
14597: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
14598: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14599: $changes{'reset'} = 1;
14600: }
14601: }
14602: } elsif ($current{'resetprelink'}) {
14603: $changes{'reset'} = 1;
14604: }
14605: foreach my $type (@oktypes) {
14606: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14607: my @postlink;
14608: foreach my $item (sort(@possplink)) {
14609: if ($item =~ /^(email|username)$/) {
14610: push(@postlink,$item);
14611: }
14612: }
14613: $newvalues{'resetpostlink'}{$type} = \@postlink;
14614: unless ($changes{'reset'}) {
14615: if (ref($current{'resetpostlink'}) eq 'HASH') {
14616: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14617: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14618: if (@diffs > 0) {
14619: $changes{'reset'} = 1;
14620: }
14621: } else {
14622: $changes{'reset'} = 1;
14623: }
14624: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
14625: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14626: if (@diffs > 0) {
14627: $changes{'reset'} = 1;
14628: }
14629: }
14630: }
14631: }
14632: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14633: my @resetemail;
14634: foreach my $item (sort(@possemailsrc)) {
14635: if ($item =~ /^(permanent|critical|notify)$/) {
14636: push(@resetemail,$item);
14637: }
14638: }
14639: $newvalues{'resetemail'} = \@resetemail;
14640: unless ($changes{'reset'}) {
14641: if (ref($current{'resetemail'}) eq 'ARRAY') {
14642: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14643: if (@diffs > 0) {
14644: $changes{'reset'} = 1;
14645: }
14646: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
14647: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14648: if (@diffs > 0) {
14649: $changes{'reset'} = 1;
14650: }
14651: }
14652: }
14653: if ($env{'form.passwords_stdtext'} == 0) {
14654: $newvalues{'resetremove'} = 1;
14655: unless ($current{'resetremove'}) {
14656: $changes{'reset'} = 1;
14657: }
14658: } elsif ($current{'resetremove'}) {
14659: $changes{'reset'} = 1;
14660: }
14661: if ($env{'form.passwords_customfile.filename'} ne '') {
14662: my $servadm = $r->dir_config('lonAdmEMail');
14663: my $servadm = $r->dir_config('lonAdmEMail');
14664: my ($configuserok,$author_ok,$switchserver) =
14665: &config_check($dom,$confname,$servadm);
14666: my $error;
14667: if ($configuserok eq 'ok') {
14668: if ($switchserver) {
14669: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14670: } else {
14671: if ($author_ok eq 'ok') {
14672: my ($result,$customurl) =
14673: &publishlogo($r,'upload','passwords_customfile',$dom,
14674: $confname,'customtext/resetpw','','',$customfn);
14675: if ($result eq 'ok') {
14676: $newvalues{'resetcustom'} = $customurl;
14677: $changes{'reset'} = 1;
14678: } else {
14679: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14680: }
14681: } else {
14682: $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);
14683: }
14684: }
14685: } else {
14686: $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);
14687: }
14688: if ($error) {
14689: &Apache::lonnet::logthis($error);
14690: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14691: }
14692: } elsif ($current{'resetcustom'}) {
14693: if ($env{'form.passwords_custom_del'}) {
14694: $changes{'reset'} = 1;
14695: } else {
14696: $newvalues{'resetcustom'} = $current{'resetcustom'};
14697: }
14698: }
14699: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14700: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14701: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14702: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14703: $changes{'intauth'} = 1;
14704: }
14705: } else {
14706: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14707: }
14708: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14709: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14710: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14711: $changes{'intauth'} = 1;
14712: }
14713: } else {
14714: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14715: }
14716: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14717: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14718: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14719: $changes{'intauth'} = 1;
14720: }
14721: } else {
14722: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14723: }
14724: foreach my $item ('cost','check','switch') {
14725: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14726: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14727: $updatedefaults = 1;
14728: }
14729: }
14730: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
14731: my %crsownerchg = (
14732: by => [],
14733: for => [],
14734: );
14735: foreach my $item ('by','for') {
14736: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
14737: foreach my $type (sort(@posstypes)) {
14738: if (grep(/^\Q$type\E$/,@oktypes)) {
14739: push(@{$crsownerchg{$item}},$type);
14740: }
14741: }
14742: }
14743: $newvalues{'crsownerchg'} = \%crsownerchg;
14744: if (ref($current{'crsownerchg'}) eq 'HASH') {
14745: foreach my $item ('by','for') {
14746: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
14747: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
14748: if (@diffs > 0) {
14749: $changes{'crsownerchg'} = 1;
14750: last;
14751: }
14752: }
14753: }
14754: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
14755: foreach my $item ('by','for') {
14756: if (@{$crsownerchg{$item}} > 0) {
14757: $changes{'crsownerchg'} = 1;
14758: last;
14759: }
14760: }
14761: }
14762:
14763: my %confighash = (
14764: defaults => \%save_defaults,
14765: passwords => \%newvalues,
14766: );
14767: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14768:
14769: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14770: if ($putresult eq 'ok') {
14771: if (keys(%changes) > 0) {
14772: $resulttext = &mt('Changes made: ').'<ul>';
14773: foreach my $key ('reset','intauth','rules','crsownerchg') {
14774: if ($changes{$key}) {
14775: unless ($key eq 'intauth') {
14776: $updateconf = 1;
14777: }
14778: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14779: if ($key eq 'reset') {
14780: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14781: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14782: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14783: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
14784: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
14785: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
14786: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
14787: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
14788: }
14789: } else {
14790: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14791: }
14792: if ($confighash{'passwords'}{'resetlink'}) {
14793: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14794: } else {
14795: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14796: &mt('Will default to 2 hours').'</li>';
14797: }
14798: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14799: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14800: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14801: } else {
14802: my $casesens;
14803: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14804: if ($type eq 'default') {
14805: $casesens .= $othertitle.', ';
14806: } elsif ($usertypes->{$type} ne '') {
14807: $casesens .= $usertypes->{$type}.', ';
14808: }
14809: }
14810: $casesens =~ s/\Q, \E$//;
14811: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14812: }
14813: } else {
14814: $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>';
14815: }
14816: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14817: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14818: } else {
14819: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14820: }
14821: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14822: my $output;
14823: if (ref($types) eq 'ARRAY') {
14824: foreach my $type (@{$types}) {
14825: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14826: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14827: $output .= $usertypes->{$type}.' -- '.&mt('none');
14828: } else {
14829: $output .= $usertypes->{$type}.' -- '.
14830: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14831: }
14832: }
14833: }
14834: }
14835: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14836: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14837: $output .= $othertitle.' -- '.&mt('none');
14838: } else {
14839: $output .= $othertitle.' -- '.
14840: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14841: }
14842: }
14843: if ($output) {
14844: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14845: } else {
14846: $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>';
14847: }
14848: } else {
14849: $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>';
14850: }
14851: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14852: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14853: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14854: } else {
14855: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14856: }
14857: } else {
14858: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14859: }
14860: if ($confighash{'passwords'}{'resetremove'}) {
14861: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14862: } else {
14863: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14864: }
14865: if ($confighash{'passwords'}{'resetcustom'}) {
14866: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
14867: &mt('custom text'),600,500,undef,undef,
14868: undef,undef,'background-color:#ffffff');
14869: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
14870: } else {
14871: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14872: }
14873: } elsif ($key eq 'intauth') {
14874: foreach my $item ('cost','switch','check') {
14875: my $value = $save_defaults{$key.'_'.$item};
14876: if ($item eq 'switch') {
14877: my %optiondesc = &Apache::lonlocal::texthash (
14878: 0 => 'No',
14879: 1 => 'Yes',
14880: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14881: );
14882: if ($value =~ /^(0|1|2)$/) {
14883: $value = $optiondesc{$value};
14884: } else {
14885: $value = &mt('none -- defaults to No');
14886: }
14887: } elsif ($item eq 'check') {
14888: my %optiondesc = &Apache::lonlocal::texthash (
14889: 0 => 'No',
14890: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14891: 2 => 'Yes, disallow login if stored cost is less than domain default',
14892: );
14893: if ($value =~ /^(0|1|2)$/) {
14894: $value = $optiondesc{$value};
14895: } else {
14896: $value = &mt('none -- defaults to No');
14897: }
14898: }
14899: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14900: }
14901: } elsif ($key eq 'rules') {
14902: foreach my $rule ('min','max','numsaved') {
14903: if ($confighash{'passwords'}{$rule} eq '') {
14904: if ($rule eq 'min') {
14905: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
14906: ' '.&mt('Default of [_1] will be used',
14907: $Apache::lonnet::passwdmin).'</li>';
14908: } else {
14909: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
14910: }
14911: } else {
14912: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14913: }
14914: }
14915: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
14916: if (@{$confighash{'passwords'}{'chars'}} > 0) {
14917: my %rulenames = &Apache::lonlocal::texthash(
14918: uc => 'At least one upper case letter',
14919: lc => 'At least one lower case letter',
14920: num => 'At least one number',
14921: spec => 'At least one non-alphanumeric',
14922: );
14923: my $needed = '<ul><li>'.
14924: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
14925: '</li></ul>';
14926: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
14927: } else {
14928: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14929: }
14930: } else {
14931: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14932: }
14933: } elsif ($key eq 'crsownerchg') {
14934: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
14935: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
14936: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
14937: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14938: } else {
14939: my %crsownerstr;
14940: foreach my $item ('by','for') {
14941: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
14942: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
14943: if ($type eq 'default') {
14944: $crsownerstr{$item} .= $othertitle.', ';
14945: } elsif ($usertypes->{$type} ne '') {
14946: $crsownerstr{$item} .= $usertypes->{$type}.', ';
14947: }
14948: }
14949: $crsownerstr{$item} =~ s/\Q, \E$//;
14950: }
14951: }
14952: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
14953: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
14954: }
14955: } else {
14956: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14957: }
14958: }
14959: $resulttext .= '</ul></li>';
14960: }
14961: }
14962: $resulttext .= '</ul>';
14963: } else {
14964: $resulttext = &mt('No changes made to password settings');
14965: }
14966: my $cachetime = 24*60*60;
14967: if ($updatedefaults) {
14968: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14969: if (ref($lastactref) eq 'HASH') {
14970: $lastactref->{'domdefaults'} = 1;
14971: }
14972: }
14973: if ($updateconf) {
14974: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
14975: if (ref($lastactref) eq 'HASH') {
14976: $lastactref->{'passwdconf'} = 1;
14977: }
14978: }
14979: } else {
14980: $resulttext = '<span class="LC_error">'.
14981: &mt('An error occurred: [_1]',$putresult).'</span>';
14982: }
14983: if ($errors) {
14984: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14985: $errors.'</ul></p>';
14986: }
14987: return $resulttext;
14988: }
14989:
14990: sub password_rule_changes {
14991: my ($prefix,$newvalues,$current,$changes) = @_;
14992: return unless ((ref($newvalues) eq 'HASH') &&
14993: (ref($current) eq 'HASH') &&
14994: (ref($changes) eq 'HASH'));
14995: my (@rules,%staticdefaults);
14996: if ($prefix eq 'passwords') {
14997: @rules = ('min','max','numsaved');
14998: } elsif ($prefix eq 'secrets') {
14999: @rules = ('min','max');
15000: }
15001: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
15002: foreach my $rule (@rules) {
15003: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
15004: my $ruleok;
15005: if ($rule eq 'min') {
15006: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
15007: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
15008: $ruleok = 1;
15009: }
15010: }
15011: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
15012: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
15013: $ruleok = 1;
15014: }
15015: if ($ruleok) {
15016: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
15017: if (exists($current->{$rule})) {
15018: if ($newvalues->{$rule} ne $current->{$rule}) {
15019: $changes->{'rules'} = 1;
15020: }
15021: } elsif ($rule eq 'min') {
15022: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
15023: $changes->{'rules'} = 1;
15024: }
15025: } else {
15026: $changes->{'rules'} = 1;
15027: }
15028: } elsif (exists($current->{$rule})) {
15029: $changes->{'rules'} = 1;
15030: }
15031: }
15032: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
15033: my @chars;
15034: foreach my $item (sort(@posschars)) {
15035: if ($item =~ /^(uc|lc|num|spec)$/) {
15036: push(@chars,$item);
15037: }
15038: }
15039: $newvalues->{'chars'} = \@chars;
15040: unless ($changes->{'rules'}) {
15041: if (ref($current->{'chars'}) eq 'ARRAY') {
15042: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
15043: if (@diffs > 0) {
15044: $changes->{'rules'} = 1;
15045: }
15046: } else {
15047: if (@chars > 0) {
15048: $changes->{'rules'} = 1;
15049: }
15050: }
15051: }
15052: return;
15053: }
15054:
15055: sub modify_usercreation {
15056: my ($dom,%domconfig) = @_;
15057: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
15058: my $warningmsg;
15059: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15060: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15061: if ($key eq 'cancreate') {
15062: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15063: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15064: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
15065: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15066: } else {
15067: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15068: }
15069: }
15070: }
15071: } elsif ($key eq 'email_rule') {
15072: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15073: } else {
15074: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15075: }
15076: }
15077: }
15078: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
15079: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
15080: my @contexts = ('author','course','requestcrs');
15081: foreach my $item(@contexts) {
15082: $cancreate{$item} = $env{'form.can_createuser_'.$item};
15083: }
15084: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15085: foreach my $item (@contexts) {
15086: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
15087: push(@{$changes{'cancreate'}},$item);
15088: }
15089: }
15090: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
15091: foreach my $item (@contexts) {
15092: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
15093: if ($cancreate{$item} ne 'any') {
15094: push(@{$changes{'cancreate'}},$item);
15095: }
15096: } else {
15097: if ($cancreate{$item} ne 'none') {
15098: push(@{$changes{'cancreate'}},$item);
15099: }
15100: }
15101: }
15102: } else {
15103: foreach my $item (@contexts) {
15104: push(@{$changes{'cancreate'}},$item);
15105: }
15106: }
15107:
15108: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
15109: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
15110: if (!grep(/^\Q$type\E$/,@username_rule)) {
15111: push(@{$changes{'username_rule'}},$type);
15112: }
15113: }
15114: foreach my $type (@username_rule) {
15115: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
15116: push(@{$changes{'username_rule'}},$type);
15117: }
15118: }
15119: } else {
15120: push(@{$changes{'username_rule'}},@username_rule);
15121: }
15122:
15123: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
15124: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
15125: if (!grep(/^\Q$type\E$/,@id_rule)) {
15126: push(@{$changes{'id_rule'}},$type);
15127: }
15128: }
15129: foreach my $type (@id_rule) {
15130: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
15131: push(@{$changes{'id_rule'}},$type);
15132: }
15133: }
15134: } else {
15135: push(@{$changes{'id_rule'}},@id_rule);
15136: }
15137:
15138: my @authen_contexts = ('author','course','domain');
15139: my @authtypes = ('int','krb4','krb5','loc');
15140: my %authhash;
15141: foreach my $item (@authen_contexts) {
15142: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
15143: foreach my $auth (@authtypes) {
15144: if (grep(/^\Q$auth\E$/,@authallowed)) {
15145: $authhash{$item}{$auth} = 1;
15146: } else {
15147: $authhash{$item}{$auth} = 0;
15148: }
15149: }
15150: }
15151: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
15152: foreach my $item (@authen_contexts) {
15153: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
15154: foreach my $auth (@authtypes) {
15155: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15156: push(@{$changes{'authtypes'}},$item);
15157: last;
15158: }
15159: }
15160: }
15161: }
15162: } else {
15163: foreach my $item (@authen_contexts) {
15164: push(@{$changes{'authtypes'}},$item);
15165: }
15166: }
15167:
15168: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15169: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15170: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15171: $save_usercreate{'id_rule'} = \@id_rule;
15172: $save_usercreate{'username_rule'} = \@username_rule,
15173: $save_usercreate{'authtypes'} = \%authhash;
15174:
15175: my %usercreation_hash = (
15176: usercreation => \%save_usercreate,
15177: );
15178:
15179: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15180: $dom);
15181:
15182: if ($putresult eq 'ok') {
15183: if (keys(%changes) > 0) {
15184: $resulttext = &mt('Changes made:').'<ul>';
15185: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15186: my %lt = &usercreation_types();
15187: foreach my $type (@{$changes{'cancreate'}}) {
15188: my $chgtext = $lt{$type}.', ';
15189: if ($cancreate{$type} eq 'none') {
15190: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15191: } elsif ($cancreate{$type} eq 'any') {
15192: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15193: } elsif ($cancreate{$type} eq 'official') {
15194: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15195: } elsif ($cancreate{$type} eq 'unofficial') {
15196: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15197: }
15198: $resulttext .= '<li>'.$chgtext.'</li>';
15199: }
15200: }
15201: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15202: my ($rules,$ruleorder) =
15203: &Apache::lonnet::inst_userrules($dom,'username');
15204: my $chgtext = '<ul>';
15205: foreach my $type (@username_rule) {
15206: if (ref($rules->{$type}) eq 'HASH') {
15207: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15208: }
15209: }
15210: $chgtext .= '</ul>';
15211: if (@username_rule > 0) {
15212: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15213: } else {
15214: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15215: }
15216: }
15217: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15218: my ($idrules,$idruleorder) =
15219: &Apache::lonnet::inst_userrules($dom,'id');
15220: my $chgtext = '<ul>';
15221: foreach my $type (@id_rule) {
15222: if (ref($idrules->{$type}) eq 'HASH') {
15223: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15224: }
15225: }
15226: $chgtext .= '</ul>';
15227: if (@id_rule > 0) {
15228: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15229: } else {
15230: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
15231: }
15232: }
15233: my %authname = &authtype_names();
15234: my %context_title = &context_names();
15235: if (ref($changes{'authtypes'}) eq 'ARRAY') {
15236: my $chgtext = '<ul>';
15237: foreach my $type (@{$changes{'authtypes'}}) {
15238: my @allowed;
15239: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
15240: foreach my $auth (@authtypes) {
15241: if ($authhash{$type}{$auth}) {
15242: push(@allowed,$authname{$auth});
15243: }
15244: }
15245: if (@allowed > 0) {
15246: $chgtext .= join(', ',@allowed).'</li>';
15247: } else {
15248: $chgtext .= &mt('none').'</li>';
15249: }
15250: }
15251: $chgtext .= '</ul>';
15252: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
15253: $resulttext .= '</li>';
15254: }
15255: $resulttext .= '</ul>';
15256: } else {
15257: $resulttext = &mt('No changes made to user creation settings');
15258: }
15259: } else {
15260: $resulttext = '<span class="LC_error">'.
15261: &mt('An error occurred: [_1]',$putresult).'</span>';
15262: }
15263: if ($warningmsg ne '') {
15264: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15265: }
15266: return $resulttext;
15267: }
15268:
15269: sub modify_selfcreation {
15270: my ($dom,$lastactref,%domconfig) = @_;
15271: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
15272: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
15273: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15274: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
15275: if (ref($typesref) eq 'ARRAY') {
15276: @types = @{$typesref};
15277: }
15278: if (ref($usertypesref) eq 'HASH') {
15279: %usertypes = %{$usertypesref};
15280: }
15281: $usertypes{'default'} = $othertitle;
15282: #
15283: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
15284: #
15285: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15286: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15287: if ($key eq 'cancreate') {
15288: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15289: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15290: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
15291: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
15292: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
15293: ($item eq 'emailusername') || ($item eq 'shibenv') ||
15294: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
15295: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
15296: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15297: } else {
15298: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15299: }
15300: }
15301: }
15302: } elsif ($key eq 'email_rule') {
15303: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15304: } else {
15305: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15306: }
15307: }
15308: }
15309: #
15310: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
15311: #
15312: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15313: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
15314: if ($key eq 'selfcreate') {
15315: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
15316: } else {
15317: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
15318: }
15319: }
15320: }
15321: #
15322: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
15323: #
15324: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15325: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
15326: if ($key eq 'inststatusguest') {
15327: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
15328: } else {
15329: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
15330: }
15331: }
15332: }
15333:
15334: my @contexts = ('selfcreate');
15335: @{$cancreate{'selfcreate'}} = ();
15336: %{$cancreate{'emailusername'}} = ();
15337: if (@types) {
15338: @{$cancreate{'statustocreate'}} = ();
15339: }
15340: %{$cancreate{'selfcreateprocessing'}} = ();
15341: %{$cancreate{'shibenv'}} = ();
15342: %{$cancreate{'emailverified'}} = ();
15343: %{$cancreate{'emailoptions'}} = ();
15344: %{$cancreate{'emaildomain'}} = ();
15345: my %selfcreatetypes = (
15346: sso => 'users authenticated by institutional single sign on',
15347: login => 'users authenticated by institutional log-in',
15348: email => 'users verified by e-mail',
15349: );
15350: #
15351: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
15352: # is permitted.
15353: #
15354:
15355: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
15356:
15357: my (@statuses,%email_rule);
15358: foreach my $item ('login','sso','email') {
15359: if ($item eq 'email') {
15360: if ($env{'form.cancreate_email'}) {
15361: if (@types) {
15362: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
15363: foreach my $status (@poss_statuses) {
15364: if (grep(/^\Q$status\E$/,(@types,'default'))) {
15365: push(@statuses,$status);
15366: }
15367: }
15368: $save_inststatus{'inststatusguest'} = \@statuses;
15369: } else {
15370: push(@statuses,'default');
15371: }
15372: if (@statuses) {
15373: my %curr_rule;
15374: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
15375: foreach my $type (@statuses) {
15376: $curr_rule{$type} = $curr_usercreation{'email_rule'};
15377: }
15378: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
15379: foreach my $type (@statuses) {
15380: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
15381: }
15382: }
15383: push(@{$cancreate{'selfcreate'}},'email');
15384: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
15385: my %curremaildom;
15386: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
15387: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
15388: }
15389: foreach my $type (@statuses) {
15390: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
15391: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
15392: }
15393: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
15394: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
15395: }
15396: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
15397: #
15398: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
15399: #
15400: my $chosen = $1;
15401: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
15402: my $emaildom;
15403: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
15404: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
15405: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
15406: if (ref($curremaildom{$type}) eq 'HASH') {
15407: if (exists($curremaildom{$type}{$chosen})) {
15408: if ($curremaildom{$type}{$chosen} ne $emaildom) {
15409: push(@{$changes{'cancreate'}},'emaildomain');
15410: }
15411: } elsif ($emaildom ne '') {
15412: push(@{$changes{'cancreate'}},'emaildomain');
15413: }
15414: } elsif ($emaildom ne '') {
15415: push(@{$changes{'cancreate'}},'emaildomain');
15416: }
15417: }
15418: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15419: } elsif ($chosen eq 'custom') {
15420: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
15421: $email_rule{$type} = [];
15422: if (ref($emailrules) eq 'HASH') {
15423: foreach my $rule (@possemail_rules) {
15424: if (exists($emailrules->{$rule})) {
15425: push(@{$email_rule{$type}},$rule);
15426: }
15427: }
15428: }
15429: if (@{$email_rule{$type}}) {
15430: $cancreate{'emailoptions'}{$type} = 'custom';
15431: if (ref($curr_rule{$type}) eq 'ARRAY') {
15432: if (@{$curr_rule{$type}} > 0) {
15433: foreach my $rule (@{$curr_rule{$type}}) {
15434: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
15435: push(@{$changes{'email_rule'}},$type);
15436: }
15437: }
15438: }
15439: foreach my $type (@{$email_rule{$type}}) {
15440: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
15441: push(@{$changes{'email_rule'}},$type);
15442: }
15443: }
15444: } else {
15445: push(@{$changes{'email_rule'}},$type);
15446: }
15447: }
15448: } else {
15449: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15450: }
15451: }
15452: }
15453: if (@types) {
15454: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15455: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
15456: if (@changed) {
15457: push(@{$changes{'inststatus'}},'inststatusguest');
15458: }
15459: } else {
15460: push(@{$changes{'inststatus'}},'inststatusguest');
15461: }
15462: }
15463: } else {
15464: delete($env{'form.cancreate_email'});
15465: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15466: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15467: push(@{$changes{'inststatus'}},'inststatusguest');
15468: }
15469: }
15470: }
15471: } else {
15472: $save_inststatus{'inststatusguest'} = [];
15473: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15474: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15475: push(@{$changes{'inststatus'}},'inststatusguest');
15476: }
15477: }
15478: }
15479: } else {
15480: if ($env{'form.cancreate_'.$item}) {
15481: push(@{$cancreate{'selfcreate'}},$item);
15482: }
15483: }
15484: }
15485: my (%userinfo,%savecaptcha);
15486: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
15487: #
15488: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
15489: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
15490: #
15491:
15492: if ($env{'form.cancreate_email'}) {
15493: push(@contexts,'emailusername');
15494: if (@statuses) {
15495: foreach my $type (@statuses) {
15496: if (ref($infofields) eq 'ARRAY') {
15497: foreach my $field (@{$infofields}) {
15498: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
15499: $cancreate{'emailusername'}{$type}{$field} = $1;
15500: }
15501: }
15502: }
15503: }
15504: }
15505: #
15506: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
15507: # queued requests for self-creation of account verified by e-mail.
15508: #
15509:
15510: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
15511: @approvalnotify = sort(@approvalnotify);
15512: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
15513: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15514: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
15515: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
15516: push(@{$changes{'cancreate'}},'notify');
15517: }
15518: } else {
15519: if ($cancreate{'notify'}{'approval'}) {
15520: push(@{$changes{'cancreate'}},'notify');
15521: }
15522: }
15523: } elsif ($cancreate{'notify'}{'approval'}) {
15524: push(@{$changes{'cancreate'}},'notify');
15525: }
15526:
15527: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
15528: }
15529: #
15530: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
15531: # institutional log-in.
15532: #
15533: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
15534: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
15535: ($domdefaults{'auth_def'} eq 'localauth'))) {
15536: $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.').' '.
15537: &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.');
15538: }
15539: }
15540: my @fields = ('lastname','firstname','middlename','generation',
15541: 'permanentemail','id');
15542: my @shibfields = (@fields,'inststatus');
15543: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15544: #
15545: # Where usernames may created for institutional log-in and/or institutional single sign on:
15546: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
15547: # may self-create accounts
15548: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
15549: # which the user may supply, if institutional data is unavailable.
15550: #
15551: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
15552: if (@types) {
15553: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
15554: push(@contexts,'statustocreate');
15555: foreach my $type (@types) {
15556: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
15557: foreach my $field (@fields) {
15558: if (grep(/^\Q$field\E$/,@modifiable)) {
15559: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
15560: } else {
15561: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
15562: }
15563: }
15564: }
15565: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
15566: foreach my $type (@types) {
15567: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
15568: foreach my $field (@fields) {
15569: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
15570: $curr_usermodify{'selfcreate'}{$type}{$field}) {
15571: push(@{$changes{'selfcreate'}},$type);
15572: last;
15573: }
15574: }
15575: }
15576: }
15577: } else {
15578: foreach my $type (@types) {
15579: push(@{$changes{'selfcreate'}},$type);
15580: }
15581: }
15582: }
15583: foreach my $field (@shibfields) {
15584: if ($env{'form.shibenv_'.$field} ne '') {
15585: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
15586: }
15587: }
15588: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15589: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
15590: foreach my $field (@shibfields) {
15591: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
15592: push(@{$changes{'cancreate'}},'shibenv');
15593: }
15594: }
15595: } else {
15596: foreach my $field (@shibfields) {
15597: if ($env{'form.shibenv_'.$field}) {
15598: push(@{$changes{'cancreate'}},'shibenv');
15599: last;
15600: }
15601: }
15602: }
15603: }
15604: }
15605: foreach my $item (@contexts) {
15606: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
15607: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
15608: if (ref($cancreate{$item}) eq 'ARRAY') {
15609: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
15610: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15611: push(@{$changes{'cancreate'}},$item);
15612: }
15613: }
15614: }
15615: }
15616: if (ref($cancreate{$item}) eq 'ARRAY') {
15617: foreach my $type (@{$cancreate{$item}}) {
15618: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
15619: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15620: push(@{$changes{'cancreate'}},$item);
15621: }
15622: }
15623: }
15624: }
15625: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
15626: if (ref($cancreate{$item}) eq 'HASH') {
15627: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
15628: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15629: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
15630: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
15631: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15632: push(@{$changes{'cancreate'}},$item);
15633: }
15634: }
15635: }
15636: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15637: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
15638: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15639: push(@{$changes{'cancreate'}},$item);
15640: }
15641: }
15642: }
15643: }
15644: foreach my $type (keys(%{$cancreate{$item}})) {
15645: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15646: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15647: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15648: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
15649: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15650: push(@{$changes{'cancreate'}},$item);
15651: }
15652: }
15653: } else {
15654: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15655: push(@{$changes{'cancreate'}},$item);
15656: }
15657: }
15658: }
15659: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15660: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
15661: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15662: push(@{$changes{'cancreate'}},$item);
15663: }
15664: }
15665: }
15666: }
15667: }
15668: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15669: if (ref($cancreate{$item}) eq 'ARRAY') {
15670: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15671: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15672: push(@{$changes{'cancreate'}},$item);
15673: }
15674: }
15675: }
15676: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15677: if (ref($cancreate{$item}) eq 'HASH') {
15678: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15679: push(@{$changes{'cancreate'}},$item);
15680: }
15681: }
15682: } elsif ($item eq 'emailusername') {
15683: if (ref($cancreate{$item}) eq 'HASH') {
15684: foreach my $type (keys(%{$cancreate{$item}})) {
15685: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15686: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15687: if ($cancreate{$item}{$type}{$field}) {
15688: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15689: push(@{$changes{'cancreate'}},$item);
15690: }
15691: last;
15692: }
15693: }
15694: }
15695: }
15696: }
15697: }
15698: }
15699: #
15700: # Populate %save_usercreate hash with updates to self-creation configuration.
15701: #
15702: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15703: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
15704: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
15705: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15706: if (ref($cancreate{'notify'}) eq 'HASH') {
15707: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15708: }
15709: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15710: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15711: }
15712: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15713: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15714: }
15715: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15716: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15717: }
15718: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15719: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15720: }
15721: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15722: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15723: }
15724: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15725: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15726: }
15727: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
15728: $save_usercreate{'email_rule'} = \%email_rule;
15729:
15730: my %userconfig_hash = (
15731: usercreation => \%save_usercreate,
15732: usermodification => \%save_usermodify,
15733: inststatus => \%save_inststatus,
15734: );
15735:
15736: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15737: $dom);
15738: #
15739: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
15740: #
15741: if ($putresult eq 'ok') {
15742: if (keys(%changes) > 0) {
15743: $resulttext = &mt('Changes made:').'<ul>';
15744: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15745: my %lt = &selfcreation_types();
15746: foreach my $type (@{$changes{'cancreate'}}) {
15747: my $chgtext = '';
15748: if ($type eq 'selfcreate') {
15749: if (@{$cancreate{$type}} == 0) {
15750: $chgtext .= &mt('Self creation of a new user account is not permitted.');
15751: } else {
15752: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15753: '<ul>';
15754: foreach my $case (@{$cancreate{$type}}) {
15755: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15756: }
15757: $chgtext .= '</ul>';
15758: if (ref($cancreate{$type}) eq 'ARRAY') {
15759: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15760: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15761: if (@{$cancreate{'statustocreate'}} == 0) {
15762: $chgtext .= '<span class="LC_warning">'.
15763: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15764: '</span><br />';
15765: }
15766: }
15767: }
15768: if (grep(/^email$/,@{$cancreate{$type}})) {
15769: if (!@statuses) {
15770: $chgtext .= '<span class="LC_warning">'.
15771: &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.").
15772: '</span><br />';
15773:
15774: }
15775: }
15776: }
15777: }
15778: } elsif ($type eq 'shibenv') {
15779: if (keys(%{$cancreate{$type}}) == 0) {
15780: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
15781: } else {
15782: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15783: '<ul>';
15784: foreach my $field (@shibfields) {
15785: next if ($cancreate{$type}{$field} eq '');
15786: if ($field eq 'inststatus') {
15787: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15788: } else {
15789: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15790: }
15791: }
15792: $chgtext .= '</ul>';
15793: }
15794: } elsif ($type eq 'statustocreate') {
15795: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15796: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15797: if (@{$cancreate{'selfcreate'}} > 0) {
15798: if (@{$cancreate{'statustocreate'}} == 0) {
15799: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
15800: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
15801: $chgtext .= '<br />'.
15802: '<span class="LC_warning">'.
15803: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15804: '</span>';
15805: }
15806: } elsif (keys(%usertypes) > 0) {
15807: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
15808: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15809: } else {
15810: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15811: }
15812: $chgtext .= '<ul>';
15813: foreach my $case (@{$cancreate{$type}}) {
15814: if ($case eq 'default') {
15815: $chgtext .= '<li>'.$othertitle.'</li>';
15816: } else {
15817: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
15818: }
15819: }
15820: $chgtext .= '</ul>';
15821: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
15822: $chgtext .= '<span class="LC_warning">'.
15823: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15824: '</span>';
15825: }
15826: }
15827: } else {
15828: if (@{$cancreate{$type}} == 0) {
15829: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15830: } else {
15831: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
15832: }
15833: }
15834: $chgtext .= '<br />';
15835: }
15836: } elsif ($type eq 'selfcreateprocessing') {
15837: my %choices = &Apache::lonlocal::texthash (
15838: automatic => 'Automatic approval',
15839: approval => 'Queued for approval',
15840: );
15841: if (@types) {
15842: if (@statuses) {
15843: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
15844: '<ul>';
15845: foreach my $status (@statuses) {
15846: if ($status eq 'default') {
15847: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15848: } else {
15849: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15850: }
15851: }
15852: $chgtext .= '</ul>';
15853: }
15854: } else {
15855: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15856: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15857: }
15858: } elsif ($type eq 'emailverified') {
15859: my %options = &Apache::lonlocal::texthash (
15860: all => 'Same as e-mail',
15861: first => 'Omit @domain',
15862: free => 'Free to choose',
15863: );
15864: if (@types) {
15865: if (@statuses) {
15866: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15867: '<ul>';
15868: foreach my $status (@statuses) {
15869: if ($status eq 'default') {
15870: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15871: } else {
15872: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15873: }
15874: }
15875: $chgtext .= '</ul>';
15876: }
15877: } else {
15878: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
15879: $options{$cancreate{'emailverified'}{'default'}});
15880: }
15881: } elsif ($type eq 'emailoptions') {
15882: my %options = &Apache::lonlocal::texthash (
15883: any => 'Any e-mail',
15884: inst => 'Institutional only',
15885: noninst => 'Non-institutional only',
15886: custom => 'Custom restrictions',
15887: );
15888: if (@types) {
15889: if (@statuses) {
15890: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15891: '<ul>';
15892: foreach my $status (@statuses) {
15893: if ($type eq 'default') {
15894: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15895: } else {
15896: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15897: }
15898: }
15899: $chgtext .= '</ul>';
15900: }
15901: } else {
15902: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15903: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15904: } else {
15905: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15906: $options{$cancreate{'emailoptions'}{'default'}});
15907: }
15908: }
15909: } elsif ($type eq 'emaildomain') {
15910: my $output;
15911: if (@statuses) {
15912: foreach my $type (@statuses) {
15913: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15914: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15915: if ($type eq 'default') {
15916: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15917: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15918: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15919: } else {
15920: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15921: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15922: }
15923: } else {
15924: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15925: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15926: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15927: } else {
15928: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15929: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15930: }
15931: }
15932: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15933: if ($type eq 'default') {
15934: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15935: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15936: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15937: } else {
15938: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15939: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15940: }
15941: } else {
15942: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15943: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15944: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15945: } else {
15946: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15947: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15948: }
15949: }
15950: }
15951: }
15952: }
15953: }
15954: if ($output ne '') {
15955: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15956: '<ul>'.$output.'</ul>';
15957: }
15958: } elsif ($type eq 'captcha') {
15959: if ($savecaptcha{$type} eq 'notused') {
15960: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15961: } else {
15962: my %captchas = &captcha_phrases();
15963: if ($captchas{$savecaptcha{$type}}) {
15964: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
15965: } else {
15966: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
15967: }
15968: }
15969: } elsif ($type eq 'recaptchakeys') {
15970: my ($privkey,$pubkey);
15971: if (ref($savecaptcha{$type}) eq 'HASH') {
15972: $pubkey = $savecaptcha{$type}{'public'};
15973: $privkey = $savecaptcha{$type}{'private'};
15974: }
15975: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15976: if (!$pubkey) {
15977: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15978: } else {
15979: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15980: }
15981: if (!$privkey) {
15982: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15983: } else {
15984: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15985: }
15986: $chgtext .= '</ul>';
15987: } elsif ($type eq 'recaptchaversion') {
15988: if ($savecaptcha{'captcha'} eq 'recaptcha') {
15989: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
15990: }
15991: } elsif ($type eq 'emailusername') {
15992: if (ref($cancreate{'emailusername'}) eq 'HASH') {
15993: if (@statuses) {
15994: foreach my $type (@statuses) {
15995: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15996: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
15997: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
15998: '<ul>';
15999: foreach my $field (@{$infofields}) {
16000: if ($cancreate{'emailusername'}{$type}{$field}) {
16001: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
16002: }
16003: }
16004: $chgtext .= '</ul>';
16005: } else {
16006: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
16007: }
16008: } else {
16009: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
16010: }
16011: }
16012: }
16013: }
16014: } elsif ($type eq 'notify') {
16015: my $numapprove = 0;
16016: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16017: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
16018: if ($cancreate{'notify'}{'approval'}) {
16019: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
16020: $numapprove ++;
16021: }
16022: }
16023: }
16024: unless ($numapprove) {
16025: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
16026: }
16027: }
16028: if ($chgtext) {
16029: $resulttext .= '<li>'.$chgtext.'</li>';
16030: }
16031: }
16032: }
16033: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
16034: my ($emailrules,$emailruleorder) =
16035: &Apache::lonnet::inst_userrules($dom,'email');
16036: foreach my $type (@{$changes{'email_rule'}}) {
16037: if (ref($email_rule{$type}) eq 'ARRAY') {
16038: my $chgtext = '<ul>';
16039: foreach my $rule (@{$email_rule{$type}}) {
16040: if (ref($emailrules->{$rule}) eq 'HASH') {
16041: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
16042: }
16043: }
16044: $chgtext .= '</ul>';
16045: my $typename;
16046: if (@types) {
16047: if ($type eq 'default') {
16048: $typename = $othertitle;
16049: } else {
16050: $typename = $usertypes{$type};
16051: }
16052: $chgtext .= &mt('(Affiliation: [_1])',$typename);
16053: }
16054: if (@{$email_rule{$type}} > 0) {
16055: $resulttext .= '<li>'.
16056: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
16057: $usertypes{$type}).
16058: $chgtext.
16059: '</li>';
16060: } else {
16061: $resulttext .= '<li>'.
16062: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
16063: '</li>'.
16064: &mt('(Affiliation: [_1])',$typename);
16065: }
16066: }
16067: }
16068: }
16069: if (ref($changes{'inststatus'}) eq 'ARRAY') {
16070: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
16071: if (@{$save_inststatus{'inststatusguest'}} > 0) {
16072: my $chgtext = '<ul>';
16073: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
16074: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
16075: }
16076: $chgtext .= '</ul>';
16077: $resulttext .= '<li>'.
16078: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
16079: $chgtext.
16080: '</li>';
16081: } else {
16082: $resulttext .= '<li>'.
16083: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
16084: '</li>';
16085: }
16086: }
16087: }
16088: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
16089: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
16090: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16091: foreach my $type (@{$changes{'selfcreate'}}) {
16092: my $typename = $type;
16093: if (keys(%usertypes) > 0) {
16094: if ($usertypes{$type} ne '') {
16095: $typename = $usertypes{$type};
16096: }
16097: }
16098: my @modifiable;
16099: $resulttext .= '<li>'.
16100: &mt('Self-creation of account by users with status: [_1]',
16101: '<span class="LC_cusr_emph">'.$typename.'</span>').
16102: ' - '.&mt('modifiable fields (if institutional data blank): ');
16103: foreach my $field (@fields) {
16104: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
16105: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
16106: }
16107: }
16108: if (@modifiable > 0) {
16109: $resulttext .= join(', ',@modifiable);
16110: } else {
16111: $resulttext .= &mt('none');
16112: }
16113: $resulttext .= '</li>';
16114: }
16115: $resulttext .= '</ul></li>';
16116: }
16117: $resulttext .= '</ul>';
16118: my $cachetime = 24*60*60;
16119: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
16120: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16121: if (ref($lastactref) eq 'HASH') {
16122: $lastactref->{'domdefaults'} = 1;
16123: }
16124: } else {
16125: $resulttext = &mt('No changes made to self-creation settings');
16126: }
16127: } else {
16128: $resulttext = '<span class="LC_error">'.
16129: &mt('An error occurred: [_1]',$putresult).'</span>';
16130: }
16131: if ($warningmsg ne '') {
16132: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16133: }
16134: return $resulttext;
16135: }
16136:
16137: sub process_captcha {
16138: my ($container,$changes,$newsettings,$currsettings) = @_;
16139: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
16140: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
16141: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
16142: $newsettings->{'captcha'} = 'original';
16143: }
16144: my %current;
16145: if (ref($currsettings) eq 'HASH') {
16146: %current = %{$currsettings};
16147: }
16148: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
16149: if ($container eq 'cancreate') {
16150: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16151: push(@{$changes->{'cancreate'}},'captcha');
16152: } elsif (!defined($changes->{'cancreate'})) {
16153: $changes->{'cancreate'} = ['captcha'];
16154: }
16155: } elsif ($container eq 'passwords') {
16156: $changes->{'reset'} = 1;
16157: } else {
16158: $changes->{'captcha'} = 1;
16159: }
16160: }
16161: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
16162: if ($newsettings->{'captcha'} eq 'recaptcha') {
16163: $newpub = $env{'form.'.$container.'_recaptchapub'};
16164: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
16165: $newpub =~ s/[^\w\-]//g;
16166: $newpriv =~ s/[^\w\-]//g;
16167: $newsettings->{'recaptchakeys'} = {
16168: public => $newpub,
16169: private => $newpriv,
16170: };
16171: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16172: $newversion =~ s/\D//g;
16173: if ($newversion ne '2') {
16174: $newversion = 1;
16175: }
16176: $newsettings->{'recaptchaversion'} = $newversion;
16177: }
16178: if (ref($current{'recaptchakeys'}) eq 'HASH') {
16179: $currpub = $current{'recaptchakeys'}{'public'};
16180: $currpriv = $current{'recaptchakeys'}{'private'};
16181: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16182: $newsettings->{'recaptchakeys'} = {
16183: public => '',
16184: private => '',
16185: }
16186: }
16187: }
16188: if ($current{'captcha'} eq 'recaptcha') {
16189: $currversion = $current{'recaptchaversion'};
16190: if ($currversion ne '2') {
16191: $currversion = 1;
16192: }
16193: }
16194: if ($currversion ne $newversion) {
16195: if ($container eq 'cancreate') {
16196: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16197: push(@{$changes->{'cancreate'}},'recaptchaversion');
16198: } elsif (!defined($changes->{'cancreate'})) {
16199: $changes->{'cancreate'} = ['recaptchaversion'];
16200: }
16201: } elsif ($container eq 'passwords') {
16202: $changes->{'reset'} = 1;
16203: } else {
16204: $changes->{'recaptchaversion'} = 1;
16205: }
16206: }
16207: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
16208: if ($container eq 'cancreate') {
16209: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16210: push(@{$changes->{'cancreate'}},'recaptchakeys');
16211: } elsif (!defined($changes->{'cancreate'})) {
16212: $changes->{'cancreate'} = ['recaptchakeys'];
16213: }
16214: } elsif ($container eq 'passwords') {
16215: $changes->{'reset'} = 1;
16216: } else {
16217: $changes->{'recaptchakeys'} = 1;
16218: }
16219: }
16220: return;
16221: }
16222:
16223: sub modify_usermodification {
16224: my ($dom,%domconfig) = @_;
16225: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
16226: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16227: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16228: if ($key eq 'selfcreate') {
16229: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16230: } else {
16231: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
16232: }
16233: }
16234: }
16235: my @contexts = ('author','course');
16236: my %context_title = (
16237: author => 'In author context',
16238: course => 'In course context',
16239: );
16240: my @fields = ('lastname','firstname','middlename','generation',
16241: 'permanentemail','id');
16242: my %roles = (
16243: author => ['ca','aa'],
16244: course => ['st','ep','ta','in','cr'],
16245: );
16246: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16247: foreach my $context (@contexts) {
16248: foreach my $role (@{$roles{$context}}) {
16249: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
16250: foreach my $item (@fields) {
16251: if (grep(/^\Q$item\E$/,@modifiable)) {
16252: $modifyhash{$context}{$role}{$item} = 1;
16253: } else {
16254: $modifyhash{$context}{$role}{$item} = 0;
16255: }
16256: }
16257: }
16258: if (ref($curr_usermodification{$context}) eq 'HASH') {
16259: foreach my $role (@{$roles{$context}}) {
16260: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
16261: foreach my $field (@fields) {
16262: if ($modifyhash{$context}{$role}{$field} ne
16263: $curr_usermodification{$context}{$role}{$field}) {
16264: push(@{$changes{$context}},$role);
16265: last;
16266: }
16267: }
16268: }
16269: }
16270: } else {
16271: foreach my $context (@contexts) {
16272: foreach my $role (@{$roles{$context}}) {
16273: push(@{$changes{$context}},$role);
16274: }
16275: }
16276: }
16277: }
16278: my %usermodification_hash = (
16279: usermodification => \%modifyhash,
16280: );
16281: my $putresult = &Apache::lonnet::put_dom('configuration',
16282: \%usermodification_hash,$dom);
16283: if ($putresult eq 'ok') {
16284: if (keys(%changes) > 0) {
16285: $resulttext = &mt('Changes made: ').'<ul>';
16286: foreach my $context (@contexts) {
16287: if (ref($changes{$context}) eq 'ARRAY') {
16288: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
16289: if (ref($changes{$context}) eq 'ARRAY') {
16290: foreach my $role (@{$changes{$context}}) {
16291: my $rolename;
16292: if ($role eq 'cr') {
16293: $rolename = &mt('Custom');
16294: } else {
16295: $rolename = &Apache::lonnet::plaintext($role);
16296: }
16297: my @modifiable;
16298: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
16299: foreach my $field (@fields) {
16300: if ($modifyhash{$context}{$role}{$field}) {
16301: push(@modifiable,$fieldtitles{$field});
16302: }
16303: }
16304: if (@modifiable > 0) {
16305: $resulttext .= join(', ',@modifiable);
16306: } else {
16307: $resulttext .= &mt('none');
16308: }
16309: $resulttext .= '</li>';
16310: }
16311: $resulttext .= '</ul></li>';
16312: }
16313: }
16314: }
16315: $resulttext .= '</ul>';
16316: } else {
16317: $resulttext = &mt('No changes made to user modification settings');
16318: }
16319: } else {
16320: $resulttext = '<span class="LC_error">'.
16321: &mt('An error occurred: [_1]',$putresult).'</span>';
16322: }
16323: return $resulttext;
16324: }
16325:
16326: sub modify_defaults {
16327: my ($dom,$lastactref,%domconfig) = @_;
16328: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
16329: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16330: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
16331: 'portal_def');
16332: my @authtypes = ('internal','krb4','krb5','localauth');
16333: foreach my $item (@items) {
16334: $newvalues{$item} = $env{'form.'.$item};
16335: if ($item eq 'auth_def') {
16336: if ($newvalues{$item} ne '') {
16337: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
16338: push(@errors,$item);
16339: }
16340: }
16341: } elsif ($item eq 'lang_def') {
16342: if ($newvalues{$item} ne '') {
16343: if ($newvalues{$item} =~ /^(\w+)/) {
16344: my $langcode = $1;
16345: if ($langcode ne 'x_chef') {
16346: if (code2language($langcode) eq '') {
16347: push(@errors,$item);
16348: }
16349: }
16350: } else {
16351: push(@errors,$item);
16352: }
16353: }
16354: } elsif ($item eq 'timezone_def') {
16355: if ($newvalues{$item} ne '') {
16356: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
16357: push(@errors,$item);
16358: }
16359: }
16360: } elsif ($item eq 'datelocale_def') {
16361: if ($newvalues{$item} ne '') {
16362: my @datelocale_ids = DateTime::Locale->ids();
16363: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
16364: push(@errors,$item);
16365: }
16366: }
16367: } elsif ($item eq 'portal_def') {
16368: if ($newvalues{$item} ne '') {
16369: unless ($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])\/?$/) {
16370: push(@errors,$item);
16371: }
16372: }
16373: }
16374: if (grep(/^\Q$item\E$/,@errors)) {
16375: $newvalues{$item} = $domdefaults{$item};
16376: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
16377: $changes{$item} = 1;
16378: }
16379: $domdefaults{$item} = $newvalues{$item};
16380: }
16381: my %staticdefaults = (
16382: 'intauth_cost' => 10,
16383: 'intauth_check' => 0,
16384: 'intauth_switch' => 0,
16385: );
16386: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
16387: if (exists($domdefaults{$item})) {
16388: $newvalues{$item} = $domdefaults{$item};
16389: } else {
16390: $newvalues{$item} = $staticdefaults{$item};
16391: }
16392: }
16393: my ($unamemaprules,$ruleorder);
16394: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
16395: if (@possunamemaprules) {
16396: ($unamemaprules,$ruleorder) =
16397: &Apache::lonnet::inst_userrules($dom,'unamemap');
16398: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
16399: if (@{$ruleorder} > 0) {
16400: my %possrules;
16401: map { $possrules{$_} = 1; } @possunamemaprules;
16402: foreach my $rule (@{$ruleorder}) {
16403: if ($possrules{$rule}) {
16404: push(@{$newvalues{'unamemap_rule'}},$rule);
16405: }
16406: }
16407: }
16408: }
16409: }
16410: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
16411: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16412: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
16413: $newvalues{'unamemap_rule'});
16414: if (@rulediffs) {
16415: $changes{'unamemap_rule'} = 1;
16416: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
16417: }
16418: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
16419: $changes{'unamemap_rule'} = 1;
16420: delete($domdefaults{'unamemap_rule'});
16421: }
16422: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16423: if (@{$newvalues{'unamemap_rule'}} > 0) {
16424: $changes{'unamemap_rule'} = 1;
16425: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
16426: }
16427: }
16428: my %defaults_hash = (
16429: defaults => \%newvalues,
16430: );
16431: my $title = &defaults_titles();
16432:
16433: my $currinststatus;
16434: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16435: $currinststatus = $domconfig{'inststatus'};
16436: } else {
16437: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16438: $currinststatus = {
16439: inststatustypes => $usertypes,
16440: inststatusorder => $types,
16441: inststatusguest => [],
16442: };
16443: }
16444: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
16445: my @allpos;
16446: my %alltypes;
16447: my @inststatusguest;
16448: if (ref($currinststatus) eq 'HASH') {
16449: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
16450: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
16451: unless (grep(/^\Q$type\E$/,@todelete)) {
16452: push(@inststatusguest,$type);
16453: }
16454: }
16455: }
16456: }
16457: my ($currtitles,$currorder);
16458: if (ref($currinststatus) eq 'HASH') {
16459: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
16460: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
16461: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
16462: if ($currinststatus->{inststatustypes}->{$type} ne '') {
16463: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
16464: }
16465: }
16466: unless (grep(/^\Q$type\E$/,@todelete)) {
16467: my $position = $env{'form.inststatus_pos_'.$type};
16468: $position =~ s/\D+//g;
16469: $allpos[$position] = $type;
16470: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
16471: $alltypes{$type} =~ s/`//g;
16472: }
16473: }
16474: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
16475: $currtitles =~ s/,$//;
16476: }
16477: }
16478: if ($env{'form.addinststatus'}) {
16479: my $newtype = $env{'form.addinststatus'};
16480: $newtype =~ s/\W//g;
16481: unless (exists($alltypes{$newtype})) {
16482: $alltypes{$newtype} = $env{'form.addinststatus_title'};
16483: $alltypes{$newtype} =~ s/`//g;
16484: my $position = $env{'form.addinststatus_pos'};
16485: $position =~ s/\D+//g;
16486: if ($position ne '') {
16487: $allpos[$position] = $newtype;
16488: }
16489: }
16490: }
16491: my @orderedstatus;
16492: foreach my $type (@allpos) {
16493: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
16494: push(@orderedstatus,$type);
16495: }
16496: }
16497: foreach my $type (keys(%alltypes)) {
16498: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
16499: delete($alltypes{$type});
16500: }
16501: }
16502: $defaults_hash{'inststatus'} = {
16503: inststatustypes => \%alltypes,
16504: inststatusorder => \@orderedstatus,
16505: inststatusguest => \@inststatusguest,
16506: };
16507: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
16508: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
16509: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
16510: }
16511: }
16512: if ($currorder ne join(',',@orderedstatus)) {
16513: $changes{'inststatus'}{'inststatusorder'} = 1;
16514: }
16515: my $newtitles;
16516: foreach my $item (@orderedstatus) {
16517: $newtitles .= $alltypes{$item}.',';
16518: }
16519: $newtitles =~ s/,$//;
16520: if ($currtitles ne $newtitles) {
16521: $changes{'inststatus'}{'inststatustypes'} = 1;
16522: }
16523: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
16524: $dom);
16525: if ($putresult eq 'ok') {
16526: if (keys(%changes) > 0) {
16527: $resulttext = &mt('Changes made:').'<ul>';
16528: my $version = &Apache::lonnet::get_server_loncaparev($dom);
16529: 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";
16530: foreach my $item (sort(keys(%changes))) {
16531: if ($item eq 'inststatus') {
16532: if (ref($changes{'inststatus'}) eq 'HASH') {
16533: if (@orderedstatus) {
16534: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
16535: foreach my $type (@orderedstatus) {
16536: $resulttext .= $alltypes{$type}.', ';
16537: }
16538: $resulttext =~ s/, $//;
16539: $resulttext .= '</li>';
16540: } else {
16541: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
16542: }
16543: }
16544: } elsif ($item eq 'unamemap_rule') {
16545: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16546: my @rulenames;
16547: if (ref($unamemaprules) eq 'HASH') {
16548: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
16549: if (ref($unamemaprules->{$rule}) eq 'HASH') {
16550: push(@rulenames,$unamemaprules->{$rule}->{'name'});
16551: }
16552: }
16553: }
16554: if (@rulenames) {
16555: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
16556: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
16557: '</li>';
16558: } else {
16559: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
16560: }
16561: } else {
16562: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
16563: }
16564: } else {
16565: my $value = $env{'form.'.$item};
16566: if ($value eq '') {
16567: $value = &mt('none');
16568: } elsif ($item eq 'auth_def') {
16569: my %authnames = &authtype_names();
16570: my %shortauth = (
16571: internal => 'int',
16572: krb4 => 'krb4',
16573: krb5 => 'krb5',
16574: localauth => 'loc',
16575: );
16576: $value = $authnames{$shortauth{$value}};
16577: }
16578: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
16579: $mailmsgtext .= "$title->{$item} set to $value\n";
16580: }
16581: }
16582: $resulttext .= '</ul>';
16583: $mailmsgtext .= "\n";
16584: my $cachetime = 24*60*60;
16585: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16586: if (ref($lastactref) eq 'HASH') {
16587: $lastactref->{'domdefaults'} = 1;
16588: }
16589: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
16590: my $notify = 1;
16591: if (ref($domconfig{'contacts'}) eq 'HASH') {
16592: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
16593: $notify = 0;
16594: }
16595: }
16596: if ($notify) {
16597: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
16598: "LON-CAPA Domain Settings Change - $dom",
16599: $mailmsgtext);
16600: }
16601: }
16602: } else {
16603: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
16604: }
16605: } else {
16606: $resulttext = '<span class="LC_error">'.
16607: &mt('An error occurred: [_1]',$putresult).'</span>';
16608: }
16609: if (@errors > 0) {
16610: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
16611: foreach my $item (@errors) {
16612: $resulttext .= ' "'.$title->{$item}.'",';
16613: }
16614: $resulttext =~ s/,$//;
16615: }
16616: return $resulttext;
16617: }
16618:
16619: sub modify_scantron {
16620: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
16621: my ($resulttext,%confhash,%changes,$errors);
16622: my $custom = 'custom.tab';
16623: my $default = 'default.tab';
16624: my $servadm = $r->dir_config('lonAdmEMail');
16625: my ($configuserok,$author_ok,$switchserver) =
16626: &config_check($dom,$confname,$servadm);
16627: if ($env{'form.scantronformat.filename'} ne '') {
16628: my $error;
16629: if ($configuserok eq 'ok') {
16630: if ($switchserver) {
16631: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
16632: } else {
16633: if ($author_ok eq 'ok') {
16634: my ($result,$scantronurl) =
16635: &publishlogo($r,'upload','scantronformat',$dom,
16636: $confname,'scantron','','',$custom);
16637: if ($result eq 'ok') {
16638: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
16639: $changes{'scantronformat'} = 1;
16640: } else {
16641: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
16642: }
16643: } else {
16644: $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);
16645: }
16646: }
16647: } else {
16648: $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);
16649: }
16650: if ($error) {
16651: &Apache::lonnet::logthis($error);
16652: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16653: }
16654: }
16655: if (ref($domconfig{'scantron'}) eq 'HASH') {
16656: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
16657: if ($env{'form.scantronformat_del'}) {
16658: $confhash{'scantron'}{'scantronformat'} = '';
16659: $changes{'scantronformat'} = 1;
16660: } else {
16661: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
16662: }
16663: }
16664: }
16665: my @options = ('hdr','pad','rem');
16666: my @fields = &scantroncsv_fields();
16667: my %titles = &scantronconfig_titles();
16668: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
16669: my ($newdat,$currdat,%newcol,%currcol);
16670: if (grep(/^dat$/,@formats)) {
16671: $confhash{'scantron'}{config}{dat} = 1;
16672: $newdat = 1;
16673: } else {
16674: $newdat = 0;
16675: }
16676: if (grep(/^csv$/,@formats)) {
16677: my %bynum;
16678: foreach my $field (@fields) {
16679: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
16680: my $posscol = $1;
16681: if (($posscol < 20) && (!$bynum{$posscol})) {
16682: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
16683: $bynum{$posscol} = $field;
16684: $newcol{$field} = $posscol;
16685: }
16686: }
16687: }
16688: if (keys(%newcol)) {
16689: foreach my $option (@options) {
16690: if ($env{'form.scantroncsv_'.$option}) {
16691: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
16692: }
16693: }
16694: }
16695: }
16696: $currdat = 1;
16697: if (ref($domconfig{'scantron'}) eq 'HASH') {
16698: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
16699: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
16700: $currdat = 0;
16701: }
16702: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16703: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16704: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16705: }
16706: }
16707: }
16708: }
16709: if ($currdat != $newdat) {
16710: $changes{'config'} = 1;
16711: } else {
16712: foreach my $field (@fields) {
16713: if ($currcol{$field} ne '') {
16714: if ($currcol{$field} ne $newcol{$field}) {
16715: $changes{'config'} = 1;
16716: last;
16717: }
16718: } elsif ($newcol{$field} ne '') {
16719: $changes{'config'} = 1;
16720: last;
16721: }
16722: }
16723: }
16724: if (keys(%confhash) > 0) {
16725: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16726: $dom);
16727: if ($putresult eq 'ok') {
16728: if (keys(%changes) > 0) {
16729: if (ref($confhash{'scantron'}) eq 'HASH') {
16730: $resulttext = &mt('Changes made:').'<ul>';
16731: if ($changes{'scantronformat'}) {
16732: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16733: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16734: } else {
16735: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16736: }
16737: }
16738: if ($changes{'config'}) {
16739: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16740: if ($confhash{'scantron'}{'config'}{'dat'}) {
16741: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16742: }
16743: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16744: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16745: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16746: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16747: foreach my $field (@fields) {
16748: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16749: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16750: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16751: }
16752: }
16753: $resulttext .= '</ul></li>';
16754: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16755: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16756: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16757: foreach my $option (@options) {
16758: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16759: $resulttext .= '<li>'.$titles{$option}.'</li>';
16760: }
16761: }
16762: $resulttext .= '</ul></li>';
16763: }
16764: }
16765: }
16766: }
16767: }
16768: } else {
16769: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16770: }
16771: }
16772: $resulttext .= '</ul>';
16773: } else {
16774: $resulttext = &mt('Changes made to bubblesheet format file.');
16775: }
16776: &Apache::loncommon::devalidate_domconfig_cache($dom);
16777: if (ref($lastactref) eq 'HASH') {
16778: $lastactref->{'domainconfig'} = 1;
16779: }
16780: } else {
16781: $resulttext = &mt('No changes made to bubblesheet format settings');
16782: }
16783: } else {
16784: $resulttext = '<span class="LC_error">'.
16785: &mt('An error occurred: [_1]',$putresult).'</span>';
16786: }
16787: } else {
16788: $resulttext = &mt('No changes made to bubblesheet format settings');
16789: }
16790: if ($errors) {
16791: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16792: $errors.'</ul>';
16793: }
16794: return $resulttext;
16795: }
16796:
16797: sub modify_coursecategories {
16798: my ($dom,$lastactref,%domconfig) = @_;
16799: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16800: $cathash);
16801: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
16802: my @catitems = ('unauth','auth');
16803: my @cattypes = ('std','domonly','codesrch','none');
16804: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16805: $cathash = $domconfig{'coursecategories'}{'cats'};
16806: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16807: $changes{'togglecats'} = 1;
16808: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16809: }
16810: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16811: $changes{'categorize'} = 1;
16812: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16813: }
16814: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16815: $changes{'togglecatscomm'} = 1;
16816: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16817: }
16818: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16819: $changes{'categorizecomm'} = 1;
16820: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
16821: }
16822: foreach my $item (@catitems) {
16823: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16824: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16825: $changes{$item} = 1;
16826: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16827: }
16828: }
16829: }
16830: } else {
16831: $changes{'togglecats'} = 1;
16832: $changes{'categorize'} = 1;
16833: $changes{'togglecatscomm'} = 1;
16834: $changes{'categorizecomm'} = 1;
16835: $domconfig{'coursecategories'} = {
16836: togglecats => $env{'form.togglecats'},
16837: categorize => $env{'form.categorize'},
16838: togglecatscomm => $env{'form.togglecatscomm'},
16839: categorizecomm => $env{'form.categorizecomm'},
16840: };
16841: foreach my $item (@catitems) {
16842: if ($env{'form.coursecat_'.$item} ne 'std') {
16843: $changes{$item} = 1;
16844: }
16845: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16846: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16847: }
16848: }
16849: }
16850: if (ref($cathash) eq 'HASH') {
16851: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
16852: push (@deletecategory,'instcode::0');
16853: }
16854: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16855: push(@deletecategory,'communities::0');
16856: }
16857: }
16858: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16859: if (ref($cathash) eq 'HASH') {
16860: if (@deletecategory > 0) {
16861: #FIXME Need to remove category from all courses using a deleted category
16862: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
16863: foreach my $item (@deletecategory) {
16864: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16865: delete($domconfig{'coursecategories'}{'cats'}{$item});
16866: $deletions{$item} = 1;
16867: &recurse_cat_deletes($item,$cathash,\%deletions);
16868: }
16869: }
16870: }
16871: foreach my $item (keys(%{$cathash})) {
16872: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16873: if ($cathash->{$item} ne $env{'form.'.$item}) {
16874: $reorderings{$item} = 1;
16875: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
16876: }
16877: if ($env{'form.addcategory_name_'.$item} ne '') {
16878: my $newcat = $env{'form.addcategory_name_'.$item};
16879: my $newdepth = $depth+1;
16880: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
16881: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
16882: $adds{$newitem} = 1;
16883: }
16884: if ($env{'form.subcat_'.$item} ne '') {
16885: my $newcat = $env{'form.subcat_'.$item};
16886: my $newdepth = $depth+1;
16887: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
16888: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
16889: $adds{$newitem} = 1;
16890: }
16891: }
16892: }
16893: if ($env{'form.instcode'} eq '1') {
16894: if (ref($cathash) eq 'HASH') {
16895: my $newitem = 'instcode::0';
16896: if ($cathash->{$newitem} eq '') {
16897: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
16898: $adds{$newitem} = 1;
16899: }
16900: } else {
16901: my $newitem = 'instcode::0';
16902: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
16903: $adds{$newitem} = 1;
16904: }
16905: }
16906: if ($env{'form.communities'} eq '1') {
16907: if (ref($cathash) eq 'HASH') {
16908: my $newitem = 'communities::0';
16909: if ($cathash->{$newitem} eq '') {
16910: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16911: $adds{$newitem} = 1;
16912: }
16913: } else {
16914: my $newitem = 'communities::0';
16915: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16916: $adds{$newitem} = 1;
16917: }
16918: }
16919: if ($env{'form.addcategory_name'} ne '') {
16920: if (($env{'form.addcategory_name'} ne 'instcode') &&
16921: ($env{'form.addcategory_name'} ne 'communities')) {
16922: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16923: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16924: $adds{$newitem} = 1;
16925: }
16926: }
16927: my $putresult;
16928: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16929: if (keys(%deletions) > 0) {
16930: foreach my $key (keys(%deletions)) {
16931: if ($predelallitems{$key} ne '') {
16932: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16933: }
16934: }
16935: }
16936: my (@chkcats,@chktrails,%chkallitems);
16937: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
16938: if (ref($chkcats[0]) eq 'ARRAY') {
16939: my $depth = 0;
16940: my $chg = 0;
16941: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16942: my $name = $chkcats[0][$i];
16943: my $item;
16944: if ($name eq '') {
16945: $chg ++;
16946: } else {
16947: $item = &escape($name).'::0';
16948: if ($chg) {
16949: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
16950: }
16951: $depth ++;
16952: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
16953: $depth --;
16954: }
16955: }
16956: }
16957: }
16958: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16959: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
16960: if ($putresult eq 'ok') {
16961: my %title = (
16962: togglecats => 'Show/Hide a course in catalog',
16963: categorize => 'Assign a category to a course',
16964: togglecatscomm => 'Show/Hide a community in catalog',
16965: categorizecomm => 'Assign a category to a community',
16966: );
16967: my %level = (
16968: dom => 'set in Domain ("Modify Course/Community")',
16969: crs => 'set in Course ("Course Configuration")',
16970: comm => 'set in Community ("Community Configuration")',
16971: none => 'No catalog',
16972: std => 'Standard catalog',
16973: domonly => 'Domain-only catalog',
16974: codesrch => 'Code search form',
16975: );
16976: $resulttext = &mt('Changes made:').'<ul>';
16977: if ($changes{'togglecats'}) {
16978: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16979: }
16980: if ($changes{'categorize'}) {
16981: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
16982: }
16983: if ($changes{'togglecatscomm'}) {
16984: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16985: }
16986: if ($changes{'categorizecomm'}) {
16987: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16988: }
16989: if ($changes{'unauth'}) {
16990: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16991: }
16992: if ($changes{'auth'}) {
16993: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16994: }
16995: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16996: my $cathash;
16997: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16998: $cathash = $domconfig{'coursecategories'}{'cats'};
16999: } else {
17000: $cathash = {};
17001: }
17002: my (@cats,@trails,%allitems);
17003: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
17004: if (keys(%deletions) > 0) {
17005: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
17006: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
17007: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
17008: }
17009: $resulttext .= '</ul></li>';
17010: }
17011: if (keys(%reorderings) > 0) {
17012: my %sort_by_trail;
17013: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
17014: foreach my $key (keys(%reorderings)) {
17015: if ($allitems{$key} ne '') {
17016: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17017: }
17018: }
17019: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17020: $resulttext .= '<li>'.$trails[$trail].'</li>';
17021: }
17022: $resulttext .= '</ul></li>';
17023: }
17024: if (keys(%adds) > 0) {
17025: my %sort_by_trail;
17026: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
17027: foreach my $key (keys(%adds)) {
17028: if ($allitems{$key} ne '') {
17029: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17030: }
17031: }
17032: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17033: $resulttext .= '<li>'.$trails[$trail].'</li>';
17034: }
17035: $resulttext .= '</ul></li>';
17036: }
17037: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
17038: if (ref($lastactref) eq 'HASH') {
17039: $lastactref->{'cats'} = 1;
17040: }
17041: }
17042: $resulttext .= '</ul>';
17043: if ($changes{'unauth'} || $changes{'auth'}) {
17044: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17045: if ($changes{'auth'}) {
17046: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
17047: }
17048: if ($changes{'unauth'}) {
17049: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
17050: }
17051: my $cachetime = 24*60*60;
17052: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17053: if (ref($lastactref) eq 'HASH') {
17054: $lastactref->{'domdefaults'} = 1;
17055: }
17056: }
17057: } else {
17058: $resulttext = '<span class="LC_error">'.
17059: &mt('An error occurred: [_1]',$putresult).'</span>';
17060: }
17061: } else {
17062: $resulttext = &mt('No changes made to course and community categories');
17063: }
17064: return $resulttext;
17065: }
17066:
17067: sub modify_serverstatuses {
17068: my ($dom,%domconfig) = @_;
17069: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
17070: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
17071: %currserverstatus = %{$domconfig{'serverstatuses'}};
17072: }
17073: my @pages = &serverstatus_pages();
17074: foreach my $type (@pages) {
17075: $newserverstatus{$type}{'namedusers'} = '';
17076: $newserverstatus{$type}{'machines'} = '';
17077: if (defined($env{'form.'.$type.'_namedusers'})) {
17078: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
17079: my @okusers;
17080: foreach my $user (@users) {
17081: my ($uname,$udom) = split(/:/,$user);
17082: if (($udom =~ /^$match_domain$/) &&
17083: (&Apache::lonnet::domain($udom)) &&
17084: ($uname =~ /^$match_username$/)) {
17085: if (!grep(/^\Q$user\E/,@okusers)) {
17086: push(@okusers,$user);
17087: }
17088: }
17089: }
17090: if (@okusers > 0) {
17091: @okusers = sort(@okusers);
17092: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
17093: }
17094: }
17095: if (defined($env{'form.'.$type.'_machines'})) {
17096: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
17097: my @okmachines;
17098: foreach my $ip (@machines) {
17099: my @parts = split(/\./,$ip);
17100: next if (@parts < 4);
17101: my $badip = 0;
17102: for (my $i=0; $i<4; $i++) {
17103: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
17104: $badip = 1;
17105: last;
17106: }
17107: }
17108: if (!$badip) {
17109: push(@okmachines,$ip);
17110: }
17111: }
17112: @okmachines = sort(@okmachines);
17113: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
17114: }
17115: }
17116: my %serverstatushash = (
17117: serverstatuses => \%newserverstatus,
17118: );
17119: foreach my $type (@pages) {
17120: foreach my $setting ('namedusers','machines') {
17121: my (@current,@new);
17122: if (ref($currserverstatus{$type}) eq 'HASH') {
17123: if ($currserverstatus{$type}{$setting} ne '') {
17124: @current = split(/,/,$currserverstatus{$type}{$setting});
17125: }
17126: }
17127: if ($newserverstatus{$type}{$setting} ne '') {
17128: @new = split(/,/,$newserverstatus{$type}{$setting});
17129: }
17130: if (@current > 0) {
17131: if (@new > 0) {
17132: foreach my $item (@current) {
17133: if (!grep(/^\Q$item\E$/,@new)) {
17134: $changes{$type}{$setting} = 1;
17135: last;
17136: }
17137: }
17138: foreach my $item (@new) {
17139: if (!grep(/^\Q$item\E$/,@current)) {
17140: $changes{$type}{$setting} = 1;
17141: last;
17142: }
17143: }
17144: } else {
17145: $changes{$type}{$setting} = 1;
17146: }
17147: } elsif (@new > 0) {
17148: $changes{$type}{$setting} = 1;
17149: }
17150: }
17151: }
17152: if (keys(%changes) > 0) {
17153: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
17154: my $putresult = &Apache::lonnet::put_dom('configuration',
17155: \%serverstatushash,$dom);
17156: if ($putresult eq 'ok') {
17157: $resulttext .= &mt('Changes made:').'<ul>';
17158: foreach my $type (@pages) {
17159: if (ref($changes{$type}) eq 'HASH') {
17160: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
17161: if ($changes{$type}{'namedusers'}) {
17162: if ($newserverstatus{$type}{'namedusers'} eq '') {
17163: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
17164: } else {
17165: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
17166: }
17167: }
17168: if ($changes{$type}{'machines'}) {
17169: if ($newserverstatus{$type}{'machines'} eq '') {
17170: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
17171: } else {
17172: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
17173: }
17174:
17175: }
17176: $resulttext .= '</ul></li>';
17177: }
17178: }
17179: $resulttext .= '</ul>';
17180: } else {
17181: $resulttext = '<span class="LC_error">'.
17182: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
17183:
17184: }
17185: } else {
17186: $resulttext = &mt('No changes made to access to server status pages');
17187: }
17188: return $resulttext;
17189: }
17190:
17191: sub modify_helpsettings {
17192: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
17193: my ($resulttext,$errors,%changes,%helphash);
17194: my %defaultchecked = ('submitbugs' => 'on');
17195: my @offon = ('off','on');
17196: my @toggles = ('submitbugs');
17197: my %current = ('submitbugs' => '',
17198: 'adhoc' => {},
17199: );
17200: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
17201: %current = %{$domconfig{'helpsettings'}};
17202: }
17203: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17204: foreach my $item (@toggles) {
17205: if ($defaultchecked{$item} eq 'on') {
17206: if ($current{$item} eq '') {
17207: if ($env{'form.'.$item} eq '0') {
17208: $changes{$item} = 1;
17209: }
17210: } elsif ($current{$item} ne $env{'form.'.$item}) {
17211: $changes{$item} = 1;
17212: }
17213: } elsif ($defaultchecked{$item} eq 'off') {
17214: if ($current{$item} eq '') {
17215: if ($env{'form.'.$item} eq '1') {
17216: $changes{$item} = 1;
17217: }
17218: } elsif ($current{$item} ne $env{'form.'.$item}) {
17219: $changes{$item} = 1;
17220: }
17221: }
17222: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
17223: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
17224: }
17225: }
17226: my $maxnum = $env{'form.helproles_maxnum'};
17227: my $confname = $dom.'-domainconfig';
17228: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
17229: my (@allpos,%newsettings,%changedprivs,$newrole);
17230: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17231: my @accesstypes = ('all','dh','da','none','status','inc','exc');
17232: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
17233: my %lt = &Apache::lonlocal::texthash(
17234: s => 'system',
17235: d => 'domain',
17236: order => 'Display order',
17237: access => 'Role usage',
17238: all => 'All with domain helpdesk or helpdesk assistant role',
17239: dh => 'All with domain helpdesk role',
17240: da => 'All with domain helpdesk assistant role',
17241: none => 'None',
17242: status => 'Determined based on institutional status',
17243: inc => 'Include all, but exclude specific personnel',
17244: exc => 'Exclude all, but include specific personnel',
17245: );
17246: for (my $num=0; $num<=$maxnum; $num++) {
17247: my ($prefix,$identifier,$rolename,%curr);
17248: if ($num == $maxnum) {
17249: next unless ($env{'form.newcusthelp'} == $maxnum);
17250: $identifier = 'custhelp'.$num;
17251: $prefix = 'helproles_'.$num;
17252: $rolename = $env{'form.custhelpname'.$num};
17253: $rolename=~s/[^A-Za-z0-9]//gs;
17254: next if ($rolename eq '');
17255: next if (exists($existing{'rolesdef_'.$rolename}));
17256: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17257: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17258: $newprivs{'c'},$confname,$dom);
17259: if ($result ne 'ok') {
17260: $errors .= '<li><span class="LC_error">'.
17261: &mt('An error occurred storing the new custom role: [_1]',
17262: $result).'</span></li>';
17263: next;
17264: } else {
17265: $changedprivs{$rolename} = \%newprivs;
17266: $newrole = $rolename;
17267: }
17268: } else {
17269: $prefix = 'helproles_'.$num;
17270: $rolename = $env{'form.'.$prefix};
17271: next if ($rolename eq '');
17272: next unless (exists($existing{'rolesdef_'.$rolename}));
17273: $identifier = 'custhelp'.$num;
17274: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17275: my %currprivs;
17276: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
17277: split(/\_/,$existing{'rolesdef_'.$rolename});
17278: foreach my $level ('c','d','s') {
17279: if ($newprivs{$level} ne $currprivs{$level}) {
17280: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17281: $newprivs{'c'},$confname,$dom);
17282: if ($result ne 'ok') {
17283: $errors .= '<li><span class="LC_error">'.
17284: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
17285: $rolename,$result).'</span></li>';
17286: } else {
17287: $changedprivs{$rolename} = \%newprivs;
17288: }
17289: last;
17290: }
17291: }
17292: if (ref($current{'adhoc'}) eq 'HASH') {
17293: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17294: %curr = %{$current{'adhoc'}{$rolename}};
17295: }
17296: }
17297: }
17298: my $newpos = $env{'form.'.$prefix.'_pos'};
17299: $newpos =~ s/\D+//g;
17300: $allpos[$newpos] = $rolename;
17301: my $newdesc = $env{'form.'.$prefix.'_desc'};
17302: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
17303: if ($curr{'desc'}) {
17304: if ($curr{'desc'} ne $newdesc) {
17305: $changes{'customrole'}{$rolename}{'desc'} = 1;
17306: $newsettings{$rolename}{'desc'} = $newdesc;
17307: }
17308: } elsif ($newdesc ne '') {
17309: $changes{'customrole'}{$rolename}{'desc'} = 1;
17310: $newsettings{$rolename}{'desc'} = $newdesc;
17311: }
17312: my $access = $env{'form.'.$prefix.'_access'};
17313: if (grep(/^\Q$access\E$/,@accesstypes)) {
17314: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
17315: if ($access eq 'status') {
17316: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
17317: if (scalar(@statuses) == 0) {
17318: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
17319: } else {
17320: my (@shownstatus,$numtypes);
17321: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17322: if (ref($types) eq 'ARRAY') {
17323: $numtypes = scalar(@{$types});
17324: foreach my $type (sort(@statuses)) {
17325: if ($type eq 'default') {
17326: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17327: } elsif (grep(/^\Q$type\E$/,@{$types})) {
17328: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17329: push(@shownstatus,$usertypes->{$type});
17330: }
17331: }
17332: }
17333: if (grep(/^default$/,@statuses)) {
17334: push(@shownstatus,$othertitle);
17335: }
17336: if (scalar(@shownstatus) == 1+$numtypes) {
17337: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
17338: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
17339: } else {
17340: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
17341: if (ref($curr{'status'}) eq 'ARRAY') {
17342: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17343: if (@diffs) {
17344: $changes{'customrole'}{$rolename}{$access} = 1;
17345: }
17346: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17347: $changes{'customrole'}{$rolename}{$access} = 1;
17348: }
17349: }
17350: }
17351: } elsif (($access eq 'inc') || ($access eq 'exc')) {
17352: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
17353: my @newspecstaff;
17354: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17355: foreach my $person (sort(@personnel)) {
17356: if ($domhelpdesk{$person}) {
17357: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
17358: }
17359: }
17360: if (ref($curr{$access}) eq 'ARRAY') {
17361: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17362: if (@diffs) {
17363: $changes{'customrole'}{$rolename}{$access} = 1;
17364: }
17365: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17366: $changes{'customrole'}{$rolename}{$access} = 1;
17367: }
17368: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17369: my ($uname,$udom) = split(/:/,$person);
17370: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
17371: }
17372: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
17373: }
17374: } else {
17375: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
17376: }
17377: unless ($curr{'access'} eq $access) {
17378: $changes{'customrole'}{$rolename}{'access'} = 1;
17379: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
17380: }
17381: }
17382: if (@allpos > 0) {
17383: my $idx = 0;
17384: foreach my $rolename (@allpos) {
17385: if ($rolename ne '') {
17386: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
17387: if (ref($current{'adhoc'}) eq 'HASH') {
17388: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17389: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
17390: $changes{'customrole'}{$rolename}{'order'} = 1;
17391: $newsettings{$rolename}{'order'} = $idx+1;
17392: }
17393: }
17394: }
17395: $idx ++;
17396: }
17397: }
17398: }
17399: my $putresult;
17400: if (keys(%changes) > 0) {
17401: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
17402: if ($putresult eq 'ok') {
17403: if (ref($helphash{'helpsettings'}) eq 'HASH') {
17404: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
17405: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
17406: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
17407: }
17408: }
17409: my $cachetime = 24*60*60;
17410: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17411: if (ref($lastactref) eq 'HASH') {
17412: $lastactref->{'domdefaults'} = 1;
17413: }
17414: } else {
17415: $errors .= '<li><span class="LC_error">'.
17416: &mt('An error occurred storing the settings: [_1]',
17417: $putresult).'</span></li>';
17418: }
17419: }
17420: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
17421: $resulttext = &mt('Changes made:').'<ul>';
17422: my (%shownprivs,@levelorder);
17423: @levelorder = ('c','d','s');
17424: if ((keys(%changes)) && ($putresult eq 'ok')) {
17425: foreach my $item (sort(keys(%changes))) {
17426: if ($item eq 'submitbugs') {
17427: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
17428: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
17429: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
17430: } elsif ($item eq 'customrole') {
17431: if (ref($changes{'customrole'}) eq 'HASH') {
17432: my @keyorder = ('order','desc','access','status','exc','inc');
17433: my %keytext = &Apache::lonlocal::texthash(
17434: order => 'Order',
17435: desc => 'Role description',
17436: access => 'Role usage',
17437: status => 'Allowed institutional types',
17438: exc => 'Allowed personnel',
17439: inc => 'Disallowed personnel',
17440: );
17441: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
17442: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
17443: if ($role eq $newrole) {
17444: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
17445: $role).'<ul>';
17446: } else {
17447: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17448: $role).'<ul>';
17449: }
17450: foreach my $key (@keyorder) {
17451: if ($changes{'customrole'}{$role}{$key}) {
17452: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
17453: $keytext{$key},$newsettings{$role}{$key}).
17454: '</li>';
17455: }
17456: }
17457: if (ref($changedprivs{$role}) eq 'HASH') {
17458: $shownprivs{$role} = 1;
17459: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
17460: foreach my $level (@levelorder) {
17461: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17462: next if ($item eq '');
17463: my ($priv) = split(/\&/,$item,2);
17464: if (&Apache::lonnet::plaintext($priv)) {
17465: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17466: unless ($level eq 'c') {
17467: $resulttext .= ' ('.$lt{$level}.')';
17468: }
17469: $resulttext .= '</li>';
17470: }
17471: }
17472: }
17473: $resulttext .= '</ul>';
17474: }
17475: $resulttext .= '</ul></li>';
17476: }
17477: }
17478: }
17479: }
17480: }
17481: }
17482: if (keys(%changedprivs)) {
17483: foreach my $role (sort(keys(%changedprivs))) {
17484: unless ($shownprivs{$role}) {
17485: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17486: $role).'<ul>'.
17487: '<li>'.&mt('Privileges set to :').'<ul>';
17488: foreach my $level (@levelorder) {
17489: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17490: next if ($item eq '');
17491: my ($priv) = split(/\&/,$item,2);
17492: if (&Apache::lonnet::plaintext($priv)) {
17493: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17494: unless ($level eq 'c') {
17495: $resulttext .= ' ('.$lt{$level}.')';
17496: }
17497: $resulttext .= '</li>';
17498: }
17499: }
17500: }
17501: $resulttext .= '</ul></li></ul></li>';
17502: }
17503: }
17504: }
17505: $resulttext .= '</ul>';
17506: } else {
17507: $resulttext = &mt('No changes made to help settings');
17508: }
17509: if ($errors) {
17510: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
17511: $errors.'</ul>';
17512: }
17513: return $resulttext;
17514: }
17515:
17516: sub modify_coursedefaults {
17517: my ($dom,$lastactref,%domconfig) = @_;
17518: my ($resulttext,$errors,%changes,%defaultshash);
17519: my %defaultchecked = (
17520: 'uselcmath' => 'on',
17521: 'usejsme' => 'on',
17522: 'inline_chem' => 'on',
17523: 'ltiauth' => 'off',
17524: );
17525: my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
17526: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
17527: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
17528: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
17529: my @types = ('official','unofficial','community','textbook');
17530: my %staticdefaults = (
17531: anonsurvey_threshold => 10,
17532: uploadquota => 500,
17533: postsubmit => 60,
17534: mysqltables => 172800,
17535: );
17536: my %texoptions = (
17537: MathJax => 'MathJax',
17538: mimetex => &mt('Convert to Images'),
17539: tth => &mt('TeX to HTML'),
17540: );
17541: $defaultshash{'coursedefaults'} = {};
17542:
17543: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
17544: if ($domconfig{'coursedefaults'} eq '') {
17545: $domconfig{'coursedefaults'} = {};
17546: }
17547: }
17548:
17549: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
17550: foreach my $item (@toggles) {
17551: if ($defaultchecked{$item} eq 'on') {
17552: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17553: ($env{'form.'.$item} eq '0')) {
17554: $changes{$item} = 1;
17555: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
17556: $changes{$item} = 1;
17557: }
17558: } elsif ($defaultchecked{$item} eq 'off') {
17559: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17560: ($env{'form.'.$item} eq '1')) {
17561: $changes{$item} = 1;
17562: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
17563: $changes{$item} = 1;
17564: }
17565: }
17566: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
17567: }
17568: foreach my $item (@numbers) {
17569: my ($currdef,$newdef);
17570: $newdef = $env{'form.'.$item};
17571: if ($item eq 'anonsurvey_threshold') {
17572: $currdef = $domconfig{'coursedefaults'}{$item};
17573: $newdef =~ s/\D//g;
17574: if ($newdef eq '' || $newdef < 1) {
17575: $newdef = 1;
17576: }
17577: $defaultshash{'coursedefaults'}{$item} = $newdef;
17578: } else {
17579: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
17580: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
17581: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
17582: }
17583: $newdef =~ s/[^\w.\-]//g;
17584: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
17585: }
17586: if ($currdef ne $newdef) {
17587: if ($item eq 'anonsurvey_threshold') {
17588: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
17589: $changes{$item} = 1;
17590: }
17591: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
17592: my $setting = $1;
17593: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
17594: $changes{$setting} = 1;
17595: }
17596: }
17597: }
17598: }
17599: my $texengine;
17600: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
17601: $texengine = $env{'form.texengine'};
17602: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
17603: if ($currdef eq '') {
17604: unless ($texengine eq $Apache::lonnet::deftex) {
17605: $changes{'texengine'} = 1;
17606: }
17607: } elsif ($currdef ne $texengine) {
17608: $changes{'texengine'} = 1;
17609: }
17610: }
17611: if ($texengine ne '') {
17612: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
17613: }
17614: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
17615: my @currclonecode;
17616: if (ref($currclone) eq 'HASH') {
17617: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
17618: @currclonecode = @{$currclone->{'instcode'}};
17619: }
17620: }
17621: my $newclone;
17622: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
17623: $newclone = $env{'form.canclone'};
17624: }
17625: if ($newclone eq 'instcode') {
17626: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
17627: my (%codedefaults,@code_order,@clonecode);
17628: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
17629: \@code_order);
17630: foreach my $item (@code_order) {
17631: if (grep(/^\Q$item\E$/,@newcodes)) {
17632: push(@clonecode,$item);
17633: }
17634: }
17635: if (@clonecode) {
17636: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
17637: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
17638: if (@diffs) {
17639: $changes{'canclone'} = 1;
17640: }
17641: } else {
17642: $newclone eq '';
17643: }
17644: } elsif ($newclone ne '') {
17645: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
17646: }
17647: if ($newclone ne $currclone) {
17648: $changes{'canclone'} = 1;
17649: }
17650: my %credits;
17651: foreach my $type (@types) {
17652: unless ($type eq 'community') {
17653: $credits{$type} = $env{'form.'.$type.'_credits'};
17654: $credits{$type} =~ s/[^\d.]+//g;
17655: }
17656: }
17657: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
17658: ($env{'form.coursecredits'} eq '1')) {
17659: $changes{'coursecredits'} = 1;
17660: foreach my $type (keys(%credits)) {
17661: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17662: }
17663: } else {
17664: if ($env{'form.coursecredits'} eq '1') {
17665: foreach my $type (@types) {
17666: unless ($type eq 'community') {
17667: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
17668: $changes{'coursecredits'} = 1;
17669: }
17670: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17671: }
17672: }
17673: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17674: foreach my $type (@types) {
17675: unless ($type eq 'community') {
17676: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17677: $changes{'coursecredits'} = 1;
17678: last;
17679: }
17680: }
17681: }
17682: }
17683: }
17684: if ($env{'form.postsubmit'} eq '1') {
17685: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17686: my %currtimeout;
17687: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17688: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17689: $changes{'postsubmit'} = 1;
17690: }
17691: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17692: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17693: }
17694: } else {
17695: $changes{'postsubmit'} = 1;
17696: }
17697: foreach my $type (@types) {
17698: my $timeout = $env{'form.'.$type.'_timeout'};
17699: $timeout =~ s/\D//g;
17700: if ($timeout == $staticdefaults{'postsubmit'}) {
17701: $timeout = '';
17702: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17703: $timeout = '0';
17704: }
17705: unless ($timeout eq '') {
17706: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17707: }
17708: if (exists($currtimeout{$type})) {
17709: if ($timeout ne $currtimeout{$type}) {
17710: $changes{'postsubmit'} = 1;
17711: }
17712: } elsif ($timeout ne '') {
17713: $changes{'postsubmit'} = 1;
17714: }
17715: }
17716: } else {
17717: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17718: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17719: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17720: $changes{'postsubmit'} = 1;
17721: }
17722: } else {
17723: $changes{'postsubmit'} = 1;
17724: }
17725: }
17726: }
17727: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17728: $dom);
17729: if ($putresult eq 'ok') {
17730: if (keys(%changes) > 0) {
17731: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17732: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
17733: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
17734: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
17735: ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
17736: foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
17737: if ($changes{$item}) {
17738: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17739: }
17740: }
17741: if ($changes{'coursecredits'}) {
17742: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17743: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17744: $domdefaults{$type.'credits'} =
17745: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17746: }
17747: }
17748: }
17749: if ($changes{'postsubmit'}) {
17750: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17751: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17752: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17753: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17754: $domdefaults{$type.'postsubtimeout'} =
17755: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17756: }
17757: }
17758: }
17759: }
17760: if ($changes{'uploadquota'}) {
17761: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17762: foreach my $type (@types) {
17763: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17764: }
17765: }
17766: }
17767: if ($changes{'canclone'}) {
17768: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17769: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17770: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17771: if (@clonecodes) {
17772: $domdefaults{'canclone'} = join('+',@clonecodes);
17773: }
17774: }
17775: } else {
17776: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17777: }
17778: }
17779: my $cachetime = 24*60*60;
17780: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17781: if (ref($lastactref) eq 'HASH') {
17782: $lastactref->{'domdefaults'} = 1;
17783: }
17784: }
17785: $resulttext = &mt('Changes made:').'<ul>';
17786: foreach my $item (sort(keys(%changes))) {
17787: if ($item eq 'uselcmath') {
17788: if ($env{'form.'.$item} eq '1') {
17789: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
17790: } else {
17791: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17792: }
17793: } elsif ($item eq 'usejsme') {
17794: if ($env{'form.'.$item} eq '1') {
17795: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17796: } else {
17797: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
17798: }
17799: } elsif ($item eq 'inline_chem') {
17800: if ($env{'form.'.$item} eq '1') {
17801: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
17802: } else {
17803: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
17804: }
17805: } elsif ($item eq 'texengine') {
17806: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17807: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17808: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17809: }
17810: } elsif ($item eq 'anonsurvey_threshold') {
17811: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
17812: } elsif ($item eq 'uploadquota') {
17813: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17814: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17815: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17816: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
17817: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
17818:
17819: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17820: '</ul>'.
17821: '</li>';
17822: } else {
17823: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17824: }
17825: } elsif ($item eq 'mysqltables') {
17826: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17827: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17828: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17829: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17830: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17831: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17832: '</ul>'.
17833: '</li>';
17834: } else {
17835: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17836: }
17837: } elsif ($item eq 'postsubmit') {
17838: if ($domdefaults{'postsubmit'} eq 'off') {
17839: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17840: } else {
17841: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
17842: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17843: $resulttext .= &mt('durations:').'<ul>';
17844: foreach my $type (@types) {
17845: $resulttext .= '<li>';
17846: my $timeout;
17847: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17848: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17849: }
17850: my $display;
17851: if ($timeout eq '0') {
17852: $display = &mt('unlimited');
17853: } elsif ($timeout eq '') {
17854: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17855: } else {
17856: $display = &mt('[quant,_1,second]',$timeout);
17857: }
17858: if ($type eq 'community') {
17859: $resulttext .= &mt('Communities');
17860: } elsif ($type eq 'official') {
17861: $resulttext .= &mt('Official courses');
17862: } elsif ($type eq 'unofficial') {
17863: $resulttext .= &mt('Unofficial courses');
17864: } elsif ($type eq 'textbook') {
17865: $resulttext .= &mt('Textbook courses');
17866: }
17867: $resulttext .= ' -- '.$display.'</li>';
17868: }
17869: $resulttext .= '</ul>';
17870: }
17871: $resulttext .= '</li>';
17872: }
17873: } elsif ($item eq 'coursecredits') {
17874: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17875: if (($domdefaults{'officialcredits'} eq '') &&
17876: ($domdefaults{'unofficialcredits'} eq '') &&
17877: ($domdefaults{'textbookcredits'} eq '')) {
17878: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17879: } else {
17880: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17881: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17882: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
17883: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
17884: '</ul>'.
17885: '</li>';
17886: }
17887: } else {
17888: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17889: }
17890: } elsif ($item eq 'canclone') {
17891: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17892: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17893: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17894: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17895: }
17896: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17897: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17898: } else {
17899: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
17900: }
17901: } elsif ($item eq 'ltiauth') {
17902: if ($env{'form.'.$item} eq '1') {
17903: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
17904: } else {
17905: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
17906: }
17907: }
17908: }
17909: $resulttext .= '</ul>';
17910: } else {
17911: $resulttext = &mt('No changes made to course defaults');
17912: }
17913: } else {
17914: $resulttext = '<span class="LC_error">'.
17915: &mt('An error occurred: [_1]',$putresult).'</span>';
17916: }
17917: return $resulttext;
17918: }
17919:
17920: sub modify_selfenrollment {
17921: my ($dom,$lastactref,%domconfig) = @_;
17922: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
17923: my @types = ('official','unofficial','community','textbook');
17924: my %titles = &tool_titles();
17925: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17926: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
17927: $ordered{'default'} = ['types','registered','approval','limit'];
17928:
17929: my (%roles,%shown,%toplevel);
17930: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17931:
17932: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17933: if ($domconfig{'selfenrollment'} eq '') {
17934: $domconfig{'selfenrollment'} = {};
17935: }
17936: }
17937: %toplevel = (
17938: admin => 'Configuration Rights',
17939: default => 'Default settings',
17940: validation => 'Validation of self-enrollment requests',
17941: );
17942: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
17943:
17944: if (ref($ordered{'admin'}) eq 'ARRAY') {
17945: foreach my $item (@{$ordered{'admin'}}) {
17946: foreach my $type (@types) {
17947: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17948: $selfenrollhash{'admin'}{$type}{$item} = 1;
17949: } else {
17950: $selfenrollhash{'admin'}{$type}{$item} = 0;
17951: }
17952: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17953: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17954: if ($selfenrollhash{'admin'}{$type}{$item} ne
17955: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17956: push(@{$changes{'admin'}{$type}},$item);
17957: }
17958: } else {
17959: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17960: push(@{$changes{'admin'}{$type}},$item);
17961: }
17962: }
17963: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17964: push(@{$changes{'admin'}{$type}},$item);
17965: }
17966: }
17967: }
17968: }
17969:
17970: foreach my $item (@{$ordered{'default'}}) {
17971: foreach my $type (@types) {
17972: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17973: if ($item eq 'types') {
17974: unless (($value eq 'all') || ($value eq 'dom')) {
17975: $value = '';
17976: }
17977: } elsif ($item eq 'registered') {
17978: unless ($value eq '1') {
17979: $value = 0;
17980: }
17981: } elsif ($item eq 'approval') {
17982: unless ($value =~ /^[012]$/) {
17983: $value = 0;
17984: }
17985: } else {
17986: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17987: $value = 'none';
17988: }
17989: }
17990: $selfenrollhash{'default'}{$type}{$item} = $value;
17991: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17992: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17993: if ($selfenrollhash{'default'}{$type}{$item} ne
17994: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17995: push(@{$changes{'default'}{$type}},$item);
17996: }
17997: } else {
17998: push(@{$changes{'default'}{$type}},$item);
17999: }
18000: } else {
18001: push(@{$changes{'default'}{$type}},$item);
18002: }
18003: if ($item eq 'limit') {
18004: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
18005: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
18006: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
18007: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
18008: }
18009: } else {
18010: $selfenrollhash{'default'}{$type}{'cap'} = '';
18011: }
18012: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
18013: if ($selfenrollhash{'default'}{$type}{'cap'} ne
18014: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
18015: push(@{$changes{'default'}{$type}},'cap');
18016: }
18017: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
18018: push(@{$changes{'default'}{$type}},'cap');
18019: }
18020: }
18021: }
18022: }
18023:
18024: foreach my $item (@{$itemsref}) {
18025: if ($item eq 'fields') {
18026: my @changed;
18027: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
18028: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
18029: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
18030: }
18031: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18032: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
18033: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
18034: $domconfig{'selfenrollment'}{'validation'}{$item});
18035: } else {
18036: @changed = @{$selfenrollhash{'validation'}{$item}};
18037: }
18038: } else {
18039: @changed = @{$selfenrollhash{'validation'}{$item}};
18040: }
18041: if (@changed) {
18042: if ($selfenrollhash{'validation'}{$item}) {
18043: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
18044: } else {
18045: $changes{'validation'}{$item} = &mt('None');
18046: }
18047: }
18048: } else {
18049: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
18050: if ($item eq 'markup') {
18051: if ($env{'form.selfenroll_validation_'.$item}) {
18052: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
18053: }
18054: }
18055: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18056: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
18057: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
18058: }
18059: }
18060: }
18061: }
18062:
18063: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
18064: $dom);
18065: if ($putresult eq 'ok') {
18066: if (keys(%changes) > 0) {
18067: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18068: $resulttext = &mt('Changes made:').'<ul>';
18069: foreach my $key ('admin','default','validation') {
18070: if (ref($changes{$key}) eq 'HASH') {
18071: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
18072: if ($key eq 'validation') {
18073: foreach my $item (@{$itemsref}) {
18074: if (exists($changes{$key}{$item})) {
18075: if ($item eq 'markup') {
18076: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
18077: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
18078: } else {
18079: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
18080: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
18081: }
18082: }
18083: }
18084: } else {
18085: foreach my $type (@types) {
18086: if ($type eq 'community') {
18087: $roles{'1'} = &mt('Community personnel');
18088: } else {
18089: $roles{'1'} = &mt('Course personnel');
18090: }
18091: if (ref($changes{$key}{$type}) eq 'ARRAY') {
18092: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
18093: if ($key eq 'admin') {
18094: my @mgrdc = ();
18095: if (ref($ordered{$key}) eq 'ARRAY') {
18096: foreach my $item (@{$ordered{'admin'}}) {
18097: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
18098: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
18099: push(@mgrdc,$item);
18100: }
18101: }
18102: }
18103: if (@mgrdc) {
18104: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
18105: } else {
18106: delete($domdefaults{$type.'selfenrolladmdc'});
18107: }
18108: }
18109: } else {
18110: if (ref($ordered{$key}) eq 'ARRAY') {
18111: foreach my $item (@{$ordered{$key}}) {
18112: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18113: $domdefaults{$type.'selfenroll'.$item} =
18114: $selfenrollhash{$key}{$type}{$item};
18115: }
18116: }
18117: }
18118: }
18119: }
18120: $resulttext .= '<li>'.$titles{$type}.'<ul>';
18121: foreach my $item (@{$ordered{$key}}) {
18122: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18123: $resulttext .= '<li>';
18124: if ($key eq 'admin') {
18125: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
18126: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
18127: } else {
18128: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
18129: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
18130: }
18131: $resulttext .= '</li>';
18132: }
18133: }
18134: $resulttext .= '</ul></li>';
18135: }
18136: }
18137: $resulttext .= '</ul></li>';
18138: }
18139: }
18140: }
18141: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
18142: my $cachetime = 24*60*60;
18143: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18144: if (ref($lastactref) eq 'HASH') {
18145: $lastactref->{'domdefaults'} = 1;
18146: }
18147: }
18148: $resulttext .= '</ul>';
18149: } else {
18150: $resulttext = &mt('No changes made to self-enrollment settings');
18151: }
18152: } else {
18153: $resulttext = '<span class="LC_error">'.
18154: &mt('An error occurred: [_1]',$putresult).'</span>';
18155: }
18156: return $resulttext;
18157: }
18158:
18159: sub modify_wafproxy {
18160: my ($dom,$action,$lastactref,%domconfig) = @_;
18161: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18162: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
18163: %wafproxy,%changes,%expirecache,%expiresaml);
18164: foreach my $server (sort(keys(%servers))) {
18165: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
18166: if ($serverhome eq $server) {
18167: my $serverdom = &Apache::lonnet::host_domain($server);
18168: if ($serverdom eq $dom) {
18169: $canset{$server} = 1;
18170: }
18171: }
18172: }
18173: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
18174: %{$values{$dom}} = ();
18175: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
18176: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
18177: }
18178: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
18179: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
18180: }
18181: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18182: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
18183: }
18184: }
18185: my $output;
18186: if (keys(%canset)) {
18187: %{$wafproxy{'alias'}} = ();
18188: %{$wafproxy{'saml'}} = ();
18189: foreach my $key (sort(keys(%canset))) {
18190: if ($env{'form.wafproxy_'.$dom}) {
18191: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
18192: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
18193: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
18194: $changes{'alias'} = 1;
18195: }
18196: if ($env{'form.wafproxy_alias_saml_'.$key}) {
18197: $wafproxy{'saml'}{$key} = 1;
18198: }
18199: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
18200: $changes{'saml'} = 1;
18201: }
18202: } else {
18203: $wafproxy{'alias'}{$key} = '';
18204: $wafproxy{'saml'}{$key} = '';
18205: if ($curralias{$key}) {
18206: $changes{'alias'} = 1;
18207: }
18208: if ($currsaml{$key}) {
18209: $changes{'saml'} = 1;
18210: }
18211: }
18212: if ($wafproxy{'alias'}{$key} eq '') {
18213: if ($curralias{$key}) {
18214: $expirecache{$key} = 1;
18215: }
18216: delete($wafproxy{'alias'}{$key});
18217: }
18218: if ($wafproxy{'saml'}{$key} eq '') {
18219: if ($currsaml{$key}) {
18220: $expiresaml{$key} = 1;
18221: }
18222: delete($wafproxy{'saml'}{$key});
18223: }
18224: }
18225: unless (keys(%{$wafproxy{'alias'}})) {
18226: delete($wafproxy{'alias'});
18227: }
18228: unless (keys(%{$wafproxy{'saml'}})) {
18229: delete($wafproxy{'saml'});
18230: }
18231: # Localization for values in %warn occurs in &mt() calls separately.
18232: my %warn = (
18233: trusted => 'trusted IP range(s)',
18234: vpnint => 'internal IP range(s) for VPN sessions(s)',
18235: vpnext => 'IP range(s) for backend WAF connections',
18236: );
18237: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18238: my $possible = $env{'form.wafproxy_'.$item};
18239: $possible =~ s/^\s+|\s+$//g;
18240: if ($possible ne '') {
18241: if ($item eq 'remoteip') {
18242: if ($possible =~ /^[mhn]$/) {
18243: $wafproxy{$item} = $possible;
18244: }
18245: } elsif ($item eq 'ipheader') {
18246: if ($wafproxy{'remoteip'} eq 'h') {
18247: $wafproxy{$item} = $possible;
18248: }
18249: } elsif ($item eq 'sslopt') {
18250: if ($possible =~ /^0|1$/) {
18251: $wafproxy{$item} = $possible;
18252: }
18253: } else {
18254: my (@ok,$count);
18255: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
18256: unless ($env{'form.wafproxy_vpnaccess'}) {
18257: $possible = '';
18258: }
18259: } elsif ($item eq 'trusted') {
18260: unless ($wafproxy{'remoteip'} eq 'h') {
18261: $possible = '';
18262: }
18263: }
18264: unless ($possible eq '') {
18265: $possible =~ s/[\r\n]+/\s/g;
18266: $possible =~ s/\s*-\s*/-/g;
18267: $possible =~ s/\s+/,/g;
18268: $possible =~ s/,+/,/g;
18269: }
18270: $count = 0;
18271: if ($possible ne '') {
18272: foreach my $poss (split(/\,/,$possible)) {
18273: $count ++;
18274: $poss = &validate_ip_pattern($poss);
18275: if ($poss ne '') {
18276: push(@ok,$poss);
18277: }
18278: }
18279: my $diff = $count - scalar(@ok);
18280: if ($diff) {
18281: push(@warnings,'<li>'.
18282: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
18283: $diff,$warn{$item}).
18284: '</li>');
18285: }
18286: if (@ok) {
18287: my @cidr_list;
18288: foreach my $item (@ok) {
18289: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
18290: }
18291: $wafproxy{$item} = join(',',@cidr_list);
18292: }
18293: }
18294: }
18295: if ($wafproxy{$item} ne $currvalue{$item}) {
18296: $changes{$item} = 1;
18297: }
18298: } elsif ($currvalue{$item}) {
18299: $changes{$item} = 1;
18300: }
18301: }
18302: } else {
18303: if (keys(%curralias)) {
18304: $changes{'alias'} = 1;
18305: }
18306: if (keys(%currsaml)) {
18307: $changes{'saml'} = 1;
18308: }
18309: if (keys(%currvalue)) {
18310: foreach my $key (keys(%currvalue)) {
18311: $changes{$key} = 1;
18312: }
18313: }
18314: }
18315: if (keys(%changes)) {
18316: my %defaultshash = (
18317: wafproxy => \%wafproxy,
18318: );
18319: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18320: $dom);
18321: if ($putresult eq 'ok') {
18322: my $cachetime = 24*60*60;
18323: my (%domdefaults,$updatedomdefs);
18324: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
18325: if ($changes{$item}) {
18326: unless ($updatedomdefs) {
18327: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18328: $updatedomdefs = 1;
18329: }
18330: if ($wafproxy{$item}) {
18331: $domdefaults{'waf_'.$item} = $wafproxy{$item};
18332: } elsif (exists($domdefaults{'waf_'.$item})) {
18333: delete($domdefaults{'waf_'.$item});
18334: }
18335: }
18336: }
18337: if ($updatedomdefs) {
18338: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18339: if (ref($lastactref) eq 'HASH') {
18340: $lastactref->{'domdefaults'} = 1;
18341: }
18342: }
18343: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
18344: my %updates = %expirecache;
18345: foreach my $key (keys(%expirecache)) {
18346: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
18347: }
18348: if (ref($wafproxy{'alias'}) eq 'HASH') {
18349: my $cachetime = 24*60*60;
18350: foreach my $key (keys(%{$wafproxy{'alias'}})) {
18351: $updates{$key} = 1;
18352: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
18353: $cachetime);
18354: }
18355: }
18356: if (ref($lastactref) eq 'HASH') {
18357: $lastactref->{'proxyalias'} = \%updates;
18358: }
18359: }
18360: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
18361: my %samlupdates = %expiresaml;
18362: foreach my $key (keys(%expiresaml)) {
18363: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
18364: }
18365: if (ref($wafproxy{'saml'}) eq 'HASH') {
18366: my $cachetime = 24*60*60;
18367: foreach my $key (keys(%{$wafproxy{'saml'}})) {
18368: $samlupdates{$key} = 1;
18369: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
18370: $cachetime);
18371: }
18372: }
18373: if (ref($lastactref) eq 'HASH') {
18374: $lastactref->{'proxysaml'} = \%samlupdates;
18375: }
18376: }
18377: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
18378: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18379: if ($changes{$item}) {
18380: if ($item eq 'alias') {
18381: my $numaliased = 0;
18382: if (ref($wafproxy{'alias'}) eq 'HASH') {
18383: my $shown;
18384: if (keys(%{$wafproxy{'alias'}})) {
18385: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
18386: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
18387: &Apache::lonnet::hostname($server),
18388: $wafproxy{'alias'}{$server}).'</li>';
18389: $numaliased ++;
18390: }
18391: if ($numaliased) {
18392: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
18393: '<ul>'.$shown.'</ul>').'</li>';
18394: }
18395: }
18396: }
18397: unless ($numaliased) {
18398: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
18399: }
18400: } elsif ($item eq 'saml') {
18401: my $shown;
18402: if (ref($wafproxy{'saml'}) eq 'HASH') {
18403: if (keys(%{$wafproxy{'saml'}})) {
18404: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
18405: }
18406: }
18407: if ($shown) {
18408: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
18409: $shown).'</li>';
18410: } else {
18411: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
18412: }
18413: } else {
18414: if ($item eq 'remoteip') {
18415: my %ip_methods = &remoteip_methods();
18416: if ($wafproxy{$item} =~ /^[mh]$/) {
18417: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
18418: $ip_methods{$wafproxy{$item}}).'</li>';
18419: } else {
18420: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
18421: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
18422: '</li>';
18423: } else {
18424: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
18425: }
18426: }
18427: } elsif ($item eq 'ipheader') {
18428: if ($wafproxy{$item}) {
18429: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
18430: $wafproxy{$item}).'</li>';
18431: } else {
18432: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
18433: }
18434: } elsif ($item eq 'trusted') {
18435: if ($wafproxy{$item}) {
18436: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
18437: $wafproxy{$item}).'</li>';
18438: } else {
18439: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
18440: }
18441: } elsif ($item eq 'vpnint') {
18442: if ($wafproxy{$item}) {
18443: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
18444: $wafproxy{$item}).'</li>';
18445: } else {
18446: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
18447: }
18448: } elsif ($item eq 'vpnext') {
18449: if ($wafproxy{$item}) {
18450: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
18451: $wafproxy{$item}).'</li>';
18452: } else {
18453: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
18454: }
18455: } elsif ($item eq 'sslopt') {
18456: if ($wafproxy{$item}) {
18457: $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>';
18458: } else {
18459: $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>';
18460: }
18461: }
18462: }
18463: }
18464: }
18465: } else {
18466: $output = '<span class="LC_error">'.
18467: &mt('An error occurred: [_1]',$putresult).'</span>';
18468: }
18469: } elsif (keys(%canset)) {
18470: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
18471: }
18472: if (@warnings) {
18473: $output .= '<br />'.&mt('Warnings:').'<ul>'.
18474: join("\n",@warnings).'</ul>';
18475: }
18476: return $output;
18477: }
18478:
18479: sub validate_ip_pattern {
18480: my ($pattern) = @_;
18481: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
18482: my ($start,$end) = ($1,$2);
18483: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
18484: if (($start !~ m{/}) && ($end !~ m{/})) {
18485: return $start.'-'.$end;
18486: }
18487: }
18488: } elsif ($pattern ne '') {
18489: $pattern = &Net::CIDR::cidrvalidate($pattern);
18490: if ($pattern ne '') {
18491: return $pattern;
18492: }
18493: }
18494: return;
18495: }
18496:
18497: sub modify_usersessions {
18498: my ($dom,$lastactref,%domconfig) = @_;
18499: my @hostingtypes = ('version','excludedomain','includedomain');
18500: my @offloadtypes = ('primary','default');
18501: my %types = (
18502: remote => \@hostingtypes,
18503: hosted => \@hostingtypes,
18504: spares => \@offloadtypes,
18505: );
18506: my @prefixes = ('remote','hosted','spares');
18507: my @lcversions = &Apache::lonnet::all_loncaparevs();
18508: my (%by_ip,%by_location,@intdoms);
18509: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
18510: my @locations = sort(keys(%by_location));
18511: my (%defaultshash,%changes);
18512: foreach my $prefix (@prefixes) {
18513: $defaultshash{'usersessions'}{$prefix} = {};
18514: }
18515: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18516: my $resulttext;
18517: my %iphost = &Apache::lonnet::get_iphost();
18518: foreach my $prefix (@prefixes) {
18519: next if ($prefix eq 'spares');
18520: foreach my $type (@{$types{$prefix}}) {
18521: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18522: if ($type eq 'version') {
18523: my $value = $env{'form.'.$prefix.'_'.$type};
18524: my $okvalue;
18525: if ($value ne '') {
18526: if (grep(/^\Q$value\E$/,@lcversions)) {
18527: $okvalue = $value;
18528: }
18529: }
18530: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18531: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18532: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
18533: if ($inuse == 0) {
18534: $changes{$prefix}{$type} = 1;
18535: } else {
18536: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
18537: $changes{$prefix}{$type} = 1;
18538: }
18539: if ($okvalue ne '') {
18540: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18541: }
18542: }
18543: } else {
18544: if (($inuse == 1) && ($okvalue ne '')) {
18545: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18546: $changes{$prefix}{$type} = 1;
18547: }
18548: }
18549: } else {
18550: if (($inuse == 1) && ($okvalue ne '')) {
18551: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18552: $changes{$prefix}{$type} = 1;
18553: }
18554: }
18555: } else {
18556: if (($inuse == 1) && ($okvalue ne '')) {
18557: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18558: $changes{$prefix}{$type} = 1;
18559: }
18560: }
18561: } else {
18562: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18563: my @okvals;
18564: foreach my $val (@vals) {
18565: if ($val =~ /:/) {
18566: my @items = split(/:/,$val);
18567: foreach my $item (@items) {
18568: if (ref($by_location{$item}) eq 'ARRAY') {
18569: push(@okvals,$item);
18570: }
18571: }
18572: } else {
18573: if (ref($by_location{$val}) eq 'ARRAY') {
18574: push(@okvals,$val);
18575: }
18576: }
18577: }
18578: @okvals = sort(@okvals);
18579: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18580: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18581: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18582: if ($inuse == 0) {
18583: $changes{$prefix}{$type} = 1;
18584: } else {
18585: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18586: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
18587: if (@changed > 0) {
18588: $changes{$prefix}{$type} = 1;
18589: }
18590: }
18591: } else {
18592: if ($inuse == 1) {
18593: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18594: $changes{$prefix}{$type} = 1;
18595: }
18596: }
18597: } else {
18598: if ($inuse == 1) {
18599: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18600: $changes{$prefix}{$type} = 1;
18601: }
18602: }
18603: } else {
18604: if ($inuse == 1) {
18605: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18606: $changes{$prefix}{$type} = 1;
18607: }
18608: }
18609: }
18610: }
18611: }
18612:
18613: my @alldoms = &Apache::lonnet::all_domains();
18614: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18615: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
18616: my $savespares;
18617:
18618: foreach my $lonhost (sort(keys(%servers))) {
18619: my $serverhomeID =
18620: &Apache::lonnet::get_server_homeID($servers{$lonhost});
18621: my $serverhostname = &Apache::lonnet::hostname($lonhost);
18622: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
18623: my %spareschg;
18624: foreach my $type (@{$types{'spares'}}) {
18625: my @okspares;
18626: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
18627: foreach my $server (@checked) {
18628: if (&Apache::lonnet::hostname($server) ne '') {
18629: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
18630: unless (grep(/^\Q$server\E$/,@okspares)) {
18631: push(@okspares,$server);
18632: }
18633: }
18634: }
18635: }
18636: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
18637: my $newspare;
18638: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
18639: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
18640: $newspare = $new;
18641: }
18642: }
18643: my @spares;
18644: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
18645: @spares = sort(@okspares,$newspare);
18646: } else {
18647: @spares = sort(@okspares);
18648: }
18649: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
18650: if (ref($spareid{$lonhost}) eq 'HASH') {
18651: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
18652: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
18653: if (@diffs > 0) {
18654: $spareschg{$type} = 1;
18655: }
18656: }
18657: }
18658: }
18659: if (keys(%spareschg) > 0) {
18660: $changes{'spares'}{$lonhost} = \%spareschg;
18661: }
18662: }
18663: $defaultshash{'usersessions'}{'offloadnow'} = {};
18664: $defaultshash{'usersessions'}{'offloadoth'} = {};
18665: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
18666: my @okoffload;
18667: if (@offloadnow) {
18668: foreach my $server (@offloadnow) {
18669: if (&Apache::lonnet::hostname($server) ne '') {
18670: unless (grep(/^\Q$server\E$/,@okoffload)) {
18671: push(@okoffload,$server);
18672: }
18673: }
18674: }
18675: if (@okoffload) {
18676: foreach my $lonhost (@okoffload) {
18677: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
18678: }
18679: }
18680: }
18681: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
18682: my @okoffloadoth;
18683: if (@offloadoth) {
18684: foreach my $server (@offloadoth) {
18685: if (&Apache::lonnet::hostname($server) ne '') {
18686: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
18687: push(@okoffloadoth,$server);
18688: }
18689: }
18690: }
18691: if (@okoffloadoth) {
18692: foreach my $lonhost (@okoffloadoth) {
18693: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
18694: }
18695: }
18696: }
18697: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18698: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
18699: if (ref($changes{'spares'}) eq 'HASH') {
18700: if (keys(%{$changes{'spares'}}) > 0) {
18701: $savespares = 1;
18702: }
18703: }
18704: } else {
18705: $savespares = 1;
18706: }
18707: foreach my $offload ('offloadnow','offloadoth') {
18708: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
18709: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
18710: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
18711: $changes{$offload} = 1;
18712: last;
18713: }
18714: }
18715: unless ($changes{$offload}) {
18716: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
18717: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
18718: $changes{$offload} = 1;
18719: last;
18720: }
18721: }
18722: }
18723: } else {
18724: if (($offload eq 'offloadnow') && (@okoffload)) {
18725: $changes{'offloadnow'} = 1;
18726: }
18727: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
18728: $changes{'offloadoth'} = 1;
18729: }
18730: }
18731: }
18732: } else {
18733: if (@okoffload) {
18734: $changes{'offloadnow'} = 1;
18735: }
18736: if (@okoffloadoth) {
18737: $changes{'offloadoth'} = 1;
18738: }
18739: }
18740: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18741: if ((keys(%changes) > 0) || ($savespares)) {
18742: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18743: $dom);
18744: if ($putresult eq 'ok') {
18745: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18746: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18747: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18748: }
18749: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18750: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18751: }
18752: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18753: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18754: }
18755: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18756: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
18757: }
18758: }
18759: my $cachetime = 24*60*60;
18760: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18761: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
18762: if (ref($lastactref) eq 'HASH') {
18763: $lastactref->{'domdefaults'} = 1;
18764: $lastactref->{'usersessions'} = 1;
18765: }
18766: if (keys(%changes) > 0) {
18767: my %lt = &usersession_titles();
18768: $resulttext = &mt('Changes made:').'<ul>';
18769: foreach my $prefix (@prefixes) {
18770: if (ref($changes{$prefix}) eq 'HASH') {
18771: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18772: if ($prefix eq 'spares') {
18773: if (ref($changes{$prefix}) eq 'HASH') {
18774: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18775: $resulttext .= '<li><b>'.$lonhost.'</b> ';
18776: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
18777: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18778: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
18779: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18780: foreach my $type (@{$types{$prefix}}) {
18781: if ($changes{$prefix}{$lonhost}{$type}) {
18782: my $offloadto = &mt('None');
18783: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18784: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18785: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18786: }
18787: }
18788: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
18789: }
18790: }
18791: }
18792: $resulttext .= '</li>';
18793: }
18794: }
18795: } else {
18796: foreach my $type (@{$types{$prefix}}) {
18797: if (defined($changes{$prefix}{$type})) {
18798: my $newvalue;
18799: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18800: if (ref($defaultshash{'usersessions'}{$prefix})) {
18801: if ($type eq 'version') {
18802: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
18803: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18804: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18805: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18806: }
18807: }
18808: }
18809: }
18810: if ($newvalue eq '') {
18811: if ($type eq 'version') {
18812: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
18813: } else {
18814: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18815: }
18816: } else {
18817: if ($type eq 'version') {
18818: $newvalue .= ' '.&mt('(or later)');
18819: }
18820: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
18821: }
18822: }
18823: }
18824: }
18825: $resulttext .= '</ul>';
18826: }
18827: }
18828: if ($changes{'offloadnow'}) {
18829: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18830: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
18831: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
18832: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18833: $resulttext .= '<li>'.$lonhost.'</li>';
18834: }
18835: $resulttext .= '</ul>';
18836: } else {
18837: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
18838: }
18839: } else {
18840: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
18841: }
18842: }
18843: if ($changes{'offloadoth'}) {
18844: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18845: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
18846: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
18847: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
18848: $resulttext .= '<li>'.$lonhost.'</li>';
18849: }
18850: $resulttext .= '</ul>';
18851: } else {
18852: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
18853: }
18854: } else {
18855: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
18856: }
18857: }
18858: $resulttext .= '</ul>';
18859: } else {
18860: $resulttext = $nochgmsg;
18861: }
18862: } else {
18863: $resulttext = '<span class="LC_error">'.
18864: &mt('An error occurred: [_1]',$putresult).'</span>';
18865: }
18866: } else {
18867: $resulttext = $nochgmsg;
18868: }
18869: return $resulttext;
18870: }
18871:
18872: sub modify_loadbalancing {
18873: my ($dom,%domconfig) = @_;
18874: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18875: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18876: my ($othertitle,$usertypes,$types) =
18877: &Apache::loncommon::sorted_inst_types($dom);
18878: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18879: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
18880: my @sparestypes = ('primary','default');
18881: my %typetitles = &sparestype_titles();
18882: my $resulttext;
18883: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
18884: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18885: %existing = %{$domconfig{'loadbalancing'}};
18886: }
18887: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
18888: \%currtargets,\%currrules,\%currcookies);
18889: my ($saveloadbalancing,%defaultshash,%changes);
18890: my ($alltypes,$othertypes,$titles) =
18891: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18892: my %ruletitles = &offloadtype_text();
18893: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18894: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18895: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18896: if ($balancer eq '') {
18897: next;
18898: }
18899: if (!exists($servers{$balancer})) {
18900: if (exists($currbalancer{$balancer})) {
18901: push(@{$changes{'delete'}},$balancer);
18902: }
18903: next;
18904: }
18905: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18906: push(@{$changes{'delete'}},$balancer);
18907: next;
18908: }
18909: if (!exists($currbalancer{$balancer})) {
18910: push(@{$changes{'add'}},$balancer);
18911: }
18912: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18913: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18914: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18915: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18916: $saveloadbalancing = 1;
18917: }
18918: foreach my $sparetype (@sparestypes) {
18919: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18920: my @offloadto;
18921: foreach my $target (@targets) {
18922: if (($servers{$target}) && ($target ne $balancer)) {
18923: if ($sparetype eq 'default') {
18924: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18925: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
18926: }
18927: }
18928: unless(grep(/^\Q$target\E$/,@offloadto)) {
18929: push(@offloadto,$target);
18930: }
18931: }
18932: }
18933: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18934: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18935: push(@offloadto,$balancer);
18936: }
18937: }
18938: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
18939: }
18940: if ($env{'form.loadbalancing_cookie_'.$i}) {
18941: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18942: if (exists($currbalancer{$balancer})) {
18943: unless ($currcookies{$balancer}) {
18944: $changes{'curr'}{$balancer}{'cookie'} = 1;
18945: }
18946: }
18947: } elsif (exists($currbalancer{$balancer})) {
18948: if ($currcookies{$balancer}) {
18949: $changes{'curr'}{$balancer}{'cookie'} = 1;
18950: }
18951: }
18952: if (ref($currtargets{$balancer}) eq 'HASH') {
18953: foreach my $sparetype (@sparestypes) {
18954: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18955: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
18956: if (@targetdiffs > 0) {
18957: $changes{'curr'}{$balancer}{'targets'} = 1;
18958: }
18959: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18960: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18961: $changes{'curr'}{$balancer}{'targets'} = 1;
18962: }
18963: }
18964: }
18965: } else {
18966: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
18967: foreach my $sparetype (@sparestypes) {
18968: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18969: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18970: $changes{'curr'}{$balancer}{'targets'} = 1;
18971: }
18972: }
18973: }
18974: }
18975: }
18976: my $ishomedom;
18977: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18978: $ishomedom = 1;
18979: }
18980: if (ref($alltypes) eq 'ARRAY') {
18981: foreach my $type (@{$alltypes}) {
18982: my $rule;
18983: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
18984: (!$ishomedom)) {
18985: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18986: }
18987: if ($rule eq 'specific') {
18988: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
18989: if (exists($servers{$specifiedhost})) {
18990: $rule = $specifiedhost;
18991: }
18992: }
18993: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18994: if (ref($currrules{$balancer}) eq 'HASH') {
18995: if ($rule ne $currrules{$balancer}{$type}) {
18996: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
18997: }
18998: } elsif ($rule ne '') {
18999: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
19000: }
19001: }
19002: }
19003: }
19004: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
19005: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
19006: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
19007: $defaultshash{'loadbalancing'} = {};
19008: }
19009: my $putresult = &Apache::lonnet::put_dom('configuration',
19010: \%defaultshash,$dom);
19011: if ($putresult eq 'ok') {
19012: if (keys(%changes) > 0) {
19013: my %toupdate;
19014: if (ref($changes{'delete'}) eq 'ARRAY') {
19015: foreach my $balancer (sort(@{$changes{'delete'}})) {
19016: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
19017: $toupdate{$balancer} = 1;
19018: }
19019: }
19020: if (ref($changes{'add'}) eq 'ARRAY') {
19021: foreach my $balancer (sort(@{$changes{'add'}})) {
19022: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
19023: $toupdate{$balancer} = 1;
19024: }
19025: }
19026: if (ref($changes{'curr'}) eq 'HASH') {
19027: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
19028: $toupdate{$balancer} = 1;
19029: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
19030: if ($changes{'curr'}{$balancer}{'targets'}) {
19031: my %offloadstr;
19032: foreach my $sparetype (@sparestypes) {
19033: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19034: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19035: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
19036: }
19037: }
19038: }
19039: if (keys(%offloadstr) == 0) {
19040: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
19041: } else {
19042: my $showoffload;
19043: foreach my $sparetype (@sparestypes) {
19044: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
19045: if (defined($offloadstr{$sparetype})) {
19046: $showoffload .= $offloadstr{$sparetype};
19047: } else {
19048: $showoffload .= &mt('None');
19049: }
19050: $showoffload .= (' 'x3);
19051: }
19052: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
19053: }
19054: }
19055: }
19056: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
19057: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
19058: foreach my $type (@{$alltypes}) {
19059: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
19060: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
19061: my $balancetext;
19062: if ($rule eq '') {
19063: $balancetext = $ruletitles{'default'};
19064: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
19065: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
19066: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
19067: foreach my $sparetype (@sparestypes) {
19068: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19069: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
19070: }
19071: }
19072: foreach my $item (@{$alltypes}) {
19073: next if ($item =~ /^_LC_ipchange/);
19074: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
19075: if ($hasrule eq 'homeserver') {
19076: map { $toupdate{$_} = 1; } (keys(%libraryservers));
19077: } else {
19078: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
19079: if ($servers{$hasrule}) {
19080: $toupdate{$hasrule} = 1;
19081: }
19082: }
19083: }
19084: }
19085: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
19086: $balancetext = $ruletitles{$rule};
19087: } else {
19088: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
19089: $balancetext = $ruletitles{'particular'}.' '.$receiver;
19090: if ($receiver) {
19091: $toupdate{$receiver};
19092: }
19093: }
19094: } else {
19095: $balancetext = $ruletitles{$rule};
19096: }
19097: } else {
19098: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
19099: }
19100: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
19101: }
19102: }
19103: }
19104: }
19105: if ($changes{'curr'}{$balancer}{'cookie'}) {
19106: if ($currcookies{$balancer}) {
19107: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
19108: $balancer).'</li>';
19109: } else {
19110: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
19111: $balancer).'</li>';
19112: }
19113: }
19114: }
19115: }
19116: if (keys(%toupdate)) {
19117: my %thismachine;
19118: my $updatedhere;
19119: my $cachetime = 60*60*24;
19120: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
19121: foreach my $lonhost (keys(%toupdate)) {
19122: if ($thismachine{$lonhost}) {
19123: unless ($updatedhere) {
19124: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
19125: $defaultshash{'loadbalancing'},
19126: $cachetime);
19127: $updatedhere = 1;
19128: }
19129: } else {
19130: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
19131: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
19132: }
19133: }
19134: }
19135: if ($resulttext ne '') {
19136: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
19137: } else {
19138: $resulttext = $nochgmsg;
19139: }
19140: } else {
19141: $resulttext = $nochgmsg;
19142: }
19143: } else {
19144: $resulttext = '<span class="LC_error">'.
19145: &mt('An error occurred: [_1]',$putresult).'</span>';
19146: }
19147: } else {
19148: $resulttext = $nochgmsg;
19149: }
19150: return $resulttext;
19151: }
19152:
19153: sub recurse_check {
19154: my ($chkcats,$categories,$depth,$name) = @_;
19155: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
19156: my $chg = 0;
19157: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
19158: my $category = $chkcats->[$depth]{$name}[$j];
19159: my $item;
19160: if ($category eq '') {
19161: $chg ++;
19162: } else {
19163: my $deeper = $depth + 1;
19164: $item = &escape($category).':'.&escape($name).':'.$depth;
19165: if ($chg) {
19166: $categories->{$item} -= $chg;
19167: }
19168: &recurse_check($chkcats,$categories,$deeper,$category);
19169: $deeper --;
19170: }
19171: }
19172: }
19173: return;
19174: }
19175:
19176: sub recurse_cat_deletes {
19177: my ($item,$coursecategories,$deletions) = @_;
19178: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
19179: my $subdepth = $depth + 1;
19180: if (ref($coursecategories) eq 'HASH') {
19181: foreach my $subitem (keys(%{$coursecategories})) {
19182: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
19183: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
19184: delete($coursecategories->{$subitem});
19185: $deletions->{$subitem} = 1;
19186: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
19187: }
19188: }
19189: }
19190: return;
19191: }
19192:
19193: sub active_dc_picker {
19194: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
19195: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
19196: my @domcoord = keys(%domcoords);
19197: if (keys(%currhash)) {
19198: foreach my $dc (keys(%currhash)) {
19199: unless (exists($domcoords{$dc})) {
19200: push(@domcoord,$dc);
19201: }
19202: }
19203: }
19204: @domcoord = sort(@domcoord);
19205: my $numdcs = scalar(@domcoord);
19206: my $rows = 0;
19207: my $table;
19208: if ($numdcs > 1) {
19209: $table = '<table>';
19210: for (my $i=0; $i<@domcoord; $i++) {
19211: my $rem = $i%($numinrow);
19212: if ($rem == 0) {
19213: if ($i > 0) {
19214: $table .= '</tr>';
19215: }
19216: $table .= '<tr>';
19217: $rows ++;
19218: }
19219: my $check = '';
19220: if ($inputtype eq 'radio') {
19221: if (keys(%currhash) == 0) {
19222: if (!$i) {
19223: $check = ' checked="checked"';
19224: }
19225: } elsif (exists($currhash{$domcoord[$i]})) {
19226: $check = ' checked="checked"';
19227: }
19228: } else {
19229: if (exists($currhash{$domcoord[$i]})) {
19230: $check = ' checked="checked"';
19231: }
19232: }
19233: if ($i == @domcoord - 1) {
19234: my $colsleft = $numinrow - $rem;
19235: if ($colsleft > 1) {
19236: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
19237: } else {
19238: $table .= '<td class="LC_left_item">';
19239: }
19240: } else {
19241: $table .= '<td class="LC_left_item">';
19242: }
19243: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
19244: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
19245: $table .= '<span class="LC_nobreak"><label>'.
19246: '<input type="'.$inputtype.'" name="'.$name.'"'.
19247: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
19248: if ($user ne $dcname.':'.$dcdom) {
19249: $table .= ' ('.$dcname.':'.$dcdom.')';
19250: }
19251: $table .= '</label></span></td>';
19252: }
19253: $table .= '</tr></table>';
19254: } elsif ($numdcs == 1) {
19255: my ($dcname,$dcdom) = split(':',$domcoord[0]);
19256: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
19257: if ($inputtype eq 'radio') {
19258: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
19259: if ($user ne $dcname.':'.$dcdom) {
19260: $table .= ' ('.$dcname.':'.$dcdom.')';
19261: }
19262: } else {
19263: my $check;
19264: if (exists($currhash{$domcoord[0]})) {
19265: $check = ' checked="checked"';
19266: }
19267: $table = '<span class="LC_nobreak"><label>'.
19268: '<input type="checkbox" name="'.$name.'" '.
19269: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
19270: if ($user ne $dcname.':'.$dcdom) {
19271: $table .= ' ('.$dcname.':'.$dcdom.')';
19272: }
19273: $table .= '</label></span>';
19274: $rows ++;
19275: }
19276: }
19277: return ($numdcs,$table,$rows);
19278: }
19279:
19280: sub usersession_titles {
19281: return &Apache::lonlocal::texthash(
19282: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
19283: remote => 'Hosting of sessions for users in this domain on servers in other domains',
19284: spares => 'Servers offloaded to, when busy',
19285: version => 'LON-CAPA version requirement',
19286: excludedomain => 'Allow all, but exclude specific domains',
19287: includedomain => 'Deny all, but include specific domains',
19288: primary => 'Primary (checked first)',
19289: default => 'Default',
19290: );
19291: }
19292:
19293: sub id_for_thisdom {
19294: my (%servers) = @_;
19295: my %altids;
19296: foreach my $server (keys(%servers)) {
19297: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19298: if ($serverhome ne $server) {
19299: $altids{$serverhome} = $server;
19300: }
19301: }
19302: return %altids;
19303: }
19304:
19305: sub count_servers {
19306: my ($currbalancer,%servers) = @_;
19307: my (@spares,$numspares);
19308: foreach my $lonhost (sort(keys(%servers))) {
19309: next if ($currbalancer eq $lonhost);
19310: push(@spares,$lonhost);
19311: }
19312: if ($currbalancer) {
19313: $numspares = scalar(@spares);
19314: } else {
19315: $numspares = scalar(@spares) - 1;
19316: }
19317: return ($numspares,@spares);
19318: }
19319:
19320: sub lonbalance_targets_js {
19321: my ($dom,$types,$servers,$settings) = @_;
19322: my $select = &mt('Select');
19323: my ($alltargets,$allishome,$allinsttypes,@alltypes);
19324: if (ref($servers) eq 'HASH') {
19325: $alltargets = join("','",sort(keys(%{$servers})));
19326: my @homedoms;
19327: foreach my $server (sort(keys(%{$servers}))) {
19328: if (&Apache::lonnet::host_domain($server) eq $dom) {
19329: push(@homedoms,'1');
19330: } else {
19331: push(@homedoms,'0');
19332: }
19333: }
19334: $allishome = join("','",@homedoms);
19335: }
19336: if (ref($types) eq 'ARRAY') {
19337: if (@{$types} > 0) {
19338: @alltypes = @{$types};
19339: }
19340: }
19341: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
19342: $allinsttypes = join("','",@alltypes);
19343: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
19344: if (ref($settings) eq 'HASH') {
19345: %existing = %{$settings};
19346: }
19347: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
19348: \%currtargets,\%currrules,\%currcookies);
19349: my $balancers = join("','",sort(keys(%currbalancer)));
19350: return <<"END";
19351:
19352: <script type="text/javascript">
19353: // <![CDATA[
19354:
19355: currBalancers = new Array('$balancers');
19356:
19357: function toggleTargets(balnum) {
19358: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19359: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
19360: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
19361: var prevbalancer = prevhostitem.value;
19362: var baltotal = document.getElementById('loadbalancing_total').value;
19363: prevhostitem.value = balancer;
19364: if (prevbalancer != '') {
19365: var prevIdx = currBalancers.indexOf(prevbalancer);
19366: if (prevIdx != -1) {
19367: currBalancers.splice(prevIdx,1);
19368: }
19369: }
19370: if (balancer == '') {
19371: hideSpares(balnum);
19372: } else {
19373: var currIdx = currBalancers.indexOf(balancer);
19374: if (currIdx == -1) {
19375: currBalancers.push(balancer);
19376: }
19377: var homedoms = new Array('$allishome');
19378: var ishomedom = homedoms[lonhostitem.selectedIndex];
19379: showSpares(balancer,ishomedom,balnum);
19380: }
19381: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
19382: return;
19383: }
19384:
19385: function showSpares(balancer,ishomedom,balnum) {
19386: var alltargets = new Array('$alltargets');
19387: var insttypes = new Array('$allinsttypes');
19388: var offloadtypes = new Array('primary','default');
19389:
19390: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
19391: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
19392:
19393: for (var i=0; i<offloadtypes.length; i++) {
19394: var count = 0;
19395: for (var j=0; j<alltargets.length; j++) {
19396: if (alltargets[j] != balancer) {
19397: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
19398: item.value = alltargets[j];
19399: item.style.textAlign='left';
19400: item.style.textFace='normal';
19401: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
19402: if (currBalancers.indexOf(alltargets[j]) == -1) {
19403: item.disabled = '';
19404: } else {
19405: item.disabled = 'disabled';
19406: item.checked = false;
19407: }
19408: count ++;
19409: }
19410: }
19411: }
19412: for (var k=0; k<insttypes.length; k++) {
19413: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
19414: if (ishomedom == 1) {
19415: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19416: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
19417: } else {
19418: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19419: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
19420: }
19421: } else {
19422: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19423: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
19424: }
19425: if ((insttypes[k] != '_LC_external') &&
19426: ((insttypes[k] != '_LC_internetdom') ||
19427: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
19428: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
19429: item.options.length = 0;
19430: item.options[0] = new Option("","",true,true);
19431: var idx = 0;
19432: for (var m=0; m<alltargets.length; m++) {
19433: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
19434: idx ++;
19435: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
19436: }
19437: }
19438: }
19439: }
19440: return;
19441: }
19442:
19443: function hideSpares(balnum) {
19444: var alltargets = new Array('$alltargets');
19445: var insttypes = new Array('$allinsttypes');
19446: var offloadtypes = new Array('primary','default');
19447:
19448: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
19449: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
19450:
19451: var total = alltargets.length - 1;
19452: for (var i=0; i<offloadtypes; i++) {
19453: for (var j=0; j<total; j++) {
19454: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
19455: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
19456: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
19457: }
19458: }
19459: for (var k=0; k<insttypes.length; k++) {
19460: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19461: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
19462: if (insttypes[k] != '_LC_external') {
19463: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
19464: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
19465: }
19466: }
19467: return;
19468: }
19469:
19470: function checkOffloads(item,balnum,type) {
19471: var alltargets = new Array('$alltargets');
19472: var offloadtypes = new Array('primary','default');
19473: if (item.checked) {
19474: var total = alltargets.length - 1;
19475: var other;
19476: if (type == offloadtypes[0]) {
19477: other = offloadtypes[1];
19478: } else {
19479: other = offloadtypes[0];
19480: }
19481: for (var i=0; i<total; i++) {
19482: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
19483: if (server == item.value) {
19484: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
19485: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
19486: }
19487: }
19488: }
19489: }
19490: return;
19491: }
19492:
19493: function singleServerToggle(balnum,type) {
19494: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
19495: if (offloadtoSelIdx == 0) {
19496: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
19497: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
19498:
19499: } else {
19500: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
19501: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
19502: }
19503: return;
19504: }
19505:
19506: function balanceruleChange(formname,balnum,type) {
19507: if (type == '_LC_external') {
19508: return;
19509: }
19510: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
19511: for (var i=0; i<typesRules.length; i++) {
19512: if (formname.elements[typesRules[i]].checked) {
19513: if (formname.elements[typesRules[i]].value != 'specific') {
19514: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
19515: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
19516: } else {
19517: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
19518: }
19519: }
19520: }
19521: return;
19522: }
19523:
19524: function balancerDeleteChange(balnum) {
19525: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19526: var baltotal = document.getElementById('loadbalancing_total').value;
19527: var addtarget;
19528: var removetarget;
19529: var action = 'delete';
19530: if (document.getElementById('loadbalancing_delete_'+balnum)) {
19531: var lonhost = hostitem.value;
19532: var currIdx = currBalancers.indexOf(lonhost);
19533: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
19534: if (currIdx != -1) {
19535: currBalancers.splice(currIdx,1);
19536: }
19537: addtarget = lonhost;
19538: } else {
19539: if (currIdx == -1) {
19540: currBalancers.push(lonhost);
19541: }
19542: removetarget = lonhost;
19543: action = 'undelete';
19544: }
19545: balancerChange(balnum,baltotal,action,addtarget,removetarget);
19546: }
19547: return;
19548: }
19549:
19550: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
19551: if (baltotal > 1) {
19552: var offloadtypes = new Array('primary','default');
19553: var alltargets = new Array('$alltargets');
19554: var insttypes = new Array('$allinsttypes');
19555: for (var i=0; i<baltotal; i++) {
19556: if (i != balnum) {
19557: for (var j=0; j<offloadtypes.length; j++) {
19558: var total = alltargets.length - 1;
19559: for (var k=0; k<total; k++) {
19560: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
19561: var server = serveritem.value;
19562: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19563: if (server == addtarget) {
19564: serveritem.disabled = '';
19565: }
19566: }
19567: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19568: if (server == removetarget) {
19569: serveritem.disabled = 'disabled';
19570: serveritem.checked = false;
19571: }
19572: }
19573: }
19574: }
19575: for (var j=0; j<insttypes.length; j++) {
19576: if (insttypes[j] != '_LC_external') {
19577: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
19578: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
19579: var currSel = singleserver.selectedIndex;
19580: var currVal = singleserver.options[currSel].value;
19581: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19582: var numoptions = singleserver.options.length;
19583: var needsnew = 1;
19584: for (var k=0; k<numoptions; k++) {
19585: if (singleserver.options[k] == addtarget) {
19586: needsnew = 0;
19587: break;
19588: }
19589: }
19590: if (needsnew == 1) {
19591: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
19592: }
19593: }
19594: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19595: singleserver.options.length = 0;
19596: if ((currVal) && (currVal != removetarget)) {
19597: singleserver.options[0] = new Option("","",false,false);
19598: } else {
19599: singleserver.options[0] = new Option("","",true,true);
19600: }
19601: var idx = 0;
19602: for (var m=0; m<alltargets.length; m++) {
19603: if (currBalancers.indexOf(alltargets[m]) == -1) {
19604: idx ++;
19605: if (currVal == alltargets[m]) {
19606: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
19607: } else {
19608: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
19609: }
19610: }
19611: }
19612: }
19613: }
19614: }
19615: }
19616: }
19617: }
19618: }
19619: return;
19620: }
19621:
19622: // ]]>
19623: </script>
19624:
19625: END
19626: }
19627:
19628: sub new_spares_js {
19629: my @sparestypes = ('primary','default');
19630: my $types = join("','",@sparestypes);
19631: my $select = &mt('Select');
19632: return <<"END";
19633:
19634: <script type="text/javascript">
19635: // <![CDATA[
19636:
19637: function updateNewSpares(formname,lonhost) {
19638: var types = new Array('$types');
19639: var include = new Array();
19640: var exclude = new Array();
19641: for (var i=0; i<types.length; i++) {
19642: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
19643: for (var j=0; j<spareboxes.length; j++) {
19644: if (formname.elements[spareboxes[j]].checked) {
19645: exclude.push(formname.elements[spareboxes[j]].value);
19646: } else {
19647: include.push(formname.elements[spareboxes[j]].value);
19648: }
19649: }
19650: }
19651: for (var i=0; i<types.length; i++) {
19652: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
19653: var selIdx = newSpare.selectedIndex;
19654: var currnew = newSpare.options[selIdx].value;
19655: var okSpares = new Array();
19656: for (var j=0; j<newSpare.options.length; j++) {
19657: var possible = newSpare.options[j].value;
19658: if (possible != '') {
19659: if (exclude.indexOf(possible) == -1) {
19660: okSpares.push(possible);
19661: } else {
19662: if (currnew == possible) {
19663: selIdx = 0;
19664: }
19665: }
19666: }
19667: }
19668: for (var k=0; k<include.length; k++) {
19669: if (okSpares.indexOf(include[k]) == -1) {
19670: okSpares.push(include[k]);
19671: }
19672: }
19673: okSpares.sort();
19674: newSpare.options.length = 0;
19675: if (selIdx == 0) {
19676: newSpare.options[0] = new Option("$select","",true,true);
19677: } else {
19678: newSpare.options[0] = new Option("$select","",false,false);
19679: }
19680: for (var m=0; m<okSpares.length; m++) {
19681: var idx = m+1;
19682: var selThis = 0;
19683: if (selIdx != 0) {
19684: if (okSpares[m] == currnew) {
19685: selThis = 1;
19686: }
19687: }
19688: if (selThis == 1) {
19689: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
19690: } else {
19691: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
19692: }
19693: }
19694: }
19695: return;
19696: }
19697:
19698: function checkNewSpares(lonhost,type) {
19699: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
19700: var chosen = newSpare.options[newSpare.selectedIndex].value;
19701: if (chosen != '') {
19702: var othertype;
19703: var othernewSpare;
19704: if (type == 'primary') {
19705: othernewSpare = document.getElementById('newspare_default_'+lonhost);
19706: }
19707: if (type == 'default') {
19708: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
19709: }
19710: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
19711: othernewSpare.selectedIndex = 0;
19712: }
19713: }
19714: return;
19715: }
19716:
19717: // ]]>
19718: </script>
19719:
19720: END
19721:
19722: }
19723:
19724: sub common_domprefs_js {
19725: return <<"END";
19726:
19727: <script type="text/javascript">
19728: // <![CDATA[
19729:
19730: function getIndicesByName(formname,item) {
19731: var group = new Array();
19732: for (var i=0;i<formname.elements.length;i++) {
19733: if (formname.elements[i].name == item) {
19734: group.push(formname.elements[i].id);
19735: }
19736: }
19737: return group;
19738: }
19739:
19740: // ]]>
19741: </script>
19742:
19743: END
19744:
19745: }
19746:
19747: sub recaptcha_js {
19748: my %lt = &captcha_phrases();
19749: return <<"END";
19750:
19751: <script type="text/javascript">
19752: // <![CDATA[
19753:
19754: function updateCaptcha(caller,context) {
19755: var privitem;
19756: var pubitem;
19757: var privtext;
19758: var pubtext;
19759: var versionitem;
19760: var versiontext;
19761: if (document.getElementById(context+'_recaptchapub')) {
19762: pubitem = document.getElementById(context+'_recaptchapub');
19763: } else {
19764: return;
19765: }
19766: if (document.getElementById(context+'_recaptchapriv')) {
19767: privitem = document.getElementById(context+'_recaptchapriv');
19768: } else {
19769: return;
19770: }
19771: if (document.getElementById(context+'_recaptchapubtxt')) {
19772: pubtext = document.getElementById(context+'_recaptchapubtxt');
19773: } else {
19774: return;
19775: }
19776: if (document.getElementById(context+'_recaptchaprivtxt')) {
19777: privtext = document.getElementById(context+'_recaptchaprivtxt');
19778: } else {
19779: return;
19780: }
19781: if (document.getElementById(context+'_recaptchaversion')) {
19782: versionitem = document.getElementById(context+'_recaptchaversion');
19783: } else {
19784: return;
19785: }
19786: if (document.getElementById(context+'_recaptchavertxt')) {
19787: versiontext = document.getElementById(context+'_recaptchavertxt');
19788: } else {
19789: return;
19790: }
19791: if (caller.checked) {
19792: if (caller.value == 'recaptcha') {
19793: pubitem.type = 'text';
19794: privitem.type = 'text';
19795: pubitem.size = '40';
19796: privitem.size = '40';
19797: pubtext.innerHTML = "$lt{'pub'}";
19798: privtext.innerHTML = "$lt{'priv'}";
19799: versionitem.type = 'text';
19800: versionitem.size = '3';
19801: versiontext.innerHTML = "$lt{'ver'}";
19802: } else {
19803: pubitem.type = 'hidden';
19804: privitem.type = 'hidden';
19805: versionitem.type = 'hidden';
19806: pubtext.innerHTML = '';
19807: privtext.innerHTML = '';
19808: versiontext.innerHTML = '';
19809: }
19810: }
19811: return;
19812: }
19813:
19814: // ]]>
19815: </script>
19816:
19817: END
19818:
19819: }
19820:
19821: sub toggle_display_js {
19822: return <<"END";
19823:
19824: <script type="text/javascript">
19825: // <![CDATA[
19826:
19827: function toggleDisplay(domForm,caller) {
19828: if (document.getElementById(caller)) {
19829: var divitem = document.getElementById(caller);
19830: var optionsElement = domForm.coursecredits;
19831: var checkval = 1;
19832: var dispval = 'block';
19833: var selfcreateRegExp = /^cancreate_emailverified/;
19834: if (caller == 'emailoptions') {
19835: optionsElement = domForm.cancreate_email;
19836: }
19837: if (caller == 'studentsubmission') {
19838: optionsElement = domForm.postsubmit;
19839: }
19840: if (caller == 'cloneinstcode') {
19841: optionsElement = domForm.canclone;
19842: checkval = 'instcode';
19843: }
19844: if (selfcreateRegExp.test(caller)) {
19845: optionsElement = domForm.elements[caller];
19846: checkval = 'other';
19847: dispval = 'inline'
19848: }
19849: if (optionsElement.length) {
19850: var currval;
19851: for (var i=0; i<optionsElement.length; i++) {
19852: if (optionsElement[i].checked) {
19853: currval = optionsElement[i].value;
19854: }
19855: }
19856: if (currval == checkval) {
19857: divitem.style.display = dispval;
19858: } else {
19859: divitem.style.display = 'none';
19860: }
19861: }
19862: }
19863: return;
19864: }
19865:
19866: // ]]>
19867: </script>
19868:
19869: END
19870:
19871: }
19872:
19873: sub captcha_phrases {
19874: return &Apache::lonlocal::texthash (
19875: priv => 'Private key',
19876: pub => 'Public key',
19877: original => 'original (CAPTCHA)',
19878: recaptcha => 'successor (ReCAPTCHA)',
19879: notused => 'unused',
19880: ver => 'ReCAPTCHA version (1 or 2)',
19881: );
19882: }
19883:
19884: sub devalidate_remote_domconfs {
19885: my ($dom,$cachekeys) = @_;
19886: return unless (ref($cachekeys) eq 'HASH');
19887: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19888: my %thismachine;
19889: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
19890: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
19891: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
19892: 'ipaccess');
19893: my %cache_by_lonhost;
19894: if (exists($cachekeys->{'samllanding'})) {
19895: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
19896: my %landing = %{$cachekeys->{'samllanding'}};
19897: my %domservers = &Apache::lonnet::get_servers($dom);
19898: if (keys(%domservers)) {
19899: foreach my $server (keys(%domservers)) {
19900: my @cached;
19901: next if ($thismachine{$server});
19902: if ($landing{$server}) {
19903: push(@cached,&escape('samllanding').':'.&escape($server));
19904: }
19905: if (@cached) {
19906: $cache_by_lonhost{$server} = \@cached;
19907: }
19908: }
19909: }
19910: }
19911: }
19912: if (keys(%servers)) {
19913: foreach my $server (keys(%servers)) {
19914: next if ($thismachine{$server});
19915: my @cached;
19916: foreach my $name (@posscached) {
19917: if ($cachekeys->{$name}) {
19918: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
19919: if (ref($cachekeys->{$name}) eq 'HASH') {
19920: foreach my $key (keys(%{$cachekeys->{$name}})) {
19921: push(@cached,&escape($name).':'.&escape($key));
19922: }
19923: }
19924: } else {
19925: push(@cached,&escape($name).':'.&escape($dom));
19926: }
19927: }
19928: }
19929: if ((exists($cache_by_lonhost{$server})) &&
19930: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
19931: push(@cached,@{$cache_by_lonhost{$server}});
19932: }
19933: if (@cached) {
19934: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19935: }
19936: }
19937: }
19938: return;
19939: }
19940:
19941: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>