1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.160.6.124 2024/07/14 23:10:08 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','wafproxy','ipaccess'],$dom);
222: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
223: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
224: 'contacts','usercreation','selfcreation','usermodification',
225: 'scantron','requestcourses','requestauthor','coursecategories',
226: 'serverstatuses','helpsettings','coursedefaults',
227: 'selfenrollment','usersessions');
228: my %existing;
229: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
230: %existing = %{$domconfig{'loadbalancing'}};
231: }
232: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
233: push(@prefs_order,'loadbalancing');
234: }
235: my %prefs = (
236: 'rolecolors' =>
237: { text => 'Default color schemes',
238: help => 'Domain_Configuration_Color_Schemes',
239: header => [{col1 => 'Student Settings',
240: col2 => '',},
241: {col1 => 'Coordinator Settings',
242: col2 => '',},
243: {col1 => 'Author Settings',
244: col2 => '',},
245: {col1 => 'Administrator Settings',
246: col2 => '',}],
247: print => \&print_rolecolors,
248: modify => \&modify_rolecolors,
249: },
250: 'login' =>
251: { text => 'Log-in page options',
252: help => 'Domain_Configuration_Login_Page',
253: header => [{col1 => 'Log-in Page Items',
254: col2 => '',},
255: {col1 => 'Log-in Help',
256: col2 => 'Value'},
257: {col1 => 'Custom HTML in document head',
258: col2 => 'Value'},
259: {col1 => 'SSO',
260: col2 => 'Dual login: SSO and non-SSO options'},
261: ],
262: print => \&print_login,
263: modify => \&modify_login,
264: },
265: 'defaults' =>
266: { text => 'Default authentication/language/timezone/portal/types',
267: help => 'Domain_Configuration_LangTZAuth',
268: header => [{col1 => 'Setting',
269: col2 => 'Value'},
270: {col1 => 'Institutional user types',
271: col2 => 'Name displayed'},
272: {col1 => 'Mapping for missing usernames via standard log-in',
273: col2 => 'Rules in use'}],
274: print => \&print_defaults,
275: modify => \&modify_defaults,
276: },
277: 'wafproxy' =>
278: { text => 'Web Application Firewall/Reverse Proxy',
279: help => 'Domain_Configuration_WAF_Proxy',
280: header => [{col1 => 'Domain(s)',
281: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
282: },
283: {col1 => 'Domain(s)',
284: col2 => 'WAF Configuration',}],
285: print => \&print_wafproxy,
286: modify => \&modify_wafproxy,
287: },
288: 'passwords' =>
289: { text => 'Passwords (Internal authentication)',
290: help => 'Domain_Configuration_Passwords',
291: header => [{col1 => 'Resetting Forgotten Password',
292: col2 => 'Settings'},
293: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
294: col2 => 'Settings'},
295: {col1 => 'Rules for LON-CAPA Passwords',
296: col2 => 'Settings'},
297: {col1 => 'Course Owner Changing Student Passwords',
298: col2 => 'Settings'}],
299: print => \&print_passwords,
300: modify => \&modify_passwords,
301: },
302: 'quotas' =>
303: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
304: help => 'Domain_Configuration_Quotas',
305: header => [{col1 => 'User affiliation',
306: col2 => 'Available tools',
307: col3 => 'Quotas, MB; (Authoring requires role)',}],
308: print => \&print_quotas,
309: modify => \&modify_quotas,
310: },
311: 'autoenroll' =>
312: { text => 'Auto-enrollment settings',
313: help => 'Domain_Configuration_Auto_Enrollment',
314: header => [{col1 => 'Configuration setting',
315: col2 => 'Value(s)'}],
316: print => \&print_autoenroll,
317: modify => \&modify_autoenroll,
318: },
319: 'autoupdate' =>
320: { text => 'Auto-update settings',
321: help => 'Domain_Configuration_Auto_Updates',
322: header => [{col1 => 'Setting',
323: col2 => 'Value',},
324: {col1 => 'Setting',
325: col2 => 'Affiliation'},
326: {col1 => 'User population',
327: col2 => 'Updatable user data'}],
328: print => \&print_autoupdate,
329: modify => \&modify_autoupdate,
330: },
331: 'autocreate' =>
332: { text => 'Auto-course creation settings',
333: help => 'Domain_Configuration_Auto_Creation',
334: header => [{col1 => 'Configuration Setting',
335: col2 => 'Value',}],
336: print => \&print_autocreate,
337: modify => \&modify_autocreate,
338: },
339: 'directorysrch' =>
340: { text => 'Directory searches',
341: help => 'Domain_Configuration_InstDirectory_Search',
342: header => [{col1 => 'Institutional Directory Setting',
343: col2 => 'Value',},
344: {col1 => 'LON-CAPA Directory Setting',
345: col2 => 'Value',}],
346: print => \&print_directorysrch,
347: modify => \&modify_directorysrch,
348: },
349: 'contacts' =>
350: { text => 'E-mail addresses and helpform',
351: help => 'Domain_Configuration_Contact_Info',
352: header => [{col1 => 'Default e-mail addresses',
353: col2 => 'Value',},
354: {col1 => 'Recipient(s) for notifications',
355: col2 => 'Value',},
356: {col1 => 'Nightly status check e-mail',
357: col2 => 'Settings',},
358: {col1 => 'Ask helpdesk form settings',
359: col2 => 'Value',},],
360: print => \&print_contacts,
361: modify => \&modify_contacts,
362: },
363: 'usercreation' =>
364: { text => 'User creation',
365: help => 'Domain_Configuration_User_Creation',
366: header => [{col1 => 'Format rule type',
367: col2 => 'Format rules in force'},
368: {col1 => 'User account creation',
369: col2 => 'Usernames which may be created',},
370: {col1 => 'Context',
371: col2 => 'Assignable authentication types'}],
372: print => \&print_usercreation,
373: modify => \&modify_usercreation,
374: },
375: 'selfcreation' =>
376: { text => 'Users self-creating accounts',
377: help => 'Domain_Configuration_Self_Creation',
378: header => [{col1 => 'Self-creation with institutional username',
379: col2 => 'Enabled?'},
380: {col1 => 'Institutional user type (login/SSO self-creation)',
381: col2 => 'Information user can enter'},
382: {col1 => 'Self-creation with e-mail verification',
383: col2 => 'Settings'}],
384: print => \&print_selfcreation,
385: modify => \&modify_selfcreation,
386: },
387: 'usermodification' =>
388: { text => 'User modification',
389: help => 'Domain_Configuration_User_Modification',
390: header => [{col1 => 'Target user has role',
391: col2 => 'User information updatable in author context'},
392: {col1 => 'Target user has role',
393: col2 => 'User information updatable in course context'}],
394: print => \&print_usermodification,
395: modify => \&modify_usermodification,
396: },
397: 'scantron' =>
398: { text => 'Bubblesheet format',
399: help => 'Domain_Configuration_Scantron_Format',
400: header => [ {col1 => 'Bubblesheet format file',
401: col2 => ''},
402: {col1 => 'Bubblesheet data upload formats',
403: col2 => 'Settings'}],
404: print => \&print_scantron,
405: modify => \&modify_scantron,
406: },
407: 'requestcourses' =>
408: {text => 'Request creation of courses',
409: help => 'Domain_Configuration_Request_Courses',
410: header => [{col1 => 'User affiliation',
411: col2 => 'Availability/Processing of requests',},
412: {col1 => 'Setting',
413: col2 => 'Value'},
414: {col1 => 'Available textbooks',
415: col2 => ''},
416: {col1 => 'Available templates',
417: col2 => ''},
418: {col1 => 'Validation (not official courses)',
419: col2 => 'Value'},],
420: print => \&print_quotas,
421: modify => \&modify_quotas,
422: },
423: 'requestauthor' =>
424: {text => 'Request Authoring Space',
425: help => 'Domain_Configuration_Request_Author',
426: header => [{col1 => 'User affiliation',
427: col2 => 'Availability/Processing of requests',},
428: {col1 => 'Setting',
429: col2 => 'Value'}],
430: print => \&print_quotas,
431: modify => \&modify_quotas,
432: },
433: 'coursecategories' =>
434: { text => 'Cataloging of courses/communities',
435: help => 'Domain_Configuration_Cataloging_Courses',
436: header => [{col1 => 'Catalog type/availability',
437: col2 => '',},
438: {col1 => 'Category settings for standard catalog',
439: col2 => '',},
440: {col1 => 'Categories',
441: col2 => '',
442: }],
443: print => \&print_coursecategories,
444: modify => \&modify_coursecategories,
445: },
446: 'serverstatuses' =>
447: {text => 'Access to server status pages',
448: help => 'Domain_Configuration_Server_Status',
449: header => [{col1 => 'Status Page',
450: col2 => 'Other named users',
451: col3 => 'Specific IPs',
452: }],
453: print => \&print_serverstatuses,
454: modify => \&modify_serverstatuses,
455: },
456: 'helpsettings' =>
457: {text => 'Support settings',
458: help => 'Domain_Configuration_Help_Settings',
459: header => [{col1 => 'Help Page Settings (logged-in users)',
460: col2 => 'Value'},
461: {col1 => 'Helpdesk Roles',
462: col2 => 'Settings'},],
463: print => \&print_helpsettings,
464: modify => \&modify_helpsettings,
465: },
466: 'coursedefaults' =>
467: {text => 'Course/Community defaults',
468: help => 'Domain_Configuration_Course_Defaults',
469: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
470: col2 => 'Value',},
471: {col1 => 'Defaults which can be overridden for each course by a DC',
472: col2 => 'Value',},],
473: print => \&print_coursedefaults,
474: modify => \&modify_coursedefaults,
475: },
476: 'selfenrollment' =>
477: {text => 'Self-enrollment in Course/Community',
478: help => 'Domain_Configuration_Selfenrollment',
479: header => [{col1 => 'Configuration Rights',
480: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
481: {col1 => 'Defaults',
482: col2 => 'Value'},
483: {col1 => 'Self-enrollment validation (optional)',
484: col2 => 'Value'},],
485: print => \&print_selfenrollment,
486: modify => \&modify_selfenrollment,
487: },
488: 'usersessions' =>
489: {text => 'User session hosting/offloading',
490: help => 'Domain_Configuration_User_Sessions',
491: header => [{col1 => 'Domain server',
492: col2 => 'Servers to offload sessions to when busy'},
493: {col1 => 'Hosting of users from other domains',
494: col2 => 'Rules'},
495: {col1 => "Hosting domain's own users elsewhere",
496: col2 => 'Rules'}],
497: print => \&print_usersessions,
498: modify => \&modify_usersessions,
499: },
500: 'loadbalancing' =>
501: {text => 'Dedicated Load Balancer(s)',
502: help => 'Domain_Configuration_Load_Balancing',
503: header => [{col1 => 'Balancers',
504: col2 => 'Default destinations',
505: col3 => 'User affiliation',
506: col4 => 'Overrides'},
507: ],
508: print => \&print_loadbalancing,
509: modify => \&modify_loadbalancing,
510: },
511: 'ipaccess' =>
512: {text => 'IP-based access control',
513: help => 'Domain_Configuration_IP_Access',
514: header => [{col1 => 'Setting',
515: col2 => 'Value'},],
516: print => \&print_ipaccess,
517: modify => \&modify_ipaccess,
518: },
519: );
520: if (keys(%servers) > 1) {
521: $prefs{'login'} = { text => 'Log-in page options',
522: help => 'Domain_Configuration_Login_Page',
523: header => [{col1 => 'Log-in Service',
524: col2 => 'Server Setting',},
525: {col1 => 'Log-in Page Items',
526: col2 => ''},
527: {col1 => 'Log-in Help',
528: col2 => 'Value'},
529: {col1 => 'Custom HTML in document head',
530: col2 => 'Value'},
531: {col1 => 'SSO',
532: col2 => 'Dual login: SSO and non-SSO options'},
533: ],
534: print => \&print_login,
535: modify => \&modify_login,
536: };
537: }
538:
539: my @roles = ('student','coordinator','author','admin');
540: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
541: &Apache::lonhtmlcommon::add_breadcrumb
542: ({href=>"javascript:changePage(document.$phase,'pickactions')",
543: text=>"Settings to display/modify"});
544: my $confname = $dom.'-domainconfig';
545:
546: if ($phase eq 'process') {
547: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
548: \%prefs,\%domconfig,$confname,\@roles);
549: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
550: $r->rflush();
551: &devalidate_remote_domconfs($dom,$result);
552: }
553: } elsif ($phase eq 'display') {
554: my $js = &recaptcha_js().
555: &toggle_display_js();
556: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
557: my ($othertitle,$usertypes,$types) =
558: &Apache::loncommon::sorted_inst_types($dom);
559: $js .= &lonbalance_targets_js($dom,$types,\%servers,
560: $domconfig{'loadbalancing'}).
561: &new_spares_js().
562: &common_domprefs_js().
563: &Apache::loncommon::javascript_array_indexof();
564: }
565: if (grep(/^requestcourses$/,@actions)) {
566: my $javascript_validations;
567: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
568: $js .= <<END;
569: <script type="text/javascript">
570: $javascript_validations
571: </script>
572: $coursebrowserjs
573: END
574: } elsif (grep(/^ipaccess$/,@actions)) {
575: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
576: }
577: if (grep(/^selfcreation$/,@actions)) {
578: $js .= &selfcreate_javascript();
579: }
580: if (grep(/^contacts$/,@actions)) {
581: $js .= &contacts_javascript();
582: }
583: if (grep(/^scantron$/,@actions)) {
584: $js .= &scantron_javascript();
585: }
586: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
587: } else {
588: # check if domconfig user exists for the domain.
589: my $servadm = $r->dir_config('lonAdmEMail');
590: my ($configuserok,$author_ok,$switchserver) =
591: &config_check($dom,$confname,$servadm);
592: unless ($configuserok eq 'ok') {
593: &Apache::lonconfigsettings::print_header($r,$phase,$context);
594: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
595: $confname).
596: '<br />'
597: );
598: if ($switchserver) {
599: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
600: '<br />'.
601: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
602: '<br />'.
603: &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).
604: '<br />'.
605: &mt('To do that now, use the following link: [_1]',$switchserver)
606: );
607: } else {
608: $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.').
609: '<br />'.
610: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
611: );
612: }
613: $r->print(&Apache::loncommon::end_page());
614: return OK;
615: }
616: if (keys(%domconfig) == 0) {
617: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
618: my @ids=&Apache::lonnet::current_machine_ids();
619: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
620: my %designhash = &Apache::loncommon::get_domainconf($dom);
621: my @loginimages = ('img','logo','domlogo','login');
622: my $custom_img_count = 0;
623: foreach my $img (@loginimages) {
624: if ($designhash{$dom.'.login.'.$img} ne '') {
625: $custom_img_count ++;
626: }
627: }
628: foreach my $role (@roles) {
629: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
630: $custom_img_count ++;
631: }
632: }
633: if ($custom_img_count > 0) {
634: &Apache::lonconfigsettings::print_header($r,$phase,$context);
635: my $switch_server = &check_switchserver($dom,$confname);
636: $r->print(
637: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
638: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
639: &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 />'.
640: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
641: if ($switch_server) {
642: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
643: }
644: $r->print(&Apache::loncommon::end_page());
645: return OK;
646: }
647: }
648: }
649: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
650: }
651: return OK;
652: }
653:
654: sub process_changes {
655: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
656: my %domconfig;
657: if (ref($values) eq 'HASH') {
658: %domconfig = %{$values};
659: }
660: my $output;
661: if ($action eq 'login') {
662: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
663: } elsif ($action eq 'rolecolors') {
664: $output = &modify_rolecolors($r,$dom,$confname,$roles,
665: $lastactref,%domconfig);
666: } elsif ($action eq 'quotas') {
667: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
668: } elsif ($action eq 'autoenroll') {
669: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
670: } elsif ($action eq 'autoupdate') {
671: $output = &modify_autoupdate($dom,%domconfig);
672: } elsif ($action eq 'autocreate') {
673: $output = &modify_autocreate($dom,%domconfig);
674: } elsif ($action eq 'directorysrch') {
675: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
676: } elsif ($action eq 'usercreation') {
677: $output = &modify_usercreation($dom,%domconfig);
678: } elsif ($action eq 'selfcreation') {
679: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
680: } elsif ($action eq 'usermodification') {
681: $output = &modify_usermodification($dom,%domconfig);
682: } elsif ($action eq 'contacts') {
683: $output = &modify_contacts($dom,$lastactref,%domconfig);
684: } elsif ($action eq 'defaults') {
685: $output = &modify_defaults($dom,$lastactref,%domconfig);
686: } elsif ($action eq 'scantron') {
687: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
688: } elsif ($action eq 'coursecategories') {
689: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
690: } elsif ($action eq 'serverstatuses') {
691: $output = &modify_serverstatuses($dom,%domconfig);
692: } elsif ($action eq 'requestcourses') {
693: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
694: } elsif ($action eq 'requestauthor') {
695: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
696: } elsif ($action eq 'helpsettings') {
697: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
698: } elsif ($action eq 'coursedefaults') {
699: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
700: } elsif ($action eq 'selfenrollment') {
701: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
702: } elsif ($action eq 'usersessions') {
703: $output = &modify_usersessions($dom,$lastactref,%domconfig);
704: } elsif ($action eq 'loadbalancing') {
705: $output = &modify_loadbalancing($dom,%domconfig);
706: } elsif ($action eq 'passwords') {
707: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
708: } elsif ($action eq 'wafproxy') {
709: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
710: } elsif ($action eq 'ipaccess') {
711: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
712: }
713: return $output;
714: }
715:
716: sub print_config_box {
717: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
718: my $rowtotal = 0;
719: my $output;
720: if ($action eq 'coursecategories') {
721: $output = &coursecategories_javascript($settings);
722: } elsif ($action eq 'defaults') {
723: $output = &defaults_javascript($settings);
724: } elsif ($action eq 'passwords') {
725: $output = &passwords_javascript();
726: } elsif ($action eq 'helpsettings') {
727: my (%privs,%levelscurrent);
728: my %full=();
729: my %levels=(
730: course => {},
731: domain => {},
732: system => {},
733: );
734: my $context = 'domain';
735: my $crstype = 'Course';
736: my $formname = 'display';
737: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
738: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
739: $output =
740: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
741: \@templateroles);
742: } elsif ($action eq 'wafproxy') {
743: $output .= &wafproxy_javascript($dom);
744: } elsif ($action eq 'autoupdate') {
745: $output .= &autoupdate_javascript();
746: } elsif ($action eq 'autoenroll') {
747: $output .= &autoenroll_javascript();
748: } elsif ($action eq 'login') {
749: $output .= &saml_javascript();
750: } elsif ($action eq 'ipaccess') {
751: $output .= &ipaccess_javascript($settings);
752: }
753: $output .=
754: '<table class="LC_nested_outer">
755: <tr>
756: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
757: &mt($item->{text}).' '.
758: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
759: '</tr>';
760: $rowtotal ++;
761: my $numheaders = 1;
762: if (ref($item->{'header'}) eq 'ARRAY') {
763: $numheaders = scalar(@{$item->{'header'}});
764: }
765: if ($numheaders > 1) {
766: my $colspan = '';
767: my $rightcolspan = '';
768: my $leftnobr = '';
769: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
770: ($action eq 'directorysrch') ||
771: (($action eq 'login') && ($numheaders < 5))) {
772: $colspan = ' colspan="2"';
773: }
774: if ($action eq 'usersessions') {
775: $rightcolspan = ' colspan="3"';
776: }
777: if ($action eq 'passwords') {
778: $leftnobr = ' LC_nobreak';
779: }
780: $output .= '
781: <tr>
782: <td>
783: <table class="LC_nested">
784: <tr class="LC_info_row">
785: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
786: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
787: </tr>';
788: $rowtotal ++;
789: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
790: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
791: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
792: ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy')) {
793: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
794: } elsif ($action eq 'passwords') {
795: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
796: } elsif ($action eq 'coursecategories') {
797: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
798: } elsif ($action eq 'scantron') {
799: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
800: } elsif ($action eq 'login') {
801: if ($numheaders == 5) {
802: $colspan = ' colspan="2"';
803: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
804: } else {
805: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
806: }
807: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
808: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
809: } elsif ($action eq 'rolecolors') {
810: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
811: }
812: $output .= '
813: </table>
814: </td>
815: </tr>
816: <tr>
817: <td>
818: <table class="LC_nested">
819: <tr class="LC_info_row">
820: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
821: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
822: </tr>';
823: $rowtotal ++;
824: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
825: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
826: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
827: ($action eq 'contacts') || ($action eq 'passwords') || ($action eq 'defaults')) {
828: if ($action eq 'coursecategories') {
829: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
830: $colspan = ' colspan="2"';
831: } elsif ($action eq 'passwords') {
832: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
833: } else {
834: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
835: }
836: $output .= '
837: </table>
838: </td>
839: </tr>
840: <tr>
841: <td>
842: <table class="LC_nested">
843: <tr class="LC_info_row">
844: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
845: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
846: </tr>'."\n";
847: if ($action eq 'coursecategories') {
848: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
849: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
850: if ($action eq 'passwords') {
851: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
852: } else {
853: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
854: }
855: $output .= '
856: </tr>
857: </table>
858: </td>
859: </tr>
860: <tr>
861: <td>
862: <table class="LC_nested">
863: <tr class="LC_info_row">
864: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
865: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
866: if ($action eq 'passwords') {
867: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
868: } else {
869: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
870: }
871: $output .= '
872: </table>
873: </td>
874: </tr>
875: <tr>';
876: } else {
877: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
878: }
879: $rowtotal ++;
880: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
881: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
882: ($action eq 'wafproxy')) {
883: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
884: } elsif ($action eq 'scantron') {
885: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
886: } elsif ($action eq 'login') {
887: if ($numheaders == 5) {
888: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
889: </table>
890: </td>
891: </tr>
892: <tr>
893: <td>
894: <table class="LC_nested">
895: <tr class="LC_info_row">
896: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
897: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
898: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
899: $rowtotal ++;
900: } else {
901: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
902: }
903: $output .= '
904: </table>
905: </td>
906: </tr>
907: <tr>
908: <td>
909: <table class="LC_nested">
910: <tr class="LC_info_row">';
911: if ($numheaders == 5) {
912: $output .= '
913: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
914: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
915: </tr>';
916: } else {
917: $output .= '
918: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
919: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
920: </tr>';
921: }
922: $rowtotal ++;
923: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
924: </table>
925: </td>
926: </tr>
927: <tr>
928: <td>
929: <table class="LC_nested">
930: <tr class="LC_info_row">';
931: if ($numheaders == 5) {
932: $output .= '
933: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
934: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
935: </tr>';
936: } else {
937: $output .= '
938: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
939: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
940: </tr>';
941: }
942: $rowtotal ++;
943: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
944: } elsif ($action eq 'requestcourses') {
945: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
946: $rowtotal ++;
947: $output .= &print_studentcode($settings,\$rowtotal).'
948: </table>
949: </td>
950: </tr>
951: <tr>
952: <td>
953: <table class="LC_nested">
954: <tr class="LC_info_row">
955: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
956: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
957: &textbookcourses_javascript($settings).
958: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
959: </table>
960: </td>
961: </tr>
962: <tr>
963: <td>
964: <table class="LC_nested">
965: <tr class="LC_info_row">
966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
967: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
968: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
969: </table>
970: </td>
971: </tr>
972: <tr>
973: <td>
974: <table class="LC_nested">
975: <tr class="LC_info_row">
976: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
977: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
978: </tr>'.
979: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
980: } elsif ($action eq 'requestauthor') {
981: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
982: $rowtotal ++;
983: } elsif ($action eq 'rolecolors') {
984: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
985: </table>
986: </td>
987: </tr>
988: <tr>
989: <td>
990: <table class="LC_nested">
991: <tr class="LC_info_row">
992: <td class="LC_left_item"'.$colspan.' valign="top">'.
993: &mt($item->{'header'}->[2]->{'col1'}).'</td>
994: <td class="LC_right_item" valign="top">'.
995: &mt($item->{'header'}->[2]->{'col2'}).'</td>
996: </tr>'.
997: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
998: </table>
999: </td>
1000: </tr>
1001: <tr>
1002: <td>
1003: <table class="LC_nested">
1004: <tr class="LC_info_row">
1005: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1006: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1007: </tr>'.
1008: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1009: $rowtotal += 2;
1010: }
1011: } else {
1012: $output .= '
1013: <tr>
1014: <td>
1015: <table class="LC_nested">
1016: <tr class="LC_info_row">';
1017: if ($action eq 'login') {
1018: $output .= '
1019: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1020: } elsif ($action eq 'serverstatuses') {
1021: $output .= '
1022: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1023: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1024:
1025: } else {
1026: $output .= '
1027: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1028: }
1029: if (defined($item->{'header'}->[0]->{'col3'})) {
1030: $output .= '<td class="LC_left_item" valign="top">'.
1031: &mt($item->{'header'}->[0]->{'col2'});
1032: if ($action eq 'serverstatuses') {
1033: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1034: }
1035: } else {
1036: $output .= '<td class="LC_right_item" valign="top">'.
1037: &mt($item->{'header'}->[0]->{'col2'});
1038: }
1039: $output .= '</td>';
1040: if ($item->{'header'}->[0]->{'col3'}) {
1041: if (defined($item->{'header'}->[0]->{'col4'})) {
1042: $output .= '<td class="LC_left_item" valign="top">'.
1043: &mt($item->{'header'}->[0]->{'col3'});
1044: } else {
1045: $output .= '<td class="LC_right_item" valign="top">'.
1046: &mt($item->{'header'}->[0]->{'col3'});
1047: }
1048: if ($action eq 'serverstatuses') {
1049: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1050: }
1051: $output .= '</td>';
1052: }
1053: if ($item->{'header'}->[0]->{'col4'}) {
1054: $output .= '<td class="LC_right_item" valign="top">'.
1055: &mt($item->{'header'}->[0]->{'col4'});
1056: }
1057: $output .= '</tr>';
1058: $rowtotal ++;
1059: if ($action eq 'quotas') {
1060: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1061: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1062: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1063: ($action eq 'ipaccess')) {
1064: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1065: }
1066: }
1067: $output .= '
1068: </table>
1069: </td>
1070: </tr>
1071: </table><br />';
1072: return ($output,$rowtotal);
1073: }
1074:
1075: sub print_login {
1076: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1077: my ($css_class,$datatable,$switchserver,%lt);
1078: my %choices = &login_choices();
1079: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1080: %lt = &login_file_options();
1081: $switchserver = &check_switchserver($dom,$confname);
1082: }
1083:
1084: if ($caller eq 'service') {
1085: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1086: my $choice = $choices{'disallowlogin'};
1087: $css_class = ' class="LC_odd_row"';
1088: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1089: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1090: '<th>'.$choices{'server'}.'</th>'.
1091: '<th>'.$choices{'serverpath'}.'</th>'.
1092: '<th>'.$choices{'custompath'}.'</th>'.
1093: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1094: my %disallowed;
1095: if (ref($settings) eq 'HASH') {
1096: if (ref($settings->{'loginvia'}) eq 'HASH') {
1097: %disallowed = %{$settings->{'loginvia'}};
1098: }
1099: }
1100: foreach my $lonhost (sort(keys(%servers))) {
1101: my $direct = 'selected="selected"';
1102: if (ref($disallowed{$lonhost}) eq 'HASH') {
1103: if ($disallowed{$lonhost}{'server'} ne '') {
1104: $direct = '';
1105: }
1106: }
1107: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1108: '<td><select name="'.$lonhost.'_server">'.
1109: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1110: '</option>';
1111: foreach my $hostid (sort(keys(%servers))) {
1112: next if ($servers{$hostid} eq $servers{$lonhost});
1113: my $selected = '';
1114: if (ref($disallowed{$lonhost}) eq 'HASH') {
1115: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1116: $selected = 'selected="selected"';
1117: }
1118: }
1119: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1120: $servers{$hostid}.'</option>';
1121: }
1122: $datatable .= '</select></td>'.
1123: '<td><select name="'.$lonhost.'_serverpath">';
1124: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1125: my $pathname = $path;
1126: if ($path eq 'custom') {
1127: $pathname = &mt('Custom Path').' ->';
1128: }
1129: my $selected = '';
1130: if (ref($disallowed{$lonhost}) eq 'HASH') {
1131: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1132: $selected = 'selected="selected"';
1133: }
1134: } elsif ($path eq '') {
1135: $selected = 'selected="selected"';
1136: }
1137: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1138: }
1139: $datatable .= '</select></td>';
1140: my ($custom,$exempt);
1141: if (ref($disallowed{$lonhost}) eq 'HASH') {
1142: $custom = $disallowed{$lonhost}{'custompath'};
1143: $exempt = $disallowed{$lonhost}{'exempt'};
1144: }
1145: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1146: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1147: '</tr>';
1148: }
1149: $datatable .= '</table></td></tr>';
1150: return $datatable;
1151: } elsif ($caller eq 'page') {
1152: my %defaultchecked = (
1153: 'coursecatalog' => 'on',
1154: 'helpdesk' => 'on',
1155: 'adminmail' => 'off',
1156: 'newuser' => 'off',
1157: );
1158: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1159: my (%checkedon,%checkedoff);
1160: foreach my $item (@toggles) {
1161: if ($defaultchecked{$item} eq 'on') {
1162: $checkedon{$item} = ' checked="checked" ';
1163: $checkedoff{$item} = ' ';
1164: } elsif ($defaultchecked{$item} eq 'off') {
1165: $checkedoff{$item} = ' checked="checked" ';
1166: $checkedon{$item} = ' ';
1167: }
1168: }
1169: my @images = ('img','logo','domlogo','login');
1170: my @alttext = ('img','logo','domlogo');
1171: my @logintext = ('textcol','bgcol');
1172: my @bgs = ('pgbg','mainbg','sidebg');
1173: my @links = ('link','alink','vlink');
1174: my %designhash = &Apache::loncommon::get_domainconf($dom);
1175: my %defaultdesign = %Apache::loncommon::defaultdesign;
1176: my (%is_custom,%designs);
1177: my %defaults = (
1178: font => $defaultdesign{'login.font'},
1179: );
1180: foreach my $item (@images) {
1181: $defaults{$item} = $defaultdesign{'login.'.$item};
1182: $defaults{'showlogo'}{$item} = 1;
1183: }
1184: foreach my $item (@bgs) {
1185: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1186: }
1187: foreach my $item (@logintext) {
1188: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1189: }
1190: foreach my $item (@links) {
1191: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1192: }
1193: if (ref($settings) eq 'HASH') {
1194: foreach my $item (@toggles) {
1195: if ($settings->{$item} eq '1') {
1196: $checkedon{$item} = ' checked="checked" ';
1197: $checkedoff{$item} = ' ';
1198: } elsif ($settings->{$item} eq '0') {
1199: $checkedoff{$item} = ' checked="checked" ';
1200: $checkedon{$item} = ' ';
1201: }
1202: }
1203: foreach my $item (@images) {
1204: if (defined($settings->{$item})) {
1205: $designs{$item} = $settings->{$item};
1206: $is_custom{$item} = 1;
1207: }
1208: if (defined($settings->{'showlogo'}{$item})) {
1209: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1210: }
1211: }
1212: foreach my $item (@alttext) {
1213: if (ref($settings->{'alttext'}) eq 'HASH') {
1214: if ($settings->{'alttext'}->{$item} ne '') {
1215: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1216: }
1217: }
1218: }
1219: foreach my $item (@logintext) {
1220: if ($settings->{$item} ne '') {
1221: $designs{'logintext'}{$item} = $settings->{$item};
1222: $is_custom{$item} = 1;
1223: }
1224: }
1225: if ($settings->{'font'} ne '') {
1226: $designs{'font'} = $settings->{'font'};
1227: $is_custom{'font'} = 1;
1228: }
1229: foreach my $item (@bgs) {
1230: if ($settings->{$item} ne '') {
1231: $designs{'bgs'}{$item} = $settings->{$item};
1232: $is_custom{$item} = 1;
1233: }
1234: }
1235: foreach my $item (@links) {
1236: if ($settings->{$item} ne '') {
1237: $designs{'links'}{$item} = $settings->{$item};
1238: $is_custom{$item} = 1;
1239: }
1240: }
1241: } else {
1242: if ($designhash{$dom.'.login.font'} ne '') {
1243: $designs{'font'} = $designhash{$dom.'.login.font'};
1244: $is_custom{'font'} = 1;
1245: }
1246: foreach my $item (@images) {
1247: if ($designhash{$dom.'.login.'.$item} ne '') {
1248: $designs{$item} = $designhash{$dom.'.login.'.$item};
1249: $is_custom{$item} = 1;
1250: }
1251: }
1252: foreach my $item (@bgs) {
1253: if ($designhash{$dom.'.login.'.$item} ne '') {
1254: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1255: $is_custom{$item} = 1;
1256: }
1257: }
1258: foreach my $item (@links) {
1259: if ($designhash{$dom.'.login.'.$item} ne '') {
1260: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1261: $is_custom{$item} = 1;
1262: }
1263: }
1264: }
1265: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1266: logo => 'Institution Logo',
1267: domlogo => 'Domain Logo',
1268: login => 'Login box');
1269: my $itemcount = 1;
1270: foreach my $item (@toggles) {
1271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1272: $datatable .=
1273: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1274: '</td><td>'.
1275: '<span class="LC_nobreak"><label><input type="radio" name="'.
1276: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1277: '</label> <label><input type="radio" name="'.$item.'"'.
1278: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1279: '</tr>';
1280: $itemcount ++;
1281: }
1282: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1283: $datatable .= '</tr></table></td></tr>';
1284: } elsif ($caller eq 'help') {
1285: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1286: my $itemcount = 1;
1287: $defaulturl = '/adm/loginproblems.html';
1288: $defaulttype = 'default';
1289: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1290: my @currlangs;
1291: if (ref($settings) eq 'HASH') {
1292: if (ref($settings->{'helpurl'}) eq 'HASH') {
1293: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1294: next if ($settings->{'helpurl'}{$key} eq '');
1295: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1296: $type{$key} = 'custom';
1297: unless ($key eq 'nolang') {
1298: push(@currlangs,$key);
1299: }
1300: }
1301: } elsif ($settings->{'helpurl'} ne '') {
1302: $type{'nolang'} = 'custom';
1303: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1304: }
1305: }
1306: foreach my $lang ('nolang',sort(@currlangs)) {
1307: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1308: $datatable .= '<tr'.$css_class.'>';
1309: if ($url{$lang} eq '') {
1310: $url{$lang} = $defaulturl;
1311: }
1312: if ($type{$lang} eq '') {
1313: $type{$lang} = $defaulttype;
1314: }
1315: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1316: if ($lang eq 'nolang') {
1317: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1318: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1319: } else {
1320: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1321: $langchoices{$lang},
1322: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1323: }
1324: $datatable .= '</span></td>'."\n".
1325: '<td class="LC_left_item">';
1326: if ($type{$lang} eq 'custom') {
1327: $datatable .= '<span class="LC_nobreak"><label>'.
1328: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1329: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1330: } else {
1331: $datatable .= $lt{'upl'};
1332: }
1333: $datatable .='<br />';
1334: if ($switchserver) {
1335: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1336: } else {
1337: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1338: }
1339: $datatable .= '</td></tr>';
1340: $itemcount ++;
1341: }
1342: my @addlangs;
1343: foreach my $lang (sort(keys(%langchoices))) {
1344: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1345: push(@addlangs,$lang);
1346: }
1347: if (@addlangs > 0) {
1348: my %toadd;
1349: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1350: $toadd{''} = &mt('Select');
1351: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1352: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1353: &mt('Add log-in help page for a specific language:').' '.
1354: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1355: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1356: if ($switchserver) {
1357: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1358: } else {
1359: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1360: }
1361: $datatable .= '</td></tr>';
1362: $itemcount ++;
1363: }
1364: $datatable .= &captcha_choice('login',$settings,$itemcount);
1365: } elsif ($caller eq 'headtag') {
1366: my %domservers = &Apache::lonnet::get_servers($dom);
1367: my $choice = $choices{'headtag'};
1368: $css_class = ' class="LC_odd_row"';
1369: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1370: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1371: '<th>'.$choices{'current'}.'</th>'.
1372: '<th>'.$choices{'action'}.'</th>'.
1373: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1374: my (%currurls,%currexempt);
1375: if (ref($settings) eq 'HASH') {
1376: if (ref($settings->{'headtag'}) eq 'HASH') {
1377: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1378: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1379: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1380: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1381: }
1382: }
1383: }
1384: }
1385: foreach my $lonhost (sort(keys(%domservers))) {
1386: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1387: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1388: if ($currurls{$lonhost}) {
1389: $datatable .= '<td class="LC_right_item"><a href="'.
1390: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1391: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1392: '">'.$lt{'curr'}.'</a></td>'.
1393: '<td><span class="LC_nobreak"><label>'.
1394: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1395: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1396: } else {
1397: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1398: }
1399: $datatable .='<br />';
1400: if ($switchserver) {
1401: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1402: } else {
1403: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1404: }
1405: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1406: }
1407: $datatable .= '</table></td></tr>';
1408: } elsif ($caller eq 'saml') {
1409: my %domservers = &Apache::lonnet::get_servers($dom);
1410: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1411: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1412: '<th>'.$choices{'samllanding'}.'</th>'.
1413: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1414: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1415: foreach my $lonhost (keys(%domservers)) {
1416: $samlurl{$lonhost} = '/adm/sso';
1417: $styleon{$lonhost} = 'display:none';
1418: $styleoff{$lonhost} = '';
1419: }
1420: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1421: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1422: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1423: $saml{$lonhost} = 1;
1424: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1425: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1426: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1427: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1428: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1429: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1430: $styleon{$lonhost} = '';
1431: $styleoff{$lonhost} = 'display:none';
1432: } else {
1433: $styleon{$lonhost} = 'display:none';
1434: $styleoff{$lonhost} = '';
1435: }
1436: }
1437: }
1438: my $itemcount = 1;
1439: foreach my $lonhost (sort(keys(%domservers))) {
1440: my $samlon = ' ';
1441: my $samloff = ' checked="checked" ';
1442: if ($saml{$lonhost}) {
1443: $samlon = $samloff;
1444: $samloff = ' ';
1445: }
1446: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1447: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1448: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1449: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1450: &mt('No').'</label>'.(' 'x2).
1451: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1452: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1453: &mt('Yes').'</label></span></td>'.
1454: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1455: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1456: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1457: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1458: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1459: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1460: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1461: $samltext{$lonhost}.'" /></td><td>';
1462: if ($samlimg{$lonhost}) {
1463: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1464: '<span class="LC_nobreak"><label>'.
1465: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1466: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1467: } else {
1468: $datatable .= $lt{'upl'};
1469: }
1470: $datatable .='<br />';
1471: if ($switchserver) {
1472: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1473: } else {
1474: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1475: }
1476: $datatable .= '</td>'.
1477: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1478: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1479: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1480: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1481: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1482: $samltitle{$lonhost}.'</textarea></td>'.
1483: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1484: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1485: '</table></td>'.
1486: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1487: $itemcount ++;
1488: }
1489: $datatable .= '</table></td></tr>';
1490: }
1491: return $datatable;
1492: }
1493:
1494: sub login_choices {
1495: my %choices =
1496: &Apache::lonlocal::texthash (
1497: coursecatalog => 'Display Course/Community Catalog link?',
1498: adminmail => "Display Administrator's E-mail Address?",
1499: helpdesk => 'Display "Contact Helpdesk" link',
1500: disallowlogin => "Login page requests redirected",
1501: hostid => "Server",
1502: server => "Redirect to:",
1503: serverpath => "Path",
1504: custompath => "Custom",
1505: exempt => "Exempt IP(s)",
1506: directlogin => "No redirect",
1507: newuser => "Link to create a user account",
1508: img => "Header",
1509: logo => "Main Logo",
1510: domlogo => "Domain Logo",
1511: login => "Log-in Header",
1512: textcol => "Text color",
1513: bgcol => "Box color",
1514: bgs => "Background colors",
1515: links => "Link colors",
1516: font => "Font color",
1517: pgbg => "Header",
1518: mainbg => "Page",
1519: sidebg => "Login box",
1520: link => "Link",
1521: alink => "Active link",
1522: vlink => "Visited link",
1523: headtag => "Custom markup",
1524: action => "Action",
1525: current => "Current",
1526: samllanding => "Dual login?",
1527: samloptions => "Options",
1528: alttext => "Alt text",
1529: );
1530: return %choices;
1531: }
1532:
1533: sub login_file_options {
1534: return &Apache::lonlocal::texthash(
1535: del => 'Delete?',
1536: rep => 'Replace:',
1537: upl => 'Upload:',
1538: curr => 'View contents',
1539: default => 'Default',
1540: custom => 'Custom',
1541: none => 'None',
1542: );
1543: }
1544:
1545: sub print_ipaccess {
1546: my ($dom,$settings,$rowtotal) = @_;
1547: my $css_class;
1548: my $itemcount = 0;
1549: my $datatable;
1550: my %ordered;
1551: if (ref($settings) eq 'HASH') {
1552: foreach my $item (keys(%{$settings})) {
1553: if (ref($settings->{$item}) eq 'HASH') {
1554: my $num = $settings->{$item}{'order'};
1555: if ($num eq '') {
1556: $num = scalar(keys(%{$settings}));
1557: }
1558: $ordered{$num} = $item;
1559: }
1560: }
1561: }
1562: my $maxnum = scalar(keys(%ordered));
1563: if (keys(%ordered)) {
1564: my @items = sort { $a <=> $b } keys(%ordered);
1565: for (my $i=0; $i<@items; $i++) {
1566: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1567: my $item = $ordered{$items[$i]};
1568: my ($name,$ipranges,%commblocks,%courses);
1569: if (ref($settings->{$item}) eq 'HASH') {
1570: $name = $settings->{$item}->{'name'};
1571: $ipranges = $settings->{$item}->{'ip'};
1572: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1573: %commblocks = %{$settings->{$item}->{'commblocks'}};
1574: }
1575: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1576: %courses = %{$settings->{$item}->{'courses'}};
1577: }
1578: }
1579: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1580: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1581: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1582: for (my $k=0; $k<=$maxnum; $k++) {
1583: my $vpos = $k+1;
1584: my $selstr;
1585: if ($k == $i) {
1586: $selstr = ' selected="selected" ';
1587: }
1588: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1589: }
1590: $datatable .= '</select>'.(' 'x2).
1591: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1592: &mt('Delete?').'</label></span></td>'.
1593: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1594: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1595: '</td></tr>';
1596: $itemcount ++;
1597: }
1598: }
1599: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1600: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1601: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1602: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1603: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1604: for (my $k=0; $k<$maxnum+1; $k++) {
1605: my $vpos = $k+1;
1606: my $selstr;
1607: if ($k == $maxnum) {
1608: $selstr = ' selected="selected" ';
1609: }
1610: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1611: }
1612: $datatable .= '</select> '."\n".
1613: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1614: '<td colspan="2">'.
1615: &ipaccess_options('add',$itemcount,$dom).
1616: '</td>'."\n".
1617: '</tr>'."\n";
1618: $$rowtotal ++;
1619: return $datatable;
1620: }
1621:
1622: sub ipaccess_options {
1623: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1624: my (%currblocks,%currcourses,$output);
1625: if (ref($blocksref) eq 'HASH') {
1626: %currblocks = %{$blocksref};
1627: }
1628: if (ref($coursesref) eq 'HASH') {
1629: %currcourses = %{$coursesref};
1630: }
1631: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1632: '<span class="LC_nobreak">'.&mt('Name').': '.
1633: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1634: '</span></fieldset>'.
1635: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1636: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1637: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1638: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1639: $ipranges.'</textarea></fieldset>'.
1640: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1641: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1642: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1643: '<table>';
1644: foreach my $cid (sort(keys(%currcourses))) {
1645: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1646: $output .= '<tr><td><span class="LC_nobreak">'.
1647: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1648: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1649: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1650: }
1651: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1652: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1653: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1654: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1655: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1656: '</span></td></tr></table>'."\n".
1657: '</fieldset>';
1658: return $output;
1659: }
1660:
1661: sub blocker_checkboxes {
1662: my ($num,$blocks) = @_;
1663: my ($typeorder,$types) = &commblocktype_text();
1664: my $numinrow = 6;
1665: my $output = '<table>';
1666: for (my $i=0; $i<@{$typeorder}; $i++) {
1667: my $block = $typeorder->[$i];
1668: my $blockstatus;
1669: if (ref($blocks) eq 'HASH') {
1670: if ($blocks->{$block} eq 'on') {
1671: $blockstatus = 'checked="checked"';
1672: }
1673: }
1674: my $rem = $i%($numinrow);
1675: if ($rem == 0) {
1676: if ($i > 0) {
1677: $output .= '</tr>';
1678: }
1679: $output .= '<tr>';
1680: }
1681: if ($i == scalar(@{$typeorder})-1) {
1682: my $colsleft = $numinrow-$rem;
1683: if ($colsleft > 1) {
1684: $output .= '<td colspan="'.$colsleft.'">';
1685: } else {
1686: $output .= '<td>';
1687: }
1688: } else {
1689: $output .= '<td>';
1690: }
1691: my $item = 'ipaccess_block_'.$num;
1692: if ($blockstatus) {
1693: $blockstatus = ' '.$blockstatus;
1694: }
1695: $output .= '<span class="LC_nobreak"><label>'."\n".
1696: '<input type="checkbox" name="'.$item.'"'.
1697: $blockstatus.' value="'.$block.'"'.' />'.
1698: $types->{$block}.'</label></span>'."\n".
1699: '<br /></td>';
1700: }
1701: $output .= '</tr></table>';
1702: return $output;
1703: }
1704:
1705: sub commblocktype_text {
1706: my %types = &Apache::lonlocal::texthash(
1707: 'com' => 'Messaging',
1708: 'chat' => 'Chat Room',
1709: 'boards' => 'Discussion',
1710: 'port' => 'Portfolio',
1711: 'groups' => 'Groups',
1712: 'blogs' => 'Blogs',
1713: 'about' => 'User Information',
1714: 'printout' => 'Printouts',
1715: 'passwd' => 'Change Password',
1716: 'grades' => 'Gradebook',
1717: 'search' => 'Course search',
1718: 'wishlist' => 'Stored links',
1719: 'annotate' => 'Annotations',
1720: );
1721: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1722: return ($typeorder,\%types);
1723: }
1724:
1725: sub print_rolecolors {
1726: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1727: my %choices = &color_font_choices();
1728: my @bgs = ('pgbg','tabbg','sidebg');
1729: my @links = ('link','alink','vlink');
1730: my @images = ('img');
1731: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1732: my %designhash = &Apache::loncommon::get_domainconf($dom);
1733: my %defaultdesign = %Apache::loncommon::defaultdesign;
1734: my (%is_custom,%designs);
1735: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1736: if (ref($settings) eq 'HASH') {
1737: if (ref($settings->{$role}) eq 'HASH') {
1738: if ($settings->{$role}->{'img'} ne '') {
1739: $designs{'img'} = $settings->{$role}->{'img'};
1740: $is_custom{'img'} = 1;
1741: }
1742: if ($settings->{$role}->{'font'} ne '') {
1743: $designs{'font'} = $settings->{$role}->{'font'};
1744: $is_custom{'font'} = 1;
1745: }
1746: if ($settings->{$role}->{'fontmenu'} ne '') {
1747: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1748: $is_custom{'fontmenu'} = 1;
1749: }
1750: foreach my $item (@bgs) {
1751: if ($settings->{$role}->{$item} ne '') {
1752: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1753: $is_custom{$item} = 1;
1754: }
1755: }
1756: foreach my $item (@links) {
1757: if ($settings->{$role}->{$item} ne '') {
1758: $designs{'links'}{$item} = $settings->{$role}->{$item};
1759: $is_custom{$item} = 1;
1760: }
1761: }
1762: }
1763: } else {
1764: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1765: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1766: $is_custom{'img'} = 1;
1767: }
1768: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1769: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1770: $is_custom{'fontmenu'} = 1;
1771: }
1772: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1773: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1774: $is_custom{'font'} = 1;
1775: }
1776: foreach my $item (@bgs) {
1777: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1778: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1779: $is_custom{$item} = 1;
1780:
1781: }
1782: }
1783: foreach my $item (@links) {
1784: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1785: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1786: $is_custom{$item} = 1;
1787: }
1788: }
1789: }
1790: my $itemcount = 1;
1791: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1792: $datatable .= '</tr></table></td></tr>';
1793: return $datatable;
1794: }
1795:
1796: sub role_defaults {
1797: my ($role,$bgs,$links,$images,$logintext) = @_;
1798: my %defaults;
1799: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1800: return %defaults;
1801: }
1802: my %defaultdesign = %Apache::loncommon::defaultdesign;
1803: if ($role eq 'login') {
1804: %defaults = (
1805: font => $defaultdesign{$role.'.font'},
1806: );
1807: if (ref($logintext) eq 'ARRAY') {
1808: foreach my $item (@{$logintext}) {
1809: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1810: }
1811: }
1812: foreach my $item (@{$images}) {
1813: $defaults{'showlogo'}{$item} = 1;
1814: }
1815: } else {
1816: %defaults = (
1817: img => $defaultdesign{$role.'.img'},
1818: font => $defaultdesign{$role.'.font'},
1819: fontmenu => $defaultdesign{$role.'.fontmenu'},
1820: );
1821: }
1822: foreach my $item (@{$bgs}) {
1823: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1824: }
1825: foreach my $item (@{$links}) {
1826: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1827: }
1828: foreach my $item (@{$images}) {
1829: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1830: }
1831: return %defaults;
1832: }
1833:
1834: sub display_color_options {
1835: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1836: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1837: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1838: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1839: my $datatable = '<tr'.$css_class.'>'.
1840: '<td>'.$choices->{'font'}.'</td>';
1841: if (!$is_custom->{'font'}) {
1842: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1843: } else {
1844: $datatable .= '<td> </td>';
1845: }
1846: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1847:
1848: $datatable .= '<td><span class="LC_nobreak">'.
1849: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1850: ' value="'.$current_color.'" /> '.
1851: ' </span></td></tr>';
1852: unless ($role eq 'login') {
1853: $datatable .= '<tr'.$css_class.'>'.
1854: '<td>'.$choices->{'fontmenu'}.'</td>';
1855: if (!$is_custom->{'fontmenu'}) {
1856: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1857: } else {
1858: $datatable .= '<td> </td>';
1859: }
1860: $current_color = $designs->{'fontmenu'} ?
1861: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1862: $datatable .= '<td><span class="LC_nobreak">'.
1863: '<input class="colorchooser" type="text" size="10" name="'
1864: .$role.'_fontmenu"'.
1865: ' value="'.$current_color.'" /> '.
1866: ' </span></td></tr>';
1867: }
1868: my $switchserver = &check_switchserver($dom,$confname);
1869: foreach my $img (@{$images}) {
1870: $itemcount ++;
1871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1872: $datatable .= '<tr'.$css_class.'>'.
1873: '<td>'.$choices->{$img};
1874: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1875: if ($role eq 'login') {
1876: if ($img eq 'login') {
1877: $login_hdr_pick =
1878: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1879: $logincolors =
1880: &login_text_colors($img,$role,$logintext,$phase,$choices,
1881: $designs,$defaults);
1882: } else {
1883: if ($img ne 'domlogo') {
1884: $datatable.= &logo_display_options($img,$defaults,$designs);
1885: }
1886: if (ref($designs->{'alttext'}) eq 'HASH') {
1887: $alttext = $designs->{'alttext'}{$img};
1888: }
1889: }
1890: }
1891: $datatable .= '</td>';
1892: if ($designs->{$img} ne '') {
1893: $imgfile = $designs->{$img};
1894: $img_import = ($imgfile =~ m{^/adm/});
1895: } else {
1896: $imgfile = $defaults->{$img};
1897: }
1898: if ($imgfile) {
1899: my ($showfile,$fullsize);
1900: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1901: my $urldir = $1;
1902: my $filename = $2;
1903: my @info = &Apache::lonnet::stat_file($designs->{$img});
1904: if (@info) {
1905: my $thumbfile = 'tn-'.$filename;
1906: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1907: if (@thumb) {
1908: $showfile = $urldir.'/'.$thumbfile;
1909: } else {
1910: $showfile = $imgfile;
1911: }
1912: } else {
1913: $showfile = '';
1914: }
1915: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1916: $showfile = $imgfile;
1917: my $imgdir = $1;
1918: my $filename = $2;
1919: if (-e "$londocroot/$imgdir/tn-".$filename) {
1920: $showfile = "/$imgdir/tn-".$filename;
1921: } else {
1922: my $input = $londocroot.$imgfile;
1923: my $output = "$londocroot/$imgdir/tn-".$filename;
1924: if (!-e $output) {
1925: my ($width,$height) = &thumb_dimensions();
1926: my ($fullwidth,$fullheight) = &check_dimensions($input);
1927: if ($fullwidth ne '' && $fullheight ne '') {
1928: if ($fullwidth > $width && $fullheight > $height) {
1929: my $size = $width.'x'.$height;
1930: my @args = ('convert','-sample',$size,$input,$output);
1931: system({$args[0]} @args);
1932: $showfile = "/$imgdir/tn-".$filename;
1933: }
1934: }
1935: }
1936: }
1937: }
1938: if ($showfile) {
1939: if ($showfile =~ m{^/(adm|res)/}) {
1940: if ($showfile =~ m{^/res/}) {
1941: my $local_showfile =
1942: &Apache::lonnet::filelocation('',$showfile);
1943: &Apache::lonnet::repcopy($local_showfile);
1944: }
1945: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1946: }
1947: if ($imgfile) {
1948: if ($imgfile =~ m{^/(adm|res)/}) {
1949: if ($imgfile =~ m{^/res/}) {
1950: my $local_imgfile =
1951: &Apache::lonnet::filelocation('',$imgfile);
1952: &Apache::lonnet::repcopy($local_imgfile);
1953: }
1954: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1955: } else {
1956: $fullsize = $imgfile;
1957: }
1958: }
1959: $datatable .= '<td>';
1960: if ($img eq 'login') {
1961: $datatable .= $login_hdr_pick;
1962: }
1963: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1964: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1965: } else {
1966: $datatable .= '<td> </td><td class="LC_left_item">'.
1967: &mt('Upload:').'<br />';
1968: }
1969: } else {
1970: $datatable .= '<td> </td><td class="LC_left_item">'.
1971: &mt('Upload:').'<br />';
1972: }
1973: if ($switchserver) {
1974: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1975: } else {
1976: if ($img ne 'login') { # suppress file selection for Log-in header
1977: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1978: }
1979: }
1980: if (($role eq 'login') && ($img ne 'login')) {
1981: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
1982: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
1983: '</label></span>';
1984: }
1985: $datatable .= '</td></tr>';
1986: }
1987: $itemcount ++;
1988: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1989: $datatable .= '<tr'.$css_class.'>'.
1990: '<td>'.$choices->{'bgs'}.'</td>';
1991: my $bgs_def;
1992: foreach my $item (@{$bgs}) {
1993: if (!$is_custom->{$item}) {
1994: $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>';
1995: }
1996: }
1997: if ($bgs_def) {
1998: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1999: } else {
2000: $datatable .= '<td> </td>';
2001: }
2002: $datatable .= '<td class="LC_right_item">'.
2003: '<table border="0"><tr>';
2004:
2005: foreach my $item (@{$bgs}) {
2006: $datatable .= '<td align="center">'.$choices->{$item};
2007: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
2008: if ($designs->{'bgs'}{$item}) {
2009: $datatable .= ' ';
2010: }
2011: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2012: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
2013: }
2014: $datatable .= '</tr></table></td></tr>';
2015: $itemcount ++;
2016: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2017: $datatable .= '<tr'.$css_class.'>'.
2018: '<td>'.$choices->{'links'}.'</td>';
2019: my $links_def;
2020: foreach my $item (@{$links}) {
2021: if (!$is_custom->{$item}) {
2022: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
2023: }
2024: }
2025: if ($links_def) {
2026: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
2027: } else {
2028: $datatable .= '<td> </td>';
2029: }
2030: $datatable .= '<td class="LC_right_item">'.
2031: '<table border="0"><tr>';
2032: foreach my $item (@{$links}) {
2033: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
2034: $datatable .= '<td align="center">'.$choices->{$item}."\n";
2035: if ($designs->{'links'}{$item}) {
2036: $datatable.=' ';
2037: }
2038: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
2039: '" /></td>';
2040: }
2041: $$rowtotal += $itemcount;
2042: return $datatable;
2043: }
2044:
2045: sub logo_display_options {
2046: my ($img,$defaults,$designs) = @_;
2047: my $checkedon;
2048: if (ref($defaults) eq 'HASH') {
2049: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2050: if ($defaults->{'showlogo'}{$img}) {
2051: $checkedon = 'checked="checked" ';
2052: }
2053: }
2054: }
2055: if (ref($designs) eq 'HASH') {
2056: if (ref($designs->{'showlogo'}) eq 'HASH') {
2057: if (defined($designs->{'showlogo'}{$img})) {
2058: if ($designs->{'showlogo'}{$img} == 0) {
2059: $checkedon = '';
2060: } elsif ($designs->{'showlogo'}{$img} == 1) {
2061: $checkedon = 'checked="checked" ';
2062: }
2063: }
2064: }
2065: }
2066: return '<br /><label> <input type="checkbox" name="'.
2067: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2068: &mt('show').'</label>'."\n";
2069: }
2070:
2071: sub login_header_options {
2072: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2073: my $output = '';
2074: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
2075: $output .= &mt('Text default(s):').'<br />';
2076: if (!$is_custom->{'textcol'}) {
2077: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2078: ' ';
2079: }
2080: if (!$is_custom->{'bgcol'}) {
2081: $output .= $choices->{'bgcol'}.': '.
2082: '<span id="css_'.$role.'_font" style="background-color: '.
2083: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2084: }
2085: $output .= '<br />';
2086: }
2087: $output .='<br />';
2088: return $output;
2089: }
2090:
2091: sub login_text_colors {
2092: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
2093: my $color_menu = '<table border="0"><tr>';
2094: foreach my $item (@{$logintext}) {
2095: $color_menu .= '<td align="center">'.$choices->{$item};
2096: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2097: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2098: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
2099: }
2100: $color_menu .= '</tr></table><br />';
2101: return $color_menu;
2102: }
2103:
2104: sub image_changes {
2105: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2106: my $output;
2107: if ($img eq 'login') {
2108: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
2109: } elsif (!$is_custom) {
2110: if ($img ne 'domlogo') {
2111: $output = &mt('Default image:').'<br />';
2112: } else {
2113: $output = &mt('Default in use:').'<br />';
2114: }
2115: }
2116: if ($img ne 'login') {
2117: if ($img_import) {
2118: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2119: }
2120: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2121: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2122: if ($is_custom) {
2123: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2124: '<input type="checkbox" name="'.
2125: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2126: '</label> '.&mt('Replace:').'</span><br />';
2127: } else {
2128: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
2129: }
2130: }
2131: return $output;
2132: }
2133:
2134: sub print_quotas {
2135: my ($dom,$settings,$rowtotal,$action) = @_;
2136: my $context;
2137: if ($action eq 'quotas') {
2138: $context = 'tools';
2139: } else {
2140: $context = $action;
2141: }
2142: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
2143: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2144: my $typecount = 0;
2145: my ($css_class,%titles);
2146: if ($context eq 'requestcourses') {
2147: @usertools = ('official','unofficial','community','textbook');
2148: @options =('norequest','approval','validate','autolimit');
2149: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2150: %titles = &courserequest_titles();
2151: } elsif ($context eq 'requestauthor') {
2152: @usertools = ('author');
2153: @options = ('norequest','approval','automatic');
2154: %titles = &authorrequest_titles();
2155: } else {
2156: @usertools = ('aboutme','blog','webdav','portfolio');
2157: %titles = &tool_titles();
2158: }
2159: if (ref($types) eq 'ARRAY') {
2160: foreach my $type (@{$types}) {
2161: my ($currdefquota,$currauthorquota);
2162: unless (($context eq 'requestcourses') ||
2163: ($context eq 'requestauthor')) {
2164: if (ref($settings) eq 'HASH') {
2165: if (ref($settings->{defaultquota}) eq 'HASH') {
2166: $currdefquota = $settings->{defaultquota}->{$type};
2167: } else {
2168: $currdefquota = $settings->{$type};
2169: }
2170: if (ref($settings->{authorquota}) eq 'HASH') {
2171: $currauthorquota = $settings->{authorquota}->{$type};
2172: }
2173: }
2174: }
2175: if (defined($usertypes->{$type})) {
2176: $typecount ++;
2177: $css_class = $typecount%2?' class="LC_odd_row"':'';
2178: $datatable .= '<tr'.$css_class.'>'.
2179: '<td>'.$usertypes->{$type}.'</td>'.
2180: '<td class="LC_left_item">';
2181: if ($context eq 'requestcourses') {
2182: $datatable .= '<table><tr>';
2183: }
2184: my %cell;
2185: foreach my $item (@usertools) {
2186: if ($context eq 'requestcourses') {
2187: my ($curroption,$currlimit);
2188: if (ref($settings) eq 'HASH') {
2189: if (ref($settings->{$item}) eq 'HASH') {
2190: $curroption = $settings->{$item}->{$type};
2191: if ($curroption =~ /^autolimit=(\d*)$/) {
2192: $currlimit = $1;
2193: }
2194: }
2195: }
2196: if (!$curroption) {
2197: $curroption = 'norequest';
2198: }
2199: $datatable .= '<th>'.$titles{$item}.'</th>';
2200: foreach my $option (@options) {
2201: my $val = $option;
2202: if ($option eq 'norequest') {
2203: $val = 0;
2204: }
2205: if ($option eq 'validate') {
2206: my $canvalidate = 0;
2207: if (ref($validations{$item}) eq 'HASH') {
2208: if ($validations{$item}{$type}) {
2209: $canvalidate = 1;
2210: }
2211: }
2212: next if (!$canvalidate);
2213: }
2214: my $checked = '';
2215: if ($option eq $curroption) {
2216: $checked = ' checked="checked"';
2217: } elsif ($option eq 'autolimit') {
2218: if ($curroption =~ /^autolimit/) {
2219: $checked = ' checked="checked"';
2220: }
2221: }
2222: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2223: '<input type="radio" name="crsreq_'.$item.
2224: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
2225: $titles{$option}.'</label>';
2226: if ($option eq 'autolimit') {
2227: $cell{$item} .= ' <input type="text" name="crsreq_'.
2228: $item.'_limit_'.$type.'" size="1" '.
2229: 'value="'.$currlimit.'" />';
2230: }
2231: $cell{$item} .= '</span> ';
2232: if ($option eq 'autolimit') {
2233: $cell{$item} .= $titles{'unlimited'};
2234: }
2235: }
2236: } elsif ($context eq 'requestauthor') {
2237: my $curroption;
2238: if (ref($settings) eq 'HASH') {
2239: $curroption = $settings->{$type};
2240: }
2241: if (!$curroption) {
2242: $curroption = 'norequest';
2243: }
2244: foreach my $option (@options) {
2245: my $val = $option;
2246: if ($option eq 'norequest') {
2247: $val = 0;
2248: }
2249: my $checked = '';
2250: if ($option eq $curroption) {
2251: $checked = ' checked="checked"';
2252: }
2253: $datatable .= '<span class="LC_nobreak"><label>'.
2254: '<input type="radio" name="authorreq_'.$type.
2255: '" value="'.$val.'"'.$checked.' />'.
2256: $titles{$option}.'</label></span> ';
2257: }
2258: } else {
2259: my $checked = 'checked="checked" ';
2260: if (ref($settings) eq 'HASH') {
2261: if (ref($settings->{$item}) eq 'HASH') {
2262: if ($settings->{$item}->{$type} == 0) {
2263: $checked = '';
2264: } elsif ($settings->{$item}->{$type} == 1) {
2265: $checked = 'checked="checked" ';
2266: }
2267: }
2268: }
2269: $datatable .= '<span class="LC_nobreak"><label>'.
2270: '<input type="checkbox" name="'.$context.'_'.$item.
2271: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2272: '</label></span> ';
2273: }
2274: }
2275: if ($context eq 'requestcourses') {
2276: $datatable .= '</tr><tr>';
2277: foreach my $item (@usertools) {
2278: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
2279: }
2280: $datatable .= '</tr></table>';
2281: }
2282: $datatable .= '</td>';
2283: unless (($context eq 'requestcourses') ||
2284: ($context eq 'requestauthor')) {
2285: $datatable .=
2286: '<td class="LC_right_item">'.
2287: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2288: '<input type="text" name="quota_'.$type.
2289: '" value="'.$currdefquota.
2290: '" size="5" /></span>'.(' ' x 2).
2291: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2292: '<input type="text" name="authorquota_'.$type.
2293: '" value="'.$currauthorquota.
2294: '" size="5" /></span></td>';
2295: }
2296: $datatable .= '</tr>';
2297: }
2298: }
2299: }
2300: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2301: $defaultquota = '20';
2302: $authorquota = '500';
2303: if (ref($settings) eq 'HASH') {
2304: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2305: $defaultquota = $settings->{'defaultquota'}->{'default'};
2306: } elsif (defined($settings->{'default'})) {
2307: $defaultquota = $settings->{'default'};
2308: }
2309: if (ref($settings->{'authorquota'}) eq 'HASH') {
2310: $authorquota = $settings->{'authorquota'}->{'default'};
2311: }
2312: }
2313: }
2314: $typecount ++;
2315: $css_class = $typecount%2?' class="LC_odd_row"':'';
2316: $datatable .= '<tr'.$css_class.'>'.
2317: '<td>'.$othertitle.'</td>'.
2318: '<td class="LC_left_item">';
2319: if ($context eq 'requestcourses') {
2320: $datatable .= '<table><tr>';
2321: }
2322: my %defcell;
2323: foreach my $item (@usertools) {
2324: if ($context eq 'requestcourses') {
2325: my ($curroption,$currlimit);
2326: if (ref($settings) eq 'HASH') {
2327: if (ref($settings->{$item}) eq 'HASH') {
2328: $curroption = $settings->{$item}->{'default'};
2329: if ($curroption =~ /^autolimit=(\d*)$/) {
2330: $currlimit = $1;
2331: }
2332: }
2333: }
2334: if (!$curroption) {
2335: $curroption = 'norequest';
2336: }
2337: $datatable .= '<th>'.$titles{$item}.'</th>';
2338: foreach my $option (@options) {
2339: my $val = $option;
2340: if ($option eq 'norequest') {
2341: $val = 0;
2342: }
2343: if ($option eq 'validate') {
2344: my $canvalidate = 0;
2345: if (ref($validations{$item}) eq 'HASH') {
2346: if ($validations{$item}{'default'}) {
2347: $canvalidate = 1;
2348: }
2349: }
2350: next if (!$canvalidate);
2351: }
2352: my $checked = '';
2353: if ($option eq $curroption) {
2354: $checked = ' checked="checked"';
2355: } elsif ($option eq 'autolimit') {
2356: if ($curroption =~ /^autolimit/) {
2357: $checked = ' checked="checked"';
2358: }
2359: }
2360: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2361: '<input type="radio" name="crsreq_'.$item.
2362: '_default" value="'.$val.'"'.$checked.' />'.
2363: $titles{$option}.'</label>';
2364: if ($option eq 'autolimit') {
2365: $defcell{$item} .= ' <input type="text" name="crsreq_'.
2366: $item.'_limit_default" size="1" '.
2367: 'value="'.$currlimit.'" />';
2368: }
2369: $defcell{$item} .= '</span> ';
2370: if ($option eq 'autolimit') {
2371: $defcell{$item} .= $titles{'unlimited'};
2372: }
2373: }
2374: } elsif ($context eq 'requestauthor') {
2375: my $curroption;
2376: if (ref($settings) eq 'HASH') {
2377: $curroption = $settings->{'default'};
2378: }
2379: if (!$curroption) {
2380: $curroption = 'norequest';
2381: }
2382: foreach my $option (@options) {
2383: my $val = $option;
2384: if ($option eq 'norequest') {
2385: $val = 0;
2386: }
2387: my $checked = '';
2388: if ($option eq $curroption) {
2389: $checked = ' checked="checked"';
2390: }
2391: $datatable .= '<span class="LC_nobreak"><label>'.
2392: '<input type="radio" name="authorreq_default"'.
2393: ' value="'.$val.'"'.$checked.' />'.
2394: $titles{$option}.'</label></span> ';
2395: }
2396: } else {
2397: my $checked = 'checked="checked" ';
2398: if (ref($settings) eq 'HASH') {
2399: if (ref($settings->{$item}) eq 'HASH') {
2400: if ($settings->{$item}->{'default'} == 0) {
2401: $checked = '';
2402: } elsif ($settings->{$item}->{'default'} == 1) {
2403: $checked = 'checked="checked" ';
2404: }
2405: }
2406: }
2407: $datatable .= '<span class="LC_nobreak"><label>'.
2408: '<input type="checkbox" name="'.$context.'_'.$item.
2409: '" value="default" '.$checked.'/>'.$titles{$item}.
2410: '</label></span> ';
2411: }
2412: }
2413: if ($context eq 'requestcourses') {
2414: $datatable .= '</tr><tr>';
2415: foreach my $item (@usertools) {
2416: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
2417: }
2418: $datatable .= '</tr></table>';
2419: }
2420: $datatable .= '</td>';
2421: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2422: $datatable .= '<td class="LC_right_item">'.
2423: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2424: '<input type="text" name="defaultquota" value="'.
2425: $defaultquota.'" size="5" /></span>'.(' ' x2).
2426: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2427: '<input type="text" name="authorquota" value="'.
2428: $authorquota.'" size="5" /></span></td>';
2429: }
2430: $datatable .= '</tr>';
2431: $typecount ++;
2432: $css_class = $typecount%2?' class="LC_odd_row"':'';
2433: $datatable .= '<tr'.$css_class.'>'.
2434: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
2435: if ($context eq 'requestcourses') {
2436: $datatable .= &mt('(overrides affiliation, if set)').
2437: '</td>'.
2438: '<td class="LC_left_item">'.
2439: '<table><tr>';
2440: } else {
2441: $datatable .= &mt('(overrides affiliation, if checked)').
2442: '</td>'.
2443: '<td class="LC_left_item" colspan="2">'.
2444: '<br />';
2445: }
2446: my %advcell;
2447: foreach my $item (@usertools) {
2448: if ($context eq 'requestcourses') {
2449: my ($curroption,$currlimit);
2450: if (ref($settings) eq 'HASH') {
2451: if (ref($settings->{$item}) eq 'HASH') {
2452: $curroption = $settings->{$item}->{'_LC_adv'};
2453: if ($curroption =~ /^autolimit=(\d*)$/) {
2454: $currlimit = $1;
2455: }
2456: }
2457: }
2458: $datatable .= '<th>'.$titles{$item}.'</th>';
2459: my $checked = '';
2460: if ($curroption eq '') {
2461: $checked = ' checked="checked"';
2462: }
2463: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2464: '<input type="radio" name="crsreq_'.$item.
2465: '__LC_adv" value=""'.$checked.' />'.
2466: &mt('No override set').'</label></span> ';
2467: foreach my $option (@options) {
2468: my $val = $option;
2469: if ($option eq 'norequest') {
2470: $val = 0;
2471: }
2472: if ($option eq 'validate') {
2473: my $canvalidate = 0;
2474: if (ref($validations{$item}) eq 'HASH') {
2475: if ($validations{$item}{'_LC_adv'}) {
2476: $canvalidate = 1;
2477: }
2478: }
2479: next if (!$canvalidate);
2480: }
2481: my $checked = '';
2482: if ($val eq $curroption) {
2483: $checked = ' checked="checked"';
2484: } elsif ($option eq 'autolimit') {
2485: if ($curroption =~ /^autolimit/) {
2486: $checked = ' checked="checked"';
2487: }
2488: }
2489: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2490: '<input type="radio" name="crsreq_'.$item.
2491: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2492: $titles{$option}.'</label>';
2493: if ($option eq 'autolimit') {
2494: $advcell{$item} .= ' <input type="text" name="crsreq_'.
2495: $item.'_limit__LC_adv" size="1" '.
2496: 'value="'.$currlimit.'" />';
2497: }
2498: $advcell{$item} .= '</span> ';
2499: if ($option eq 'autolimit') {
2500: $advcell{$item} .= $titles{'unlimited'};
2501: }
2502: }
2503: } elsif ($context eq 'requestauthor') {
2504: my $curroption;
2505: if (ref($settings) eq 'HASH') {
2506: $curroption = $settings->{'_LC_adv'};
2507: }
2508: my $checked = '';
2509: if ($curroption eq '') {
2510: $checked = ' checked="checked"';
2511: }
2512: $datatable .= '<span class="LC_nobreak"><label>'.
2513: '<input type="radio" name="authorreq__LC_adv"'.
2514: ' value=""'.$checked.' />'.
2515: &mt('No override set').'</label></span> ';
2516: foreach my $option (@options) {
2517: my $val = $option;
2518: if ($option eq 'norequest') {
2519: $val = 0;
2520: }
2521: my $checked = '';
2522: if ($val eq $curroption) {
2523: $checked = ' checked="checked"';
2524: }
2525: $datatable .= '<span class="LC_nobreak"><label>'.
2526: '<input type="radio" name="authorreq__LC_adv"'.
2527: ' value="'.$val.'"'.$checked.' />'.
2528: $titles{$option}.'</label></span> ';
2529: }
2530: } else {
2531: my $checked = 'checked="checked" ';
2532: if (ref($settings) eq 'HASH') {
2533: if (ref($settings->{$item}) eq 'HASH') {
2534: if ($settings->{$item}->{'_LC_adv'} == 0) {
2535: $checked = '';
2536: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2537: $checked = 'checked="checked" ';
2538: }
2539: }
2540: }
2541: $datatable .= '<span class="LC_nobreak"><label>'.
2542: '<input type="checkbox" name="'.$context.'_'.$item.
2543: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2544: '</label></span> ';
2545: }
2546: }
2547: if ($context eq 'requestcourses') {
2548: $datatable .= '</tr><tr>';
2549: foreach my $item (@usertools) {
2550: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2551: }
2552: $datatable .= '</tr></table>';
2553: }
2554: $datatable .= '</td></tr>';
2555: $$rowtotal += $typecount;
2556: return $datatable;
2557: }
2558:
2559: sub print_requestmail {
2560: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
2561: my ($now,$datatable,%currapp);
2562: $now = time;
2563: if (ref($settings) eq 'HASH') {
2564: if (ref($settings->{'notify'}) eq 'HASH') {
2565: if ($settings->{'notify'}{'approval'} ne '') {
2566: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2567: }
2568: }
2569: }
2570: my $numinrow = 2;
2571: my $css_class;
2572: if ($$rowtotal%2) {
2573: $css_class = 'LC_odd_row';
2574: }
2575: if ($customcss) {
2576: $css_class .= " $customcss";
2577: }
2578: $css_class =~ s/^\s+//;
2579: if ($css_class) {
2580: $css_class = ' class="'.$css_class.'"';
2581: }
2582: if ($rowstyle) {
2583: $css_class .= ' style="'.$rowstyle.'"';
2584: }
2585: my $text;
2586: if ($action eq 'requestcourses') {
2587: $text = &mt('Receive notification of course requests requiring approval');
2588: } elsif ($action eq 'requestauthor') {
2589: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2590: } else {
2591: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2592: }
2593: $datatable = '<tr'.$css_class.'>'.
2594: ' <td>'.$text.'</td>'.
2595: ' <td class="LC_left_item">';
2596: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2597: $action.'notifyapproval',%currapp);
2598: if ($numdc > 0) {
2599: $datatable .= $table;
2600: } else {
2601: $datatable .= &mt('There are no active Domain Coordinators');
2602: }
2603: $datatable .='</td></tr>';
2604: return $datatable;
2605: }
2606:
2607: sub print_studentcode {
2608: my ($settings,$rowtotal) = @_;
2609: my $rownum = 0;
2610: my ($output,%current);
2611: my @crstypes = ('official','unofficial','community','textbook');
2612: if (ref($settings) eq 'HASH') {
2613: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2614: foreach my $type (@crstypes) {
2615: $current{$type} = $settings->{'uniquecode'}{$type};
2616: }
2617: }
2618: }
2619: $output .= '<tr>'.
2620: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2621: '<td class="LC_left_item">';
2622: foreach my $type (@crstypes) {
2623: my $check = ' ';
2624: if ($current{$type}) {
2625: $check = ' checked="checked" ';
2626: }
2627: $output .= '<span class="LC_nobreak"><label>'.
2628: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2629: &mt($type).'</label></span>'.(' 'x2).' ';
2630: }
2631: $output .= '</td></tr>';
2632: $$rowtotal ++;
2633: return $output;
2634: }
2635:
2636: sub print_textbookcourses {
2637: my ($dom,$type,$settings,$rowtotal) = @_;
2638: my $rownum = 0;
2639: my $css_class;
2640: my $itemcount = 1;
2641: my $maxnum = 0;
2642: my $bookshash;
2643: if (ref($settings) eq 'HASH') {
2644: $bookshash = $settings->{$type};
2645: }
2646: my %ordered;
2647: if (ref($bookshash) eq 'HASH') {
2648: foreach my $item (keys(%{$bookshash})) {
2649: if (ref($bookshash->{$item}) eq 'HASH') {
2650: my $num = $bookshash->{$item}{'order'};
2651: $ordered{$num} = $item;
2652: }
2653: }
2654: }
2655: my $confname = $dom.'-domainconfig';
2656: my $switchserver = &check_switchserver($dom,$confname);
2657: my $maxnum = scalar(keys(%ordered));
2658: my $datatable;
2659: if (keys(%ordered)) {
2660: my @items = sort { $a <=> $b } keys(%ordered);
2661: for (my $i=0; $i<@items; $i++) {
2662: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2663: my $key = $ordered{$items[$i]};
2664: my %coursehash=&Apache::lonnet::coursedescription($key);
2665: my $coursetitle = $coursehash{'description'};
2666: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2667: if (ref($bookshash->{$key}) eq 'HASH') {
2668: $subject = $bookshash->{$key}->{'subject'};
2669: $title = $bookshash->{$key}->{'title'};
2670: if ($type eq 'textbooks') {
2671: $publisher = $bookshash->{$key}->{'publisher'};
2672: $author = $bookshash->{$key}->{'author'};
2673: $image = $bookshash->{$key}->{'image'};
2674: if ($image ne '') {
2675: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2676: my $imagethumb = "$path/tn-".$imagefile;
2677: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2678: }
2679: }
2680: }
2681: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2682: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2683: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2684: for (my $k=0; $k<=$maxnum; $k++) {
2685: my $vpos = $k+1;
2686: my $selstr;
2687: if ($k == $i) {
2688: $selstr = ' selected="selected" ';
2689: }
2690: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2691: }
2692: $datatable .= '</select>'.(' 'x2).
2693: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2694: &mt('Delete?').'</label></span></td>'.
2695: '<td colspan="2">'.
2696: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2697: (' 'x2).
2698: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2699: if ($type eq 'textbooks') {
2700: $datatable .= (' 'x2).
2701: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2702: (' 'x2).
2703: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2704: (' 'x2).
2705: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2706: if ($image) {
2707: $datatable .= $imgsrc.
2708: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2709: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2710: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2711: }
2712: if ($switchserver) {
2713: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2714: } else {
2715: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2716: }
2717: }
2718: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2719: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2720: $coursetitle.'</span></td></tr>'."\n";
2721: $itemcount ++;
2722: }
2723: }
2724: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2725: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2726: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2727: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2728: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2729: for (my $k=0; $k<$maxnum+1; $k++) {
2730: my $vpos = $k+1;
2731: my $selstr;
2732: if ($k == $maxnum) {
2733: $selstr = ' selected="selected" ';
2734: }
2735: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2736: }
2737: $datatable .= '</select> '."\n".
2738: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
2739: '<td colspan="2">'.
2740: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2741: (' 'x2).
2742: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2743: (' 'x2);
2744: if ($type eq 'textbooks') {
2745: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2746: (' 'x2).
2747: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2748: (' 'x2).
2749: '<span class="LC_nobreak">'.&mt('Image:').' ';
2750: if ($switchserver) {
2751: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2752: } else {
2753: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2754: }
2755: $datatable .= '</span>'."\n";
2756: }
2757: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2758: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2759: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2760: &Apache::loncommon::selectcourse_link
2761: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
2762: '</span></td>'."\n".
2763: '</tr>'."\n";
2764: $itemcount ++;
2765: return $datatable;
2766: }
2767:
2768: sub textbookcourses_javascript {
2769: my ($settings) = @_;
2770: return unless(ref($settings) eq 'HASH');
2771: my (%ordered,%total,%jstext);
2772: foreach my $type ('textbooks','templates') {
2773: $total{$type} = 0;
2774: if (ref($settings->{$type}) eq 'HASH') {
2775: foreach my $item (keys(%{$settings->{$type}})) {
2776: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2777: my $num = $settings->{$type}->{$item}{'order'};
2778: $ordered{$type}{$num} = $item;
2779: }
2780: }
2781: $total{$type} = scalar(keys(%{$settings->{$type}}));
2782: }
2783: my @jsarray = ();
2784: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2785: push(@jsarray,$ordered{$type}{$item});
2786: }
2787: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2788: }
2789: return <<"ENDSCRIPT";
2790: <script type="text/javascript">
2791: // <![CDATA[
2792: function reorderBooks(form,item,caller) {
2793: var changedVal;
2794: $jstext{'textbooks'};
2795: $jstext{'templates'};
2796: var newpos;
2797: var maxh;
2798: if (caller == 'textbooks') {
2799: newpos = 'textbooks_addbook_pos';
2800: maxh = 1 + $total{'textbooks'};
2801: } else {
2802: newpos = 'templates_addbook_pos';
2803: maxh = 1 + $total{'templates'};
2804: }
2805: var current = new Array;
2806: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2807: if (item == newpos) {
2808: changedVal = newitemVal;
2809: } else {
2810: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2811: current[newitemVal] = newpos;
2812: }
2813: if (caller == 'textbooks') {
2814: for (var i=0; i<textbooks.length; i++) {
2815: var elementName = 'textbooks_'+textbooks[i];
2816: if (elementName != item) {
2817: if (form.elements[elementName]) {
2818: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2819: current[currVal] = elementName;
2820: }
2821: }
2822: }
2823: }
2824: if (caller == 'templates') {
2825: for (var i=0; i<templates.length; i++) {
2826: var elementName = 'templates_'+templates[i];
2827: if (elementName != item) {
2828: if (form.elements[elementName]) {
2829: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2830: current[currVal] = elementName;
2831: }
2832: }
2833: }
2834: }
2835: var oldVal;
2836: for (var j=0; j<maxh; j++) {
2837: if (current[j] == undefined) {
2838: oldVal = j;
2839: }
2840: }
2841: if (oldVal < changedVal) {
2842: for (var k=oldVal+1; k<=changedVal ; k++) {
2843: var elementName = current[k];
2844: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2845: }
2846: } else {
2847: for (var k=changedVal; k<oldVal; k++) {
2848: var elementName = current[k];
2849: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2850: }
2851: }
2852: return;
2853: }
2854:
2855: // ]]>
2856: </script>
2857:
2858: ENDSCRIPT
2859: }
2860:
2861: sub wafproxy_javascript {
2862: my ($dom) = @_;
2863: return <<"ENDSCRIPT";
2864: <script type="text/javascript">
2865: // <![CDATA[
2866: function updateWAF() {
2867: if (document.getElementById('wafproxy_remoteip')) {
2868: var wafremote = 0;
2869: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2870: wafremote = 1;
2871: }
2872: var fields = new Array('header','trust');
2873: for (var i=0; i<fields.length; i++) {
2874: if (document.getElementById('wafproxy_'+fields[i])) {
2875: if (wafremote == 1) {
2876: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
2877: }
2878: else {
2879: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
2880: }
2881: }
2882: }
2883: if (document.getElementById('wafproxyranges_$dom')) {
2884: if (wafremote == 1) {
2885: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2886: } else {
2887: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2888: if (document.display.wafproxy_vpnaccess[i].checked) {
2889: if (document.display.wafproxy_vpnaccess[i].value == 0) {
2890: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2891: }
2892: }
2893: }
2894: }
2895: }
2896: }
2897: return;
2898: }
2899:
2900: function checkWAF() {
2901: if (document.getElementById('wafproxy_remoteip')) {
2902: var wafvpn = 0;
2903: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
2904: if (document.display.wafproxy_vpnaccess[i].checked) {
2905: if (document.display.wafproxy_vpnaccess[i].value == 1) {
2906: wafvpn = 1;
2907: }
2908: break;
2909: }
2910: }
2911: var vpn = new Array('vpnint','vpnext');
2912: for (var i=0; i<vpn.length; i++) {
2913: if (document.getElementById('wafproxy_show_'+vpn[i])) {
2914: if (wafvpn == 1) {
2915: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
2916: }
2917: else {
2918: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
2919: }
2920: }
2921: }
2922: if (document.getElementById('wafproxyranges_$dom')) {
2923: if (wafvpn == 1) {
2924: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
2925: }
2926: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
2927: document.getElementById('wafproxyranges_$dom').style.display = 'none';
2928: }
2929: }
2930: }
2931: return;
2932: }
2933:
2934: function toggleWAF() {
2935: if (document.getElementById('wafproxy_table')) {
2936: var wafproxy = 0;
2937: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
2938: if (document.display.wafproxy_${dom}[i].checked) {
2939: if (document.display.wafproxy_${dom}[i].value == 1) {
2940: wafproxy = 1;
2941: break;
2942: }
2943: }
2944: }
2945: if (wafproxy == 1) {
2946: document.getElementById('wafproxy_table').style.display='inline';
2947: }
2948: else {
2949: document.getElementById('wafproxy_table').style.display='none';
2950: }
2951: if (document.getElementById('wafproxyrow_${dom}')) {
2952: if (wafproxy == 1) {
2953: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
2954: }
2955: else {
2956: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
2957: }
2958: }
2959: if (document.getElementById('nowafproxyrow_$dom')) {
2960: if (wafproxy == 1) {
2961: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
2962: }
2963: else {
2964: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
2965: }
2966: }
2967: }
2968: return;
2969: }
2970: // ]]>
2971: </script>
2972:
2973: ENDSCRIPT
2974: }
2975:
2976: sub autoupdate_javascript {
2977: return <<"ENDSCRIPT";
2978: <script type="text/javascript">
2979: // <![CDATA[
2980: function toggleLastActiveDays(form) {
2981: var radioname = 'lastactive';
2982: var divid = 'lastactive_div';
2983: var num = form.elements[radioname].length;
2984: if (num) {
2985: var setvis = '';
2986: for (var i=0; i<num; i++) {
2987: if (form.elements[radioname][i].checked) {
2988: if (form.elements[radioname][i].value == '1') {
2989: if (document.getElementById(divid)) {
2990: document.getElementById(divid).style.display = 'inline-block';
2991: }
2992: setvis = 1;
2993: }
2994: break;
2995: }
2996: }
2997: if (!setvis) {
2998: if (document.getElementById(divid)) {
2999: document.getElementById(divid).style.display = 'none';
3000: }
3001: }
3002: }
3003: return;
3004: }
3005: // ]]>
3006: </script>
3007:
3008: ENDSCRIPT
3009: }
3010:
3011: sub autoenroll_javascript {
3012: return <<"ENDSCRIPT";
3013: <script type="text/javascript">
3014: // <![CDATA[
3015: function toggleFailsafe(form) {
3016: var radioname = 'autoenroll_failsafe';
3017: var divid = 'autoenroll_failsafe_div';
3018: var num = form.elements[radioname].length;
3019: if (num) {
3020: var setvis = '';
3021: for (var i=0; i<num; i++) {
3022: if (form.elements[radioname][i].checked) {
3023: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3024: if (document.getElementById(divid)) {
3025: document.getElementById(divid).style.display = 'inline-block';
3026: }
3027: setvis = 1;
3028: }
3029: break;
3030: }
3031: }
3032: if (!setvis) {
3033: if (document.getElementById(divid)) {
3034: document.getElementById(divid).style.display = 'none';
3035: }
3036: }
3037: }
3038: return;
3039: }
3040: // ]]>
3041: </script>
3042:
3043: ENDSCRIPT
3044: }
3045:
3046: sub saml_javascript {
3047: return <<"ENDSCRIPT";
3048: <script type="text/javascript">
3049: // <![CDATA[
3050: function toggleSamlOptions(form,hostid) {
3051: var radioname = 'saml_'+hostid;
3052: var tablecellon = 'samloptionson_'+hostid;
3053: var tablecelloff = 'samloptionsoff_'+hostid;
3054: var num = form.elements[radioname].length;
3055: if (num) {
3056: var setvis = '';
3057: for (var i=0; i<num; i++) {
3058: if (form.elements[radioname][i].checked) {
3059: if (form.elements[radioname][i].value == '1') {
3060: if (document.getElementById(tablecellon)) {
3061: document.getElementById(tablecellon).style.display='';
3062: }
3063: if (document.getElementById(tablecelloff)) {
3064: document.getElementById(tablecelloff).style.display='none';
3065: }
3066: setvis = 1;
3067: }
3068: break;
3069: }
3070: }
3071: if (!setvis) {
3072: if (document.getElementById(tablecellon)) {
3073: document.getElementById(tablecellon).style.display='none';
3074: }
3075: if (document.getElementById(tablecelloff)) {
3076: document.getElementById(tablecelloff).style.display='';
3077: }
3078: }
3079: }
3080: return;
3081: }
3082: // ]]>
3083: </script>
3084:
3085: ENDSCRIPT
3086: }
3087:
3088: sub ipaccess_javascript {
3089: my ($settings) = @_;
3090: my (%ordered,$total,%jstext);
3091: $total = 0;
3092: if (ref($settings) eq 'HASH') {
3093: foreach my $item (keys(%{$settings})) {
3094: if (ref($settings->{$item}) eq 'HASH') {
3095: my $num = $settings->{$item}{'order'};
3096: $ordered{$num} = $item;
3097: }
3098: }
3099: $total = scalar(keys(%{$settings}));
3100: }
3101: my @jsarray = ();
3102: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3103: push(@jsarray,$ordered{$item});
3104: }
3105: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3106: return <<"ENDSCRIPT";
3107: <script type="text/javascript">
3108: // <![CDATA[
3109: function reorderIPaccess(form,item) {
3110: var changedVal;
3111: $jstext
3112: var newpos = 'ipaccess_pos_add';
3113: var maxh = 1 + $total;
3114: var current = new Array;
3115: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3116: if (item == newpos) {
3117: changedVal = newitemVal;
3118: } else {
3119: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3120: current[newitemVal] = newpos;
3121: }
3122: for (var i=0; i<ipaccess.length; i++) {
3123: var elementName = 'ipaccess_pos_'+ipaccess[i];
3124: if (elementName != item) {
3125: if (form.elements[elementName]) {
3126: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3127: current[currVal] = elementName;
3128: }
3129: }
3130: }
3131: var oldVal;
3132: for (var j=0; j<maxh; j++) {
3133: if (current[j] == undefined) {
3134: oldVal = j;
3135: }
3136: }
3137: if (oldVal < changedVal) {
3138: for (var k=oldVal+1; k<=changedVal ; k++) {
3139: var elementName = current[k];
3140: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3141: }
3142: } else {
3143: for (var k=changedVal; k<oldVal; k++) {
3144: var elementName = current[k];
3145: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3146: }
3147: }
3148: return;
3149: }
3150: // ]]>
3151: </script>
3152:
3153: ENDSCRIPT
3154: }
3155:
3156: sub print_autoenroll {
3157: my ($dom,$settings,$rowtotal) = @_;
3158: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
3159: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3160: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3161: $failsafesty = 'none';
3162: %failsafechecked = (
3163: off => ' checked="checked"',
3164: );
3165: if (ref($settings) eq 'HASH') {
3166: if (exists($settings->{'run'})) {
3167: if ($settings->{'run'} eq '0') {
3168: $runoff = ' checked="checked" ';
3169: $runon = ' ';
3170: } else {
3171: $runon = ' checked="checked" ';
3172: $runoff = ' ';
3173: }
3174: } else {
3175: if ($autorun) {
3176: $runon = ' checked="checked" ';
3177: $runoff = ' ';
3178: } else {
3179: $runoff = ' checked="checked" ';
3180: $runon = ' ';
3181: }
3182: }
3183: if (exists($settings->{'co-owners'})) {
3184: if ($settings->{'co-owners'} eq '0') {
3185: $coownersoff = ' checked="checked" ';
3186: $coownerson = ' ';
3187: } else {
3188: $coownerson = ' checked="checked" ';
3189: $coownersoff = ' ';
3190: }
3191: } else {
3192: $coownersoff = ' checked="checked" ';
3193: $coownerson = ' ';
3194: }
3195: if (exists($settings->{'sender_domain'})) {
3196: $defdom = $settings->{'sender_domain'};
3197: }
3198: if (exists($settings->{'failsafe'})) {
3199: $failsafe = $settings->{'failsafe'};
3200: if ($failsafe eq 'zero') {
3201: $failsafechecked{'zero'} = ' checked="checked"';
3202: $failsafechecked{'off'} = '';
3203: $failsafesty = 'inline-block';
3204: } elsif ($failsafe eq 'any') {
3205: $failsafechecked{'any'} = ' checked="checked"';
3206: $failsafechecked{'off'} = '';
3207: }
3208: $autofailsafe = $settings->{'autofailsafe'};
3209: } elsif (exists($settings->{'autofailsafe'})) {
3210: $autofailsafe = $settings->{'autofailsafe'};
3211: if ($autofailsafe ne '') {
3212: $failsafechecked{'zero'} = ' checked="checked"';
3213: $failsafe = 'zero';
3214: $failsafechecked{'off'} = '';
3215: }
3216: }
3217: } else {
3218: if ($autorun) {
3219: $runon = ' checked="checked" ';
3220: $runoff = ' ';
3221: } else {
3222: $runoff = ' checked="checked" ';
3223: $runon = ' ';
3224: }
3225: }
3226: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
3227: my $notif_sender;
3228: if (ref($settings) eq 'HASH') {
3229: $notif_sender = $settings->{'sender_uname'};
3230: }
3231: my $datatable='<tr class="LC_odd_row">'.
3232: '<td>'.&mt('Auto-enrollment active?').'</td>'.
3233: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3234: '<input type="radio" name="autoenroll_run"'.
3235: $runon.' value="1" />'.&mt('Yes').'</label> '.
3236: '<label><input type="radio" name="autoenroll_run"'.
3237: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
3238: '</tr><tr>'.
3239: '<td>'.&mt('Notification messages - sender').
3240: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
3241: &mt('username').': '.
3242: '<input type="text" name="sender_uname" value="'.
3243: $notif_sender.'" size="10" /> '.&mt('domain').
3244: ': '.$domform.'</span></td></tr>'.
3245: '<tr class="LC_odd_row">'.
3246: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3247: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3248: '<input type="radio" name="autoassign_coowners"'.
3249: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3250: '<label><input type="radio" name="autoassign_coowners"'.
3251: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
3252: '</tr><tr>'.
3253: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3254: '<td class="LC_left_item"><span class="LC_nobreak">'.
3255: '<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> '.
3256: '<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 />'.
3257: '<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>'.
3258: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3259: '<span class="LC_nobreak">'.
3260: &mt('Threshold for number of students in section to drop: [_1]',
3261: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3262: '</span></div></td></tr>';
3263: $$rowtotal += 4;
3264: return $datatable;
3265: }
3266:
3267: sub print_autoupdate {
3268: my ($position,$dom,$settings,$rowtotal) = @_;
3269: my ($enable,$datatable);
3270: if ($position eq 'top') {
3271: my %choices = &Apache::lonlocal::texthash (
3272: run => 'Auto-update active?',
3273: classlists => 'Update information in classlists?',
3274: unexpired => 'Skip updates for users without active or future roles?',
3275: lastactive => 'Skip updates for inactive users?',
3276: );
3277: my $itemcount = 0;
3278: my $updateon = ' ';
3279: my $updateoff = ' checked="checked" ';
3280: if (ref($settings) eq 'HASH') {
3281: if ($settings->{'run'} eq '1') {
3282: $updateon = $updateoff;
3283: $updateoff = ' ';
3284: }
3285: }
3286: $enable = '<tr class="LC_odd_row">'.
3287: '<td>'.&mt($choices{'run'}).'</td>'.
3288: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3289: '<input type="radio" name="autoupdate_run"'.
3290: $updateoff.'value="0" />'.&mt('No').'</label> '.
3291: '<label><input type="radio" name="autoupdate_run"'.
3292: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
3293: '</tr>';
3294: my @toggles = ('classlists','unexpired');
3295: my %defaultchecked = ('classlists' => 'off',
3296: 'unexpired' => 'off'
3297: );
3298: $$rowtotal ++;
3299: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3300: \%choices,$itemcount,'','','left','no');
3301: $datatable = $enable.$datatable;
3302: $$rowtotal += $itemcount;
3303: my $lastactiveon = ' ';
3304: my $lastactiveoff = ' checked="checked" ';
3305: my $lastactivestyle = 'none';
3306: my $lastactivedays;
3307: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3308: if (ref($settings) eq 'HASH') {
3309: if ($settings->{'lastactive'} =~ /^\d+$/) {
3310: $lastactiveon = $lastactiveoff;
3311: $lastactiveoff = ' ';
3312: $lastactivestyle = 'inline-block';
3313: $lastactivedays = $settings->{'lastactive'};
3314: }
3315: }
3316: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3317: $datatable .= '<tr'.$css_class.'>'.
3318: '<td>'.$choices{'lastactive'}.'</td>'.
3319: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3320: '<input type="radio" name="lastactive"'.
3321: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3322: ' <label>'.
3323: '<input type="radio" name="lastactive"'.
3324: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3325: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3326: ': '.&mt('inactive = no activity in last [_1] days',
3327: '<input type="text" size="5" name="lastactivedays" value="'.
3328: $lastactivedays.'" />').
3329: '</span></td>'.
3330: '</tr>';
3331: $$rowtotal ++;
3332: } elsif ($position eq 'middle') {
3333: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3334: my $numinrow = 3;
3335: my $locknamesettings;
3336: $datatable .= &insttypes_row($settings,$types,$usertypes,
3337: $dom,$numinrow,$othertitle,
3338: 'lockablenames',$rowtotal);
3339: $$rowtotal ++;
3340: } else {
3341: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3342: my @fields = ('lastname','firstname','middlename','generation',
3343: 'permanentemail','id');
3344: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3345: my $numrows = 0;
3346: if (ref($types) eq 'ARRAY') {
3347: if (@{$types} > 0) {
3348: $datatable =
3349: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3350: \@fields,$types,\$numrows);
3351: $$rowtotal += @{$types};
3352: }
3353: }
3354: $datatable .=
3355: &usertype_update_row($settings,{'default' => $othertitle},
3356: \%fieldtitles,\@fields,['default'],
3357: \$numrows);
3358: $$rowtotal ++;
3359: }
3360: return $datatable;
3361: }
3362:
3363: sub print_autocreate {
3364: my ($dom,$settings,$rowtotal) = @_;
3365: my (%createon,%createoff,%currhash);
3366: my @types = ('xml','req');
3367: if (ref($settings) eq 'HASH') {
3368: foreach my $item (@types) {
3369: $createoff{$item} = ' checked="checked" ';
3370: $createon{$item} = ' ';
3371: if (exists($settings->{$item})) {
3372: if ($settings->{$item}) {
3373: $createon{$item} = ' checked="checked" ';
3374: $createoff{$item} = ' ';
3375: }
3376: }
3377: }
3378: if ($settings->{'xmldc'} ne '') {
3379: $currhash{$settings->{'xmldc'}} = 1;
3380: }
3381: } else {
3382: foreach my $item (@types) {
3383: $createoff{$item} = ' checked="checked" ';
3384: $createon{$item} = ' ';
3385: }
3386: }
3387: $$rowtotal += 2;
3388: my $numinrow = 2;
3389: my $datatable='<tr class="LC_odd_row">'.
3390: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3391: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3392: '<input type="radio" name="autocreate_xml"'.
3393: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3394: '<label><input type="radio" name="autocreate_xml"'.
3395: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3396: '</td></tr><tr>'.
3397: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3398: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3399: '<input type="radio" name="autocreate_req"'.
3400: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3401: '<label><input type="radio" name="autocreate_req"'.
3402: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
3403: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3404: 'autocreate_xmldc',%currhash);
3405: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
3406: if ($numdc > 1) {
3407: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3408: '</td><td class="LC_left_item">';
3409: } else {
3410: $datatable .= &mt('Course creation processed as:').
3411: '</td><td class="LC_right_item">';
3412: }
3413: $datatable .= $dctable.'</td></tr>';
3414: $$rowtotal += $rows;
3415: return $datatable;
3416: }
3417:
3418: sub print_directorysrch {
3419: my ($position,$dom,$settings,$rowtotal) = @_;
3420: my $datatable;
3421: if ($position eq 'top') {
3422: my $instsrchon = ' ';
3423: my $instsrchoff = ' checked="checked" ';
3424: my ($exacton,$containson,$beginson);
3425: my $instlocalon = ' ';
3426: my $instlocaloff = ' checked="checked" ';
3427: if (ref($settings) eq 'HASH') {
3428: if ($settings->{'available'} eq '1') {
3429: $instsrchon = $instsrchoff;
3430: $instsrchoff = ' ';
3431: }
3432: if ($settings->{'localonly'} eq '1') {
3433: $instlocalon = $instlocaloff;
3434: $instlocaloff = ' ';
3435: }
3436: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3437: foreach my $type (@{$settings->{'searchtypes'}}) {
3438: if ($type eq 'exact') {
3439: $exacton = ' checked="checked" ';
3440: } elsif ($type eq 'contains') {
3441: $containson = ' checked="checked" ';
3442: } elsif ($type eq 'begins') {
3443: $beginson = ' checked="checked" ';
3444: }
3445: }
3446: } else {
3447: if ($settings->{'searchtypes'} eq 'exact') {
3448: $exacton = ' checked="checked" ';
3449: } elsif ($settings->{'searchtypes'} eq 'contains') {
3450: $containson = ' checked="checked" ';
3451: } elsif ($settings->{'searchtypes'} eq 'specify') {
3452: $exacton = ' checked="checked" ';
3453: $containson = ' checked="checked" ';
3454: }
3455: }
3456: }
3457: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3458: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3459:
3460: my $numinrow = 4;
3461: my $cansrchrow = 0;
3462: $datatable='<tr class="LC_odd_row">'.
3463: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3464: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3465: '<input type="radio" name="dirsrch_available"'.
3466: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3467: '<label><input type="radio" name="dirsrch_available"'.
3468: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3469: '</tr><tr>'.
3470: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3471: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3472: '<input type="radio" name="dirsrch_instlocalonly"'.
3473: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3474: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3475: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3476: '</tr>';
3477: $$rowtotal += 2;
3478: if (ref($usertypes) eq 'HASH') {
3479: if (keys(%{$usertypes}) > 0) {
3480: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3481: $numinrow,$othertitle,'cansearch',
3482: $rowtotal);
3483: $cansrchrow = 1;
3484: }
3485: }
3486: if ($cansrchrow) {
3487: $$rowtotal ++;
3488: $datatable .= '<tr>';
3489: } else {
3490: $datatable .= '<tr class="LC_odd_row">';
3491: }
3492: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3493: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3494: foreach my $title (@{$titleorder}) {
3495: if (defined($searchtitles->{$title})) {
3496: my $check = ' ';
3497: if (ref($settings) eq 'HASH') {
3498: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3499: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3500: $check = ' checked="checked" ';
3501: }
3502: }
3503: }
3504: $datatable .= '<td class="LC_left_item">'.
3505: '<span class="LC_nobreak"><label>'.
3506: '<input type="checkbox" name="searchby" '.
3507: 'value="'.$title.'"'.$check.'/>'.
3508: $searchtitles->{$title}.'</label></span></td>';
3509: }
3510: }
3511: $datatable .= '</tr></table></td></tr>';
3512: $$rowtotal ++;
3513: if ($cansrchrow) {
3514: $datatable .= '<tr class="LC_odd_row">';
3515: } else {
3516: $datatable .= '<tr>';
3517: }
3518: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3519: '<td class="LC_left_item" colspan="2">'.
3520: '<span class="LC_nobreak"><label>'.
3521: '<input type="checkbox" name="searchtypes" '.
3522: $exacton.' value="exact" />'.&mt('Exact match').
3523: '</label> '.
3524: '<label><input type="checkbox" name="searchtypes" '.
3525: $beginson.' value="begins" />'.&mt('Begins with').
3526: '</label> '.
3527: '<label><input type="checkbox" name="searchtypes" '.
3528: $containson.' value="contains" />'.&mt('Contains').
3529: '</label></span></td></tr>';
3530: $$rowtotal ++;
3531: } else {
3532: my $domsrchon = ' checked="checked" ';
3533: my $domsrchoff = ' ';
3534: my $domlocalon = ' ';
3535: my $domlocaloff = ' checked="checked" ';
3536: if (ref($settings) eq 'HASH') {
3537: if ($settings->{'lclocalonly'} eq '1') {
3538: $domlocalon = $domlocaloff;
3539: $domlocaloff = ' ';
3540: }
3541: if ($settings->{'lcavailable'} eq '0') {
3542: $domsrchoff = $domsrchon;
3543: $domsrchon = ' ';
3544: }
3545: }
3546: $datatable='<tr class="LC_odd_row">'.
3547: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3548: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3549: '<input type="radio" name="dirsrch_domavailable"'.
3550: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3551: '<label><input type="radio" name="dirsrch_domavailable"'.
3552: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3553: '</tr><tr>'.
3554: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3555: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3556: '<input type="radio" name="dirsrch_domlocalonly"'.
3557: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3558: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3559: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3560: '</tr>';
3561: $$rowtotal += 2;
3562: }
3563: return $datatable;
3564: }
3565:
3566: sub print_contacts {
3567: my ($position,$dom,$settings,$rowtotal) = @_;
3568: my $datatable;
3569: my @contacts = ('adminemail','supportemail');
3570: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3571: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
3572: if ($position eq 'top') {
3573: if (ref($settings) eq 'HASH') {
3574: foreach my $item (@contacts) {
3575: if (exists($settings->{$item})) {
3576: $to{$item} = $settings->{$item};
3577: }
3578: }
3579: }
3580: } elsif ($position eq 'middle') {
3581: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3582: 'updatesmail','idconflictsmail','hostipmail');
3583: foreach my $type (@mailings) {
3584: $otheremails{$type} = '';
3585: }
3586: } elsif ($position eq 'lower') {
3587: if (ref($settings) eq 'HASH') {
3588: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3589: %lonstatus = %{$settings->{'lonstatus'}};
3590: }
3591: }
3592: } else {
3593: @mailings = ('helpdeskmail','otherdomsmail');
3594: foreach my $type (@mailings) {
3595: $otheremails{$type} = '';
3596: }
3597: $bccemails{'helpdeskmail'} = '';
3598: $bccemails{'otherdomsmail'} = '';
3599: $includestr{'helpdeskmail'} = '';
3600: $includestr{'otherdomsmail'} = '';
3601: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3602: }
3603: if (ref($settings) eq 'HASH') {
3604: unless (($position eq 'top') || ($position eq 'lower')) {
3605: foreach my $type (@mailings) {
3606: if (exists($settings->{$type})) {
3607: if (ref($settings->{$type}) eq 'HASH') {
3608: foreach my $item (@contacts) {
3609: if ($settings->{$type}{$item}) {
3610: $checked{$type}{$item} = ' checked="checked" ';
3611: }
3612: }
3613: $otheremails{$type} = $settings->{$type}{'others'};
3614: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3615: $bccemails{$type} = $settings->{$type}{'bcc'};
3616: if ($settings->{$type}{'include'} ne '') {
3617: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3618: $includestr{$type} = &unescape($includestr{$type});
3619: }
3620: }
3621: }
3622: } elsif ($type eq 'lonstatusmail') {
3623: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3624: }
3625: }
3626: }
3627: if ($position eq 'bottom') {
3628: foreach my $type (@mailings) {
3629: $bccemails{$type} = $settings->{$type}{'bcc'};
3630: if ($settings->{$type}{'include'} ne '') {
3631: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3632: $includestr{$type} = &unescape($includestr{$type});
3633: }
3634: }
3635: if (ref($settings->{'helpform'}) eq 'HASH') {
3636: if (ref($fields) eq 'ARRAY') {
3637: foreach my $field (@{$fields}) {
3638: $currfield{$field} = $settings->{'helpform'}{$field};
3639: }
3640: }
3641: if (exists($settings->{'helpform'}{'maxsize'})) {
3642: $maxsize = $settings->{'helpform'}{'maxsize'};
3643: } else {
3644: $maxsize = '1.0';
3645: }
3646: } else {
3647: if (ref($fields) eq 'ARRAY') {
3648: foreach my $field (@{$fields}) {
3649: $currfield{$field} = 'yes';
3650: }
3651: }
3652: $maxsize = '1.0';
3653: }
3654: }
3655: } else {
3656: if ($position eq 'top') {
3657: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3658: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3659: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3660: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3661: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3662: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3663: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3664: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3665: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
3666: } elsif ($position eq 'bottom') {
3667: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3668: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3669: if (ref($fields) eq 'ARRAY') {
3670: foreach my $field (@{$fields}) {
3671: $currfield{$field} = 'yes';
3672: }
3673: }
3674: $maxsize = '1.0';
3675: }
3676: }
3677: my ($titles,$short_titles) = &contact_titles();
3678: my $rownum = 0;
3679: my $css_class;
3680: if ($position eq 'top') {
3681: foreach my $item (@contacts) {
3682: $css_class = $rownum%2?' class="LC_odd_row"':'';
3683: $datatable .= '<tr'.$css_class.'>'.
3684: '<td><span class="LC_nobreak">'.$titles->{$item}.
3685: '</span></td><td class="LC_right_item">'.
3686: '<input type="text" name="'.$item.'" value="'.
3687: $to{$item}.'" /></td></tr>';
3688: $rownum ++;
3689: }
3690: } elsif ($position eq 'bottom') {
3691: $css_class = $rownum%2?' class="LC_odd_row"':'';
3692: $datatable .= '<tr'.$css_class.'>'.
3693: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3694: &mt('(e-mail, subject, and description always shown)').
3695: '</td><td class="LC_left_item">';
3696: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3697: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3698: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3699: foreach my $field (@{$fields}) {
3700: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3701: if (($field eq 'screenshot') || ($field eq 'cc')) {
3702: $datatable .= ' '.&mt('(logged-in users)');
3703: }
3704: $datatable .='</td><td>';
3705: my $clickaction;
3706: if ($field eq 'screenshot') {
3707: $clickaction = ' onclick="screenshotSize(this);"';
3708: }
3709: if (ref($possoptions->{$field}) eq 'ARRAY') {
3710: foreach my $option (@{$possoptions->{$field}}) {
3711: my $checked;
3712: if ($currfield{$field} eq $option) {
3713: $checked = ' checked="checked"';
3714: }
3715: $datatable .= '<span class="LC_nobreak"><label>'.
3716: '<input type="radio" name="helpform_'.$field.'" '.
3717: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3718: '</label></span>'.(' 'x2);
3719: }
3720: }
3721: if ($field eq 'screenshot') {
3722: my $display;
3723: if ($currfield{$field} eq 'no') {
3724: $display = ' style="display:none"';
3725: }
3726: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3727: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3728: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3729: }
3730: $datatable .= '</td></tr>';
3731: }
3732: $datatable .= '</table>';
3733: }
3734: $datatable .= '</td></tr>'."\n";
3735: $rownum ++;
3736: }
3737: unless (($position eq 'top') || ($position eq 'lower')) {
3738: foreach my $type (@mailings) {
3739: $css_class = $rownum%2?' class="LC_odd_row"':'';
3740: $datatable .= '<tr'.$css_class.'>'.
3741: '<td><span class="LC_nobreak">'.
3742: $titles->{$type}.': </span></td>'.
3743: '<td class="LC_left_item">';
3744: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3745: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3746: }
3747: $datatable .= '<span class="LC_nobreak">';
3748: foreach my $item (@contacts) {
3749: $datatable .= '<label>'.
3750: '<input type="checkbox" name="'.$type.'"'.
3751: $checked{$type}{$item}.
3752: ' value="'.$item.'" />'.$short_titles->{$item}.
3753: '</label> ';
3754: }
3755: $datatable .= '</span><br />'.&mt('Others').': '.
3756: '<input type="text" name="'.$type.'_others" '.
3757: 'value="'.$otheremails{$type}.'" />';
3758: my %locchecked;
3759: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3760: foreach my $loc ('s','b') {
3761: if ($includeloc{$type} eq $loc) {
3762: $locchecked{$loc} = ' checked="checked"';
3763: last;
3764: }
3765: }
3766: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3767: '<input type="text" name="'.$type.'_bcc" '.
3768: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3769: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3770: &mt('Text automatically added to e-mail:').' '.
3771: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
3772: '<span class="LC_nobreak">'.&mt('Location:').' '.
3773: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3774: (' 'x2).
3775: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3776: '</span></fieldset>';
3777: }
3778: $datatable .= '</td></tr>'."\n";
3779: $rownum ++;
3780: }
3781: }
3782: if ($position eq 'middle') {
3783: my %choices;
3784: my $corelink = &core_link_msu();
3785: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
3786: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3787: $corelink);
3788: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3789: my @toggles = ('reporterrors','reportupdates','reportstatus');
3790: my %defaultchecked = ('reporterrors' => 'on',
3791: 'reportupdates' => 'on',
3792: 'reportstatus' => 'on');
3793: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3794: \%choices,$rownum);
3795: $datatable .= $reports;
3796: } elsif ($position eq 'lower') {
3797: my (%current,%excluded,%weights);
3798: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3799: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3800: $current{'errorthreshold'} = $lonstatus{'threshold'};
3801: } else {
3802: $current{'errorthreshold'} = $defaults->{'threshold'};
3803: }
3804: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3805: $current{'errorsysmail'} = $lonstatus{'sysmail'};
3806: } else {
3807: $current{'errorsysmail'} = $defaults->{'sysmail'};
3808: }
3809: if (ref($lonstatus{'weights'}) eq 'HASH') {
3810: foreach my $type ('E','W','N','U') {
3811: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3812: $weights{$type} = $lonstatus{'weights'}{$type};
3813: } else {
3814: $weights{$type} = $defaults->{$type};
3815: }
3816: }
3817: } else {
3818: foreach my $type ('E','W','N','U') {
3819: $weights{$type} = $defaults->{$type};
3820: }
3821: }
3822: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3823: if (@{$lonstatus{'excluded'}} > 0) {
3824: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3825: }
3826: }
3827: foreach my $item ('errorthreshold','errorsysmail') {
3828: $css_class = $rownum%2?' class="LC_odd_row"':'';
3829: $datatable .= '<tr'.$css_class.'>'.
3830: '<td class="LC_left_item"><span class="LC_nobreak">'.
3831: $titles->{$item}.
3832: '</span></td><td class="LC_left_item">'.
3833: '<input type="text" name="'.$item.'" value="'.
3834: $current{$item}.'" size="5" /></td></tr>';
3835: $rownum ++;
3836: }
3837: $css_class = $rownum%2?' class="LC_odd_row"':'';
3838: $datatable .= '<tr'.$css_class.'>'.
3839: '<td class="LC_left_item">'.
3840: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3841: '</span></td><td class="LC_left_item"><table><tr>';
3842: foreach my $type ('E','W','N','U') {
3843: $datatable .= '<td>'.$names->{$type}.'<br />'.
3844: '<input type="text" name="errorweights_'.$type.'" value="'.
3845: $weights{$type}.'" size="5" /></td>';
3846: }
3847: $datatable .= '</tr></table></tr>';
3848: $rownum ++;
3849: $css_class = $rownum%2?' class="LC_odd_row"':'';
3850: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3851: $titles->{'errorexcluded'}.'</td>'.
3852: '<td class="LC_left_item"><table>';
3853: my $numinrow = 4;
3854: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3855: for (my $i=0; $i<@ids; $i++) {
3856: my $rem = $i%($numinrow);
3857: if ($rem == 0) {
3858: if ($i > 0) {
3859: $datatable .= '</tr>';
3860: }
3861: $datatable .= '<tr>';
3862: }
3863: my $check;
3864: if ($excluded{$ids[$i]}) {
3865: $check = ' checked="checked" ';
3866: }
3867: $datatable .= '<td class="LC_left_item">'.
3868: '<span class="LC_nobreak"><label>'.
3869: '<input type="checkbox" name="errorexcluded" '.
3870: 'value="'.$ids[$i].'"'.$check.' />'.
3871: $ids[$i].'</label></span></td>';
3872: }
3873: my $colsleft = $numinrow - @ids%($numinrow);
3874: if ($colsleft > 1 ) {
3875: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3876: ' </td>';
3877: } elsif ($colsleft == 1) {
3878: $datatable .= '<td class="LC_left_item"> </td>';
3879: }
3880: $datatable .= '</tr></table></td></tr>';
3881: $rownum ++;
3882: } elsif ($position eq 'bottom') {
3883: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3884: my (@posstypes,%usertypeshash);
3885: if (ref($types) eq 'ARRAY') {
3886: @posstypes = @{$types};
3887: }
3888: if (@posstypes) {
3889: if (ref($usertypes) eq 'HASH') {
3890: %usertypeshash = %{$usertypes};
3891: }
3892: my @overridden;
3893: my $numinrow = 4;
3894: if (ref($settings) eq 'HASH') {
3895: if (ref($settings->{'overrides'}) eq 'HASH') {
3896: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3897: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3898: push(@overridden,$key);
3899: foreach my $item (@contacts) {
3900: if ($settings->{'overrides'}{$key}{$item}) {
3901: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3902: }
3903: }
3904: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3905: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3906: $includeloc{'override_'.$key} = '';
3907: $includestr{'override_'.$key} = '';
3908: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3909: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3910: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3911: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3912: }
3913: }
3914: }
3915: }
3916: }
3917: my $customclass = 'LC_helpdesk_override';
3918: my $optionsprefix = 'LC_options_helpdesk_';
3919:
3920: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3921:
3922: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3923: $numinrow,$othertitle,'overrides',
3924: \$rownum,$onclicktypes,$customclass);
3925: $rownum ++;
3926: $usertypeshash{'default'} = $othertitle;
3927: foreach my $status (@posstypes) {
3928: my $css_class;
3929: if ($rownum%2) {
3930: $css_class = 'LC_odd_row ';
3931: }
3932: $css_class .= $customclass;
3933: my $rowid = $optionsprefix.$status;
3934: my $hidden = 1;
3935: my $currstyle = 'display:none';
3936: if (grep(/^\Q$status\E$/,@overridden)) {
3937: $currstyle = 'display:table-row';
3938: $hidden = 0;
3939: }
3940: my $key = 'override_'.$status;
3941: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3942: $includeloc{$key},$includestr{$key},$status,$rowid,
3943: $usertypeshash{$status},$css_class,$currstyle,
3944: \@contacts,$short_titles);
3945: unless ($hidden) {
3946: $rownum ++;
3947: }
3948: }
3949: }
3950: }
3951: $$rowtotal += $rownum;
3952: return $datatable;
3953: }
3954:
3955: sub core_link_msu {
3956: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3957: &mt('LON-CAPA core group - MSU'),600,500);
3958: }
3959:
3960: sub overridden_helpdesk {
3961: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3962: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3963: my $class = 'LC_left_item';
3964: if ($css_class) {
3965: $css_class = ' class="'.$css_class.'"';
3966: }
3967: if ($rowid) {
3968: $rowid = ' id="'.$rowid.'"';
3969: }
3970: if ($rowstyle) {
3971: $rowstyle = ' style="'.$rowstyle.'"';
3972: }
3973: my ($output,$description);
3974: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3975: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3976: "<td>$description</td>\n".
3977: '<td class="'.$class.'" colspan="2">'.
3978: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3979: '<span class="LC_nobreak">';
3980: if (ref($contacts) eq 'ARRAY') {
3981: foreach my $item (@{$contacts}) {
3982: my $check;
3983: if (ref($checked) eq 'HASH') {
3984: $check = $checked->{$item};
3985: }
3986: my $title;
3987: if (ref($short_titles) eq 'HASH') {
3988: $title = $short_titles->{$item};
3989: }
3990: $output .= '<label>'.
3991: '<input type="checkbox" name="override_'.$type.'"'.$check.
3992: ' value="'.$item.'" />'.$title.'</label> ';
3993: }
3994: }
3995: $output .= '</span><br />'.&mt('Others').': '.
3996: '<input type="text" name="override_'.$type.'_others" '.
3997: 'value="'.$otheremails.'" />';
3998: my %locchecked;
3999: foreach my $loc ('s','b') {
4000: if ($includeloc eq $loc) {
4001: $locchecked{$loc} = ' checked="checked"';
4002: last;
4003: }
4004: }
4005: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4006: '<input type="text" name="override_'.$type.'_bcc" '.
4007: 'value="'.$bccemails.'" /></fieldset>'.
4008: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4009: &mt('Text automatically added to e-mail:').' '.
4010: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4011: '<span class="LC_nobreak">'.&mt('Location:').' '.
4012: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4013: (' 'x2).
4014: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4015: '</span></fieldset>'.
4016: '</td></tr>'."\n";
4017: return $output;
4018: }
4019:
4020: sub contacts_javascript {
4021: return <<"ENDSCRIPT";
4022:
4023: <script type="text/javascript">
4024: // <![CDATA[
4025:
4026: function screenshotSize(field) {
4027: if (document.getElementById('help_screenshotsize')) {
4028: if (field.value == 'no') {
4029: document.getElementById('help_screenshotsize').style.display="none";
4030: } else {
4031: document.getElementById('help_screenshotsize').style.display="";
4032: }
4033: }
4034: return;
4035: }
4036:
4037: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4038: if (form.elements[checkbox].length != undefined) {
4039: var count = 0;
4040: if (docount) {
4041: for (var i=0; i<form.elements[checkbox].length; i++) {
4042: if (form.elements[checkbox][i].checked) {
4043: count ++;
4044: }
4045: }
4046: }
4047: for (var i=0; i<form.elements[checkbox].length; i++) {
4048: var type = form.elements[checkbox][i].value;
4049: if (document.getElementById(prefix+type)) {
4050: if (form.elements[checkbox][i].checked) {
4051: document.getElementById(prefix+type).style.display = 'table-row';
4052: if (count % 2 == 1) {
4053: document.getElementById(prefix+type).className = target+' LC_odd_row';
4054: } else {
4055: document.getElementById(prefix+type).className = target;
4056: }
4057: count ++;
4058: } else {
4059: document.getElementById(prefix+type).style.display = 'none';
4060: }
4061: }
4062: }
4063: }
4064: return;
4065: }
4066:
4067: // ]]>
4068: </script>
4069:
4070: ENDSCRIPT
4071: }
4072:
4073: sub print_helpsettings {
4074: my ($position,$dom,$settings,$rowtotal) = @_;
4075: my $confname = $dom.'-domainconfig';
4076: my $formname = 'display';
4077: my ($datatable,$itemcount);
4078: if ($position eq 'top') {
4079: $itemcount = 1;
4080: my (%choices,%defaultchecked,@toggles);
4081: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4082: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4083: &mt('LON-CAPA bug tracker'),600,500));
4084: %defaultchecked = ('submitbugs' => 'on');
4085: @toggles = ('submitbugs');
4086: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4087: \%choices,$itemcount);
4088: $$rowtotal ++;
4089: } else {
4090: my $css_class;
4091: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
4092: my (%customroles,%ordered,%current);
4093: if (ref($settings) eq 'HASH') {
4094: if (ref($settings->{'adhoc'}) eq 'HASH') {
4095: %current = %{$settings->{'adhoc'}};
4096: }
4097: }
4098: my $count = 0;
4099: foreach my $key (sort(keys(%existing))) {
4100: if ($key=~/^rolesdef\_(\w+)$/) {
4101: my $rolename = $1;
4102: my (%privs,$order);
4103: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4104: $customroles{$rolename} = \%privs;
4105: if (ref($current{$rolename}) eq 'HASH') {
4106: $order = $current{$rolename}{'order'};
4107: }
4108: if ($order eq '') {
4109: $order = $count;
4110: }
4111: $ordered{$order} = $rolename;
4112: $count++;
4113: }
4114: }
4115: my $maxnum = scalar(keys(%ordered));
4116: my @roles_by_num = ();
4117: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4118: push(@roles_by_num,$item);
4119: }
4120: my $context = 'domprefs';
4121: my $crstype = 'Course';
4122: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4123: my @accesstypes = ('all','dh','da','none');
4124: my ($numstatustypes,@jsarray);
4125: if (ref($types) eq 'ARRAY') {
4126: if (@{$types} > 0) {
4127: $numstatustypes = scalar(@{$types});
4128: push(@accesstypes,'status');
4129: @jsarray = ('bystatus');
4130: }
4131: }
4132: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
4133: if (keys(%domhelpdesk)) {
4134: push(@accesstypes,('inc','exc'));
4135: push(@jsarray,('notinc','notexc'));
4136: }
4137: my $hiddenstr = join("','",@jsarray);
4138: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
4139: my $context = 'domprefs';
4140: my $crstype = 'Course';
4141: my $prefix = 'helproles_';
4142: my $add_class = 'LC_hidden';
4143: foreach my $num (@roles_by_num) {
4144: my $role = $ordered{$num};
4145: my ($desc,$access,@statuses);
4146: if (ref($current{$role}) eq 'HASH') {
4147: $desc = $current{$role}{'desc'};
4148: $access = $current{$role}{'access'};
4149: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4150: @statuses = @{$current{$role}{'insttypes'}};
4151: }
4152: }
4153: if ($desc eq '') {
4154: $desc = $role;
4155: }
4156: my $identifier = 'custhelp'.$num;
4157: my %full=();
4158: my %levels= (
4159: course => {},
4160: domain => {},
4161: system => {},
4162: );
4163: my %levelscurrent=(
4164: course => {},
4165: domain => {},
4166: system => {},
4167: );
4168: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4169: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4170: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4171: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4172: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4173: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4174: for (my $k=0; $k<=$maxnum; $k++) {
4175: my $vpos = $k+1;
4176: my $selstr;
4177: if ($k == $num) {
4178: $selstr = ' selected="selected" ';
4179: }
4180: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4181: }
4182: $datatable .= '</select>'.(' 'x2).
4183: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4184: '</td>'.
4185: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4186: &mt('Name shown to users:').
4187: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4188: '</fieldset>'.
4189: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4190: $othertitle,$usertypes,$types,\%domhelpdesk).
4191: '<fieldset>'.
4192: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
4193: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4194: \%levelscurrent,$identifier,
4195: 'LC_hidden',$prefix.$num.'_privs').
4196: '</fieldset></td>';
4197: $itemcount ++;
4198: }
4199: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4200: my $newcust = 'custhelp'.$count;
4201: my (%privs,%levelscurrent);
4202: my %full=();
4203: my %levels= (
4204: course => {},
4205: domain => {},
4206: system => {},
4207: );
4208: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4209: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4210: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4211: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4212: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4213: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4214: for (my $k=0; $k<$maxnum+1; $k++) {
4215: my $vpos = $k+1;
4216: my $selstr;
4217: if ($k == $maxnum) {
4218: $selstr = ' selected="selected" ';
4219: }
4220: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4221: }
4222: $datatable .= '</select> '."\n".
4223: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4224: '</label></span></td>'.
4225: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4226: '<span class="LC_nobreak">'.
4227: &mt('Internal name:').
4228: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4229: '</span>'.(' 'x4).
4230: '<span class="LC_nobreak">'.
4231: &mt('Name shown to users:').
4232: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4233: '</span></fieldset>'.
4234: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4235: $usertypes,$types,\%domhelpdesk).
4236: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
4237: &Apache::lonuserutils::custom_role_header($context,$crstype,
4238: \@templateroles,$newcust).
4239: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4240: \%levelscurrent,$newcust).
4241: '</fieldset>'.
4242: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4243: '</td></tr>';
4244: $count ++;
4245: $$rowtotal += $count;
4246: }
4247: return $datatable;
4248: }
4249:
4250: sub adhocbutton {
4251: my ($prefix,$num,$field,$visibility) = @_;
4252: my %lt = &Apache::lonlocal::texthash(
4253: show => 'Show details',
4254: hide => 'Hide details',
4255: );
4256: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4257: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4258: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4259: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4260: }
4261:
4262: sub helpsettings_javascript {
4263: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4264: return unless(ref($roles_by_num) eq 'ARRAY');
4265: my %html_js_lt = &Apache::lonlocal::texthash(
4266: show => 'Show details',
4267: hide => 'Hide details',
4268: );
4269: &html_escape(\%html_js_lt);
4270: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4271: return <<"ENDSCRIPT";
4272: <script type="text/javascript">
4273: // <![CDATA[
4274:
4275: function reorderHelpRoles(form,item) {
4276: var changedVal;
4277: $jstext
4278: var newpos = 'helproles_${total}_pos';
4279: var maxh = 1 + $total;
4280: var current = new Array();
4281: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4282: if (item == newpos) {
4283: changedVal = newitemVal;
4284: } else {
4285: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4286: current[newitemVal] = newpos;
4287: }
4288: for (var i=0; i<helproles.length; i++) {
4289: var elementName = 'helproles_'+helproles[i]+'_pos';
4290: if (elementName != item) {
4291: if (form.elements[elementName]) {
4292: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4293: current[currVal] = elementName;
4294: }
4295: }
4296: }
4297: var oldVal;
4298: for (var j=0; j<maxh; j++) {
4299: if (current[j] == undefined) {
4300: oldVal = j;
4301: }
4302: }
4303: if (oldVal < changedVal) {
4304: for (var k=oldVal+1; k<=changedVal ; k++) {
4305: var elementName = current[k];
4306: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4307: }
4308: } else {
4309: for (var k=changedVal; k<oldVal; k++) {
4310: var elementName = current[k];
4311: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4312: }
4313: }
4314: return;
4315: }
4316:
4317: function helpdeskAccess(num) {
4318: var curraccess = null;
4319: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4320: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4321: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4322: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4323: }
4324: }
4325: }
4326: var shown = Array();
4327: var hidden = Array();
4328: if (curraccess == 'none') {
4329: hidden = Array('$hiddenstr');
4330: } else {
4331: if (curraccess == 'status') {
4332: shown = Array('bystatus');
4333: hidden = Array('notinc','notexc');
4334: } else {
4335: if (curraccess == 'exc') {
4336: shown = Array('notexc');
4337: hidden = Array('notinc','bystatus');
4338: }
4339: if (curraccess == 'inc') {
4340: shown = Array('notinc');
4341: hidden = Array('notexc','bystatus');
4342: }
4343: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
4344: hidden = Array('notinc','notexc','bystatus');
4345: }
4346: }
4347: }
4348: if (hidden.length > 0) {
4349: for (var i=0; i<hidden.length; i++) {
4350: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4351: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4352: }
4353: }
4354: }
4355: if (shown.length > 0) {
4356: for (var i=0; i<shown.length; i++) {
4357: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4358: if (shown[i] == 'privs') {
4359: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4360: } else {
4361: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4362: }
4363: }
4364: }
4365: }
4366: return;
4367: }
4368:
4369: function toggleHelpdeskItem(num,field) {
4370: if (document.getElementById('helproles_'+num+'_'+field)) {
4371: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4372: document.getElementById('helproles_'+num+'_'+field).className =
4373: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4374: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4375: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4376: }
4377: } else {
4378: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4379: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4380: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4381: }
4382: }
4383: }
4384: return;
4385: }
4386:
4387: // ]]>
4388: </script>
4389:
4390: ENDSCRIPT
4391: }
4392:
4393: sub helpdeskroles_access {
4394: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4395: $usertypes,$types,$domhelpdesk) = @_;
4396: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4397: my %lt = &Apache::lonlocal::texthash(
4398: 'rou' => 'Role usage',
4399: 'whi' => 'Which helpdesk personnel may use this role?',
4400: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4401: 'dh' => 'All with domain helpdesk role',
4402: 'da' => 'All with domain helpdesk assistant role',
4403: 'none' => 'None',
4404: 'status' => 'Determined based on institutional status',
4405: 'inc' => 'Include all, but exclude specific personnel',
4406: 'exc' => 'Exclude all, but include specific personnel',
4407: );
4408: my %usecheck = (
4409: all => ' checked="checked"',
4410: );
4411: my %displaydiv = (
4412: status => 'none',
4413: inc => 'none',
4414: exc => 'none',
4415: priv => 'block',
4416: );
4417: my $output;
4418: if (ref($current) eq 'HASH') {
4419: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4420: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4421: $usecheck{$current->{access}} = $usecheck{'all'};
4422: delete($usecheck{'all'});
4423: if ($current->{access} =~ /^(status|inc|exc)$/) {
4424: my $access = $1;
4425: $displaydiv{$access} = 'inline';
4426: } elsif ($current->{access} eq 'none') {
4427: $displaydiv{'priv'} = 'none';
4428: }
4429: }
4430: }
4431: }
4432: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4433: '<p>'.$lt{'whi'}.'</p>';
4434: foreach my $access (@{$accesstypes}) {
4435: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4436: ' onclick="helpdeskAccess('."'$num'".');" />'.
4437: $lt{$access}.'</label>';
4438: if ($access eq 'status') {
4439: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4440: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4441: $othertitle,$usertypes,$types).
4442: '</div>';
4443: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4444: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4445: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4446: '</div>';
4447: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4448: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4449: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4450: '</div>';
4451: }
4452: $output .= '</p>';
4453: }
4454: $output .= '</fieldset>';
4455: return $output;
4456: }
4457:
4458: sub radiobutton_prefs {
4459: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
4460: $additional,$align,$firstval) = @_;
4461: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4462: (ref($choices) eq 'HASH'));
4463:
4464: my (%checkedon,%checkedoff,$datatable,$css_class);
4465:
4466: foreach my $item (@{$toggles}) {
4467: if ($defaultchecked->{$item} eq 'on') {
4468: $checkedon{$item} = ' checked="checked" ';
4469: $checkedoff{$item} = ' ';
4470: } elsif ($defaultchecked->{$item} eq 'off') {
4471: $checkedoff{$item} = ' checked="checked" ';
4472: $checkedon{$item} = ' ';
4473: }
4474: }
4475: if (ref($settings) eq 'HASH') {
4476: foreach my $item (@{$toggles}) {
4477: if ($settings->{$item} eq '1') {
4478: $checkedon{$item} = ' checked="checked" ';
4479: $checkedoff{$item} = ' ';
4480: } elsif ($settings->{$item} eq '0') {
4481: $checkedoff{$item} = ' checked="checked" ';
4482: $checkedon{$item} = ' ';
4483: }
4484: }
4485: }
4486: if ($onclick) {
4487: $onclick = ' onclick="'.$onclick.'"';
4488: }
4489: foreach my $item (@{$toggles}) {
4490: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4491: $datatable .=
4492: '<tr'.$css_class.'><td valign="top">'.
4493: '<span class="LC_nobreak">'.$choices->{$item}.
4494: '</span></td>';
4495: if ($align eq 'left') {
4496: $datatable .= '<td class="LC_left_item">';
4497: } else {
4498: $datatable .= '<td class="LC_right_item">';
4499: }
4500: $datatable .= '<span class="LC_nobreak">';
4501: if ($firstval eq 'no') {
4502: $datatable .=
4503: '<label><input type="radio" name="'.
4504: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4505: '</label> <label><input type="radio" name="'.$item.'" '.
4506: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4507: } else {
4508: $datatable .=
4509: '<label><input type="radio" name="'.
4510: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
4511: '</label> <label><input type="radio" name="'.$item.'" '.
4512: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4513: }
4514: $datatable .= '</span>'.$additional.'</td></tr>';
4515: $itemcount ++;
4516: }
4517: return ($datatable,$itemcount);
4518: }
4519:
4520: sub print_coursedefaults {
4521: my ($position,$dom,$settings,$rowtotal) = @_;
4522: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
4523: my $itemcount = 1;
4524: my %choices = &Apache::lonlocal::texthash (
4525: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
4526: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4527: coursecredits => 'Credits can be specified for courses',
4528: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4529: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4530: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
4531: texengine => 'Default method to display mathematics',
4532: postsubmit => 'Disable submit button/keypress following student submission',
4533: canclone => "People who may clone a course (besides course's owner and coordinators)",
4534: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
4535: );
4536: my %staticdefaults = (
4537: anonsurvey_threshold => 10,
4538: uploadquota => 500,
4539: postsubmit => 60,
4540: mysqltables => 172800,
4541: );
4542: if ($position eq 'top') {
4543: %defaultchecked = (
4544: 'uselcmath' => 'on',
4545: 'usejsme' => 'on',
4546: 'inline_chem' => 'on',
4547: 'canclone' => 'none',
4548: );
4549: @toggles = ('uselcmath','usejsme','inline_chem');
4550: my $deftex = $Apache::lonnet::deftex;
4551: if (ref($settings) eq 'HASH') {
4552: if ($settings->{'texengine'}) {
4553: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4554: $deftex = $settings->{'texengine'};
4555: }
4556: }
4557: }
4558: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4559: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4560: '<span class="LC_nobreak">'.$choices{'texengine'}.
4561: '</span></td><td class="LC_right_item">'.
4562: '<select name="texengine">'."\n";
4563: my %texoptions = (
4564: MathJax => 'MathJax',
4565: mimetex => &mt('Convert to Images'),
4566: tth => &mt('TeX to HTML'),
4567: );
4568: foreach my $renderer ('MathJax','mimetex','tth') {
4569: my $selected = '';
4570: if ($renderer eq $deftex) {
4571: $selected = ' selected="selected"';
4572: }
4573: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4574: }
4575: $mathdisp .= '</select></td></tr>'."\n";
4576: $itemcount ++;
4577: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4578: \%choices,$itemcount);
4579: $datatable = $mathdisp.$datatable;
4580: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4581: $datatable .=
4582: '<tr'.$css_class.'><td valign="top">'.
4583: '<span class="LC_nobreak">'.$choices{'canclone'}.
4584: '</span></td><td class="LC_left_item">';
4585: my $currcanclone = 'none';
4586: my $onclick;
4587: my @cloneoptions = ('none','domain');
4588: my %clonetitles = &Apache::lonlocal::texthash (
4589: none => 'No additional course requesters',
4590: domain => "Any course requester in course's domain",
4591: instcode => 'Course requests for official courses ...',
4592: );
4593: my (%codedefaults,@code_order,@posscodes);
4594: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4595: \@code_order) eq 'ok') {
4596: if (@code_order > 0) {
4597: push(@cloneoptions,'instcode');
4598: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4599: }
4600: }
4601: if (ref($settings) eq 'HASH') {
4602: if ($settings->{'canclone'}) {
4603: if (ref($settings->{'canclone'}) eq 'HASH') {
4604: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4605: if (@code_order > 0) {
4606: $currcanclone = 'instcode';
4607: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4608: }
4609: }
4610: } elsif ($settings->{'canclone'} eq 'domain') {
4611: $currcanclone = $settings->{'canclone'};
4612: }
4613: }
4614: }
4615: foreach my $option (@cloneoptions) {
4616: my ($checked,$additional);
4617: if ($currcanclone eq $option) {
4618: $checked = ' checked="checked"';
4619: }
4620: if ($option eq 'instcode') {
4621: if (@code_order) {
4622: my $show = 'none';
4623: if ($checked) {
4624: $show = 'block';
4625: }
4626: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4627: &mt('Institutional codes for new and cloned course have identical:').
4628: '<br />';
4629: foreach my $item (@code_order) {
4630: my $codechk;
4631: if ($checked) {
4632: if (grep(/^\Q$item\E$/,@posscodes)) {
4633: $codechk = ' checked="checked"';
4634: }
4635: }
4636: $additional .= '<label>'.
4637: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4638: $item.'</label>';
4639: }
4640: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4641: }
4642: }
4643: $datatable .=
4644: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4645: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4646: '</label> '.$additional.'</span><br />';
4647: }
4648: $datatable .= '</td>'.
4649: '</tr>';
4650: $itemcount ++;
4651: } else {
4652: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4653: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
4654: my $currusecredits = 0;
4655: my $postsubmitclient = 1;
4656: my @types = ('official','unofficial','community','textbook');
4657: if (ref($settings) eq 'HASH') {
4658: $currdefresponder = $settings->{'anonsurvey_threshold'};
4659: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4660: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4661: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4662: }
4663: }
4664: if (ref($settings->{'coursecredits'}) eq 'HASH') {
4665: foreach my $type (@types) {
4666: next if ($type eq 'community');
4667: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4668: if ($defcredits{$type} ne '') {
4669: $currusecredits = 1;
4670: }
4671: }
4672: }
4673: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4674: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4675: $postsubmitclient = 0;
4676: foreach my $type (@types) {
4677: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4678: }
4679: } else {
4680: foreach my $type (@types) {
4681: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4682: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4683: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4684: } else {
4685: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4686: }
4687: } else {
4688: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4689: }
4690: }
4691: }
4692: } else {
4693: foreach my $type (@types) {
4694: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4695: }
4696: }
4697: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4698: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4699: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4700: }
4701: } else {
4702: foreach my $type (@types) {
4703: $currmysql{$type} = $staticdefaults{'mysqltables'};
4704: }
4705: }
4706: } else {
4707: foreach my $type (@types) {
4708: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4709: }
4710: }
4711: if (!$currdefresponder) {
4712: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
4713: } elsif ($currdefresponder < 1) {
4714: $currdefresponder = 1;
4715: }
4716: foreach my $type (@types) {
4717: if ($curruploadquota{$type} eq '') {
4718: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4719: }
4720: }
4721: $datatable .=
4722: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4723: $choices{'anonsurvey_threshold'}.
4724: '</span></td>'.
4725: '<td class="LC_right_item"><span class="LC_nobreak">'.
4726: '<input type="text" name="anonsurvey_threshold"'.
4727: ' value="'.$currdefresponder.'" size="5" /></span>'.
4728: '</td></tr>'."\n";
4729: $itemcount ++;
4730: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4731: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4732: $choices{'uploadquota'}.
4733: '</span></td>'.
4734: '<td align="right" class="LC_right_item">'.
4735: '<table><tr>';
4736: foreach my $type (@types) {
4737: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4738: '<input type="text" name="uploadquota_'.$type.'"'.
4739: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4740: }
4741: $datatable .= '</tr></table></td></tr>'."\n";
4742: $itemcount ++;
4743: my $onclick = "toggleDisplay(this.form,'credits');";
4744: my $display = 'none';
4745: if ($currusecredits) {
4746: $display = 'block';
4747: }
4748: my $additional = '<div id="credits" style="display: '.$display.'">'.
4749: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4750: foreach my $type (@types) {
4751: next if ($type eq 'community');
4752: $additional .= '<td align="center">'.&mt($type).'<br />'.
4753: '<input type="text" name="'.$type.'_credits"'.
4754: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4755: }
4756: $additional .= '</tr></table></div>'."\n";
4757: %defaultchecked = ('coursecredits' => 'off');
4758: @toggles = ('coursecredits');
4759: my $current = {
4760: 'coursecredits' => $currusecredits,
4761: };
4762: (my $table,$itemcount) =
4763: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4764: \%choices,$itemcount,$onclick,$additional,'left');
4765: $datatable .= $table;
4766: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4767: my $display = 'none';
4768: if ($postsubmitclient) {
4769: $display = 'block';
4770: }
4771: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
4772: &mt('Number of seconds submit is disabled').'<br />'.
4773: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4774: '<table><tr>';
4775: foreach my $type (@types) {
4776: $additional .= '<td align="center">'.&mt($type).'<br />'.
4777: '<input type="text" name="'.$type.'_timeout" value="'.
4778: $deftimeout{$type}.'" size="5" /></td>';
4779: }
4780: $additional .= '</tr></table></div>'."\n";
4781: %defaultchecked = ('postsubmit' => 'on');
4782: @toggles = ('postsubmit');
4783: $current = {
4784: 'postsubmit' => $postsubmitclient,
4785: };
4786: ($table,$itemcount) =
4787: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4788: \%choices,$itemcount,$onclick,$additional,'left');
4789: $datatable .= $table;
4790: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4791: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4792: $choices{'mysqltables'}.
4793: '</span></td>'.
4794: '<td align="right" class="LC_right_item">'.
4795: '<table><tr>';
4796: foreach my $type (@types) {
4797: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4798: '<input type="text" name="mysqltables_'.$type.'"'.
4799: ' value="'.$currmysql{$type}.'" size="8" /></td>';
4800: }
4801: $datatable .= '</tr></table></td></tr>'."\n";
4802: $itemcount ++;
4803:
4804: }
4805: $$rowtotal += $itemcount;
4806: return $datatable;
4807: }
4808:
4809: sub print_selfenrollment {
4810: my ($position,$dom,$settings,$rowtotal) = @_;
4811: my ($css_class,$datatable);
4812: my $itemcount = 1;
4813: my @types = ('official','unofficial','community','textbook');
4814: if (($position eq 'top') || ($position eq 'middle')) {
4815: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4816: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4817: my @rows;
4818: my $key;
4819: if ($position eq 'top') {
4820: $key = 'admin';
4821: if (ref($rowsref) eq 'ARRAY') {
4822: @rows = @{$rowsref};
4823: }
4824: } elsif ($position eq 'middle') {
4825: $key = 'default';
4826: @rows = ('types','registered','approval','limit');
4827: }
4828: foreach my $row (@rows) {
4829: if (defined($titlesref->{$row})) {
4830: $itemcount ++;
4831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4832: $datatable .= '<tr'.$css_class.'>'.
4833: '<td>'.$titlesref->{$row}.'</td>'.
4834: '<td class="LC_left_item">'.
4835: '<table><tr>';
4836: my (%current,%currentcap);
4837: if (ref($settings) eq 'HASH') {
4838: if (ref($settings->{$key}) eq 'HASH') {
4839: foreach my $type (@types) {
4840: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4841: $current{$type} = $settings->{$key}->{$type}->{$row};
4842: }
4843: if (($row eq 'limit') && ($key eq 'default')) {
4844: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4845: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4846: }
4847: }
4848: }
4849: }
4850: }
4851: my %roles = (
4852: '0' => &Apache::lonnet::plaintext('dc'),
4853: );
4854:
4855: foreach my $type (@types) {
4856: unless (($row eq 'registered') && ($key eq 'default')) {
4857: $datatable .= '<th>'.&mt($type).'</th>';
4858: }
4859: }
4860: unless (($row eq 'registered') && ($key eq 'default')) {
4861: $datatable .= '</tr><tr>';
4862: }
4863: foreach my $type (@types) {
4864: if ($type eq 'community') {
4865: $roles{'1'} = &mt('Community personnel');
4866: } else {
4867: $roles{'1'} = &mt('Course personnel');
4868: }
4869: $datatable .= '<td style="vertical-align: top">';
4870: if ($position eq 'top') {
4871: my %checked;
4872: if ($current{$type} eq '0') {
4873: $checked{'0'} = ' checked="checked"';
4874: } else {
4875: $checked{'1'} = ' checked="checked"';
4876: }
4877: foreach my $role ('1','0') {
4878: $datatable .= '<span class="LC_nobreak"><label>'.
4879: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4880: 'value="'.$role.'"'.$checked{$role}.' />'.
4881: $roles{$role}.'</label></span> ';
4882: }
4883: } else {
4884: if ($row eq 'types') {
4885: my %checked;
4886: if ($current{$type} =~ /^(all|dom)$/) {
4887: $checked{$1} = ' checked="checked"';
4888: } else {
4889: $checked{''} = ' checked="checked"';
4890: }
4891: foreach my $val ('','dom','all') {
4892: $datatable .= '<span class="LC_nobreak"><label>'.
4893: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4894: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4895: }
4896: } elsif ($row eq 'registered') {
4897: my %checked;
4898: if ($current{$type} eq '1') {
4899: $checked{'1'} = ' checked="checked"';
4900: } else {
4901: $checked{'0'} = ' checked="checked"';
4902: }
4903: foreach my $val ('0','1') {
4904: $datatable .= '<span class="LC_nobreak"><label>'.
4905: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4906: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4907: }
4908: } elsif ($row eq 'approval') {
4909: my %checked;
4910: if ($current{$type} =~ /^([12])$/) {
4911: $checked{$1} = ' checked="checked"';
4912: } else {
4913: $checked{'0'} = ' checked="checked"';
4914: }
4915: for my $val (0..2) {
4916: $datatable .= '<span class="LC_nobreak"><label>'.
4917: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4918: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4919: }
4920: } elsif ($row eq 'limit') {
4921: my %checked;
4922: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4923: $checked{$1} = ' checked="checked"';
4924: } else {
4925: $checked{'none'} = ' checked="checked"';
4926: }
4927: my $cap;
4928: if ($currentcap{$type} =~ /^\d+$/) {
4929: $cap = $currentcap{$type};
4930: }
4931: foreach my $val ('none','allstudents','selfenrolled') {
4932: $datatable .= '<span class="LC_nobreak"><label>'.
4933: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4934: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4935: }
4936: $datatable .= '<br />'.
4937: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4938: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4939: '</span>';
4940: }
4941: }
4942: $datatable .= '</td>';
4943: }
4944: $datatable .= '</tr>';
4945: }
4946: $datatable .= '</table></td></tr>';
4947: }
4948: } elsif ($position eq 'bottom') {
4949: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4950: }
4951: $$rowtotal += $itemcount;
4952: return $datatable;
4953: }
4954:
4955: sub print_validation_rows {
4956: my ($caller,$dom,$settings,$rowtotal) = @_;
4957: my ($itemsref,$namesref,$fieldsref);
4958: if ($caller eq 'selfenroll') {
4959: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4960: } elsif ($caller eq 'requestcourses') {
4961: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4962: }
4963: my %currvalidation;
4964: if (ref($settings) eq 'HASH') {
4965: if (ref($settings->{'validation'}) eq 'HASH') {
4966: %currvalidation = %{$settings->{'validation'}};
4967: }
4968: }
4969: my $datatable;
4970: my $itemcount = 0;
4971: foreach my $item (@{$itemsref}) {
4972: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4973: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4974: $namesref->{$item}.
4975: '</span></td>'.
4976: '<td class="LC_left_item">';
4977: if (($item eq 'url') || ($item eq 'button')) {
4978: $datatable .= '<span class="LC_nobreak">'.
4979: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4980: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4981: } elsif ($item eq 'fields') {
4982: my @currfields;
4983: if (ref($currvalidation{$item}) eq 'ARRAY') {
4984: @currfields = @{$currvalidation{$item}};
4985: }
4986: foreach my $field (@{$fieldsref}) {
4987: my $check = '';
4988: if (grep(/^\Q$field\E$/,@currfields)) {
4989: $check = ' checked="checked"';
4990: }
4991: $datatable .= '<span class="LC_nobreak"><label>'.
4992: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4993: ' value="'.$field.'"'.$check.' />'.$field.
4994: '</label></span> ';
4995: }
4996: } elsif ($item eq 'markup') {
4997: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
4998: $currvalidation{$item}.
4999: '</textarea>';
5000: }
5001: $datatable .= '</td></tr>'."\n";
5002: if (ref($rowtotal)) {
5003: $itemcount ++;
5004: }
5005: }
5006: if ($caller eq 'requestcourses') {
5007: my %currhash;
5008: if (ref($settings) eq 'HASH') {
5009: if (ref($settings->{'validation'}) eq 'HASH') {
5010: if ($settings->{'validation'}{'dc'} ne '') {
5011: $currhash{$settings->{'validation'}{'dc'}} = 1;
5012: }
5013: }
5014: }
5015: my $numinrow = 2;
5016: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5017: 'validationdc',%currhash);
5018: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5019: $datatable .= '<tr'.$css_class.'><td>';
5020: if ($numdc > 1) {
5021: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
5022: } else {
5023: $datatable .= &mt('Course creation processed as: ');
5024: }
5025: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
5026: $itemcount ++;
5027: }
5028: if (ref($rowtotal)) {
5029: $$rowtotal += $itemcount;
5030: }
5031: return $datatable;
5032: }
5033:
5034: sub print_passwords {
5035: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5036: my ($datatable,$css_class);
5037: my $itemcount = 0;
5038: my %titles = &Apache::lonlocal::texthash (
5039: captcha => '"Forgot Password" CAPTCHA validation',
5040: link => 'Reset link expiration (hours)',
5041: case => 'Case-sensitive usernames/e-mail',
5042: prelink => 'Information required (form 1)',
5043: postlink => 'Information required (form 2)',
5044: emailsrc => 'LON-CAPA e-mail address type(s)',
5045: customtext => 'Domain specific text (HTML)',
5046: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5047: intauth_check => 'Check bcrypt cost if authenticated',
5048: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5049: permanent => 'Permanent e-mail address',
5050: critical => 'Critical notification address',
5051: notify => 'Notification address',
5052: min => 'Minimum password length',
5053: max => 'Maximum password length',
5054: chars => 'Required characters',
5055: numsaved => 'Number of previous passwords to save and disallow reuse',
5056: );
5057: if ($position eq 'top') {
5058: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5059: my $shownlinklife = 2;
5060: my $prelink = 'both';
5061: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5062: if (ref($settings) eq 'HASH') {
5063: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5064: $shownlinklife = $settings->{resetlink};
5065: }
5066: if (ref($settings->{resetcase}) eq 'ARRAY') {
5067: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5068: }
5069: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5070: $prelink = $settings->{resetprelink};
5071: }
5072: if (ref($settings->{resetpostlink}) eq 'HASH') {
5073: %postlink = %{$settings->{resetpostlink}};
5074: }
5075: if (ref($settings->{resetemail}) eq 'ARRAY') {
5076: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5077: }
5078: if ($settings->{resetremove}) {
5079: $nostdtext = 1;
5080: }
5081: if ($settings->{resetcustom}) {
5082: $customurl = $settings->{resetcustom};
5083: }
5084: } else {
5085: if (ref($types) eq 'ARRAY') {
5086: foreach my $item (@{$types}) {
5087: $casesens{$item} = 1;
5088: $postlink{$item} = ['username','email'];
5089: }
5090: }
5091: $casesens{'default'} = 1;
5092: $postlink{'default'} = ['username','email'];
5093: $prelink = 'both';
5094: %emailsrc = (
5095: permanent => 1,
5096: critical => 1,
5097: notify => 1,
5098: );
5099: }
5100: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5101: $itemcount ++;
5102: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5103: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5104: '<td class="LC_left_item">'.
5105: '<input type="textbox" value="'.$shownlinklife.'" '.
5106: 'name="passwords_link" size="3" /></td></tr>';
5107: $itemcount ++;
5108: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5109: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5110: '<td class="LC_left_item">';
5111: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5112: foreach my $item (@{$types}) {
5113: my $checkedcase;
5114: if ($casesens{$item}) {
5115: $checkedcase = ' checked="checked"';
5116: }
5117: $datatable .= '<span class="LC_nobreak"><label>'.
5118: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5119: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
5120: '</span> ';
5121: }
5122: }
5123: my $checkedcase;
5124: if ($casesens{'default'}) {
5125: $checkedcase = ' checked="checked"';
5126: }
5127: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5128: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5129: $othertitle.'</label></span></td>';
5130: $itemcount ++;
5131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5132: my %checkedpre = (
5133: both => ' checked="checked"',
5134: either => '',
5135: );
5136: if ($prelink eq 'either') {
5137: $checkedpre{either} = ' checked="checked"';
5138: $checkedpre{both} = '';
5139: }
5140: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5141: '<td class="LC_left_item"><span class="LC_nobreak">'.
5142: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5143: &mt('Both username and e-mail address').'</label></span> '.
5144: '<span class="LC_nobreak"><label>'.
5145: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5146: &mt('Either username or e-mail address').'</label></span></td></tr>';
5147: $itemcount ++;
5148: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5149: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5150: '<td class="LC_left_item">';
5151: my %postlinked;
5152: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5153: foreach my $item (@{$types}) {
5154: undef(%postlinked);
5155: $datatable .= '<fieldset style="display: inline-block;">'.
5156: '<legend>'.$usertypes->{$item}.'</legend>';
5157: if (ref($postlink{$item}) eq 'ARRAY') {
5158: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5159: }
5160: foreach my $field ('email','username') {
5161: my $checked;
5162: if ($postlinked{$field}) {
5163: $checked = ' checked="checked"';
5164: }
5165: $datatable .= '<span class="LC_nobreak"><label>'.
5166: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5167: $field.'"'.$checked.' />'.$field.'</label>'.
5168: '<span> ';
5169: }
5170: $datatable .= '</fieldset>';
5171: }
5172: }
5173: if (ref($postlink{'default'}) eq 'ARRAY') {
5174: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5175: }
5176: $datatable .= '<fieldset style="display: inline-block;">'.
5177: '<legend>'.$othertitle.'</legend>';
5178: foreach my $field ('email','username') {
5179: my $checked;
5180: if ($postlinked{$field}) {
5181: $checked = ' checked="checked"';
5182: }
5183: $datatable .= '<span class="LC_nobreak"><label>'.
5184: '<input type="checkbox" name="passwords_postlink_default" value="'.
5185: $field.'"'.$checked.' />'.$field.'</label>'.
5186: '<span> ';
5187: }
5188: $datatable .= '</fieldset></td></tr>';
5189: $itemcount ++;
5190: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5191: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5192: '<td class="LC_left_item">';
5193: foreach my $type ('permanent','critical','notify') {
5194: my $checkedemail;
5195: if ($emailsrc{$type}) {
5196: $checkedemail = ' checked="checked"';
5197: }
5198: $datatable .= '<span class="LC_nobreak"><label>'.
5199: '<input type="checkbox" name="passwords_emailsrc" value="'.
5200: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5201: '<span> ';
5202: }
5203: $datatable .= '</td></tr>';
5204: $itemcount ++;
5205: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5206: my $switchserver = &check_switchserver($dom,$confname);
5207: my ($showstd,$noshowstd);
5208: if ($nostdtext) {
5209: $noshowstd = ' checked="checked"';
5210: } else {
5211: $showstd = ' checked="checked"';
5212: }
5213: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5214: '<td class="LC_left_item"><span class="LC_nobreak">'.
5215: &mt('Retain standard text:').
5216: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5217: &mt('Yes').'</label>'.' '.
5218: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5219: &mt('No').'</label></span><br />'.
5220: '<span class="LC_fontsize_small">'.
5221: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5222: &mt('Include custom text:');
5223: if ($customurl) {
5224: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
5225: undef,undef,undef,undef,'background-color:#ffffff');
5226: $datatable .= '<span class="LC_nobreak"> '.$link.
5227: '<label><input type="checkbox" name="passwords_custom_del"'.
5228: ' value="1" />'.&mt('Delete?').'</label></span>'.
5229: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5230: }
5231: if ($switchserver) {
5232: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5233: } else {
5234: $datatable .='<span class="LC_nobreak"> '.
5235: '<input type="file" name="passwords_customfile" /></span>';
5236: }
5237: $datatable .= '</td></tr>';
5238: } elsif ($position eq 'middle') {
5239: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5240: my @items = ('intauth_cost','intauth_check','intauth_switch');
5241: my %defaults;
5242: if (ref($domconf{'defaults'}) eq 'HASH') {
5243: %defaults = %{$domconf{'defaults'}};
5244: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5245: $defaults{'intauth_cost'} = 10;
5246: }
5247: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5248: $defaults{'intauth_check'} = 0;
5249: }
5250: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5251: $defaults{'intauth_switch'} = 0;
5252: }
5253: } else {
5254: %defaults = (
5255: 'intauth_cost' => 10,
5256: 'intauth_check' => 0,
5257: 'intauth_switch' => 0,
5258: );
5259: }
5260: foreach my $item (@items) {
5261: if ($itemcount%2) {
5262: $css_class = '';
5263: } else {
5264: $css_class = ' class="LC_odd_row" ';
5265: }
5266: $datatable .= '<tr'.$css_class.'>'.
5267: '<td><span class="LC_nobreak">'.$titles{$item}.
5268: '</span></td><td class="LC_left_item" colspan="3">';
5269: if ($item eq 'intauth_switch') {
5270: my @options = (0,1,2);
5271: my %optiondesc = &Apache::lonlocal::texthash (
5272: 0 => 'No',
5273: 1 => 'Yes',
5274: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5275: );
5276: $datatable .= '<table width="100%">';
5277: foreach my $option (@options) {
5278: my $checked = ' ';
5279: if ($defaults{$item} eq $option) {
5280: $checked = ' checked="checked"';
5281: }
5282: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5283: '<label><input type="radio" name="'.$item.
5284: '" value="'.$option.'"'.$checked.' />'.
5285: $optiondesc{$option}.'</label></span></td></tr>';
5286: }
5287: $datatable .= '</table>';
5288: } elsif ($item eq 'intauth_check') {
5289: my @options = (0,1,2);
5290: my %optiondesc = &Apache::lonlocal::texthash (
5291: 0 => 'No',
5292: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5293: 2 => 'Yes, disallow login if stored cost is less than domain default',
5294: );
5295: $datatable .= '<table width="100%">';
5296: foreach my $option (@options) {
5297: my $checked = ' ';
5298: my $onclick;
5299: if ($defaults{$item} eq $option) {
5300: $checked = ' checked="checked"';
5301: }
5302: if ($option == 2) {
5303: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5304: }
5305: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5306: '<label><input type="radio" name="'.$item.
5307: '" value="'.$option.'"'.$checked.$onclick.' />'.
5308: $optiondesc{$option}.'</label></span></td></tr>';
5309: }
5310: $datatable .= '</table>';
5311: } else {
5312: $datatable .= '<input type="text" name="'.$item.'" value="'.
5313: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5314: }
5315: $datatable .= '</td></tr>';
5316: $itemcount ++;
5317: }
5318: } elsif ($position eq 'lower') {
5319: my ($min,$max,%chars,$numsaved);
5320: $min = $Apache::lonnet::passwdmin;
5321: if (ref($settings) eq 'HASH') {
5322: if ($settings->{min}) {
5323: $min = $settings->{min};
5324: }
5325: if ($settings->{max}) {
5326: $max = $settings->{max};
5327: }
5328: if (ref($settings->{chars}) eq 'ARRAY') {
5329: map { $chars{$_} = 1; } (@{$settings->{chars}});
5330: }
5331: if ($settings->{numsaved}) {
5332: $numsaved = $settings->{numsaved};
5333: }
5334: }
5335: my %rulenames = &Apache::lonlocal::texthash(
5336: uc => 'At least one upper case letter',
5337: lc => 'At least one lower case letter',
5338: num => 'At least one number',
5339: spec => 'At least one non-alphanumeric',
5340: );
5341: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5342: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5343: '<td class="LC_left_item"><span class="LC_nobreak">'.
5344: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5345: 'onblur="javascript:warnIntPass(this);" />'.
5346: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
5347: '</span></td></tr>';
5348: $itemcount ++;
5349: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5350: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5351: '<td class="LC_left_item"><span class="LC_nobreak">'.
5352: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5353: 'onblur="javascript:warnIntPass(this);" />'.
5354: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5355: '</span></td></tr>';
5356: $itemcount ++;
5357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5358: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5359: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5360: '</span></td>';
5361: my $numinrow = 2;
5362: my @possrules = ('uc','lc','num','spec');
5363: $datatable .= '<td class="LC_left_item"><table>';
5364: for (my $i=0; $i<@possrules; $i++) {
5365: my ($rem,$checked);
5366: if ($chars{$possrules[$i]}) {
5367: $checked = ' checked="checked"';
5368: }
5369: $rem = $i%($numinrow);
5370: if ($rem == 0) {
5371: if ($i > 0) {
5372: $datatable .= '</tr>';
5373: }
5374: $datatable .= '<tr>';
5375: }
5376: $datatable .= '<td><span class="LC_nobreak"><label>'.
5377: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5378: $rulenames{$possrules[$i]}.'</label></span></td>';
5379: }
5380: my $rem = @possrules%($numinrow);
5381: my $colsleft = $numinrow - $rem;
5382: if ($colsleft > 1 ) {
5383: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5384: ' </td>';
5385: } elsif ($colsleft == 1) {
5386: $datatable .= '<td class="LC_left_item"> </td>';
5387: }
5388: $datatable .='</table></td></tr>';
5389: $itemcount ++;
5390: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5391: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5392: '<td class="LC_left_item"><span class="LC_nobreak">'.
5393: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
5394: 'onblur="javascript:warnIntPass(this);" />'.
5395: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5396: '</span></td></tr>';
5397: } else {
5398: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5399: my %ownerchg = (
5400: by => {},
5401: for => {},
5402: );
5403: my %ownertitles = &Apache::lonlocal::texthash (
5404: by => 'Course owner status(es) allowed',
5405: for => 'Student status(es) allowed',
5406: );
5407: if (ref($settings) eq 'HASH') {
5408: if (ref($settings->{crsownerchg}) eq 'HASH') {
5409: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5410: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5411: }
5412: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5413: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5414: }
5415: }
5416: }
5417: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5418: $datatable .= '<tr '.$css_class.'>'.
5419: '<td>'.
5420: &mt('Requirements').'<ul>'.
5421: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5422: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5423: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5424: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5425: '</ul>'.
5426: '</td>'.
5427: '<td class="LC_left_item">';
5428: foreach my $item ('by','for') {
5429: $datatable .= '<fieldset style="display: inline-block;">'.
5430: '<legend>'.$ownertitles{$item}.'</legend>';
5431: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5432: foreach my $type (@{$types}) {
5433: my $checked;
5434: if ($ownerchg{$item}{$type}) {
5435: $checked = ' checked="checked"';
5436: }
5437: $datatable .= '<span class="LC_nobreak"><label>'.
5438: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5439: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
5440: '</span> ';
5441: }
5442: }
5443: my $checked;
5444: if ($ownerchg{$item}{'default'}) {
5445: $checked = ' checked="checked"';
5446: }
5447: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5448: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5449: $othertitle.'</label></span></fieldset>';
5450: }
5451: $datatable .= '</td></tr>';
5452: }
5453: return $datatable;
5454: }
5455:
5456: sub print_wafproxy {
5457: my ($position,$dom,$settings,$rowtotal) = @_;
5458: my $css_class;
5459: my $itemcount = 0;
5460: my $datatable;
5461: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5462: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
5463: my %lt = &wafproxy_titles();
5464: foreach my $server (sort(keys(%servers))) {
5465: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
5466: next if ($serverhome eq '');
5467: my $serverdom;
5468: if ($serverhome ne $server) {
5469: $serverdom = &Apache::lonnet::host_domain($serverhome);
5470: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
5471: $othercontrol{$server} = $serverdom;
5472: }
5473: } else {
5474: $serverdom = &Apache::lonnet::host_domain($server);
5475: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
5476: if ($serverdom ne $dom) {
5477: $othercontrol{$server} = $serverdom;
5478: } else {
5479: $setdom = 1;
5480: if (ref($settings) eq 'HASH') {
5481: if (ref($settings->{'alias'}) eq 'HASH') {
5482: $aliases{$dom} = $settings->{'alias'};
5483: if ($aliases{$dom} ne '') {
5484: $showdom = 1;
5485: }
5486: }
5487: if (ref($settings->{'saml'}) eq 'HASH') {
5488: $saml{$dom} = $settings->{'saml'};
5489: }
5490: }
5491: }
5492: }
5493: }
5494: if ($setdom) {
5495: %{$values{$dom}} = ();
5496: if (ref($settings) eq 'HASH') {
5497: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5498: $values{$dom}{$item} = $settings->{$item};
5499: }
5500: }
5501: }
5502: if (keys(%othercontrol)) {
5503: %otherdoms = reverse(%othercontrol);
5504: foreach my $domain (keys(%otherdoms)) {
5505: %{$values{$domain}} = ();
5506: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
5507: if (ref($config{'wafproxy'}) eq 'HASH') {
5508: $aliases{$domain} = $config{'wafproxy'}{'alias'};
5509: if (exists($config{'wafproxy'}{'saml'})) {
5510: $saml{$domain} = $config{'wafproxy'}{'saml'};
5511: }
5512: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
5513: $values{$domain}{$item} = $config{'wafproxy'}{$item};
5514: }
5515: }
5516: }
5517: }
5518: if ($position eq 'top') {
5519: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5520: my %aliasinfo;
5521: foreach my $server (sort(keys(%servers))) {
5522: $itemcount ++;
5523: my $dom_in_effect;
5524: my $aliasrows = '<tr>'.
5525: '<td class="LC_left_item" style="vertical-align: baseline;">'.
5526: &mt('Hostname').': '.
5527: '<span class="LC_nobreak LC_cusr_emph">'.
5528: &Apache::lonnet::hostname($server).
5529: '</span></td><td> </td>';
5530: if ($othercontrol{$server}) {
5531: $dom_in_effect = $othercontrol{$server};
5532: my ($current,$forsaml);
5533: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
5534: $current = $aliases{$dom_in_effect}{$server};
5535: }
5536: if (ref($saml{$dom_in_effect}) eq 'HASH') {
5537: if ($saml{$dom_in_effect}{$server}) {
5538: $forsaml = 1;
5539: }
5540: }
5541: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5542: &mt('Alias').': ';
5543: if ($current) {
5544: $aliasrows .= $current;
5545: if ($forsaml) {
5546: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
5547: }
5548: } else {
5549: $aliasrows .= &mt('None');
5550: }
5551: $aliasrows .= ' <span class="LC_small">('.
5552: &mt('controlled by domain: [_1]',
5553: '<b>'.$dom_in_effect.'</b>').')</span></td>';
5554: } else {
5555: $dom_in_effect = $dom;
5556: my ($current,$samlon,$samloff);
5557: $samloff = ' checked="checked"';
5558: if (ref($aliases{$dom}) eq 'HASH') {
5559: if ($aliases{$dom}{$server}) {
5560: $current = $aliases{$dom}{$server};
5561: }
5562: }
5563: if (ref($saml{$dom}) eq 'HASH') {
5564: if ($saml{$dom}{$server}) {
5565: $samlon = $samloff;
5566: undef($samloff);
5567: }
5568: }
5569: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
5570: &mt('Alias').': '.
5571: '<input type="text" name="wafproxy_alias_'.$server.'" '.
5572: 'value="'.$current.'" size="30" />'.
5573: (' 'x2).'<span class="LC_nobreak">'.
5574: &mt('Alias used for SSO Auth').': <label>'.
5575: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
5576: &mt('No').'</label> <label>'.
5577: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
5578: &mt('Yes').'</label></span>'.
5579: '</td>';
5580: }
5581: $aliasrows .= '</tr>';
5582: $aliasinfo{$dom_in_effect} .= $aliasrows;
5583: }
5584: if ($aliasinfo{$dom}) {
5585: my ($onclick,$wafon,$wafoff,$showtable);
5586: $onclick = ' onclick="javascript:toggleWAF();"';
5587: $wafoff = ' checked="checked"';
5588: $showtable = ' style="display:none";';
5589: if ($showdom) {
5590: $wafon = $wafoff;
5591: $wafoff = '';
5592: $showtable = ' style="display:inline;"';
5593: }
5594: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5595: $datatable = '<tr'.$css_class.'>'.
5596: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
5597: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
5598: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
5599: &mt('Yes').'</label>'.(' 'x2).'<label>'.
5600: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
5601: &mt('No').'</label></span></td>'.
5602: '<td class="LC_left_item">'.
5603: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
5604: '</table></td></tr>';
5605: $itemcount++;
5606: }
5607: if (keys(%otherdoms)) {
5608: foreach my $key (sort(keys(%otherdoms))) {
5609: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5610: $datatable .= '<tr'.$css_class.'>'.
5611: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
5612: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
5613: '</table></td></tr>';
5614: $itemcount++;
5615: }
5616: }
5617: } else {
5618: my %ip_methods = &remoteip_methods();
5619: if ($setdom) {
5620: $itemcount ++;
5621: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5622: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
5623: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
5624: $wafstyle = ' style="display:none;"';
5625: $nowafstyle = ' style="display:table-row;"';
5626: $currwafdisplay = ' style="display: none"';
5627: $wafrangestyle = ' style="display: none"';
5628: $curr_remotip = 'n';
5629: $ssltossl = ' checked="checked"';
5630: if ($showdom) {
5631: $wafstyle = ' style="display:table-row;"';
5632: $nowafstyle = ' style="display:none;"';
5633: if (keys(%{$values{$dom}})) {
5634: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
5635: $curr_remotip = $values{$dom}{remoteip};
5636: }
5637: if ($curr_remotip eq 'h') {
5638: $currwafdisplay = ' style="display:table-row"';
5639: $wafrangestyle = ' style="display:inline-block;"';
5640: }
5641: if ($values{$dom}{'sslopt'}) {
5642: $alltossl = ' checked="checked"';
5643: $ssltossl = '';
5644: }
5645: }
5646: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
5647: $vpndircheck = ' checked="checked"';
5648: $currwafvpn = ' style="display:table-row;"';
5649: $wafrangestyle = ' style="display:inline-block;"';
5650: } else {
5651: $vpnaliascheck = ' checked="checked"';
5652: $currwafvpn = ' style="display:none;"';
5653: }
5654: }
5655: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5656: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
5657: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
5658: '</tr>'.
5659: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
5660: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
5661: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
5662: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
5663: &mt('Range(s) stored in CIDR notation').'</div></td>'.
5664: '<td class="LC_left_item"><table>'.
5665: '<tr>'.
5666: '<td valign="top">'.$lt{'remoteip'}.': '.
5667: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
5668: foreach my $option ('m','h','n') {
5669: my $sel;
5670: if ($option eq $curr_remotip) {
5671: $sel = ' selected="selected"';
5672: }
5673: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
5674: $ip_methods{$option}.'</option>';
5675: }
5676: $datatable .= '</select></td></tr>'."\n".
5677: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
5678: $lt{'ipheader'}.': '.
5679: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
5680: 'name="wafproxy_ipheader" />'.
5681: '</td></tr>'."\n".
5682: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
5683: $lt{'trusted'}.':<br />'.
5684: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
5685: $values{$dom}{'trusted'}.'</textarea>'.
5686: '</td></tr>'."\n".
5687: '<tr><td><hr /></td></tr>'."\n".
5688: '<tr>'.
5689: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
5690: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
5691: $lt{'vpndirect'}.'</label>'.(' 'x2).
5692: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
5693: $lt{'vpnaliased'}.'</label></span></td></tr>';
5694: foreach my $item ('vpnint','vpnext') {
5695: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
5696: '<td valign="top">'.$lt{$item}.':<br />'.
5697: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
5698: $values{$dom}{$item}.'</textarea>'.
5699: '</td></tr>'."\n";
5700: }
5701: $datatable .= '<tr><td><hr /></td></tr>'."\n".
5702: '<tr>'.
5703: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
5704: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
5705: $lt{'alltossl'}.'</label>'.(' 'x2).
5706: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
5707: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
5708: '</table></td></tr>';
5709: }
5710: if (keys(%otherdoms)) {
5711: foreach my $domain (sort(keys(%otherdoms))) {
5712: $itemcount ++;
5713: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5714: $datatable .= '<tr'.$css_class.'>'.
5715: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
5716: '<td class="LC_left_item"><table>';
5717: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
5718: my $showval = &mt('None');
5719: if ($item eq 'ssl') {
5720: $showval = $lt{'ssltossl'};
5721: }
5722: if ($values{$domain}{$item}) {
5723: $showval = $values{$domain}{$item};
5724: if ($item eq 'ssl') {
5725: $showval = $lt{'alltossl'};
5726: } elsif ($item eq 'remoteip') {
5727: $showval = $ip_methods{$values{$domain}{$item}};
5728: }
5729: }
5730: $datatable .= '<tr>'.
5731: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
5732: }
5733: $datatable .= '</table></td></tr>';
5734: }
5735: }
5736: }
5737: $$rowtotal += $itemcount;
5738: return $datatable;
5739: }
5740:
5741: sub wafproxy_titles {
5742: return &Apache::lonlocal::texthash(
5743: remoteip => "Method for determining user's IP",
5744: ipheader => 'Request header containing remote IP',
5745: trusted => 'Trusted IP range(s)',
5746: vpnaccess => 'Access from institutional VPN',
5747: vpndirect => 'via regular hostname (no WAF)',
5748: vpnaliased => 'via aliased hostname (WAF)',
5749: vpnint => 'Internal IP Range(s) for VPN sessions',
5750: vpnext => 'IP Range(s) for backend WAF connections',
5751: sslopt => 'Forwarding http/https',
5752: alltossl => 'WAF forwards both http and https requests to https',
5753: ssltossl => 'WAF forwards http requests to http and https to https',
5754: );
5755: }
5756:
5757: sub remoteip_methods {
5758: return &Apache::lonlocal::texthash(
5759: m => 'Use Apache mod_remoteip',
5760: h => 'Use headers parsed by LON-CAPA',
5761: n => 'Not in use',
5762: );
5763: }
5764:
5765: sub print_usersessions {
5766: my ($position,$dom,$settings,$rowtotal) = @_;
5767: my ($css_class,$datatable,%checked,%choices);
5768: my (%by_ip,%by_location,@intdoms);
5769: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
5770:
5771: my @alldoms = &Apache::lonnet::all_domains();
5772: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5773: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5774: my %altids = &id_for_thisdom(%servers);
5775: my $itemcount = 1;
5776: if ($position eq 'top') {
5777: if (keys(%serverhomes) > 1) {
5778: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
5779: my ($curroffloadnow,$curroffloadoth);
5780: if (ref($settings) eq 'HASH') {
5781: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5782: $curroffloadnow = $settings->{'offloadnow'};
5783: }
5784: if (ref($settings->{'offloadoth'}) eq 'HASH') {
5785: $curroffloadoth = $settings->{'offloadoth'};
5786: }
5787: }
5788: my $other_insts = scalar(keys(%by_location));
5789: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5790: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
5791: } else {
5792: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
5793: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
5794: }
5795: } else {
5796: if (keys(%by_location) == 0) {
5797: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
5798: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
5799: } else {
5800: my %lt = &usersession_titles();
5801: my $numinrow = 5;
5802: my $prefix;
5803: my @types;
5804: if ($position eq 'bottom') {
5805: $prefix = 'remote';
5806: @types = ('version','excludedomain','includedomain');
5807: } else {
5808: $prefix = 'hosted';
5809: @types = ('excludedomain','includedomain');
5810: }
5811: my (%current,%checkedon,%checkedoff);
5812: my @lcversions = &Apache::lonnet::all_loncaparevs();
5813: my @locations = sort(keys(%by_location));
5814: foreach my $type (@types) {
5815: $checkedon{$type} = '';
5816: $checkedoff{$type} = ' checked="checked"';
5817: }
5818: if (ref($settings) eq 'HASH') {
5819: if (ref($settings->{$prefix}) eq 'HASH') {
5820: foreach my $key (keys(%{$settings->{$prefix}})) {
5821: $current{$key} = $settings->{$prefix}{$key};
5822: if ($key eq 'version') {
5823: if ($current{$key} ne '') {
5824: $checkedon{$key} = ' checked="checked"';
5825: $checkedoff{$key} = '';
5826: }
5827: } elsif (ref($current{$key}) eq 'ARRAY') {
5828: $checkedon{$key} = ' checked="checked"';
5829: $checkedoff{$key} = '';
5830: }
5831: }
5832: }
5833: }
5834: foreach my $type (@types) {
5835: next if ($type ne 'version' && !@locations);
5836: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5837: $datatable .= '<tr'.$css_class.'>
5838: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5839: <span class="LC_nobreak">
5840: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5841: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5842: if ($type eq 'version') {
5843: my $selector = '<select name="'.$prefix.'_version">';
5844: foreach my $version (@lcversions) {
5845: my $selected = '';
5846: if ($current{'version'} eq $version) {
5847: $selected = ' selected="selected"';
5848: }
5849: $selector .= ' <option value="'.$version.'"'.
5850: $selected.'>'.$version.'</option>';
5851: }
5852: $selector .= '</select> ';
5853: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5854: } else {
5855: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5856: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5857: ' />'.(' 'x2).
5858: '<input type="button" value="'.&mt('uncheck all').'" '.
5859: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5860: "\n".
5861: '</div><div><table>';
5862: my $rem;
5863: for (my $i=0; $i<@locations; $i++) {
5864: my ($showloc,$value,$checkedtype);
5865: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5866: my $ip = $by_location{$locations[$i]}->[0];
5867: if (ref($by_ip{$ip}) eq 'ARRAY') {
5868: $value = join(':',@{$by_ip{$ip}});
5869: $showloc = join(', ',@{$by_ip{$ip}});
5870: if (ref($current{$type}) eq 'ARRAY') {
5871: foreach my $loc (@{$by_ip{$ip}}) {
5872: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5873: $checkedtype = ' checked="checked"';
5874: last;
5875: }
5876: }
5877: }
5878: }
5879: }
5880: $rem = $i%($numinrow);
5881: if ($rem == 0) {
5882: if ($i > 0) {
5883: $datatable .= '</tr>';
5884: }
5885: $datatable .= '<tr>';
5886: }
5887: $datatable .= '<td class="LC_left_item">'.
5888: '<span class="LC_nobreak"><label>'.
5889: '<input type="checkbox" name="'.$prefix.'_'.$type.
5890: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5891: '</label></span></td>';
5892: }
5893: $rem = @locations%($numinrow);
5894: my $colsleft = $numinrow - $rem;
5895: if ($colsleft > 1 ) {
5896: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5897: ' </td>';
5898: } elsif ($colsleft == 1) {
5899: $datatable .= '<td class="LC_left_item"> </td>';
5900: }
5901: $datatable .= '</tr></table>';
5902: }
5903: $datatable .= '</td></tr>';
5904: $itemcount ++;
5905: }
5906: }
5907: }
5908: $$rowtotal += $itemcount;
5909: return $datatable;
5910: }
5911:
5912: sub build_location_hashes {
5913: my ($intdoms,$by_ip,$by_location) = @_;
5914: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5915: (ref($by_location) eq 'HASH'));
5916: my %iphost = &Apache::lonnet::get_iphost();
5917: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5918: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5919: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5920: foreach my $id (@{$iphost{$primary_ip}}) {
5921: my $intdom = &Apache::lonnet::internet_dom($id);
5922: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5923: push(@{$intdoms},$intdom);
5924: }
5925: }
5926: }
5927: foreach my $ip (keys(%iphost)) {
5928: if (ref($iphost{$ip}) eq 'ARRAY') {
5929: foreach my $id (@{$iphost{$ip}}) {
5930: my $location = &Apache::lonnet::internet_dom($id);
5931: if ($location) {
5932: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5933: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5934: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5935: push(@{$by_ip->{$ip}},$location);
5936: }
5937: } else {
5938: $by_ip->{$ip} = [$location];
5939: }
5940: }
5941: }
5942: }
5943: }
5944: foreach my $ip (sort(keys(%{$by_ip}))) {
5945: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5946: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5947: my $first = $by_ip->{$ip}->[0];
5948: if (ref($by_location->{$first}) eq 'ARRAY') {
5949: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5950: push(@{$by_location->{$first}},$ip);
5951: }
5952: } else {
5953: $by_location->{$first} = [$ip];
5954: }
5955: }
5956: }
5957: return;
5958: }
5959:
5960: sub current_offloads_to {
5961: my ($dom,$settings,$servers) = @_;
5962: my (%spareid,%otherdomconfigs);
5963: if (ref($servers) eq 'HASH') {
5964: foreach my $lonhost (sort(keys(%{$servers}))) {
5965: my $gotspares;
5966: if (ref($settings) eq 'HASH') {
5967: if (ref($settings->{'spares'}) eq 'HASH') {
5968: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5969: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5970: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5971: $gotspares = 1;
5972: }
5973: }
5974: }
5975: unless ($gotspares) {
5976: my $gotspares;
5977: my $serverhomeID =
5978: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5979: my $serverhomedom =
5980: &Apache::lonnet::host_domain($serverhomeID);
5981: if ($serverhomedom ne $dom) {
5982: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5983: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5984: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5985: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5986: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5987: $gotspares = 1;
5988: }
5989: }
5990: } else {
5991: $otherdomconfigs{$serverhomedom} =
5992: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5993: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5994: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5995: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5996: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5997: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5998: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5999: $gotspares = 1;
6000: }
6001: }
6002: }
6003: }
6004: }
6005: }
6006: }
6007: unless ($gotspares) {
6008: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6009: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6010: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6011: } else {
6012: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6013: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6014: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6015: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6016: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6017: } else {
6018: my %what = (
6019: spareid => 1,
6020: );
6021: my ($result,$returnhash) =
6022: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6023: if ($result eq 'ok') {
6024: if (ref($returnhash) eq 'HASH') {
6025: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6026: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6027: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6028: }
6029: }
6030: }
6031: }
6032: }
6033: }
6034: }
6035: }
6036: return %spareid;
6037: }
6038:
6039: sub spares_row {
6040: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6041: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
6042: my $css_class;
6043: my $numinrow = 4;
6044: my $itemcount = 1;
6045: my $datatable;
6046: my %typetitles = &sparestype_titles();
6047: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
6048: foreach my $server (sort(keys(%{$servers}))) {
6049: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6050: my ($othercontrol,$serverdom);
6051: if ($serverhome ne $server) {
6052: $serverdom = &Apache::lonnet::host_domain($serverhome);
6053: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6054: } else {
6055: $serverdom = &Apache::lonnet::host_domain($server);
6056: if ($serverdom ne $dom) {
6057: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6058: }
6059: }
6060: next unless (ref($spareid->{$server}) eq 'HASH');
6061: my ($checkednow,$checkedoth);
6062: if (ref($curroffloadnow) eq 'HASH') {
6063: if ($curroffloadnow->{$server}) {
6064: $checkednow = ' checked="checked"';
6065: }
6066: }
6067: if (ref($curroffloadoth) eq 'HASH') {
6068: if ($curroffloadoth->{$server}) {
6069: $checkedoth = ' checked="checked"';
6070: }
6071: }
6072: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6073: $datatable .= '<tr'.$css_class.'>
6074: <td rowspan="2">
6075: <span class="LC_nobreak">'.
6076: &mt('[_1] when busy, offloads to:'
6077: ,'<b>'.$server.'</b>').'</span><br />'.
6078: '<span class="LC_nobreak">'."\n".
6079: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6080: ' '.&mt('Switch any active user on next access').'</label></span>'.
6081: "\n";
6082: if ($other_insts) {
6083: $datatable .= '<br />'.
6084: '<span class="LC_nobreak">'."\n".
6085: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6086: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6087: "\n";
6088: }
6089: my (%current,%canselect);
6090: my @choices =
6091: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6092: foreach my $type ('primary','default') {
6093: if (ref($spareid->{$server}) eq 'HASH') {
6094: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6095: my @spares = @{$spareid->{$server}{$type}};
6096: if (@spares > 0) {
6097: if ($othercontrol) {
6098: $current{$type} = join(', ',@spares);
6099: } else {
6100: $current{$type} .= '<table>';
6101: my $numspares = scalar(@spares);
6102: for (my $i=0; $i<@spares; $i++) {
6103: my $rem = $i%($numinrow);
6104: if ($rem == 0) {
6105: if ($i > 0) {
6106: $current{$type} .= '</tr>';
6107: }
6108: $current{$type} .= '<tr>';
6109: }
6110: $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'".');" /> '.
6111: $spareid->{$server}{$type}[$i].
6112: '</label></td>'."\n";
6113: }
6114: my $rem = @spares%($numinrow);
6115: my $colsleft = $numinrow - $rem;
6116: if ($colsleft > 1 ) {
6117: $current{$type} .= '<td colspan="'.$colsleft.
6118: '" class="LC_left_item">'.
6119: ' </td>';
6120: } elsif ($colsleft == 1) {
6121: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
6122: }
6123: $current{$type} .= '</tr></table>';
6124: }
6125: }
6126: }
6127: if ($current{$type} eq '') {
6128: $current{$type} = &mt('None specified');
6129: }
6130: if ($othercontrol) {
6131: if ($type eq 'primary') {
6132: $canselect{$type} = $othercontrol;
6133: }
6134: } else {
6135: $canselect{$type} =
6136: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6137: '<select name="newspare_'.$type.'_'.$server.'" '.
6138: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6139: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6140: if (@choices > 0) {
6141: foreach my $lonhost (@choices) {
6142: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6143: }
6144: }
6145: $canselect{$type} .= '</select>'."\n";
6146: }
6147: } else {
6148: $current{$type} = &mt('Could not be determined');
6149: if ($type eq 'primary') {
6150: $canselect{$type} = $othercontrol;
6151: }
6152: }
6153: if ($type eq 'default') {
6154: $datatable .= '<tr'.$css_class.'>';
6155: }
6156: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6157: '<td>'.$current{$type}.'</td>'."\n".
6158: '<td>'.$canselect{$type}.'</td></tr>'."\n";
6159: }
6160: $itemcount ++;
6161: }
6162: }
6163: $$rowtotal += $itemcount;
6164: return $datatable;
6165: }
6166:
6167: sub possible_newspares {
6168: my ($server,$currspares,$serverhomes,$altids) = @_;
6169: my $serverhostname = &Apache::lonnet::hostname($server);
6170: my %excluded;
6171: if ($serverhostname ne '') {
6172: %excluded = (
6173: $serverhostname => 1,
6174: );
6175: }
6176: if (ref($currspares) eq 'HASH') {
6177: foreach my $type (keys(%{$currspares})) {
6178: if (ref($currspares->{$type}) eq 'ARRAY') {
6179: if (@{$currspares->{$type}} > 0) {
6180: foreach my $curr (@{$currspares->{$type}}) {
6181: my $hostname = &Apache::lonnet::hostname($curr);
6182: $excluded{$hostname} = 1;
6183: }
6184: }
6185: }
6186: }
6187: }
6188: my @choices;
6189: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6190: if (keys(%{$serverhomes}) > 1) {
6191: foreach my $name (sort(keys(%{$serverhomes}))) {
6192: unless ($excluded{$name}) {
6193: if (exists($altids->{$serverhomes->{$name}})) {
6194: push(@choices,$altids->{$serverhomes->{$name}});
6195: } else {
6196: push(@choices,$serverhomes->{$name});
6197: }
6198: }
6199: }
6200: }
6201: }
6202: return sort(@choices);
6203: }
6204:
6205: sub print_loadbalancing {
6206: my ($dom,$settings,$rowtotal) = @_;
6207: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6208: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6209: my $numinrow = 1;
6210: my $datatable;
6211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6212: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
6213: if (ref($settings) eq 'HASH') {
6214: %existing = %{$settings};
6215: }
6216: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6217: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
6218: \%currtargets,\%currrules,\%currcookies);
6219: } else {
6220: return;
6221: }
6222: my ($othertitle,$usertypes,$types) =
6223: &Apache::loncommon::sorted_inst_types($dom);
6224: my $rownum = 8;
6225: if (ref($types) eq 'ARRAY') {
6226: $rownum += scalar(@{$types});
6227: }
6228: my @css_class = ('LC_odd_row','LC_even_row');
6229: my $balnum = 0;
6230: my $islast;
6231: my (@toshow,$disabledtext);
6232: if (keys(%currbalancer) > 0) {
6233: @toshow = sort(keys(%currbalancer));
6234: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6235: push(@toshow,'');
6236: }
6237: } else {
6238: @toshow = ('');
6239: $disabledtext = &mt('No existing load balancer');
6240: }
6241: foreach my $lonhost (@toshow) {
6242: if ($balnum == scalar(@toshow)-1) {
6243: $islast = 1;
6244: } else {
6245: $islast = 0;
6246: }
6247: my $cssidx = $balnum%2;
6248: my $targets_div_style = 'display: none';
6249: my $disabled_div_style = 'display: block';
6250: my $homedom_div_style = 'display: none';
6251: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
6252: '<td rowspan="'.$rownum.'" valign="top">'.
6253: '<p>';
6254: if ($lonhost eq '') {
6255: $datatable .= '<span class="LC_nobreak">';
6256: if (keys(%currbalancer) > 0) {
6257: $datatable .= &mt('Add balancer:');
6258: } else {
6259: $datatable .= &mt('Enable balancer:');
6260: }
6261: $datatable .= ' '.
6262: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6263: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6264: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6265: '<option value="" selected="selected">'.&mt('None').
6266: '</option>'."\n";
6267: foreach my $server (sort(keys(%servers))) {
6268: next if ($currbalancer{$server});
6269: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6270: }
6271: $datatable .=
6272: '</select>'."\n".
6273: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6274: } else {
6275: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6276: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6277: &mt('Stop balancing').'</label>'.
6278: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6279: $targets_div_style = 'display: block';
6280: $disabled_div_style = 'display: none';
6281: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6282: $homedom_div_style = 'display: block';
6283: }
6284: }
6285: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
6286: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6287: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6288: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6289: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6290: my @sparestypes = ('primary','default');
6291: my %typetitles = &sparestype_titles();
6292: my %hostherechecked = (
6293: no => ' checked="checked"',
6294: );
6295: my %balcookiechecked = (
6296: no => ' checked="checked"',
6297: );
6298: foreach my $sparetype (@sparestypes) {
6299: my $targettable;
6300: for (my $i=0; $i<$numspares; $i++) {
6301: my $checked;
6302: if (ref($currtargets{$lonhost}) eq 'HASH') {
6303: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6304: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6305: $checked = ' checked="checked"';
6306: }
6307: }
6308: }
6309: my ($chkboxval,$disabled);
6310: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6311: $chkboxval = $spares[$i];
6312: }
6313: if (exists($currbalancer{$spares[$i]})) {
6314: $disabled = ' disabled="disabled"';
6315: }
6316: $targettable .=
6317: '<td><span class="LC_nobreak"><label>'.
6318: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
6319: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
6320: '</span></label></span></td>';
6321: my $rem = $i%($numinrow);
6322: if ($rem == 0) {
6323: if (($i > 0) && ($i < $numspares-1)) {
6324: $targettable .= '</tr>';
6325: }
6326: if ($i < $numspares-1) {
6327: $targettable .= '<tr>';
6328: }
6329: }
6330: }
6331: if ($targettable ne '') {
6332: my $rem = $numspares%($numinrow);
6333: my $colsleft = $numinrow - $rem;
6334: if ($colsleft > 1 ) {
6335: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6336: ' </td>';
6337: } elsif ($colsleft == 1) {
6338: $targettable .= '<td class="LC_left_item"> </td>';
6339: }
6340: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6341: '<table><tr>'.$targettable.'</tr></table><br />';
6342: }
6343: $hostherechecked{$sparetype} = '';
6344: if (ref($currtargets{$lonhost}) eq 'HASH') {
6345: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6346: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6347: $hostherechecked{$sparetype} = ' checked="checked"';
6348: $hostherechecked{'no'} = '';
6349: }
6350: }
6351: }
6352: }
6353: if ($currcookies{$lonhost}) {
6354: %balcookiechecked = (
6355: yes => ' checked="checked"',
6356: );
6357: }
6358: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6359: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6360: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6361: foreach my $sparetype (@sparestypes) {
6362: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6363: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6364: '</i></label><br />';
6365: }
6366: $datatable .= &mt('Use balancer cookie').'<br />'.
6367: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6368: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6369: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6370: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6371: '</div></td></tr>'.
6372: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6373: $othertitle,$usertypes,$types,\%servers,
6374: \%currbalancer,$lonhost,
6375: $targets_div_style,$homedom_div_style,
6376: $css_class[$cssidx],$balnum,$islast);
6377: $$rowtotal += $rownum;
6378: $balnum ++;
6379: }
6380: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6381: return $datatable;
6382: }
6383:
6384: sub get_loadbalancers_config {
6385: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
6386: return unless ((ref($servers) eq 'HASH') &&
6387: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6388: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6389: (ref($currcookies) eq 'HASH'));
6390: if (keys(%{$existing}) > 0) {
6391: my $oldlonhost;
6392: foreach my $key (sort(keys(%{$existing}))) {
6393: if ($key eq 'lonhost') {
6394: $oldlonhost = $existing->{'lonhost'};
6395: $currbalancer->{$oldlonhost} = 1;
6396: } elsif ($key eq 'targets') {
6397: if ($oldlonhost) {
6398: $currtargets->{$oldlonhost} = $existing->{'targets'};
6399: }
6400: } elsif ($key eq 'rules') {
6401: if ($oldlonhost) {
6402: $currrules->{$oldlonhost} = $existing->{'rules'};
6403: }
6404: } elsif (ref($existing->{$key}) eq 'HASH') {
6405: $currbalancer->{$key} = 1;
6406: $currtargets->{$key} = $existing->{$key}{'targets'};
6407: $currrules->{$key} = $existing->{$key}{'rules'};
6408: if ($existing->{$key}{'cookie'}) {
6409: $currcookies->{$key} = 1;
6410: }
6411: }
6412: }
6413: } else {
6414: my ($balancerref,$targetsref) =
6415: &Apache::lonnet::get_lonbalancer_config($servers);
6416: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6417: foreach my $server (sort(keys(%{$balancerref}))) {
6418: $currbalancer->{$server} = 1;
6419: $currtargets->{$server} = $targetsref->{$server};
6420: }
6421: }
6422: }
6423: return;
6424: }
6425:
6426: sub loadbalancing_rules {
6427: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
6428: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6429: $css_class,$balnum,$islast) = @_;
6430: my $output;
6431: my $num = 0;
6432: my ($alltypes,$othertypes,$titles) =
6433: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6434: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6435: foreach my $type (@{$alltypes}) {
6436: $num ++;
6437: my $current;
6438: if (ref($currrules) eq 'HASH') {
6439: $current = $currrules->{$type};
6440: }
6441: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
6442: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
6443: $current = '';
6444: }
6445: }
6446: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
6447: $servers,$currbalancer,$lonhost,$dom,
6448: $targets_div_style,$homedom_div_style,
6449: $css_class,$balnum,$num,$islast);
6450: }
6451: }
6452: return $output;
6453: }
6454:
6455: sub loadbalancing_titles {
6456: my ($dom,$intdom,$usertypes,$types) = @_;
6457: my %othertypes = (
6458: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6459: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6460: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6461: '_LC_external' => &mt('Users not from [_1]',$intdom),
6462: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6463: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
6464: );
6465: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
6466: my @available;
6467: if (ref($types) eq 'ARRAY') {
6468: @available = @{$types};
6469: }
6470: unless (grep(/^default$/,@available)) {
6471: push(@available,'default');
6472: }
6473: unshift(@alltypes,@available);
6474: my %titles;
6475: foreach my $type (@alltypes) {
6476: if ($type =~ /^_LC_/) {
6477: $titles{$type} = $othertypes{$type};
6478: } elsif ($type eq 'default') {
6479: $titles{$type} = &mt('All users from [_1]',$dom);
6480: if (ref($types) eq 'ARRAY') {
6481: if (@{$types} > 0) {
6482: $titles{$type} = &mt('Other users from [_1]',$dom);
6483: }
6484: }
6485: } elsif (ref($usertypes) eq 'HASH') {
6486: $titles{$type} = $usertypes->{$type};
6487: }
6488: }
6489: return (\@alltypes,\%othertypes,\%titles);
6490: }
6491:
6492: sub loadbalance_rule_row {
6493: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6494: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
6495: my @rulenames;
6496: my %ruletitles = &offloadtype_text();
6497: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
6498: @rulenames = ('balancer','offloadedto','specific');
6499: } else {
6500: @rulenames = ('default','homeserver');
6501: if ($type eq '_LC_external') {
6502: push(@rulenames,'externalbalancer');
6503: } else {
6504: push(@rulenames,'specific');
6505: }
6506: push(@rulenames,'none');
6507: }
6508: my $style = $targets_div_style;
6509: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
6510: $style = $homedom_div_style;
6511: }
6512: my $space;
6513: if ($islast && $num == 1) {
6514: $space = '<div display="inline-block"> </div>';
6515: }
6516: my $output =
6517: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6518: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6519: '<td valaign="top">'.$space.
6520: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
6521: for (my $i=0; $i<@rulenames; $i++) {
6522: my $rule = $rulenames[$i];
6523: my ($checked,$extra);
6524: if ($rulenames[$i] eq 'default') {
6525: $rule = '';
6526: }
6527: if ($rulenames[$i] eq 'specific') {
6528: if (ref($servers) eq 'HASH') {
6529: my $default;
6530: if (($current ne '') && (exists($servers->{$current}))) {
6531: $checked = ' checked="checked"';
6532: }
6533: unless ($checked) {
6534: $default = ' selected="selected"';
6535: }
6536: $extra =
6537: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6538: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6539: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6540: '<option value=""'.$default.'></option>'."\n";
6541: foreach my $server (sort(keys(%{$servers}))) {
6542: if (ref($currbalancer) eq 'HASH') {
6543: next if (exists($currbalancer->{$server}));
6544: }
6545: my $selected;
6546: if ($server eq $current) {
6547: $selected = ' selected="selected"';
6548: }
6549: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
6550: }
6551: $extra .= '</select>';
6552: }
6553: } elsif ($rule eq $current) {
6554: $checked = ' checked="checked"';
6555: }
6556: $output .= '<span class="LC_nobreak"><label>'.
6557: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6558: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6559: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
6560: ')"'.$checked.' /> ';
6561: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6562: $output .= $ruletitles{'particular'};
6563: } else {
6564: $output .= $ruletitles{$rulenames[$i]};
6565: }
6566: $output .= '</label>'.$extra.'</span><br />'."\n";
6567: }
6568: $output .= '</div></td></tr>'."\n";
6569: return $output;
6570: }
6571:
6572: sub offloadtype_text {
6573: my %ruletitles = &Apache::lonlocal::texthash (
6574: 'default' => 'Offloads to default destinations',
6575: 'homeserver' => "Offloads to user's home server",
6576: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6577: 'specific' => 'Offloads to specific server',
6578: 'none' => 'No offload',
6579: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6580: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
6581: 'particular' => 'Session hosted (after re-auth) on server:',
6582: );
6583: return %ruletitles;
6584: }
6585:
6586: sub sparestype_titles {
6587: my %typestitles = &Apache::lonlocal::texthash (
6588: 'primary' => 'primary',
6589: 'default' => 'default',
6590: );
6591: return %typestitles;
6592: }
6593:
6594: sub contact_titles {
6595: my %titles = &Apache::lonlocal::texthash (
6596: 'supportemail' => 'Support E-mail address',
6597: 'adminemail' => 'Default Server Admin E-mail address',
6598: 'errormail' => 'Error reports to be e-mailed to',
6599: 'packagesmail' => 'Package update alerts to be e-mailed to',
6600: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6601: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
6602: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6603: 'requestsmail' => 'E-mail from course requests requiring approval',
6604: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
6605: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
6606: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
6607: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
6608: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
6609: 'errorweights' => 'Weights used to compute error count',
6610: 'errorexcluded' => 'Servers with unsent updates excluded from count',
6611: );
6612: my %short_titles = &Apache::lonlocal::texthash (
6613: adminemail => 'Admin E-mail address',
6614: supportemail => 'Support E-mail',
6615: );
6616: return (\%titles,\%short_titles);
6617: }
6618:
6619: sub helpform_fields {
6620: my %titles = &Apache::lonlocal::texthash (
6621: 'username' => 'Name',
6622: 'user' => 'Username/domain',
6623: 'phone' => 'Phone',
6624: 'cc' => 'Cc e-mail',
6625: 'course' => 'Course Details',
6626: 'section' => 'Sections',
6627: 'screenshot' => 'File upload',
6628: );
6629: my @fields = ('username','phone','user','course','section','cc','screenshot');
6630: my %possoptions = (
6631: username => ['yes','no','req'],
6632: phone => ['yes','no','req'],
6633: user => ['yes','no'],
6634: cc => ['yes','no'],
6635: course => ['yes','no'],
6636: section => ['yes','no'],
6637: screenshot => ['yes','no'],
6638: );
6639: my %fieldoptions = &Apache::lonlocal::texthash (
6640: 'yes' => 'Optional',
6641: 'req' => 'Required',
6642: 'no' => "Not shown",
6643: );
6644: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6645: }
6646:
6647: sub tool_titles {
6648: my %titles = &Apache::lonlocal::texthash (
6649: aboutme => 'Personal web page',
6650: blog => 'Blog',
6651: webdav => 'WebDAV',
6652: portfolio => 'Portfolio',
6653: official => 'Official courses (with institutional codes)',
6654: unofficial => 'Unofficial courses',
6655: community => 'Communities',
6656: textbook => 'Textbook courses',
6657: );
6658: return %titles;
6659: }
6660:
6661: sub courserequest_titles {
6662: my %titles = &Apache::lonlocal::texthash (
6663: official => 'Official',
6664: unofficial => 'Unofficial',
6665: community => 'Communities',
6666: textbook => 'Textbook',
6667: norequest => 'Not allowed',
6668: approval => 'Approval by Dom. Coord.',
6669: validate => 'With validation',
6670: autolimit => 'Numerical limit',
6671: unlimited => '(blank for unlimited)',
6672: );
6673: return %titles;
6674: }
6675:
6676: sub authorrequest_titles {
6677: my %titles = &Apache::lonlocal::texthash (
6678: norequest => 'Not allowed',
6679: approval => 'Approval by Dom. Coord.',
6680: automatic => 'Automatic approval',
6681: );
6682: return %titles;
6683: }
6684:
6685: sub courserequest_conditions {
6686: my %conditions = &Apache::lonlocal::texthash (
6687: approval => '(Processing of request subject to approval by Domain Coordinator).',
6688: validate => '(Processing of request subject to institutional validation).',
6689: );
6690: return %conditions;
6691: }
6692:
6693:
6694: sub print_usercreation {
6695: my ($position,$dom,$settings,$rowtotal) = @_;
6696: my $numinrow = 4;
6697: my $datatable;
6698: if ($position eq 'top') {
6699: $$rowtotal ++;
6700: my $rowcount = 0;
6701: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
6702: if (ref($rules) eq 'HASH') {
6703: if (keys(%{$rules}) > 0) {
6704: $datatable .= &user_formats_row('username',$settings,$rules,
6705: $ruleorder,$numinrow,$rowcount);
6706: $$rowtotal ++;
6707: $rowcount ++;
6708: }
6709: }
6710: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6711: if (ref($idrules) eq 'HASH') {
6712: if (keys(%{$idrules}) > 0) {
6713: $datatable .= &user_formats_row('id',$settings,$idrules,
6714: $idruleorder,$numinrow,$rowcount);
6715: $$rowtotal ++;
6716: $rowcount ++;
6717: }
6718: }
6719: if ($rowcount == 0) {
6720: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6721: $$rowtotal ++;
6722: $rowcount ++;
6723: }
6724: } elsif ($position eq 'middle') {
6725: my @creators = ('author','course','requestcrs');
6726: my ($rules,$ruleorder) =
6727: &Apache::lonnet::inst_userrules($dom,'username');
6728: my %lt = &usercreation_types();
6729: my %checked;
6730: if (ref($settings) eq 'HASH') {
6731: if (ref($settings->{'cancreate'}) eq 'HASH') {
6732: foreach my $item (@creators) {
6733: $checked{$item} = $settings->{'cancreate'}{$item};
6734: }
6735: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6736: foreach my $item (@creators) {
6737: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6738: $checked{$item} = 'none';
6739: }
6740: }
6741: }
6742: }
6743: my $rownum = 0;
6744: foreach my $item (@creators) {
6745: $rownum ++;
6746: if ($checked{$item} eq '') {
6747: $checked{$item} = 'any';
6748: }
6749: my $css_class;
6750: if ($rownum%2) {
6751: $css_class = '';
6752: } else {
6753: $css_class = ' class="LC_odd_row" ';
6754: }
6755: $datatable .= '<tr'.$css_class.'>'.
6756: '<td><span class="LC_nobreak">'.$lt{$item}.
6757: '</span></td><td align="right">';
6758: my @options = ('any');
6759: if (ref($rules) eq 'HASH') {
6760: if (keys(%{$rules}) > 0) {
6761: push(@options,('official','unofficial'));
6762: }
6763: }
6764: push(@options,'none');
6765: foreach my $option (@options) {
6766: my $type = 'radio';
6767: my $check = ' ';
6768: if ($checked{$item} eq $option) {
6769: $check = ' checked="checked" ';
6770: }
6771: $datatable .= '<span class="LC_nobreak"><label>'.
6772: '<input type="'.$type.'" name="can_createuser_'.
6773: $item.'" value="'.$option.'"'.$check.'/> '.
6774: $lt{$option}.'</label> </span>';
6775: }
6776: $datatable .= '</td></tr>';
6777: }
6778: } else {
6779: my @contexts = ('author','course','domain');
6780: my @authtypes = ('int','krb4','krb5','loc');
6781: my %checked;
6782: if (ref($settings) eq 'HASH') {
6783: if (ref($settings->{'authtypes'}) eq 'HASH') {
6784: foreach my $item (@contexts) {
6785: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6786: foreach my $auth (@authtypes) {
6787: if ($settings->{'authtypes'}{$item}{$auth}) {
6788: $checked{$item}{$auth} = ' checked="checked" ';
6789: }
6790: }
6791: }
6792: }
6793: }
6794: } else {
6795: foreach my $item (@contexts) {
6796: foreach my $auth (@authtypes) {
6797: $checked{$item}{$auth} = ' checked="checked" ';
6798: }
6799: }
6800: }
6801: my %title = &context_names();
6802: my %authname = &authtype_names();
6803: my $rownum = 0;
6804: my $css_class;
6805: foreach my $item (@contexts) {
6806: if ($rownum%2) {
6807: $css_class = '';
6808: } else {
6809: $css_class = ' class="LC_odd_row" ';
6810: }
6811: $datatable .= '<tr'.$css_class.'>'.
6812: '<td>'.$title{$item}.
6813: '</td><td class="LC_left_item">'.
6814: '<span class="LC_nobreak">';
6815: foreach my $auth (@authtypes) {
6816: $datatable .= '<label>'.
6817: '<input type="checkbox" name="'.$item.'_auth" '.
6818: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6819: $authname{$auth}.'</label> ';
6820: }
6821: $datatable .= '</span></td></tr>';
6822: $rownum ++;
6823: }
6824: $$rowtotal += $rownum;
6825: }
6826: return $datatable;
6827: }
6828:
6829: sub print_selfcreation {
6830: my ($position,$dom,$settings,$rowtotal) = @_;
6831: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6832: $emaildomain,$datatable);
6833: if (ref($settings) eq 'HASH') {
6834: if (ref($settings->{'cancreate'}) eq 'HASH') {
6835: $createsettings = $settings->{'cancreate'};
6836: if (ref($createsettings) eq 'HASH') {
6837: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6838: @selfcreate = @{$createsettings->{'selfcreate'}};
6839: } elsif ($createsettings->{'selfcreate'} ne '') {
6840: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6841: @selfcreate = ('email','login','sso');
6842: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6843: @selfcreate = ($createsettings->{'selfcreate'});
6844: }
6845: }
6846: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6847: $processing = $createsettings->{'selfcreateprocessing'};
6848: }
6849: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6850: $emailoptions = $createsettings->{'emailoptions'};
6851: }
6852: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6853: $emailverified = $createsettings->{'emailverified'};
6854: }
6855: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6856: $emaildomain = $createsettings->{'emaildomain'};
6857: }
6858: }
6859: }
6860: }
6861: my %radiohash;
6862: my $numinrow = 4;
6863: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
6864: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6865: if ($position eq 'top') {
6866: my %choices = &Apache::lonlocal::texthash (
6867: cancreate_login => 'Institutional Login',
6868: cancreate_sso => 'Institutional Single Sign On',
6869: );
6870: my @toggles = sort(keys(%choices));
6871: my %defaultchecked = (
6872: 'cancreate_login' => 'off',
6873: 'cancreate_sso' => 'off',
6874: );
6875: my ($onclick,$itemcount);
6876: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6877: \%choices,$itemcount,$onclick);
6878: $$rowtotal += $itemcount;
6879:
6880: if (ref($usertypes) eq 'HASH') {
6881: if (keys(%{$usertypes}) > 0) {
6882: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6883: $dom,$numinrow,$othertitle,
6884: 'statustocreate',$rowtotal);
6885: $$rowtotal ++;
6886: }
6887: }
6888: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6889: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6890: $fieldtitles{'inststatus'} = &mt('Institutional status');
6891: my $rem;
6892: my $numperrow = 2;
6893: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6894: $datatable .= '<tr'.$css_class.'>'.
6895: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
6896: '<td class="LC_left_item">'."\n".
6897: '<table>'."\n";
6898: for (my $i=0; $i<@fields; $i++) {
6899: $rem = $i%($numperrow);
6900: if ($rem == 0) {
6901: if ($i > 0) {
6902: $datatable .= '</tr>';
6903: }
6904: $datatable .= '<tr>';
6905: }
6906: my $currval;
6907: if (ref($createsettings) eq 'HASH') {
6908: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6909: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6910: }
6911: }
6912: $datatable .= '<td class="LC_left_item">'.
6913: '<span class="LC_nobreak">'.
6914: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6915: 'value="'.$currval.'" size="10" /> '.
6916: $fieldtitles{$fields[$i]}.'</span></td>';
6917: }
6918: my $colsleft = $numperrow - $rem;
6919: if ($colsleft > 1 ) {
6920: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6921: ' </td>';
6922: } elsif ($colsleft == 1) {
6923: $datatable .= '<td class="LC_left_item"> </td>';
6924: }
6925: $datatable .= '</tr></table></td></tr>';
6926: $$rowtotal ++;
6927: } elsif ($position eq 'middle') {
6928: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
6929: my @posstypes;
6930: if (ref($types) eq 'ARRAY') {
6931: @posstypes = @{$types};
6932: }
6933: unless (grep(/^default$/,@posstypes)) {
6934: push(@posstypes,'default');
6935: }
6936: my %usertypeshash;
6937: if (ref($usertypes) eq 'HASH') {
6938: %usertypeshash = %{$usertypes};
6939: }
6940: $usertypeshash{'default'} = $othertitle;
6941: foreach my $status (@posstypes) {
6942: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6943: $numinrow,$$rowtotal,\%usertypeshash);
6944: $$rowtotal ++;
6945: }
6946: } else {
6947: my %choices = &Apache::lonlocal::texthash (
6948: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
6949: );
6950: my @toggles = sort(keys(%choices));
6951: my %defaultchecked = (
6952: 'cancreate_email' => 'off',
6953: );
6954: my $customclass = 'LC_selfcreate_email';
6955: my $classprefix = 'LC_canmodify_emailusername_';
6956: my $optionsprefix = 'LC_options_emailusername_';
6957: my $display = 'none';
6958: my $rowstyle = 'display:none';
6959: if (grep(/^\Qemail\E$/,@selfcreate)) {
6960: $display = 'block';
6961: $rowstyle = 'display:table-row';
6962: }
6963: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6964: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6965: \%choices,$$rowtotal,$onclick);
6966: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6967: $rowstyle);
6968: $$rowtotal ++;
6969: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6970: $rowstyle);
6971: $$rowtotal ++;
6972: my (@ordered,@posstypes,%usertypeshash);
6973: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6974: my ($emailrules,$emailruleorder) =
6975: &Apache::lonnet::inst_userrules($dom,'email');
6976: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6977: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6978: if (ref($types) eq 'ARRAY') {
6979: @posstypes = @{$types};
6980: }
6981: if (@posstypes) {
6982: unless (grep(/^default$/,@posstypes)) {
6983: push(@posstypes,'default');
6984: }
6985: if (ref($usertypes) eq 'HASH') {
6986: %usertypeshash = %{$usertypes};
6987: }
6988: my $currassign;
6989: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6990: $currassign = {
6991: selfassign => $domdefaults{'inststatusguest'},
6992: };
6993: @ordered = @{$domdefaults{'inststatusguest'}};
6994: } else {
6995: $currassign = { selfassign => [] };
6996: }
6997: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6998: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6999: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7000: $numinrow,$othertitle,'selfassign',
7001: $rowtotal,$onclicktypes,$customclass,
7002: $rowstyle);
7003: $$rowtotal ++;
7004: $usertypeshash{'default'} = $othertitle;
7005: foreach my $status (@posstypes) {
7006: my $css_class;
7007: if ($$rowtotal%2) {
7008: $css_class = 'LC_odd_row ';
7009: }
7010: $css_class .= $customclass;
7011: my $rowid = $optionsprefix.$status;
7012: my $hidden = 1;
7013: my $currstyle = 'display:none';
7014: if (grep(/^\Q$status\E$/,@ordered)) {
7015: $currstyle = $rowstyle;
7016: $hidden = 0;
7017: }
7018: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7019: $emailrules,$emailruleorder,$settings,$status,$rowid,
7020: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7021: unless ($hidden) {
7022: $$rowtotal ++;
7023: }
7024: }
7025: } else {
7026: my $css_class;
7027: if ($$rowtotal%2) {
7028: $css_class = 'LC_odd_row ';
7029: }
7030: $css_class .= $customclass;
7031: $usertypeshash{'default'} = $othertitle;
7032: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7033: $emailrules,$emailruleorder,$settings,'default','',
7034: $othertitle,$css_class,$rowstyle,$intdom);
7035: $$rowtotal ++;
7036: }
7037: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7038: $numinrow = 1;
7039: if (@posstypes) {
7040: foreach my $status (@posstypes) {
7041: my $rowid = $classprefix.$status;
7042: my $datarowstyle = 'display:none';
7043: if (grep(/^\Q$status\E$/,@ordered)) {
7044: $datarowstyle = $rowstyle;
7045: }
7046: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7047: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7048: $infotitles,$rowid,$customclass,$datarowstyle);
7049: unless ($datarowstyle eq 'display:none') {
7050: $$rowtotal ++;
7051: }
7052: }
7053: } else {
7054: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7055: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7056: $infotitles,'',$customclass,$rowstyle);
7057: }
7058: }
7059: return $datatable;
7060: }
7061:
7062: sub selfcreate_javascript {
7063: return <<"ENDSCRIPT";
7064:
7065: <script type="text/javascript">
7066: // <![CDATA[
7067:
7068: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7069: var x = document.getElementsByClassName(target);
7070: var insttypes = 0;
7071: var insttypeRegExp = new RegExp(prefix);
7072: if ((x.length != undefined) && (x.length > 0)) {
7073: if (form.elements[radio].length != undefined) {
7074: for (var i=0; i<form.elements[radio].length; i++) {
7075: if (form.elements[radio][i].checked) {
7076: if (form.elements[radio][i].value == 1) {
7077: for (var j=0; j<x.length; j++) {
7078: if (x[j].id == 'undefined') {
7079: x[j].style.display = 'table-row';
7080: } else if (insttypeRegExp.test(x[j].id)) {
7081: insttypes ++;
7082: } else {
7083: x[j].style.display = 'table-row';
7084: }
7085: }
7086: } else {
7087: for (var j=0; j<x.length; j++) {
7088: x[j].style.display = 'none';
7089: }
7090: }
7091: break;
7092: }
7093: }
7094: if (insttypes > 0) {
7095: toggleDataRow(form,checkbox,target,altprefix);
7096: toggleDataRow(form,checkbox,target,prefix,1);
7097: }
7098: }
7099: }
7100: return;
7101: }
7102:
7103: function toggleDataRow(form,checkbox,target,prefix,docount) {
7104: if (form.elements[checkbox].length != undefined) {
7105: var count = 0;
7106: if (docount) {
7107: for (var i=0; i<form.elements[checkbox].length; i++) {
7108: if (form.elements[checkbox][i].checked) {
7109: count ++;
7110: }
7111: }
7112: }
7113: for (var i=0; i<form.elements[checkbox].length; i++) {
7114: var type = form.elements[checkbox][i].value;
7115: if (document.getElementById(prefix+type)) {
7116: if (form.elements[checkbox][i].checked) {
7117: document.getElementById(prefix+type).style.display = 'table-row';
7118: if (count % 2 == 1) {
7119: document.getElementById(prefix+type).className = target+' LC_odd_row';
7120: } else {
7121: document.getElementById(prefix+type).className = target;
7122: }
7123: count ++;
7124: } else {
7125: document.getElementById(prefix+type).style.display = 'none';
7126: }
7127: }
7128: }
7129: }
7130: return;
7131: }
7132:
7133: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7134: var caller = radio+'_'+status;
7135: if (form.elements[caller].length != undefined) {
7136: for (var i=0; i<form.elements[caller].length; i++) {
7137: if (form.elements[caller][i].checked) {
7138: if (document.getElementById(altprefix+'_inst_'+status)) {
7139: var curr = form.elements[caller][i].value;
7140: if (prefix) {
7141: document.getElementById(prefix+'_'+status).style.display = 'none';
7142: }
7143: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7144: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7145: if (curr == 'custom') {
7146: if (prefix) {
7147: document.getElementById(prefix+'_'+status).style.display = 'inline';
7148: }
7149: } else if (curr == 'inst') {
7150: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7151: } else if (curr == 'noninst') {
7152: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
7153: }
7154: break;
7155: }
7156: }
7157: }
7158: }
7159: }
7160:
7161: // ]]>
7162: </script>
7163:
7164: ENDSCRIPT
7165: }
7166:
7167: sub noninst_users {
7168: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7169: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7170: my $class = 'LC_left_item';
7171: if ($css_class) {
7172: $css_class = ' class="'.$css_class.'"';
7173: }
7174: if ($rowid) {
7175: $rowid = ' id="'.$rowid.'"';
7176: }
7177: if ($rowstyle) {
7178: $rowstyle = ' style="'.$rowstyle.'"';
7179: }
7180: my ($output,$description);
7181: if ($type eq 'default') {
7182: $description = &mt('Requests for: [_1]',$typetitle);
7183: } else {
7184: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7185: }
7186: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7187: "<td>$description</td>\n".
7188: '<td class="'.$class.'" colspan="2">'.
7189: '<table><tr>';
7190: my %headers = &Apache::lonlocal::texthash(
7191: approve => 'Processing',
7192: email => 'E-mail',
7193: username => 'Username',
7194: );
7195: foreach my $item ('approve','email','username') {
7196: $output .= '<th>'.$headers{$item}.'</th>';
7197: }
7198: $output .= '</tr><tr>';
7199: foreach my $item ('approve','email','username') {
7200: $output .= '<td valign="top">';
7201: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7202: if ($item eq 'approve') {
7203: %choices = &Apache::lonlocal::texthash (
7204: automatic => 'Automatically approved',
7205: approval => 'Queued for approval',
7206: );
7207: @options = ('automatic','approval');
7208: $hashref = $processing;
7209: $defoption = 'automatic';
7210: $name = 'cancreate_emailprocess_'.$type;
7211: } elsif ($item eq 'email') {
7212: %choices = &Apache::lonlocal::texthash (
7213: any => 'Any e-mail',
7214: inst => 'Institutional only',
7215: noninst => 'Non-institutional only',
7216: custom => 'Custom restrictions',
7217: );
7218: @options = ('any','inst','noninst');
7219: my $showcustom;
7220: if (ref($emailrules) eq 'HASH') {
7221: if (keys(%{$emailrules}) > 0) {
7222: push(@options,'custom');
7223: $showcustom = 'cancreate_emailrule';
7224: if (ref($settings) eq 'HASH') {
7225: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7226: foreach my $rule (@{$settings->{'email_rule'}}) {
7227: if (exists($emailrules->{$rule})) {
7228: $hascustom ++;
7229: }
7230: }
7231: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7232: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7233: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7234: if (exists($emailrules->{$rule})) {
7235: $hascustom ++;
7236: }
7237: }
7238: }
7239: }
7240: }
7241: }
7242: }
7243: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7244: "'cancreate_emaildomain','$type'".');"';
7245: $hashref = $emailoptions;
7246: $defoption = 'any';
7247: $name = 'cancreate_emailoptions_'.$type;
7248: } elsif ($item eq 'username') {
7249: %choices = &Apache::lonlocal::texthash (
7250: all => 'Same as e-mail',
7251: first => 'Omit @domain',
7252: free => 'Free to choose',
7253: );
7254: @options = ('all','first','free');
7255: $hashref = $emailverified;
7256: $defoption = 'all';
7257: $name = 'cancreate_usernameoptions_'.$type;
7258: }
7259: foreach my $option (@options) {
7260: my $checked;
7261: if (ref($hashref) eq 'HASH') {
7262: if ($type eq '') {
7263: if (!exists($hashref->{'default'})) {
7264: if ($option eq $defoption) {
7265: $checked = ' checked="checked"';
7266: }
7267: } else {
7268: if ($hashref->{'default'} eq $option) {
7269: $checked = ' checked="checked"';
7270: }
7271: }
7272: } else {
7273: if (!exists($hashref->{$type})) {
7274: if ($option eq $defoption) {
7275: $checked = ' checked="checked"';
7276: }
7277: } else {
7278: if ($hashref->{$type} eq $option) {
7279: $checked = ' checked="checked"';
7280: }
7281: }
7282: }
7283: } elsif (($item eq 'email') && ($hascustom)) {
7284: if ($option eq 'custom') {
7285: $checked = ' checked="checked"';
7286: }
7287: } elsif ($option eq $defoption) {
7288: $checked = ' checked="checked"';
7289: }
7290: $output .= '<span class="LC_nobreak"><label>'.
7291: '<input type="radio" name="'.$name.'"'.
7292: $checked.' value="'.$option.'"'.$onclick.' />'.
7293: $choices{$option}.'</label></span><br />';
7294: if ($item eq 'email') {
7295: if ($option eq 'custom') {
7296: my $id = 'cancreate_emailrule_'.$type;
7297: my $display = 'none';
7298: if ($checked) {
7299: $display = 'inline';
7300: }
7301: my $numinrow = 2;
7302: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7303: '<legend>'.&mt('Disallow').'</legend><table>'.
7304: &user_formats_row('email',$settings,$emailrules,
7305: $emailruleorder,$numinrow,'',$type);
7306: '</table></fieldset>';
7307: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7308: my %text = &Apache::lonlocal::texthash (
7309: inst => 'must end:',
7310: noninst => 'cannot end:',
7311: );
7312: my $value;
7313: if (ref($emaildomain) eq 'HASH') {
7314: if (ref($emaildomain->{$type}) eq 'HASH') {
7315: $value = $emaildomain->{$type}->{$option};
7316: }
7317: }
7318: if ($value eq '') {
7319: $value = '@'.$intdom;
7320: }
7321: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7322: my $display = 'none';
7323: if ($checked) {
7324: $display = 'inline';
7325: }
7326: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7327: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7328: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7329: '</div>';
7330: }
7331: }
7332: }
7333: $output .= '</td>'."\n";
7334: }
7335: $output .= "</tr></table></td></tr>\n";
7336: return $output;
7337: }
7338:
7339: sub captcha_choice {
7340: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
7341: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7342: $vertext,$currver);
7343: my %lt = &captcha_phrases();
7344: $keyentry = 'hidden';
7345: my $colspan=2;
7346: if ($context eq 'cancreate') {
7347: $rowname = &mt('CAPTCHA validation');
7348: } elsif ($context eq 'login') {
7349: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
7350: } elsif ($context eq 'passwords') {
7351: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7352: $colspan=1;
7353: }
7354: if (ref($settings) eq 'HASH') {
7355: if ($settings->{'captcha'}) {
7356: $checked{$settings->{'captcha'}} = ' checked="checked"';
7357: } else {
7358: $checked{'original'} = ' checked="checked"';
7359: }
7360: if ($settings->{'captcha'} eq 'recaptcha') {
7361: $pubtext = $lt{'pub'};
7362: $privtext = $lt{'priv'};
7363: $keyentry = 'text';
7364: $vertext = $lt{'ver'};
7365: $currver = $settings->{'recaptchaversion'};
7366: if ($currver ne '2') {
7367: $currver = 1;
7368: }
7369: }
7370: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7371: $currpub = $settings->{'recaptchakeys'}{'public'};
7372: $currpriv = $settings->{'recaptchakeys'}{'private'};
7373: }
7374: } else {
7375: $checked{'original'} = ' checked="checked"';
7376: }
7377: my $css_class;
7378: if ($itemcount%2) {
7379: $css_class = 'LC_odd_row';
7380: }
7381: if ($customcss) {
7382: $css_class .= " $customcss";
7383: }
7384: $css_class =~ s/^\s+//;
7385: if ($css_class) {
7386: $css_class = ' class="'.$css_class.'"';
7387: }
7388: if ($rowstyle) {
7389: $css_class .= ' style="'.$rowstyle.'"';
7390: }
7391: my $output = '<tr'.$css_class.'>'.
7392: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
7393: '<table><tr><td>'."\n";
7394: foreach my $option ('original','recaptcha','notused') {
7395: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7396: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7397: $lt{$option}.'</label></span>';
7398: unless ($option eq 'notused') {
7399: $output .= (' 'x2)."\n";
7400: }
7401: }
7402: #
7403: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7404: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
7405: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
7406: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
7407: #
7408: $output .= '</td></tr>'."\n".
7409: '<tr><td class="LC_zero_height">'."\n".
7410: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7411: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7412: $currpub.'" size="40" /></span><br />'."\n".
7413: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7414: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
7415: $currpriv.'" size="40" /></span><br />'.
7416: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7417: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7418: $currver.'" size="3" /></span><br />'.
7419: '</td></tr></table>'."\n".
7420: '</td></tr>';
7421: return $output;
7422: }
7423:
7424: sub user_formats_row {
7425: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
7426: my $output;
7427: my %text = (
7428: 'username' => 'new usernames',
7429: 'id' => 'IDs',
7430: );
7431: unless (($type eq 'email') || ($type eq 'unamemap')) {
7432: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7433: $output = '<tr '.$css_class.'>'.
7434: '<td><span class="LC_nobreak">'.
7435: &mt("Format rules to check for $text{$type}: ").
7436: '</td><td class="LC_left_item" colspan="2"><table>';
7437: }
7438: my $rem;
7439: if (ref($ruleorder) eq 'ARRAY') {
7440: for (my $i=0; $i<@{$ruleorder}; $i++) {
7441: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7442: my $rem = $i%($numinrow);
7443: if ($rem == 0) {
7444: if ($i > 0) {
7445: $output .= '</tr>';
7446: }
7447: $output .= '<tr>';
7448: }
7449: my $check = ' ';
7450: if (ref($settings) eq 'HASH') {
7451: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7452: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7453: $check = ' checked="checked" ';
7454: }
7455: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7456: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7457: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7458: $check = ' checked="checked" ';
7459: }
7460: }
7461: }
7462: }
7463: my $name = $type.'_rule';
7464: if ($type eq 'email') {
7465: $name .= '_'.$status;
7466: }
7467: $output .= '<td class="LC_left_item">'.
7468: '<span class="LC_nobreak"><label>'.
7469: '<input type="checkbox" name="'.$name.'" '.
7470: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7471: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7472: }
7473: }
7474: $rem = @{$ruleorder}%($numinrow);
7475: }
7476: my $colsleft;
7477: if ($rem) {
7478: $colsleft = $numinrow - $rem;
7479: }
7480: if ($colsleft > 1 ) {
7481: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7482: ' </td>';
7483: } elsif ($colsleft == 1) {
7484: $output .= '<td class="LC_left_item"> </td>';
7485: }
7486: $output .= '</tr>';
7487: unless (($type eq 'email') || ($type eq 'unamemap')) {
7488: $output .= '</table></td></tr>';
7489: }
7490: return $output;
7491: }
7492:
7493: sub usercreation_types {
7494: my %lt = &Apache::lonlocal::texthash (
7495: author => 'When adding a co-author',
7496: course => 'When adding a user to a course',
7497: requestcrs => 'When requesting a course',
7498: any => 'Any',
7499: official => 'Institutional only ',
7500: unofficial => 'Non-institutional only',
7501: none => 'None',
7502: );
7503: return %lt;
7504: }
7505:
7506: sub selfcreation_types {
7507: my %lt = &Apache::lonlocal::texthash (
7508: selfcreate => 'User creates own account',
7509: any => 'Any',
7510: official => 'Institutional only ',
7511: unofficial => 'Non-institutional only',
7512: email => 'E-mail address',
7513: login => 'Institutional Login',
7514: sso => 'SSO',
7515: );
7516: }
7517:
7518: sub authtype_names {
7519: my %lt = &Apache::lonlocal::texthash(
7520: int => 'Internal',
7521: krb4 => 'Kerberos 4',
7522: krb5 => 'Kerberos 5',
7523: loc => 'Local',
7524: );
7525: return %lt;
7526: }
7527:
7528: sub context_names {
7529: my %context_title = &Apache::lonlocal::texthash(
7530: author => 'Creating users when an Author',
7531: course => 'Creating users when in a course',
7532: domain => 'Creating users when a Domain Coordinator',
7533: );
7534: return %context_title;
7535: }
7536:
7537: sub print_usermodification {
7538: my ($position,$dom,$settings,$rowtotal) = @_;
7539: my $numinrow = 4;
7540: my ($context,$datatable,$rowcount);
7541: if ($position eq 'top') {
7542: $rowcount = 0;
7543: $context = 'author';
7544: foreach my $role ('ca','aa') {
7545: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7546: $numinrow,$rowcount);
7547: $$rowtotal ++;
7548: $rowcount ++;
7549: }
7550: } elsif ($position eq 'bottom') {
7551: $context = 'course';
7552: $rowcount = 0;
7553: foreach my $role ('st','ep','ta','in','cr') {
7554: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7555: $numinrow,$rowcount);
7556: $$rowtotal ++;
7557: $rowcount ++;
7558: }
7559: }
7560: return $datatable;
7561: }
7562:
7563: sub print_defaults {
7564: my ($position,$dom,$settings,$rowtotal) = @_;
7565: my $rownum = 0;
7566: my ($datatable,$css_class,$titles);
7567: unless ($position eq 'bottom') {
7568: $titles = &defaults_titles($dom);
7569: }
7570: if ($position eq 'top') {
7571: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7572: 'datelocale_def','portal_def');
7573: my %defaults;
7574: if (ref($settings) eq 'HASH') {
7575: %defaults = %{$settings};
7576: } else {
7577: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7578: foreach my $item (@items) {
7579: $defaults{$item} = $domdefaults{$item};
7580: }
7581: }
7582: foreach my $item (@items) {
7583: if ($rownum%2) {
7584: $css_class = '';
7585: } else {
7586: $css_class = ' class="LC_odd_row" ';
7587: }
7588: $datatable .= '<tr'.$css_class.'>'.
7589: '<td><span class="LC_nobreak">'.$titles->{$item}.
7590: '</span></td><td class="LC_right_item" colspan="3">';
7591: if ($item eq 'auth_def') {
7592: my @authtypes = ('internal','krb4','krb5','localauth');
7593: my %shortauth = (
7594: internal => 'int',
7595: krb4 => 'krb4',
7596: krb5 => 'krb5',
7597: localauth => 'loc'
7598: );
7599: my %authnames = &authtype_names();
7600: foreach my $auth (@authtypes) {
7601: my $checked = ' ';
7602: if ($defaults{$item} eq $auth) {
7603: $checked = ' checked="checked" ';
7604: }
7605: $datatable .= '<label><input type="radio" name="'.$item.
7606: '" value="'.$auth.'"'.$checked.'/>'.
7607: $authnames{$shortauth{$auth}}.'</label> ';
7608: }
7609: } elsif ($item eq 'timezone_def') {
7610: my $includeempty = 1;
7611: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7612: } elsif ($item eq 'datelocale_def') {
7613: my $includeempty = 1;
7614: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7615: } elsif ($item eq 'lang_def') {
7616: my $includeempty = 1;
7617: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
7618: } else {
7619: my $size;
7620: if ($item eq 'portal_def') {
7621: $size = ' size="25"';
7622: }
7623: $datatable .= '<input type="text" name="'.$item.'" value="'.
7624: $defaults{$item}.'"'.$size.' />';
7625: }
7626: $datatable .= '</td></tr>';
7627: $rownum ++;
7628: }
7629: } elsif ($position eq 'middle') {
7630: my %defaults;
7631: if (ref($settings) eq 'HASH') {
7632: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7633: my $maxnum = @{$settings->{'inststatusorder'}};
7634: for (my $i=0; $i<$maxnum; $i++) {
7635: $css_class = $rownum%2?' class="LC_odd_row"':'';
7636: my $item = $settings->{'inststatusorder'}->[$i];
7637: my $title = $settings->{'inststatustypes'}->{$item};
7638: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7639: $datatable .= '<tr'.$css_class.'>'.
7640: '<td><span class="LC_nobreak">'.
7641: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7642: for (my $k=0; $k<=$maxnum; $k++) {
7643: my $vpos = $k+1;
7644: my $selstr;
7645: if ($k == $i) {
7646: $selstr = ' selected="selected" ';
7647: }
7648: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7649: }
7650: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7651: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7652: &mt('delete').'</span></td>'.
7653: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
7654: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
7655: '</span></td></tr>';
7656: }
7657: $css_class = $rownum%2?' class="LC_odd_row"':'';
7658: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7659: $datatable .= '<tr '.$css_class.'>'.
7660: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7661: for (my $k=0; $k<=$maxnum; $k++) {
7662: my $vpos = $k+1;
7663: my $selstr;
7664: if ($k == $maxnum) {
7665: $selstr = ' selected="selected" ';
7666: }
7667: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7668: }
7669: $datatable .= '</select> '.&mt('Internal ID:').
7670: '<input type="text" size="10" name="addinststatus" value="" />'.
7671: ' '.&mt('(new)').
7672: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
7673: &mt('Name displayed').':'.
7674: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7675: '</tr>'."\n";
7676: $rownum ++;
7677: }
7678: }
7679: } else {
7680: my ($unamemaprules,$ruleorder) =
7681: &Apache::lonnet::inst_userrules($dom,'unamemap');
7682: $css_class = $rownum%2?' class="LC_odd_row"':'';
7683: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7684: my $numinrow = 2;
7685: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
7686: &user_formats_row('unamemap',$settings,$unamemaprules,
7687: $ruleorder,$numinrow).
7688: '</table></td></tr>';
7689: }
7690: if ($datatable eq '') {
7691: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
7692: &mt('No rules set for domain in customized localenroll.pm').
7693: '</td></tr>';
7694: }
7695: }
7696: $$rowtotal += $rownum;
7697: return $datatable;
7698: }
7699:
7700: sub get_languages_hash {
7701: my %langchoices;
7702: foreach my $id (&Apache::loncommon::languageids()) {
7703: my $code = &Apache::loncommon::supportedlanguagecode($id);
7704: if ($code ne '') {
7705: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7706: }
7707: }
7708: return %langchoices;
7709: }
7710:
7711: sub defaults_titles {
7712: my ($dom) = @_;
7713: my %titles = &Apache::lonlocal::texthash (
7714: 'auth_def' => 'Default authentication type',
7715: 'auth_arg_def' => 'Default authentication argument',
7716: 'lang_def' => 'Default language',
7717: 'timezone_def' => 'Default timezone',
7718: 'datelocale_def' => 'Default locale for dates',
7719: 'portal_def' => 'Portal/Default URL',
7720: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7721: 'intauth_check' => 'Check bcrypt cost if authenticated',
7722: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
7723: );
7724: if ($dom) {
7725: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7726: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7727: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7728: $protocol = 'http' if ($protocol ne 'https');
7729: if ($uint_dom) {
7730: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7731: $uint_dom);
7732: }
7733: }
7734: return (\%titles);
7735: }
7736:
7737: sub print_scantron {
7738: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7739: if ($position eq 'top') {
7740: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7741: } else {
7742: return &print_scantronconfig($dom,$settings,\$rowtotal);
7743: }
7744: }
7745:
7746: sub scantron_javascript {
7747: return <<"ENDSCRIPT";
7748:
7749: <script type="text/javascript">
7750: // <![CDATA[
7751:
7752: function toggleScantron(form) {
7753: var csvfieldset = new Array();
7754: if (document.getElementById('scantroncsv_cols')) {
7755: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7756: }
7757: if (document.getElementById('scantroncsv_options')) {
7758: csvfieldset.push(document.getElementById('scantroncsv_options'));
7759: }
7760: if (csvfieldset.length) {
7761: if (document.getElementById('scantronconfcsv')) {
7762: var scantroncsv = document.getElementById('scantronconfcsv');
7763: if (scantroncsv.checked) {
7764: for (var i=0; i<csvfieldset.length; i++) {
7765: csvfieldset[i].style.display = 'block';
7766: }
7767: } else {
7768: for (var i=0; i<csvfieldset.length; i++) {
7769: csvfieldset[i].style.display = 'none';
7770: }
7771: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7772: if (csvselects.length) {
7773: for (var j=0; j<csvselects.length; j++) {
7774: csvselects[j].selectedIndex = 0;
7775: }
7776: }
7777: }
7778: }
7779: }
7780: return;
7781: }
7782: // ]]>
7783: </script>
7784:
7785: ENDSCRIPT
7786:
7787: }
7788:
7789: sub print_scantronformat {
7790: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7791: my $itemcount = 1;
7792: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7793: %confhash);
7794: my $switchserver = &check_switchserver($dom,$confname);
7795: my %lt = &Apache::lonlocal::texthash (
7796: default => 'Default bubblesheet format file error',
7797: custom => 'Custom bubblesheet format file error',
7798: );
7799: my %scantronfiles = (
7800: default => 'default.tab',
7801: custom => 'custom.tab',
7802: );
7803: foreach my $key (keys(%scantronfiles)) {
7804: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7805: .$scantronfiles{$key};
7806: }
7807: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7808: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7809: if (!$switchserver) {
7810: my $servadm = $r->dir_config('lonAdmEMail');
7811: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7812: if ($configuserok eq 'ok') {
7813: if ($author_ok eq 'ok') {
7814: my %legacyfile = (
7815: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7816: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7817: );
7818: my %md5chk;
7819: foreach my $type (keys(%legacyfile)) {
7820: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7821: chomp($md5chk{$type});
7822: }
7823: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7824: foreach my $type (keys(%legacyfile)) {
7825: ($scantronurls{$type},my $error) =
7826: &legacy_scantronformat($r,$dom,$confname,
7827: $type,$legacyfile{$type},
7828: $scantronurls{$type},
7829: $scantronfiles{$type});
7830: if ($error ne '') {
7831: $error{$type} = $error;
7832: }
7833: }
7834: if (keys(%error) == 0) {
7835: $is_custom = 1;
7836: $confhash{'scantron'}{'scantronformat'} =
7837: $scantronurls{'custom'};
7838: my $putresult =
7839: &Apache::lonnet::put_dom('configuration',
7840: \%confhash,$dom);
7841: if ($putresult ne 'ok') {
7842: $error{'custom'} =
7843: '<span class="LC_error">'.
7844: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7845: }
7846: }
7847: } else {
7848: ($scantronurls{'default'},my $error) =
7849: &legacy_scantronformat($r,$dom,$confname,
7850: 'default',$legacyfile{'default'},
7851: $scantronurls{'default'},
7852: $scantronfiles{'default'});
7853: if ($error eq '') {
7854: $confhash{'scantron'}{'scantronformat'} = '';
7855: my $putresult =
7856: &Apache::lonnet::put_dom('configuration',
7857: \%confhash,$dom);
7858: if ($putresult ne 'ok') {
7859: $error{'default'} =
7860: '<span class="LC_error">'.
7861: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7862: }
7863: } else {
7864: $error{'default'} = $error;
7865: }
7866: }
7867: }
7868: }
7869: } else {
7870: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
7871: }
7872: }
7873: if (ref($settings) eq 'HASH') {
7874: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7875: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7876: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7877: $scantronurl = '';
7878: } else {
7879: $scantronurl = $settings->{'scantronformat'};
7880: }
7881: $is_custom = 1;
7882: } else {
7883: $scantronurl = $scantronurls{'default'};
7884: }
7885: } else {
7886: if ($is_custom) {
7887: $scantronurl = $scantronurls{'custom'};
7888: } else {
7889: $scantronurl = $scantronurls{'default'};
7890: }
7891: }
7892: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7893: $datatable .= '<tr'.$css_class.'>';
7894: if (!$is_custom) {
7895: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7896: '<span class="LC_nobreak">';
7897: if ($scantronurl) {
7898: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7899: undef,undef,undef,undef,'background-color:#ffffff');
7900: } else {
7901: $datatable = &mt('File unavailable for display');
7902: }
7903: $datatable .= '</span></td>';
7904: if (keys(%error) == 0) {
7905: $datatable .= '<td valign="bottom">';
7906: if (!$switchserver) {
7907: $datatable .= &mt('Upload:').'<br />';
7908: }
7909: } else {
7910: my $errorstr;
7911: foreach my $key (sort(keys(%error))) {
7912: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7913: }
7914: $datatable .= '<td>'.$errorstr;
7915: }
7916: } else {
7917: if (keys(%error) > 0) {
7918: my $errorstr;
7919: foreach my $key (sort(keys(%error))) {
7920: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7921: }
7922: $datatable .= '<td>'.$errorstr.'</td><td> ';
7923: } elsif ($scantronurl) {
7924: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7925: undef,undef,undef,undef,'background-color:#ffffff');
7926: $datatable .= '<td><span class="LC_nobreak">'.
7927: $link.
7928: '<label><input type="checkbox" name="scantronformat_del"'.
7929: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
7930: '<td><span class="LC_nobreak"> '.
7931: &mt('Replace:').'</span><br />';
7932: }
7933: }
7934: if (keys(%error) == 0) {
7935: if ($switchserver) {
7936: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7937: } else {
7938: $datatable .='<span class="LC_nobreak"> '.
7939: '<input type="file" name="scantronformat" /></span>';
7940: }
7941: }
7942: $datatable .= '</td></tr>';
7943: $$rowtotal ++;
7944: return $datatable;
7945: }
7946:
7947: sub legacy_scantronformat {
7948: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7949: my ($url,$error);
7950: my @statinfo = &Apache::lonnet::stat_file($newurl);
7951: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7952: (my $result,$url) =
7953: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7954: '','',$newfile);
7955: if ($result ne 'ok') {
7956: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
7957: }
7958: }
7959: return ($url,$error);
7960: }
7961:
7962: sub print_scantronconfig {
7963: my ($dom,$settings,$rowtotal) = @_;
7964: my $itemcount = 2;
7965: my $is_checked = ' checked="checked"';
7966: my %optionson = (
7967: hdr => ' checked="checked"',
7968: pad => ' checked="checked"',
7969: rem => ' checked="checked"',
7970: );
7971: my %optionsoff = (
7972: hdr => '',
7973: pad => '',
7974: rem => '',
7975: );
7976: my $currcsvsty = 'none';
7977: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7978: my @fields = &scantroncsv_fields();
7979: my %titles = &scantronconfig_titles();
7980: if (ref($settings) eq 'HASH') {
7981: if (ref($settings->{config}) eq 'HASH') {
7982: if ($settings->{config}->{dat}) {
7983: $checked{'dat'} = $is_checked;
7984: }
7985: if (ref($settings->{config}->{csv}) eq 'HASH') {
7986: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7987: %csvfields = %{$settings->{config}->{csv}->{fields}};
7988: if (keys(%csvfields) > 0) {
7989: $checked{'csv'} = $is_checked;
7990: $currcsvsty = 'block';
7991: }
7992: }
7993: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7994: %csvoptions = %{$settings->{config}->{csv}->{options}};
7995: foreach my $option (keys(%optionson)) {
7996: unless ($csvoptions{$option}) {
7997: $optionsoff{$option} = $optionson{$option};
7998: $optionson{$option} = '';
7999: }
8000: }
8001: }
8002: }
8003: } else {
8004: $checked{'dat'} = $is_checked;
8005: }
8006: } else {
8007: $checked{'dat'} = $is_checked;
8008: }
8009: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8010: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8011: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8012: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8013: foreach my $item ('dat','csv') {
8014: my $id;
8015: if ($item eq 'csv') {
8016: $id = 'id="scantronconfcsv" ';
8017: }
8018: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8019: $titles{$item}.'</label>'.(' 'x3);
8020: if ($item eq 'csv') {
8021: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8022: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8023: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8024: foreach my $col (@fields) {
8025: my $selnone;
8026: if ($csvfields{$col} eq '') {
8027: $selnone = ' selected="selected"';
8028: }
8029: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8030: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8031: '<option value=""'.$selnone.'></option>';
8032: for (my $i=0; $i<20; $i++) {
8033: my $shown = $i+1;
8034: my $sel;
8035: unless ($selnone) {
8036: if (exists($csvfields{$col})) {
8037: if ($csvfields{$col} == $i) {
8038: $sel = ' selected="selected"';
8039: }
8040: }
8041: }
8042: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8043: }
8044: $datatable .= '</select></td></tr>';
8045: }
8046: $datatable .= '</table></fieldset>'.
8047: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8048: '<legend>'.&mt('CSV Options').'</legend>';
8049: foreach my $option ('hdr','pad','rem') {
8050: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8051: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8052: &mt('Yes').'</label>'.(' 'x2)."\n".
8053: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8054: }
8055: $datatable .= '</fieldset>';
8056: $itemcount ++;
8057: }
8058: }
8059: $datatable .= '</td></tr>';
8060: $$rowtotal ++;
8061: return $datatable;
8062: }
8063:
8064: sub scantronconfig_titles {
8065: return &Apache::lonlocal::texthash(
8066: dat => 'Standard format (.dat)',
8067: csv => 'Comma separated values (.csv)',
8068: hdr => 'Remove first line in file (contains column titles)',
8069: pad => 'Prepend 0s to PaperID',
8070: rem => 'Remove leading spaces (except Question Response columns)',
8071: CODE => 'CODE',
8072: ID => 'Student ID',
8073: PaperID => 'Paper ID',
8074: FirstName => 'First Name',
8075: LastName => 'Last Name',
8076: FirstQuestion => 'First Question Response',
8077: Section => 'Section',
8078: );
8079: }
8080:
8081: sub scantroncsv_fields {
8082: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8083: }
8084:
8085: sub print_coursecategories {
8086: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8087: my $datatable;
8088: if ($position eq 'top') {
8089: my (%checked);
8090: my @catitems = ('unauth','auth');
8091: my @cattypes = ('std','domonly','codesrch','none');
8092: $checked{'unauth'} = 'std';
8093: $checked{'auth'} = 'std';
8094: if (ref($settings) eq 'HASH') {
8095: foreach my $type (@cattypes) {
8096: if ($type eq $settings->{'unauth'}) {
8097: $checked{'unauth'} = $type;
8098: }
8099: if ($type eq $settings->{'auth'}) {
8100: $checked{'auth'} = $type;
8101: }
8102: }
8103: }
8104: my %lt = &Apache::lonlocal::texthash (
8105: unauth => 'Catalog type for unauthenticated users',
8106: auth => 'Catalog type for authenticated users',
8107: none => 'No catalog',
8108: std => 'Standard catalog',
8109: domonly => 'Domain-only catalog',
8110: codesrch => "Code search form",
8111: );
8112: my $itemcount = 0;
8113: foreach my $item (@catitems) {
8114: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8115: $datatable .= '<tr '.$css_class.'>'.
8116: '<td>'.$lt{$item}.'</td>'.
8117: '<td class="LC_right_item"><span class="LC_nobreak">';
8118: foreach my $type (@cattypes) {
8119: my $ischecked;
8120: if ($checked{$item} eq $type) {
8121: $ischecked=' checked="checked"';
8122: }
8123: $datatable .= '<label>'.
8124: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8125: ' />'.$lt{$type}.'</label> ';
8126: }
8127: $datatable .= '</span></td></tr>';
8128: $itemcount ++;
8129: }
8130: $$rowtotal += $itemcount;
8131: } elsif ($position eq 'middle') {
8132: my $toggle_cats_crs = ' ';
8133: my $toggle_cats_dom = ' checked="checked" ';
8134: my $can_cat_crs = ' ';
8135: my $can_cat_dom = ' checked="checked" ';
8136: my $toggle_catscomm_comm = ' ';
8137: my $toggle_catscomm_dom = ' checked="checked" ';
8138: my $can_catcomm_comm = ' ';
8139: my $can_catcomm_dom = ' checked="checked" ';
8140:
8141: if (ref($settings) eq 'HASH') {
8142: if ($settings->{'togglecats'} eq 'crs') {
8143: $toggle_cats_crs = $toggle_cats_dom;
8144: $toggle_cats_dom = ' ';
8145: }
8146: if ($settings->{'categorize'} eq 'crs') {
8147: $can_cat_crs = $can_cat_dom;
8148: $can_cat_dom = ' ';
8149: }
8150: if ($settings->{'togglecatscomm'} eq 'comm') {
8151: $toggle_catscomm_comm = $toggle_catscomm_dom;
8152: $toggle_catscomm_dom = ' ';
8153: }
8154: if ($settings->{'categorizecomm'} eq 'comm') {
8155: $can_catcomm_comm = $can_catcomm_dom;
8156: $can_catcomm_dom = ' ';
8157: }
8158: }
8159: my %title = &Apache::lonlocal::texthash (
8160: togglecats => 'Show/Hide a course in catalog',
8161: togglecatscomm => 'Show/Hide a community in catalog',
8162: categorize => 'Assign a category to a course',
8163: categorizecomm => 'Assign a category to a community',
8164: );
8165: my %level = &Apache::lonlocal::texthash (
8166: dom => 'Set in Domain',
8167: crs => 'Set in Course',
8168: comm => 'Set in Community',
8169: );
8170: $datatable = '<tr class="LC_odd_row">'.
8171: '<td>'.$title{'togglecats'}.'</td>'.
8172: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8173: '<input type="radio" name="togglecats"'.
8174: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8175: '<label><input type="radio" name="togglecats"'.
8176: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8177: '</tr><tr>'.
8178: '<td>'.$title{'categorize'}.'</td>'.
8179: '<td class="LC_right_item"><span class="LC_nobreak">'.
8180: '<label><input type="radio" name="categorize"'.
8181: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8182: '<label><input type="radio" name="categorize"'.
8183: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
8184: '</tr><tr class="LC_odd_row">'.
8185: '<td>'.$title{'togglecatscomm'}.'</td>'.
8186: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8187: '<input type="radio" name="togglecatscomm"'.
8188: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8189: '<label><input type="radio" name="togglecatscomm"'.
8190: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8191: '</tr><tr>'.
8192: '<td>'.$title{'categorizecomm'}.'</td>'.
8193: '<td class="LC_right_item"><span class="LC_nobreak">'.
8194: '<label><input type="radio" name="categorizecomm"'.
8195: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8196: '<label><input type="radio" name="categorizecomm"'.
8197: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
8198: '</tr>';
8199: $$rowtotal += 4;
8200: } else {
8201: my $css_class;
8202: my $itemcount = 1;
8203: my $cathash;
8204: if (ref($settings) eq 'HASH') {
8205: $cathash = $settings->{'cats'};
8206: }
8207: if (ref($cathash) eq 'HASH') {
8208: my (@cats,@trails,%allitems,%idx,@jsarray);
8209: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8210: \%allitems,\%idx,\@jsarray);
8211: my $maxdepth = scalar(@cats);
8212: my $colattrib = '';
8213: if ($maxdepth > 2) {
8214: $colattrib = ' colspan="2" ';
8215: }
8216: my @path;
8217: if (@cats > 0) {
8218: if (ref($cats[0]) eq 'ARRAY') {
8219: my $numtop = @{$cats[0]};
8220: my $maxnum = $numtop;
8221: my %default_names = (
8222: instcode => &mt('Official courses'),
8223: communities => &mt('Communities'),
8224: );
8225:
8226: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8227: ($cathash->{'instcode::0'} eq '') ||
8228: (!grep(/^communities$/,@{$cats[0]})) ||
8229: ($cathash->{'communities::0'} eq '')) {
8230: $maxnum ++;
8231: }
8232: my $lastidx;
8233: for (my $i=0; $i<$numtop; $i++) {
8234: my $parent = $cats[0][$i];
8235: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8236: my $item = &escape($parent).'::0';
8237: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8238: $lastidx = $idx{$item};
8239: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8240: .'<select name="'.$item.'"'.$chgstr.'>';
8241: for (my $k=0; $k<=$maxnum; $k++) {
8242: my $vpos = $k+1;
8243: my $selstr;
8244: if ($k == $i) {
8245: $selstr = ' selected="selected" ';
8246: }
8247: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8248: }
8249: $datatable .= '</select></span></td><td>';
8250: if ($parent eq 'instcode' || $parent eq 'communities') {
8251: $datatable .= '<span class="LC_nobreak">'
8252: .$default_names{$parent}.'</span>';
8253: if ($parent eq 'instcode') {
8254: $datatable .= '<br /><span class="LC_nobreak">('
8255: .&mt('with institutional codes')
8256: .')</span></td><td'.$colattrib.'>';
8257: } else {
8258: $datatable .= '<table><tr><td>';
8259: }
8260: $datatable .= '<span class="LC_nobreak">'
8261: .'<label><input type="radio" name="'
8262: .$parent.'" value="1" checked="checked" />'
8263: .&mt('Display').'</label>';
8264: if ($parent eq 'instcode') {
8265: $datatable .= ' ';
8266: } else {
8267: $datatable .= '</span></td></tr><tr><td>'
8268: .'<span class="LC_nobreak">';
8269: }
8270: $datatable .= '<label><input type="radio" name="'
8271: .$parent.'" value="0" />'
8272: .&mt('Do not display').'</label></span>';
8273: if ($parent eq 'communities') {
8274: $datatable .= '</td></tr></table>';
8275: }
8276: $datatable .= '</td>';
8277: } else {
8278: $datatable .= $parent
8279: .' <span class="LC_nobreak"><label>'
8280: .'<input type="checkbox" name="deletecategory" '
8281: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8282: }
8283: my $depth = 1;
8284: push(@path,$parent);
8285: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8286: pop(@path);
8287: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8288: $itemcount ++;
8289: }
8290: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8291: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8292: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
8293: for (my $k=0; $k<=$maxnum; $k++) {
8294: my $vpos = $k+1;
8295: my $selstr;
8296: if ($k == $numtop) {
8297: $selstr = ' selected="selected" ';
8298: }
8299: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8300: }
8301: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
8302: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8303: .'</tr>'."\n";
8304: $itemcount ++;
8305: foreach my $default ('instcode','communities') {
8306: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8307: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8308: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8309: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8310: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8311: for (my $k=0; $k<=$maxnum; $k++) {
8312: my $vpos = $k+1;
8313: my $selstr;
8314: if ($k == $maxnum) {
8315: $selstr = ' selected="selected" ';
8316: }
8317: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8318: }
8319: $datatable .= '</select></span></td>'.
8320: '<td><span class="LC_nobreak">'.
8321: $default_names{$default}.'</span>';
8322: if ($default eq 'instcode') {
8323: $datatable .= '<br /><span class="LC_nobreak">('
8324: .&mt('with institutional codes').')</span>';
8325: }
8326: $datatable .= '</td>'
8327: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8328: .&mt('Display').'</label> '
8329: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8330: .&mt('Do not display').'</label></span></td></tr>';
8331: }
8332: }
8333: }
8334: } else {
8335: $datatable .= &initialize_categories($itemcount);
8336: }
8337: } else {
8338: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
8339: .&initialize_categories($itemcount);
8340: }
8341: $$rowtotal += $itemcount;
8342: }
8343: return $datatable;
8344: }
8345:
8346: sub print_serverstatuses {
8347: my ($dom,$settings,$rowtotal) = @_;
8348: my $datatable;
8349: my @pages = &serverstatus_pages();
8350: my (%namedaccess,%machineaccess);
8351: foreach my $type (@pages) {
8352: $namedaccess{$type} = '';
8353: $machineaccess{$type}= '';
8354: }
8355: if (ref($settings) eq 'HASH') {
8356: foreach my $type (@pages) {
8357: if (exists($settings->{$type})) {
8358: if (ref($settings->{$type}) eq 'HASH') {
8359: foreach my $key (keys(%{$settings->{$type}})) {
8360: if ($key eq 'namedusers') {
8361: $namedaccess{$type} = $settings->{$type}->{$key};
8362: } elsif ($key eq 'machines') {
8363: $machineaccess{$type} = $settings->{$type}->{$key};
8364: }
8365: }
8366: }
8367: }
8368: }
8369: }
8370: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
8371: my $rownum = 0;
8372: my $css_class;
8373: foreach my $type (@pages) {
8374: $rownum ++;
8375: $css_class = $rownum%2?' class="LC_odd_row"':'';
8376: $datatable .= '<tr'.$css_class.'>'.
8377: '<td><span class="LC_nobreak">'.
8378: $titles->{$type}.'</span></td>'.
8379: '<td class="LC_left_item">'.
8380: '<input type="text" name="'.$type.'_namedusers" '.
8381: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8382: '<td class="LC_right_item">'.
8383: '<span class="LC_nobreak">'.
8384: '<input type="text" name="'.$type.'_machines" '.
8385: 'value="'.$machineaccess{$type}.'" size="10" />'.
8386: '</span></td></tr>'."\n";
8387: }
8388: $$rowtotal += $rownum;
8389: return $datatable;
8390: }
8391:
8392: sub serverstatus_pages {
8393: return ('userstatus','lonstatus','loncron','server-status','codeversions',
8394: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
8395: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
8396: 'uniquecodes','diskusage','coursecatalog');
8397: }
8398:
8399: sub defaults_javascript {
8400: my ($settings) = @_;
8401: return unless (ref($settings) eq 'HASH');
8402: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8403: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8404: if ($maxnum eq '') {
8405: $maxnum = 0;
8406: }
8407: $maxnum ++;
8408: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
8409: return <<"ENDSCRIPT";
8410: <script type="text/javascript">
8411: // <![CDATA[
8412: function reorderTypes(form,caller) {
8413: var changedVal;
8414: $jstext
8415: var newpos = 'addinststatus_pos';
8416: var current = new Array;
8417: var maxh = $maxnum;
8418: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8419: var oldVal;
8420: if (caller == newpos) {
8421: changedVal = newitemVal;
8422: } else {
8423: var curritem = 'inststatus_pos_'+caller;
8424: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8425: current[newitemVal] = newpos;
8426: }
8427: for (var i=0; i<inststatuses.length; i++) {
8428: if (inststatuses[i] != caller) {
8429: var elementName = 'inststatus_pos_'+inststatuses[i];
8430: if (form.elements[elementName]) {
8431: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8432: current[currVal] = elementName;
8433: }
8434: }
8435: }
8436: for (var j=0; j<maxh; j++) {
8437: if (current[j] == undefined) {
8438: oldVal = j;
8439: }
8440: }
8441: if (oldVal < changedVal) {
8442: for (var k=oldVal+1; k<=changedVal ; k++) {
8443: var elementName = current[k];
8444: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8445: }
8446: } else {
8447: for (var k=changedVal; k<oldVal; k++) {
8448: var elementName = current[k];
8449: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8450: }
8451: }
8452: return;
8453: }
8454:
8455: // ]]>
8456: </script>
8457:
8458: ENDSCRIPT
8459: }
8460: }
8461:
8462: sub passwords_javascript {
8463: my %intalert = &Apache::lonlocal::texthash (
8464: 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.',
8465: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
8466: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
8467: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
8468: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
8469: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
8470: );
8471: &js_escape(\%intalert);
8472: my $defmin = $Apache::lonnet::passwdmin;
8473: my $intauthjs = <<"ENDSCRIPT";
8474:
8475: function warnIntAuth(field) {
8476: if (field.name == 'intauth_check') {
8477: if (field.value == '2') {
8478: alert('$intalert{authcheck}');
8479: }
8480: }
8481: if (field.name == 'intauth_cost') {
8482: field.value.replace(/\s/g,'');
8483: if (field.value != '') {
8484: var regexdigit=/^\\d+\$/;
8485: if (!regexdigit.test(field.value)) {
8486: alert('$intalert{authcost}');
8487: }
8488: }
8489: }
8490: return;
8491: }
8492:
8493: function warnIntPass(field) {
8494: field.value.replace(/^\s+/,'');
8495: field.value.replace(/\s+\$/,'');
8496: var regexdigit=/^\\d+\$/;
8497: if (field.name == 'passwords_min') {
8498: if (field.value == '') {
8499: alert('$intalert{passmin}');
8500: field.value = '$defmin';
8501: } else {
8502: if (!regexdigit.test(field.value)) {
8503: alert('$intalert{passmin}');
8504: field.value = '$defmin';
8505: }
8506: var minval = parseInt(field.value,10);
8507: if (minval < $defmin) {
8508: alert('$intalert{passmin}');
8509: field.value = '$defmin';
8510: }
8511: }
8512: } else {
8513: if (field.value == '0') {
8514: field.value = '';
8515: }
8516: if (field.value != '') {
8517: if (field.name == 'passwords_expire') {
8518: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8519: if (!regexpposnum.test(field.value)) {
8520: alert('$intalert{passexp}');
8521: field.value = '';
8522: } else {
8523: var expval = parseFloat(field.value);
8524: if (expval == 0) {
8525: alert('$intalert{passexp}');
8526: field.value = '';
8527: }
8528: }
8529: } else {
8530: if (!regexdigit.test(field.value)) {
8531: if (field.name == 'passwords_max') {
8532: alert('$intalert{passmax}');
8533: } else {
8534: if (field.name == 'passwords_numsaved') {
8535: alert('$intalert{passnum}');
8536: }
8537: }
8538: field.value = '';
8539: }
8540: }
8541: }
8542: }
8543: return;
8544: }
8545:
8546: ENDSCRIPT
8547: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8548: }
8549:
8550: sub coursecategories_javascript {
8551: my ($settings) = @_;
8552: my ($output,$jstext,$cathash);
8553: if (ref($settings) eq 'HASH') {
8554: $cathash = $settings->{'cats'};
8555: }
8556: if (ref($cathash) eq 'HASH') {
8557: my (@cats,@jsarray,%idx);
8558: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
8559: if (@jsarray > 0) {
8560: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8561: for (my $i=0; $i<@jsarray; $i++) {
8562: if (ref($jsarray[$i]) eq 'ARRAY') {
8563: my $catstr = join('","',@{$jsarray[$i]});
8564: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8565: }
8566: }
8567: }
8568: } else {
8569: $jstext = ' var categories = Array(1);'."\n".
8570: ' categories[0] = Array("instcode_pos");'."\n";
8571: }
8572: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8573: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
8574: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8575: &js_escape(\$instcode_reserved);
8576: &js_escape(\$communities_reserved);
8577: &js_escape(\$choose_again);
8578: $output = <<"ENDSCRIPT";
8579: <script type="text/javascript">
8580: // <![CDATA[
8581: function reorderCats(form,parent,item,idx) {
8582: var changedVal;
8583: $jstext
8584: var newpos = 'addcategory_pos';
8585: if (parent == '') {
8586: var has_instcode = 0;
8587: var maxtop = categories[idx].length;
8588: for (var j=0; j<maxtop; j++) {
8589: if (categories[idx][j] == 'instcode::0') {
8590: has_instcode == 1;
8591: }
8592: }
8593: if (has_instcode == 0) {
8594: categories[idx][maxtop] = 'instcode_pos';
8595: }
8596: } else {
8597: newpos += '_'+parent;
8598: }
8599: var maxh = 1 + categories[idx].length;
8600: var current = new Array;
8601: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8602: if (item == newpos) {
8603: changedVal = newitemVal;
8604: } else {
8605: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8606: current[newitemVal] = newpos;
8607: }
8608: for (var i=0; i<categories[idx].length; i++) {
8609: var elementName = categories[idx][i];
8610: if (elementName != item) {
8611: if (form.elements[elementName]) {
8612: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8613: current[currVal] = elementName;
8614: }
8615: }
8616: }
8617: var oldVal;
8618: for (var j=0; j<maxh; j++) {
8619: if (current[j] == undefined) {
8620: oldVal = j;
8621: }
8622: }
8623: if (oldVal < changedVal) {
8624: for (var k=oldVal+1; k<=changedVal ; k++) {
8625: var elementName = current[k];
8626: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8627: }
8628: } else {
8629: for (var k=changedVal; k<oldVal; k++) {
8630: var elementName = current[k];
8631: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8632: }
8633: }
8634: return;
8635: }
8636:
8637: function categoryCheck(form) {
8638: if (form.elements['addcategory_name'].value == 'instcode') {
8639: alert('$instcode_reserved\\n$choose_again');
8640: return false;
8641: }
8642: if (form.elements['addcategory_name'].value == 'communities') {
8643: alert('$communities_reserved\\n$choose_again');
8644: return false;
8645: }
8646: return true;
8647: }
8648:
8649: // ]]>
8650: </script>
8651:
8652: ENDSCRIPT
8653: return $output;
8654: }
8655:
8656: sub initialize_categories {
8657: my ($itemcount) = @_;
8658: my ($datatable,$css_class,$chgstr);
8659: my %default_names = &Apache::lonlocal::texthash (
8660: instcode => 'Official courses (with institutional codes)',
8661: communities => 'Communities',
8662: );
8663: my $select0 = ' selected="selected"';
8664: my $select1 = '';
8665: foreach my $default ('instcode','communities') {
8666: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8667: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
8668: if ($default eq 'communities') {
8669: $select1 = $select0;
8670: $select0 = '';
8671: }
8672: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8673: .'<select name="'.$default.'_pos">'
8674: .'<option value="0"'.$select0.'>1</option>'
8675: .'<option value="1"'.$select1.'>2</option>'
8676: .'<option value="2">3</option></select> '
8677: .$default_names{$default}
8678: .'</span></td><td><span class="LC_nobreak">'
8679: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8680: .&mt('Display').'</label> <label>'
8681: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
8682: .'</label></span></td></tr>';
8683: $itemcount ++;
8684: }
8685: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8686: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
8687: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8688: .'<select name="addcategory_pos"'.$chgstr.'>'
8689: .'<option value="0">1</option>'
8690: .'<option value="1">2</option>'
8691: .'<option value="2" selected="selected">3</option></select> '
8692: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8693: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8694: .'</td></tr>';
8695: return $datatable;
8696: }
8697:
8698: sub build_category_rows {
8699: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8700: my ($text,$name,$item,$chgstr);
8701: if (ref($cats) eq 'ARRAY') {
8702: my $maxdepth = scalar(@{$cats});
8703: if (ref($cats->[$depth]) eq 'HASH') {
8704: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8705: my $numchildren = @{$cats->[$depth]{$parent}};
8706: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8707: $text .= '<td><table class="LC_data_table">';
8708: my ($idxnum,$parent_name,$parent_item);
8709: my $higher = $depth - 1;
8710: if ($higher == 0) {
8711: $parent_name = &escape($parent).'::'.$higher;
8712: } else {
8713: if (ref($path) eq 'ARRAY') {
8714: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8715: }
8716: }
8717: $parent_item = 'addcategory_pos_'.$parent_name;
8718: for (my $j=0; $j<=$numchildren; $j++) {
8719: if ($j < $numchildren) {
8720: $name = $cats->[$depth]{$parent}[$j];
8721: $item = &escape($name).':'.&escape($parent).':'.$depth;
8722: $idxnum = $idx->{$item};
8723: } else {
8724: $name = $parent_name;
8725: $item = $parent_item;
8726: }
8727: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8728: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
8729: for (my $i=0; $i<=$numchildren; $i++) {
8730: my $vpos = $i+1;
8731: my $selstr;
8732: if ($j == $i) {
8733: $selstr = ' selected="selected" ';
8734: }
8735: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8736: }
8737: $text .= '</select> ';
8738: if ($j < $numchildren) {
8739: my $deeper = $depth+1;
8740: $text .= $name.' '
8741: .'<label><input type="checkbox" name="deletecategory" value="'
8742: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8743: if(ref($path) eq 'ARRAY') {
8744: push(@{$path},$name);
8745: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
8746: pop(@{$path});
8747: }
8748: } else {
8749: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
8750: if ($j == $numchildren) {
8751: $text .= $name;
8752: } else {
8753: $text .= $item;
8754: }
8755: $text .= '" value="" />';
8756: }
8757: $text .= '</td></tr>';
8758: }
8759: $text .= '</table></td>';
8760: } else {
8761: my $higher = $depth-1;
8762: if ($higher == 0) {
8763: $name = &escape($parent).'::'.$higher;
8764: } else {
8765: if (ref($path) eq 'ARRAY') {
8766: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8767: }
8768: }
8769: my $colspan;
8770: if ($parent ne 'instcode') {
8771: $colspan = $maxdepth - $depth - 1;
8772: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
8773: }
8774: }
8775: }
8776: }
8777: return $text;
8778: }
8779:
8780: sub modifiable_userdata_row {
8781: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8782: $rowid,$customcss,$rowstyle) = @_;
8783: my ($role,$rolename,$statustype);
8784: $role = $item;
8785: if ($context eq 'cancreate') {
8786: if ($item =~ /^(emailusername)_(.+)$/) {
8787: $role = $1;
8788: $statustype = $2;
8789: if (ref($usertypes) eq 'HASH') {
8790: if ($usertypes->{$statustype}) {
8791: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8792: } else {
8793: $rolename = &mt('Data provided by user');
8794: }
8795: }
8796: }
8797: } elsif ($context eq 'selfcreate') {
8798: if (ref($usertypes) eq 'HASH') {
8799: $rolename = $usertypes->{$role};
8800: } else {
8801: $rolename = $role;
8802: }
8803: } else {
8804: if ($role eq 'cr') {
8805: $rolename = &mt('Custom role');
8806: } else {
8807: $rolename = &Apache::lonnet::plaintext($role);
8808: }
8809: }
8810: my (@fields,%fieldtitles);
8811: if (ref($fieldsref) eq 'ARRAY') {
8812: @fields = @{$fieldsref};
8813: } else {
8814: @fields = ('lastname','firstname','middlename','generation',
8815: 'permanentemail','id');
8816: }
8817: if ((ref($titlesref) eq 'HASH')) {
8818: %fieldtitles = %{$titlesref};
8819: } else {
8820: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8821: }
8822: my $output;
8823: my $css_class;
8824: if ($rowcount%2) {
8825: $css_class = 'LC_odd_row';
8826: }
8827: if ($customcss) {
8828: $css_class .= " $customcss";
8829: }
8830: $css_class =~ s/^\s+//;
8831: if ($css_class) {
8832: $css_class = ' class="'.$css_class.'"';
8833: }
8834: if ($rowstyle) {
8835: $css_class .= ' style="'.$rowstyle.'"';
8836: }
8837: if ($rowid) {
8838: $rowid = ' id="'.$rowid.'"';
8839: }
8840:
8841: $output = '<tr '.$css_class.$rowid.'>'.
8842: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8843: '<td class="LC_left_item" colspan="2"><table>';
8844: my $rem;
8845: my %checks;
8846: if (ref($settings) eq 'HASH') {
8847: if (ref($settings->{$context}) eq 'HASH') {
8848: if (ref($settings->{$context}->{$role}) eq 'HASH') {
8849: my $hashref = $settings->{$context}->{$role};
8850: if ($role eq 'emailusername') {
8851: if ($statustype) {
8852: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8853: $hashref = $settings->{$context}->{$role}->{$statustype};
8854: if (ref($hashref) eq 'HASH') {
8855: foreach my $field (@fields) {
8856: if ($hashref->{$field}) {
8857: $checks{$field} = $hashref->{$field};
8858: }
8859: }
8860: }
8861: }
8862: }
8863: } else {
8864: if (ref($hashref) eq 'HASH') {
8865: foreach my $field (@fields) {
8866: if ($hashref->{$field}) {
8867: $checks{$field} = ' checked="checked" ';
8868: }
8869: }
8870: }
8871: }
8872: }
8873: }
8874: }
8875:
8876: my $total = scalar(@fields);
8877: for (my $i=0; $i<$total; $i++) {
8878: $rem = $i%($numinrow);
8879: if ($rem == 0) {
8880: if ($i > 0) {
8881: $output .= '</tr>';
8882: }
8883: $output .= '<tr>';
8884: }
8885: my $check = ' ';
8886: unless ($role eq 'emailusername') {
8887: if (exists($checks{$fields[$i]})) {
8888: $check = $checks{$fields[$i]};
8889: } else {
8890: if ($role eq 'st') {
8891: if (ref($settings) ne 'HASH') {
8892: $check = ' checked="checked" ';
8893: }
8894: }
8895: }
8896: }
8897: $output .= '<td class="LC_left_item">'.
8898: '<span class="LC_nobreak">';
8899: if ($role eq 'emailusername') {
8900: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8901: $checks{$fields[$i]} = 'omit';
8902: }
8903: foreach my $option ('required','optional','omit') {
8904: my $checked='';
8905: if ($checks{$fields[$i]} eq $option) {
8906: $checked='checked="checked" ';
8907: }
8908: $output .= '<label>'.
8909: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8910: &mt($option).'</label>'.(' ' x2);
8911: }
8912: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8913: } else {
8914: $output .= '<label>'.
8915: '<input type="checkbox" name="canmodify_'.$role.'" '.
8916: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8917: '</label>';
8918: }
8919: $output .= '</span></td>';
8920: }
8921: $rem = $total%$numinrow;
8922: my $colsleft;
8923: if ($rem) {
8924: $colsleft = $numinrow - $rem;
8925: }
8926: if ($colsleft > 1) {
8927: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8928: ' </td>';
8929: } elsif ($colsleft == 1) {
8930: $output .= '<td class="LC_left_item"> </td>';
8931: }
8932: $output .= '</tr></table></td></tr>';
8933: return $output;
8934: }
8935:
8936: sub insttypes_row {
8937: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8938: $customcss,$rowstyle) = @_;
8939: my %lt = &Apache::lonlocal::texthash (
8940: cansearch => 'Users allowed to search',
8941: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
8942: lockablenames => 'User preference to lock name',
8943: selfassign => 'Self-reportable affiliations',
8944: overrides => "Override domain's helpdesk settings based on requester's affiliation",
8945: );
8946: my $showdom;
8947: if ($context eq 'cansearch') {
8948: $showdom = ' ('.$dom.')';
8949: }
8950: my $class = 'LC_left_item';
8951: if ($context eq 'statustocreate') {
8952: $class = 'LC_right_item';
8953: }
8954: my $css_class;
8955: if ($$rowtotal%2) {
8956: $css_class = 'LC_odd_row';
8957: }
8958: if ($customcss) {
8959: $css_class .= ' '.$customcss;
8960: }
8961: $css_class =~ s/^\s+//;
8962: if ($css_class) {
8963: $css_class = ' class="'.$css_class.'"';
8964: }
8965: if ($rowstyle) {
8966: $css_class .= ' style="'.$rowstyle.'"';
8967: }
8968: if ($onclick) {
8969: $onclick = 'onclick="'.$onclick.'" ';
8970: }
8971: my $output = '<tr'.$css_class.'>'.
8972: '<td>'.$lt{$context}.$showdom.
8973: '</td><td class="'.$class.'" colspan="2"><table>';
8974: my $rem;
8975: if (ref($types) eq 'ARRAY') {
8976: for (my $i=0; $i<@{$types}; $i++) {
8977: if (defined($usertypes->{$types->[$i]})) {
8978: my $rem = $i%($numinrow);
8979: if ($rem == 0) {
8980: if ($i > 0) {
8981: $output .= '</tr>';
8982: }
8983: $output .= '<tr>';
8984: }
8985: my $check = ' ';
8986: if (ref($settings) eq 'HASH') {
8987: if (ref($settings->{$context}) eq 'ARRAY') {
8988: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8989: $check = ' checked="checked" ';
8990: }
8991: } elsif (ref($settings->{$context}) eq 'HASH') {
8992: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8993: $check = ' checked="checked" ';
8994: }
8995: } elsif ($context eq 'statustocreate') {
8996: $check = ' checked="checked" ';
8997: }
8998: }
8999: $output .= '<td class="LC_left_item">'.
9000: '<span class="LC_nobreak"><label>'.
9001: '<input type="checkbox" name="'.$context.'" '.
9002: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
9003: $usertypes->{$types->[$i]}.'</label></span></td>';
9004: }
9005: }
9006: $rem = @{$types}%($numinrow);
9007: }
9008: my $colsleft = $numinrow - $rem;
9009: if ($context eq 'overrides') {
9010: if ($colsleft > 1) {
9011: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9012: } else {
9013: $output .= '<td class="LC_left_item">';
9014: }
9015: $output .= ' ';
9016: } else {
9017: if ($rem == 0) {
9018: $output .= '<tr>';
9019: }
9020: if ($colsleft > 1) {
9021: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9022: } else {
9023: $output .= '<td class="LC_left_item">';
9024: }
9025: my $defcheck = ' ';
9026: if (ref($settings) eq 'HASH') {
9027: if (ref($settings->{$context}) eq 'ARRAY') {
9028: if (grep(/^default$/,@{$settings->{$context}})) {
9029: $defcheck = ' checked="checked" ';
9030: }
9031: } elsif ($context eq 'statustocreate') {
9032: $defcheck = ' checked="checked" ';
9033: }
9034: }
9035: $output .= '<span class="LC_nobreak"><label>'.
9036: '<input type="checkbox" name="'.$context.'" '.
9037: 'value="default"'.$defcheck.$onclick.' />'.
9038: $othertitle.'</label></span>';
9039: }
9040: $output .= '</td></tr></table></td></tr>';
9041: return $output;
9042: }
9043:
9044: sub sorted_searchtitles {
9045: my %searchtitles = &Apache::lonlocal::texthash(
9046: 'uname' => 'username',
9047: 'lastname' => 'last name',
9048: 'lastfirst' => 'last name, first name',
9049: );
9050: my @titleorder = ('uname','lastname','lastfirst');
9051: return (\%searchtitles,\@titleorder);
9052: }
9053:
9054: sub sorted_searchtypes {
9055: my %srchtypes_desc = (
9056: exact => 'is exact match',
9057: contains => 'contains ..',
9058: begins => 'begins with ..',
9059: );
9060: my @srchtypeorder = ('exact','begins','contains');
9061: return (\%srchtypes_desc,\@srchtypeorder);
9062: }
9063:
9064: sub usertype_update_row {
9065: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9066: my $datatable;
9067: my $numinrow = 4;
9068: foreach my $type (@{$types}) {
9069: if (defined($usertypes->{$type})) {
9070: $$rownums ++;
9071: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9072: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9073: '</td><td class="LC_left_item"><table>';
9074: for (my $i=0; $i<@{$fields}; $i++) {
9075: my $rem = $i%($numinrow);
9076: if ($rem == 0) {
9077: if ($i > 0) {
9078: $datatable .= '</tr>';
9079: }
9080: $datatable .= '<tr>';
9081: }
9082: my $check = ' ';
9083: if (ref($settings) eq 'HASH') {
9084: if (ref($settings->{'fields'}) eq 'HASH') {
9085: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9086: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9087: $check = ' checked="checked" ';
9088: }
9089: }
9090: }
9091: }
9092:
9093: if ($i == @{$fields}-1) {
9094: my $colsleft = $numinrow - $rem;
9095: if ($colsleft > 1) {
9096: $datatable .= '<td colspan="'.$colsleft.'">';
9097: } else {
9098: $datatable .= '<td>';
9099: }
9100: } else {
9101: $datatable .= '<td>';
9102: }
9103: $datatable .= '<span class="LC_nobreak"><label>'.
9104: '<input type="checkbox" name="updateable_'.$type.
9105: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9106: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
9107: }
9108: $datatable .= '</tr></table></td></tr>';
9109: }
9110: }
9111: return $datatable;
9112: }
9113:
9114: sub modify_login {
9115: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
9116: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
9117: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
9118: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
9119: %title = ( coursecatalog => 'Display course catalog',
9120: adminmail => 'Display administrator E-mail address',
9121: helpdesk => 'Display "Contact Helpdesk" link',
9122: newuser => 'Link for visitors to create a user account',
9123: loginheader => 'Log-in box header',
9124: saml => 'Dual SSO and non-SSO login');
9125: @offon = ('off','on');
9126: if (ref($domconfig{login}) eq 'HASH') {
9127: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9128: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9129: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9130: }
9131: }
9132: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
9133: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
9134: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
9135: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
9136: $saml{$lonhost} = 1;
9137: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
9138: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
9139: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
9140: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
9141: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
9142: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
9143: }
9144: }
9145: }
9146: }
9147: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9148: \%domconfig,\%loginhash);
9149: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
9150: foreach my $item (@toggles) {
9151: $loginhash{login}{$item} = $env{'form.'.$item};
9152: }
9153: $loginhash{login}{loginheader} = $env{'form.loginheader'};
9154: if (ref($colchanges{'login'}) eq 'HASH') {
9155: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9156: \%loginhash);
9157: }
9158:
9159: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9160: my %domservers = &Apache::lonnet::get_servers($dom);
9161: my @loginvia_attribs = ('serverpath','custompath','exempt');
9162: if (keys(%servers) > 1) {
9163: foreach my $lonhost (keys(%servers)) {
9164: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9165: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9166: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9167: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9168: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9169: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9170: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9171: $changes{'loginvia'}{$lonhost} = 1;
9172: } else {
9173: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9174: $changes{'loginvia'}{$lonhost} = 1;
9175: }
9176: } else {
9177: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9178: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9179: $changes{'loginvia'}{$lonhost} = 1;
9180: }
9181: }
9182: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9183: foreach my $item (@loginvia_attribs) {
9184: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9185: }
9186: } else {
9187: foreach my $item (@loginvia_attribs) {
9188: my $new = $env{'form.'.$lonhost.'_'.$item};
9189: if (($item eq 'serverpath') && ($new eq 'custom')) {
9190: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9191: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9192: $new = '/';
9193: }
9194: }
9195: if (($item eq 'custompath') &&
9196: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9197: $new = '';
9198: }
9199: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9200: $changes{'loginvia'}{$lonhost} = 1;
9201: }
9202: if ($item eq 'exempt') {
9203: $new = &check_exempt_addresses($new);
9204: }
9205: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9206: }
9207: }
9208: } else {
9209: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9210: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9211: $changes{'loginvia'}{$lonhost} = 1;
9212: foreach my $item (@loginvia_attribs) {
9213: my $new = $env{'form.'.$lonhost.'_'.$item};
9214: if (($item eq 'serverpath') && ($new eq 'custom')) {
9215: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9216: $new = '/';
9217: }
9218: }
9219: if (($item eq 'custompath') &&
9220: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9221: $new = '';
9222: }
9223: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9224: }
9225: }
9226: }
9227: }
9228: }
9229:
9230: my $servadm = $r->dir_config('lonAdmEMail');
9231: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9232: if (ref($domconfig{'login'}) eq 'HASH') {
9233: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9234: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9235: if ($lang eq 'nolang') {
9236: push(@currlangs,$lang);
9237: } elsif (defined($langchoices{$lang})) {
9238: push(@currlangs,$lang);
9239: } else {
9240: next;
9241: }
9242: }
9243: }
9244: }
9245: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9246: if (@currlangs > 0) {
9247: foreach my $lang (@currlangs) {
9248: if (grep(/^\Q$lang\E$/,@delurls)) {
9249: $changes{'helpurl'}{$lang} = 1;
9250: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9251: $changes{'helpurl'}{$lang} = 1;
9252: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9253: push(@newlangs,$lang);
9254: } else {
9255: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9256: }
9257: }
9258: }
9259: unless (grep(/^nolang$/,@currlangs)) {
9260: if ($env{'form.loginhelpurl_nolang.filename'}) {
9261: $changes{'helpurl'}{'nolang'} = 1;
9262: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9263: push(@newlangs,'nolang');
9264: }
9265: }
9266: if ($env{'form.loginhelpurl_add_lang'}) {
9267: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9268: ($env{'form.loginhelpurl_add_file.filename'})) {
9269: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9270: $addedfile = $env{'form.loginhelpurl_add_lang'};
9271: }
9272: }
9273: if ((@newlangs > 0) || ($addedfile)) {
9274: my $error;
9275: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9276: if ($configuserok eq 'ok') {
9277: if ($switchserver) {
9278: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9279: } elsif ($author_ok eq 'ok') {
9280: my @allnew = @newlangs;
9281: if ($addedfile ne '') {
9282: push(@allnew,$addedfile);
9283: }
9284: foreach my $lang (@allnew) {
9285: my $formelem = 'loginhelpurl_'.$lang;
9286: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9287: $formelem = 'loginhelpurl_add_file';
9288: }
9289: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9290: "help/$lang",'','',$newfile{$lang});
9291: if ($result eq 'ok') {
9292: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9293: $changes{'helpurl'}{$lang} = 1;
9294: } else {
9295: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9296: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9297: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
9298: (!grep(/^\Q$lang\E$/,@delurls))) {
9299: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9300: }
9301: }
9302: }
9303: } else {
9304: $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);
9305: }
9306: } else {
9307: $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);
9308: }
9309: if ($error) {
9310: &Apache::lonnet::logthis($error);
9311: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9312: }
9313: }
9314:
9315: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9316: if (ref($domconfig{'login'}) eq 'HASH') {
9317: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9318: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9319: if ($domservers{$lonhost}) {
9320: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9321: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
9322: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
9323: }
9324: }
9325: }
9326: }
9327: }
9328: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9329: foreach my $lonhost (sort(keys(%domservers))) {
9330: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9331: $changes{'headtag'}{$lonhost} = 1;
9332: } else {
9333: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9334: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9335: }
9336: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9337: push(@newhosts,$lonhost);
9338: } elsif ($currheadtagurls{$lonhost}) {
9339: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9340: if ($currexempt{$lonhost}) {
9341: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
9342: $changes{'headtag'}{$lonhost} = 1;
9343: }
9344: } elsif ($possexempt{$lonhost}) {
9345: $changes{'headtag'}{$lonhost} = 1;
9346: }
9347: if ($possexempt{$lonhost}) {
9348: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9349: }
9350: }
9351: }
9352: }
9353: if (@newhosts) {
9354: my $error;
9355: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9356: if ($configuserok eq 'ok') {
9357: if ($switchserver) {
9358: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9359: } elsif ($author_ok eq 'ok') {
9360: foreach my $lonhost (@newhosts) {
9361: my $formelem = 'loginheadtag_'.$lonhost;
9362: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9363: "login/headtag/$lonhost",'','',
9364: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9365: if ($result eq 'ok') {
9366: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9367: $changes{'headtag'}{$lonhost} = 1;
9368: if ($possexempt{$lonhost}) {
9369: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9370: }
9371: } else {
9372: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9373: $newheadtagurls{$lonhost},$result);
9374: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9375: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9376: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9377: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9378: }
9379: }
9380: }
9381: } else {
9382: $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);
9383: }
9384: } else {
9385: $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);
9386: }
9387: if ($error) {
9388: &Apache::lonnet::logthis($error);
9389: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9390: }
9391: }
9392: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
9393: my @newsamlimgs;
9394: foreach my $lonhost (keys(%domservers)) {
9395: if ($env{'form.saml_'.$lonhost}) {
9396: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
9397: push(@newsamlimgs,$lonhost);
9398: }
9399: foreach my $item ('text','alt','url','title','notsso') {
9400: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
9401: }
9402: if ($saml{$lonhost}) {
9403: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
9404: #FIXME Need to obsolete published image
9405: delete($currsaml{$lonhost}{'img'});
9406: $changes{'saml'}{$lonhost} = 1;
9407: }
9408: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
9409: $changes{'saml'}{$lonhost} = 1;
9410: }
9411: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
9412: $changes{'saml'}{$lonhost} = 1;
9413: }
9414: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
9415: $changes{'saml'}{$lonhost} = 1;
9416: }
9417: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
9418: $changes{'saml'}{$lonhost} = 1;
9419: }
9420: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
9421: $changes{'saml'}{$lonhost} = 1;
9422: }
9423: } else {
9424: $changes{'saml'}{$lonhost} = 1;
9425: }
9426: foreach my $item ('text','alt','url','title','notsso') {
9427: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
9428: }
9429: } else {
9430: if ($saml{$lonhost}) {
9431: $changes{'saml'}{$lonhost} = 1;
9432: delete($currsaml{$lonhost});
9433: }
9434: }
9435: }
9436: foreach my $posshost (keys(%currsaml)) {
9437: unless (exists($domservers{$posshost})) {
9438: delete($currsaml{$posshost});
9439: }
9440: }
9441: %{$loginhash{'login'}{'saml'}} = %currsaml;
9442: if (@newsamlimgs) {
9443: my $error;
9444: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9445: if ($configuserok eq 'ok') {
9446: if ($switchserver) {
9447: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
9448: } elsif ($author_ok eq 'ok') {
9449: foreach my $lonhost (@newsamlimgs) {
9450: my $formelem = 'saml_img_'.$lonhost;
9451: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9452: "login/saml/$lonhost",'','',
9453: $env{'form.saml_img_'.$lonhost.'.filename'});
9454: if ($result eq 'ok') {
9455: $currsaml{$lonhost}{'img'} = $imgurl;
9456: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
9457: $changes{'saml'}{$lonhost} = 1;
9458: } else {
9459: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
9460: $lonhost,$result);
9461: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9462: }
9463: }
9464: } else {
9465: $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);
9466: }
9467: } else {
9468: $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);
9469: }
9470: if ($error) {
9471: &Apache::lonnet::logthis($error);
9472: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9473: }
9474: }
9475: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
9476:
9477: my $defaulthelpfile = '/adm/loginproblems.html';
9478: my $defaulttext = &mt('Default in use');
9479:
9480: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9481: $dom);
9482: if ($putresult eq 'ok') {
9483: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
9484: my %defaultchecked = (
9485: 'coursecatalog' => 'on',
9486: 'helpdesk' => 'on',
9487: 'adminmail' => 'off',
9488: 'newuser' => 'off',
9489: );
9490: if (ref($domconfig{'login'}) eq 'HASH') {
9491: foreach my $item (@toggles) {
9492: if ($defaultchecked{$item} eq 'on') {
9493: if (($domconfig{'login'}{$item} eq '0') &&
9494: ($env{'form.'.$item} eq '1')) {
9495: $changes{$item} = 1;
9496: } elsif (($domconfig{'login'}{$item} eq '' ||
9497: $domconfig{'login'}{$item} eq '1') &&
9498: ($env{'form.'.$item} eq '0')) {
9499: $changes{$item} = 1;
9500: }
9501: } elsif ($defaultchecked{$item} eq 'off') {
9502: if (($domconfig{'login'}{$item} eq '1') &&
9503: ($env{'form.'.$item} eq '0')) {
9504: $changes{$item} = 1;
9505: } elsif (($domconfig{'login'}{$item} eq '' ||
9506: $domconfig{'login'}{$item} eq '0') &&
9507: ($env{'form.'.$item} eq '1')) {
9508: $changes{$item} = 1;
9509: }
9510: }
9511: }
9512: }
9513: if (keys(%changes) > 0 || $colchgtext) {
9514: &Apache::loncommon::devalidate_domconfig_cache($dom);
9515: if (exists($changes{'saml'})) {
9516: my $hostid_in_use;
9517: my @hosts = &Apache::lonnet::current_machine_ids();
9518: if (@hosts > 1) {
9519: foreach my $hostid (@hosts) {
9520: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
9521: $hostid_in_use = $hostid;
9522: last;
9523: }
9524: }
9525: } else {
9526: $hostid_in_use = $r->dir_config('lonHostID');
9527: }
9528: if (($hostid_in_use) &&
9529: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
9530: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
9531: }
9532: if (ref($lastactref) eq 'HASH') {
9533: if (ref($changes{'saml'}) eq 'HASH') {
9534: my %updates;
9535: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
9536: $lastactref->{'samllanding'} = \%updates;
9537: }
9538: }
9539: }
9540: if (ref($lastactref) eq 'HASH') {
9541: $lastactref->{'domainconfig'} = 1;
9542: }
9543: $resulttext = &mt('Changes made:').'<ul>';
9544: foreach my $item (sort(keys(%changes))) {
9545: if ($item eq 'loginvia') {
9546: if (ref($changes{$item}) eq 'HASH') {
9547: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9548: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9549: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9550: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9551: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9552: $protocol = 'http' if ($protocol ne 'https');
9553: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9554:
9555: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9556: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9557: } else {
9558: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9559: }
9560: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9561: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9562: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9563: }
9564: $resulttext .= '</li>';
9565: } else {
9566: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9567: }
9568: } else {
9569: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
9570: }
9571: }
9572: $resulttext .= '</ul></li>';
9573: }
9574: } elsif ($item eq 'helpurl') {
9575: if (ref($changes{$item}) eq 'HASH') {
9576: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9577: if (grep(/^\Q$lang\E$/,@delurls)) {
9578: my ($chg,$link);
9579: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9580: if ($lang eq 'nolang') {
9581: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9582: } else {
9583: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9584: }
9585: $resulttext .= '<li>'.$chg.'</li>';
9586: } else {
9587: my $chg;
9588: if ($lang eq 'nolang') {
9589: $chg = &mt('custom log-in help file for no preferred language');
9590: } else {
9591: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9592: }
9593: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9594: $loginhash{'login'}{'helpurl'}{$lang}.
9595: '?inhibitmenu=yes',$chg,600,500).
9596: '</li>';
9597: }
9598: }
9599: }
9600: } elsif ($item eq 'headtag') {
9601: if (ref($changes{$item}) eq 'HASH') {
9602: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9603: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9604: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9605: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9606: $resulttext .= '<li><a href="'.
9607: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9608: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9609: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9610: if ($possexempt{$lonhost}) {
9611: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9612: } else {
9613: $resulttext .= &mt('included for any client IP');
9614: }
9615: $resulttext .= '</li>';
9616: }
9617: }
9618: }
9619: } elsif ($item eq 'saml') {
9620: if (ref($changes{$item}) eq 'HASH') {
9621: my %notlt = (
9622: text => 'Text for log-in by SSO',
9623: img => 'SSO button image',
9624: alt => 'Alt text for button image',
9625: url => 'SSO URL',
9626: title => 'Tooltip for SSO link',
9627: notsso => 'Text for non-SSO log-in',
9628: );
9629: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9630: if (ref($currsaml{$lonhost}) eq 'HASH') {
9631: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
9632: '<ul>';
9633: foreach my $key ('text','img','alt','url','title','notsso') {
9634: if ($currsaml{$lonhost}{$key} eq '') {
9635: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
9636: } else {
9637: my $value = "'$currsaml{$lonhost}{$key}'";
9638: if ($key eq 'img') {
9639: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
9640: }
9641: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
9642: $value).'</li>';
9643: }
9644: }
9645: $resulttext .= '</ul></li>';
9646: } else {
9647: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
9648: }
9649: }
9650: }
9651: } elsif ($item eq 'captcha') {
9652: if (ref($loginhash{'login'}) eq 'HASH') {
9653: my $chgtxt;
9654: if ($loginhash{'login'}{$item} eq 'notused') {
9655: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9656: } else {
9657: my %captchas = &captcha_phrases();
9658: if ($captchas{$loginhash{'login'}{$item}}) {
9659: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9660: } else {
9661: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9662: }
9663: }
9664: $resulttext .= '<li>'.$chgtxt.'</li>';
9665: }
9666: } elsif ($item eq 'recaptchakeys') {
9667: if (ref($loginhash{'login'}) eq 'HASH') {
9668: my ($privkey,$pubkey);
9669: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9670: $pubkey = $loginhash{'login'}{$item}{'public'};
9671: $privkey = $loginhash{'login'}{$item}{'private'};
9672: }
9673: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9674: if (!$pubkey) {
9675: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9676: } else {
9677: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9678: }
9679: if (!$privkey) {
9680: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9681: } else {
9682: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
9683: }
9684: $chgtxt .= '</ul>';
9685: $resulttext .= '<li>'.$chgtxt.'</li>';
9686: }
9687: } elsif ($item eq 'recaptchaversion') {
9688: if (ref($loginhash{'login'}) eq 'HASH') {
9689: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9690: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9691: '</li>';
9692: }
9693: }
9694: } else {
9695: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9696: }
9697: }
9698: $resulttext .= $colchgtext.'</ul>';
9699: } else {
9700: $resulttext = &mt('No changes made to log-in page settings');
9701: }
9702: } else {
9703: $resulttext = '<span class="LC_error">'.
9704: &mt('An error occurred: [_1]',$putresult).'</span>';
9705: }
9706: if ($errors) {
9707: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
9708: $errors.'</ul>';
9709: }
9710: return $resulttext;
9711: }
9712:
9713: sub check_exempt_addresses {
9714: my ($iplist) = @_;
9715: $iplist =~ s/^\s+//;
9716: $iplist =~ s/\s+$//;
9717: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9718: my (@okips,$new);
9719: foreach my $ip (@poss_ips) {
9720: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9721: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9722: push(@okips,$ip);
9723: }
9724: }
9725: }
9726: if (@okips > 0) {
9727: $new = join(',',@okips);
9728: } else {
9729: $new = '';
9730: }
9731: return $new;
9732: }
9733:
9734: sub color_font_choices {
9735: my %choices =
9736: &Apache::lonlocal::texthash (
9737: img => "Header",
9738: bgs => "Background colors",
9739: links => "Link colors",
9740: images => "Images",
9741: font => "Font color",
9742: fontmenu => "Font menu",
9743: pgbg => "Page",
9744: tabbg => "Header",
9745: sidebg => "Border",
9746: link => "Link",
9747: alink => "Active link",
9748: vlink => "Visited link",
9749: );
9750: return %choices;
9751: }
9752:
9753: sub modify_ipaccess {
9754: my ($dom,$lastactref,%domconfig) = @_;
9755: my (@allpos,%changes,%confhash,$errors,$resulttext);
9756: my (@items,%deletions,%itemids,@warnings);
9757: my ($typeorder,$types) = &commblocktype_text();
9758: if ($env{'form.ipaccess_add'}) {
9759: my $name = $env{'form.ipaccess_name_add'};
9760: my ($newid,$error) = &get_ipaccess_id($dom,$name);
9761: if ($newid) {
9762: $itemids{'add'} = $newid;
9763: push(@items,'add');
9764: $changes{$newid} = 1;
9765: } else {
9766: $error = &mt('Failed to acquire unique ID for new IP access control item');
9767: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9768: }
9769: }
9770: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9771: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
9772: if (@todelete) {
9773: map { $deletions{$_} = 1; } @todelete;
9774: }
9775: my $maxnum = $env{'form.ipaccess_maxnum'};
9776: for (my $i=0; $i<$maxnum; $i++) {
9777: my $itemid = $env{'form.ipaccess_id_'.$i};
9778: $itemid =~ s/\D+//g;
9779: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9780: if ($deletions{$itemid}) {
9781: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
9782: } else {
9783: push(@items,$i);
9784: $itemids{$i} = $itemid;
9785: }
9786: }
9787: }
9788: }
9789: foreach my $idx (@items) {
9790: my $itemid = $itemids{$idx};
9791: next unless ($itemid);
9792: my %current;
9793: unless ($idx eq 'add') {
9794: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9795: %current = %{$domconfig{'ipaccess'}{$itemid}};
9796: }
9797: }
9798: my $position = $env{'form.ipaccess_pos_'.$itemid};
9799: $position =~ s/\D+//g;
9800: if ($position ne '') {
9801: $allpos[$position] = $itemid;
9802: }
9803: my $name = $env{'form.ipaccess_name_'.$idx};
9804: $name =~ s/^\s+|\s+$//g;
9805: $confhash{$itemid}{'name'} = $name;
9806: my $possrange = $env{'form.ipaccess_range_'.$idx};
9807: $possrange =~ s/^\s+|\s+$//g;
9808: unless ($possrange eq '') {
9809: $possrange =~ s/[\r\n]+/\s/g;
9810: $possrange =~ s/\s*-\s*/-/g;
9811: $possrange =~ s/\s+/,/g;
9812: $possrange =~ s/,+/,/g;
9813: if ($possrange ne '') {
9814: my (@ok,$count);
9815: $count = 0;
9816: foreach my $poss (split(/\,/,$possrange)) {
9817: $count ++;
9818: $poss = &validate_ip_pattern($poss);
9819: if ($poss ne '') {
9820: push(@ok,$poss);
9821: }
9822: }
9823: my $diff = $count - scalar(@ok);
9824: if ($diff) {
9825: $errors .= '<li><span class="LC_error">'.
9826: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
9827: $diff,$name).
9828: '</span></li>';
9829: }
9830: if (@ok) {
9831: my @cidr_list;
9832: foreach my $item (@ok) {
9833: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
9834: }
9835: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
9836: }
9837: }
9838: }
9839: foreach my $field ('name','ip') {
9840: unless (($idx eq 'add') || ($changes{$itemid})) {
9841: if ($current{$field} ne $confhash{$itemid}{$field}) {
9842: $changes{$itemid} = 1;
9843: last;
9844: }
9845: }
9846: }
9847: $confhash{$itemid}{'commblocks'} = {};
9848:
9849: my %commblocks;
9850: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
9851: foreach my $type (@{$typeorder}) {
9852: if ($commblocks{$type}) {
9853: $confhash{$itemid}{'commblocks'}{$type} = 'on';
9854: }
9855: unless (($idx eq 'add') || ($changes{$itemid})) {
9856: if (ref($current{'commblocks'}) eq 'HASH') {
9857: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
9858: $changes{$itemid} = 1;
9859: }
9860: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
9861: $changes{$itemid} = 1;
9862: }
9863: }
9864: }
9865: $confhash{$itemid}{'courses'} = {};
9866: my %crsdeletions;
9867: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
9868: if (@delcrs) {
9869: map { $crsdeletions{$_} = 1; } @delcrs;
9870: }
9871: if (ref($current{'courses'}) eq 'HASH') {
9872: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
9873: if ($crsdeletions{$cid}) {
9874: $changes{$itemid} = 1;
9875: } else {
9876: $confhash{$itemid}{'courses'}{$cid} = 1;
9877: }
9878: }
9879: }
9880: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
9881: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
9882: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
9883: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
9884: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
9885: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
9886: $errors .= '<li><span class="LC_error">'.
9887: &mt('Invalid courseID [_1] omitted from list of allowed courses',
9888: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
9889: '</span></li>';
9890: } else {
9891: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
9892: $changes{$itemid} = 1;
9893: }
9894: }
9895: }
9896: if (@allpos > 0) {
9897: my $idx = 0;
9898: foreach my $itemid (@allpos) {
9899: if ($itemid ne '') {
9900: $confhash{$itemid}{'order'} = $idx;
9901: unless ($changes{$itemid}) {
9902: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
9903: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
9904: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
9905: $changes{$itemid} = 1;
9906: }
9907: }
9908: }
9909: }
9910: $idx ++;
9911: }
9912: }
9913: }
9914: if (keys(%changes)) {
9915: my %defaultshash = (
9916: ipaccess => \%confhash,
9917: );
9918: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9919: $dom);
9920: if ($putresult eq 'ok') {
9921: my $cachetime = 1800;
9922: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
9923: if (ref($lastactref) eq 'HASH') {
9924: $lastactref->{'ipaccess'} = 1;
9925: }
9926: $resulttext = &mt('Changes made:').'<ul>';
9927: my %bynum;
9928: foreach my $itemid (sort(keys(%changes))) {
9929: if (ref($confhash{$itemid}) eq 'HASH') {
9930: my $position = $confhash{$itemid}{'order'};
9931: if ($position =~ /^\d+$/) {
9932: $bynum{$position} = $itemid;
9933: }
9934: }
9935: }
9936: if (keys(%deletions)) {
9937: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
9938: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9939: }
9940: }
9941: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9942: my $itemid = $bynum{$pos};
9943: if (ref($confhash{$itemid}) eq 'HASH') {
9944: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
9945: my $position = $pos + 1;
9946: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9947: if ($confhash{$itemid}{'ip'} eq '') {
9948: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
9949: } else {
9950: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
9951: }
9952: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
9953: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
9954: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
9955: '</li>';
9956: } else {
9957: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
9958: }
9959: if (keys(%{$confhash{$itemid}{'courses'}})) {
9960: my @courses;
9961: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
9962: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
9963: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
9964: }
9965: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
9966: join('</li><li>',@courses).'</li></ul>';
9967: } else {
9968: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
9969: }
9970: $resulttext .= '</ul></li>';
9971: }
9972: }
9973: $resulttext .= '</ul>';
9974: } else {
9975: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9976: }
9977: } else {
9978: $resulttext = &mt('No changes made');
9979: }
9980: if ($errors) {
9981: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
9982: $errors.'</ul></p>';
9983: }
9984: return $resulttext;
9985: }
9986:
9987: sub get_ipaccess_id {
9988: my ($domain,$location) = @_;
9989: # get lock on ipaccess db
9990: my $lockhash = {
9991: lock => $env{'user.name'}.
9992: ':'.$env{'user.domain'},
9993: };
9994: my $tries = 0;
9995: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
9996: my ($id,$error);
9997:
9998: while (($gotlock ne 'ok') && ($tries<10)) {
9999: $tries ++;
10000: sleep (0.1);
10001: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10002: }
10003: if ($gotlock eq 'ok') {
10004: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
10005: if ($currids{'lock'}) {
10006: delete($currids{'lock'});
10007: if (keys(%currids)) {
10008: my @curr = sort { $a <=> $b } keys(%currids);
10009: if ($curr[-1] =~ /^\d+$/) {
10010: $id = 1 + $curr[-1];
10011: }
10012: } else {
10013: $id = 1;
10014: }
10015: if ($id) {
10016: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10017: $error = 'nostore';
10018: }
10019: } else {
10020: $error = 'nonumber';
10021: }
10022: }
10023: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10024: } else {
10025: $error = 'nolock';
10026: }
10027: return ($id,$error);
10028: }
10029:
10030: sub modify_rolecolors {
10031: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
10032: my ($resulttext,%rolehash);
10033: $rolehash{'rolecolors'} = {};
10034: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10035: if ($domconfig{'rolecolors'} eq '') {
10036: $domconfig{'rolecolors'} = {};
10037: }
10038: }
10039: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
10040: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10041: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10042: $dom);
10043: if ($putresult eq 'ok') {
10044: if (keys(%changes) > 0) {
10045: &Apache::loncommon::devalidate_domconfig_cache($dom);
10046: if (ref($lastactref) eq 'HASH') {
10047: $lastactref->{'domainconfig'} = 1;
10048: }
10049: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10050: $rolehash{'rolecolors'});
10051: } else {
10052: $resulttext = &mt('No changes made to default color schemes');
10053: }
10054: } else {
10055: $resulttext = '<span class="LC_error">'.
10056: &mt('An error occurred: [_1]',$putresult).'</span>';
10057: }
10058: if ($errors) {
10059: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10060: $errors.'</ul>';
10061: }
10062: return $resulttext;
10063: }
10064:
10065: sub modify_colors {
10066: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
10067: my (%changes,%choices);
10068: my @bgs;
10069: my @links = ('link','alink','vlink');
10070: my @logintext;
10071: my @images;
10072: my $servadm = $r->dir_config('lonAdmEMail');
10073: my $errors;
10074: my %defaults;
10075: foreach my $role (@{$roles}) {
10076: if ($role eq 'login') {
10077: %choices = &login_choices();
10078: @logintext = ('textcol','bgcol');
10079: } else {
10080: %choices = &color_font_choices();
10081: }
10082: if ($role eq 'login') {
10083: @images = ('img','logo','domlogo','login');
10084: @bgs = ('pgbg','mainbg','sidebg');
10085: } else {
10086: @images = ('img');
10087: @bgs = ('pgbg','tabbg','sidebg');
10088: }
10089: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10090: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10091: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10092: }
10093: if ($role eq 'login') {
10094: foreach my $item (@logintext) {
10095: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10096: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10097: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10098: }
10099: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
10100: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10101: }
10102: }
10103: } else {
10104: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10105: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10106: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10107: }
10108: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
10109: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10110: }
10111: }
10112: foreach my $item (@bgs) {
10113: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10114: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10115: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10116: }
10117: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
10118: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10119: }
10120: }
10121: foreach my $item (@links) {
10122: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10123: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10124: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10125: }
10126: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
10127: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10128: }
10129: }
10130: my ($configuserok,$author_ok,$switchserver) =
10131: &config_check($dom,$confname,$servadm);
10132: my ($width,$height) = &thumb_dimensions();
10133: if (ref($domconfig->{$role}) ne 'HASH') {
10134: $domconfig->{$role} = {};
10135: }
10136: foreach my $img (@images) {
10137: if ($role eq 'login') {
10138: if (($img eq 'img') || ($img eq 'logo')) {
10139: if (defined($env{'form.login_showlogo_'.$img})) {
10140: $confhash->{$role}{'showlogo'}{$img} = 1;
10141: } else {
10142: $confhash->{$role}{'showlogo'}{$img} = 0;
10143: }
10144: }
10145: if ($env{'form.login_alt_'.$img} ne '') {
10146: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
10147: }
10148: }
10149: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10150: && !defined($domconfig->{$role}{$img})
10151: && !$env{'form.'.$role.'_del_'.$img}
10152: && $env{'form.'.$role.'_import_'.$img}) {
10153: # import the old configured image from the .tab setting
10154: # if they haven't provided a new one
10155: $domconfig->{$role}{$img} =
10156: $env{'form.'.$role.'_import_'.$img};
10157: }
10158: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
10159: my $error;
10160: if ($configuserok eq 'ok') {
10161: if ($switchserver) {
10162: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
10163: } else {
10164: if ($author_ok eq 'ok') {
10165: my ($result,$logourl) =
10166: &publishlogo($r,'upload',$role.'_'.$img,
10167: $dom,$confname,$img,$width,$height);
10168: if ($result eq 'ok') {
10169: $confhash->{$role}{$img} = $logourl;
10170: $changes{$role}{'images'}{$img} = 1;
10171: } else {
10172: $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);
10173: }
10174: } else {
10175: $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);
10176: }
10177: }
10178: } else {
10179: $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);
10180: }
10181: if ($error) {
10182: &Apache::lonnet::logthis($error);
10183: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10184: }
10185: } elsif ($domconfig->{$role}{$img} ne '') {
10186: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10187: my $error;
10188: if ($configuserok eq 'ok') {
10189: # is confname an author?
10190: if ($switchserver eq '') {
10191: if ($author_ok eq 'ok') {
10192: my ($result,$logourl) =
10193: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10194: $dom,$confname,$img,$width,$height);
10195: if ($result eq 'ok') {
10196: $confhash->{$role}{$img} = $logourl;
10197: $changes{$role}{'images'}{$img} = 1;
10198: }
10199: }
10200: }
10201: }
10202: }
10203: }
10204: }
10205: if (ref($domconfig) eq 'HASH') {
10206: if (ref($domconfig->{$role}) eq 'HASH') {
10207: foreach my $img (@images) {
10208: if ($domconfig->{$role}{$img} ne '') {
10209: if ($env{'form.'.$role.'_del_'.$img}) {
10210: $confhash->{$role}{$img} = '';
10211: $changes{$role}{'images'}{$img} = 1;
10212: } else {
10213: if ($confhash->{$role}{$img} eq '') {
10214: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10215: }
10216: }
10217: } else {
10218: if ($env{'form.'.$role.'_del_'.$img}) {
10219: $confhash->{$role}{$img} = '';
10220: $changes{$role}{'images'}{$img} = 1;
10221: }
10222: }
10223: if ($role eq 'login') {
10224: if (($img eq 'logo') || ($img eq 'img')) {
10225: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10226: if ($confhash->{$role}{'showlogo'}{$img} ne
10227: $domconfig->{$role}{'showlogo'}{$img}) {
10228: $changes{$role}{'showlogo'}{$img} = 1;
10229: }
10230: } else {
10231: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10232: $changes{$role}{'showlogo'}{$img} = 1;
10233: }
10234: }
10235: }
10236: if ($img ne 'login') {
10237: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
10238: if ($confhash->{$role}{'alttext'}{$img} ne
10239: $domconfig->{$role}{'alttext'}{$img}) {
10240: $changes{$role}{'alttext'}{$img} = 1;
10241: }
10242: } else {
10243: if ($confhash->{$role}{'alttext'}{$img} ne '') {
10244: $changes{$role}{'alttext'}{$img} = 1;
10245: }
10246: }
10247: }
10248: }
10249: }
10250: if ($domconfig->{$role}{'font'} ne '') {
10251: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10252: $changes{$role}{'font'} = 1;
10253: }
10254: } else {
10255: if ($confhash->{$role}{'font'}) {
10256: $changes{$role}{'font'} = 1;
10257: }
10258: }
10259: if ($role ne 'login') {
10260: if ($domconfig->{$role}{'fontmenu'} ne '') {
10261: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10262: $changes{$role}{'fontmenu'} = 1;
10263: }
10264: } else {
10265: if ($confhash->{$role}{'fontmenu'}) {
10266: $changes{$role}{'fontmenu'} = 1;
10267: }
10268: }
10269: }
10270: foreach my $item (@bgs) {
10271: if ($domconfig->{$role}{$item} ne '') {
10272: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10273: $changes{$role}{'bgs'}{$item} = 1;
10274: }
10275: } else {
10276: if ($confhash->{$role}{$item}) {
10277: $changes{$role}{'bgs'}{$item} = 1;
10278: }
10279: }
10280: }
10281: foreach my $item (@links) {
10282: if ($domconfig->{$role}{$item} ne '') {
10283: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10284: $changes{$role}{'links'}{$item} = 1;
10285: }
10286: } else {
10287: if ($confhash->{$role}{$item}) {
10288: $changes{$role}{'links'}{$item} = 1;
10289: }
10290: }
10291: }
10292: foreach my $item (@logintext) {
10293: if ($domconfig->{$role}{$item} ne '') {
10294: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10295: $changes{$role}{'logintext'}{$item} = 1;
10296: }
10297: } else {
10298: if ($confhash->{$role}{$item}) {
10299: $changes{$role}{'logintext'}{$item} = 1;
10300: }
10301: }
10302: }
10303: } else {
10304: &default_change_checker($role,\@images,\@links,\@bgs,
10305: \@logintext,$confhash,\%changes);
10306: }
10307: } else {
10308: &default_change_checker($role,\@images,\@links,\@bgs,
10309: \@logintext,$confhash,\%changes);
10310: }
10311: }
10312: return ($errors,%changes);
10313: }
10314:
10315: sub config_check {
10316: my ($dom,$confname,$servadm) = @_;
10317: my ($configuserok,$author_ok,$switchserver,%currroles);
10318: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10319: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10320: $confname,$servadm);
10321: if ($configuserok eq 'ok') {
10322: $switchserver = &check_switchserver($dom,$confname);
10323: if ($switchserver eq '') {
10324: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10325: }
10326: }
10327: return ($configuserok,$author_ok,$switchserver);
10328: }
10329:
10330: sub default_change_checker {
10331: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
10332: foreach my $item (@{$links}) {
10333: if ($confhash->{$role}{$item}) {
10334: $changes->{$role}{'links'}{$item} = 1;
10335: }
10336: }
10337: foreach my $item (@{$bgs}) {
10338: if ($confhash->{$role}{$item}) {
10339: $changes->{$role}{'bgs'}{$item} = 1;
10340: }
10341: }
10342: foreach my $item (@{$logintext}) {
10343: if ($confhash->{$role}{$item}) {
10344: $changes->{$role}{'logintext'}{$item} = 1;
10345: }
10346: }
10347: foreach my $img (@{$images}) {
10348: if ($env{'form.'.$role.'_del_'.$img}) {
10349: $confhash->{$role}{$img} = '';
10350: $changes->{$role}{'images'}{$img} = 1;
10351: }
10352: if ($role eq 'login') {
10353: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10354: $changes->{$role}{'showlogo'}{$img} = 1;
10355: }
10356: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
10357: if ($confhash->{$role}{'alttext'}{$img} ne '') {
10358: $changes->{$role}{'alttext'}{$img} = 1;
10359: }
10360: }
10361: }
10362: }
10363: if ($confhash->{$role}{'font'}) {
10364: $changes->{$role}{'font'} = 1;
10365: }
10366: }
10367:
10368: sub display_colorchgs {
10369: my ($dom,$changes,$roles,$confhash) = @_;
10370: my (%choices,$resulttext);
10371: if (!grep(/^login$/,@{$roles})) {
10372: $resulttext = &mt('Changes made:').'<br />';
10373: }
10374: foreach my $role (@{$roles}) {
10375: if ($role eq 'login') {
10376: %choices = &login_choices();
10377: } else {
10378: %choices = &color_font_choices();
10379: }
10380: if (ref($changes->{$role}) eq 'HASH') {
10381: if ($role ne 'login') {
10382: $resulttext .= '<h4>'.&mt($role).'</h4>';
10383: }
10384: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10385: if ($role ne 'login') {
10386: $resulttext .= '<ul>';
10387: }
10388: if (ref($changes->{$role}{$key}) eq 'HASH') {
10389: if ($role ne 'login') {
10390: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10391: }
10392: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
10393: if (($role eq 'login') && ($key eq 'showlogo')) {
10394: if ($confhash->{$role}{$key}{$item}) {
10395: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10396: } else {
10397: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10398: }
10399: } elsif (($role eq 'login') && ($key eq 'alttext')) {
10400: if ($confhash->{$role}{$key}{$item} ne '') {
10401: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
10402: $confhash->{$role}{$key}{$item}).'</li>';
10403: } else {
10404: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
10405: }
10406: } elsif ($confhash->{$role}{$item} eq '') {
10407: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10408: } else {
10409: my $newitem = $confhash->{$role}{$item};
10410: if ($key eq 'images') {
10411: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
10412: }
10413: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
10414: }
10415: }
10416: if ($role ne 'login') {
10417: $resulttext .= '</ul></li>';
10418: }
10419: } else {
10420: if ($confhash->{$role}{$key} eq '') {
10421: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10422: } else {
10423: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10424: }
10425: }
10426: if ($role ne 'login') {
10427: $resulttext .= '</ul>';
10428: }
10429: }
10430: }
10431: }
10432: return $resulttext;
10433: }
10434:
10435: sub thumb_dimensions {
10436: return ('200','50');
10437: }
10438:
10439: sub check_dimensions {
10440: my ($inputfile) = @_;
10441: my ($fullwidth,$fullheight);
10442: if ($inputfile =~ m|^[/\w.\-]+$|) {
10443: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10444: my $imageinfo = <PIPE>;
10445: if (!close(PIPE)) {
10446: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10447: }
10448: chomp($imageinfo);
10449: my ($fullsize) =
10450: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
10451: if ($fullsize) {
10452: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10453: }
10454: }
10455: }
10456: return ($fullwidth,$fullheight);
10457: }
10458:
10459: sub check_configuser {
10460: my ($uhome,$dom,$confname,$servadm) = @_;
10461: my ($configuserok,%currroles);
10462: if ($uhome eq 'no_host') {
10463: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
10464: my $configpass = &LONCAPA::Enrollment::create_password($dom);
10465: $configuserok =
10466: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10467: $configpass,'','','','','',undef,$servadm);
10468: } else {
10469: $configuserok = 'ok';
10470: %currroles =
10471: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10472: }
10473: return ($configuserok,%currroles);
10474: }
10475:
10476: sub check_authorstatus {
10477: my ($dom,$confname,%currroles) = @_;
10478: my $author_ok;
10479: if (!$currroles{':'.$dom.':au'}) {
10480: my $start = time;
10481: my $end = 0;
10482: $author_ok =
10483: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
10484: 'au',$end,$start,'','','domconfig');
10485: } else {
10486: $author_ok = 'ok';
10487: }
10488: return $author_ok;
10489: }
10490:
10491: sub publishlogo {
10492: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
10493: my ($output,$fname,$logourl);
10494: if ($action eq 'upload') {
10495: $fname=$env{'form.'.$formname.'.filename'};
10496: chop($env{'form.'.$formname});
10497: } else {
10498: ($fname) = ($formname =~ /([^\/]+)$/);
10499: }
10500: if ($savefileas ne '') {
10501: $fname = $savefileas;
10502: }
10503: $fname=&Apache::lonnet::clean_filename($fname);
10504: # See if there is anything left
10505: unless ($fname) { return ('error: no uploaded file'); }
10506: $fname="$subdir/$fname";
10507: my $docroot=$r->dir_config('lonDocRoot');
10508: my $filepath="$docroot/priv";
10509: my $relpath = "$dom/$confname";
10510: my ($fnamepath,$file,$fetchthumb);
10511: $file=$fname;
10512: if ($fname=~m|/|) {
10513: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10514: }
10515: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
10516: my $count;
10517: for ($count=5;$count<=$#parts;$count++) {
10518: $filepath.="/$parts[$count]";
10519: if ((-e $filepath)!=1) {
10520: mkdir($filepath,02770);
10521: }
10522: }
10523: # Check for bad extension and disallow upload
10524: if ($file=~/\.(\w+)$/ &&
10525: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10526: $output =
10527: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
10528: } elsif ($file=~/\.(\w+)$/ &&
10529: !defined(&Apache::loncommon::fileembstyle($1))) {
10530: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10531: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
10532: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
10533: } elsif (-d "$filepath/$file") {
10534: $output = &mt('Filename is a directory name - rename the file and re-upload');
10535: } else {
10536: my $source = $filepath.'/'.$file;
10537: my $logfile;
10538: if (!open($logfile,">>",$source.'.log')) {
10539: return (&mt('No write permission to Authoring Space'));
10540: }
10541: print $logfile
10542: "\n================= Publish ".localtime()." ================\n".
10543: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10544: # Save the file
10545: if (!open(FH,">",$source)) {
10546: &Apache::lonnet::logthis('Failed to create '.$source);
10547: return (&mt('Failed to create file'));
10548: }
10549: if ($action eq 'upload') {
10550: if (!print FH ($env{'form.'.$formname})) {
10551: &Apache::lonnet::logthis('Failed to write to '.$source);
10552: return (&mt('Failed to write file'));
10553: }
10554: } else {
10555: my $original = &Apache::lonnet::filelocation('',$formname);
10556: if(!copy($original,$source)) {
10557: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10558: return (&mt('Failed to write file'));
10559: }
10560: }
10561: close(FH);
10562: chmod(0660, $source); # Permissions to rw-rw---.
10563:
10564: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10565: my $copyfile=$targetdir.'/'.$file;
10566:
10567: my @parts=split(/\//,$targetdir);
10568: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10569: for (my $count=5;$count<=$#parts;$count++) {
10570: $path.="/$parts[$count]";
10571: if (!-e $path) {
10572: print $logfile "\nCreating directory ".$path;
10573: mkdir($path,02770);
10574: }
10575: }
10576: my $versionresult;
10577: if (-e $copyfile) {
10578: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10579: } else {
10580: $versionresult = 'ok';
10581: }
10582: if ($versionresult eq 'ok') {
10583: if (copy($source,$copyfile)) {
10584: print $logfile "\nCopied original source to ".$copyfile."\n";
10585: $output = 'ok';
10586: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
10587: push(@{$modified_urls},[$copyfile,$source]);
10588: my $metaoutput =
10589: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10590: unless ($registered_cleanup) {
10591: my $handlers = $r->get_handlers('PerlCleanupHandler');
10592: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10593: $registered_cleanup=1;
10594: }
10595: } else {
10596: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10597: $output = &mt('Failed to copy file to RES space').", $!";
10598: }
10599: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10600: my $inputfile = $filepath.'/'.$file;
10601: my $outfile = $filepath.'/'.'tn-'.$file;
10602: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10603: if ($fullwidth ne '' && $fullheight ne '') {
10604: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10605: my $thumbsize = $thumbwidth.'x'.$thumbheight;
10606: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10607: system({$args[0]} @args);
10608: chmod(0660, $filepath.'/tn-'.$file);
10609: if (-e $outfile) {
10610: my $copyfile=$targetdir.'/tn-'.$file;
10611: if (copy($outfile,$copyfile)) {
10612: print $logfile "\nCopied source to ".$copyfile."\n";
10613: my $thumb_metaoutput =
10614: &write_metadata($dom,$confname,$formname,
10615: $targetdir,'tn-'.$file,$logfile);
10616: push(@{$modified_urls},[$copyfile,$outfile]);
10617: unless ($registered_cleanup) {
10618: my $handlers = $r->get_handlers('PerlCleanupHandler');
10619: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10620: $registered_cleanup=1;
10621: }
10622: } else {
10623: print $logfile "\nUnable to write ".$copyfile.
10624: ':'.$!."\n";
10625: }
10626: }
10627: }
10628: }
10629: }
10630: } else {
10631: $output = $versionresult;
10632: }
10633: }
10634: return ($output,$logourl);
10635: }
10636:
10637: sub logo_versioning {
10638: my ($targetdir,$file,$logfile) = @_;
10639: my $target = $targetdir.'/'.$file;
10640: my ($maxversion,$fn,$extn,$output);
10641: $maxversion = 0;
10642: if ($file =~ /^(.+)\.(\w+)$/) {
10643: $fn=$1;
10644: $extn=$2;
10645: }
10646: opendir(DIR,$targetdir);
10647: while (my $filename=readdir(DIR)) {
10648: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10649: $maxversion=($1>$maxversion)?$1:$maxversion;
10650: }
10651: }
10652: $maxversion++;
10653: print $logfile "\nCreating old version ".$maxversion."\n";
10654: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10655: if (copy($target,$copyfile)) {
10656: print $logfile "Copied old target to ".$copyfile."\n";
10657: $copyfile=$copyfile.'.meta';
10658: if (copy($target.'.meta',$copyfile)) {
10659: print $logfile "Copied old target metadata to ".$copyfile."\n";
10660: $output = 'ok';
10661: } else {
10662: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10663: $output = &mt('Failed to copy old meta').", $!, ";
10664: }
10665: } else {
10666: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10667: $output = &mt('Failed to copy old target').", $!, ";
10668: }
10669: return $output;
10670: }
10671:
10672: sub write_metadata {
10673: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10674: my (%metadatafields,%metadatakeys,$output);
10675: $metadatafields{'title'}=$formname;
10676: $metadatafields{'creationdate'}=time;
10677: $metadatafields{'lastrevisiondate'}=time;
10678: $metadatafields{'copyright'}='public';
10679: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10680: $env{'user.domain'};
10681: $metadatafields{'authorspace'}=$confname.':'.$dom;
10682: $metadatafields{'domain'}=$dom;
10683: {
10684: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10685: my $mfh;
10686: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
10687: foreach (sort(keys(%metadatafields))) {
10688: unless ($_=~/\./) {
10689: my $unikey=$_;
10690: $unikey=~/^([A-Za-z]+)/;
10691: my $tag=$1;
10692: $tag=~tr/A-Z/a-z/;
10693: print $mfh "\n\<$tag";
10694: foreach (split(/\,/,$metadatakeys{$unikey})) {
10695: my $value=$metadatafields{$unikey.'.'.$_};
10696: $value=~s/\"/\'\'/g;
10697: print $mfh ' '.$_.'="'.$value.'"';
10698: }
10699: print $mfh '>'.
10700: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10701: .'</'.$tag.'>';
10702: }
10703: }
10704: $output = 'ok';
10705: print $logfile "\nWrote metadata";
10706: close($mfh);
10707: } else {
10708: print $logfile "\nFailed to open metadata file";
10709: $output = &mt('Could not write metadata');
10710: }
10711: }
10712: return $output;
10713: }
10714:
10715: sub notifysubscribed {
10716: foreach my $targetsource (@{$modified_urls}){
10717: next unless (ref($targetsource) eq 'ARRAY');
10718: my ($target,$source)=@{$targetsource};
10719: if ($source ne '') {
10720: if (open(my $logfh,">>",$source.'.log')) {
10721: print $logfh "\nCleanup phase: Notifications\n";
10722: my @subscribed=&subscribed_hosts($target);
10723: foreach my $subhost (@subscribed) {
10724: print $logfh "\nNotifying host ".$subhost.':';
10725: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10726: print $logfh $reply;
10727: }
10728: my @subscribedmeta=&subscribed_hosts("$target.meta");
10729: foreach my $subhost (@subscribedmeta) {
10730: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10731: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10732: $subhost);
10733: print $logfh $reply;
10734: }
10735: print $logfh "\n============ Done ============\n";
10736: close($logfh);
10737: }
10738: }
10739: }
10740: return OK;
10741: }
10742:
10743: sub subscribed_hosts {
10744: my ($target) = @_;
10745: my @subscribed;
10746: if (open(my $fh,"<","$target.subscription")) {
10747: while (my $subline=<$fh>) {
10748: if ($subline =~ /^($match_lonid):/) {
10749: my $host = $1;
10750: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10751: unless (grep(/^\Q$host\E$/,@subscribed)) {
10752: push(@subscribed,$host);
10753: }
10754: }
10755: }
10756: }
10757: }
10758: return @subscribed;
10759: }
10760:
10761: sub check_switchserver {
10762: my ($dom,$confname) = @_;
10763: my ($allowed,$switchserver);
10764: my $home = &Apache::lonnet::homeserver($confname,$dom);
10765: if ($home eq 'no_host') {
10766: $home = &Apache::lonnet::domain($dom,'primary');
10767: }
10768: my @ids=&Apache::lonnet::current_machine_ids();
10769: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10770: if (!$allowed) {
10771: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
10772: }
10773: return $switchserver;
10774: }
10775:
10776: sub modify_quotas {
10777: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10778: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
10779: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
10780: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10781: $validationfieldsref);
10782: if ($action eq 'quotas') {
10783: $context = 'tools';
10784: } else {
10785: $context = $action;
10786: }
10787: if ($context eq 'requestcourses') {
10788: @usertools = ('official','unofficial','community','textbook');
10789: @options =('norequest','approval','validate','autolimit');
10790: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10791: %titles = &courserequest_titles();
10792: $toolregexp = join('|',@usertools);
10793: %conditions = &courserequest_conditions();
10794: $confname = $dom.'-domainconfig';
10795: my $servadm = $r->dir_config('lonAdmEMail');
10796: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10797: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10798: &Apache::loncoursequeueadmin::requestcourses_validation_types();
10799: } elsif ($context eq 'requestauthor') {
10800: @usertools = ('author');
10801: %titles = &authorrequest_titles();
10802: } else {
10803: @usertools = ('aboutme','blog','webdav','portfolio');
10804: %titles = &tool_titles();
10805: }
10806: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10807: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10808: foreach my $key (keys(%env)) {
10809: if ($context eq 'requestcourses') {
10810: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10811: my $item = $1;
10812: my $type = $2;
10813: if ($type =~ /^limit_(.+)/) {
10814: $limithash{$item}{$1} = $env{$key};
10815: } else {
10816: $confhash{$item}{$type} = $env{$key};
10817: }
10818: }
10819: } elsif ($context eq 'requestauthor') {
10820: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10821: $confhash{$1} = $env{$key};
10822: }
10823: } else {
10824: if ($key =~ /^form\.quota_(.+)$/) {
10825: $confhash{'defaultquota'}{$1} = $env{$key};
10826: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10827: $confhash{'authorquota'}{$1} = $env{$key};
10828: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
10829: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10830: }
10831: }
10832: }
10833: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
10834: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
10835: @approvalnotify = sort(@approvalnotify);
10836: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
10837: my @crstypes = ('official','unofficial','community','textbook');
10838: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10839: foreach my $type (@hasuniquecode) {
10840: if (grep(/^\Q$type\E$/,@crstypes)) {
10841: $confhash{'uniquecode'}{$type} = 1;
10842: }
10843: }
10844: my (%newbook,%allpos);
10845: if ($context eq 'requestcourses') {
10846: foreach my $type ('textbooks','templates') {
10847: @{$allpos{$type}} = ();
10848: my $invalid;
10849: if ($type eq 'textbooks') {
10850: $invalid = &mt('Invalid LON-CAPA course for textbook');
10851: } else {
10852: $invalid = &mt('Invalid LON-CAPA course for template');
10853: }
10854: if ($env{'form.'.$type.'_addbook'}) {
10855: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10856: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10857: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10858: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10859: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10860: } else {
10861: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10862: my $position = $env{'form.'.$type.'_addbook_pos'};
10863: $position =~ s/\D+//g;
10864: if ($position ne '') {
10865: $allpos{$type}[$position] = $newbook{$type};
10866: }
10867: }
10868: } else {
10869: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10870: }
10871: }
10872: }
10873: }
10874: if (ref($domconfig{$action}) eq 'HASH') {
10875: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10876: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10877: $changes{'notify'}{'approval'} = 1;
10878: }
10879: } else {
10880: if ($confhash{'notify'}{'approval'}) {
10881: $changes{'notify'}{'approval'} = 1;
10882: }
10883: }
10884: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10885: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10886: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10887: unless ($confhash{'uniquecode'}{$crstype}) {
10888: $changes{'uniquecode'} = 1;
10889: }
10890: }
10891: unless ($changes{'uniquecode'}) {
10892: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10893: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10894: $changes{'uniquecode'} = 1;
10895: }
10896: }
10897: }
10898: } else {
10899: $changes{'uniquecode'} = 1;
10900: }
10901: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10902: $changes{'uniquecode'} = 1;
10903: }
10904: if ($context eq 'requestcourses') {
10905: foreach my $type ('textbooks','templates') {
10906: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10907: my %deletions;
10908: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10909: if (@todelete) {
10910: map { $deletions{$_} = 1; } @todelete;
10911: }
10912: my %imgdeletions;
10913: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10914: if (@todeleteimages) {
10915: map { $imgdeletions{$_} = 1; } @todeleteimages;
10916: }
10917: my $maxnum = $env{'form.'.$type.'_maxnum'};
10918: for (my $i=0; $i<=$maxnum; $i++) {
10919: my $itemid = $env{'form.'.$type.'_id_'.$i};
10920: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10921: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10922: if ($deletions{$key}) {
10923: if ($domconfig{$action}{$type}{$key}{'image'}) {
10924: #FIXME need to obsolete item in RES space
10925: }
10926: next;
10927: } else {
10928: my $newpos = $env{'form.'.$itemid};
10929: $newpos =~ s/\D+//g;
10930: foreach my $item ('subject','title','publisher','author') {
10931: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10932: ($type eq 'templates'));
10933: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10934: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10935: $changes{$type}{$key} = 1;
10936: }
10937: }
10938: $allpos{$type}[$newpos] = $key;
10939: }
10940: if ($imgdeletions{$key}) {
10941: $changes{$type}{$key} = 1;
10942: #FIXME need to obsolete item in RES space
10943: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10944: my ($cdom,$cnum) = split(/_/,$key);
10945: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10946: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10947: } else {
10948: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10949: $cdom,$cnum,$type,$configuserok,
10950: $switchserver,$author_ok);
10951: if ($imgurl) {
10952: $confhash{$type}{$key}{'image'} = $imgurl;
10953: $changes{$type}{$key} = 1;
10954: }
10955: if ($error) {
10956: &Apache::lonnet::logthis($error);
10957: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10958: }
10959: }
10960: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10961: $confhash{$type}{$key}{'image'} =
10962: $domconfig{$action}{$type}{$key}{'image'};
10963: }
10964: }
10965: }
10966: }
10967: }
10968: }
10969: } else {
10970: if ($confhash{'notify'}{'approval'}) {
10971: $changes{'notify'}{'approval'} = 1;
10972: }
10973: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10974: $changes{'uniquecode'} = 1;
10975: }
10976: }
10977: if ($context eq 'requestcourses') {
10978: foreach my $type ('textbooks','templates') {
10979: if ($newbook{$type}) {
10980: $changes{$type}{$newbook{$type}} = 1;
10981: foreach my $item ('subject','title','publisher','author') {
10982: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10983: ($type eq 'template'));
10984: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10985: if ($env{'form.'.$type.'_addbook_'.$item}) {
10986: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10987: }
10988: }
10989: if ($type eq 'textbooks') {
10990: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10991: my ($cdom,$cnum) = split(/_/,$newbook{$type});
10992: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10993: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10994: } else {
10995: my ($imageurl,$error) =
10996: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10997: $configuserok,$switchserver,$author_ok);
10998: if ($imageurl) {
10999: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11000: }
11001: if ($error) {
11002: &Apache::lonnet::logthis($error);
11003: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11004: }
11005: }
11006: }
11007: }
11008: }
11009: if (@{$allpos{$type}} > 0) {
11010: my $idx = 0;
11011: foreach my $item (@{$allpos{$type}}) {
11012: if ($item ne '') {
11013: $confhash{$type}{$item}{'order'} = $idx;
11014: if (ref($domconfig{$action}) eq 'HASH') {
11015: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11016: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11017: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11018: $changes{$type}{$item} = 1;
11019: }
11020: }
11021: }
11022: }
11023: $idx ++;
11024: }
11025: }
11026: }
11027: }
11028: if (ref($validationitemsref) eq 'ARRAY') {
11029: foreach my $item (@{$validationitemsref}) {
11030: if ($item eq 'fields') {
11031: my @changed;
11032: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11033: if (@{$confhash{'validation'}{$item}} > 0) {
11034: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11035: }
11036: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11037: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11038: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11039: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11040: $domconfig{'requestcourses'}{'validation'}{$item});
11041: } else {
11042: @changed = @{$confhash{'validation'}{$item}};
11043: }
11044: } else {
11045: @changed = @{$confhash{'validation'}{$item}};
11046: }
11047: } else {
11048: @changed = @{$confhash{'validation'}{$item}};
11049: }
11050: if (@changed) {
11051: if ($confhash{'validation'}{$item}) {
11052: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11053: } else {
11054: $changes{'validation'}{$item} = &mt('None');
11055: }
11056: }
11057: } else {
11058: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11059: if ($item eq 'markup') {
11060: if ($env{'form.requestcourses_validation_'.$item}) {
11061: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11062: }
11063: }
11064: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11065: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11066: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11067: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11068: }
11069: } else {
11070: if ($confhash{'validation'}{$item} ne '') {
11071: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11072: }
11073: }
11074: } else {
11075: if ($confhash{'validation'}{$item} ne '') {
11076: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11077: }
11078: }
11079: }
11080: }
11081: }
11082: if ($env{'form.validationdc'}) {
11083: my $newval = $env{'form.validationdc'};
11084: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
11085: if (exists($domcoords{$newval})) {
11086: $confhash{'validation'}{'dc'} = $newval;
11087: }
11088: }
11089: if (ref($confhash{'validation'}) eq 'HASH') {
11090: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11091: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11092: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11093: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11094: if ($confhash{'validation'}{'dc'} eq '') {
11095: $changes{'validation'}{'dc'} = &mt('None');
11096: } else {
11097: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11098: }
11099: }
11100: } elsif ($confhash{'validation'}{'dc'} ne '') {
11101: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11102: }
11103: } elsif ($confhash{'validation'}{'dc'} ne '') {
11104: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11105: }
11106: } elsif ($confhash{'validation'}{'dc'} ne '') {
11107: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11108: }
11109: } else {
11110: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11111: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11112: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11113: $changes{'validation'}{'dc'} = &mt('None');
11114: }
11115: }
11116: }
11117: }
11118: }
11119: } else {
11120: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
11121: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
11122: }
11123: foreach my $item (@usertools) {
11124: foreach my $type (@{$types},'default','_LC_adv') {
11125: my $unset;
11126: if ($context eq 'requestcourses') {
11127: $unset = '0';
11128: if ($type eq '_LC_adv') {
11129: $unset = '';
11130: }
11131: if ($confhash{$item}{$type} eq 'autolimit') {
11132: $confhash{$item}{$type} .= '=';
11133: unless ($limithash{$item}{$type} =~ /\D/) {
11134: $confhash{$item}{$type} .= $limithash{$item}{$type};
11135: }
11136: }
11137: } elsif ($context eq 'requestauthor') {
11138: $unset = '0';
11139: if ($type eq '_LC_adv') {
11140: $unset = '';
11141: }
11142: } else {
11143: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11144: $confhash{$item}{$type} = 1;
11145: } else {
11146: $confhash{$item}{$type} = 0;
11147: }
11148: }
11149: if (ref($domconfig{$action}) eq 'HASH') {
11150: if ($action eq 'requestauthor') {
11151: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11152: $changes{$type} = 1;
11153: }
11154: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
11155: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11156: $changes{$item}{$type} = 1;
11157: }
11158: } else {
11159: if ($context eq 'requestcourses') {
11160: if ($confhash{$item}{$type} ne $unset) {
11161: $changes{$item}{$type} = 1;
11162: }
11163: } else {
11164: if (!$confhash{$item}{$type}) {
11165: $changes{$item}{$type} = 1;
11166: }
11167: }
11168: }
11169: } else {
11170: if ($context eq 'requestcourses') {
11171: if ($confhash{$item}{$type} ne $unset) {
11172: $changes{$item}{$type} = 1;
11173: }
11174: } elsif ($context eq 'requestauthor') {
11175: if ($confhash{$type} ne $unset) {
11176: $changes{$type} = 1;
11177: }
11178: } else {
11179: if (!$confhash{$item}{$type}) {
11180: $changes{$item}{$type} = 1;
11181: }
11182: }
11183: }
11184: }
11185: }
11186: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
11187: if (ref($domconfig{'quotas'}) eq 'HASH') {
11188: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11189: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11190: if (exists($confhash{'defaultquota'}{$key})) {
11191: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11192: $changes{'defaultquota'}{$key} = 1;
11193: }
11194: } else {
11195: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
11196: }
11197: }
11198: } else {
11199: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11200: if (exists($confhash{'defaultquota'}{$key})) {
11201: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11202: $changes{'defaultquota'}{$key} = 1;
11203: }
11204: } else {
11205: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
11206: }
11207: }
11208: }
11209: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11210: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11211: if (exists($confhash{'authorquota'}{$key})) {
11212: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11213: $changes{'authorquota'}{$key} = 1;
11214: }
11215: } else {
11216: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11217: }
11218: }
11219: }
11220: }
11221: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11222: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11223: if (ref($domconfig{'quotas'}) eq 'HASH') {
11224: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11225: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11226: $changes{'defaultquota'}{$key} = 1;
11227: }
11228: } else {
11229: if (!exists($domconfig{'quotas'}{$key})) {
11230: $changes{'defaultquota'}{$key} = 1;
11231: }
11232: }
11233: } else {
11234: $changes{'defaultquota'}{$key} = 1;
11235: }
11236: }
11237: }
11238: if (ref($confhash{'authorquota'}) eq 'HASH') {
11239: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11240: if (ref($domconfig{'quotas'}) eq 'HASH') {
11241: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11242: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11243: $changes{'authorquota'}{$key} = 1;
11244: }
11245: } else {
11246: $changes{'authorquota'}{$key} = 1;
11247: }
11248: } else {
11249: $changes{'authorquota'}{$key} = 1;
11250: }
11251: }
11252: }
11253: }
11254:
11255: if ($context eq 'requestauthor') {
11256: $domdefaults{'requestauthor'} = \%confhash;
11257: } else {
11258: foreach my $key (keys(%confhash)) {
11259: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
11260: $domdefaults{$key} = $confhash{$key};
11261: }
11262: }
11263: }
11264:
11265: my %quotahash = (
11266: $action => { %confhash }
11267: );
11268: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11269: $dom);
11270: if ($putresult eq 'ok') {
11271: if (keys(%changes) > 0) {
11272: my $cachetime = 24*60*60;
11273: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11274: if (ref($lastactref) eq 'HASH') {
11275: $lastactref->{'domdefaults'} = 1;
11276: }
11277: $resulttext = &mt('Changes made:').'<ul>';
11278: unless (($context eq 'requestcourses') ||
11279: ($context eq 'requestauthor')) {
11280: if (ref($changes{'defaultquota'}) eq 'HASH') {
11281: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11282: foreach my $type (@{$types},'default') {
11283: if (defined($changes{'defaultquota'}{$type})) {
11284: my $typetitle = $usertypes->{$type};
11285: if ($type eq 'default') {
11286: $typetitle = $othertitle;
11287: }
11288: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
11289: }
11290: }
11291: $resulttext .= '</ul></li>';
11292: }
11293: if (ref($changes{'authorquota'}) eq 'HASH') {
11294: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
11295: foreach my $type (@{$types},'default') {
11296: if (defined($changes{'authorquota'}{$type})) {
11297: my $typetitle = $usertypes->{$type};
11298: if ($type eq 'default') {
11299: $typetitle = $othertitle;
11300: }
11301: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
11302: }
11303: }
11304: $resulttext .= '</ul></li>';
11305: }
11306: }
11307: my %newenv;
11308: foreach my $item (@usertools) {
11309: my (%haschgs,%inconf);
11310: if ($context eq 'requestauthor') {
11311: %haschgs = %changes;
11312: %inconf = %confhash;
11313: } else {
11314: if (ref($changes{$item}) eq 'HASH') {
11315: %haschgs = %{$changes{$item}};
11316: }
11317: if (ref($confhash{$item}) eq 'HASH') {
11318: %inconf = %{$confhash{$item}};
11319: }
11320: }
11321: if (keys(%haschgs) > 0) {
11322: my $newacc =
11323: &Apache::lonnet::usertools_access($env{'user.name'},
11324: $env{'user.domain'},
11325: $item,'reload',$context);
11326: if (($context eq 'requestcourses') ||
11327: ($context eq 'requestauthor')) {
11328: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11329: $newenv{'environment.canrequest.'.$item} = $newacc;
11330: }
11331: } else {
11332: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11333: $newenv{'environment.availabletools.'.$item} = $newacc;
11334: }
11335: }
11336: unless ($context eq 'requestauthor') {
11337: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11338: }
11339: foreach my $type (@{$types},'default','_LC_adv') {
11340: if ($haschgs{$type}) {
11341: my $typetitle = $usertypes->{$type};
11342: if ($type eq 'default') {
11343: $typetitle = $othertitle;
11344: } elsif ($type eq '_LC_adv') {
11345: $typetitle = 'LON-CAPA Advanced Users';
11346: }
11347: if ($inconf{$type}) {
11348: if ($context eq 'requestcourses') {
11349: my $cond;
11350: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
11351: if ($1 eq '') {
11352: $cond = &mt('(Automatic processing of any request).');
11353: } else {
11354: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11355: }
11356: } else {
11357: $cond = $conditions{$inconf{$type}};
11358: }
11359: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
11360: } elsif ($context eq 'requestauthor') {
11361: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11362: $titles{$inconf{$type}},$typetitle);
11363:
11364: } else {
11365: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11366: }
11367: } else {
11368: if ($type eq '_LC_adv') {
11369: if ($inconf{$type} eq '0') {
11370: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11371: } else {
11372: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11373: }
11374: } else {
11375: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11376: }
11377: }
11378: }
11379: }
11380: unless ($context eq 'requestauthor') {
11381: $resulttext .= '</ul></li>';
11382: }
11383: }
11384: }
11385: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
11386: if (ref($changes{'notify'}) eq 'HASH') {
11387: if ($changes{'notify'}{'approval'}) {
11388: if (ref($confhash{'notify'}) eq 'HASH') {
11389: if ($confhash{'notify'}{'approval'}) {
11390: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11391: } else {
11392: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
11393: }
11394: }
11395: }
11396: }
11397: }
11398: if ($action eq 'requestcourses') {
11399: my @offon = ('off','on');
11400: if ($changes{'uniquecode'}) {
11401: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11402: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11403: $resulttext .= '<li>'.
11404: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11405: '</li>';
11406: } else {
11407: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11408: '</li>';
11409: }
11410: }
11411: foreach my $type ('textbooks','templates') {
11412: if (ref($changes{$type}) eq 'HASH') {
11413: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11414: foreach my $key (sort(keys(%{$changes{$type}}))) {
11415: my %coursehash = &Apache::lonnet::coursedescription($key);
11416: my $coursetitle = $coursehash{'description'};
11417: my $position = $confhash{$type}{$key}{'order'} + 1;
11418: $resulttext .= '<li>';
11419: foreach my $item ('subject','title','publisher','author') {
11420: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11421: ($type eq 'templates'));
11422: my $name = $item.':';
11423: $name =~ s/^(\w)/\U$1/;
11424: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11425: }
11426: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11427: if ($type eq 'textbooks') {
11428: if ($confhash{$type}{$key}{'image'}) {
11429: $resulttext .= ' '.&mt('Image: [_1]',
11430: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11431: ' alt="Textbook cover" />').'<br />';
11432: }
11433: }
11434: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
11435: }
11436: $resulttext .= '</ul></li>';
11437: }
11438: }
11439: if (ref($changes{'validation'}) eq 'HASH') {
11440: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11441: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11442: foreach my $item (@{$validationitemsref}) {
11443: if (exists($changes{'validation'}{$item})) {
11444: if ($item eq 'markup') {
11445: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11446: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11447: } else {
11448: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11449: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11450: }
11451: }
11452: }
11453: if (exists($changes{'validation'}{'dc'})) {
11454: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11455: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11456: }
11457: $resulttext .= '</ul></li>';
11458: }
11459: }
11460: }
11461: $resulttext .= '</ul>';
11462: if (keys(%newenv)) {
11463: &Apache::lonnet::appenv(\%newenv);
11464: }
11465: } else {
11466: if ($context eq 'requestcourses') {
11467: $resulttext = &mt('No changes made to rights to request creation of courses.');
11468: } elsif ($context eq 'requestauthor') {
11469: $resulttext = &mt('No changes made to rights to request author space.');
11470: } else {
11471: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
11472: }
11473: }
11474: } else {
11475: $resulttext = '<span class="LC_error">'.
11476: &mt('An error occurred: [_1]',$putresult).'</span>';
11477: }
11478: if ($errors) {
11479: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11480: '<ul>'.$errors.'</ul></p>';
11481: }
11482: return $resulttext;
11483: }
11484:
11485: sub process_textbook_image {
11486: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
11487: my $filename = $env{'form.'.$caller.'.filename'};
11488: my ($error,$url);
11489: my ($width,$height) = (50,50);
11490: if ($configuserok eq 'ok') {
11491: if ($switchserver) {
11492: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11493: $switchserver);
11494: } elsif ($author_ok eq 'ok') {
11495: my ($result,$imageurl) =
11496: &publishlogo($r,'upload',$caller,$dom,$confname,
11497: "$type/$cdom/$cnum/cover",$width,$height);
11498: if ($result eq 'ok') {
11499: $url = $imageurl;
11500: } else {
11501: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11502: }
11503: } else {
11504: $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);
11505: }
11506: } else {
11507: $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);
11508: }
11509: return ($url,$error);
11510: }
11511:
11512: sub modify_autoenroll {
11513: my ($dom,$lastactref,%domconfig) = @_;
11514: my ($resulttext,%changes);
11515: my %currautoenroll;
11516: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11517: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11518: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11519: }
11520: }
11521: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11522: my %title = ( run => 'Auto-enrollment active',
11523: sender => 'Sender for notification messages',
11524: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11525: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
11526: my @offon = ('off','on');
11527: my $sender_uname = $env{'form.sender_uname'};
11528: my $sender_domain = $env{'form.sender_domain'};
11529: if ($sender_domain eq '') {
11530: $sender_uname = '';
11531: } elsif ($sender_uname eq '') {
11532: $sender_domain = '';
11533: }
11534: my $coowners = $env{'form.autoassign_coowners'};
11535: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
11536: $autofailsafe =~ s{^\s+|\s+$}{}g;
11537: if ($autofailsafe =~ /\D/) {
11538: undef($autofailsafe);
11539: }
11540: my $failsafe = $env{'form.autoenroll_failsafe'};
11541: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
11542: $failsafe = 'off';
11543: undef($autofailsafe);
11544: }
11545: my %autoenrollhash = (
11546: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11547: 'sender_uname' => $sender_uname,
11548: 'sender_domain' => $sender_domain,
11549: 'co-owners' => $coowners,
11550: 'autofailsafe' => $autofailsafe,
11551: 'failsafe' => $failsafe,
11552: }
11553: );
11554: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11555: $dom);
11556: if ($putresult eq 'ok') {
11557: if (exists($currautoenroll{'run'})) {
11558: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11559: $changes{'run'} = 1;
11560: }
11561: } elsif ($autorun) {
11562: if ($env{'form.autoenroll_run'} ne '1') {
11563: $changes{'run'} = 1;
11564: }
11565: }
11566: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
11567: $changes{'sender'} = 1;
11568: }
11569: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
11570: $changes{'sender'} = 1;
11571: }
11572: if ($currautoenroll{'co-owners'} ne '') {
11573: if ($currautoenroll{'co-owners'} ne $coowners) {
11574: $changes{'coowners'} = 1;
11575: }
11576: } elsif ($coowners) {
11577: $changes{'coowners'} = 1;
11578: }
11579: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
11580: $changes{'autofailsafe'} = 1;
11581: }
11582: if ($currautoenroll{'failsafe'} ne $failsafe) {
11583: $changes{'failsafe'} = 1;
11584: }
11585: if (keys(%changes) > 0) {
11586: $resulttext = &mt('Changes made:').'<ul>';
11587: if ($changes{'run'}) {
11588: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11589: }
11590: if ($changes{'sender'}) {
11591: if ($sender_uname eq '' || $sender_domain eq '') {
11592: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11593: } else {
11594: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11595: }
11596: }
11597: if ($changes{'coowners'}) {
11598: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11599: &Apache::loncommon::devalidate_domconfig_cache($dom);
11600: if (ref($lastactref) eq 'HASH') {
11601: $lastactref->{'domainconfig'} = 1;
11602: }
11603: }
11604: if ($changes{'autofailsafe'}) {
11605: if ($autofailsafe ne '') {
11606: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
11607: } else {
11608: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
11609: }
11610: }
11611: if ($changes{'failsafe'}) {
11612: if ($failsafe eq 'off') {
11613: unless ($changes{'autofailsafe'}) {
11614: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
11615: }
11616: } elsif ($failsafe eq 'zero') {
11617: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
11618: } else {
11619: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
11620: }
11621: }
11622: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
11623: &Apache::lonnet::get_domain_defaults($dom,1);
11624: if (ref($lastactref) eq 'HASH') {
11625: $lastactref->{'domdefaults'} = 1;
11626: }
11627: }
11628: $resulttext .= '</ul>';
11629: } else {
11630: $resulttext = &mt('No changes made to auto-enrollment settings');
11631: }
11632: } else {
11633: $resulttext = '<span class="LC_error">'.
11634: &mt('An error occurred: [_1]',$putresult).'</span>';
11635: }
11636: return $resulttext;
11637: }
11638:
11639: sub modify_autoupdate {
11640: my ($dom,%domconfig) = @_;
11641: my ($resulttext,%currautoupdate,%fields,%changes);
11642: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11643: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11644: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11645: }
11646: }
11647: my @offon = ('off','on');
11648: my %title = &Apache::lonlocal::texthash (
11649: run => 'Auto-update:',
11650: classlists => 'Updates to user information in classlists?',
11651: unexpired => 'Skip updates for users without active or future roles?',
11652: lastactive => 'Skip updates for inactive users?',
11653: );
11654: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11655: my %fieldtitles = &Apache::lonlocal::texthash (
11656: id => 'Student/Employee ID',
11657: permanentemail => 'E-mail address',
11658: lastname => 'Last Name',
11659: firstname => 'First Name',
11660: middlename => 'Middle Name',
11661: generation => 'Generation',
11662: );
11663: $othertitle = &mt('All users');
11664: if (keys(%{$usertypes}) > 0) {
11665: $othertitle = &mt('Other users');
11666: }
11667: foreach my $key (keys(%env)) {
11668: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
11669: my ($usertype,$item) = ($1,$2);
11670: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11671: if ($usertype eq 'default') {
11672: push(@{$fields{$1}},$2);
11673: } elsif (ref($types) eq 'ARRAY') {
11674: if (grep(/^\Q$usertype\E$/,@{$types})) {
11675: push(@{$fields{$1}},$2);
11676: }
11677: }
11678: }
11679: }
11680: }
11681: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11682: @lockablenames = sort(@lockablenames);
11683: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11684: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11685: if (@changed) {
11686: $changes{'lockablenames'} = 1;
11687: }
11688: } else {
11689: if (@lockablenames) {
11690: $changes{'lockablenames'} = 1;
11691: }
11692: }
11693: my %updatehash = (
11694: autoupdate => { run => $env{'form.autoupdate_run'},
11695: classlists => $env{'form.classlists'},
11696: unexpired => $env{'form.unexpired'},
11697: fields => {%fields},
11698: lockablenames => \@lockablenames,
11699: }
11700: );
11701: my $lastactivedays;
11702: if ($env{'form.lastactive'}) {
11703: $lastactivedays = $env{'form.lastactivedays'};
11704: $lastactivedays =~ s/^\s+|\s+$//g;
11705: unless ($lastactivedays =~ /^\d+$/) {
11706: undef($lastactivedays);
11707: $env{'form.lastactive'} = 0;
11708: }
11709: }
11710: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
11711: foreach my $key (keys(%currautoupdate)) {
11712: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
11713: if (exists($updatehash{autoupdate}{$key})) {
11714: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11715: $changes{$key} = 1;
11716: }
11717: }
11718: } elsif ($key eq 'fields') {
11719: if (ref($currautoupdate{$key}) eq 'HASH') {
11720: foreach my $item (@{$types},'default') {
11721: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11722: my $change = 0;
11723: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11724: if (!exists($fields{$item})) {
11725: $change = 1;
11726: last;
11727: } elsif (ref($fields{$item}) eq 'ARRAY') {
11728: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
11729: $change = 1;
11730: last;
11731: }
11732: }
11733: }
11734: if ($change) {
11735: push(@{$changes{$key}},$item);
11736: }
11737: }
11738: }
11739: }
11740: } elsif ($key eq 'lockablenames') {
11741: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11742: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11743: if (@changed) {
11744: $changes{'lockablenames'} = 1;
11745: }
11746: } else {
11747: if (@lockablenames) {
11748: $changes{'lockablenames'} = 1;
11749: }
11750: }
11751: }
11752: }
11753: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11754: if (@lockablenames) {
11755: $changes{'lockablenames'} = 1;
11756: }
11757: }
11758: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
11759: if ($updatehash{'autoupdate'}{'unexpired'}) {
11760: $changes{'unexpired'} = 1;
11761: }
11762: }
11763: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
11764: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
11765: $changes{'lastactive'} = 1;
11766: }
11767: }
11768: foreach my $item (@{$types},'default') {
11769: if (defined($fields{$item})) {
11770: if (ref($currautoupdate{'fields'}) eq 'HASH') {
11771: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11772: my $change = 0;
11773: if (ref($fields{$item}) eq 'ARRAY') {
11774: foreach my $type (@{$fields{$item}}) {
11775: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11776: $change = 1;
11777: last;
11778: }
11779: }
11780: }
11781: if ($change) {
11782: push(@{$changes{'fields'}},$item);
11783: }
11784: } else {
11785: push(@{$changes{'fields'}},$item);
11786: }
11787: } else {
11788: push(@{$changes{'fields'}},$item);
11789: }
11790: }
11791: }
11792: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11793: $dom);
11794: if ($putresult eq 'ok') {
11795: if (keys(%changes) > 0) {
11796: $resulttext = &mt('Changes made:').'<ul>';
11797: foreach my $key (sort(keys(%changes))) {
11798: if ($key eq 'lockablenames') {
11799: $resulttext .= '<li>';
11800: if (@lockablenames) {
11801: $usertypes->{'default'} = $othertitle;
11802: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11803: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11804: } else {
11805: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11806: }
11807: $resulttext .= '</li>';
11808: } elsif (ref($changes{$key}) eq 'ARRAY') {
11809: foreach my $item (@{$changes{$key}}) {
11810: my @newvalues;
11811: foreach my $type (@{$fields{$item}}) {
11812: push(@newvalues,$fieldtitles{$type});
11813: }
11814: my $newvaluestr;
11815: if (@newvalues > 0) {
11816: $newvaluestr = join(', ',@newvalues);
11817: } else {
11818: $newvaluestr = &mt('none');
11819: }
11820: if ($item eq 'default') {
11821: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
11822: } else {
11823: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
11824: }
11825: }
11826: } else {
11827: my $newvalue;
11828: if ($key eq 'run') {
11829: $newvalue = $offon[$env{'form.autoupdate_run'}];
11830: } elsif ($key eq 'lastactive') {
11831: $newvalue = $offon[$env{'form.lastactive'}];
11832: unless ($lastactivedays eq '') {
11833: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
11834: }
11835: } else {
11836: $newvalue = $offon[$env{'form.'.$key}];
11837: }
11838: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11839: }
11840: }
11841: $resulttext .= '</ul>';
11842: } else {
11843: $resulttext = &mt('No changes made to autoupdates');
11844: }
11845: } else {
11846: $resulttext = '<span class="LC_error">'.
11847: &mt('An error occurred: [_1]',$putresult).'</span>';
11848: }
11849: return $resulttext;
11850: }
11851:
11852: sub modify_autocreate {
11853: my ($dom,%domconfig) = @_;
11854: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11855: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11856: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11857: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11858: }
11859: }
11860: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11861: req => 'Auto-creation of validated requests for official courses',
11862: xmldc => 'Identity of course creator of courses from XML files',
11863: );
11864: my @types = ('xml','req');
11865: foreach my $item (@types) {
11866: $newvals{$item} = $env{'form.autocreate_'.$item};
11867: $newvals{$item} =~ s/\D//g;
11868: $newvals{$item} = 0 if ($newvals{$item} eq '');
11869: }
11870: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
11871: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
11872: unless (exists($domcoords{$newvals{'xmldc'}})) {
11873: $newvals{'xmldc'} = '';
11874: }
11875: %autocreatehash = (
11876: autocreate => { xml => $newvals{'xml'},
11877: req => $newvals{'req'},
11878: }
11879: );
11880: if ($newvals{'xmldc'} ne '') {
11881: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11882: }
11883: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11884: $dom);
11885: if ($putresult eq 'ok') {
11886: my @items = @types;
11887: if ($newvals{'xml'}) {
11888: push(@items,'xmldc');
11889: }
11890: foreach my $item (@items) {
11891: if (exists($currautocreate{$item})) {
11892: if ($currautocreate{$item} ne $newvals{$item}) {
11893: $changes{$item} = 1;
11894: }
11895: } elsif ($newvals{$item}) {
11896: $changes{$item} = 1;
11897: }
11898: }
11899: if (keys(%changes) > 0) {
11900: my @offon = ('off','on');
11901: $resulttext = &mt('Changes made:').'<ul>';
11902: foreach my $item (@types) {
11903: if ($changes{$item}) {
11904: my $newtxt = $offon[$newvals{$item}];
11905: $resulttext .= '<li>'.
11906: &mt("$title{$item} set to [_1]$newtxt [_2]",
11907: '<b>','</b>').
11908: '</li>';
11909: }
11910: }
11911: if ($changes{'xmldc'}) {
11912: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11913: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
11914: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
11915: }
11916: $resulttext .= '</ul>';
11917: } else {
11918: $resulttext = &mt('No changes made to auto-creation settings');
11919: }
11920: } else {
11921: $resulttext = '<span class="LC_error">'.
11922: &mt('An error occurred: [_1]',$putresult).'</span>';
11923: }
11924: return $resulttext;
11925: }
11926:
11927: sub modify_directorysrch {
11928: my ($dom,$lastactref,%domconfig) = @_;
11929: my ($resulttext,%changes);
11930: my %currdirsrch;
11931: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11932: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11933: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11934: }
11935: }
11936: my %title = ( available => 'Institutional directory search available',
11937: localonly => 'Other domains can search institution',
11938: lcavailable => 'LON-CAPA directory search available',
11939: lclocalonly => 'Other domains can search LON-CAPA domain',
11940: searchby => 'Search types',
11941: searchtypes => 'Search latitude');
11942: my @offon = ('off','on');
11943: my @otherdoms = ('Yes','No');
11944:
11945: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
11946: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11947: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11948:
11949: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11950: if (keys(%{$usertypes}) == 0) {
11951: @cansearch = ('default');
11952: } else {
11953: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11954: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11955: if (!grep(/^\Q$type\E$/,@cansearch)) {
11956: push(@{$changes{'cansearch'}},$type);
11957: }
11958: }
11959: foreach my $type (@cansearch) {
11960: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11961: push(@{$changes{'cansearch'}},$type);
11962: }
11963: }
11964: } else {
11965: push(@{$changes{'cansearch'}},@cansearch);
11966: }
11967: }
11968:
11969: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11970: foreach my $by (@{$currdirsrch{'searchby'}}) {
11971: if (!grep(/^\Q$by\E$/,@searchby)) {
11972: push(@{$changes{'searchby'}},$by);
11973: }
11974: }
11975: foreach my $by (@searchby) {
11976: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11977: push(@{$changes{'searchby'}},$by);
11978: }
11979: }
11980: } else {
11981: push(@{$changes{'searchby'}},@searchby);
11982: }
11983:
11984: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11985: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11986: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11987: push(@{$changes{'searchtypes'}},$type);
11988: }
11989: }
11990: foreach my $type (@searchtypes) {
11991: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11992: push(@{$changes{'searchtypes'}},$type);
11993: }
11994: }
11995: } else {
11996: if (exists($currdirsrch{'searchtypes'})) {
11997: foreach my $type (@searchtypes) {
11998: if ($type ne $currdirsrch{'searchtypes'}) {
11999: push(@{$changes{'searchtypes'}},$type);
12000: }
12001: }
12002: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12003: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12004: }
12005: } else {
12006: push(@{$changes{'searchtypes'}},@searchtypes);
12007: }
12008: }
12009:
12010: my %dirsrch_hash = (
12011: directorysrch => { available => $env{'form.dirsrch_available'},
12012: cansearch => \@cansearch,
12013: localonly => $env{'form.dirsrch_instlocalonly'},
12014: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12015: lcavailable => $env{'form.dirsrch_domavailable'},
12016: searchby => \@searchby,
12017: searchtypes => \@searchtypes,
12018: }
12019: );
12020: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12021: $dom);
12022: if ($putresult eq 'ok') {
12023: if (exists($currdirsrch{'available'})) {
12024: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12025: $changes{'available'} = 1;
12026: }
12027: } else {
12028: if ($env{'form.dirsrch_available'} eq '1') {
12029: $changes{'available'} = 1;
12030: }
12031: }
12032: if (exists($currdirsrch{'lcavailable'})) {
12033: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12034: $changes{'lcavailable'} = 1;
12035: }
12036: } else {
12037: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12038: $changes{'lcavailable'} = 1;
12039: }
12040: }
12041: if (exists($currdirsrch{'localonly'})) {
12042: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12043: $changes{'localonly'} = 1;
12044: }
12045: } else {
12046: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
12047: $changes{'localonly'} = 1;
12048: }
12049: }
12050: if (exists($currdirsrch{'lclocalonly'})) {
12051: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12052: $changes{'lclocalonly'} = 1;
12053: }
12054: } else {
12055: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12056: $changes{'lclocalonly'} = 1;
12057: }
12058: }
12059: if (keys(%changes) > 0) {
12060: $resulttext = &mt('Changes made:').'<ul>';
12061: if ($changes{'available'}) {
12062: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12063: }
12064: if ($changes{'lcavailable'}) {
12065: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12066: }
12067: if ($changes{'localonly'}) {
12068: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
12069: }
12070: if ($changes{'lclocalonly'}) {
12071: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
12072: }
12073: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12074: my $chgtext;
12075: if (ref($usertypes) eq 'HASH') {
12076: if (keys(%{$usertypes}) > 0) {
12077: foreach my $type (@{$types}) {
12078: if (grep(/^\Q$type\E$/,@cansearch)) {
12079: $chgtext .= $usertypes->{$type}.'; ';
12080: }
12081: }
12082: if (grep(/^default$/,@cansearch)) {
12083: $chgtext .= $othertitle;
12084: } else {
12085: $chgtext =~ s/\; $//;
12086: }
12087: $resulttext .=
12088: '<li>'.
12089: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12090: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12091: '</li>';
12092: }
12093: }
12094: }
12095: if (ref($changes{'searchby'}) eq 'ARRAY') {
12096: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12097: my $chgtext;
12098: foreach my $type (@{$titleorder}) {
12099: if (grep(/^\Q$type\E$/,@searchby)) {
12100: if (defined($searchtitles->{$type})) {
12101: $chgtext .= $searchtitles->{$type}.'; ';
12102: }
12103: }
12104: }
12105: $chgtext =~ s/\; $//;
12106: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12107: }
12108: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12109: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12110: my $chgtext;
12111: foreach my $type (@{$srchtypeorder}) {
12112: if (grep(/^\Q$type\E$/,@searchtypes)) {
12113: if (defined($srchtypes_desc->{$type})) {
12114: $chgtext .= $srchtypes_desc->{$type}.'; ';
12115: }
12116: }
12117: }
12118: $chgtext =~ s/\; $//;
12119: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
12120: }
12121: $resulttext .= '</ul>';
12122: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12123: if (ref($lastactref) eq 'HASH') {
12124: $lastactref->{'directorysrch'} = 1;
12125: }
12126: } else {
12127: $resulttext = &mt('No changes made to directory search settings');
12128: }
12129: } else {
12130: $resulttext = '<span class="LC_error">'.
12131: &mt('An error occurred: [_1]',$putresult).'</span>';
12132: }
12133: return $resulttext;
12134: }
12135:
12136: sub modify_contacts {
12137: my ($dom,$lastactref,%domconfig) = @_;
12138: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12139: if (ref($domconfig{'contacts'}) eq 'HASH') {
12140: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12141: $currsetting{$key} = $domconfig{'contacts'}{$key};
12142: }
12143: }
12144: my (%others,%to,%bcc,%includestr,%includeloc);
12145: my @contacts = ('supportemail','adminemail');
12146: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12147: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
12148: my @toggles = ('reporterrors','reportupdates','reportstatus');
12149: my @lonstatus = ('threshold','sysmail','weights','excluded');
12150: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
12151: foreach my $type (@mailings) {
12152: @{$newsetting{$type}} =
12153: &Apache::loncommon::get_env_multiple('form.'.$type);
12154: foreach my $item (@contacts) {
12155: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12156: $contacts_hash{contacts}{$type}{$item} = 1;
12157: } else {
12158: $contacts_hash{contacts}{$type}{$item} = 0;
12159: }
12160: }
12161: $others{$type} = $env{'form.'.$type.'_others'};
12162: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
12163: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12164: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12165: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
12166: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12167: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12168: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12169: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12170: }
12171: }
12172: }
12173: foreach my $item (@contacts) {
12174: $to{$item} = $env{'form.'.$item};
12175: $contacts_hash{'contacts'}{$item} = $to{$item};
12176: }
12177: foreach my $item (@toggles) {
12178: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12179: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12180: }
12181: }
12182: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
12183: foreach my $item (@lonstatus) {
12184: if ($item eq 'excluded') {
12185: my (%serverhomes,@excluded);
12186: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
12187: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
12188: if (@possexcluded) {
12189: foreach my $id (sort(@possexcluded)) {
12190: if ($serverhomes{$id}) {
12191: push(@excluded,$id);
12192: }
12193: }
12194: }
12195: if (@excluded) {
12196: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
12197: }
12198: } elsif ($item eq 'weights') {
12199: foreach my $type ('E','W','N','U') {
12200: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
12201: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
12202: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
12203: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
12204: $env{'form.error'.$item.'_'.$type};
12205: }
12206: }
12207: }
12208: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
12209: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
12210: if ($env{'form.error'.$item} =~ /^\d+$/) {
12211: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
12212: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
12213: }
12214: }
12215: }
12216: }
12217: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12218: foreach my $field (@{$fields}) {
12219: if (ref($possoptions->{$field}) eq 'ARRAY') {
12220: my $value = $env{'form.helpform_'.$field};
12221: $value =~ s/^\s+|\s+$//g;
12222: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
12223: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
12224: if ($field eq 'screenshot') {
12225: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12226: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
12227: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
12228: }
12229: }
12230: }
12231: }
12232: }
12233: }
12234: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12235: my (@statuses,%usertypeshash,@overrides);
12236: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12237: @statuses = @{$types};
12238: if (ref($usertypes) eq 'HASH') {
12239: %usertypeshash = %{$usertypes};
12240: }
12241: }
12242: if (@statuses) {
12243: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12244: foreach my $type (@possoverrides) {
12245: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12246: push(@overrides,$type);
12247: }
12248: }
12249: if (@overrides) {
12250: foreach my $type (@overrides) {
12251: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12252: foreach my $item (@contacts) {
12253: if (grep(/^\Q$item\E$/,@standard)) {
12254: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12255: $newsetting{'override_'.$type}{$item} = 1;
12256: } else {
12257: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12258: $newsetting{'override_'.$type}{$item} = 0;
12259: }
12260: }
12261: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12262: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12263: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12264: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12265: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12266: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12267: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12268: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12269: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12270: }
12271: }
12272: }
12273: }
12274: if (keys(%currsetting) > 0) {
12275: foreach my $item (@contacts) {
12276: if ($to{$item} ne $currsetting{$item}) {
12277: $changes{$item} = 1;
12278: }
12279: }
12280: foreach my $type (@mailings) {
12281: foreach my $item (@contacts) {
12282: if (ref($currsetting{$type}) eq 'HASH') {
12283: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12284: push(@{$changes{$type}},$item);
12285: }
12286: } else {
12287: push(@{$changes{$type}},@{$newsetting{$type}});
12288: }
12289: }
12290: if ($others{$type} ne $currsetting{$type}{'others'}) {
12291: push(@{$changes{$type}},'others');
12292: }
12293: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12294: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12295: push(@{$changes{$type}},'bcc');
12296: }
12297: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12298: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12299: push(@{$changes{$type}},'include');
12300: }
12301: }
12302: }
12303: if (ref($fields) eq 'ARRAY') {
12304: if (ref($currsetting{'helpform'}) eq 'HASH') {
12305: foreach my $field (@{$fields}) {
12306: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12307: push(@{$changes{'helpform'}},$field);
12308: }
12309: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12310: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12311: push(@{$changes{'helpform'}},'maxsize');
12312: }
12313: }
12314: }
12315: } else {
12316: foreach my $field (@{$fields}) {
12317: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12318: push(@{$changes{'helpform'}},$field);
12319: }
12320: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12321: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12322: push(@{$changes{'helpform'}},'maxsize');
12323: }
12324: }
12325: }
12326: }
12327: }
12328: if (@statuses) {
12329: if (ref($currsetting{'overrides'}) eq 'HASH') {
12330: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12331: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12332: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12333: foreach my $item (@contacts,'bcc','others','include') {
12334: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12335: push(@{$changes{'overrides'}},$key);
12336: last;
12337: }
12338: }
12339: } else {
12340: push(@{$changes{'overrides'}},$key);
12341: }
12342: }
12343: }
12344: foreach my $key (@overrides) {
12345: unless (exists($currsetting{'overrides'}{$key})) {
12346: push(@{$changes{'overrides'}},$key);
12347: }
12348: }
12349: } else {
12350: foreach my $key (@overrides) {
12351: push(@{$changes{'overrides'}},$key);
12352: }
12353: }
12354: }
12355: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
12356: foreach my $key ('excluded','weights','threshold','sysmail') {
12357: if ($key eq 'excluded') {
12358: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12359: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
12360: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12361: (@{$currsetting{'lonstatus'}{$key}})) {
12362: my @diffs =
12363: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
12364: $currsetting{'lonstatus'}{$key});
12365: if (@diffs) {
12366: push(@{$changes{'lonstatus'}},$key);
12367: }
12368: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
12369: push(@{$changes{'lonstatus'}},$key);
12370: }
12371: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
12372: (@{$currsetting{'lonstatus'}{$key}})) {
12373: push(@{$changes{'lonstatus'}},$key);
12374: }
12375: } elsif ($key eq 'weights') {
12376: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
12377: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
12378: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12379: foreach my $type ('E','W','N','U') {
12380: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
12381: $currsetting{'lonstatus'}{$key}{$type}) {
12382: push(@{$changes{'lonstatus'}},$key);
12383: last;
12384: }
12385: }
12386: } else {
12387: foreach my $type ('E','W','N','U') {
12388: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
12389: push(@{$changes{'lonstatus'}},$key);
12390: last;
12391: }
12392: }
12393: }
12394: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
12395: foreach my $type ('E','W','N','U') {
12396: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
12397: push(@{$changes{'lonstatus'}},$key);
12398: last;
12399: }
12400: }
12401: }
12402: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
12403: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12404: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12405: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12406: push(@{$changes{'lonstatus'}},$key);
12407: }
12408: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12409: push(@{$changes{'lonstatus'}},$key);
12410: }
12411: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12412: push(@{$changes{'lonstatus'}},$key);
12413: }
12414: }
12415: }
12416: } else {
12417: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12418: foreach my $key ('excluded','weights','threshold','sysmail') {
12419: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12420: push(@{$changes{'lonstatus'}},$key);
12421: }
12422: }
12423: }
12424: }
12425: } else {
12426: my %default;
12427: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12428: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12429: $default{'errormail'} = 'adminemail';
12430: $default{'packagesmail'} = 'adminemail';
12431: $default{'helpdeskmail'} = 'supportemail';
12432: $default{'otherdomsmail'} = 'supportemail';
12433: $default{'lonstatusmail'} = 'adminemail';
12434: $default{'requestsmail'} = 'adminemail';
12435: $default{'updatesmail'} = 'adminemail';
12436: $default{'hostipmail'} = 'adminemail';
12437: foreach my $item (@contacts) {
12438: if ($to{$item} ne $default{$item}) {
12439: $changes{$item} = 1;
12440: }
12441: }
12442: foreach my $type (@mailings) {
12443: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12444: push(@{$changes{$type}},@{$newsetting{$type}});
12445: }
12446: if ($others{$type} ne '') {
12447: push(@{$changes{$type}},'others');
12448: }
12449: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12450: if ($bcc{$type} ne '') {
12451: push(@{$changes{$type}},'bcc');
12452: }
12453: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12454: push(@{$changes{$type}},'include');
12455: }
12456: }
12457: }
12458: if (ref($fields) eq 'ARRAY') {
12459: foreach my $field (@{$fields}) {
12460: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12461: push(@{$changes{'helpform'}},$field);
12462: }
12463: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12464: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12465: push(@{$changes{'helpform'}},'maxsize');
12466: }
12467: }
12468: }
12469: }
12470: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12471: foreach my $key ('excluded','weights','threshold','sysmail') {
12472: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12473: push(@{$changes{'lonstatus'}},$key);
12474: }
12475: }
12476: }
12477: }
12478: foreach my $item (@toggles) {
12479: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12480: $changes{$item} = 1;
12481: } elsif ((!$env{'form.'.$item}) &&
12482: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12483: $changes{$item} = 1;
12484: }
12485: }
12486: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12487: $dom);
12488: if ($putresult eq 'ok') {
12489: if (keys(%changes) > 0) {
12490: &Apache::loncommon::devalidate_domconfig_cache($dom);
12491: if (ref($lastactref) eq 'HASH') {
12492: $lastactref->{'domainconfig'} = 1;
12493: }
12494: my ($titles,$short_titles) = &contact_titles();
12495: $resulttext = &mt('Changes made:').'<ul>';
12496: foreach my $item (@contacts) {
12497: if ($changes{$item}) {
12498: $resulttext .= '<li>'.$titles->{$item}.
12499: &mt(' set to: ').
12500: '<span class="LC_cusr_emph">'.
12501: $to{$item}.'</span></li>';
12502: }
12503: }
12504: foreach my $type (@mailings) {
12505: if (ref($changes{$type}) eq 'ARRAY') {
12506: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12507: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12508: } else {
12509: $resulttext .= '<li>'.$titles->{$type}.': ';
12510: }
12511: my @text;
12512: foreach my $item (@{$newsetting{$type}}) {
12513: push(@text,$short_titles->{$item});
12514: }
12515: if ($others{$type} ne '') {
12516: push(@text,$others{$type});
12517: }
12518: if (@text) {
12519: $resulttext .= '<span class="LC_cusr_emph">'.
12520: join(', ',@text).'</span>';
12521: }
12522: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12523: if ($bcc{$type} ne '') {
12524: my $bcctext;
12525: if (@text) {
12526: $bcctext = ' '.&mt('with Bcc to');
12527: } else {
12528: $bcctext = '(Bcc)';
12529: }
12530: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12531: } elsif (!@text) {
12532: $resulttext .= &mt('No one');
12533: }
12534: if ($includestr{$type} ne '') {
12535: if ($includeloc{$type} eq 'b') {
12536: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12537: } elsif ($includeloc{$type} eq 's') {
12538: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12539: }
12540: }
12541: } elsif (!@text) {
12542: $resulttext .= &mt('No recipients');
12543: }
12544: $resulttext .= '</li>';
12545: }
12546: }
12547: if (ref($changes{'overrides'}) eq 'ARRAY') {
12548: my @deletions;
12549: foreach my $type (@{$changes{'overrides'}}) {
12550: if ($usertypeshash{$type}) {
12551: if (grep(/^\Q$type\E/,@overrides)) {
12552: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12553: $usertypeshash{$type}).'<ul><li>';
12554: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12555: my @text;
12556: foreach my $item (@contacts) {
12557: if ($newsetting{'override_'.$type}{$item}) {
12558: push(@text,$short_titles->{$item});
12559: }
12560: }
12561: if ($newsetting{'override_'.$type}{'others'} ne '') {
12562: push(@text,$newsetting{'override_'.$type}{'others'});
12563: }
12564:
12565: if (@text) {
12566: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12567: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12568: }
12569: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12570: my $bcctext;
12571: if (@text) {
12572: $bcctext = ' '.&mt('with Bcc to');
12573: } else {
12574: $bcctext = '(Bcc)';
12575: }
12576: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12577: } elsif (!@text) {
12578: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12579: }
12580: $resulttext .= '</li>';
12581: if ($newsetting{'override_'.$type}{'include'} ne '') {
12582: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12583: if ($loc eq 'b') {
12584: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12585: } elsif ($loc eq 's') {
12586: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12587: }
12588: }
12589: }
12590: $resulttext .= '</li></ul></li>';
12591: } else {
12592: push(@deletions,$usertypeshash{$type});
12593: }
12594: }
12595: }
12596: if (@deletions) {
12597: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12598: join(', ',@deletions)).'</li>';
12599: }
12600: }
12601: my @offon = ('off','on');
12602: my $corelink = &core_link_msu();
12603: if ($changes{'reporterrors'}) {
12604: $resulttext .= '<li>'.
12605: &mt('E-mail error reports to [_1] set to "'.
12606: $offon[$env{'form.reporterrors'}].'".',
12607: $corelink).
12608: '</li>';
12609: }
12610: if ($changes{'reportupdates'}) {
12611: $resulttext .= '<li>'.
12612: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12613: $offon[$env{'form.reportupdates'}].'".',
12614: $corelink).
12615: '</li>';
12616: }
12617: if ($changes{'reportstatus'}) {
12618: $resulttext .= '<li>'.
12619: &mt('E-mail status if errors above threshold to [_1] set to "'.
12620: $offon[$env{'form.reportstatus'}].'".',
12621: $corelink).
12622: '</li>';
12623: }
12624: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12625: $resulttext .= '<li>'.
12626: &mt('Nightly status check e-mail settings').':<ul>';
12627: my (%defval,%use_def,%shown);
12628: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12629: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12630: $defval{'weights'} =
12631: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12632: $defval{'excluded'} = &mt('None');
12633: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12634: foreach my $item ('threshold','sysmail','weights','excluded') {
12635: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12636: if (($item eq 'threshold') || ($item eq 'sysmail')) {
12637: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12638: } elsif ($item eq 'weights') {
12639: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12640: foreach my $type ('E','W','N','U') {
12641: $shown{$item} .= $lonstatus_names->{$type}.'=';
12642: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12643: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12644: } else {
12645: $shown{$item} .= $lonstatus_defs->{$type};
12646: }
12647: $shown{$item} .= ', ';
12648: }
12649: $shown{$item} =~ s/, $//;
12650: } else {
12651: $shown{$item} = $defval{$item};
12652: }
12653: } elsif ($item eq 'excluded') {
12654: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12655: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12656: } else {
12657: $shown{$item} = $defval{$item};
12658: }
12659: }
12660: } else {
12661: $shown{$item} = $defval{$item};
12662: }
12663: }
12664: } else {
12665: foreach my $item ('threshold','weights','excluded','sysmail') {
12666: $shown{$item} = $defval{$item};
12667: }
12668: }
12669: foreach my $item ('threshold','weights','excluded','sysmail') {
12670: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12671: $shown{$item}).'</li>';
12672: }
12673: $resulttext .= '</ul></li>';
12674: }
12675: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12676: my (@optional,@required,@unused,$maxsizechg);
12677: foreach my $field (@{$changes{'helpform'}}) {
12678: if ($field eq 'maxsize') {
12679: $maxsizechg = 1;
12680: next;
12681: }
12682: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12683: push(@optional,$field);
12684: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12685: push(@unused,$field);
12686: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12687: push(@required,$field);
12688: }
12689: }
12690: if (@optional) {
12691: $resulttext .= '<li>'.
12692: &mt('Help form fields changed to "Optional": [_1].',
12693: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12694: '</li>';
12695: }
12696: if (@required) {
12697: $resulttext .= '<li>'.
12698: &mt('Help form fields changed to "Required": [_1].',
12699: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12700: '</li>';
12701: }
12702: if (@unused) {
12703: $resulttext .= '<li>'.
12704: &mt('Help form fields changed to "Not shown": [_1].',
12705: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12706: '</li>';
12707: }
12708: if ($maxsizechg) {
12709: $resulttext .= '<li>'.
12710: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12711: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12712: '</li>';
12713: }
12714: }
12715: $resulttext .= '</ul>';
12716: } else {
12717: $resulttext = &mt('No changes made to contacts and form settings');
12718: }
12719: } else {
12720: $resulttext = '<span class="LC_error">'.
12721: &mt('An error occurred: [_1].',$putresult).'</span>';
12722: }
12723: return $resulttext;
12724: }
12725:
12726: sub modify_passwords {
12727: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12728: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12729: $updatedefaults,$updateconf);
12730: my $customfn = 'resetpw.html';
12731: if (ref($domconfig{'passwords'}) eq 'HASH') {
12732: %current = %{$domconfig{'passwords'}};
12733: }
12734: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12735: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12736: if (ref($types) eq 'ARRAY') {
12737: @oktypes = @{$types};
12738: }
12739: push(@oktypes,'default');
12740:
12741: my %titles = &Apache::lonlocal::texthash (
12742: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12743: intauth_check => 'Check bcrypt cost if authenticated',
12744: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12745: permanent => 'Permanent e-mail address',
12746: critical => 'Critical notification address',
12747: notify => 'Notification address',
12748: min => 'Minimum password length',
12749: max => 'Maximum password length',
12750: chars => 'Required characters',
12751: numsaved => 'Number of previous passwords to save',
12752: reset => 'Resetting Forgotten Password',
12753: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12754: rules => 'Rules for LON-CAPA Passwords',
12755: crsownerchg => 'Course Owner Changing Student Passwords',
12756: username => 'Username',
12757: email => 'E-mail address',
12758: );
12759:
12760: #
12761: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12762: #
12763: my (%curr_defaults,%save_defaults);
12764: if (ref($domconfig{'defaults'}) eq 'HASH') {
12765: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12766: if ($key =~ /^intauth_(cost|check|switch)$/) {
12767: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12768: } else {
12769: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12770: }
12771: }
12772: }
12773: my %staticdefaults = (
12774: 'resetlink' => 2,
12775: 'resetcase' => \@oktypes,
12776: 'resetprelink' => 'both',
12777: 'resetemail' => ['critical','notify','permanent'],
12778: 'intauth_cost' => 10,
12779: 'intauth_check' => 0,
12780: 'intauth_switch' => 0,
12781: );
12782: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
12783: foreach my $type (@oktypes) {
12784: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12785: }
12786: my $linklife = $env{'form.passwords_link'};
12787: $linklife =~ s/^\s+|\s+$//g;
12788: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12789: $newvalues{'resetlink'} = $linklife;
12790: if ($current{'resetlink'}) {
12791: if ($current{'resetlink'} ne $linklife) {
12792: $changes{'reset'} = 1;
12793: }
12794: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12795: if ($staticdefaults{'resetlink'} ne $linklife) {
12796: $changes{'reset'} = 1;
12797: }
12798: }
12799: } elsif ($current{'resetlink'}) {
12800: $changes{'reset'} = 1;
12801: }
12802: my @casesens;
12803: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12804: foreach my $case (sort(@posscase)) {
12805: if (grep(/^\Q$case\E$/,@oktypes)) {
12806: push(@casesens,$case);
12807: }
12808: }
12809: $newvalues{'resetcase'} = \@casesens;
12810: if (ref($current{'resetcase'}) eq 'ARRAY') {
12811: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12812: if (@diffs > 0) {
12813: $changes{'reset'} = 1;
12814: }
12815: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12816: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12817: if (@diffs > 0) {
12818: $changes{'reset'} = 1;
12819: }
12820: }
12821: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12822: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12823: if (exists($current{'resetprelink'})) {
12824: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12825: $changes{'reset'} = 1;
12826: }
12827: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12828: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12829: $changes{'reset'} = 1;
12830: }
12831: }
12832: } elsif ($current{'resetprelink'}) {
12833: $changes{'reset'} = 1;
12834: }
12835: foreach my $type (@oktypes) {
12836: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12837: my @postlink;
12838: foreach my $item (sort(@possplink)) {
12839: if ($item =~ /^(email|username)$/) {
12840: push(@postlink,$item);
12841: }
12842: }
12843: $newvalues{'resetpostlink'}{$type} = \@postlink;
12844: unless ($changes{'reset'}) {
12845: if (ref($current{'resetpostlink'}) eq 'HASH') {
12846: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12847: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12848: if (@diffs > 0) {
12849: $changes{'reset'} = 1;
12850: }
12851: } else {
12852: $changes{'reset'} = 1;
12853: }
12854: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12855: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12856: if (@diffs > 0) {
12857: $changes{'reset'} = 1;
12858: }
12859: }
12860: }
12861: }
12862: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12863: my @resetemail;
12864: foreach my $item (sort(@possemailsrc)) {
12865: if ($item =~ /^(permanent|critical|notify)$/) {
12866: push(@resetemail,$item);
12867: }
12868: }
12869: $newvalues{'resetemail'} = \@resetemail;
12870: unless ($changes{'reset'}) {
12871: if (ref($current{'resetemail'}) eq 'ARRAY') {
12872: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12873: if (@diffs > 0) {
12874: $changes{'reset'} = 1;
12875: }
12876: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12877: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12878: if (@diffs > 0) {
12879: $changes{'reset'} = 1;
12880: }
12881: }
12882: }
12883: if ($env{'form.passwords_stdtext'} == 0) {
12884: $newvalues{'resetremove'} = 1;
12885: unless ($current{'resetremove'}) {
12886: $changes{'reset'} = 1;
12887: }
12888: } elsif ($current{'resetremove'}) {
12889: $changes{'reset'} = 1;
12890: }
12891: if ($env{'form.passwords_customfile.filename'} ne '') {
12892: my $servadm = $r->dir_config('lonAdmEMail');
12893: my $servadm = $r->dir_config('lonAdmEMail');
12894: my ($configuserok,$author_ok,$switchserver) =
12895: &config_check($dom,$confname,$servadm);
12896: my $error;
12897: if ($configuserok eq 'ok') {
12898: if ($switchserver) {
12899: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12900: } else {
12901: if ($author_ok eq 'ok') {
12902: my ($result,$customurl) =
12903: &publishlogo($r,'upload','passwords_customfile',$dom,
12904: $confname,'customtext/resetpw','','',$customfn);
12905: if ($result eq 'ok') {
12906: $newvalues{'resetcustom'} = $customurl;
12907: $changes{'reset'} = 1;
12908: } else {
12909: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12910: }
12911: } else {
12912: $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);
12913: }
12914: }
12915: } else {
12916: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customfn,$confname,$dom,$configuserok);
12917: }
12918: if ($error) {
12919: &Apache::lonnet::logthis($error);
12920: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12921: }
12922: } elsif ($current{'resetcustom'}) {
12923: if ($env{'form.passwords_custom_del'}) {
12924: $changes{'reset'} = 1;
12925: } else {
12926: $newvalues{'resetcustom'} = $current{'resetcustom'};
12927: }
12928: }
12929: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12930: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12931: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12932: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12933: $changes{'intauth'} = 1;
12934: }
12935: } else {
12936: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12937: }
12938: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12939: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12940: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12941: $changes{'intauth'} = 1;
12942: }
12943: } else {
12944: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12945: }
12946: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12947: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12948: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12949: $changes{'intauth'} = 1;
12950: }
12951: } else {
12952: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12953: }
12954: foreach my $item ('cost','check','switch') {
12955: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12956: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12957: $updatedefaults = 1;
12958: }
12959: }
12960: foreach my $rule ('min','max','numsaved') {
12961: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
12962: my $ruleok;
12963: if ($rule eq 'min') {
12964: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12965: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12966: $ruleok = 1;
12967: }
12968: }
12969: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12970: ($env{'form.passwords_'.$rule} ne '0')) {
12971: $ruleok = 1;
12972: }
12973: if ($ruleok) {
12974: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12975: if (exists($current{$rule})) {
12976: if ($newvalues{$rule} ne $current{$rule}) {
12977: $changes{'rules'} = 1;
12978: }
12979: } elsif ($rule eq 'min') {
12980: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12981: $changes{'rules'} = 1;
12982: }
12983: } else {
12984: $changes{'rules'} = 1;
12985: }
12986: } elsif (exists($current{$rule})) {
12987: $changes{'rules'} = 1;
12988: }
12989: }
12990: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12991: my @chars;
12992: foreach my $item (sort(@posschars)) {
12993: if ($item =~ /^(uc|lc|num|spec)$/) {
12994: push(@chars,$item);
12995: }
12996: }
12997: $newvalues{'chars'} = \@chars;
12998: unless ($changes{'rules'}) {
12999: if (ref($current{'chars'}) eq 'ARRAY') {
13000: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
13001: if (@diffs > 0) {
13002: $changes{'rules'} = 1;
13003: }
13004: } else {
13005: if (@chars > 0) {
13006: $changes{'rules'} = 1;
13007: }
13008: }
13009: }
13010: my %crsownerchg = (
13011: by => [],
13012: for => [],
13013: );
13014: foreach my $item ('by','for') {
13015: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
13016: foreach my $type (sort(@posstypes)) {
13017: if (grep(/^\Q$type\E$/,@oktypes)) {
13018: push(@{$crsownerchg{$item}},$type);
13019: }
13020: }
13021: }
13022: $newvalues{'crsownerchg'} = \%crsownerchg;
13023: if (ref($current{'crsownerchg'}) eq 'HASH') {
13024: foreach my $item ('by','for') {
13025: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
13026: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
13027: if (@diffs > 0) {
13028: $changes{'crsownerchg'} = 1;
13029: last;
13030: }
13031: }
13032: }
13033: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
13034: foreach my $item ('by','for') {
13035: if (@{$crsownerchg{$item}} > 0) {
13036: $changes{'crsownerchg'} = 1;
13037: last;
13038: }
13039: }
13040: }
13041:
13042: my %confighash = (
13043: defaults => \%save_defaults,
13044: passwords => \%newvalues,
13045: );
13046: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
13047:
13048: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
13049: if ($putresult eq 'ok') {
13050: if (keys(%changes) > 0) {
13051: $resulttext = &mt('Changes made: ').'<ul>';
13052: foreach my $key ('reset','intauth','rules','crsownerchg') {
13053: if ($changes{$key}) {
13054: unless ($key eq 'intauth') {
13055: $updateconf = 1;
13056: }
13057: $resulttext .= '<li>'.$titles{$key}.':<ul>';
13058: if ($key eq 'reset') {
13059: if ($confighash{'passwords'}{'captcha'} eq 'original') {
13060: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
13061: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
13062: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
13063: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
13064: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
13065: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
13066: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
13067: }
13068: } else {
13069: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
13070: }
13071: if ($confighash{'passwords'}{'resetlink'}) {
13072: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
13073: } else {
13074: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
13075: &mt('Will default to 2 hours').'</li>';
13076: }
13077: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
13078: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
13079: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
13080: } else {
13081: my $casesens;
13082: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
13083: if ($type eq 'default') {
13084: $casesens .= $othertitle.', ';
13085: } elsif ($usertypes->{$type} ne '') {
13086: $casesens .= $usertypes->{$type}.', ';
13087: }
13088: }
13089: $casesens =~ s/\Q, \E$//;
13090: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
13091: }
13092: } else {
13093: $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>';
13094: }
13095: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
13096: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
13097: } else {
13098: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
13099: }
13100: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
13101: my $output;
13102: if (ref($types) eq 'ARRAY') {
13103: foreach my $type (@{$types}) {
13104: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
13105: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
13106: $output .= $usertypes->{$type}.' -- '.&mt('none');
13107: } else {
13108: $output .= $usertypes->{$type}.' -- '.
13109: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
13110: }
13111: }
13112: }
13113: }
13114: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
13115: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
13116: $output .= $othertitle.' -- '.&mt('none');
13117: } else {
13118: $output .= $othertitle.' -- '.
13119: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
13120: }
13121: }
13122: if ($output) {
13123: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
13124: } else {
13125: $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>';
13126: }
13127: } else {
13128: $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>';
13129: }
13130: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
13131: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
13132: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
13133: } else {
13134: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
13135: }
13136: } else {
13137: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
13138: }
13139: if ($confighash{'passwords'}{'resetremove'}) {
13140: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
13141: } else {
13142: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
13143: }
13144: if ($confighash{'passwords'}{'resetcustom'}) {
13145: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
13146: &mt('custom text'),600,500,undef,undef,
13147: undef,undef,'background-color:#ffffff');
13148: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
13149: } else {
13150: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
13151: }
13152: } elsif ($key eq 'intauth') {
13153: foreach my $item ('cost','switch','check') {
13154: my $value = $save_defaults{$key.'_'.$item};
13155: if ($item eq 'switch') {
13156: my %optiondesc = &Apache::lonlocal::texthash (
13157: 0 => 'No',
13158: 1 => 'Yes',
13159: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
13160: );
13161: if ($value =~ /^(0|1|2)$/) {
13162: $value = $optiondesc{$value};
13163: } else {
13164: $value = &mt('none -- defaults to No');
13165: }
13166: } elsif ($item eq 'check') {
13167: my %optiondesc = &Apache::lonlocal::texthash (
13168: 0 => 'No',
13169: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
13170: 2 => 'Yes, disallow login if stored cost is less than domain default',
13171: );
13172: if ($value =~ /^(0|1|2)$/) {
13173: $value = $optiondesc{$value};
13174: } else {
13175: $value = &mt('none -- defaults to No');
13176: }
13177: }
13178: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
13179: }
13180: } elsif ($key eq 'rules') {
13181: foreach my $rule ('min','max','numsaved') {
13182: if ($confighash{'passwords'}{$rule} eq '') {
13183: if ($rule eq 'min') {
13184: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13185: ' '.&mt('Default of [_1] will be used',
13186: $Apache::lonnet::passwdmin).'</li>';
13187: } else {
13188: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13189: }
13190: } else {
13191: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
13192: }
13193: }
13194: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
13195: if (@{$confighash{'passwords'}{'chars'}} > 0) {
13196: my %rulenames = &Apache::lonlocal::texthash(
13197: uc => 'At least one upper case letter',
13198: lc => 'At least one lower case letter',
13199: num => 'At least one number',
13200: spec => 'At least one non-alphanumeric',
13201: );
13202: my $needed = '<ul><li>'.
13203: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
13204: '</li></ul>';
13205: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13206: } else {
13207: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13208: }
13209: } else {
13210: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13211: }
13212: } elsif ($key eq 'crsownerchg') {
13213: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
13214: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
13215: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
13216: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13217: } else {
13218: my %crsownerstr;
13219: foreach my $item ('by','for') {
13220: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
13221: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
13222: if ($type eq 'default') {
13223: $crsownerstr{$item} .= $othertitle.', ';
13224: } elsif ($usertypes->{$type} ne '') {
13225: $crsownerstr{$item} .= $usertypes->{$type}.', ';
13226: }
13227: }
13228: $crsownerstr{$item} =~ s/\Q, \E$//;
13229: }
13230: }
13231: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
13232: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
13233: }
13234: } else {
13235: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
13236: }
13237: }
13238: $resulttext .= '</ul></li>';
13239: }
13240: }
13241: $resulttext .= '</ul>';
13242: } else {
13243: $resulttext = &mt('No changes made to password settings');
13244: }
13245: my $cachetime = 24*60*60;
13246: if ($updatedefaults) {
13247: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13248: if (ref($lastactref) eq 'HASH') {
13249: $lastactref->{'domdefaults'} = 1;
13250: }
13251: }
13252: if ($updateconf) {
13253: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
13254: if (ref($lastactref) eq 'HASH') {
13255: $lastactref->{'passwdconf'} = 1;
13256: }
13257: }
13258: } else {
13259: $resulttext = '<span class="LC_error">'.
13260: &mt('An error occurred: [_1]',$putresult).'</span>';
13261: }
13262: if ($errors) {
13263: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13264: $errors.'</ul></p>';
13265: }
13266: return $resulttext;
13267: }
13268:
13269: sub modify_usercreation {
13270: my ($dom,%domconfig) = @_;
13271: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
13272: my $warningmsg;
13273: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13274: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13275: if ($key eq 'cancreate') {
13276: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13277: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13278: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13279: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13280: } else {
13281: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13282: }
13283: }
13284: }
13285: } elsif ($key eq 'email_rule') {
13286: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13287: } else {
13288: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13289: }
13290: }
13291: }
13292: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
13293: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
13294: my @contexts = ('author','course','requestcrs');
13295: foreach my $item(@contexts) {
13296: $cancreate{$item} = $env{'form.can_createuser_'.$item};
13297: }
13298: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13299: foreach my $item (@contexts) {
13300: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13301: push(@{$changes{'cancreate'}},$item);
13302: }
13303: }
13304: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13305: foreach my $item (@contexts) {
13306: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
13307: if ($cancreate{$item} ne 'any') {
13308: push(@{$changes{'cancreate'}},$item);
13309: }
13310: } else {
13311: if ($cancreate{$item} ne 'none') {
13312: push(@{$changes{'cancreate'}},$item);
13313: }
13314: }
13315: }
13316: } else {
13317: foreach my $item (@contexts) {
13318: push(@{$changes{'cancreate'}},$item);
13319: }
13320: }
13321:
13322: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13323: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13324: if (!grep(/^\Q$type\E$/,@username_rule)) {
13325: push(@{$changes{'username_rule'}},$type);
13326: }
13327: }
13328: foreach my $type (@username_rule) {
13329: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13330: push(@{$changes{'username_rule'}},$type);
13331: }
13332: }
13333: } else {
13334: push(@{$changes{'username_rule'}},@username_rule);
13335: }
13336:
13337: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13338: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13339: if (!grep(/^\Q$type\E$/,@id_rule)) {
13340: push(@{$changes{'id_rule'}},$type);
13341: }
13342: }
13343: foreach my $type (@id_rule) {
13344: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13345: push(@{$changes{'id_rule'}},$type);
13346: }
13347: }
13348: } else {
13349: push(@{$changes{'id_rule'}},@id_rule);
13350: }
13351:
13352: my @authen_contexts = ('author','course','domain');
13353: my @authtypes = ('int','krb4','krb5','loc');
13354: my %authhash;
13355: foreach my $item (@authen_contexts) {
13356: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13357: foreach my $auth (@authtypes) {
13358: if (grep(/^\Q$auth\E$/,@authallowed)) {
13359: $authhash{$item}{$auth} = 1;
13360: } else {
13361: $authhash{$item}{$auth} = 0;
13362: }
13363: }
13364: }
13365: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
13366: foreach my $item (@authen_contexts) {
13367: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13368: foreach my $auth (@authtypes) {
13369: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13370: push(@{$changes{'authtypes'}},$item);
13371: last;
13372: }
13373: }
13374: }
13375: }
13376: } else {
13377: foreach my $item (@authen_contexts) {
13378: push(@{$changes{'authtypes'}},$item);
13379: }
13380: }
13381:
13382: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13383: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13384: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13385: $save_usercreate{'id_rule'} = \@id_rule;
13386: $save_usercreate{'username_rule'} = \@username_rule,
13387: $save_usercreate{'authtypes'} = \%authhash;
13388:
13389: my %usercreation_hash = (
13390: usercreation => \%save_usercreate,
13391: );
13392:
13393: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13394: $dom);
13395:
13396: if ($putresult eq 'ok') {
13397: if (keys(%changes) > 0) {
13398: $resulttext = &mt('Changes made:').'<ul>';
13399: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13400: my %lt = &usercreation_types();
13401: foreach my $type (@{$changes{'cancreate'}}) {
13402: my $chgtext = $lt{$type}.', ';
13403: if ($cancreate{$type} eq 'none') {
13404: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13405: } elsif ($cancreate{$type} eq 'any') {
13406: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13407: } elsif ($cancreate{$type} eq 'official') {
13408: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13409: } elsif ($cancreate{$type} eq 'unofficial') {
13410: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13411: }
13412: $resulttext .= '<li>'.$chgtext.'</li>';
13413: }
13414: }
13415: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13416: my ($rules,$ruleorder) =
13417: &Apache::lonnet::inst_userrules($dom,'username');
13418: my $chgtext = '<ul>';
13419: foreach my $type (@username_rule) {
13420: if (ref($rules->{$type}) eq 'HASH') {
13421: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13422: }
13423: }
13424: $chgtext .= '</ul>';
13425: if (@username_rule > 0) {
13426: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13427: } else {
13428: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13429: }
13430: }
13431: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13432: my ($idrules,$idruleorder) =
13433: &Apache::lonnet::inst_userrules($dom,'id');
13434: my $chgtext = '<ul>';
13435: foreach my $type (@id_rule) {
13436: if (ref($idrules->{$type}) eq 'HASH') {
13437: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13438: }
13439: }
13440: $chgtext .= '</ul>';
13441: if (@id_rule > 0) {
13442: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13443: } else {
13444: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13445: }
13446: }
13447: my %authname = &authtype_names();
13448: my %context_title = &context_names();
13449: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13450: my $chgtext = '<ul>';
13451: foreach my $type (@{$changes{'authtypes'}}) {
13452: my @allowed;
13453: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13454: foreach my $auth (@authtypes) {
13455: if ($authhash{$type}{$auth}) {
13456: push(@allowed,$authname{$auth});
13457: }
13458: }
13459: if (@allowed > 0) {
13460: $chgtext .= join(', ',@allowed).'</li>';
13461: } else {
13462: $chgtext .= &mt('none').'</li>';
13463: }
13464: }
13465: $chgtext .= '</ul>';
13466: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13467: $resulttext .= '</li>';
13468: }
13469: $resulttext .= '</ul>';
13470: } else {
13471: $resulttext = &mt('No changes made to user creation settings');
13472: }
13473: } else {
13474: $resulttext = '<span class="LC_error">'.
13475: &mt('An error occurred: [_1]',$putresult).'</span>';
13476: }
13477: if ($warningmsg ne '') {
13478: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13479: }
13480: return $resulttext;
13481: }
13482:
13483: sub modify_selfcreation {
13484: my ($dom,$lastactref,%domconfig) = @_;
13485: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13486: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13487: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13488: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13489: if (ref($typesref) eq 'ARRAY') {
13490: @types = @{$typesref};
13491: }
13492: if (ref($usertypesref) eq 'HASH') {
13493: %usertypes = %{$usertypesref};
13494: }
13495: $usertypes{'default'} = $othertitle;
13496: #
13497: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13498: #
13499: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13500: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13501: if ($key eq 'cancreate') {
13502: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13503: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13504: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
13505: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13506: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13507: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13508: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13509: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
13510: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13511: } else {
13512: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13513: }
13514: }
13515: }
13516: } elsif ($key eq 'email_rule') {
13517: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13518: } else {
13519: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13520: }
13521: }
13522: }
13523: #
13524: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13525: #
13526: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13527: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13528: if ($key eq 'selfcreate') {
13529: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13530: } else {
13531: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13532: }
13533: }
13534: }
13535: #
13536: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13537: #
13538: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13539: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13540: if ($key eq 'inststatusguest') {
13541: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13542: } else {
13543: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13544: }
13545: }
13546: }
13547:
13548: my @contexts = ('selfcreate');
13549: @{$cancreate{'selfcreate'}} = ();
13550: %{$cancreate{'emailusername'}} = ();
13551: if (@types) {
13552: @{$cancreate{'statustocreate'}} = ();
13553: }
13554: %{$cancreate{'selfcreateprocessing'}} = ();
13555: %{$cancreate{'shibenv'}} = ();
13556: %{$cancreate{'emailverified'}} = ();
13557: %{$cancreate{'emailoptions'}} = ();
13558: %{$cancreate{'emaildomain'}} = ();
13559: my %selfcreatetypes = (
13560: sso => 'users authenticated by institutional single sign on',
13561: login => 'users authenticated by institutional log-in',
13562: email => 'users verified by e-mail',
13563: );
13564: #
13565: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13566: # is permitted.
13567: #
13568:
13569: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
13570:
13571: my (@statuses,%email_rule);
13572: foreach my $item ('login','sso','email') {
13573: if ($item eq 'email') {
13574: if ($env{'form.cancreate_email'}) {
13575: if (@types) {
13576: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13577: foreach my $status (@poss_statuses) {
13578: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13579: push(@statuses,$status);
13580: }
13581: }
13582: $save_inststatus{'inststatusguest'} = \@statuses;
13583: } else {
13584: push(@statuses,'default');
13585: }
13586: if (@statuses) {
13587: my %curr_rule;
13588: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13589: foreach my $type (@statuses) {
13590: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13591: }
13592: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13593: foreach my $type (@statuses) {
13594: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13595: }
13596: }
13597: push(@{$cancreate{'selfcreate'}},'email');
13598: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13599: my %curremaildom;
13600: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13601: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13602: }
13603: foreach my $type (@statuses) {
13604: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13605: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13606: }
13607: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13608: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13609: }
13610: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13611: #
13612: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13613: #
13614: my $chosen = $1;
13615: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13616: my $emaildom;
13617: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13618: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13619: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13620: if (ref($curremaildom{$type}) eq 'HASH') {
13621: if (exists($curremaildom{$type}{$chosen})) {
13622: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13623: push(@{$changes{'cancreate'}},'emaildomain');
13624: }
13625: } elsif ($emaildom ne '') {
13626: push(@{$changes{'cancreate'}},'emaildomain');
13627: }
13628: } elsif ($emaildom ne '') {
13629: push(@{$changes{'cancreate'}},'emaildomain');
13630: }
13631: }
13632: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13633: } elsif ($chosen eq 'custom') {
13634: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13635: $email_rule{$type} = [];
13636: if (ref($emailrules) eq 'HASH') {
13637: foreach my $rule (@possemail_rules) {
13638: if (exists($emailrules->{$rule})) {
13639: push(@{$email_rule{$type}},$rule);
13640: }
13641: }
13642: }
13643: if (@{$email_rule{$type}}) {
13644: $cancreate{'emailoptions'}{$type} = 'custom';
13645: if (ref($curr_rule{$type}) eq 'ARRAY') {
13646: if (@{$curr_rule{$type}} > 0) {
13647: foreach my $rule (@{$curr_rule{$type}}) {
13648: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13649: push(@{$changes{'email_rule'}},$type);
13650: }
13651: }
13652: }
13653: foreach my $type (@{$email_rule{$type}}) {
13654: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13655: push(@{$changes{'email_rule'}},$type);
13656: }
13657: }
13658: } else {
13659: push(@{$changes{'email_rule'}},$type);
13660: }
13661: }
13662: } else {
13663: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13664: }
13665: }
13666: }
13667: if (@types) {
13668: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13669: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13670: if (@changed) {
13671: push(@{$changes{'inststatus'}},'inststatusguest');
13672: }
13673: } else {
13674: push(@{$changes{'inststatus'}},'inststatusguest');
13675: }
13676: }
13677: } else {
13678: delete($env{'form.cancreate_email'});
13679: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13680: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13681: push(@{$changes{'inststatus'}},'inststatusguest');
13682: }
13683: }
13684: }
13685: } else {
13686: $save_inststatus{'inststatusguest'} = [];
13687: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13688: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13689: push(@{$changes{'inststatus'}},'inststatusguest');
13690: }
13691: }
13692: }
13693: } else {
13694: if ($env{'form.cancreate_'.$item}) {
13695: push(@{$cancreate{'selfcreate'}},$item);
13696: }
13697: }
13698: }
13699: my (%userinfo,%savecaptcha);
13700: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13701: #
13702: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13703: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
13704: #
13705:
13706: if ($env{'form.cancreate_email'}) {
13707: push(@contexts,'emailusername');
13708: if (@statuses) {
13709: foreach my $type (@statuses) {
13710: if (ref($infofields) eq 'ARRAY') {
13711: foreach my $field (@{$infofields}) {
13712: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13713: $cancreate{'emailusername'}{$type}{$field} = $1;
13714: }
13715: }
13716: }
13717: }
13718: }
13719: #
13720: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
13721: # queued requests for self-creation of account verified by e-mail.
13722: #
13723:
13724: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13725: @approvalnotify = sort(@approvalnotify);
13726: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13727: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13728: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13729: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13730: push(@{$changes{'cancreate'}},'notify');
13731: }
13732: } else {
13733: if ($cancreate{'notify'}{'approval'}) {
13734: push(@{$changes{'cancreate'}},'notify');
13735: }
13736: }
13737: } elsif ($cancreate{'notify'}{'approval'}) {
13738: push(@{$changes{'cancreate'}},'notify');
13739: }
13740:
13741: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13742: }
13743: #
13744: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
13745: # institutional log-in.
13746: #
13747: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13748: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13749: ($domdefaults{'auth_def'} eq 'localauth'))) {
13750: $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.').' '.
13751: &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.');
13752: }
13753: }
13754: my @fields = ('lastname','firstname','middlename','generation',
13755: 'permanentemail','id');
13756: my @shibfields = (@fields,'inststatus');
13757: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13758: #
13759: # Where usernames may created for institutional log-in and/or institutional single sign on:
13760: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13761: # may self-create accounts
13762: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13763: # which the user may supply, if institutional data is unavailable.
13764: #
13765: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
13766: if (@types) {
13767: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13768: push(@contexts,'statustocreate');
13769: foreach my $type (@types) {
13770: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13771: foreach my $field (@fields) {
13772: if (grep(/^\Q$field\E$/,@modifiable)) {
13773: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13774: } else {
13775: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13776: }
13777: }
13778: }
13779: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
13780: foreach my $type (@types) {
13781: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13782: foreach my $field (@fields) {
13783: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13784: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13785: push(@{$changes{'selfcreate'}},$type);
13786: last;
13787: }
13788: }
13789: }
13790: }
13791: } else {
13792: foreach my $type (@types) {
13793: push(@{$changes{'selfcreate'}},$type);
13794: }
13795: }
13796: }
13797: foreach my $field (@shibfields) {
13798: if ($env{'form.shibenv_'.$field} ne '') {
13799: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13800: }
13801: }
13802: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13803: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13804: foreach my $field (@shibfields) {
13805: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13806: push(@{$changes{'cancreate'}},'shibenv');
13807: }
13808: }
13809: } else {
13810: foreach my $field (@shibfields) {
13811: if ($env{'form.shibenv_'.$field}) {
13812: push(@{$changes{'cancreate'}},'shibenv');
13813: last;
13814: }
13815: }
13816: }
13817: }
13818: }
13819: foreach my $item (@contexts) {
13820: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13821: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13822: if (ref($cancreate{$item}) eq 'ARRAY') {
13823: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13824: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13825: push(@{$changes{'cancreate'}},$item);
13826: }
13827: }
13828: }
13829: }
13830: if (ref($cancreate{$item}) eq 'ARRAY') {
13831: foreach my $type (@{$cancreate{$item}}) {
13832: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13833: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13834: push(@{$changes{'cancreate'}},$item);
13835: }
13836: }
13837: }
13838: }
13839: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13840: if (ref($cancreate{$item}) eq 'HASH') {
13841: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13842: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13843: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13844: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
13845: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13846: push(@{$changes{'cancreate'}},$item);
13847: }
13848: }
13849: }
13850: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13851: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
13852: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13853: push(@{$changes{'cancreate'}},$item);
13854: }
13855: }
13856: }
13857: }
13858: foreach my $type (keys(%{$cancreate{$item}})) {
13859: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13860: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13861: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13862: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
13863: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13864: push(@{$changes{'cancreate'}},$item);
13865: }
13866: }
13867: } else {
13868: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13869: push(@{$changes{'cancreate'}},$item);
13870: }
13871: }
13872: }
13873: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13874: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
13875: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13876: push(@{$changes{'cancreate'}},$item);
13877: }
13878: }
13879: }
13880: }
13881: }
13882: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13883: if (ref($cancreate{$item}) eq 'ARRAY') {
13884: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13885: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13886: push(@{$changes{'cancreate'}},$item);
13887: }
13888: }
13889: }
13890: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13891: if (ref($cancreate{$item}) eq 'HASH') {
13892: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13893: push(@{$changes{'cancreate'}},$item);
13894: }
13895: }
13896: } elsif ($item eq 'emailusername') {
13897: if (ref($cancreate{$item}) eq 'HASH') {
13898: foreach my $type (keys(%{$cancreate{$item}})) {
13899: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13900: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13901: if ($cancreate{$item}{$type}{$field}) {
13902: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13903: push(@{$changes{'cancreate'}},$item);
13904: }
13905: last;
13906: }
13907: }
13908: }
13909: }
13910: }
13911: }
13912: }
13913: #
13914: # Populate %save_usercreate hash with updates to self-creation configuration.
13915: #
13916: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13917: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
13918: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
13919: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13920: if (ref($cancreate{'notify'}) eq 'HASH') {
13921: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13922: }
13923: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13924: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13925: }
13926: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13927: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13928: }
13929: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13930: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13931: }
13932: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13933: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13934: }
13935: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13936: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13937: }
13938: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13939: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13940: }
13941: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
13942: $save_usercreate{'email_rule'} = \%email_rule;
13943:
13944: my %userconfig_hash = (
13945: usercreation => \%save_usercreate,
13946: usermodification => \%save_usermodify,
13947: inststatus => \%save_inststatus,
13948: );
13949:
13950: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13951: $dom);
13952: #
13953: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
13954: #
13955: if ($putresult eq 'ok') {
13956: if (keys(%changes) > 0) {
13957: $resulttext = &mt('Changes made:').'<ul>';
13958: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13959: my %lt = &selfcreation_types();
13960: foreach my $type (@{$changes{'cancreate'}}) {
13961: my $chgtext = '';
13962: if ($type eq 'selfcreate') {
13963: if (@{$cancreate{$type}} == 0) {
13964: $chgtext .= &mt('Self creation of a new user account is not permitted.');
13965: } else {
13966: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13967: '<ul>';
13968: foreach my $case (@{$cancreate{$type}}) {
13969: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13970: }
13971: $chgtext .= '</ul>';
13972: if (ref($cancreate{$type}) eq 'ARRAY') {
13973: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13974: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13975: if (@{$cancreate{'statustocreate'}} == 0) {
13976: $chgtext .= '<span class="LC_warning">'.
13977: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13978: '</span><br />';
13979: }
13980: }
13981: }
13982: if (grep(/^email$/,@{$cancreate{$type}})) {
13983: if (!@statuses) {
13984: $chgtext .= '<span class="LC_warning">'.
13985: &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.").
13986: '</span><br />';
13987:
13988: }
13989: }
13990: }
13991: }
13992: } elsif ($type eq 'shibenv') {
13993: if (keys(%{$cancreate{$type}}) == 0) {
13994: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
13995: } else {
13996: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13997: '<ul>';
13998: foreach my $field (@shibfields) {
13999: next if ($cancreate{$type}{$field} eq '');
14000: if ($field eq 'inststatus') {
14001: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
14002: } else {
14003: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
14004: }
14005: }
14006: $chgtext .= '</ul>';
14007: }
14008: } elsif ($type eq 'statustocreate') {
14009: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
14010: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
14011: if (@{$cancreate{'selfcreate'}} > 0) {
14012: if (@{$cancreate{'statustocreate'}} == 0) {
14013: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
14014: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
14015: $chgtext .= '<br />'.
14016: '<span class="LC_warning">'.
14017: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
14018: '</span>';
14019: }
14020: } elsif (keys(%usertypes) > 0) {
14021: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
14022: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
14023: } else {
14024: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
14025: }
14026: $chgtext .= '<ul>';
14027: foreach my $case (@{$cancreate{$type}}) {
14028: if ($case eq 'default') {
14029: $chgtext .= '<li>'.$othertitle.'</li>';
14030: } else {
14031: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
14032: }
14033: }
14034: $chgtext .= '</ul>';
14035: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
14036: $chgtext .= '<span class="LC_warning">'.
14037: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
14038: '</span>';
14039: }
14040: }
14041: } else {
14042: if (@{$cancreate{$type}} == 0) {
14043: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
14044: } else {
14045: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
14046: }
14047: }
14048: $chgtext .= '<br />';
14049: }
14050: } elsif ($type eq 'selfcreateprocessing') {
14051: my %choices = &Apache::lonlocal::texthash (
14052: automatic => 'Automatic approval',
14053: approval => 'Queued for approval',
14054: );
14055: if (@types) {
14056: if (@statuses) {
14057: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
14058: '<ul>';
14059: foreach my $status (@statuses) {
14060: if ($status eq 'default') {
14061: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
14062: } else {
14063: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
14064: }
14065: }
14066: $chgtext .= '</ul>';
14067: }
14068: } else {
14069: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
14070: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
14071: }
14072: } elsif ($type eq 'emailverified') {
14073: my %options = &Apache::lonlocal::texthash (
14074: all => 'Same as e-mail',
14075: first => 'Omit @domain',
14076: free => 'Free to choose',
14077: );
14078: if (@types) {
14079: if (@statuses) {
14080: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
14081: '<ul>';
14082: foreach my $status (@statuses) {
14083: if ($status eq 'default') {
14084: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
14085: } else {
14086: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
14087: }
14088: }
14089: $chgtext .= '</ul>';
14090: }
14091: } else {
14092: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
14093: $options{$cancreate{'emailverified'}{'default'}});
14094: }
14095: } elsif ($type eq 'emailoptions') {
14096: my %options = &Apache::lonlocal::texthash (
14097: any => 'Any e-mail',
14098: inst => 'Institutional only',
14099: noninst => 'Non-institutional only',
14100: custom => 'Custom restrictions',
14101: );
14102: if (@types) {
14103: if (@statuses) {
14104: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
14105: '<ul>';
14106: foreach my $status (@statuses) {
14107: if ($type eq 'default') {
14108: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14109: } else {
14110: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14111: }
14112: }
14113: $chgtext .= '</ul>';
14114: }
14115: } else {
14116: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
14117: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
14118: } else {
14119: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
14120: $options{$cancreate{'emailoptions'}{'default'}});
14121: }
14122: }
14123: } elsif ($type eq 'emaildomain') {
14124: my $output;
14125: if (@statuses) {
14126: foreach my $type (@statuses) {
14127: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
14128: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
14129: if ($type eq 'default') {
14130: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14131: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14132: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14133: } else {
14134: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
14135: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14136: }
14137: } else {
14138: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14139: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14140: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14141: } else {
14142: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
14143: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14144: }
14145: }
14146: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
14147: if ($type eq 'default') {
14148: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14149: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14150: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14151: } else {
14152: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
14153: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14154: }
14155: } else {
14156: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14157: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14158: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14159: } else {
14160: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
14161: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14162: }
14163: }
14164: }
14165: }
14166: }
14167: }
14168: if ($output ne '') {
14169: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
14170: '<ul>'.$output.'</ul>';
14171: }
14172: } elsif ($type eq 'captcha') {
14173: if ($savecaptcha{$type} eq 'notused') {
14174: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
14175: } else {
14176: my %captchas = &captcha_phrases();
14177: if ($captchas{$savecaptcha{$type}}) {
14178: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
14179: } else {
14180: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
14181: }
14182: }
14183: } elsif ($type eq 'recaptchakeys') {
14184: my ($privkey,$pubkey);
14185: if (ref($savecaptcha{$type}) eq 'HASH') {
14186: $pubkey = $savecaptcha{$type}{'public'};
14187: $privkey = $savecaptcha{$type}{'private'};
14188: }
14189: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14190: if (!$pubkey) {
14191: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14192: } else {
14193: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14194: }
14195: if (!$privkey) {
14196: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14197: } else {
14198: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14199: }
14200: $chgtext .= '</ul>';
14201: } elsif ($type eq 'recaptchaversion') {
14202: if ($savecaptcha{'captcha'} eq 'recaptcha') {
14203: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
14204: }
14205: } elsif ($type eq 'emailusername') {
14206: if (ref($cancreate{'emailusername'}) eq 'HASH') {
14207: if (@statuses) {
14208: foreach my $type (@statuses) {
14209: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14210: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
14211: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
14212: '<ul>';
14213: foreach my $field (@{$infofields}) {
14214: if ($cancreate{'emailusername'}{$type}{$field}) {
14215: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14216: }
14217: }
14218: $chgtext .= '</ul>';
14219: } else {
14220: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
14221: }
14222: } else {
14223: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
14224: }
14225: }
14226: }
14227: }
14228: } elsif ($type eq 'notify') {
14229: my $numapprove = 0;
14230: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14231: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14232: if ($cancreate{'notify'}{'approval'}) {
14233: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14234: $numapprove ++;
14235: }
14236: }
14237: }
14238: unless ($numapprove) {
14239: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14240: }
14241: }
14242: if ($chgtext) {
14243: $resulttext .= '<li>'.$chgtext.'</li>';
14244: }
14245: }
14246: }
14247: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
14248: my ($emailrules,$emailruleorder) =
14249: &Apache::lonnet::inst_userrules($dom,'email');
14250: foreach my $type (@{$changes{'email_rule'}}) {
14251: if (ref($email_rule{$type}) eq 'ARRAY') {
14252: my $chgtext = '<ul>';
14253: foreach my $rule (@{$email_rule{$type}}) {
14254: if (ref($emailrules->{$rule}) eq 'HASH') {
14255: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14256: }
14257: }
14258: $chgtext .= '</ul>';
14259: my $typename;
14260: if (@types) {
14261: if ($type eq 'default') {
14262: $typename = $othertitle;
14263: } else {
14264: $typename = $usertypes{$type};
14265: }
14266: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14267: }
14268: if (@{$email_rule{$type}} > 0) {
14269: $resulttext .= '<li>'.
14270: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14271: $usertypes{$type}).
14272: $chgtext.
14273: '</li>';
14274: } else {
14275: $resulttext .= '<li>'.
14276: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
14277: '</li>'.
14278: &mt('(Affiliation: [_1])',$typename);
14279: }
14280: }
14281: }
14282: }
14283: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14284: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14285: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14286: my $chgtext = '<ul>';
14287: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14288: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14289: }
14290: $chgtext .= '</ul>';
14291: $resulttext .= '<li>'.
14292: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14293: $chgtext.
14294: '</li>';
14295: } else {
14296: $resulttext .= '<li>'.
14297: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14298: '</li>';
14299: }
14300: }
14301: }
14302: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14303: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14304: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14305: foreach my $type (@{$changes{'selfcreate'}}) {
14306: my $typename = $type;
14307: if (keys(%usertypes) > 0) {
14308: if ($usertypes{$type} ne '') {
14309: $typename = $usertypes{$type};
14310: }
14311: }
14312: my @modifiable;
14313: $resulttext .= '<li>'.
14314: &mt('Self-creation of account by users with status: [_1]',
14315: '<span class="LC_cusr_emph">'.$typename.'</span>').
14316: ' - '.&mt('modifiable fields (if institutional data blank): ');
14317: foreach my $field (@fields) {
14318: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14319: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
14320: }
14321: }
14322: if (@modifiable > 0) {
14323: $resulttext .= join(', ',@modifiable);
14324: } else {
14325: $resulttext .= &mt('none');
14326: }
14327: $resulttext .= '</li>';
14328: }
14329: $resulttext .= '</ul></li>';
14330: }
14331: $resulttext .= '</ul>';
14332: my $cachetime = 24*60*60;
14333: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14334: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14335: if (ref($lastactref) eq 'HASH') {
14336: $lastactref->{'domdefaults'} = 1;
14337: }
14338: } else {
14339: $resulttext = &mt('No changes made to self-creation settings');
14340: }
14341: } else {
14342: $resulttext = '<span class="LC_error">'.
14343: &mt('An error occurred: [_1]',$putresult).'</span>';
14344: }
14345: if ($warningmsg ne '') {
14346: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14347: }
14348: return $resulttext;
14349: }
14350:
14351: sub process_captcha {
14352: my ($container,$changes,$newsettings,$currsettings) = @_;
14353: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
14354: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14355: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14356: $newsettings->{'captcha'} = 'original';
14357: }
14358: my %current;
14359: if (ref($currsettings) eq 'HASH') {
14360: %current = %{$currsettings};
14361: }
14362: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
14363: if ($container eq 'cancreate') {
14364: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14365: push(@{$changes->{'cancreate'}},'captcha');
14366: } elsif (!defined($changes->{'cancreate'})) {
14367: $changes->{'cancreate'} = ['captcha'];
14368: }
14369: } elsif ($container eq 'passwords') {
14370: $changes->{'reset'} = 1;
14371: } else {
14372: $changes->{'captcha'} = 1;
14373: }
14374: }
14375: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
14376: if ($newsettings->{'captcha'} eq 'recaptcha') {
14377: $newpub = $env{'form.'.$container.'_recaptchapub'};
14378: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
14379: $newpub =~ s/[^\w\-]//g;
14380: $newpriv =~ s/[^\w\-]//g;
14381: $newsettings->{'recaptchakeys'} = {
14382: public => $newpub,
14383: private => $newpriv,
14384: };
14385: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14386: $newversion =~ s/\D//g;
14387: if ($newversion ne '2') {
14388: $newversion = 1;
14389: }
14390: $newsettings->{'recaptchaversion'} = $newversion;
14391: }
14392: if (ref($current{'recaptchakeys'}) eq 'HASH') {
14393: $currpub = $current{'recaptchakeys'}{'public'};
14394: $currpriv = $current{'recaptchakeys'}{'private'};
14395: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14396: $newsettings->{'recaptchakeys'} = {
14397: public => '',
14398: private => '',
14399: }
14400: }
14401: }
14402: if ($current{'captcha'} eq 'recaptcha') {
14403: $currversion = $current{'recaptchaversion'};
14404: if ($currversion ne '2') {
14405: $currversion = 1;
14406: }
14407: }
14408: if ($currversion ne $newversion) {
14409: if ($container eq 'cancreate') {
14410: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14411: push(@{$changes->{'cancreate'}},'recaptchaversion');
14412: } elsif (!defined($changes->{'cancreate'})) {
14413: $changes->{'cancreate'} = ['recaptchaversion'];
14414: }
14415: } elsif ($container eq 'passwords') {
14416: $changes->{'reset'} = 1;
14417: } else {
14418: $changes->{'recaptchaversion'} = 1;
14419: }
14420: }
14421: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14422: if ($container eq 'cancreate') {
14423: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14424: push(@{$changes->{'cancreate'}},'recaptchakeys');
14425: } elsif (!defined($changes->{'cancreate'})) {
14426: $changes->{'cancreate'} = ['recaptchakeys'];
14427: }
14428: } elsif ($container eq 'passwords') {
14429: $changes->{'reset'} = 1;
14430: } else {
14431: $changes->{'recaptchakeys'} = 1;
14432: }
14433: }
14434: return;
14435: }
14436:
14437: sub modify_usermodification {
14438: my ($dom,%domconfig) = @_;
14439: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
14440: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14441: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
14442: if ($key eq 'selfcreate') {
14443: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14444: } else {
14445: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14446: }
14447: }
14448: }
14449: my @contexts = ('author','course');
14450: my %context_title = (
14451: author => 'In author context',
14452: course => 'In course context',
14453: );
14454: my @fields = ('lastname','firstname','middlename','generation',
14455: 'permanentemail','id');
14456: my %roles = (
14457: author => ['ca','aa'],
14458: course => ['st','ep','ta','in','cr'],
14459: );
14460: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14461: foreach my $context (@contexts) {
14462: foreach my $role (@{$roles{$context}}) {
14463: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14464: foreach my $item (@fields) {
14465: if (grep(/^\Q$item\E$/,@modifiable)) {
14466: $modifyhash{$context}{$role}{$item} = 1;
14467: } else {
14468: $modifyhash{$context}{$role}{$item} = 0;
14469: }
14470: }
14471: }
14472: if (ref($curr_usermodification{$context}) eq 'HASH') {
14473: foreach my $role (@{$roles{$context}}) {
14474: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14475: foreach my $field (@fields) {
14476: if ($modifyhash{$context}{$role}{$field} ne
14477: $curr_usermodification{$context}{$role}{$field}) {
14478: push(@{$changes{$context}},$role);
14479: last;
14480: }
14481: }
14482: }
14483: }
14484: } else {
14485: foreach my $context (@contexts) {
14486: foreach my $role (@{$roles{$context}}) {
14487: push(@{$changes{$context}},$role);
14488: }
14489: }
14490: }
14491: }
14492: my %usermodification_hash = (
14493: usermodification => \%modifyhash,
14494: );
14495: my $putresult = &Apache::lonnet::put_dom('configuration',
14496: \%usermodification_hash,$dom);
14497: if ($putresult eq 'ok') {
14498: if (keys(%changes) > 0) {
14499: $resulttext = &mt('Changes made: ').'<ul>';
14500: foreach my $context (@contexts) {
14501: if (ref($changes{$context}) eq 'ARRAY') {
14502: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14503: if (ref($changes{$context}) eq 'ARRAY') {
14504: foreach my $role (@{$changes{$context}}) {
14505: my $rolename;
14506: if ($role eq 'cr') {
14507: $rolename = &mt('Custom');
14508: } else {
14509: $rolename = &Apache::lonnet::plaintext($role);
14510: }
14511: my @modifiable;
14512: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
14513: foreach my $field (@fields) {
14514: if ($modifyhash{$context}{$role}{$field}) {
14515: push(@modifiable,$fieldtitles{$field});
14516: }
14517: }
14518: if (@modifiable > 0) {
14519: $resulttext .= join(', ',@modifiable);
14520: } else {
14521: $resulttext .= &mt('none');
14522: }
14523: $resulttext .= '</li>';
14524: }
14525: $resulttext .= '</ul></li>';
14526: }
14527: }
14528: }
14529: $resulttext .= '</ul>';
14530: } else {
14531: $resulttext = &mt('No changes made to user modification settings');
14532: }
14533: } else {
14534: $resulttext = '<span class="LC_error">'.
14535: &mt('An error occurred: [_1]',$putresult).'</span>';
14536: }
14537: return $resulttext;
14538: }
14539:
14540: sub modify_defaults {
14541: my ($dom,$lastactref,%domconfig) = @_;
14542: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
14543: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14544: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14545: 'portal_def');
14546: my @authtypes = ('internal','krb4','krb5','localauth');
14547: foreach my $item (@items) {
14548: $newvalues{$item} = $env{'form.'.$item};
14549: if ($item eq 'auth_def') {
14550: if ($newvalues{$item} ne '') {
14551: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14552: push(@errors,$item);
14553: }
14554: }
14555: } elsif ($item eq 'lang_def') {
14556: if ($newvalues{$item} ne '') {
14557: if ($newvalues{$item} =~ /^(\w+)/) {
14558: my $langcode = $1;
14559: if ($langcode ne 'x_chef') {
14560: if (code2language($langcode) eq '') {
14561: push(@errors,$item);
14562: }
14563: }
14564: } else {
14565: push(@errors,$item);
14566: }
14567: }
14568: } elsif ($item eq 'timezone_def') {
14569: if ($newvalues{$item} ne '') {
14570: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
14571: push(@errors,$item);
14572: }
14573: }
14574: } elsif ($item eq 'datelocale_def') {
14575: if ($newvalues{$item} ne '') {
14576: my @datelocale_ids = DateTime::Locale->ids();
14577: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14578: push(@errors,$item);
14579: }
14580: }
14581: } elsif ($item eq 'portal_def') {
14582: if ($newvalues{$item} ne '') {
14583: 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])\/?$/) {
14584: push(@errors,$item);
14585: }
14586: }
14587: }
14588: if (grep(/^\Q$item\E$/,@errors)) {
14589: $newvalues{$item} = $domdefaults{$item};
14590: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14591: $changes{$item} = 1;
14592: }
14593: $domdefaults{$item} = $newvalues{$item};
14594: }
14595: my %staticdefaults = (
14596: 'intauth_cost' => 10,
14597: 'intauth_check' => 0,
14598: 'intauth_switch' => 0,
14599: );
14600: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14601: if (exists($domdefaults{$item})) {
14602: $newvalues{$item} = $domdefaults{$item};
14603: } else {
14604: $newvalues{$item} = $staticdefaults{$item};
14605: }
14606: }
14607: my ($unamemaprules,$ruleorder);
14608: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
14609: if (@possunamemaprules) {
14610: ($unamemaprules,$ruleorder) =
14611: &Apache::lonnet::inst_userrules($dom,'unamemap');
14612: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
14613: if (@{$ruleorder} > 0) {
14614: my %possrules;
14615: map { $possrules{$_} = 1; } @possunamemaprules;
14616: foreach my $rule (@{$ruleorder}) {
14617: if ($possrules{$rule}) {
14618: push(@{$newvalues{'unamemap_rule'}},$rule);
14619: }
14620: }
14621: }
14622: }
14623: }
14624: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
14625: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
14626: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
14627: $newvalues{'unamemap_rule'});
14628: if (@rulediffs) {
14629: $changes{'unamemap_rule'} = 1;
14630: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
14631: }
14632: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
14633: $changes{'unamemap_rule'} = 1;
14634: delete($domdefaults{'unamemap_rule'});
14635: }
14636: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
14637: if (@{$newvalues{'unamemap_rule'}} > 0) {
14638: $changes{'unamemap_rule'} = 1;
14639: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
14640: }
14641: }
14642: my %defaults_hash = (
14643: defaults => \%newvalues,
14644: );
14645: my $title = &defaults_titles();
14646:
14647: my $currinststatus;
14648: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14649: $currinststatus = $domconfig{'inststatus'};
14650: } else {
14651: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14652: $currinststatus = {
14653: inststatustypes => $usertypes,
14654: inststatusorder => $types,
14655: inststatusguest => [],
14656: };
14657: }
14658: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14659: my @allpos;
14660: my %alltypes;
14661: my @inststatusguest;
14662: if (ref($currinststatus) eq 'HASH') {
14663: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14664: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14665: unless (grep(/^\Q$type\E$/,@todelete)) {
14666: push(@inststatusguest,$type);
14667: }
14668: }
14669: }
14670: }
14671: my ($currtitles,$currorder);
14672: if (ref($currinststatus) eq 'HASH') {
14673: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14674: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14675: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14676: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14677: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14678: }
14679: }
14680: unless (grep(/^\Q$type\E$/,@todelete)) {
14681: my $position = $env{'form.inststatus_pos_'.$type};
14682: $position =~ s/\D+//g;
14683: $allpos[$position] = $type;
14684: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14685: $alltypes{$type} =~ s/`//g;
14686: }
14687: }
14688: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14689: $currtitles =~ s/,$//;
14690: }
14691: }
14692: if ($env{'form.addinststatus'}) {
14693: my $newtype = $env{'form.addinststatus'};
14694: $newtype =~ s/\W//g;
14695: unless (exists($alltypes{$newtype})) {
14696: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14697: $alltypes{$newtype} =~ s/`//g;
14698: my $position = $env{'form.addinststatus_pos'};
14699: $position =~ s/\D+//g;
14700: if ($position ne '') {
14701: $allpos[$position] = $newtype;
14702: }
14703: }
14704: }
14705: my @orderedstatus;
14706: foreach my $type (@allpos) {
14707: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14708: push(@orderedstatus,$type);
14709: }
14710: }
14711: foreach my $type (keys(%alltypes)) {
14712: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14713: delete($alltypes{$type});
14714: }
14715: }
14716: $defaults_hash{'inststatus'} = {
14717: inststatustypes => \%alltypes,
14718: inststatusorder => \@orderedstatus,
14719: inststatusguest => \@inststatusguest,
14720: };
14721: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14722: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14723: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14724: }
14725: }
14726: if ($currorder ne join(',',@orderedstatus)) {
14727: $changes{'inststatus'}{'inststatusorder'} = 1;
14728: }
14729: my $newtitles;
14730: foreach my $item (@orderedstatus) {
14731: $newtitles .= $alltypes{$item}.',';
14732: }
14733: $newtitles =~ s/,$//;
14734: if ($currtitles ne $newtitles) {
14735: $changes{'inststatus'}{'inststatustypes'} = 1;
14736: }
14737: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14738: $dom);
14739: if ($putresult eq 'ok') {
14740: if (keys(%changes) > 0) {
14741: $resulttext = &mt('Changes made:').'<ul>';
14742: my $version = &Apache::lonnet::get_server_loncaparev($dom);
14743: 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";
14744: foreach my $item (sort(keys(%changes))) {
14745: if ($item eq 'inststatus') {
14746: if (ref($changes{'inststatus'}) eq 'HASH') {
14747: if (@orderedstatus) {
14748: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14749: foreach my $type (@orderedstatus) {
14750: $resulttext .= $alltypes{$type}.', ';
14751: }
14752: $resulttext =~ s/, $//;
14753: $resulttext .= '</li>';
14754: } else {
14755: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
14756: }
14757: }
14758: } elsif ($item eq 'unamemap_rule') {
14759: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
14760: my @rulenames;
14761: if (ref($unamemaprules) eq 'HASH') {
14762: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
14763: if (ref($unamemaprules->{$rule}) eq 'HASH') {
14764: push(@rulenames,$unamemaprules->{$rule}->{'name'});
14765: }
14766: }
14767: }
14768: if (@rulenames) {
14769: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
14770: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
14771: '</li>';
14772: } else {
14773: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
14774: }
14775: } else {
14776: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
14777: }
14778: } else {
14779: my $value = $env{'form.'.$item};
14780: if ($value eq '') {
14781: $value = &mt('none');
14782: } elsif ($item eq 'auth_def') {
14783: my %authnames = &authtype_names();
14784: my %shortauth = (
14785: internal => 'int',
14786: krb4 => 'krb4',
14787: krb5 => 'krb5',
14788: localauth => 'loc',
14789: );
14790: $value = $authnames{$shortauth{$value}};
14791: }
14792: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14793: $mailmsgtext .= "$title->{$item} set to $value\n";
14794: }
14795: }
14796: $resulttext .= '</ul>';
14797: $mailmsgtext .= "\n";
14798: my $cachetime = 24*60*60;
14799: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14800: if (ref($lastactref) eq 'HASH') {
14801: $lastactref->{'domdefaults'} = 1;
14802: }
14803: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
14804: my $notify = 1;
14805: if (ref($domconfig{'contacts'}) eq 'HASH') {
14806: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14807: $notify = 0;
14808: }
14809: }
14810: if ($notify) {
14811: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14812: "LON-CAPA Domain Settings Change - $dom",
14813: $mailmsgtext);
14814: }
14815: }
14816: } else {
14817: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
14818: }
14819: } else {
14820: $resulttext = '<span class="LC_error">'.
14821: &mt('An error occurred: [_1]',$putresult).'</span>';
14822: }
14823: if (@errors > 0) {
14824: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14825: foreach my $item (@errors) {
14826: $resulttext .= ' "'.$title->{$item}.'",';
14827: }
14828: $resulttext =~ s/,$//;
14829: }
14830: return $resulttext;
14831: }
14832:
14833: sub modify_scantron {
14834: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
14835: my ($resulttext,%confhash,%changes,$errors);
14836: my $custom = 'custom.tab';
14837: my $default = 'default.tab';
14838: my $servadm = $r->dir_config('lonAdmEMail');
14839: my ($configuserok,$author_ok,$switchserver) =
14840: &config_check($dom,$confname,$servadm);
14841: if ($env{'form.scantronformat.filename'} ne '') {
14842: my $error;
14843: if ($configuserok eq 'ok') {
14844: if ($switchserver) {
14845: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
14846: } else {
14847: if ($author_ok eq 'ok') {
14848: my ($result,$scantronurl) =
14849: &publishlogo($r,'upload','scantronformat',$dom,
14850: $confname,'scantron','','',$custom);
14851: if ($result eq 'ok') {
14852: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
14853: $changes{'scantronformat'} = 1;
14854: } else {
14855: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14856: }
14857: } else {
14858: $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);
14859: }
14860: }
14861: } else {
14862: $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);
14863: }
14864: if ($error) {
14865: &Apache::lonnet::logthis($error);
14866: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14867: }
14868: }
14869: if (ref($domconfig{'scantron'}) eq 'HASH') {
14870: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14871: if ($env{'form.scantronformat_del'}) {
14872: $confhash{'scantron'}{'scantronformat'} = '';
14873: $changes{'scantronformat'} = 1;
14874: } else {
14875: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14876: }
14877: }
14878: }
14879: my @options = ('hdr','pad','rem');
14880: my @fields = &scantroncsv_fields();
14881: my %titles = &scantronconfig_titles();
14882: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14883: my ($newdat,$currdat,%newcol,%currcol);
14884: if (grep(/^dat$/,@formats)) {
14885: $confhash{'scantron'}{config}{dat} = 1;
14886: $newdat = 1;
14887: } else {
14888: $newdat = 0;
14889: }
14890: if (grep(/^csv$/,@formats)) {
14891: my %bynum;
14892: foreach my $field (@fields) {
14893: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14894: my $posscol = $1;
14895: if (($posscol < 20) && (!$bynum{$posscol})) {
14896: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14897: $bynum{$posscol} = $field;
14898: $newcol{$field} = $posscol;
14899: }
14900: }
14901: }
14902: if (keys(%newcol)) {
14903: foreach my $option (@options) {
14904: if ($env{'form.scantroncsv_'.$option}) {
14905: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14906: }
14907: }
14908: }
14909: }
14910: $currdat = 1;
14911: if (ref($domconfig{'scantron'}) eq 'HASH') {
14912: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14913: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14914: $currdat = 0;
14915: }
14916: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14917: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14918: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14919: }
14920: }
14921: }
14922: }
14923: if ($currdat != $newdat) {
14924: $changes{'config'} = 1;
14925: } else {
14926: foreach my $field (@fields) {
14927: if ($currcol{$field} ne '') {
14928: if ($currcol{$field} ne $newcol{$field}) {
14929: $changes{'config'} = 1;
14930: last;
14931: }
14932: } elsif ($newcol{$field} ne '') {
14933: $changes{'config'} = 1;
14934: last;
14935: }
14936: }
14937: }
14938: if (keys(%confhash) > 0) {
14939: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14940: $dom);
14941: if ($putresult eq 'ok') {
14942: if (keys(%changes) > 0) {
14943: if (ref($confhash{'scantron'}) eq 'HASH') {
14944: $resulttext = &mt('Changes made:').'<ul>';
14945: if ($changes{'scantronformat'}) {
14946: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14947: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14948: } else {
14949: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14950: }
14951: }
14952: if ($changes{'config'}) {
14953: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14954: if ($confhash{'scantron'}{'config'}{'dat'}) {
14955: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14956: }
14957: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14958: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14959: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14960: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14961: foreach my $field (@fields) {
14962: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14963: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14964: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14965: }
14966: }
14967: $resulttext .= '</ul></li>';
14968: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14969: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14970: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14971: foreach my $option (@options) {
14972: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14973: $resulttext .= '<li>'.$titles{$option}.'</li>';
14974: }
14975: }
14976: $resulttext .= '</ul></li>';
14977: }
14978: }
14979: }
14980: }
14981: }
14982: } else {
14983: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14984: }
14985: }
14986: $resulttext .= '</ul>';
14987: } else {
14988: $resulttext = &mt('Changes made to bubblesheet format file.');
14989: }
14990: &Apache::loncommon::devalidate_domconfig_cache($dom);
14991: if (ref($lastactref) eq 'HASH') {
14992: $lastactref->{'domainconfig'} = 1;
14993: }
14994: } else {
14995: $resulttext = &mt('No changes made to bubblesheet format settings');
14996: }
14997: } else {
14998: $resulttext = '<span class="LC_error">'.
14999: &mt('An error occurred: [_1]',$putresult).'</span>';
15000: }
15001: } else {
15002: $resulttext = &mt('No changes made to bubblesheet format settings');
15003: }
15004: if ($errors) {
15005: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15006: $errors.'</ul>';
15007: }
15008: return $resulttext;
15009: }
15010:
15011: sub modify_coursecategories {
15012: my ($dom,$lastactref,%domconfig) = @_;
15013: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
15014: $cathash);
15015: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
15016: my @catitems = ('unauth','auth');
15017: my @cattypes = ('std','domonly','codesrch','none');
15018: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
15019: $cathash = $domconfig{'coursecategories'}{'cats'};
15020: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
15021: $changes{'togglecats'} = 1;
15022: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
15023: }
15024: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
15025: $changes{'categorize'} = 1;
15026: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
15027: }
15028: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
15029: $changes{'togglecatscomm'} = 1;
15030: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
15031: }
15032: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
15033: $changes{'categorizecomm'} = 1;
15034: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
15035: }
15036: foreach my $item (@catitems) {
15037: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15038: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
15039: $changes{$item} = 1;
15040: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15041: }
15042: }
15043: }
15044: } else {
15045: $changes{'togglecats'} = 1;
15046: $changes{'categorize'} = 1;
15047: $changes{'togglecatscomm'} = 1;
15048: $changes{'categorizecomm'} = 1;
15049: $domconfig{'coursecategories'} = {
15050: togglecats => $env{'form.togglecats'},
15051: categorize => $env{'form.categorize'},
15052: togglecatscomm => $env{'form.togglecatscomm'},
15053: categorizecomm => $env{'form.categorizecomm'},
15054: };
15055: foreach my $item (@catitems) {
15056: if ($env{'form.coursecat_'.$item} ne 'std') {
15057: $changes{$item} = 1;
15058: }
15059: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15060: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15061: }
15062: }
15063: }
15064: if (ref($cathash) eq 'HASH') {
15065: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
15066: push (@deletecategory,'instcode::0');
15067: }
15068: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
15069: push(@deletecategory,'communities::0');
15070: }
15071: }
15072: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
15073: if (ref($cathash) eq 'HASH') {
15074: if (@deletecategory > 0) {
15075: #FIXME Need to remove category from all courses using a deleted category
15076: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
15077: foreach my $item (@deletecategory) {
15078: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
15079: delete($domconfig{'coursecategories'}{'cats'}{$item});
15080: $deletions{$item} = 1;
15081: &recurse_cat_deletes($item,$cathash,\%deletions);
15082: }
15083: }
15084: }
15085: foreach my $item (keys(%{$cathash})) {
15086: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15087: if ($cathash->{$item} ne $env{'form.'.$item}) {
15088: $reorderings{$item} = 1;
15089: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
15090: }
15091: if ($env{'form.addcategory_name_'.$item} ne '') {
15092: my $newcat = $env{'form.addcategory_name_'.$item};
15093: my $newdepth = $depth+1;
15094: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
15095: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
15096: $adds{$newitem} = 1;
15097: }
15098: if ($env{'form.subcat_'.$item} ne '') {
15099: my $newcat = $env{'form.subcat_'.$item};
15100: my $newdepth = $depth+1;
15101: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
15102: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
15103: $adds{$newitem} = 1;
15104: }
15105: }
15106: }
15107: if ($env{'form.instcode'} eq '1') {
15108: if (ref($cathash) eq 'HASH') {
15109: my $newitem = 'instcode::0';
15110: if ($cathash->{$newitem} eq '') {
15111: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
15112: $adds{$newitem} = 1;
15113: }
15114: } else {
15115: my $newitem = 'instcode::0';
15116: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
15117: $adds{$newitem} = 1;
15118: }
15119: }
15120: if ($env{'form.communities'} eq '1') {
15121: if (ref($cathash) eq 'HASH') {
15122: my $newitem = 'communities::0';
15123: if ($cathash->{$newitem} eq '') {
15124: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15125: $adds{$newitem} = 1;
15126: }
15127: } else {
15128: my $newitem = 'communities::0';
15129: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15130: $adds{$newitem} = 1;
15131: }
15132: }
15133: if ($env{'form.addcategory_name'} ne '') {
15134: if (($env{'form.addcategory_name'} ne 'instcode') &&
15135: ($env{'form.addcategory_name'} ne 'communities')) {
15136: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
15137: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
15138: $adds{$newitem} = 1;
15139: }
15140: }
15141: my $putresult;
15142: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15143: if (keys(%deletions) > 0) {
15144: foreach my $key (keys(%deletions)) {
15145: if ($predelallitems{$key} ne '') {
15146: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
15147: }
15148: }
15149: }
15150: my (@chkcats,@chktrails,%chkallitems);
15151: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
15152: if (ref($chkcats[0]) eq 'ARRAY') {
15153: my $depth = 0;
15154: my $chg = 0;
15155: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
15156: my $name = $chkcats[0][$i];
15157: my $item;
15158: if ($name eq '') {
15159: $chg ++;
15160: } else {
15161: $item = &escape($name).'::0';
15162: if ($chg) {
15163: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
15164: }
15165: $depth ++;
15166: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
15167: $depth --;
15168: }
15169: }
15170: }
15171: }
15172: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15173: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
15174: if ($putresult eq 'ok') {
15175: my %title = (
15176: togglecats => 'Show/Hide a course in catalog',
15177: categorize => 'Assign a category to a course',
15178: togglecatscomm => 'Show/Hide a community in catalog',
15179: categorizecomm => 'Assign a category to a community',
15180: );
15181: my %level = (
15182: dom => 'set in Domain ("Modify Course/Community")',
15183: crs => 'set in Course ("Course Configuration")',
15184: comm => 'set in Community ("Community Configuration")',
15185: none => 'No catalog',
15186: std => 'Standard catalog',
15187: domonly => 'Domain-only catalog',
15188: codesrch => 'Code search form',
15189: );
15190: $resulttext = &mt('Changes made:').'<ul>';
15191: if ($changes{'togglecats'}) {
15192: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
15193: }
15194: if ($changes{'categorize'}) {
15195: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
15196: }
15197: if ($changes{'togglecatscomm'}) {
15198: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
15199: }
15200: if ($changes{'categorizecomm'}) {
15201: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
15202: }
15203: if ($changes{'unauth'}) {
15204: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
15205: }
15206: if ($changes{'auth'}) {
15207: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
15208: }
15209: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15210: my $cathash;
15211: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
15212: $cathash = $domconfig{'coursecategories'}{'cats'};
15213: } else {
15214: $cathash = {};
15215: }
15216: my (@cats,@trails,%allitems);
15217: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
15218: if (keys(%deletions) > 0) {
15219: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
15220: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
15221: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
15222: }
15223: $resulttext .= '</ul></li>';
15224: }
15225: if (keys(%reorderings) > 0) {
15226: my %sort_by_trail;
15227: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
15228: foreach my $key (keys(%reorderings)) {
15229: if ($allitems{$key} ne '') {
15230: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15231: }
15232: }
15233: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15234: $resulttext .= '<li>'.$trails[$trail].'</li>';
15235: }
15236: $resulttext .= '</ul></li>';
15237: }
15238: if (keys(%adds) > 0) {
15239: my %sort_by_trail;
15240: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15241: foreach my $key (keys(%adds)) {
15242: if ($allitems{$key} ne '') {
15243: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15244: }
15245: }
15246: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15247: $resulttext .= '<li>'.$trails[$trail].'</li>';
15248: }
15249: $resulttext .= '</ul></li>';
15250: }
15251: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
15252: if (ref($lastactref) eq 'HASH') {
15253: $lastactref->{'cats'} = 1;
15254: }
15255: }
15256: $resulttext .= '</ul>';
15257: if ($changes{'unauth'} || $changes{'auth'}) {
15258: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15259: if ($changes{'auth'}) {
15260: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15261: }
15262: if ($changes{'unauth'}) {
15263: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15264: }
15265: my $cachetime = 24*60*60;
15266: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15267: if (ref($lastactref) eq 'HASH') {
15268: $lastactref->{'domdefaults'} = 1;
15269: }
15270: }
15271: } else {
15272: $resulttext = '<span class="LC_error">'.
15273: &mt('An error occurred: [_1]',$putresult).'</span>';
15274: }
15275: } else {
15276: $resulttext = &mt('No changes made to course and community categories');
15277: }
15278: return $resulttext;
15279: }
15280:
15281: sub modify_serverstatuses {
15282: my ($dom,%domconfig) = @_;
15283: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15284: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15285: %currserverstatus = %{$domconfig{'serverstatuses'}};
15286: }
15287: my @pages = &serverstatus_pages();
15288: foreach my $type (@pages) {
15289: $newserverstatus{$type}{'namedusers'} = '';
15290: $newserverstatus{$type}{'machines'} = '';
15291: if (defined($env{'form.'.$type.'_namedusers'})) {
15292: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15293: my @okusers;
15294: foreach my $user (@users) {
15295: my ($uname,$udom) = split(/:/,$user);
15296: if (($udom =~ /^$match_domain$/) &&
15297: (&Apache::lonnet::domain($udom)) &&
15298: ($uname =~ /^$match_username$/)) {
15299: if (!grep(/^\Q$user\E/,@okusers)) {
15300: push(@okusers,$user);
15301: }
15302: }
15303: }
15304: if (@okusers > 0) {
15305: @okusers = sort(@okusers);
15306: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15307: }
15308: }
15309: if (defined($env{'form.'.$type.'_machines'})) {
15310: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15311: my @okmachines;
15312: foreach my $ip (@machines) {
15313: my @parts = split(/\./,$ip);
15314: next if (@parts < 4);
15315: my $badip = 0;
15316: for (my $i=0; $i<4; $i++) {
15317: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15318: $badip = 1;
15319: last;
15320: }
15321: }
15322: if (!$badip) {
15323: push(@okmachines,$ip);
15324: }
15325: }
15326: @okmachines = sort(@okmachines);
15327: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15328: }
15329: }
15330: my %serverstatushash = (
15331: serverstatuses => \%newserverstatus,
15332: );
15333: foreach my $type (@pages) {
15334: foreach my $setting ('namedusers','machines') {
15335: my (@current,@new);
15336: if (ref($currserverstatus{$type}) eq 'HASH') {
15337: if ($currserverstatus{$type}{$setting} ne '') {
15338: @current = split(/,/,$currserverstatus{$type}{$setting});
15339: }
15340: }
15341: if ($newserverstatus{$type}{$setting} ne '') {
15342: @new = split(/,/,$newserverstatus{$type}{$setting});
15343: }
15344: if (@current > 0) {
15345: if (@new > 0) {
15346: foreach my $item (@current) {
15347: if (!grep(/^\Q$item\E$/,@new)) {
15348: $changes{$type}{$setting} = 1;
15349: last;
15350: }
15351: }
15352: foreach my $item (@new) {
15353: if (!grep(/^\Q$item\E$/,@current)) {
15354: $changes{$type}{$setting} = 1;
15355: last;
15356: }
15357: }
15358: } else {
15359: $changes{$type}{$setting} = 1;
15360: }
15361: } elsif (@new > 0) {
15362: $changes{$type}{$setting} = 1;
15363: }
15364: }
15365: }
15366: if (keys(%changes) > 0) {
15367: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
15368: my $putresult = &Apache::lonnet::put_dom('configuration',
15369: \%serverstatushash,$dom);
15370: if ($putresult eq 'ok') {
15371: $resulttext .= &mt('Changes made:').'<ul>';
15372: foreach my $type (@pages) {
15373: if (ref($changes{$type}) eq 'HASH') {
15374: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
15375: if ($changes{$type}{'namedusers'}) {
15376: if ($newserverstatus{$type}{'namedusers'} eq '') {
15377: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15378: } else {
15379: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15380: }
15381: }
15382: if ($changes{$type}{'machines'}) {
15383: if ($newserverstatus{$type}{'machines'} eq '') {
15384: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15385: } else {
15386: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15387: }
15388:
15389: }
15390: $resulttext .= '</ul></li>';
15391: }
15392: }
15393: $resulttext .= '</ul>';
15394: } else {
15395: $resulttext = '<span class="LC_error">'.
15396: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15397:
15398: }
15399: } else {
15400: $resulttext = &mt('No changes made to access to server status pages');
15401: }
15402: return $resulttext;
15403: }
15404:
15405: sub modify_helpsettings {
15406: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
15407: my ($resulttext,$errors,%changes,%helphash);
15408: my %defaultchecked = ('submitbugs' => 'on');
15409: my @offon = ('off','on');
15410: my @toggles = ('submitbugs');
15411: my %current = ('submitbugs' => '',
15412: 'adhoc' => {},
15413: );
15414: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
15415: %current = %{$domconfig{'helpsettings'}};
15416: }
15417: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15418: foreach my $item (@toggles) {
15419: if ($defaultchecked{$item} eq 'on') {
15420: if ($current{$item} eq '') {
15421: if ($env{'form.'.$item} eq '0') {
15422: $changes{$item} = 1;
15423: }
15424: } elsif ($current{$item} ne $env{'form.'.$item}) {
15425: $changes{$item} = 1;
15426: }
15427: } elsif ($defaultchecked{$item} eq 'off') {
15428: if ($current{$item} eq '') {
15429: if ($env{'form.'.$item} eq '1') {
15430: $changes{$item} = 1;
15431: }
15432: } elsif ($current{$item} ne $env{'form.'.$item}) {
15433: $changes{$item} = 1;
15434: }
15435: }
15436: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15437: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15438: }
15439: }
15440: my $maxnum = $env{'form.helproles_maxnum'};
15441: my $confname = $dom.'-domainconfig';
15442: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
15443: my (@allpos,%newsettings,%changedprivs,$newrole);
15444: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15445: my @accesstypes = ('all','dh','da','none','status','inc','exc');
15446: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
15447: my %lt = &Apache::lonlocal::texthash(
15448: s => 'system',
15449: d => 'domain',
15450: order => 'Display order',
15451: access => 'Role usage',
15452: all => 'All with domain helpdesk or helpdesk assistant role',
15453: dh => 'All with domain helpdesk role',
15454: da => 'All with domain helpdesk assistant role',
15455: none => 'None',
15456: status => 'Determined based on institutional status',
15457: inc => 'Include all, but exclude specific personnel',
15458: exc => 'Exclude all, but include specific personnel',
15459: );
15460: for (my $num=0; $num<=$maxnum; $num++) {
15461: my ($prefix,$identifier,$rolename,%curr);
15462: if ($num == $maxnum) {
15463: next unless ($env{'form.newcusthelp'} == $maxnum);
15464: $identifier = 'custhelp'.$num;
15465: $prefix = 'helproles_'.$num;
15466: $rolename = $env{'form.custhelpname'.$num};
15467: $rolename=~s/[^A-Za-z0-9]//gs;
15468: next if ($rolename eq '');
15469: next if (exists($existing{'rolesdef_'.$rolename}));
15470: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15471: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15472: $newprivs{'c'},$confname,$dom);
15473: if ($result ne 'ok') {
15474: $errors .= '<li><span class="LC_error">'.
15475: &mt('An error occurred storing the new custom role: [_1]',
15476: $result).'</span></li>';
15477: next;
15478: } else {
15479: $changedprivs{$rolename} = \%newprivs;
15480: $newrole = $rolename;
15481: }
15482: } else {
15483: $prefix = 'helproles_'.$num;
15484: $rolename = $env{'form.'.$prefix};
15485: next if ($rolename eq '');
15486: next unless (exists($existing{'rolesdef_'.$rolename}));
15487: $identifier = 'custhelp'.$num;
15488: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15489: my %currprivs;
15490: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15491: split(/\_/,$existing{'rolesdef_'.$rolename});
15492: foreach my $level ('c','d','s') {
15493: if ($newprivs{$level} ne $currprivs{$level}) {
15494: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15495: $newprivs{'c'},$confname,$dom);
15496: if ($result ne 'ok') {
15497: $errors .= '<li><span class="LC_error">'.
15498: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15499: $rolename,$result).'</span></li>';
15500: } else {
15501: $changedprivs{$rolename} = \%newprivs;
15502: }
15503: last;
15504: }
15505: }
15506: if (ref($current{'adhoc'}) eq 'HASH') {
15507: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15508: %curr = %{$current{'adhoc'}{$rolename}};
15509: }
15510: }
15511: }
15512: my $newpos = $env{'form.'.$prefix.'_pos'};
15513: $newpos =~ s/\D+//g;
15514: $allpos[$newpos] = $rolename;
15515: my $newdesc = $env{'form.'.$prefix.'_desc'};
15516: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15517: if ($curr{'desc'}) {
15518: if ($curr{'desc'} ne $newdesc) {
15519: $changes{'customrole'}{$rolename}{'desc'} = 1;
15520: $newsettings{$rolename}{'desc'} = $newdesc;
15521: }
15522: } elsif ($newdesc ne '') {
15523: $changes{'customrole'}{$rolename}{'desc'} = 1;
15524: $newsettings{$rolename}{'desc'} = $newdesc;
15525: }
15526: my $access = $env{'form.'.$prefix.'_access'};
15527: if (grep(/^\Q$access\E$/,@accesstypes)) {
15528: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15529: if ($access eq 'status') {
15530: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15531: if (scalar(@statuses) == 0) {
15532: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15533: } else {
15534: my (@shownstatus,$numtypes);
15535: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15536: if (ref($types) eq 'ARRAY') {
15537: $numtypes = scalar(@{$types});
15538: foreach my $type (sort(@statuses)) {
15539: if ($type eq 'default') {
15540: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15541: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15542: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15543: push(@shownstatus,$usertypes->{$type});
15544: }
15545: }
15546: }
15547: if (grep(/^default$/,@statuses)) {
15548: push(@shownstatus,$othertitle);
15549: }
15550: if (scalar(@shownstatus) == 1+$numtypes) {
15551: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15552: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15553: } else {
15554: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15555: if (ref($curr{'status'}) eq 'ARRAY') {
15556: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15557: if (@diffs) {
15558: $changes{'customrole'}{$rolename}{$access} = 1;
15559: }
15560: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15561: $changes{'customrole'}{$rolename}{$access} = 1;
15562: }
15563: }
15564: }
15565: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15566: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15567: my @newspecstaff;
15568: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15569: foreach my $person (sort(@personnel)) {
15570: if ($domhelpdesk{$person}) {
15571: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15572: }
15573: }
15574: if (ref($curr{$access}) eq 'ARRAY') {
15575: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15576: if (@diffs) {
15577: $changes{'customrole'}{$rolename}{$access} = 1;
15578: }
15579: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15580: $changes{'customrole'}{$rolename}{$access} = 1;
15581: }
15582: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15583: my ($uname,$udom) = split(/:/,$person);
15584: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15585: }
15586: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
15587: }
15588: } else {
15589: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15590: }
15591: unless ($curr{'access'} eq $access) {
15592: $changes{'customrole'}{$rolename}{'access'} = 1;
15593: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
15594: }
15595: }
15596: if (@allpos > 0) {
15597: my $idx = 0;
15598: foreach my $rolename (@allpos) {
15599: if ($rolename ne '') {
15600: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15601: if (ref($current{'adhoc'}) eq 'HASH') {
15602: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15603: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15604: $changes{'customrole'}{$rolename}{'order'} = 1;
15605: $newsettings{$rolename}{'order'} = $idx+1;
15606: }
15607: }
15608: }
15609: $idx ++;
15610: }
15611: }
15612: }
15613: my $putresult;
15614: if (keys(%changes) > 0) {
15615: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15616: if ($putresult eq 'ok') {
15617: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15618: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15619: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15620: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15621: }
15622: }
15623: my $cachetime = 24*60*60;
15624: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15625: if (ref($lastactref) eq 'HASH') {
15626: $lastactref->{'domdefaults'} = 1;
15627: }
15628: } else {
15629: $errors .= '<li><span class="LC_error">'.
15630: &mt('An error occurred storing the settings: [_1]',
15631: $putresult).'</span></li>';
15632: }
15633: }
15634: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15635: $resulttext = &mt('Changes made:').'<ul>';
15636: my (%shownprivs,@levelorder);
15637: @levelorder = ('c','d','s');
15638: if ((keys(%changes)) && ($putresult eq 'ok')) {
15639: foreach my $item (sort(keys(%changes))) {
15640: if ($item eq 'submitbugs') {
15641: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15642: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15643: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
15644: } elsif ($item eq 'customrole') {
15645: if (ref($changes{'customrole'}) eq 'HASH') {
15646: my @keyorder = ('order','desc','access','status','exc','inc');
15647: my %keytext = &Apache::lonlocal::texthash(
15648: order => 'Order',
15649: desc => 'Role description',
15650: access => 'Role usage',
15651: status => 'Allowed institutional types',
15652: exc => 'Allowed personnel',
15653: inc => 'Disallowed personnel',
15654: );
15655: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
15656: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15657: if ($role eq $newrole) {
15658: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15659: $role).'<ul>';
15660: } else {
15661: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15662: $role).'<ul>';
15663: }
15664: foreach my $key (@keyorder) {
15665: if ($changes{'customrole'}{$role}{$key}) {
15666: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15667: $keytext{$key},$newsettings{$role}{$key}).
15668: '</li>';
15669: }
15670: }
15671: if (ref($changedprivs{$role}) eq 'HASH') {
15672: $shownprivs{$role} = 1;
15673: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15674: foreach my $level (@levelorder) {
15675: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15676: next if ($item eq '');
15677: my ($priv) = split(/\&/,$item,2);
15678: if (&Apache::lonnet::plaintext($priv)) {
15679: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15680: unless ($level eq 'c') {
15681: $resulttext .= ' ('.$lt{$level}.')';
15682: }
15683: $resulttext .= '</li>';
15684: }
15685: }
15686: }
15687: $resulttext .= '</ul>';
15688: }
15689: $resulttext .= '</ul></li>';
15690: }
15691: }
15692: }
15693: }
15694: }
15695: }
15696: if (keys(%changedprivs)) {
15697: foreach my $role (sort(keys(%changedprivs))) {
15698: unless ($shownprivs{$role}) {
15699: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15700: $role).'<ul>'.
15701: '<li>'.&mt('Privileges set to :').'<ul>';
15702: foreach my $level (@levelorder) {
15703: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15704: next if ($item eq '');
15705: my ($priv) = split(/\&/,$item,2);
15706: if (&Apache::lonnet::plaintext($priv)) {
15707: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15708: unless ($level eq 'c') {
15709: $resulttext .= ' ('.$lt{$level}.')';
15710: }
15711: $resulttext .= '</li>';
15712: }
15713: }
15714: }
15715: $resulttext .= '</ul></li></ul></li>';
15716: }
15717: }
15718: }
15719: $resulttext .= '</ul>';
15720: } else {
15721: $resulttext = &mt('No changes made to help settings');
15722: }
15723: if ($errors) {
15724: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
15725: $errors.'</ul>';
15726: }
15727: return $resulttext;
15728: }
15729:
15730: sub modify_coursedefaults {
15731: my ($dom,$lastactref,%domconfig) = @_;
15732: my ($resulttext,$errors,%changes,%defaultshash);
15733: my %defaultchecked = (
15734: 'uselcmath' => 'on',
15735: 'usejsme' => 'on',
15736: 'inline_chem' => 'on',
15737: );
15738: my @toggles = ('uselcmath','usejsme','inline_chem');
15739: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
15740: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15741: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
15742: my @types = ('official','unofficial','community','textbook');
15743: my %staticdefaults = (
15744: anonsurvey_threshold => 10,
15745: uploadquota => 500,
15746: postsubmit => 60,
15747: mysqltables => 172800,
15748: );
15749: my %texoptions = (
15750: MathJax => 'MathJax',
15751: mimetex => &mt('Convert to Images'),
15752: tth => &mt('TeX to HTML'),
15753: );
15754: $defaultshash{'coursedefaults'} = {};
15755:
15756: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15757: if ($domconfig{'coursedefaults'} eq '') {
15758: $domconfig{'coursedefaults'} = {};
15759: }
15760: }
15761:
15762: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15763: foreach my $item (@toggles) {
15764: if ($defaultchecked{$item} eq 'on') {
15765: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15766: ($env{'form.'.$item} eq '0')) {
15767: $changes{$item} = 1;
15768: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15769: $changes{$item} = 1;
15770: }
15771: } elsif ($defaultchecked{$item} eq 'off') {
15772: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15773: ($env{'form.'.$item} eq '1')) {
15774: $changes{$item} = 1;
15775: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15776: $changes{$item} = 1;
15777: }
15778: }
15779: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15780: }
15781: foreach my $item (@numbers) {
15782: my ($currdef,$newdef);
15783: $newdef = $env{'form.'.$item};
15784: if ($item eq 'anonsurvey_threshold') {
15785: $currdef = $domconfig{'coursedefaults'}{$item};
15786: $newdef =~ s/\D//g;
15787: if ($newdef eq '' || $newdef < 1) {
15788: $newdef = 1;
15789: }
15790: $defaultshash{'coursedefaults'}{$item} = $newdef;
15791: } else {
15792: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15793: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15794: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
15795: }
15796: $newdef =~ s/[^\w.\-]//g;
15797: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
15798: }
15799: if ($currdef ne $newdef) {
15800: if ($item eq 'anonsurvey_threshold') {
15801: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15802: $changes{$item} = 1;
15803: }
15804: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15805: my $setting = $1;
15806: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15807: $changes{$setting} = 1;
15808: }
15809: }
15810: }
15811: }
15812: my $texengine;
15813: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15814: $texengine = $env{'form.texengine'};
15815: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15816: if ($currdef eq '') {
15817: unless ($texengine eq $Apache::lonnet::deftex) {
15818: $changes{'texengine'} = 1;
15819: }
15820: } elsif ($currdef ne $texengine) {
15821: $changes{'texengine'} = 1;
15822: }
15823: }
15824: if ($texengine ne '') {
15825: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15826: }
15827: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15828: my @currclonecode;
15829: if (ref($currclone) eq 'HASH') {
15830: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15831: @currclonecode = @{$currclone->{'instcode'}};
15832: }
15833: }
15834: my $newclone;
15835: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15836: $newclone = $env{'form.canclone'};
15837: }
15838: if ($newclone eq 'instcode') {
15839: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15840: my (%codedefaults,@code_order,@clonecode);
15841: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15842: \@code_order);
15843: foreach my $item (@code_order) {
15844: if (grep(/^\Q$item\E$/,@newcodes)) {
15845: push(@clonecode,$item);
15846: }
15847: }
15848: if (@clonecode) {
15849: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15850: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15851: if (@diffs) {
15852: $changes{'canclone'} = 1;
15853: }
15854: } else {
15855: $newclone eq '';
15856: }
15857: } elsif ($newclone ne '') {
15858: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15859: }
15860: if ($newclone ne $currclone) {
15861: $changes{'canclone'} = 1;
15862: }
15863: my %credits;
15864: foreach my $type (@types) {
15865: unless ($type eq 'community') {
15866: $credits{$type} = $env{'form.'.$type.'_credits'};
15867: $credits{$type} =~ s/[^\d.]+//g;
15868: }
15869: }
15870: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15871: ($env{'form.coursecredits'} eq '1')) {
15872: $changes{'coursecredits'} = 1;
15873: foreach my $type (keys(%credits)) {
15874: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15875: }
15876: } else {
15877: if ($env{'form.coursecredits'} eq '1') {
15878: foreach my $type (@types) {
15879: unless ($type eq 'community') {
15880: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15881: $changes{'coursecredits'} = 1;
15882: }
15883: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15884: }
15885: }
15886: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15887: foreach my $type (@types) {
15888: unless ($type eq 'community') {
15889: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15890: $changes{'coursecredits'} = 1;
15891: last;
15892: }
15893: }
15894: }
15895: }
15896: }
15897: if ($env{'form.postsubmit'} eq '1') {
15898: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15899: my %currtimeout;
15900: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15901: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15902: $changes{'postsubmit'} = 1;
15903: }
15904: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15905: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15906: }
15907: } else {
15908: $changes{'postsubmit'} = 1;
15909: }
15910: foreach my $type (@types) {
15911: my $timeout = $env{'form.'.$type.'_timeout'};
15912: $timeout =~ s/\D//g;
15913: if ($timeout == $staticdefaults{'postsubmit'}) {
15914: $timeout = '';
15915: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15916: $timeout = '0';
15917: }
15918: unless ($timeout eq '') {
15919: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15920: }
15921: if (exists($currtimeout{$type})) {
15922: if ($timeout ne $currtimeout{$type}) {
15923: $changes{'postsubmit'} = 1;
15924: }
15925: } elsif ($timeout ne '') {
15926: $changes{'postsubmit'} = 1;
15927: }
15928: }
15929: } else {
15930: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15931: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15932: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15933: $changes{'postsubmit'} = 1;
15934: }
15935: } else {
15936: $changes{'postsubmit'} = 1;
15937: }
15938: }
15939: }
15940: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15941: $dom);
15942: if ($putresult eq 'ok') {
15943: if (keys(%changes) > 0) {
15944: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15945: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
15946: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
15947: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
15948: ($changes{'inline_chem'})) {
15949: foreach my $item ('uselcmath','usejsme','inline_chem','texengine') {
15950: if ($changes{$item}) {
15951: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15952: }
15953: }
15954: if ($changes{'coursecredits'}) {
15955: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15956: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15957: $domdefaults{$type.'credits'} =
15958: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15959: }
15960: }
15961: }
15962: if ($changes{'postsubmit'}) {
15963: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15964: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15965: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15966: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15967: $domdefaults{$type.'postsubtimeout'} =
15968: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15969: }
15970: }
15971: }
15972: }
15973: if ($changes{'uploadquota'}) {
15974: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15975: foreach my $type (@types) {
15976: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15977: }
15978: }
15979: }
15980: if ($changes{'canclone'}) {
15981: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15982: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15983: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15984: if (@clonecodes) {
15985: $domdefaults{'canclone'} = join('+',@clonecodes);
15986: }
15987: }
15988: } else {
15989: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15990: }
15991: }
15992: my $cachetime = 24*60*60;
15993: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15994: if (ref($lastactref) eq 'HASH') {
15995: $lastactref->{'domdefaults'} = 1;
15996: }
15997: }
15998: $resulttext = &mt('Changes made:').'<ul>';
15999: foreach my $item (sort(keys(%changes))) {
16000: if ($item eq 'uselcmath') {
16001: if ($env{'form.'.$item} eq '1') {
16002: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
16003: } else {
16004: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
16005: }
16006: } elsif ($item eq 'usejsme') {
16007: if ($env{'form.'.$item} eq '1') {
16008: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
16009: } else {
16010: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
16011: }
16012: } elsif ($item eq 'inline_chem') {
16013: if ($env{'form.'.$item} eq '1') {
16014: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
16015: } else {
16016: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
16017: }
16018: } elsif ($item eq 'texengine') {
16019: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
16020: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
16021: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
16022: }
16023: } elsif ($item eq 'anonsurvey_threshold') {
16024: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
16025: } elsif ($item eq 'uploadquota') {
16026: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
16027: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
16028: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
16029: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
16030: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
16031:
16032: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
16033: '</ul>'.
16034: '</li>';
16035: } else {
16036: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
16037: }
16038: } elsif ($item eq 'mysqltables') {
16039: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
16040: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
16041: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
16042: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
16043: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
16044: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
16045: '</ul>'.
16046: '</li>';
16047: } else {
16048: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
16049: }
16050: } elsif ($item eq 'postsubmit') {
16051: if ($domdefaults{'postsubmit'} eq 'off') {
16052: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
16053: } else {
16054: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
16055: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16056: $resulttext .= &mt('durations:').'<ul>';
16057: foreach my $type (@types) {
16058: $resulttext .= '<li>';
16059: my $timeout;
16060: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16061: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
16062: }
16063: my $display;
16064: if ($timeout eq '0') {
16065: $display = &mt('unlimited');
16066: } elsif ($timeout eq '') {
16067: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
16068: } else {
16069: $display = &mt('[quant,_1,second]',$timeout);
16070: }
16071: if ($type eq 'community') {
16072: $resulttext .= &mt('Communities');
16073: } elsif ($type eq 'official') {
16074: $resulttext .= &mt('Official courses');
16075: } elsif ($type eq 'unofficial') {
16076: $resulttext .= &mt('Unofficial courses');
16077: } elsif ($type eq 'textbook') {
16078: $resulttext .= &mt('Textbook courses');
16079: }
16080: $resulttext .= ' -- '.$display.'</li>';
16081: }
16082: $resulttext .= '</ul>';
16083: }
16084: $resulttext .= '</li>';
16085: }
16086: } elsif ($item eq 'coursecredits') {
16087: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16088: if (($domdefaults{'officialcredits'} eq '') &&
16089: ($domdefaults{'unofficialcredits'} eq '') &&
16090: ($domdefaults{'textbookcredits'} eq '')) {
16091: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16092: } else {
16093: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
16094: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
16095: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
16096: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
16097: '</ul>'.
16098: '</li>';
16099: }
16100: } else {
16101: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16102: }
16103: } elsif ($item eq 'canclone') {
16104: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
16105: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
16106: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
16107: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
16108: }
16109: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
16110: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
16111: } else {
16112: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
16113: }
16114: }
16115: }
16116: $resulttext .= '</ul>';
16117: } else {
16118: $resulttext = &mt('No changes made to course defaults');
16119: }
16120: } else {
16121: $resulttext = '<span class="LC_error">'.
16122: &mt('An error occurred: [_1]',$putresult).'</span>';
16123: }
16124: return $resulttext;
16125: }
16126:
16127: sub modify_selfenrollment {
16128: my ($dom,$lastactref,%domconfig) = @_;
16129: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
16130: my @types = ('official','unofficial','community','textbook');
16131: my %titles = &tool_titles();
16132: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
16133: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
16134: $ordered{'default'} = ['types','registered','approval','limit'];
16135:
16136: my (%roles,%shown,%toplevel);
16137: $roles{'0'} = &Apache::lonnet::plaintext('dc');
16138:
16139: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
16140: if ($domconfig{'selfenrollment'} eq '') {
16141: $domconfig{'selfenrollment'} = {};
16142: }
16143: }
16144: %toplevel = (
16145: admin => 'Configuration Rights',
16146: default => 'Default settings',
16147: validation => 'Validation of self-enrollment requests',
16148: );
16149: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
16150:
16151: if (ref($ordered{'admin'}) eq 'ARRAY') {
16152: foreach my $item (@{$ordered{'admin'}}) {
16153: foreach my $type (@types) {
16154: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
16155: $selfenrollhash{'admin'}{$type}{$item} = 1;
16156: } else {
16157: $selfenrollhash{'admin'}{$type}{$item} = 0;
16158: }
16159: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
16160: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
16161: if ($selfenrollhash{'admin'}{$type}{$item} ne
16162: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
16163: push(@{$changes{'admin'}{$type}},$item);
16164: }
16165: } else {
16166: if (!$selfenrollhash{'admin'}{$type}{$item}) {
16167: push(@{$changes{'admin'}{$type}},$item);
16168: }
16169: }
16170: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
16171: push(@{$changes{'admin'}{$type}},$item);
16172: }
16173: }
16174: }
16175: }
16176:
16177: foreach my $item (@{$ordered{'default'}}) {
16178: foreach my $type (@types) {
16179: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
16180: if ($item eq 'types') {
16181: unless (($value eq 'all') || ($value eq 'dom')) {
16182: $value = '';
16183: }
16184: } elsif ($item eq 'registered') {
16185: unless ($value eq '1') {
16186: $value = 0;
16187: }
16188: } elsif ($item eq 'approval') {
16189: unless ($value =~ /^[012]$/) {
16190: $value = 0;
16191: }
16192: } else {
16193: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16194: $value = 'none';
16195: }
16196: }
16197: $selfenrollhash{'default'}{$type}{$item} = $value;
16198: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
16199: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16200: if ($selfenrollhash{'default'}{$type}{$item} ne
16201: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
16202: push(@{$changes{'default'}{$type}},$item);
16203: }
16204: } else {
16205: push(@{$changes{'default'}{$type}},$item);
16206: }
16207: } else {
16208: push(@{$changes{'default'}{$type}},$item);
16209: }
16210: if ($item eq 'limit') {
16211: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16212: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
16213: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
16214: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
16215: }
16216: } else {
16217: $selfenrollhash{'default'}{$type}{'cap'} = '';
16218: }
16219: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16220: if ($selfenrollhash{'default'}{$type}{'cap'} ne
16221: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
16222: push(@{$changes{'default'}{$type}},'cap');
16223: }
16224: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
16225: push(@{$changes{'default'}{$type}},'cap');
16226: }
16227: }
16228: }
16229: }
16230:
16231: foreach my $item (@{$itemsref}) {
16232: if ($item eq 'fields') {
16233: my @changed;
16234: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
16235: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
16236: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
16237: }
16238: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16239: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
16240: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
16241: $domconfig{'selfenrollment'}{'validation'}{$item});
16242: } else {
16243: @changed = @{$selfenrollhash{'validation'}{$item}};
16244: }
16245: } else {
16246: @changed = @{$selfenrollhash{'validation'}{$item}};
16247: }
16248: if (@changed) {
16249: if ($selfenrollhash{'validation'}{$item}) {
16250: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16251: } else {
16252: $changes{'validation'}{$item} = &mt('None');
16253: }
16254: }
16255: } else {
16256: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16257: if ($item eq 'markup') {
16258: if ($env{'form.selfenroll_validation_'.$item}) {
16259: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16260: }
16261: }
16262: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16263: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16264: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16265: }
16266: }
16267: }
16268: }
16269:
16270: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16271: $dom);
16272: if ($putresult eq 'ok') {
16273: if (keys(%changes) > 0) {
16274: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16275: $resulttext = &mt('Changes made:').'<ul>';
16276: foreach my $key ('admin','default','validation') {
16277: if (ref($changes{$key}) eq 'HASH') {
16278: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16279: if ($key eq 'validation') {
16280: foreach my $item (@{$itemsref}) {
16281: if (exists($changes{$key}{$item})) {
16282: if ($item eq 'markup') {
16283: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16284: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16285: } else {
16286: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16287: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16288: }
16289: }
16290: }
16291: } else {
16292: foreach my $type (@types) {
16293: if ($type eq 'community') {
16294: $roles{'1'} = &mt('Community personnel');
16295: } else {
16296: $roles{'1'} = &mt('Course personnel');
16297: }
16298: if (ref($changes{$key}{$type}) eq 'ARRAY') {
16299: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16300: if ($key eq 'admin') {
16301: my @mgrdc = ();
16302: if (ref($ordered{$key}) eq 'ARRAY') {
16303: foreach my $item (@{$ordered{'admin'}}) {
16304: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16305: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16306: push(@mgrdc,$item);
16307: }
16308: }
16309: }
16310: if (@mgrdc) {
16311: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16312: } else {
16313: delete($domdefaults{$type.'selfenrolladmdc'});
16314: }
16315: }
16316: } else {
16317: if (ref($ordered{$key}) eq 'ARRAY') {
16318: foreach my $item (@{$ordered{$key}}) {
16319: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16320: $domdefaults{$type.'selfenroll'.$item} =
16321: $selfenrollhash{$key}{$type}{$item};
16322: }
16323: }
16324: }
16325: }
16326: }
16327: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16328: foreach my $item (@{$ordered{$key}}) {
16329: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16330: $resulttext .= '<li>';
16331: if ($key eq 'admin') {
16332: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16333: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16334: } else {
16335: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16336: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16337: }
16338: $resulttext .= '</li>';
16339: }
16340: }
16341: $resulttext .= '</ul></li>';
16342: }
16343: }
16344: $resulttext .= '</ul></li>';
16345: }
16346: }
16347: }
16348: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16349: my $cachetime = 24*60*60;
16350: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16351: if (ref($lastactref) eq 'HASH') {
16352: $lastactref->{'domdefaults'} = 1;
16353: }
16354: }
16355: $resulttext .= '</ul>';
16356: } else {
16357: $resulttext = &mt('No changes made to self-enrollment settings');
16358: }
16359: } else {
16360: $resulttext = '<span class="LC_error">'.
16361: &mt('An error occurred: [_1]',$putresult).'</span>';
16362: }
16363: return $resulttext;
16364: }
16365:
16366: sub modify_wafproxy {
16367: my ($dom,$action,$lastactref,%domconfig) = @_;
16368: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16369: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
16370: %wafproxy,%changes,%expirecache,%expiresaml);
16371: foreach my $server (sort(keys(%servers))) {
16372: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16373: if ($serverhome eq $server) {
16374: my $serverdom = &Apache::lonnet::host_domain($server);
16375: if ($serverdom eq $dom) {
16376: $canset{$server} = 1;
16377: }
16378: }
16379: }
16380: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
16381: %{$values{$dom}} = ();
16382: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
16383: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
16384: }
16385: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
16386: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
16387: }
16388: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16389: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
16390: }
16391: }
16392: my $output;
16393: if (keys(%canset)) {
16394: %{$wafproxy{'alias'}} = ();
16395: %{$wafproxy{'saml'}} = ();
16396: foreach my $key (sort(keys(%canset))) {
16397: if ($env{'form.wafproxy_'.$dom}) {
16398: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
16399: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
16400: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
16401: $changes{'alias'} = 1;
16402: }
16403: if ($env{'form.wafproxy_alias_saml_'.$key}) {
16404: $wafproxy{'saml'}{$key} = 1;
16405: }
16406: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
16407: $changes{'saml'} = 1;
16408: }
16409: } else {
16410: $wafproxy{'alias'}{$key} = '';
16411: $wafproxy{'saml'}{$key} = '';
16412: if ($curralias{$key}) {
16413: $changes{'alias'} = 1;
16414: }
16415: if ($currsaml{$key}) {
16416: $changes{'saml'} = 1;
16417: }
16418: }
16419: if ($wafproxy{'alias'}{$key} eq '') {
16420: if ($curralias{$key}) {
16421: $expirecache{$key} = 1;
16422: }
16423: delete($wafproxy{'alias'}{$key});
16424: }
16425: if ($wafproxy{'saml'}{$key} eq '') {
16426: if ($currsaml{$key}) {
16427: $expiresaml{$key} = 1;
16428: }
16429: delete($wafproxy{'saml'}{$key});
16430: }
16431: }
16432: unless (keys(%{$wafproxy{'alias'}})) {
16433: delete($wafproxy{'alias'});
16434: }
16435: unless (keys(%{$wafproxy{'saml'}})) {
16436: delete($wafproxy{'saml'});
16437: }
16438: # Localization for values in %warn occurs in &mt() calls separately.
16439: my %warn = (
16440: trusted => 'trusted IP range(s)',
16441: vpnint => 'internal IP range(s) for VPN sessions(s)',
16442: vpnext => 'IP range(s) for backend WAF connections',
16443: );
16444: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16445: my $possible = $env{'form.wafproxy_'.$item};
16446: $possible =~ s/^\s+|\s+$//g;
16447: if ($possible ne '') {
16448: if ($item eq 'remoteip') {
16449: if ($possible =~ /^[mhn]$/) {
16450: $wafproxy{$item} = $possible;
16451: }
16452: } elsif ($item eq 'ipheader') {
16453: if ($wafproxy{'remoteip'} eq 'h') {
16454: $wafproxy{$item} = $possible;
16455: }
16456: } elsif ($item eq 'sslopt') {
16457: if ($possible =~ /^0|1$/) {
16458: $wafproxy{$item} = $possible;
16459: }
16460: } else {
16461: my (@ok,$count);
16462: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
16463: unless ($env{'form.wafproxy_vpnaccess'}) {
16464: $possible = '';
16465: }
16466: } elsif ($item eq 'trusted') {
16467: unless ($wafproxy{'remoteip'} eq 'h') {
16468: $possible = '';
16469: }
16470: }
16471: unless ($possible eq '') {
16472: $possible =~ s/[\r\n]+/\s/g;
16473: $possible =~ s/\s*-\s*/-/g;
16474: $possible =~ s/\s+/,/g;
16475: $possible =~ s/,+/,/g;
16476: }
16477: $count = 0;
16478: if ($possible ne '') {
16479: foreach my $poss (split(/\,/,$possible)) {
16480: $count ++;
16481: $poss = &validate_ip_pattern($poss);
16482: if ($poss ne '') {
16483: push(@ok,$poss);
16484: }
16485: }
16486: my $diff = $count - scalar(@ok);
16487: if ($diff) {
16488: push(@warnings,'<li>'.
16489: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
16490: $diff,$warn{$item}).
16491: '</li>');
16492: }
16493: if (@ok) {
16494: my @cidr_list;
16495: foreach my $item (@ok) {
16496: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
16497: }
16498: $wafproxy{$item} = join(',',@cidr_list);
16499: }
16500: }
16501: }
16502: if ($wafproxy{$item} ne $currvalue{$item}) {
16503: $changes{$item} = 1;
16504: }
16505: } elsif ($currvalue{$item}) {
16506: $changes{$item} = 1;
16507: }
16508: }
16509: } else {
16510: if (keys(%curralias)) {
16511: $changes{'alias'} = 1;
16512: }
16513: if (keys(%currsaml)) {
16514: $changes{'saml'} = 1;
16515: }
16516: if (keys(%currvalue)) {
16517: foreach my $key (keys(%currvalue)) {
16518: $changes{$key} = 1;
16519: }
16520: }
16521: }
16522: if (keys(%changes)) {
16523: my %defaultshash = (
16524: wafproxy => \%wafproxy,
16525: );
16526: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16527: $dom);
16528: if ($putresult eq 'ok') {
16529: my $cachetime = 24*60*60;
16530: my (%domdefaults,$updatedomdefs);
16531: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
16532: if ($changes{$item}) {
16533: unless ($updatedomdefs) {
16534: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16535: $updatedomdefs = 1;
16536: }
16537: if ($wafproxy{$item}) {
16538: $domdefaults{'waf_'.$item} = $wafproxy{$item};
16539: } elsif (exists($domdefaults{'waf_'.$item})) {
16540: delete($domdefaults{'waf_'.$item});
16541: }
16542: }
16543: }
16544: if ($updatedomdefs) {
16545: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16546: if (ref($lastactref) eq 'HASH') {
16547: $lastactref->{'domdefaults'} = 1;
16548: }
16549: }
16550: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
16551: my %updates = %expirecache;
16552: foreach my $key (keys(%expirecache)) {
16553: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
16554: }
16555: if (ref($wafproxy{'alias'}) eq 'HASH') {
16556: my $cachetime = 24*60*60;
16557: foreach my $key (keys(%{$wafproxy{'alias'}})) {
16558: $updates{$key} = 1;
16559: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
16560: $cachetime);
16561: }
16562: }
16563: if (ref($lastactref) eq 'HASH') {
16564: $lastactref->{'proxyalias'} = \%updates;
16565: }
16566: }
16567: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
16568: my %samlupdates = %expiresaml;
16569: foreach my $key (keys(%expiresaml)) {
16570: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
16571: }
16572: if (ref($wafproxy{'saml'}) eq 'HASH') {
16573: my $cachetime = 24*60*60;
16574: foreach my $key (keys(%{$wafproxy{'saml'}})) {
16575: $samlupdates{$key} = 1;
16576: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
16577: $cachetime);
16578: }
16579: }
16580: if (ref($lastactref) eq 'HASH') {
16581: $lastactref->{'proxysaml'} = \%samlupdates;
16582: }
16583: }
16584: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
16585: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
16586: if ($changes{$item}) {
16587: if ($item eq 'alias') {
16588: my $numaliased = 0;
16589: if (ref($wafproxy{'alias'}) eq 'HASH') {
16590: my $shown;
16591: if (keys(%{$wafproxy{'alias'}})) {
16592: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
16593: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
16594: &Apache::lonnet::hostname($server),
16595: $wafproxy{'alias'}{$server}).'</li>';
16596: $numaliased ++;
16597: }
16598: if ($numaliased) {
16599: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
16600: '<ul>'.$shown.'</ul>').'</li>';
16601: }
16602: }
16603: }
16604: unless ($numaliased) {
16605: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
16606: }
16607: } elsif ($item eq 'saml') {
16608: my $shown;
16609: if (ref($wafproxy{'saml'}) eq 'HASH') {
16610: if (keys(%{$wafproxy{'saml'}})) {
16611: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
16612: }
16613: }
16614: if ($shown) {
16615: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
16616: $shown).'</li>';
16617: } else {
16618: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
16619: }
16620: } else {
16621: if ($item eq 'remoteip') {
16622: my %ip_methods = &remoteip_methods();
16623: if ($wafproxy{$item} =~ /^[mh]$/) {
16624: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
16625: $ip_methods{$wafproxy{$item}}).'</li>';
16626: } else {
16627: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
16628: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
16629: '</li>';
16630: } else {
16631: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
16632: }
16633: }
16634: } elsif ($item eq 'ipheader') {
16635: if ($wafproxy{$item}) {
16636: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
16637: $wafproxy{$item}).'</li>';
16638: } else {
16639: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
16640: }
16641: } elsif ($item eq 'trusted') {
16642: if ($wafproxy{$item}) {
16643: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
16644: $wafproxy{$item}).'</li>';
16645: } else {
16646: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
16647: }
16648: } elsif ($item eq 'vpnint') {
16649: if ($wafproxy{$item}) {
16650: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
16651: $wafproxy{$item}).'</li>';
16652: } else {
16653: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
16654: }
16655: } elsif ($item eq 'vpnext') {
16656: if ($wafproxy{$item}) {
16657: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
16658: $wafproxy{$item}).'</li>';
16659: } else {
16660: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
16661: }
16662: } elsif ($item eq 'sslopt') {
16663: if ($wafproxy{$item}) {
16664: $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>';
16665: } else {
16666: $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>';
16667: }
16668: }
16669: }
16670: }
16671: }
16672: $output .= '</ul>';
16673: } else {
16674: $output = '<span class="LC_error">'.
16675: &mt('An error occurred: [_1]',$putresult).'</span>';
16676: }
16677: } elsif (keys(%canset)) {
16678: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
16679: }
16680: if (@warnings) {
16681: $output .= '<br />'.&mt('Warnings:').'<ul>'.
16682: join("\n",@warnings).'</ul>';
16683: }
16684: return $output;
16685: }
16686:
16687: sub validate_ip_pattern {
16688: my ($pattern) = @_;
16689: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
16690: my ($start,$end) = ($1,$2);
16691: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
16692: if (($start !~ m{/}) && ($end !~ m{/})) {
16693: return $start.'-'.$end;
16694: }
16695: }
16696: } elsif ($pattern ne '') {
16697: $pattern = &Net::CIDR::cidrvalidate($pattern);
16698: if ($pattern ne '') {
16699: return $pattern;
16700: }
16701: }
16702: return;
16703: }
16704:
16705: sub modify_usersessions {
16706: my ($dom,$lastactref,%domconfig) = @_;
16707: my @hostingtypes = ('version','excludedomain','includedomain');
16708: my @offloadtypes = ('primary','default');
16709: my %types = (
16710: remote => \@hostingtypes,
16711: hosted => \@hostingtypes,
16712: spares => \@offloadtypes,
16713: );
16714: my @prefixes = ('remote','hosted','spares');
16715: my @lcversions = &Apache::lonnet::all_loncaparevs();
16716: my (%by_ip,%by_location,@intdoms);
16717: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
16718: my @locations = sort(keys(%by_location));
16719: my (%defaultshash,%changes);
16720: foreach my $prefix (@prefixes) {
16721: $defaultshash{'usersessions'}{$prefix} = {};
16722: }
16723: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16724: my $resulttext;
16725: my %iphost = &Apache::lonnet::get_iphost();
16726: foreach my $prefix (@prefixes) {
16727: next if ($prefix eq 'spares');
16728: foreach my $type (@{$types{$prefix}}) {
16729: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16730: if ($type eq 'version') {
16731: my $value = $env{'form.'.$prefix.'_'.$type};
16732: my $okvalue;
16733: if ($value ne '') {
16734: if (grep(/^\Q$value\E$/,@lcversions)) {
16735: $okvalue = $value;
16736: }
16737: }
16738: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16739: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16740: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16741: if ($inuse == 0) {
16742: $changes{$prefix}{$type} = 1;
16743: } else {
16744: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16745: $changes{$prefix}{$type} = 1;
16746: }
16747: if ($okvalue ne '') {
16748: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16749: }
16750: }
16751: } else {
16752: if (($inuse == 1) && ($okvalue ne '')) {
16753: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16754: $changes{$prefix}{$type} = 1;
16755: }
16756: }
16757: } else {
16758: if (($inuse == 1) && ($okvalue ne '')) {
16759: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16760: $changes{$prefix}{$type} = 1;
16761: }
16762: }
16763: } else {
16764: if (($inuse == 1) && ($okvalue ne '')) {
16765: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16766: $changes{$prefix}{$type} = 1;
16767: }
16768: }
16769: } else {
16770: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16771: my @okvals;
16772: foreach my $val (@vals) {
16773: if ($val =~ /:/) {
16774: my @items = split(/:/,$val);
16775: foreach my $item (@items) {
16776: if (ref($by_location{$item}) eq 'ARRAY') {
16777: push(@okvals,$item);
16778: }
16779: }
16780: } else {
16781: if (ref($by_location{$val}) eq 'ARRAY') {
16782: push(@okvals,$val);
16783: }
16784: }
16785: }
16786: @okvals = sort(@okvals);
16787: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16788: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16789: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16790: if ($inuse == 0) {
16791: $changes{$prefix}{$type} = 1;
16792: } else {
16793: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16794: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16795: if (@changed > 0) {
16796: $changes{$prefix}{$type} = 1;
16797: }
16798: }
16799: } else {
16800: if ($inuse == 1) {
16801: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16802: $changes{$prefix}{$type} = 1;
16803: }
16804: }
16805: } else {
16806: if ($inuse == 1) {
16807: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16808: $changes{$prefix}{$type} = 1;
16809: }
16810: }
16811: } else {
16812: if ($inuse == 1) {
16813: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16814: $changes{$prefix}{$type} = 1;
16815: }
16816: }
16817: }
16818: }
16819: }
16820:
16821: my @alldoms = &Apache::lonnet::all_domains();
16822: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16823: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16824: my $savespares;
16825:
16826: foreach my $lonhost (sort(keys(%servers))) {
16827: my $serverhomeID =
16828: &Apache::lonnet::get_server_homeID($servers{$lonhost});
16829: my $serverhostname = &Apache::lonnet::hostname($lonhost);
16830: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16831: my %spareschg;
16832: foreach my $type (@{$types{'spares'}}) {
16833: my @okspares;
16834: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16835: foreach my $server (@checked) {
16836: if (&Apache::lonnet::hostname($server) ne '') {
16837: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16838: unless (grep(/^\Q$server\E$/,@okspares)) {
16839: push(@okspares,$server);
16840: }
16841: }
16842: }
16843: }
16844: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16845: my $newspare;
16846: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16847: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
16848: $newspare = $new;
16849: }
16850: }
16851: my @spares;
16852: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16853: @spares = sort(@okspares,$newspare);
16854: } else {
16855: @spares = sort(@okspares);
16856: }
16857: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
16858: if (ref($spareid{$lonhost}) eq 'HASH') {
16859: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
16860: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
16861: if (@diffs > 0) {
16862: $spareschg{$type} = 1;
16863: }
16864: }
16865: }
16866: }
16867: if (keys(%spareschg) > 0) {
16868: $changes{'spares'}{$lonhost} = \%spareschg;
16869: }
16870: }
16871: $defaultshash{'usersessions'}{'offloadnow'} = {};
16872: $defaultshash{'usersessions'}{'offloadoth'} = {};
16873: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16874: my @okoffload;
16875: if (@offloadnow) {
16876: foreach my $server (@offloadnow) {
16877: if (&Apache::lonnet::hostname($server) ne '') {
16878: unless (grep(/^\Q$server\E$/,@okoffload)) {
16879: push(@okoffload,$server);
16880: }
16881: }
16882: }
16883: if (@okoffload) {
16884: foreach my $lonhost (@okoffload) {
16885: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16886: }
16887: }
16888: }
16889: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16890: my @okoffloadoth;
16891: if (@offloadoth) {
16892: foreach my $server (@offloadoth) {
16893: if (&Apache::lonnet::hostname($server) ne '') {
16894: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16895: push(@okoffloadoth,$server);
16896: }
16897: }
16898: }
16899: if (@okoffloadoth) {
16900: foreach my $lonhost (@okoffloadoth) {
16901: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16902: }
16903: }
16904: }
16905: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16906: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16907: if (ref($changes{'spares'}) eq 'HASH') {
16908: if (keys(%{$changes{'spares'}}) > 0) {
16909: $savespares = 1;
16910: }
16911: }
16912: } else {
16913: $savespares = 1;
16914: }
16915: foreach my $offload ('offloadnow','offloadoth') {
16916: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16917: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16918: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16919: $changes{$offload} = 1;
16920: last;
16921: }
16922: }
16923: unless ($changes{$offload}) {
16924: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16925: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16926: $changes{$offload} = 1;
16927: last;
16928: }
16929: }
16930: }
16931: } else {
16932: if (($offload eq 'offloadnow') && (@okoffload)) {
16933: $changes{'offloadnow'} = 1;
16934: }
16935: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16936: $changes{'offloadoth'} = 1;
16937: }
16938: }
16939: }
16940: } else {
16941: if (@okoffload) {
16942: $changes{'offloadnow'} = 1;
16943: }
16944: if (@okoffloadoth) {
16945: $changes{'offloadoth'} = 1;
16946: }
16947: }
16948: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16949: if ((keys(%changes) > 0) || ($savespares)) {
16950: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16951: $dom);
16952: if ($putresult eq 'ok') {
16953: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16954: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16955: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16956: }
16957: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16958: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16959: }
16960: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16961: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16962: }
16963: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16964: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16965: }
16966: }
16967: my $cachetime = 24*60*60;
16968: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16969: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
16970: if (ref($lastactref) eq 'HASH') {
16971: $lastactref->{'domdefaults'} = 1;
16972: $lastactref->{'usersessions'} = 1;
16973: }
16974: if (keys(%changes) > 0) {
16975: my %lt = &usersession_titles();
16976: $resulttext = &mt('Changes made:').'<ul>';
16977: foreach my $prefix (@prefixes) {
16978: if (ref($changes{$prefix}) eq 'HASH') {
16979: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16980: if ($prefix eq 'spares') {
16981: if (ref($changes{$prefix}) eq 'HASH') {
16982: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16983: $resulttext .= '<li><b>'.$lonhost.'</b> ';
16984: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
16985: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16986: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16987: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16988: foreach my $type (@{$types{$prefix}}) {
16989: if ($changes{$prefix}{$lonhost}{$type}) {
16990: my $offloadto = &mt('None');
16991: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16992: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16993: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16994: }
16995: }
16996: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
16997: }
16998: }
16999: }
17000: $resulttext .= '</li>';
17001: }
17002: }
17003: } else {
17004: foreach my $type (@{$types{$prefix}}) {
17005: if (defined($changes{$prefix}{$type})) {
17006: my $newvalue;
17007: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
17008: if (ref($defaultshash{'usersessions'}{$prefix})) {
17009: if ($type eq 'version') {
17010: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
17011: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17012: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
17013: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
17014: }
17015: }
17016: }
17017: }
17018: if ($newvalue eq '') {
17019: if ($type eq 'version') {
17020: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
17021: } else {
17022: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
17023: }
17024: } else {
17025: if ($type eq 'version') {
17026: $newvalue .= ' '.&mt('(or later)');
17027: }
17028: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
17029: }
17030: }
17031: }
17032: }
17033: $resulttext .= '</ul>';
17034: }
17035: }
17036: if ($changes{'offloadnow'}) {
17037: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17038: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
17039: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
17040: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
17041: $resulttext .= '<li>'.$lonhost.'</li>';
17042: }
17043: $resulttext .= '</ul>';
17044: } else {
17045: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
17046: }
17047: } else {
17048: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
17049: }
17050: }
17051: if ($changes{'offloadoth'}) {
17052: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
17053: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
17054: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
17055: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
17056: $resulttext .= '<li>'.$lonhost.'</li>';
17057: }
17058: $resulttext .= '</ul>';
17059: } else {
17060: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
17061: }
17062: } else {
17063: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
17064: }
17065: }
17066: $resulttext .= '</ul>';
17067: } else {
17068: $resulttext = $nochgmsg;
17069: }
17070: } else {
17071: $resulttext = '<span class="LC_error">'.
17072: &mt('An error occurred: [_1]',$putresult).'</span>';
17073: }
17074: } else {
17075: $resulttext = $nochgmsg;
17076: }
17077: return $resulttext;
17078: }
17079:
17080: sub modify_loadbalancing {
17081: my ($dom,%domconfig) = @_;
17082: my $primary_id = &Apache::lonnet::domain($dom,'primary');
17083: my $intdom = &Apache::lonnet::internet_dom($primary_id);
17084: my ($othertitle,$usertypes,$types) =
17085: &Apache::loncommon::sorted_inst_types($dom);
17086: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17087: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
17088: my @sparestypes = ('primary','default');
17089: my %typetitles = &sparestype_titles();
17090: my $resulttext;
17091: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
17092: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17093: %existing = %{$domconfig{'loadbalancing'}};
17094: }
17095: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
17096: \%currtargets,\%currrules,\%currcookies);
17097: my ($saveloadbalancing,%defaultshash,%changes);
17098: my ($alltypes,$othertypes,$titles) =
17099: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
17100: my %ruletitles = &offloadtype_text();
17101: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
17102: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
17103: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
17104: if ($balancer eq '') {
17105: next;
17106: }
17107: if (!exists($servers{$balancer})) {
17108: if (exists($currbalancer{$balancer})) {
17109: push(@{$changes{'delete'}},$balancer);
17110: }
17111: next;
17112: }
17113: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
17114: push(@{$changes{'delete'}},$balancer);
17115: next;
17116: }
17117: if (!exists($currbalancer{$balancer})) {
17118: push(@{$changes{'add'}},$balancer);
17119: }
17120: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
17121: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
17122: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
17123: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17124: $saveloadbalancing = 1;
17125: }
17126: foreach my $sparetype (@sparestypes) {
17127: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
17128: my @offloadto;
17129: foreach my $target (@targets) {
17130: if (($servers{$target}) && ($target ne $balancer)) {
17131: if ($sparetype eq 'default') {
17132: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
17133: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
17134: }
17135: }
17136: unless(grep(/^\Q$target\E$/,@offloadto)) {
17137: push(@offloadto,$target);
17138: }
17139: }
17140: }
17141: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
17142: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
17143: push(@offloadto,$balancer);
17144: }
17145: }
17146: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
17147: }
17148: if ($env{'form.loadbalancing_cookie_'.$i}) {
17149: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
17150: if (exists($currbalancer{$balancer})) {
17151: unless ($currcookies{$balancer}) {
17152: $changes{'curr'}{$balancer}{'cookie'} = 1;
17153: }
17154: }
17155: } elsif (exists($currbalancer{$balancer})) {
17156: if ($currcookies{$balancer}) {
17157: $changes{'curr'}{$balancer}{'cookie'} = 1;
17158: }
17159: }
17160: if (ref($currtargets{$balancer}) eq 'HASH') {
17161: foreach my $sparetype (@sparestypes) {
17162: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
17163: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
17164: if (@targetdiffs > 0) {
17165: $changes{'curr'}{$balancer}{'targets'} = 1;
17166: }
17167: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17168: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17169: $changes{'curr'}{$balancer}{'targets'} = 1;
17170: }
17171: }
17172: }
17173: } else {
17174: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
17175: foreach my $sparetype (@sparestypes) {
17176: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17177: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17178: $changes{'curr'}{$balancer}{'targets'} = 1;
17179: }
17180: }
17181: }
17182: }
17183: }
17184: my $ishomedom;
17185: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
17186: $ishomedom = 1;
17187: }
17188: if (ref($alltypes) eq 'ARRAY') {
17189: foreach my $type (@{$alltypes}) {
17190: my $rule;
17191: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
17192: (!$ishomedom)) {
17193: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
17194: }
17195: if ($rule eq 'specific') {
17196: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
17197: if (exists($servers{$specifiedhost})) {
17198: $rule = $specifiedhost;
17199: }
17200: }
17201: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
17202: if (ref($currrules{$balancer}) eq 'HASH') {
17203: if ($rule ne $currrules{$balancer}{$type}) {
17204: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
17205: }
17206: } elsif ($rule ne '') {
17207: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
17208: }
17209: }
17210: }
17211: }
17212: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
17213: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
17214: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
17215: $defaultshash{'loadbalancing'} = {};
17216: }
17217: my $putresult = &Apache::lonnet::put_dom('configuration',
17218: \%defaultshash,$dom);
17219: if ($putresult eq 'ok') {
17220: if (keys(%changes) > 0) {
17221: my %toupdate;
17222: if (ref($changes{'delete'}) eq 'ARRAY') {
17223: foreach my $balancer (sort(@{$changes{'delete'}})) {
17224: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
17225: $toupdate{$balancer} = 1;
17226: }
17227: }
17228: if (ref($changes{'add'}) eq 'ARRAY') {
17229: foreach my $balancer (sort(@{$changes{'add'}})) {
17230: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
17231: $toupdate{$balancer} = 1;
17232: }
17233: }
17234: if (ref($changes{'curr'}) eq 'HASH') {
17235: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
17236: $toupdate{$balancer} = 1;
17237: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
17238: if ($changes{'curr'}{$balancer}{'targets'}) {
17239: my %offloadstr;
17240: foreach my $sparetype (@sparestypes) {
17241: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17242: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17243: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17244: }
17245: }
17246: }
17247: if (keys(%offloadstr) == 0) {
17248: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
17249: } else {
17250: my $showoffload;
17251: foreach my $sparetype (@sparestypes) {
17252: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17253: if (defined($offloadstr{$sparetype})) {
17254: $showoffload .= $offloadstr{$sparetype};
17255: } else {
17256: $showoffload .= &mt('None');
17257: }
17258: $showoffload .= (' 'x3);
17259: }
17260: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
17261: }
17262: }
17263: }
17264: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17265: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17266: foreach my $type (@{$alltypes}) {
17267: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17268: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17269: my $balancetext;
17270: if ($rule eq '') {
17271: $balancetext = $ruletitles{'default'};
17272: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
17273: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
17274: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
17275: foreach my $sparetype (@sparestypes) {
17276: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17277: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17278: }
17279: }
17280: foreach my $item (@{$alltypes}) {
17281: next if ($item =~ /^_LC_ipchange/);
17282: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17283: if ($hasrule eq 'homeserver') {
17284: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17285: } else {
17286: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17287: if ($servers{$hasrule}) {
17288: $toupdate{$hasrule} = 1;
17289: }
17290: }
17291: }
17292: }
17293: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17294: $balancetext = $ruletitles{$rule};
17295: } else {
17296: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17297: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17298: if ($receiver) {
17299: $toupdate{$receiver};
17300: }
17301: }
17302: } else {
17303: $balancetext = $ruletitles{$rule};
17304: }
17305: } else {
17306: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17307: }
17308: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
17309: }
17310: }
17311: }
17312: }
17313: if ($changes{'curr'}{$balancer}{'cookie'}) {
17314: if ($currcookies{$balancer}) {
17315: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
17316: $balancer).'</li>';
17317: } else {
17318: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17319: $balancer).'</li>';
17320: }
17321: }
17322: }
17323: }
17324: if (keys(%toupdate)) {
17325: my %thismachine;
17326: my $updatedhere;
17327: my $cachetime = 60*60*24;
17328: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17329: foreach my $lonhost (keys(%toupdate)) {
17330: if ($thismachine{$lonhost}) {
17331: unless ($updatedhere) {
17332: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17333: $defaultshash{'loadbalancing'},
17334: $cachetime);
17335: $updatedhere = 1;
17336: }
17337: } else {
17338: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17339: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
17340: }
17341: }
17342: }
17343: if ($resulttext ne '') {
17344: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
17345: } else {
17346: $resulttext = $nochgmsg;
17347: }
17348: } else {
17349: $resulttext = $nochgmsg;
17350: }
17351: } else {
17352: $resulttext = '<span class="LC_error">'.
17353: &mt('An error occurred: [_1]',$putresult).'</span>';
17354: }
17355: } else {
17356: $resulttext = $nochgmsg;
17357: }
17358: return $resulttext;
17359: }
17360:
17361: sub recurse_check {
17362: my ($chkcats,$categories,$depth,$name) = @_;
17363: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17364: my $chg = 0;
17365: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17366: my $category = $chkcats->[$depth]{$name}[$j];
17367: my $item;
17368: if ($category eq '') {
17369: $chg ++;
17370: } else {
17371: my $deeper = $depth + 1;
17372: $item = &escape($category).':'.&escape($name).':'.$depth;
17373: if ($chg) {
17374: $categories->{$item} -= $chg;
17375: }
17376: &recurse_check($chkcats,$categories,$deeper,$category);
17377: $deeper --;
17378: }
17379: }
17380: }
17381: return;
17382: }
17383:
17384: sub recurse_cat_deletes {
17385: my ($item,$coursecategories,$deletions) = @_;
17386: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17387: my $subdepth = $depth + 1;
17388: if (ref($coursecategories) eq 'HASH') {
17389: foreach my $subitem (keys(%{$coursecategories})) {
17390: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17391: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17392: delete($coursecategories->{$subitem});
17393: $deletions->{$subitem} = 1;
17394: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
17395: }
17396: }
17397: }
17398: return;
17399: }
17400:
17401: sub active_dc_picker {
17402: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
17403: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17404: my @domcoord = keys(%domcoords);
17405: if (keys(%currhash)) {
17406: foreach my $dc (keys(%currhash)) {
17407: unless (exists($domcoords{$dc})) {
17408: push(@domcoord,$dc);
17409: }
17410: }
17411: }
17412: @domcoord = sort(@domcoord);
17413: my $numdcs = scalar(@domcoord);
17414: my $rows = 0;
17415: my $table;
17416: if ($numdcs > 1) {
17417: $table = '<table>';
17418: for (my $i=0; $i<@domcoord; $i++) {
17419: my $rem = $i%($numinrow);
17420: if ($rem == 0) {
17421: if ($i > 0) {
17422: $table .= '</tr>';
17423: }
17424: $table .= '<tr>';
17425: $rows ++;
17426: }
17427: my $check = '';
17428: if ($inputtype eq 'radio') {
17429: if (keys(%currhash) == 0) {
17430: if (!$i) {
17431: $check = ' checked="checked"';
17432: }
17433: } elsif (exists($currhash{$domcoord[$i]})) {
17434: $check = ' checked="checked"';
17435: }
17436: } else {
17437: if (exists($currhash{$domcoord[$i]})) {
17438: $check = ' checked="checked"';
17439: }
17440: }
17441: if ($i == @domcoord - 1) {
17442: my $colsleft = $numinrow - $rem;
17443: if ($colsleft > 1) {
17444: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
17445: } else {
17446: $table .= '<td class="LC_left_item">';
17447: }
17448: } else {
17449: $table .= '<td class="LC_left_item">';
17450: }
17451: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17452: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17453: $table .= '<span class="LC_nobreak"><label>'.
17454: '<input type="'.$inputtype.'" name="'.$name.'"'.
17455: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17456: if ($user ne $dcname.':'.$dcdom) {
17457: $table .= ' ('.$dcname.':'.$dcdom.')';
17458: }
17459: $table .= '</label></span></td>';
17460: }
17461: $table .= '</tr></table>';
17462: } elsif ($numdcs == 1) {
17463: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17464: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17465: if ($inputtype eq 'radio') {
17466: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
17467: if ($user ne $dcname.':'.$dcdom) {
17468: $table .= ' ('.$dcname.':'.$dcdom.')';
17469: }
17470: } else {
17471: my $check;
17472: if (exists($currhash{$domcoord[0]})) {
17473: $check = ' checked="checked"';
17474: }
17475: $table = '<span class="LC_nobreak"><label>'.
17476: '<input type="checkbox" name="'.$name.'" '.
17477: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
17478: if ($user ne $dcname.':'.$dcdom) {
17479: $table .= ' ('.$dcname.':'.$dcdom.')';
17480: }
17481: $table .= '</label></span>';
17482: $rows ++;
17483: }
17484: }
17485: return ($numdcs,$table,$rows);
17486: }
17487:
17488: sub usersession_titles {
17489: return &Apache::lonlocal::texthash(
17490: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17491: remote => 'Hosting of sessions for users in this domain on servers in other domains',
17492: spares => 'Servers offloaded to, when busy',
17493: version => 'LON-CAPA version requirement',
17494: excludedomain => 'Allow all, but exclude specific domains',
17495: includedomain => 'Deny all, but include specific domains',
17496: primary => 'Primary (checked first)',
17497: default => 'Default',
17498: );
17499: }
17500:
17501: sub id_for_thisdom {
17502: my (%servers) = @_;
17503: my %altids;
17504: foreach my $server (keys(%servers)) {
17505: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17506: if ($serverhome ne $server) {
17507: $altids{$serverhome} = $server;
17508: }
17509: }
17510: return %altids;
17511: }
17512:
17513: sub count_servers {
17514: my ($currbalancer,%servers) = @_;
17515: my (@spares,$numspares);
17516: foreach my $lonhost (sort(keys(%servers))) {
17517: next if ($currbalancer eq $lonhost);
17518: push(@spares,$lonhost);
17519: }
17520: if ($currbalancer) {
17521: $numspares = scalar(@spares);
17522: } else {
17523: $numspares = scalar(@spares) - 1;
17524: }
17525: return ($numspares,@spares);
17526: }
17527:
17528: sub lonbalance_targets_js {
17529: my ($dom,$types,$servers,$settings) = @_;
17530: my $select = &mt('Select');
17531: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17532: if (ref($servers) eq 'HASH') {
17533: $alltargets = join("','",sort(keys(%{$servers})));
17534: my @homedoms;
17535: foreach my $server (sort(keys(%{$servers}))) {
17536: if (&Apache::lonnet::host_domain($server) eq $dom) {
17537: push(@homedoms,'1');
17538: } else {
17539: push(@homedoms,'0');
17540: }
17541: }
17542: $allishome = join("','",@homedoms);
17543: }
17544: if (ref($types) eq 'ARRAY') {
17545: if (@{$types} > 0) {
17546: @alltypes = @{$types};
17547: }
17548: }
17549: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17550: $allinsttypes = join("','",@alltypes);
17551: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
17552: if (ref($settings) eq 'HASH') {
17553: %existing = %{$settings};
17554: }
17555: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
17556: \%currtargets,\%currrules,\%currcookies);
17557: my $balancers = join("','",sort(keys(%currbalancer)));
17558: return <<"END";
17559:
17560: <script type="text/javascript">
17561: // <![CDATA[
17562:
17563: currBalancers = new Array('$balancers');
17564:
17565: function toggleTargets(balnum) {
17566: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17567: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17568: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17569: var prevbalancer = prevhostitem.value;
17570: var baltotal = document.getElementById('loadbalancing_total').value;
17571: prevhostitem.value = balancer;
17572: if (prevbalancer != '') {
17573: var prevIdx = currBalancers.indexOf(prevbalancer);
17574: if (prevIdx != -1) {
17575: currBalancers.splice(prevIdx,1);
17576: }
17577: }
17578: if (balancer == '') {
17579: hideSpares(balnum);
17580: } else {
17581: var currIdx = currBalancers.indexOf(balancer);
17582: if (currIdx == -1) {
17583: currBalancers.push(balancer);
17584: }
17585: var homedoms = new Array('$allishome');
17586: var ishomedom = homedoms[lonhostitem.selectedIndex];
17587: showSpares(balancer,ishomedom,balnum);
17588: }
17589: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
17590: return;
17591: }
17592:
17593: function showSpares(balancer,ishomedom,balnum) {
17594: var alltargets = new Array('$alltargets');
17595: var insttypes = new Array('$allinsttypes');
17596: var offloadtypes = new Array('primary','default');
17597:
17598: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17599: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
17600:
17601: for (var i=0; i<offloadtypes.length; i++) {
17602: var count = 0;
17603: for (var j=0; j<alltargets.length; j++) {
17604: if (alltargets[j] != balancer) {
17605: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17606: item.value = alltargets[j];
17607: item.style.textAlign='left';
17608: item.style.textFace='normal';
17609: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17610: if (currBalancers.indexOf(alltargets[j]) == -1) {
17611: item.disabled = '';
17612: } else {
17613: item.disabled = 'disabled';
17614: item.checked = false;
17615: }
17616: count ++;
17617: }
17618: }
17619: }
17620: for (var k=0; k<insttypes.length; k++) {
17621: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
17622: if (ishomedom == 1) {
17623: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17624: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
17625: } else {
17626: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17627: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
17628: }
17629: } else {
17630: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17631: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
17632: }
17633: if ((insttypes[k] != '_LC_external') &&
17634: ((insttypes[k] != '_LC_internetdom') ||
17635: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
17636: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17637: item.options.length = 0;
17638: item.options[0] = new Option("","",true,true);
17639: var idx = 0;
17640: for (var m=0; m<alltargets.length; m++) {
17641: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17642: idx ++;
17643: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17644: }
17645: }
17646: }
17647: }
17648: return;
17649: }
17650:
17651: function hideSpares(balnum) {
17652: var alltargets = new Array('$alltargets');
17653: var insttypes = new Array('$allinsttypes');
17654: var offloadtypes = new Array('primary','default');
17655:
17656: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17657: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
17658:
17659: var total = alltargets.length - 1;
17660: for (var i=0; i<offloadtypes; i++) {
17661: for (var j=0; j<total; j++) {
17662: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17663: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17664: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
17665: }
17666: }
17667: for (var k=0; k<insttypes.length; k++) {
17668: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17669: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
17670: if (insttypes[k] != '_LC_external') {
17671: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17672: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
17673: }
17674: }
17675: return;
17676: }
17677:
17678: function checkOffloads(item,balnum,type) {
17679: var alltargets = new Array('$alltargets');
17680: var offloadtypes = new Array('primary','default');
17681: if (item.checked) {
17682: var total = alltargets.length - 1;
17683: var other;
17684: if (type == offloadtypes[0]) {
17685: other = offloadtypes[1];
17686: } else {
17687: other = offloadtypes[0];
17688: }
17689: for (var i=0; i<total; i++) {
17690: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
17691: if (server == item.value) {
17692: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17693: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
17694: }
17695: }
17696: }
17697: }
17698: return;
17699: }
17700:
17701: function singleServerToggle(balnum,type) {
17702: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
17703: if (offloadtoSelIdx == 0) {
17704: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17705: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
17706:
17707: } else {
17708: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17709: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17710: }
17711: return;
17712: }
17713:
17714: function balanceruleChange(formname,balnum,type) {
17715: if (type == '_LC_external') {
17716: return;
17717: }
17718: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
17719: for (var i=0; i<typesRules.length; i++) {
17720: if (formname.elements[typesRules[i]].checked) {
17721: if (formname.elements[typesRules[i]].value != 'specific') {
17722: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17723: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
17724: } else {
17725: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17726: }
17727: }
17728: }
17729: return;
17730: }
17731:
17732: function balancerDeleteChange(balnum) {
17733: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17734: var baltotal = document.getElementById('loadbalancing_total').value;
17735: var addtarget;
17736: var removetarget;
17737: var action = 'delete';
17738: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17739: var lonhost = hostitem.value;
17740: var currIdx = currBalancers.indexOf(lonhost);
17741: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17742: if (currIdx != -1) {
17743: currBalancers.splice(currIdx,1);
17744: }
17745: addtarget = lonhost;
17746: } else {
17747: if (currIdx == -1) {
17748: currBalancers.push(lonhost);
17749: }
17750: removetarget = lonhost;
17751: action = 'undelete';
17752: }
17753: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17754: }
17755: return;
17756: }
17757:
17758: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17759: if (baltotal > 1) {
17760: var offloadtypes = new Array('primary','default');
17761: var alltargets = new Array('$alltargets');
17762: var insttypes = new Array('$allinsttypes');
17763: for (var i=0; i<baltotal; i++) {
17764: if (i != balnum) {
17765: for (var j=0; j<offloadtypes.length; j++) {
17766: var total = alltargets.length - 1;
17767: for (var k=0; k<total; k++) {
17768: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17769: var server = serveritem.value;
17770: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17771: if (server == addtarget) {
17772: serveritem.disabled = '';
17773: }
17774: }
17775: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17776: if (server == removetarget) {
17777: serveritem.disabled = 'disabled';
17778: serveritem.checked = false;
17779: }
17780: }
17781: }
17782: }
17783: for (var j=0; j<insttypes.length; j++) {
17784: if (insttypes[j] != '_LC_external') {
17785: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17786: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17787: var currSel = singleserver.selectedIndex;
17788: var currVal = singleserver.options[currSel].value;
17789: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17790: var numoptions = singleserver.options.length;
17791: var needsnew = 1;
17792: for (var k=0; k<numoptions; k++) {
17793: if (singleserver.options[k] == addtarget) {
17794: needsnew = 0;
17795: break;
17796: }
17797: }
17798: if (needsnew == 1) {
17799: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17800: }
17801: }
17802: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17803: singleserver.options.length = 0;
17804: if ((currVal) && (currVal != removetarget)) {
17805: singleserver.options[0] = new Option("","",false,false);
17806: } else {
17807: singleserver.options[0] = new Option("","",true,true);
17808: }
17809: var idx = 0;
17810: for (var m=0; m<alltargets.length; m++) {
17811: if (currBalancers.indexOf(alltargets[m]) == -1) {
17812: idx ++;
17813: if (currVal == alltargets[m]) {
17814: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17815: } else {
17816: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17817: }
17818: }
17819: }
17820: }
17821: }
17822: }
17823: }
17824: }
17825: }
17826: }
17827: return;
17828: }
17829:
17830: // ]]>
17831: </script>
17832:
17833: END
17834: }
17835:
17836: sub new_spares_js {
17837: my @sparestypes = ('primary','default');
17838: my $types = join("','",@sparestypes);
17839: my $select = &mt('Select');
17840: return <<"END";
17841:
17842: <script type="text/javascript">
17843: // <![CDATA[
17844:
17845: function updateNewSpares(formname,lonhost) {
17846: var types = new Array('$types');
17847: var include = new Array();
17848: var exclude = new Array();
17849: for (var i=0; i<types.length; i++) {
17850: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17851: for (var j=0; j<spareboxes.length; j++) {
17852: if (formname.elements[spareboxes[j]].checked) {
17853: exclude.push(formname.elements[spareboxes[j]].value);
17854: } else {
17855: include.push(formname.elements[spareboxes[j]].value);
17856: }
17857: }
17858: }
17859: for (var i=0; i<types.length; i++) {
17860: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17861: var selIdx = newSpare.selectedIndex;
17862: var currnew = newSpare.options[selIdx].value;
17863: var okSpares = new Array();
17864: for (var j=0; j<newSpare.options.length; j++) {
17865: var possible = newSpare.options[j].value;
17866: if (possible != '') {
17867: if (exclude.indexOf(possible) == -1) {
17868: okSpares.push(possible);
17869: } else {
17870: if (currnew == possible) {
17871: selIdx = 0;
17872: }
17873: }
17874: }
17875: }
17876: for (var k=0; k<include.length; k++) {
17877: if (okSpares.indexOf(include[k]) == -1) {
17878: okSpares.push(include[k]);
17879: }
17880: }
17881: okSpares.sort();
17882: newSpare.options.length = 0;
17883: if (selIdx == 0) {
17884: newSpare.options[0] = new Option("$select","",true,true);
17885: } else {
17886: newSpare.options[0] = new Option("$select","",false,false);
17887: }
17888: for (var m=0; m<okSpares.length; m++) {
17889: var idx = m+1;
17890: var selThis = 0;
17891: if (selIdx != 0) {
17892: if (okSpares[m] == currnew) {
17893: selThis = 1;
17894: }
17895: }
17896: if (selThis == 1) {
17897: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17898: } else {
17899: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17900: }
17901: }
17902: }
17903: return;
17904: }
17905:
17906: function checkNewSpares(lonhost,type) {
17907: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17908: var chosen = newSpare.options[newSpare.selectedIndex].value;
17909: if (chosen != '') {
17910: var othertype;
17911: var othernewSpare;
17912: if (type == 'primary') {
17913: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17914: }
17915: if (type == 'default') {
17916: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17917: }
17918: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17919: othernewSpare.selectedIndex = 0;
17920: }
17921: }
17922: return;
17923: }
17924:
17925: // ]]>
17926: </script>
17927:
17928: END
17929:
17930: }
17931:
17932: sub common_domprefs_js {
17933: return <<"END";
17934:
17935: <script type="text/javascript">
17936: // <![CDATA[
17937:
17938: function getIndicesByName(formname,item) {
17939: var group = new Array();
17940: for (var i=0;i<formname.elements.length;i++) {
17941: if (formname.elements[i].name == item) {
17942: group.push(formname.elements[i].id);
17943: }
17944: }
17945: return group;
17946: }
17947:
17948: // ]]>
17949: </script>
17950:
17951: END
17952:
17953: }
17954:
17955: sub recaptcha_js {
17956: my %lt = &captcha_phrases();
17957: return <<"END";
17958:
17959: <script type="text/javascript">
17960: // <![CDATA[
17961:
17962: function updateCaptcha(caller,context) {
17963: var privitem;
17964: var pubitem;
17965: var privtext;
17966: var pubtext;
17967: var versionitem;
17968: var versiontext;
17969: if (document.getElementById(context+'_recaptchapub')) {
17970: pubitem = document.getElementById(context+'_recaptchapub');
17971: } else {
17972: return;
17973: }
17974: if (document.getElementById(context+'_recaptchapriv')) {
17975: privitem = document.getElementById(context+'_recaptchapriv');
17976: } else {
17977: return;
17978: }
17979: if (document.getElementById(context+'_recaptchapubtxt')) {
17980: pubtext = document.getElementById(context+'_recaptchapubtxt');
17981: } else {
17982: return;
17983: }
17984: if (document.getElementById(context+'_recaptchaprivtxt')) {
17985: privtext = document.getElementById(context+'_recaptchaprivtxt');
17986: } else {
17987: return;
17988: }
17989: if (document.getElementById(context+'_recaptchaversion')) {
17990: versionitem = document.getElementById(context+'_recaptchaversion');
17991: } else {
17992: return;
17993: }
17994: if (document.getElementById(context+'_recaptchavertxt')) {
17995: versiontext = document.getElementById(context+'_recaptchavertxt');
17996: } else {
17997: return;
17998: }
17999: if (caller.checked) {
18000: if (caller.value == 'recaptcha') {
18001: pubitem.type = 'text';
18002: privitem.type = 'text';
18003: pubitem.size = '40';
18004: privitem.size = '40';
18005: pubtext.innerHTML = "$lt{'pub'}";
18006: privtext.innerHTML = "$lt{'priv'}";
18007: versionitem.type = 'text';
18008: versionitem.size = '3';
18009: versiontext.innerHTML = "$lt{'ver'}";
18010: } else {
18011: pubitem.type = 'hidden';
18012: privitem.type = 'hidden';
18013: versionitem.type = 'hidden';
18014: pubtext.innerHTML = '';
18015: privtext.innerHTML = '';
18016: versiontext.innerHTML = '';
18017: }
18018: }
18019: return;
18020: }
18021:
18022: // ]]>
18023: </script>
18024:
18025: END
18026:
18027: }
18028:
18029: sub toggle_display_js {
18030: return <<"END";
18031:
18032: <script type="text/javascript">
18033: // <![CDATA[
18034:
18035: function toggleDisplay(domForm,caller) {
18036: if (document.getElementById(caller)) {
18037: var divitem = document.getElementById(caller);
18038: var optionsElement = domForm.coursecredits;
18039: var checkval = 1;
18040: var dispval = 'block';
18041: var selfcreateRegExp = /^cancreate_emailverified/;
18042: if (caller == 'emailoptions') {
18043: optionsElement = domForm.cancreate_email;
18044: }
18045: if (caller == 'studentsubmission') {
18046: optionsElement = domForm.postsubmit;
18047: }
18048: if (caller == 'cloneinstcode') {
18049: optionsElement = domForm.canclone;
18050: checkval = 'instcode';
18051: }
18052: if (selfcreateRegExp.test(caller)) {
18053: optionsElement = domForm.elements[caller];
18054: checkval = 'other';
18055: dispval = 'inline'
18056: }
18057: if (optionsElement.length) {
18058: var currval;
18059: for (var i=0; i<optionsElement.length; i++) {
18060: if (optionsElement[i].checked) {
18061: currval = optionsElement[i].value;
18062: }
18063: }
18064: if (currval == checkval) {
18065: divitem.style.display = dispval;
18066: } else {
18067: divitem.style.display = 'none';
18068: }
18069: }
18070: }
18071: return;
18072: }
18073:
18074: // ]]>
18075: </script>
18076:
18077: END
18078:
18079: }
18080:
18081: sub captcha_phrases {
18082: return &Apache::lonlocal::texthash (
18083: priv => 'Private key',
18084: pub => 'Public key',
18085: original => 'original (CAPTCHA)',
18086: recaptcha => 'successor (ReCAPTCHA)',
18087: notused => 'unused',
18088: ver => 'ReCAPTCHA version (1 or 2)',
18089: );
18090: }
18091:
18092: sub devalidate_remote_domconfs {
18093: my ($dom,$cachekeys) = @_;
18094: return unless (ref($cachekeys) eq 'HASH');
18095: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18096: my %thismachine;
18097: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
18098: my @posscached = ('domainconfig','domdefaults','usersessions',
18099: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
18100: 'ipaccess');
18101: my %cache_by_lonhost;
18102: if (exists($cachekeys->{'samllanding'})) {
18103: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
18104: my %landing = %{$cachekeys->{'samllanding'}};
18105: my %domservers = &Apache::lonnet::get_servers($dom);
18106: if (keys(%domservers)) {
18107: foreach my $server (keys(%domservers)) {
18108: my @cached;
18109: next if ($thismachine{$server});
18110: if ($landing{$server}) {
18111: push(@cached,&escape('samllanding').':'.&escape($server));
18112: }
18113: if (@cached) {
18114: $cache_by_lonhost{$server} = \@cached;
18115: }
18116: }
18117: }
18118: }
18119: }
18120: if (keys(%servers)) {
18121: foreach my $server (keys(%servers)) {
18122: next if ($thismachine{$server});
18123: my @cached;
18124: foreach my $name (@posscached) {
18125: if ($cachekeys->{$name}) {
18126: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
18127: if (ref($cachekeys->{$name}) eq 'HASH') {
18128: foreach my $key (keys(%{$cachekeys->{$name}})) {
18129: push(@cached,&escape($name).':'.&escape($key));
18130: }
18131: }
18132: } else {
18133: push(@cached,&escape($name).':'.&escape($dom));
18134: }
18135: }
18136: }
18137: if ((exists($cache_by_lonhost{$server})) &&
18138: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
18139: push(@cached,@{$cache_by_lonhost{$server}});
18140: }
18141: if (@cached) {
18142: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
18143: }
18144: }
18145: }
18146: return;
18147: }
18148:
18149: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>