1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.160.6.102.2.7 2021/01/31 00:36:58 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:
178: my $registered_cleanup;
179: my $modified_urls;
180:
181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
189: my $context = 'domain';
190: my $dom = $env{'request.role.domain'};
191: my $domdesc = &Apache::lonnet::domain($dom,'description');
192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
206: ['phase','actions']);
207: my $phase = 'pickactions';
208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
212: my %domconfig =
213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
219: 'requestauthor','selfenrollment','inststatus',
220: 'passwords','ltitools'],$dom);
221: if (ref($domconfig{'ltitools'}) eq 'HASH') {
222: my %encconfig =
223: &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
224: if (ref($encconfig{'ltitools'}) eq 'HASH') {
225: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
226: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
227: foreach my $item ('key','secret') {
228: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
229: }
230: }
231: }
232: }
233: }
234: my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
235: 'autoupdate','autocreate','directorysrch','contacts',
236: 'usercreation','selfcreation','usermodification','scantron',
237: 'requestcourses','requestauthor','coursecategories',
238: 'serverstatuses','helpsettings','coursedefaults',
239: 'ltitools','selfenrollment','usersessions');
240: my %existing;
241: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
242: %existing = %{$domconfig{'loadbalancing'}};
243: }
244: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
245: push(@prefs_order,'loadbalancing');
246: }
247: my %prefs = (
248: 'rolecolors' =>
249: { text => 'Default color schemes',
250: help => 'Domain_Configuration_Color_Schemes',
251: header => [{col1 => 'Student Settings',
252: col2 => '',},
253: {col1 => 'Coordinator Settings',
254: col2 => '',},
255: {col1 => 'Author Settings',
256: col2 => '',},
257: {col1 => 'Administrator Settings',
258: col2 => '',}],
259: print => \&print_rolecolors,
260: modify => \&modify_rolecolors,
261: },
262: 'login' =>
263: { text => 'Log-in page options',
264: help => 'Domain_Configuration_Login_Page',
265: header => [{col1 => 'Log-in Page Items',
266: col2 => '',},
267: {col1 => 'Log-in Help',
268: col2 => 'Value'},
269: {col1 => 'Custom HTML in document head',
270: col2 => 'Value'}],
271: print => \&print_login,
272: modify => \&modify_login,
273: },
274: 'defaults' =>
275: { text => 'Default authentication/language/timezone/portal/types',
276: help => 'Domain_Configuration_LangTZAuth',
277: header => [{col1 => 'Setting',
278: col2 => 'Value'},
279: {col1 => 'Institutional user types',
280: col2 => 'Name displayed'}],
281: print => \&print_defaults,
282: modify => \&modify_defaults,
283: },
284: 'passwords' =>
285: { text => 'Passwords (Internal authentication)',
286: help => 'Domain_Configuration_Passwords',
287: header => [{col1 => 'Resetting Forgotten Password',
288: col2 => 'Settings'},
289: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
290: col2 => 'Settings'},
291: {col1 => 'Rules for LON-CAPA Passwords',
292: col2 => 'Settings'},
293: {col1 => 'Course Owner Changing Student Passwords',
294: col2 => 'Settings'}],
295: print => \&print_passwords,
296: modify => \&modify_passwords,
297: },
298: 'quotas' =>
299: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
300: help => 'Domain_Configuration_Quotas',
301: header => [{col1 => 'User affiliation',
302: col2 => 'Available tools',
303: col3 => 'Quotas, MB; (Authoring requires role)',}],
304: print => \&print_quotas,
305: modify => \&modify_quotas,
306: },
307: 'autoenroll' =>
308: { text => 'Auto-enrollment settings',
309: help => 'Domain_Configuration_Auto_Enrollment',
310: header => [{col1 => 'Configuration setting',
311: col2 => 'Value(s)'}],
312: print => \&print_autoenroll,
313: modify => \&modify_autoenroll,
314: },
315: 'autoupdate' =>
316: { text => 'Auto-update settings',
317: help => 'Domain_Configuration_Auto_Updates',
318: header => [{col1 => 'Setting',
319: col2 => 'Value',},
320: {col1 => 'Setting',
321: col2 => 'Affiliation'},
322: {col1 => 'User population',
323: col2 => 'Updatable user data'}],
324: print => \&print_autoupdate,
325: modify => \&modify_autoupdate,
326: },
327: 'autocreate' =>
328: { text => 'Auto-course creation settings',
329: help => 'Domain_Configuration_Auto_Creation',
330: header => [{col1 => 'Configuration Setting',
331: col2 => 'Value',}],
332: print => \&print_autocreate,
333: modify => \&modify_autocreate,
334: },
335: 'directorysrch' =>
336: { text => 'Directory searches',
337: help => 'Domain_Configuration_InstDirectory_Search',
338: header => [{col1 => 'Institutional Directory Setting',
339: col2 => 'Value',},
340: {col1 => 'LON-CAPA Directory Setting',
341: col2 => 'Value',}],
342: print => \&print_directorysrch,
343: modify => \&modify_directorysrch,
344: },
345: 'contacts' =>
346: { text => 'E-mail addresses and helpform',
347: help => 'Domain_Configuration_Contact_Info',
348: header => [{col1 => 'Default e-mail addresses',
349: col2 => 'Value',},
350: {col1 => 'Recipient(s) for notifications',
351: col2 => 'Value',},
352: {col1 => 'Nightly status check e-mail',
353: col2 => 'Settings',},
354: {col1 => 'Ask helpdesk form settings',
355: col2 => 'Value',},],
356: print => \&print_contacts,
357: modify => \&modify_contacts,
358: },
359: 'usercreation' =>
360: { text => 'User creation',
361: help => 'Domain_Configuration_User_Creation',
362: header => [{col1 => 'Format rule type',
363: col2 => 'Format rules in force'},
364: {col1 => 'User account creation',
365: col2 => 'Usernames which may be created',},
366: {col1 => 'Context',
367: col2 => 'Assignable authentication types'}],
368: print => \&print_usercreation,
369: modify => \&modify_usercreation,
370: },
371: 'selfcreation' =>
372: { text => 'Users self-creating accounts',
373: help => 'Domain_Configuration_Self_Creation',
374: header => [{col1 => 'Self-creation with institutional username',
375: col2 => 'Enabled?'},
376: {col1 => 'Institutional user type (login/SSO self-creation)',
377: col2 => 'Information user can enter'},
378: {col1 => 'Self-creation with e-mail verification',
379: col2 => 'Settings'}],
380: print => \&print_selfcreation,
381: modify => \&modify_selfcreation,
382: },
383: 'usermodification' =>
384: { text => 'User modification',
385: help => 'Domain_Configuration_User_Modification',
386: header => [{col1 => 'Target user has role',
387: col2 => 'User information updatable in author context'},
388: {col1 => 'Target user has role',
389: col2 => 'User information updatable in course context'}],
390: print => \&print_usermodification,
391: modify => \&modify_usermodification,
392: },
393: 'scantron' =>
394: { text => 'Bubblesheet format',
395: help => 'Domain_Configuration_Scantron_Format',
396: header => [ {col1 => 'Bubblesheet format file',
397: col2 => ''},
398: {col1 => 'Bubblesheet data upload formats',
399: col2 => 'Settings'}],
400: print => \&print_scantron,
401: modify => \&modify_scantron,
402: },
403: 'requestcourses' =>
404: {text => 'Request creation of courses',
405: help => 'Domain_Configuration_Request_Courses',
406: header => [{col1 => 'User affiliation',
407: col2 => 'Availability/Processing of requests',},
408: {col1 => 'Setting',
409: col2 => 'Value'},
410: {col1 => 'Available textbooks',
411: col2 => ''},
412: {col1 => 'Available templates',
413: col2 => ''},
414: {col1 => 'Validation (not official courses)',
415: col2 => 'Value'},],
416: print => \&print_quotas,
417: modify => \&modify_quotas,
418: },
419: 'requestauthor' =>
420: {text => 'Request Authoring Space',
421: help => 'Domain_Configuration_Request_Author',
422: header => [{col1 => 'User affiliation',
423: col2 => 'Availability/Processing of requests',},
424: {col1 => 'Setting',
425: col2 => 'Value'}],
426: print => \&print_quotas,
427: modify => \&modify_quotas,
428: },
429: 'coursecategories' =>
430: { text => 'Cataloging of courses/communities',
431: help => 'Domain_Configuration_Cataloging_Courses',
432: header => [{col1 => 'Catalog type/availability',
433: col2 => '',},
434: {col1 => 'Category settings for standard catalog',
435: col2 => '',},
436: {col1 => 'Categories',
437: col2 => '',
438: }],
439: print => \&print_coursecategories,
440: modify => \&modify_coursecategories,
441: },
442: 'serverstatuses' =>
443: {text => 'Access to server status pages',
444: help => 'Domain_Configuration_Server_Status',
445: header => [{col1 => 'Status Page',
446: col2 => 'Other named users',
447: col3 => 'Specific IPs',
448: }],
449: print => \&print_serverstatuses,
450: modify => \&modify_serverstatuses,
451: },
452: 'helpsettings' =>
453: {text => 'Support settings',
454: help => 'Domain_Configuration_Help_Settings',
455: header => [{col1 => 'Help Page Settings (logged-in users)',
456: col2 => 'Value'},
457: {col1 => 'Helpdesk Roles',
458: col2 => 'Settings'},],
459: print => \&print_helpsettings,
460: modify => \&modify_helpsettings,
461: },
462: 'coursedefaults' =>
463: {text => 'Course/Community defaults',
464: help => 'Domain_Configuration_Course_Defaults',
465: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
466: col2 => 'Value',},
467: {col1 => 'Defaults which can be overridden for each course by a DC',
468: col2 => 'Value',},],
469: print => \&print_coursedefaults,
470: modify => \&modify_coursedefaults,
471: },
472: 'selfenrollment' =>
473: {text => 'Self-enrollment in Course/Community',
474: help => 'Domain_Configuration_Selfenrollment',
475: header => [{col1 => 'Configuration Rights',
476: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
477: {col1 => 'Defaults',
478: col2 => 'Value'},
479: {col1 => 'Self-enrollment validation (optional)',
480: col2 => 'Value'},],
481: print => \&print_selfenrollment,
482: modify => \&modify_selfenrollment,
483: },
484: 'usersessions' =>
485: {text => 'User session hosting/offloading',
486: help => 'Domain_Configuration_User_Sessions',
487: header => [{col1 => 'Domain server',
488: col2 => 'Servers to offload sessions to when busy'},
489: {col1 => 'Hosting of users from other domains',
490: col2 => 'Rules'},
491: {col1 => "Hosting domain's own users elsewhere",
492: col2 => 'Rules'}],
493: print => \&print_usersessions,
494: modify => \&modify_usersessions,
495: },
496: 'loadbalancing' =>
497: {text => 'Dedicated Load Balancer(s)',
498: help => 'Domain_Configuration_Load_Balancing',
499: header => [{col1 => 'Balancers',
500: col2 => 'Default destinations',
501: col3 => 'User affiliation',
502: col4 => 'Overrides'},
503: ],
504: print => \&print_loadbalancing,
505: modify => \&modify_loadbalancing,
506: },
507: 'ltitools' =>
508: {text => 'External Tools (LTI)',
509: help => 'Domain_Configuration_LTI_Tools',
510: header => [{col1 => 'Setting',
511: col2 => 'Value',}],
512: print => \&print_ltitools,
513: modify => \&modify_ltitools,
514: },
515: );
516: if (keys(%servers) > 1) {
517: $prefs{'login'} = { text => 'Log-in page options',
518: help => 'Domain_Configuration_Login_Page',
519: header => [{col1 => 'Log-in Service',
520: col2 => 'Server Setting',},
521: {col1 => 'Log-in Page Items',
522: col2 => ''},
523: {col1 => 'Log-in Help',
524: col2 => 'Value'},
525: {col1 => 'Custom HTML in document head',
526: col2 => 'Value'}],
527: print => \&print_login,
528: modify => \&modify_login,
529: };
530: }
531:
532: my @roles = ('student','coordinator','author','admin');
533: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
534: &Apache::lonhtmlcommon::add_breadcrumb
535: ({href=>"javascript:changePage(document.$phase,'pickactions')",
536: text=>"Settings to display/modify"});
537: my $confname = $dom.'-domainconfig';
538:
539: if ($phase eq 'process') {
540: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
541: \%prefs,\%domconfig,$confname,\@roles);
542: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
543: $r->rflush();
544: &devalidate_remote_domconfs($dom,$result);
545: }
546: } elsif ($phase eq 'display') {
547: my $js = &recaptcha_js().
548: &toggle_display_js();
549: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
550: my ($othertitle,$usertypes,$types) =
551: &Apache::loncommon::sorted_inst_types($dom);
552: $js .= &lonbalance_targets_js($dom,$types,\%servers,
553: $domconfig{'loadbalancing'}).
554: &new_spares_js().
555: &common_domprefs_js().
556: &Apache::loncommon::javascript_array_indexof();
557: }
558: if (grep(/^requestcourses$/,@actions)) {
559: my $javascript_validations;
560: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
561: $js .= <<END;
562: <script type="text/javascript">
563: $javascript_validations
564: </script>
565: $coursebrowserjs
566: END
567: }
568: if (grep(/^selfcreation$/,@actions)) {
569: $js .= &selfcreate_javascript();
570: }
571: if (grep(/^contacts$/,@actions)) {
572: $js .= &contacts_javascript();
573: }
574: if (grep(/^scantron$/,@actions)) {
575: $js .= &scantron_javascript();
576: }
577: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
578: } else {
579: # check if domconfig user exists for the domain.
580: my $servadm = $r->dir_config('lonAdmEMail');
581: my ($configuserok,$author_ok,$switchserver) =
582: &config_check($dom,$confname,$servadm);
583: unless ($configuserok eq 'ok') {
584: &Apache::lonconfigsettings::print_header($r,$phase,$context);
585: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
586: $confname).
587: '<br />'
588: );
589: if ($switchserver) {
590: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
591: '<br />'.
592: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
593: '<br />'.
594: &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).
595: '<br />'.
596: &mt('To do that now, use the following link: [_1]',$switchserver)
597: );
598: } else {
599: $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.').
600: '<br />'.
601: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
602: );
603: }
604: $r->print(&Apache::loncommon::end_page());
605: return OK;
606: }
607: if (keys(%domconfig) == 0) {
608: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
609: my @ids=&Apache::lonnet::current_machine_ids();
610: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
611: my %designhash = &Apache::loncommon::get_domainconf($dom);
612: my @loginimages = ('img','logo','domlogo','login');
613: my $custom_img_count = 0;
614: foreach my $img (@loginimages) {
615: if ($designhash{$dom.'.login.'.$img} ne '') {
616: $custom_img_count ++;
617: }
618: }
619: foreach my $role (@roles) {
620: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
621: $custom_img_count ++;
622: }
623: }
624: if ($custom_img_count > 0) {
625: &Apache::lonconfigsettings::print_header($r,$phase,$context);
626: my $switch_server = &check_switchserver($dom,$confname);
627: $r->print(
628: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
629: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
630: &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 />'.
631: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
632: if ($switch_server) {
633: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
634: }
635: $r->print(&Apache::loncommon::end_page());
636: return OK;
637: }
638: }
639: }
640: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
641: }
642: return OK;
643: }
644:
645: sub process_changes {
646: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
647: my %domconfig;
648: if (ref($values) eq 'HASH') {
649: %domconfig = %{$values};
650: }
651: my $output;
652: if ($action eq 'login') {
653: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
654: } elsif ($action eq 'rolecolors') {
655: $output = &modify_rolecolors($r,$dom,$confname,$roles,
656: $lastactref,%domconfig);
657: } elsif ($action eq 'quotas') {
658: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
659: } elsif ($action eq 'autoenroll') {
660: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
661: } elsif ($action eq 'autoupdate') {
662: $output = &modify_autoupdate($dom,%domconfig);
663: } elsif ($action eq 'autocreate') {
664: $output = &modify_autocreate($dom,%domconfig);
665: } elsif ($action eq 'directorysrch') {
666: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
667: } elsif ($action eq 'usercreation') {
668: $output = &modify_usercreation($dom,%domconfig);
669: } elsif ($action eq 'selfcreation') {
670: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
671: } elsif ($action eq 'usermodification') {
672: $output = &modify_usermodification($dom,%domconfig);
673: } elsif ($action eq 'contacts') {
674: $output = &modify_contacts($dom,$lastactref,%domconfig);
675: } elsif ($action eq 'defaults') {
676: $output = &modify_defaults($dom,$lastactref,%domconfig);
677: } elsif ($action eq 'scantron') {
678: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
679: } elsif ($action eq 'coursecategories') {
680: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
681: } elsif ($action eq 'serverstatuses') {
682: $output = &modify_serverstatuses($dom,%domconfig);
683: } elsif ($action eq 'requestcourses') {
684: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
685: } elsif ($action eq 'requestauthor') {
686: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
687: } elsif ($action eq 'helpsettings') {
688: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
689: } elsif ($action eq 'coursedefaults') {
690: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
691: } elsif ($action eq 'selfenrollment') {
692: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
693: } elsif ($action eq 'usersessions') {
694: $output = &modify_usersessions($dom,$lastactref,%domconfig);
695: } elsif ($action eq 'loadbalancing') {
696: $output = &modify_loadbalancing($dom,%domconfig);
697: } elsif ($action eq 'passwords') {
698: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
699: } elsif ($action eq 'ltitools') {
700: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
701: }
702: return $output;
703: }
704:
705: sub print_config_box {
706: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
707: my $rowtotal = 0;
708: my $output;
709: if ($action eq 'coursecategories') {
710: $output = &coursecategories_javascript($settings);
711: } elsif ($action eq 'defaults') {
712: $output = &defaults_javascript($settings);
713: } elsif ($action eq 'passwords') {
714: $output = &passwords_javascript();
715: } elsif ($action eq 'helpsettings') {
716: my (%privs,%levelscurrent);
717: my %full=();
718: my %levels=(
719: course => {},
720: domain => {},
721: system => {},
722: );
723: my $context = 'domain';
724: my $crstype = 'Course';
725: my $formname = 'display';
726: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
727: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
728: $output =
729: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
730: \@templateroles);
731: } elsif ($action eq 'ltitools') {
732: $output .= <itools_javascript($settings);
733: }
734: $output .=
735: '<table class="LC_nested_outer">
736: <tr>
737: <th align="left" valign="middle"><span class="LC_nobreak">'.
738: &mt($item->{text}).' '.
739: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
740: '</tr>';
741: $rowtotal ++;
742: my $numheaders = 1;
743: if (ref($item->{'header'}) eq 'ARRAY') {
744: $numheaders = scalar(@{$item->{'header'}});
745: }
746: if ($numheaders > 1) {
747: my $colspan = '';
748: my $rightcolspan = '';
749: my $leftnobr = '';
750: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
751: ($action eq 'directorysrch') ||
752: (($action eq 'login') && ($numheaders < 4))) {
753: $colspan = ' colspan="2"';
754: }
755: if ($action eq 'usersessions') {
756: $rightcolspan = ' colspan="3"';
757: }
758: if ($action eq 'passwords') {
759: $leftnobr = ' LC_nobreak';
760: }
761: $output .= '
762: <tr>
763: <td>
764: <table class="LC_nested">
765: <tr class="LC_info_row">
766: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
767: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
768: </tr>';
769: $rowtotal ++;
770: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
771: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
772: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
773: ($action eq 'helpsettings') || ($action eq 'contacts')) {
774: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
775: } elsif ($action eq 'passwords') {
776: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
777: } elsif ($action eq 'coursecategories') {
778: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
779: } elsif ($action eq 'scantron') {
780: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
781: } elsif ($action eq 'login') {
782: if ($numheaders == 4) {
783: $colspan = ' colspan="2"';
784: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
785: } else {
786: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
787: }
788: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
789: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
790: } elsif ($action eq 'rolecolors') {
791: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
792: }
793: $output .= '
794: </table>
795: </td>
796: </tr>
797: <tr>
798: <td>
799: <table class="LC_nested">
800: <tr class="LC_info_row">
801: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
802: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
803: </tr>';
804: $rowtotal ++;
805: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
806: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
807: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
808: ($action eq 'contacts') || ($action eq 'passwords')) {
809: if ($action eq 'coursecategories') {
810: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
811: $colspan = ' colspan="2"';
812: } elsif ($action eq 'passwords') {
813: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
814: } else {
815: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
816: }
817: $output .= '
818: </table>
819: </td>
820: </tr>
821: <tr>
822: <td>
823: <table class="LC_nested">
824: <tr class="LC_info_row">
825: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
826: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
827: </tr>'."\n";
828: if ($action eq 'coursecategories') {
829: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
830: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
831: if ($action eq 'passwords') {
832: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
833: } else {
834: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
835: }
836: $output .= '
837: </tr>
838: </table>
839: </td>
840: </tr>
841: <tr>
842: <td>
843: <table class="LC_nested">
844: <tr class="LC_info_row">
845: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
846: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
847: if ($action eq 'passwords') {
848: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
849: } else {
850: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
851: }
852: $output .= '
853: </table>
854: </td>
855: </tr>
856: <tr>';
857: } else {
858: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
859: }
860: $rowtotal ++;
861: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
862: ($action eq 'defaults') || ($action eq 'directorysrch') ||
863: ($action eq 'helpsettings')) {
864: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
865: } elsif ($action eq 'scantron') {
866: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
867: } elsif ($action eq 'login') {
868: if ($numheaders == 4) {
869: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
870: </table>
871: </td>
872: </tr>
873: <tr>
874: <td>
875: <table class="LC_nested">
876: <tr class="LC_info_row">
877: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
878: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
879: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
880: $rowtotal ++;
881: } else {
882: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
883: }
884: $output .= '
885: </table>
886: </td>
887: </tr>
888: <tr>
889: <td>
890: <table class="LC_nested">
891: <tr class="LC_info_row">';
892: if ($numheaders == 4) {
893: $output .= '
894: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
895: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
896: </tr>';
897: } else {
898: $output .= '
899: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
900: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
901: </tr>';
902: }
903: $rowtotal ++;
904: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
905: } elsif ($action eq 'requestcourses') {
906: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
907: $rowtotal ++;
908: $output .= &print_studentcode($settings,\$rowtotal).'
909: </table>
910: </td>
911: </tr>
912: <tr>
913: <td>
914: <table class="LC_nested">
915: <tr class="LC_info_row">
916: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
917: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
918: &textbookcourses_javascript($settings).
919: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
920: </table>
921: </td>
922: </tr>
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
927: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
928: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
929: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
930: </table>
931: </td>
932: </tr>
933: <tr>
934: <td>
935: <table class="LC_nested">
936: <tr class="LC_info_row">
937: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
938: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
939: </tr>'.
940: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
941: } elsif ($action eq 'requestauthor') {
942: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
943: $rowtotal ++;
944: } elsif ($action eq 'rolecolors') {
945: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
946: </table>
947: </td>
948: </tr>
949: <tr>
950: <td>
951: <table class="LC_nested">
952: <tr class="LC_info_row">
953: <td class="LC_left_item"'.$colspan.' valign="top">'.
954: &mt($item->{'header'}->[2]->{'col1'}).'</td>
955: <td class="LC_right_item" valign="top">'.
956: &mt($item->{'header'}->[2]->{'col2'}).'</td>
957: </tr>'.
958: &print_rolecolors($phase,'author',$dom,$confname,$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>
968: </tr>'.
969: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
970: $rowtotal += 2;
971: }
972: } else {
973: $output .= '
974: <tr>
975: <td>
976: <table class="LC_nested">
977: <tr class="LC_info_row">';
978: if ($action eq 'login') {
979: $output .= '
980: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
981: } elsif ($action eq 'serverstatuses') {
982: $output .= '
983: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
984: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
985:
986: } else {
987: $output .= '
988: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
989: }
990: if (defined($item->{'header'}->[0]->{'col3'})) {
991: $output .= '<td class="LC_left_item" valign="top">'.
992: &mt($item->{'header'}->[0]->{'col2'});
993: if ($action eq 'serverstatuses') {
994: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
995: }
996: } else {
997: $output .= '<td class="LC_right_item" valign="top">'.
998: &mt($item->{'header'}->[0]->{'col2'});
999: }
1000: $output .= '</td>';
1001: if ($item->{'header'}->[0]->{'col3'}) {
1002: if (defined($item->{'header'}->[0]->{'col4'})) {
1003: $output .= '<td class="LC_left_item" valign="top">'.
1004: &mt($item->{'header'}->[0]->{'col3'});
1005: } else {
1006: $output .= '<td class="LC_right_item" valign="top">'.
1007: &mt($item->{'header'}->[0]->{'col3'});
1008: }
1009: if ($action eq 'serverstatuses') {
1010: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1011: }
1012: $output .= '</td>';
1013: }
1014: if ($item->{'header'}->[0]->{'col4'}) {
1015: $output .= '<td class="LC_right_item" valign="top">'.
1016: &mt($item->{'header'}->[0]->{'col4'});
1017: }
1018: $output .= '</tr>';
1019: $rowtotal ++;
1020: if ($action eq 'quotas') {
1021: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1022: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1023: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1024: ($action eq 'ltitools')) {
1025: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1026: }
1027: }
1028: $output .= '
1029: </table>
1030: </td>
1031: </tr>
1032: </table><br />';
1033: return ($output,$rowtotal);
1034: }
1035:
1036: sub print_login {
1037: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1038: my ($css_class,$datatable);
1039: my %choices = &login_choices();
1040:
1041: if ($caller eq 'service') {
1042: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1043: my $choice = $choices{'disallowlogin'};
1044: $css_class = ' class="LC_odd_row"';
1045: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1046: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1047: '<th>'.$choices{'server'}.'</th>'.
1048: '<th>'.$choices{'serverpath'}.'</th>'.
1049: '<th>'.$choices{'custompath'}.'</th>'.
1050: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1051: my %disallowed;
1052: if (ref($settings) eq 'HASH') {
1053: if (ref($settings->{'loginvia'}) eq 'HASH') {
1054: %disallowed = %{$settings->{'loginvia'}};
1055: }
1056: }
1057: foreach my $lonhost (sort(keys(%servers))) {
1058: my $direct = 'selected="selected"';
1059: if (ref($disallowed{$lonhost}) eq 'HASH') {
1060: if ($disallowed{$lonhost}{'server'} ne '') {
1061: $direct = '';
1062: }
1063: }
1064: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1065: '<td><select name="'.$lonhost.'_server">'.
1066: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1067: '</option>';
1068: foreach my $hostid (sort(keys(%servers))) {
1069: next if ($servers{$hostid} eq $servers{$lonhost});
1070: my $selected = '';
1071: if (ref($disallowed{$lonhost}) eq 'HASH') {
1072: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1073: $selected = 'selected="selected"';
1074: }
1075: }
1076: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1077: $servers{$hostid}.'</option>';
1078: }
1079: $datatable .= '</select></td>'.
1080: '<td><select name="'.$lonhost.'_serverpath">';
1081: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1082: my $pathname = $path;
1083: if ($path eq 'custom') {
1084: $pathname = &mt('Custom Path').' ->';
1085: }
1086: my $selected = '';
1087: if (ref($disallowed{$lonhost}) eq 'HASH') {
1088: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1089: $selected = 'selected="selected"';
1090: }
1091: } elsif ($path eq '') {
1092: $selected = 'selected="selected"';
1093: }
1094: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1095: }
1096: $datatable .= '</select></td>';
1097: my ($custom,$exempt);
1098: if (ref($disallowed{$lonhost}) eq 'HASH') {
1099: $custom = $disallowed{$lonhost}{'custompath'};
1100: $exempt = $disallowed{$lonhost}{'exempt'};
1101: }
1102: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1103: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1104: '</tr>';
1105: }
1106: $datatable .= '</table></td></tr>';
1107: return $datatable;
1108: } elsif ($caller eq 'page') {
1109: my %defaultchecked = (
1110: 'coursecatalog' => 'on',
1111: 'helpdesk' => 'on',
1112: 'adminmail' => 'off',
1113: 'newuser' => 'off',
1114: );
1115: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1116: my (%checkedon,%checkedoff);
1117: foreach my $item (@toggles) {
1118: if ($defaultchecked{$item} eq 'on') {
1119: $checkedon{$item} = ' checked="checked" ';
1120: $checkedoff{$item} = ' ';
1121: } elsif ($defaultchecked{$item} eq 'off') {
1122: $checkedoff{$item} = ' checked="checked" ';
1123: $checkedon{$item} = ' ';
1124: }
1125: }
1126: my @images = ('img','logo','domlogo','login');
1127: my @logintext = ('textcol','bgcol');
1128: my @bgs = ('pgbg','mainbg','sidebg');
1129: my @links = ('link','alink','vlink');
1130: my %designhash = &Apache::loncommon::get_domainconf($dom);
1131: my %defaultdesign = %Apache::loncommon::defaultdesign;
1132: my (%is_custom,%designs);
1133: my %defaults = (
1134: font => $defaultdesign{'login.font'},
1135: );
1136: foreach my $item (@images) {
1137: $defaults{$item} = $defaultdesign{'login.'.$item};
1138: $defaults{'showlogo'}{$item} = 1;
1139: }
1140: foreach my $item (@bgs) {
1141: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1142: }
1143: foreach my $item (@logintext) {
1144: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1145: }
1146: foreach my $item (@links) {
1147: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1148: }
1149: if (ref($settings) eq 'HASH') {
1150: foreach my $item (@toggles) {
1151: if ($settings->{$item} eq '1') {
1152: $checkedon{$item} = ' checked="checked" ';
1153: $checkedoff{$item} = ' ';
1154: } elsif ($settings->{$item} eq '0') {
1155: $checkedoff{$item} = ' checked="checked" ';
1156: $checkedon{$item} = ' ';
1157: }
1158: }
1159: foreach my $item (@images) {
1160: if (defined($settings->{$item})) {
1161: $designs{$item} = $settings->{$item};
1162: $is_custom{$item} = 1;
1163: }
1164: if (defined($settings->{'showlogo'}{$item})) {
1165: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1166: }
1167: }
1168: foreach my $item (@logintext) {
1169: if ($settings->{$item} ne '') {
1170: $designs{'logintext'}{$item} = $settings->{$item};
1171: $is_custom{$item} = 1;
1172: }
1173: }
1174: if ($settings->{'font'} ne '') {
1175: $designs{'font'} = $settings->{'font'};
1176: $is_custom{'font'} = 1;
1177: }
1178: foreach my $item (@bgs) {
1179: if ($settings->{$item} ne '') {
1180: $designs{'bgs'}{$item} = $settings->{$item};
1181: $is_custom{$item} = 1;
1182: }
1183: }
1184: foreach my $item (@links) {
1185: if ($settings->{$item} ne '') {
1186: $designs{'links'}{$item} = $settings->{$item};
1187: $is_custom{$item} = 1;
1188: }
1189: }
1190: } else {
1191: if ($designhash{$dom.'.login.font'} ne '') {
1192: $designs{'font'} = $designhash{$dom.'.login.font'};
1193: $is_custom{'font'} = 1;
1194: }
1195: foreach my $item (@images) {
1196: if ($designhash{$dom.'.login.'.$item} ne '') {
1197: $designs{$item} = $designhash{$dom.'.login.'.$item};
1198: $is_custom{$item} = 1;
1199: }
1200: }
1201: foreach my $item (@bgs) {
1202: if ($designhash{$dom.'.login.'.$item} ne '') {
1203: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1204: $is_custom{$item} = 1;
1205: }
1206: }
1207: foreach my $item (@links) {
1208: if ($designhash{$dom.'.login.'.$item} ne '') {
1209: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1210: $is_custom{$item} = 1;
1211: }
1212: }
1213: }
1214: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1215: logo => 'Institution Logo',
1216: domlogo => 'Domain Logo',
1217: login => 'Login box');
1218: my $itemcount = 1;
1219: foreach my $item (@toggles) {
1220: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1221: $datatable .=
1222: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1223: '</td><td>'.
1224: '<span class="LC_nobreak"><label><input type="radio" name="'.
1225: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1226: '</label> <label><input type="radio" name="'.$item.'"'.
1227: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1228: '</tr>';
1229: $itemcount ++;
1230: }
1231: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1232: $datatable .= '</tr></table></td></tr>';
1233: } elsif ($caller eq 'help') {
1234: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1235: my $switchserver = &check_switchserver($dom,$confname);
1236: my $itemcount = 1;
1237: $defaulturl = '/adm/loginproblems.html';
1238: $defaulttype = 'default';
1239: %lt = &Apache::lonlocal::texthash (
1240: del => 'Delete?',
1241: rep => 'Replace:',
1242: upl => 'Upload:',
1243: default => 'Default',
1244: custom => 'Custom',
1245: );
1246: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1247: my @currlangs;
1248: if (ref($settings) eq 'HASH') {
1249: if (ref($settings->{'helpurl'}) eq 'HASH') {
1250: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1251: next if ($settings->{'helpurl'}{$key} eq '');
1252: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1253: $type{$key} = 'custom';
1254: unless ($key eq 'nolang') {
1255: push(@currlangs,$key);
1256: }
1257: }
1258: } elsif ($settings->{'helpurl'} ne '') {
1259: $type{'nolang'} = 'custom';
1260: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1261: }
1262: }
1263: foreach my $lang ('nolang',sort(@currlangs)) {
1264: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1265: $datatable .= '<tr'.$css_class.'>';
1266: if ($url{$lang} eq '') {
1267: $url{$lang} = $defaulturl;
1268: }
1269: if ($type{$lang} eq '') {
1270: $type{$lang} = $defaulttype;
1271: }
1272: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1273: if ($lang eq 'nolang') {
1274: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1275: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1276: } else {
1277: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1278: $langchoices{$lang},
1279: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1280: }
1281: $datatable .= '</span></td>'."\n".
1282: '<td class="LC_left_item">';
1283: if ($type{$lang} eq 'custom') {
1284: $datatable .= '<span class="LC_nobreak"><label>'.
1285: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1286: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1287: } else {
1288: $datatable .= $lt{'upl'};
1289: }
1290: $datatable .='<br />';
1291: if ($switchserver) {
1292: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1293: } else {
1294: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1295: }
1296: $datatable .= '</td></tr>';
1297: $itemcount ++;
1298: }
1299: my @addlangs;
1300: foreach my $lang (sort(keys(%langchoices))) {
1301: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1302: push(@addlangs,$lang);
1303: }
1304: if (@addlangs > 0) {
1305: my %toadd;
1306: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1307: $toadd{''} = &mt('Select');
1308: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1309: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1310: &mt('Add log-in help page for a specific language:').' '.
1311: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1312: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1313: if ($switchserver) {
1314: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1315: } else {
1316: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1317: }
1318: $datatable .= '</td></tr>';
1319: $itemcount ++;
1320: }
1321: $datatable .= &captcha_choice('login',$settings,$itemcount);
1322: } elsif ($caller eq 'headtag') {
1323: my %domservers = &Apache::lonnet::get_servers($dom);
1324: my $choice = $choices{'headtag'};
1325: $css_class = ' class="LC_odd_row"';
1326: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1327: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1328: '<th>'.$choices{'current'}.'</th>'.
1329: '<th>'.$choices{'action'}.'</th>'.
1330: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1331: my (%currurls,%currexempt);
1332: if (ref($settings) eq 'HASH') {
1333: if (ref($settings->{'headtag'}) eq 'HASH') {
1334: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1335: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1336: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1337: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1338: }
1339: }
1340: }
1341: }
1342: my %lt = &Apache::lonlocal::texthash(
1343: del => 'Delete?',
1344: rep => 'Replace:',
1345: upl => 'Upload:',
1346: curr => 'View contents',
1347: none => 'None',
1348: );
1349: my $switchserver = &check_switchserver($dom,$confname);
1350: foreach my $lonhost (sort(keys(%domservers))) {
1351: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1352: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1353: if ($currurls{$lonhost}) {
1354: $datatable .= '<td class="LC_right_item"><a href="'.
1355: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1356: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1357: '">'.$lt{'curr'}.'</a></td>'.
1358: '<td><span class="LC_nobreak"><label>'.
1359: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1360: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1361: } else {
1362: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1363: }
1364: $datatable .='<br />';
1365: if ($switchserver) {
1366: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1367: } else {
1368: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1369: }
1370: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1371: }
1372: $datatable .= '</table></td></tr>';
1373: }
1374: return $datatable;
1375: }
1376:
1377: sub login_choices {
1378: my %choices =
1379: &Apache::lonlocal::texthash (
1380: coursecatalog => 'Display Course/Community Catalog link?',
1381: adminmail => "Display Administrator's E-mail Address?",
1382: helpdesk => 'Display "Contact Helpdesk" link',
1383: disallowlogin => "Login page requests redirected",
1384: hostid => "Server",
1385: server => "Redirect to:",
1386: serverpath => "Path",
1387: custompath => "Custom",
1388: exempt => "Exempt IP(s)",
1389: directlogin => "No redirect",
1390: newuser => "Link to create a user account",
1391: img => "Header",
1392: logo => "Main Logo",
1393: domlogo => "Domain Logo",
1394: login => "Log-in Header",
1395: textcol => "Text color",
1396: bgcol => "Box color",
1397: bgs => "Background colors",
1398: links => "Link colors",
1399: font => "Font color",
1400: pgbg => "Header",
1401: mainbg => "Page",
1402: sidebg => "Login box",
1403: link => "Link",
1404: alink => "Active link",
1405: vlink => "Visited link",
1406: headtag => "Custom markup",
1407: action => "Action",
1408: current => "Current",
1409: );
1410: return %choices;
1411: }
1412:
1413: sub print_rolecolors {
1414: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1415: my %choices = &color_font_choices();
1416: my @bgs = ('pgbg','tabbg','sidebg');
1417: my @links = ('link','alink','vlink');
1418: my @images = ('img');
1419: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1420: my %designhash = &Apache::loncommon::get_domainconf($dom);
1421: my %defaultdesign = %Apache::loncommon::defaultdesign;
1422: my (%is_custom,%designs);
1423: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1424: if (ref($settings) eq 'HASH') {
1425: if (ref($settings->{$role}) eq 'HASH') {
1426: if ($settings->{$role}->{'img'} ne '') {
1427: $designs{'img'} = $settings->{$role}->{'img'};
1428: $is_custom{'img'} = 1;
1429: }
1430: if ($settings->{$role}->{'font'} ne '') {
1431: $designs{'font'} = $settings->{$role}->{'font'};
1432: $is_custom{'font'} = 1;
1433: }
1434: if ($settings->{$role}->{'fontmenu'} ne '') {
1435: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1436: $is_custom{'fontmenu'} = 1;
1437: }
1438: foreach my $item (@bgs) {
1439: if ($settings->{$role}->{$item} ne '') {
1440: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1441: $is_custom{$item} = 1;
1442: }
1443: }
1444: foreach my $item (@links) {
1445: if ($settings->{$role}->{$item} ne '') {
1446: $designs{'links'}{$item} = $settings->{$role}->{$item};
1447: $is_custom{$item} = 1;
1448: }
1449: }
1450: }
1451: } else {
1452: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1453: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1454: $is_custom{'img'} = 1;
1455: }
1456: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1457: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1458: $is_custom{'fontmenu'} = 1;
1459: }
1460: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1461: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1462: $is_custom{'font'} = 1;
1463: }
1464: foreach my $item (@bgs) {
1465: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1466: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1467: $is_custom{$item} = 1;
1468:
1469: }
1470: }
1471: foreach my $item (@links) {
1472: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1473: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1474: $is_custom{$item} = 1;
1475: }
1476: }
1477: }
1478: my $itemcount = 1;
1479: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1480: $datatable .= '</tr></table></td></tr>';
1481: return $datatable;
1482: }
1483:
1484: sub role_defaults {
1485: my ($role,$bgs,$links,$images,$logintext) = @_;
1486: my %defaults;
1487: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1488: return %defaults;
1489: }
1490: my %defaultdesign = %Apache::loncommon::defaultdesign;
1491: if ($role eq 'login') {
1492: %defaults = (
1493: font => $defaultdesign{$role.'.font'},
1494: );
1495: if (ref($logintext) eq 'ARRAY') {
1496: foreach my $item (@{$logintext}) {
1497: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1498: }
1499: }
1500: foreach my $item (@{$images}) {
1501: $defaults{'showlogo'}{$item} = 1;
1502: }
1503: } else {
1504: %defaults = (
1505: img => $defaultdesign{$role.'.img'},
1506: font => $defaultdesign{$role.'.font'},
1507: fontmenu => $defaultdesign{$role.'.fontmenu'},
1508: );
1509: }
1510: foreach my $item (@{$bgs}) {
1511: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1512: }
1513: foreach my $item (@{$links}) {
1514: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1515: }
1516: foreach my $item (@{$images}) {
1517: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1518: }
1519: return %defaults;
1520: }
1521:
1522: sub display_color_options {
1523: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1524: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1525: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1526: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1527: my $datatable = '<tr'.$css_class.'>'.
1528: '<td>'.$choices->{'font'}.'</td>';
1529: if (!$is_custom->{'font'}) {
1530: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1531: } else {
1532: $datatable .= '<td> </td>';
1533: }
1534: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1535:
1536: $datatable .= '<td><span class="LC_nobreak">'.
1537: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1538: ' value="'.$current_color.'" /> '.
1539: ' </span></td></tr>';
1540: unless ($role eq 'login') {
1541: $datatable .= '<tr'.$css_class.'>'.
1542: '<td>'.$choices->{'fontmenu'}.'</td>';
1543: if (!$is_custom->{'fontmenu'}) {
1544: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1545: } else {
1546: $datatable .= '<td> </td>';
1547: }
1548: $current_color = $designs->{'fontmenu'} ?
1549: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1550: $datatable .= '<td><span class="LC_nobreak">'.
1551: '<input class="colorchooser" type="text" size="10" name="'
1552: .$role.'_fontmenu"'.
1553: ' value="'.$current_color.'" /> '.
1554: ' </span></td></tr>';
1555: }
1556: my $switchserver = &check_switchserver($dom,$confname);
1557: foreach my $img (@{$images}) {
1558: $itemcount ++;
1559: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1560: $datatable .= '<tr'.$css_class.'>'.
1561: '<td>'.$choices->{$img};
1562: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1563: if ($role eq 'login') {
1564: if ($img eq 'login') {
1565: $login_hdr_pick =
1566: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1567: $logincolors =
1568: &login_text_colors($img,$role,$logintext,$phase,$choices,
1569: $designs,$defaults);
1570: } elsif ($img ne 'domlogo') {
1571: $datatable.= &logo_display_options($img,$defaults,$designs);
1572: }
1573: }
1574: $datatable .= '</td>';
1575: if ($designs->{$img} ne '') {
1576: $imgfile = $designs->{$img};
1577: $img_import = ($imgfile =~ m{^/adm/});
1578: } else {
1579: $imgfile = $defaults->{$img};
1580: }
1581: if ($imgfile) {
1582: my ($showfile,$fullsize);
1583: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1584: my $urldir = $1;
1585: my $filename = $2;
1586: my @info = &Apache::lonnet::stat_file($designs->{$img});
1587: if (@info) {
1588: my $thumbfile = 'tn-'.$filename;
1589: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1590: if (@thumb) {
1591: $showfile = $urldir.'/'.$thumbfile;
1592: } else {
1593: $showfile = $imgfile;
1594: }
1595: } else {
1596: $showfile = '';
1597: }
1598: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1599: $showfile = $imgfile;
1600: my $imgdir = $1;
1601: my $filename = $2;
1602: if (-e "$londocroot/$imgdir/tn-".$filename) {
1603: $showfile = "/$imgdir/tn-".$filename;
1604: } else {
1605: my $input = $londocroot.$imgfile;
1606: my $output = "$londocroot/$imgdir/tn-".$filename;
1607: if (!-e $output) {
1608: my ($width,$height) = &thumb_dimensions();
1609: my ($fullwidth,$fullheight) = &check_dimensions($input);
1610: if ($fullwidth ne '' && $fullheight ne '') {
1611: if ($fullwidth > $width && $fullheight > $height) {
1612: my $size = $width.'x'.$height;
1613: my @args = ('convert','-sample',$size,$input,$output);
1614: system({$args[0]} @args);
1615: $showfile = "/$imgdir/tn-".$filename;
1616: }
1617: }
1618: }
1619: }
1620: }
1621: if ($showfile) {
1622: if ($showfile =~ m{^/(adm|res)/}) {
1623: if ($showfile =~ m{^/res/}) {
1624: my $local_showfile =
1625: &Apache::lonnet::filelocation('',$showfile);
1626: &Apache::lonnet::repcopy($local_showfile);
1627: }
1628: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1629: }
1630: if ($imgfile) {
1631: if ($imgfile =~ m{^/(adm|res)/}) {
1632: if ($imgfile =~ m{^/res/}) {
1633: my $local_imgfile =
1634: &Apache::lonnet::filelocation('',$imgfile);
1635: &Apache::lonnet::repcopy($local_imgfile);
1636: }
1637: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1638: } else {
1639: $fullsize = $imgfile;
1640: }
1641: }
1642: $datatable .= '<td>';
1643: if ($img eq 'login') {
1644: $datatable .= $login_hdr_pick;
1645: }
1646: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1647: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1648: } else {
1649: $datatable .= '<td> </td><td class="LC_left_item">'.
1650: &mt('Upload:').'<br />';
1651: }
1652: } else {
1653: $datatable .= '<td> </td><td class="LC_left_item">'.
1654: &mt('Upload:').'<br />';
1655: }
1656: if ($switchserver) {
1657: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1658: } else {
1659: if ($img ne 'login') { # suppress file selection for Log-in header
1660: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1661: }
1662: }
1663: $datatable .= '</td></tr>';
1664: }
1665: $itemcount ++;
1666: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1667: $datatable .= '<tr'.$css_class.'>'.
1668: '<td>'.$choices->{'bgs'}.'</td>';
1669: my $bgs_def;
1670: foreach my $item (@{$bgs}) {
1671: if (!$is_custom->{$item}) {
1672: $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>';
1673: }
1674: }
1675: if ($bgs_def) {
1676: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1677: } else {
1678: $datatable .= '<td> </td>';
1679: }
1680: $datatable .= '<td class="LC_right_item">'.
1681: '<table border="0"><tr>';
1682:
1683: foreach my $item (@{$bgs}) {
1684: $datatable .= '<td align="center">'.$choices->{$item};
1685: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1686: if ($designs->{'bgs'}{$item}) {
1687: $datatable .= ' ';
1688: }
1689: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1690: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1691: }
1692: $datatable .= '</tr></table></td></tr>';
1693: $itemcount ++;
1694: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1695: $datatable .= '<tr'.$css_class.'>'.
1696: '<td>'.$choices->{'links'}.'</td>';
1697: my $links_def;
1698: foreach my $item (@{$links}) {
1699: if (!$is_custom->{$item}) {
1700: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1701: }
1702: }
1703: if ($links_def) {
1704: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1705: } else {
1706: $datatable .= '<td> </td>';
1707: }
1708: $datatable .= '<td class="LC_right_item">'.
1709: '<table border="0"><tr>';
1710: foreach my $item (@{$links}) {
1711: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1712: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1713: if ($designs->{'links'}{$item}) {
1714: $datatable.=' ';
1715: }
1716: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1717: '" /></td>';
1718: }
1719: $$rowtotal += $itemcount;
1720: return $datatable;
1721: }
1722:
1723: sub logo_display_options {
1724: my ($img,$defaults,$designs) = @_;
1725: my $checkedon;
1726: if (ref($defaults) eq 'HASH') {
1727: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1728: if ($defaults->{'showlogo'}{$img}) {
1729: $checkedon = 'checked="checked" ';
1730: }
1731: }
1732: }
1733: if (ref($designs) eq 'HASH') {
1734: if (ref($designs->{'showlogo'}) eq 'HASH') {
1735: if (defined($designs->{'showlogo'}{$img})) {
1736: if ($designs->{'showlogo'}{$img} == 0) {
1737: $checkedon = '';
1738: } elsif ($designs->{'showlogo'}{$img} == 1) {
1739: $checkedon = 'checked="checked" ';
1740: }
1741: }
1742: }
1743: }
1744: return '<br /><label> <input type="checkbox" name="'.
1745: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1746: &mt('show').'</label>'."\n";
1747: }
1748:
1749: sub login_header_options {
1750: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1751: my $output = '';
1752: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1753: $output .= &mt('Text default(s):').'<br />';
1754: if (!$is_custom->{'textcol'}) {
1755: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1756: ' ';
1757: }
1758: if (!$is_custom->{'bgcol'}) {
1759: $output .= $choices->{'bgcol'}.': '.
1760: '<span id="css_'.$role.'_font" style="background-color: '.
1761: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1762: }
1763: $output .= '<br />';
1764: }
1765: $output .='<br />';
1766: return $output;
1767: }
1768:
1769: sub login_text_colors {
1770: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1771: my $color_menu = '<table border="0"><tr>';
1772: foreach my $item (@{$logintext}) {
1773: $color_menu .= '<td align="center">'.$choices->{$item};
1774: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1775: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1776: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1777: }
1778: $color_menu .= '</tr></table><br />';
1779: return $color_menu;
1780: }
1781:
1782: sub image_changes {
1783: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1784: my $output;
1785: if ($img eq 'login') {
1786: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1787: } elsif (!$is_custom) {
1788: if ($img ne 'domlogo') {
1789: $output = &mt('Default image:').'<br />';
1790: } else {
1791: $output = &mt('Default in use:').'<br />';
1792: }
1793: }
1794: if ($img ne 'login') {
1795: if ($img_import) {
1796: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1797: }
1798: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1799: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1800: if ($is_custom) {
1801: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1802: '<input type="checkbox" name="'.
1803: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1804: '</label> '.&mt('Replace:').'</span><br />';
1805: } else {
1806: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1807: }
1808: }
1809: return $output;
1810: }
1811:
1812: sub print_quotas {
1813: my ($dom,$settings,$rowtotal,$action) = @_;
1814: my $context;
1815: if ($action eq 'quotas') {
1816: $context = 'tools';
1817: } else {
1818: $context = $action;
1819: }
1820: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1821: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1822: my $typecount = 0;
1823: my ($css_class,%titles);
1824: if ($context eq 'requestcourses') {
1825: @usertools = ('official','unofficial','community','textbook');
1826: @options =('norequest','approval','validate','autolimit');
1827: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1828: %titles = &courserequest_titles();
1829: } elsif ($context eq 'requestauthor') {
1830: @usertools = ('author');
1831: @options = ('norequest','approval','automatic');
1832: %titles = &authorrequest_titles();
1833: } else {
1834: @usertools = ('aboutme','blog','webdav','portfolio');
1835: %titles = &tool_titles();
1836: }
1837: if (ref($types) eq 'ARRAY') {
1838: foreach my $type (@{$types}) {
1839: my ($currdefquota,$currauthorquota);
1840: unless (($context eq 'requestcourses') ||
1841: ($context eq 'requestauthor')) {
1842: if (ref($settings) eq 'HASH') {
1843: if (ref($settings->{defaultquota}) eq 'HASH') {
1844: $currdefquota = $settings->{defaultquota}->{$type};
1845: } else {
1846: $currdefquota = $settings->{$type};
1847: }
1848: if (ref($settings->{authorquota}) eq 'HASH') {
1849: $currauthorquota = $settings->{authorquota}->{$type};
1850: }
1851: }
1852: }
1853: if (defined($usertypes->{$type})) {
1854: $typecount ++;
1855: $css_class = $typecount%2?' class="LC_odd_row"':'';
1856: $datatable .= '<tr'.$css_class.'>'.
1857: '<td>'.$usertypes->{$type}.'</td>'.
1858: '<td class="LC_left_item">';
1859: if ($context eq 'requestcourses') {
1860: $datatable .= '<table><tr>';
1861: }
1862: my %cell;
1863: foreach my $item (@usertools) {
1864: if ($context eq 'requestcourses') {
1865: my ($curroption,$currlimit);
1866: if (ref($settings) eq 'HASH') {
1867: if (ref($settings->{$item}) eq 'HASH') {
1868: $curroption = $settings->{$item}->{$type};
1869: if ($curroption =~ /^autolimit=(\d*)$/) {
1870: $currlimit = $1;
1871: }
1872: }
1873: }
1874: if (!$curroption) {
1875: $curroption = 'norequest';
1876: }
1877: $datatable .= '<th>'.$titles{$item}.'</th>';
1878: foreach my $option (@options) {
1879: my $val = $option;
1880: if ($option eq 'norequest') {
1881: $val = 0;
1882: }
1883: if ($option eq 'validate') {
1884: my $canvalidate = 0;
1885: if (ref($validations{$item}) eq 'HASH') {
1886: if ($validations{$item}{$type}) {
1887: $canvalidate = 1;
1888: }
1889: }
1890: next if (!$canvalidate);
1891: }
1892: my $checked = '';
1893: if ($option eq $curroption) {
1894: $checked = ' checked="checked"';
1895: } elsif ($option eq 'autolimit') {
1896: if ($curroption =~ /^autolimit/) {
1897: $checked = ' checked="checked"';
1898: }
1899: }
1900: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1901: '<input type="radio" name="crsreq_'.$item.
1902: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1903: $titles{$option}.'</label>';
1904: if ($option eq 'autolimit') {
1905: $cell{$item} .= ' <input type="text" name="crsreq_'.
1906: $item.'_limit_'.$type.'" size="1" '.
1907: 'value="'.$currlimit.'" />';
1908: }
1909: $cell{$item} .= '</span> ';
1910: if ($option eq 'autolimit') {
1911: $cell{$item} .= $titles{'unlimited'};
1912: }
1913: }
1914: } elsif ($context eq 'requestauthor') {
1915: my $curroption;
1916: if (ref($settings) eq 'HASH') {
1917: $curroption = $settings->{$type};
1918: }
1919: if (!$curroption) {
1920: $curroption = 'norequest';
1921: }
1922: foreach my $option (@options) {
1923: my $val = $option;
1924: if ($option eq 'norequest') {
1925: $val = 0;
1926: }
1927: my $checked = '';
1928: if ($option eq $curroption) {
1929: $checked = ' checked="checked"';
1930: }
1931: $datatable .= '<span class="LC_nobreak"><label>'.
1932: '<input type="radio" name="authorreq_'.$type.
1933: '" value="'.$val.'"'.$checked.' />'.
1934: $titles{$option}.'</label></span> ';
1935: }
1936: } else {
1937: my $checked = 'checked="checked" ';
1938: if (ref($settings) eq 'HASH') {
1939: if (ref($settings->{$item}) eq 'HASH') {
1940: if ($settings->{$item}->{$type} == 0) {
1941: $checked = '';
1942: } elsif ($settings->{$item}->{$type} == 1) {
1943: $checked = 'checked="checked" ';
1944: }
1945: }
1946: }
1947: $datatable .= '<span class="LC_nobreak"><label>'.
1948: '<input type="checkbox" name="'.$context.'_'.$item.
1949: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1950: '</label></span> ';
1951: }
1952: }
1953: if ($context eq 'requestcourses') {
1954: $datatable .= '</tr><tr>';
1955: foreach my $item (@usertools) {
1956: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1957: }
1958: $datatable .= '</tr></table>';
1959: }
1960: $datatable .= '</td>';
1961: unless (($context eq 'requestcourses') ||
1962: ($context eq 'requestauthor')) {
1963: $datatable .=
1964: '<td class="LC_right_item">'.
1965: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1966: '<input type="text" name="quota_'.$type.
1967: '" value="'.$currdefquota.
1968: '" size="5" /></span>'.(' ' x 2).
1969: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1970: '<input type="text" name="authorquota_'.$type.
1971: '" value="'.$currauthorquota.
1972: '" size="5" /></span></td>';
1973: }
1974: $datatable .= '</tr>';
1975: }
1976: }
1977: }
1978: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1979: $defaultquota = '20';
1980: $authorquota = '500';
1981: if (ref($settings) eq 'HASH') {
1982: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1983: $defaultquota = $settings->{'defaultquota'}->{'default'};
1984: } elsif (defined($settings->{'default'})) {
1985: $defaultquota = $settings->{'default'};
1986: }
1987: if (ref($settings->{'authorquota'}) eq 'HASH') {
1988: $authorquota = $settings->{'authorquota'}->{'default'};
1989: }
1990: }
1991: }
1992: $typecount ++;
1993: $css_class = $typecount%2?' class="LC_odd_row"':'';
1994: $datatable .= '<tr'.$css_class.'>'.
1995: '<td>'.$othertitle.'</td>'.
1996: '<td class="LC_left_item">';
1997: if ($context eq 'requestcourses') {
1998: $datatable .= '<table><tr>';
1999: }
2000: my %defcell;
2001: foreach my $item (@usertools) {
2002: if ($context eq 'requestcourses') {
2003: my ($curroption,$currlimit);
2004: if (ref($settings) eq 'HASH') {
2005: if (ref($settings->{$item}) eq 'HASH') {
2006: $curroption = $settings->{$item}->{'default'};
2007: if ($curroption =~ /^autolimit=(\d*)$/) {
2008: $currlimit = $1;
2009: }
2010: }
2011: }
2012: if (!$curroption) {
2013: $curroption = 'norequest';
2014: }
2015: $datatable .= '<th>'.$titles{$item}.'</th>';
2016: foreach my $option (@options) {
2017: my $val = $option;
2018: if ($option eq 'norequest') {
2019: $val = 0;
2020: }
2021: if ($option eq 'validate') {
2022: my $canvalidate = 0;
2023: if (ref($validations{$item}) eq 'HASH') {
2024: if ($validations{$item}{'default'}) {
2025: $canvalidate = 1;
2026: }
2027: }
2028: next if (!$canvalidate);
2029: }
2030: my $checked = '';
2031: if ($option eq $curroption) {
2032: $checked = ' checked="checked"';
2033: } elsif ($option eq 'autolimit') {
2034: if ($curroption =~ /^autolimit/) {
2035: $checked = ' checked="checked"';
2036: }
2037: }
2038: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2039: '<input type="radio" name="crsreq_'.$item.
2040: '_default" value="'.$val.'"'.$checked.' />'.
2041: $titles{$option}.'</label>';
2042: if ($option eq 'autolimit') {
2043: $defcell{$item} .= ' <input type="text" name="crsreq_'.
2044: $item.'_limit_default" size="1" '.
2045: 'value="'.$currlimit.'" />';
2046: }
2047: $defcell{$item} .= '</span> ';
2048: if ($option eq 'autolimit') {
2049: $defcell{$item} .= $titles{'unlimited'};
2050: }
2051: }
2052: } elsif ($context eq 'requestauthor') {
2053: my $curroption;
2054: if (ref($settings) eq 'HASH') {
2055: $curroption = $settings->{'default'};
2056: }
2057: if (!$curroption) {
2058: $curroption = 'norequest';
2059: }
2060: foreach my $option (@options) {
2061: my $val = $option;
2062: if ($option eq 'norequest') {
2063: $val = 0;
2064: }
2065: my $checked = '';
2066: if ($option eq $curroption) {
2067: $checked = ' checked="checked"';
2068: }
2069: $datatable .= '<span class="LC_nobreak"><label>'.
2070: '<input type="radio" name="authorreq_default"'.
2071: ' value="'.$val.'"'.$checked.' />'.
2072: $titles{$option}.'</label></span> ';
2073: }
2074: } else {
2075: my $checked = 'checked="checked" ';
2076: if (ref($settings) eq 'HASH') {
2077: if (ref($settings->{$item}) eq 'HASH') {
2078: if ($settings->{$item}->{'default'} == 0) {
2079: $checked = '';
2080: } elsif ($settings->{$item}->{'default'} == 1) {
2081: $checked = 'checked="checked" ';
2082: }
2083: }
2084: }
2085: $datatable .= '<span class="LC_nobreak"><label>'.
2086: '<input type="checkbox" name="'.$context.'_'.$item.
2087: '" value="default" '.$checked.'/>'.$titles{$item}.
2088: '</label></span> ';
2089: }
2090: }
2091: if ($context eq 'requestcourses') {
2092: $datatable .= '</tr><tr>';
2093: foreach my $item (@usertools) {
2094: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
2095: }
2096: $datatable .= '</tr></table>';
2097: }
2098: $datatable .= '</td>';
2099: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2100: $datatable .= '<td class="LC_right_item">'.
2101: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2102: '<input type="text" name="defaultquota" value="'.
2103: $defaultquota.'" size="5" /></span>'.(' ' x2).
2104: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2105: '<input type="text" name="authorquota" value="'.
2106: $authorquota.'" size="5" /></span></td>';
2107: }
2108: $datatable .= '</tr>';
2109: $typecount ++;
2110: $css_class = $typecount%2?' class="LC_odd_row"':'';
2111: $datatable .= '<tr'.$css_class.'>'.
2112: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
2113: if ($context eq 'requestcourses') {
2114: $datatable .= &mt('(overrides affiliation, if set)').
2115: '</td>'.
2116: '<td class="LC_left_item">'.
2117: '<table><tr>';
2118: } else {
2119: $datatable .= &mt('(overrides affiliation, if checked)').
2120: '</td>'.
2121: '<td class="LC_left_item" colspan="2">'.
2122: '<br />';
2123: }
2124: my %advcell;
2125: foreach my $item (@usertools) {
2126: if ($context eq 'requestcourses') {
2127: my ($curroption,$currlimit);
2128: if (ref($settings) eq 'HASH') {
2129: if (ref($settings->{$item}) eq 'HASH') {
2130: $curroption = $settings->{$item}->{'_LC_adv'};
2131: if ($curroption =~ /^autolimit=(\d*)$/) {
2132: $currlimit = $1;
2133: }
2134: }
2135: }
2136: $datatable .= '<th>'.$titles{$item}.'</th>';
2137: my $checked = '';
2138: if ($curroption eq '') {
2139: $checked = ' checked="checked"';
2140: }
2141: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2142: '<input type="radio" name="crsreq_'.$item.
2143: '__LC_adv" value=""'.$checked.' />'.
2144: &mt('No override set').'</label></span> ';
2145: foreach my $option (@options) {
2146: my $val = $option;
2147: if ($option eq 'norequest') {
2148: $val = 0;
2149: }
2150: if ($option eq 'validate') {
2151: my $canvalidate = 0;
2152: if (ref($validations{$item}) eq 'HASH') {
2153: if ($validations{$item}{'_LC_adv'}) {
2154: $canvalidate = 1;
2155: }
2156: }
2157: next if (!$canvalidate);
2158: }
2159: my $checked = '';
2160: if ($val eq $curroption) {
2161: $checked = ' checked="checked"';
2162: } elsif ($option eq 'autolimit') {
2163: if ($curroption =~ /^autolimit/) {
2164: $checked = ' checked="checked"';
2165: }
2166: }
2167: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2168: '<input type="radio" name="crsreq_'.$item.
2169: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2170: $titles{$option}.'</label>';
2171: if ($option eq 'autolimit') {
2172: $advcell{$item} .= ' <input type="text" name="crsreq_'.
2173: $item.'_limit__LC_adv" size="1" '.
2174: 'value="'.$currlimit.'" />';
2175: }
2176: $advcell{$item} .= '</span> ';
2177: if ($option eq 'autolimit') {
2178: $advcell{$item} .= $titles{'unlimited'};
2179: }
2180: }
2181: } elsif ($context eq 'requestauthor') {
2182: my $curroption;
2183: if (ref($settings) eq 'HASH') {
2184: $curroption = $settings->{'_LC_adv'};
2185: }
2186: my $checked = '';
2187: if ($curroption eq '') {
2188: $checked = ' checked="checked"';
2189: }
2190: $datatable .= '<span class="LC_nobreak"><label>'.
2191: '<input type="radio" name="authorreq__LC_adv"'.
2192: ' value=""'.$checked.' />'.
2193: &mt('No override set').'</label></span> ';
2194: foreach my $option (@options) {
2195: my $val = $option;
2196: if ($option eq 'norequest') {
2197: $val = 0;
2198: }
2199: my $checked = '';
2200: if ($val eq $curroption) {
2201: $checked = ' checked="checked"';
2202: }
2203: $datatable .= '<span class="LC_nobreak"><label>'.
2204: '<input type="radio" name="authorreq__LC_adv"'.
2205: ' value="'.$val.'"'.$checked.' />'.
2206: $titles{$option}.'</label></span> ';
2207: }
2208: } else {
2209: my $checked = 'checked="checked" ';
2210: if (ref($settings) eq 'HASH') {
2211: if (ref($settings->{$item}) eq 'HASH') {
2212: if ($settings->{$item}->{'_LC_adv'} == 0) {
2213: $checked = '';
2214: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2215: $checked = 'checked="checked" ';
2216: }
2217: }
2218: }
2219: $datatable .= '<span class="LC_nobreak"><label>'.
2220: '<input type="checkbox" name="'.$context.'_'.$item.
2221: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2222: '</label></span> ';
2223: }
2224: }
2225: if ($context eq 'requestcourses') {
2226: $datatable .= '</tr><tr>';
2227: foreach my $item (@usertools) {
2228: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2229: }
2230: $datatable .= '</tr></table>';
2231: }
2232: $datatable .= '</td></tr>';
2233: $$rowtotal += $typecount;
2234: return $datatable;
2235: }
2236:
2237: sub print_requestmail {
2238: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
2239: my ($now,$datatable,%currapp);
2240: $now = time;
2241: if (ref($settings) eq 'HASH') {
2242: if (ref($settings->{'notify'}) eq 'HASH') {
2243: if ($settings->{'notify'}{'approval'} ne '') {
2244: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2245: }
2246: }
2247: }
2248: my $numinrow = 2;
2249: my $css_class;
2250: if ($$rowtotal%2) {
2251: $css_class = 'LC_odd_row';
2252: }
2253: if ($customcss) {
2254: $css_class .= " $customcss";
2255: }
2256: $css_class =~ s/^\s+//;
2257: if ($css_class) {
2258: $css_class = ' class="'.$css_class.'"';
2259: }
2260: if ($rowstyle) {
2261: $css_class .= ' style="'.$rowstyle.'"';
2262: }
2263: my $text;
2264: if ($action eq 'requestcourses') {
2265: $text = &mt('Receive notification of course requests requiring approval');
2266: } elsif ($action eq 'requestauthor') {
2267: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2268: } else {
2269: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2270: }
2271: $datatable = '<tr'.$css_class.'>'.
2272: ' <td>'.$text.'</td>'.
2273: ' <td class="LC_left_item">';
2274: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2275: $action.'notifyapproval',%currapp);
2276: if ($numdc > 0) {
2277: $datatable .= $table;
2278: } else {
2279: $datatable .= &mt('There are no active Domain Coordinators');
2280: }
2281: $datatable .='</td></tr>';
2282: return $datatable;
2283: }
2284:
2285: sub print_studentcode {
2286: my ($settings,$rowtotal) = @_;
2287: my $rownum = 0;
2288: my ($output,%current);
2289: my @crstypes = ('official','unofficial','community','textbook');
2290: if (ref($settings) eq 'HASH') {
2291: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2292: foreach my $type (@crstypes) {
2293: $current{$type} = $settings->{'uniquecode'}{$type};
2294: }
2295: }
2296: }
2297: $output .= '<tr>'.
2298: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2299: '<td class="LC_left_item">';
2300: foreach my $type (@crstypes) {
2301: my $check = ' ';
2302: if ($current{$type}) {
2303: $check = ' checked="checked" ';
2304: }
2305: $output .= '<span class="LC_nobreak"><label>'.
2306: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2307: &mt($type).'</label></span>'.(' 'x2).' ';
2308: }
2309: $output .= '</td></tr>';
2310: $$rowtotal ++;
2311: return $output;
2312: }
2313:
2314: sub print_textbookcourses {
2315: my ($dom,$type,$settings,$rowtotal) = @_;
2316: my $rownum = 0;
2317: my $css_class;
2318: my $itemcount = 1;
2319: my $maxnum = 0;
2320: my $bookshash;
2321: if (ref($settings) eq 'HASH') {
2322: $bookshash = $settings->{$type};
2323: }
2324: my %ordered;
2325: if (ref($bookshash) eq 'HASH') {
2326: foreach my $item (keys(%{$bookshash})) {
2327: if (ref($bookshash->{$item}) eq 'HASH') {
2328: my $num = $bookshash->{$item}{'order'};
2329: $ordered{$num} = $item;
2330: }
2331: }
2332: }
2333: my $confname = $dom.'-domainconfig';
2334: my $switchserver = &check_switchserver($dom,$confname);
2335: my $maxnum = scalar(keys(%ordered));
2336: my $datatable;
2337: if (keys(%ordered)) {
2338: my @items = sort { $a <=> $b } keys(%ordered);
2339: for (my $i=0; $i<@items; $i++) {
2340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2341: my $key = $ordered{$items[$i]};
2342: my %coursehash=&Apache::lonnet::coursedescription($key);
2343: my $coursetitle = $coursehash{'description'};
2344: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2345: if (ref($bookshash->{$key}) eq 'HASH') {
2346: $subject = $bookshash->{$key}->{'subject'};
2347: $title = $bookshash->{$key}->{'title'};
2348: if ($type eq 'textbooks') {
2349: $publisher = $bookshash->{$key}->{'publisher'};
2350: $author = $bookshash->{$key}->{'author'};
2351: $image = $bookshash->{$key}->{'image'};
2352: if ($image ne '') {
2353: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2354: my $imagethumb = "$path/tn-".$imagefile;
2355: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2356: }
2357: }
2358: }
2359: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2360: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2361: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2362: for (my $k=0; $k<=$maxnum; $k++) {
2363: my $vpos = $k+1;
2364: my $selstr;
2365: if ($k == $i) {
2366: $selstr = ' selected="selected" ';
2367: }
2368: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2369: }
2370: $datatable .= '</select>'.(' 'x2).
2371: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2372: &mt('Delete?').'</label></span></td>'.
2373: '<td colspan="2">'.
2374: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2375: (' 'x2).
2376: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2377: if ($type eq 'textbooks') {
2378: $datatable .= (' 'x2).
2379: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2380: (' 'x2).
2381: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2382: (' 'x2).
2383: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2384: if ($image) {
2385: $datatable .= '<span class="LC_nobreak">'.
2386: $imgsrc.
2387: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2388: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2389: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2390: }
2391: if ($switchserver) {
2392: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2393: } else {
2394: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2395: }
2396: }
2397: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2398: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2399: $coursetitle.'</span></td></tr>'."\n";
2400: $itemcount ++;
2401: }
2402: }
2403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2404: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2405: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2406: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2407: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2408: for (my $k=0; $k<$maxnum+1; $k++) {
2409: my $vpos = $k+1;
2410: my $selstr;
2411: if ($k == $maxnum) {
2412: $selstr = ' selected="selected" ';
2413: }
2414: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2415: }
2416: $datatable .= '</select> '."\n".
2417: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
2418: '<td colspan="2">'.
2419: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2420: (' 'x2).
2421: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2422: (' 'x2);
2423: if ($type eq 'textbooks') {
2424: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2425: (' 'x2).
2426: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2427: (' 'x2).
2428: '<span class="LC_nobreak">'.&mt('Image:').' ';
2429: if ($switchserver) {
2430: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2431: } else {
2432: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2433: }
2434: $datatable .= '</span>'."\n";
2435: }
2436: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2437: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2438: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2439: &Apache::loncommon::selectcourse_link
2440: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
2441: '</span></td>'."\n".
2442: '</tr>'."\n";
2443: $itemcount ++;
2444: return $datatable;
2445: }
2446:
2447: sub textbookcourses_javascript {
2448: my ($settings) = @_;
2449: return unless(ref($settings) eq 'HASH');
2450: my (%ordered,%total,%jstext);
2451: foreach my $type ('textbooks','templates') {
2452: $total{$type} = 0;
2453: if (ref($settings->{$type}) eq 'HASH') {
2454: foreach my $item (keys(%{$settings->{$type}})) {
2455: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2456: my $num = $settings->{$type}->{$item}{'order'};
2457: $ordered{$type}{$num} = $item;
2458: }
2459: }
2460: $total{$type} = scalar(keys(%{$settings->{$type}}));
2461: }
2462: my @jsarray = ();
2463: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2464: push(@jsarray,$ordered{$type}{$item});
2465: }
2466: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2467: }
2468: return <<"ENDSCRIPT";
2469: <script type="text/javascript">
2470: // <![CDATA[
2471: function reorderBooks(form,item,caller) {
2472: var changedVal;
2473: $jstext{'textbooks'};
2474: $jstext{'templates'};
2475: var newpos;
2476: var maxh;
2477: if (caller == 'textbooks') {
2478: newpos = 'textbooks_addbook_pos';
2479: maxh = 1 + $total{'textbooks'};
2480: } else {
2481: newpos = 'templates_addbook_pos';
2482: maxh = 1 + $total{'templates'};
2483: }
2484: var current = new Array;
2485: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2486: if (item == newpos) {
2487: changedVal = newitemVal;
2488: } else {
2489: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2490: current[newitemVal] = newpos;
2491: }
2492: if (caller == 'textbooks') {
2493: for (var i=0; i<textbooks.length; i++) {
2494: var elementName = 'textbooks_'+textbooks[i];
2495: if (elementName != item) {
2496: if (form.elements[elementName]) {
2497: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2498: current[currVal] = elementName;
2499: }
2500: }
2501: }
2502: }
2503: if (caller == 'templates') {
2504: for (var i=0; i<templates.length; i++) {
2505: var elementName = 'templates_'+templates[i];
2506: if (elementName != item) {
2507: if (form.elements[elementName]) {
2508: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2509: current[currVal] = elementName;
2510: }
2511: }
2512: }
2513: }
2514: var oldVal;
2515: for (var j=0; j<maxh; j++) {
2516: if (current[j] == undefined) {
2517: oldVal = j;
2518: }
2519: }
2520: if (oldVal < changedVal) {
2521: for (var k=oldVal+1; k<=changedVal ; k++) {
2522: var elementName = current[k];
2523: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2524: }
2525: } else {
2526: for (var k=changedVal; k<oldVal; k++) {
2527: var elementName = current[k];
2528: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2529: }
2530: }
2531: return;
2532: }
2533:
2534: // ]]>
2535: </script>
2536:
2537: ENDSCRIPT
2538: }
2539:
2540: sub ltitools_javascript {
2541: my ($settings) = @_;
2542: my $togglejs = <itools_toggle_js();
2543: unless (ref($settings) eq 'HASH') {
2544: return $togglejs;
2545: }
2546: my (%ordered,$total,%jstext);
2547: $total = 0;
2548: foreach my $item (keys(%{$settings})) {
2549: if (ref($settings->{$item}) eq 'HASH') {
2550: my $num = $settings->{$item}{'order'};
2551: $ordered{$num} = $item;
2552: }
2553: }
2554: $total = scalar(keys(%{$settings}));
2555: my @jsarray = ();
2556: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2557: push(@jsarray,$ordered{$item});
2558: }
2559: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2560: return <<"ENDSCRIPT";
2561: <script type="text/javascript">
2562: // <![CDATA[
2563: function reorderLTITools(form,item) {
2564: var changedVal;
2565: $jstext
2566: var newpos = 'ltitools_add_pos';
2567: var maxh = 1 + $total;
2568: var current = new Array;
2569: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2570: if (item == newpos) {
2571: changedVal = newitemVal;
2572: } else {
2573: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2574: current[newitemVal] = newpos;
2575: }
2576: for (var i=0; i<ltitools.length; i++) {
2577: var elementName = 'ltitools_'+ltitools[i];
2578: if (elementName != item) {
2579: if (form.elements[elementName]) {
2580: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2581: current[currVal] = elementName;
2582: }
2583: }
2584: }
2585: var oldVal;
2586: for (var j=0; j<maxh; j++) {
2587: if (current[j] == undefined) {
2588: oldVal = j;
2589: }
2590: }
2591: if (oldVal < changedVal) {
2592: for (var k=oldVal+1; k<=changedVal ; k++) {
2593: var elementName = current[k];
2594: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2595: }
2596: } else {
2597: for (var k=changedVal; k<oldVal; k++) {
2598: var elementName = current[k];
2599: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2600: }
2601: }
2602: return;
2603: }
2604:
2605: // ]]>
2606: </script>
2607:
2608: $togglejs
2609:
2610: ENDSCRIPT
2611: }
2612:
2613: sub ltitools_toggle_js {
2614: return <<"ENDSCRIPT";
2615: <script type="text/javascript">
2616: // <![CDATA[
2617:
2618: function toggleLTITools(form,setting,item) {
2619: var radioname = '';
2620: var divid = '';
2621: if (setting == 'user') {
2622: divid = 'ltitools_'+setting+'_div_'+item;
2623: var checkid = 'ltitools_'+setting+'_field_'+item;
2624: if (document.getElementById(divid)) {
2625: if (document.getElementById(checkid)) {
2626: if (document.getElementById(checkid).checked) {
2627: document.getElementById(divid).style.display = 'inline-block';
2628: } else {
2629: document.getElementById(divid).style.display = 'none';
2630: }
2631: }
2632: }
2633: }
2634: return;
2635: }
2636: // ]]>
2637: </script>
2638:
2639: ENDSCRIPT
2640: }
2641:
2642: sub print_autoenroll {
2643: my ($dom,$settings,$rowtotal) = @_;
2644: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2645: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
2646: if (ref($settings) eq 'HASH') {
2647: if (exists($settings->{'run'})) {
2648: if ($settings->{'run'} eq '0') {
2649: $runoff = ' checked="checked" ';
2650: $runon = ' ';
2651: } else {
2652: $runon = ' checked="checked" ';
2653: $runoff = ' ';
2654: }
2655: } else {
2656: if ($autorun) {
2657: $runon = ' checked="checked" ';
2658: $runoff = ' ';
2659: } else {
2660: $runoff = ' checked="checked" ';
2661: $runon = ' ';
2662: }
2663: }
2664: if (exists($settings->{'co-owners'})) {
2665: if ($settings->{'co-owners'} eq '0') {
2666: $coownersoff = ' checked="checked" ';
2667: $coownerson = ' ';
2668: } else {
2669: $coownerson = ' checked="checked" ';
2670: $coownersoff = ' ';
2671: }
2672: } else {
2673: $coownersoff = ' checked="checked" ';
2674: $coownerson = ' ';
2675: }
2676: if (exists($settings->{'sender_domain'})) {
2677: $defdom = $settings->{'sender_domain'};
2678: }
2679: if (exists($settings->{'autofailsafe'})) {
2680: $failsafe = $settings->{'autofailsafe'};
2681: }
2682: } else {
2683: if ($autorun) {
2684: $runon = ' checked="checked" ';
2685: $runoff = ' ';
2686: } else {
2687: $runoff = ' checked="checked" ';
2688: $runon = ' ';
2689: }
2690: }
2691: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
2692: my $notif_sender;
2693: if (ref($settings) eq 'HASH') {
2694: $notif_sender = $settings->{'sender_uname'};
2695: }
2696: my $datatable='<tr class="LC_odd_row">'.
2697: '<td>'.&mt('Auto-enrollment active?').'</td>'.
2698: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2699: '<input type="radio" name="autoenroll_run"'.
2700: $runon.' value="1" />'.&mt('Yes').'</label> '.
2701: '<label><input type="radio" name="autoenroll_run"'.
2702: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
2703: '</tr><tr>'.
2704: '<td>'.&mt('Notification messages - sender').
2705: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
2706: &mt('username').': '.
2707: '<input type="text" name="sender_uname" value="'.
2708: $notif_sender.'" size="10" /> '.&mt('domain').
2709: ': '.$domform.'</span></td></tr>'.
2710: '<tr class="LC_odd_row">'.
2711: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2712: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2713: '<input type="radio" name="autoassign_coowners"'.
2714: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2715: '<label><input type="radio" name="autoassign_coowners"'.
2716: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2717: '</tr><tr>'.
2718: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2719: '<td class="LC_right_item"><span class="LC_nobreak">'.
2720: '<input type="text" name="autoenroll_failsafe"'.
2721: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
2722: $$rowtotal += 4;
2723: return $datatable;
2724: }
2725:
2726: sub print_autoupdate {
2727: my ($position,$dom,$settings,$rowtotal) = @_;
2728: my $datatable;
2729: if ($position eq 'top') {
2730: my $updateon = ' ';
2731: my $updateoff = ' checked="checked" ';
2732: my $classlistson = ' ';
2733: my $classlistsoff = ' checked="checked" ';
2734: if (ref($settings) eq 'HASH') {
2735: if ($settings->{'run'} eq '1') {
2736: $updateon = $updateoff;
2737: $updateoff = ' ';
2738: }
2739: if ($settings->{'classlists'} eq '1') {
2740: $classlistson = $classlistsoff;
2741: $classlistsoff = ' ';
2742: }
2743: }
2744: my %title = (
2745: run => 'Auto-update active?',
2746: classlists => 'Update information in classlists?',
2747: );
2748: $datatable = '<tr class="LC_odd_row">'.
2749: '<td>'.&mt($title{'run'}).'</td>'.
2750: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2751: '<input type="radio" name="autoupdate_run"'.
2752: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2753: '<label><input type="radio" name="autoupdate_run"'.
2754: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
2755: '</tr><tr>'.
2756: '<td>'.&mt($title{'classlists'}).'</td>'.
2757: '<td class="LC_right_item"><span class="LC_nobreak">'.
2758: '<label><input type="radio" name="classlists"'.
2759: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2760: '<label><input type="radio" name="classlists"'.
2761: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
2762: '</tr>';
2763: $$rowtotal += 2;
2764: } elsif ($position eq 'middle') {
2765: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2766: my $numinrow = 3;
2767: my $locknamesettings;
2768: $datatable .= &insttypes_row($settings,$types,$usertypes,
2769: $dom,$numinrow,$othertitle,
2770: 'lockablenames',$rowtotal);
2771: $$rowtotal ++;
2772: } else {
2773: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2774: my @fields = ('lastname','firstname','middlename','generation',
2775: 'permanentemail','id');
2776: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2777: my $numrows = 0;
2778: if (ref($types) eq 'ARRAY') {
2779: if (@{$types} > 0) {
2780: $datatable =
2781: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2782: \@fields,$types,\$numrows);
2783: $$rowtotal += @{$types};
2784: }
2785: }
2786: $datatable .=
2787: &usertype_update_row($settings,{'default' => $othertitle},
2788: \%fieldtitles,\@fields,['default'],
2789: \$numrows);
2790: $$rowtotal ++;
2791: }
2792: return $datatable;
2793: }
2794:
2795: sub print_autocreate {
2796: my ($dom,$settings,$rowtotal) = @_;
2797: my (%createon,%createoff,%currhash);
2798: my @types = ('xml','req');
2799: if (ref($settings) eq 'HASH') {
2800: foreach my $item (@types) {
2801: $createoff{$item} = ' checked="checked" ';
2802: $createon{$item} = ' ';
2803: if (exists($settings->{$item})) {
2804: if ($settings->{$item}) {
2805: $createon{$item} = ' checked="checked" ';
2806: $createoff{$item} = ' ';
2807: }
2808: }
2809: }
2810: if ($settings->{'xmldc'} ne '') {
2811: $currhash{$settings->{'xmldc'}} = 1;
2812: }
2813: } else {
2814: foreach my $item (@types) {
2815: $createoff{$item} = ' checked="checked" ';
2816: $createon{$item} = ' ';
2817: }
2818: }
2819: $$rowtotal += 2;
2820: my $numinrow = 2;
2821: my $datatable='<tr class="LC_odd_row">'.
2822: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2823: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2824: '<input type="radio" name="autocreate_xml"'.
2825: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2826: '<label><input type="radio" name="autocreate_xml"'.
2827: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2828: '</td></tr><tr>'.
2829: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2830: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2831: '<input type="radio" name="autocreate_req"'.
2832: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2833: '<label><input type="radio" name="autocreate_req"'.
2834: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2835: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2836: 'autocreate_xmldc',%currhash);
2837: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
2838: if ($numdc > 1) {
2839: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2840: '</td><td class="LC_left_item">';
2841: } else {
2842: $datatable .= &mt('Course creation processed as:').
2843: '</td><td class="LC_right_item">';
2844: }
2845: $datatable .= $dctable.'</td></tr>';
2846: $$rowtotal += $rows;
2847: return $datatable;
2848: }
2849:
2850: sub print_directorysrch {
2851: my ($position,$dom,$settings,$rowtotal) = @_;
2852: my $datatable;
2853: if ($position eq 'top') {
2854: my $instsrchon = ' ';
2855: my $instsrchoff = ' checked="checked" ';
2856: my ($exacton,$containson,$beginson);
2857: my $instlocalon = ' ';
2858: my $instlocaloff = ' checked="checked" ';
2859: if (ref($settings) eq 'HASH') {
2860: if ($settings->{'available'} eq '1') {
2861: $instsrchon = $instsrchoff;
2862: $instsrchoff = ' ';
2863: }
2864: if ($settings->{'localonly'} eq '1') {
2865: $instlocalon = $instlocaloff;
2866: $instlocaloff = ' ';
2867: }
2868: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2869: foreach my $type (@{$settings->{'searchtypes'}}) {
2870: if ($type eq 'exact') {
2871: $exacton = ' checked="checked" ';
2872: } elsif ($type eq 'contains') {
2873: $containson = ' checked="checked" ';
2874: } elsif ($type eq 'begins') {
2875: $beginson = ' checked="checked" ';
2876: }
2877: }
2878: } else {
2879: if ($settings->{'searchtypes'} eq 'exact') {
2880: $exacton = ' checked="checked" ';
2881: } elsif ($settings->{'searchtypes'} eq 'contains') {
2882: $containson = ' checked="checked" ';
2883: } elsif ($settings->{'searchtypes'} eq 'specify') {
2884: $exacton = ' checked="checked" ';
2885: $containson = ' checked="checked" ';
2886: }
2887: }
2888: }
2889: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2890: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2891:
2892: my $numinrow = 4;
2893: my $cansrchrow = 0;
2894: $datatable='<tr class="LC_odd_row">'.
2895: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2896: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2897: '<input type="radio" name="dirsrch_available"'.
2898: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2899: '<label><input type="radio" name="dirsrch_available"'.
2900: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2901: '</tr><tr>'.
2902: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2903: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2904: '<input type="radio" name="dirsrch_instlocalonly"'.
2905: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2906: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2907: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2908: '</tr>';
2909: $$rowtotal += 2;
2910: if (ref($usertypes) eq 'HASH') {
2911: if (keys(%{$usertypes}) > 0) {
2912: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2913: $numinrow,$othertitle,'cansearch',
2914: $rowtotal);
2915: $cansrchrow = 1;
2916: }
2917: }
2918: if ($cansrchrow) {
2919: $$rowtotal ++;
2920: $datatable .= '<tr>';
2921: } else {
2922: $datatable .= '<tr class="LC_odd_row">';
2923: }
2924: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2925: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2926: foreach my $title (@{$titleorder}) {
2927: if (defined($searchtitles->{$title})) {
2928: my $check = ' ';
2929: if (ref($settings) eq 'HASH') {
2930: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2931: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2932: $check = ' checked="checked" ';
2933: }
2934: }
2935: }
2936: $datatable .= '<td class="LC_left_item">'.
2937: '<span class="LC_nobreak"><label>'.
2938: '<input type="checkbox" name="searchby" '.
2939: 'value="'.$title.'"'.$check.'/>'.
2940: $searchtitles->{$title}.'</label></span></td>';
2941: }
2942: }
2943: $datatable .= '</tr></table></td></tr>';
2944: $$rowtotal ++;
2945: if ($cansrchrow) {
2946: $datatable .= '<tr class="LC_odd_row">';
2947: } else {
2948: $datatable .= '<tr>';
2949: }
2950: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2951: '<td class="LC_left_item" colspan="2">'.
2952: '<span class="LC_nobreak"><label>'.
2953: '<input type="checkbox" name="searchtypes" '.
2954: $exacton.' value="exact" />'.&mt('Exact match').
2955: '</label> '.
2956: '<label><input type="checkbox" name="searchtypes" '.
2957: $beginson.' value="begins" />'.&mt('Begins with').
2958: '</label> '.
2959: '<label><input type="checkbox" name="searchtypes" '.
2960: $containson.' value="contains" />'.&mt('Contains').
2961: '</label></span></td></tr>';
2962: $$rowtotal ++;
2963: } else {
2964: my $domsrchon = ' checked="checked" ';
2965: my $domsrchoff = ' ';
2966: my $domlocalon = ' ';
2967: my $domlocaloff = ' checked="checked" ';
2968: if (ref($settings) eq 'HASH') {
2969: if ($settings->{'lclocalonly'} eq '1') {
2970: $domlocalon = $domlocaloff;
2971: $domlocaloff = ' ';
2972: }
2973: if ($settings->{'lcavailable'} eq '0') {
2974: $domsrchoff = $domsrchon;
2975: $domsrchon = ' ';
2976: }
2977: }
2978: $datatable='<tr class="LC_odd_row">'.
2979: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2980: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2981: '<input type="radio" name="dirsrch_domavailable"'.
2982: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2983: '<label><input type="radio" name="dirsrch_domavailable"'.
2984: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2985: '</tr><tr>'.
2986: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2987: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2988: '<input type="radio" name="dirsrch_domlocalonly"'.
2989: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2990: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2991: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2992: '</tr>';
2993: $$rowtotal += 2;
2994: }
2995: return $datatable;
2996: }
2997:
2998: sub print_contacts {
2999: my ($position,$dom,$settings,$rowtotal) = @_;
3000: my $datatable;
3001: my @contacts = ('adminemail','supportemail');
3002: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3003: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
3004: if ($position eq 'top') {
3005: if (ref($settings) eq 'HASH') {
3006: foreach my $item (@contacts) {
3007: if (exists($settings->{$item})) {
3008: $to{$item} = $settings->{$item};
3009: }
3010: }
3011: }
3012: } elsif ($position eq 'middle') {
3013: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3014: 'updatesmail','idconflictsmail','hostipmail');
3015: foreach my $type (@mailings) {
3016: $otheremails{$type} = '';
3017: }
3018: } elsif ($position eq 'lower') {
3019: if (ref($settings) eq 'HASH') {
3020: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3021: %lonstatus = %{$settings->{'lonstatus'}};
3022: }
3023: }
3024: } else {
3025: @mailings = ('helpdeskmail','otherdomsmail');
3026: foreach my $type (@mailings) {
3027: $otheremails{$type} = '';
3028: }
3029: $bccemails{'helpdeskmail'} = '';
3030: $bccemails{'otherdomsmail'} = '';
3031: $includestr{'helpdeskmail'} = '';
3032: $includestr{'otherdomsmail'} = '';
3033: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3034: }
3035: if (ref($settings) eq 'HASH') {
3036: unless (($position eq 'top') || ($position eq 'lower')) {
3037: foreach my $type (@mailings) {
3038: if (exists($settings->{$type})) {
3039: if (ref($settings->{$type}) eq 'HASH') {
3040: foreach my $item (@contacts) {
3041: if ($settings->{$type}{$item}) {
3042: $checked{$type}{$item} = ' checked="checked" ';
3043: }
3044: }
3045: $otheremails{$type} = $settings->{$type}{'others'};
3046: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3047: $bccemails{$type} = $settings->{$type}{'bcc'};
3048: if ($settings->{$type}{'include'} ne '') {
3049: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3050: $includestr{$type} = &unescape($includestr{$type});
3051: }
3052: }
3053: }
3054: } elsif ($type eq 'lonstatusmail') {
3055: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3056: }
3057: }
3058: }
3059: if ($position eq 'bottom') {
3060: foreach my $type (@mailings) {
3061: $bccemails{$type} = $settings->{$type}{'bcc'};
3062: if ($settings->{$type}{'include'} ne '') {
3063: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3064: $includestr{$type} = &unescape($includestr{$type});
3065: }
3066: }
3067: if (ref($settings->{'helpform'}) eq 'HASH') {
3068: if (ref($fields) eq 'ARRAY') {
3069: foreach my $field (@{$fields}) {
3070: $currfield{$field} = $settings->{'helpform'}{$field};
3071: }
3072: }
3073: if (exists($settings->{'helpform'}{'maxsize'})) {
3074: $maxsize = $settings->{'helpform'}{'maxsize'};
3075: } else {
3076: $maxsize = '1.0';
3077: }
3078: } else {
3079: if (ref($fields) eq 'ARRAY') {
3080: foreach my $field (@{$fields}) {
3081: $currfield{$field} = 'yes';
3082: }
3083: }
3084: $maxsize = '1.0';
3085: }
3086: }
3087: } else {
3088: if ($position eq 'top') {
3089: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3090: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3091: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3092: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3093: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3094: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3095: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3096: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3097: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
3098: } elsif ($position eq 'bottom') {
3099: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3100: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3101: if (ref($fields) eq 'ARRAY') {
3102: foreach my $field (@{$fields}) {
3103: $currfield{$field} = 'yes';
3104: }
3105: }
3106: $maxsize = '1.0';
3107: }
3108: }
3109: my ($titles,$short_titles) = &contact_titles();
3110: my $rownum = 0;
3111: my $css_class;
3112: if ($position eq 'top') {
3113: foreach my $item (@contacts) {
3114: $css_class = $rownum%2?' class="LC_odd_row"':'';
3115: $datatable .= '<tr'.$css_class.'>'.
3116: '<td><span class="LC_nobreak">'.$titles->{$item}.
3117: '</span></td><td class="LC_right_item">'.
3118: '<input type="text" name="'.$item.'" value="'.
3119: $to{$item}.'" /></td></tr>';
3120: $rownum ++;
3121: }
3122: } elsif ($position eq 'bottom') {
3123: $css_class = $rownum%2?' class="LC_odd_row"':'';
3124: $datatable .= '<tr'.$css_class.'>'.
3125: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3126: &mt('(e-mail, subject, and description always shown)').
3127: '</td><td class="LC_left_item">';
3128: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3129: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3130: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3131: foreach my $field (@{$fields}) {
3132: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3133: if (($field eq 'screenshot') || ($field eq 'cc')) {
3134: $datatable .= ' '.&mt('(logged-in users)');
3135: }
3136: $datatable .='</td><td>';
3137: my $clickaction;
3138: if ($field eq 'screenshot') {
3139: $clickaction = ' onclick="screenshotSize(this);"';
3140: }
3141: if (ref($possoptions->{$field}) eq 'ARRAY') {
3142: foreach my $option (@{$possoptions->{$field}}) {
3143: my $checked;
3144: if ($currfield{$field} eq $option) {
3145: $checked = ' checked="checked"';
3146: }
3147: $datatable .= '<span class="LC_nobreak"><label>'.
3148: '<input type="radio" name="helpform_'.$field.'" '.
3149: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3150: '</label></span>'.(' 'x2);
3151: }
3152: }
3153: if ($field eq 'screenshot') {
3154: my $display;
3155: if ($currfield{$field} eq 'no') {
3156: $display = ' style="display:none"';
3157: }
3158: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3159: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3160: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3161: }
3162: $datatable .= '</td></tr>';
3163: }
3164: $datatable .= '</table>';
3165: }
3166: $datatable .= '</td></tr>'."\n";
3167: $rownum ++;
3168: }
3169: unless (($position eq 'top') || ($position eq 'lower')) {
3170: foreach my $type (@mailings) {
3171: $css_class = $rownum%2?' class="LC_odd_row"':'';
3172: $datatable .= '<tr'.$css_class.'>'.
3173: '<td><span class="LC_nobreak">'.
3174: $titles->{$type}.': </span></td>'.
3175: '<td class="LC_left_item">';
3176: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3177: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3178: }
3179: $datatable .= '<span class="LC_nobreak">';
3180: foreach my $item (@contacts) {
3181: $datatable .= '<label>'.
3182: '<input type="checkbox" name="'.$type.'"'.
3183: $checked{$type}{$item}.
3184: ' value="'.$item.'" />'.$short_titles->{$item}.
3185: '</label> ';
3186: }
3187: $datatable .= '</span><br />'.&mt('Others').': '.
3188: '<input type="text" name="'.$type.'_others" '.
3189: 'value="'.$otheremails{$type}.'" />';
3190: my %locchecked;
3191: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3192: foreach my $loc ('s','b') {
3193: if ($includeloc{$type} eq $loc) {
3194: $locchecked{$loc} = ' checked="checked"';
3195: last;
3196: }
3197: }
3198: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3199: '<input type="text" name="'.$type.'_bcc" '.
3200: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3201: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3202: &mt('Text automatically added to e-mail:').' '.
3203: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
3204: '<span class="LC_nobreak">'.&mt('Location:').' '.
3205: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3206: (' 'x2).
3207: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3208: '</span></fieldset>';
3209: }
3210: $datatable .= '</td></tr>'."\n";
3211: $rownum ++;
3212: }
3213: }
3214: if ($position eq 'middle') {
3215: my %choices;
3216: my $corelink = &core_link_msu();
3217: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
3218: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3219: $corelink);
3220: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3221: my @toggles = ('reporterrors','reportupdates','reportstatus');
3222: my %defaultchecked = ('reporterrors' => 'on',
3223: 'reportupdates' => 'on',
3224: 'reportstatus' => 'on');
3225: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3226: \%choices,$rownum);
3227: $datatable .= $reports;
3228: } elsif ($position eq 'lower') {
3229: $css_class = $rownum%2?' class="LC_odd_row"':'';
3230: my ($threshold,$sysmail,%excluded,%weights);
3231: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3232: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3233: $threshold = $lonstatus{'threshold'};
3234: } else {
3235: $threshold = $defaults->{'threshold'};
3236: }
3237: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3238: $sysmail = $lonstatus{'sysmail'};
3239: } else {
3240: $sysmail = $defaults->{'sysmail'};
3241: }
3242: if (ref($lonstatus{'weights'}) eq 'HASH') {
3243: foreach my $type ('E','W','N','U') {
3244: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3245: $weights{$type} = $lonstatus{'weights'}{$type};
3246: } else {
3247: $weights{$type} = $defaults->{$type};
3248: }
3249: }
3250: } else {
3251: foreach my $type ('E','W','N','U') {
3252: $weights{$type} = $defaults->{$type};
3253: }
3254: }
3255: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3256: if (@{$lonstatus{'excluded'}} > 0) {
3257: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3258: }
3259: }
3260: $datatable .= '<tr'.$css_class.'>'.
3261: '<td class="LC_left_item"><span class="LC_nobreak">'.
3262: $titles->{'errorthreshold'}.
3263: '</span></td><td class="LC_left_item">'.
3264: '<input type="text" name="errorthreshold" value="'.
3265: $threshold.'" size="5" /></td></tr>';
3266: $rownum ++;
3267: $css_class = $rownum%2?' class="LC_odd_row"':'';
3268: $datatable .= '<tr'.$css_class.'>'.
3269: '<td class="LC_left_item">'.
3270: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3271: '</span></td><td class="LC_left_item"><table><tr>';
3272: foreach my $type ('E','W','N','U') {
3273: $datatable .= '<td>'.$names->{$type}.'<br />'.
3274: '<input type="text" name="errorweights_'.$type.'" value="'.
3275: $weights{$type}.'" size="5" /></td>';
3276: }
3277: $datatable .= '</tr></table></tr>';
3278: $rownum ++;
3279: $css_class = $rownum%2?' class="LC_odd_row"':'';
3280: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3281: $titles->{'errorexcluded'}.'</td>'.
3282: '<td class="LC_left_item"><table>';
3283: my $numinrow = 4;
3284: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3285: for (my $i=0; $i<@ids; $i++) {
3286: my $rem = $i%($numinrow);
3287: if ($rem == 0) {
3288: if ($i > 0) {
3289: $datatable .= '</tr>';
3290: }
3291: $datatable .= '<tr>';
3292: }
3293: my $check;
3294: if ($excluded{$ids[$i]}) {
3295: $check = ' checked="checked" ';
3296: }
3297: $datatable .= '<td class="LC_left_item">'.
3298: '<span class="LC_nobreak"><label>'.
3299: '<input type="checkbox" name="errorexcluded" '.
3300: 'value="'.$ids[$i].'"'.$check.' />'.
3301: $ids[$i].'</label></span></td>';
3302: }
3303: my $colsleft = $numinrow - @ids%($numinrow);
3304: if ($colsleft > 1 ) {
3305: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3306: ' </td>';
3307: } elsif ($colsleft == 1) {
3308: $datatable .= '<td class="LC_left_item"> </td>';
3309: }
3310: $datatable .= '</tr></table></td></tr>';
3311: $rownum ++;
3312: $css_class = $rownum%2?' class="LC_odd_row"':'';
3313: $datatable .= '<tr'.$css_class.'>'.
3314: '<td class="LC_left_item"><span class="LC_nobreak">'.
3315: $titles->{'errorsysmail'}.
3316: '</span></td><td class="LC_left_item">'.
3317: '<input type="text" name="errorsysmail" value="'.
3318: $sysmail.'" size="5" /></td></tr>';
3319: $rownum ++;
3320: } elsif ($position eq 'bottom') {
3321: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3322: my (@posstypes,%usertypeshash);
3323: if (ref($types) eq 'ARRAY') {
3324: @posstypes = @{$types};
3325: }
3326: if (@posstypes) {
3327: if (ref($usertypes) eq 'HASH') {
3328: %usertypeshash = %{$usertypes};
3329: }
3330: my @overridden;
3331: my $numinrow = 4;
3332: if (ref($settings) eq 'HASH') {
3333: if (ref($settings->{'overrides'}) eq 'HASH') {
3334: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3335: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3336: push(@overridden,$key);
3337: foreach my $item (@contacts) {
3338: if ($settings->{'overrides'}{$key}{$item}) {
3339: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3340: }
3341: }
3342: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3343: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3344: $includeloc{'override_'.$key} = '';
3345: $includestr{'override_'.$key} = '';
3346: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3347: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3348: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3349: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3350: }
3351: }
3352: }
3353: }
3354: }
3355: my $customclass = 'LC_helpdesk_override';
3356: my $optionsprefix = 'LC_options_helpdesk_';
3357:
3358: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3359:
3360: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3361: $numinrow,$othertitle,'overrides',
3362: \$rownum,$onclicktypes,$customclass);
3363: $rownum ++;
3364: $usertypeshash{'default'} = $othertitle;
3365: foreach my $status (@posstypes) {
3366: my $css_class;
3367: if ($rownum%2) {
3368: $css_class = 'LC_odd_row ';
3369: }
3370: $css_class .= $customclass;
3371: my $rowid = $optionsprefix.$status;
3372: my $hidden = 1;
3373: my $currstyle = 'display:none';
3374: if (grep(/^\Q$status\E$/,@overridden)) {
3375: $currstyle = 'display:table-row';
3376: $hidden = 0;
3377: }
3378: my $key = 'override_'.$status;
3379: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3380: $includeloc{$key},$includestr{$key},$status,$rowid,
3381: $usertypeshash{$status},$css_class,$currstyle,
3382: \@contacts,$short_titles);
3383: unless ($hidden) {
3384: $rownum ++;
3385: }
3386: }
3387: }
3388: }
3389: $$rowtotal += $rownum;
3390: return $datatable;
3391: }
3392:
3393: sub core_link_msu {
3394: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3395: &mt('LON-CAPA core group - MSU'),600,500);
3396: }
3397:
3398: sub overridden_helpdesk {
3399: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3400: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3401: my $class = 'LC_left_item';
3402: if ($css_class) {
3403: $css_class = ' class="'.$css_class.'"';
3404: }
3405: if ($rowid) {
3406: $rowid = ' id="'.$rowid.'"';
3407: }
3408: if ($rowstyle) {
3409: $rowstyle = ' style="'.$rowstyle.'"';
3410: }
3411: my ($output,$description);
3412: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3413: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3414: "<td>$description</td>\n".
3415: '<td class="'.$class.'" colspan="2">'.
3416: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3417: '<span class="LC_nobreak">';
3418: if (ref($contacts) eq 'ARRAY') {
3419: foreach my $item (@{$contacts}) {
3420: my $check;
3421: if (ref($checked) eq 'HASH') {
3422: $check = $checked->{$item};
3423: }
3424: my $title;
3425: if (ref($short_titles) eq 'HASH') {
3426: $title = $short_titles->{$item};
3427: }
3428: $output .= '<label>'.
3429: '<input type="checkbox" name="override_'.$type.'"'.$check.
3430: ' value="'.$item.'" />'.$title.'</label> ';
3431: }
3432: }
3433: $output .= '</span><br />'.&mt('Others').': '.
3434: '<input type="text" name="override_'.$type.'_others" '.
3435: 'value="'.$otheremails.'" />';
3436: my %locchecked;
3437: foreach my $loc ('s','b') {
3438: if ($includeloc eq $loc) {
3439: $locchecked{$loc} = ' checked="checked"';
3440: last;
3441: }
3442: }
3443: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3444: '<input type="text" name="override_'.$type.'_bcc" '.
3445: 'value="'.$bccemails.'" /></fieldset>'.
3446: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3447: &mt('Text automatically added to e-mail:').' '.
3448: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
3449: '<span class="LC_nobreak">'.&mt('Location:').' '.
3450: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3451: (' 'x2).
3452: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3453: '</span></fieldset>'.
3454: '</td></tr>'."\n";
3455: return $output;
3456: }
3457:
3458: sub contacts_javascript {
3459: return <<"ENDSCRIPT";
3460:
3461: <script type="text/javascript">
3462: // <![CDATA[
3463:
3464: function screenshotSize(field) {
3465: if (document.getElementById('help_screenshotsize')) {
3466: if (field.value == 'no') {
3467: document.getElementById('help_screenshotsize').style.display="none";
3468: } else {
3469: document.getElementById('help_screenshotsize').style.display="";
3470: }
3471: }
3472: return;
3473: }
3474:
3475: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3476: if (form.elements[checkbox].length != undefined) {
3477: var count = 0;
3478: if (docount) {
3479: for (var i=0; i<form.elements[checkbox].length; i++) {
3480: if (form.elements[checkbox][i].checked) {
3481: count ++;
3482: }
3483: }
3484: }
3485: for (var i=0; i<form.elements[checkbox].length; i++) {
3486: var type = form.elements[checkbox][i].value;
3487: if (document.getElementById(prefix+type)) {
3488: if (form.elements[checkbox][i].checked) {
3489: document.getElementById(prefix+type).style.display = 'table-row';
3490: if (count % 2 == 1) {
3491: document.getElementById(prefix+type).className = target+' LC_odd_row';
3492: } else {
3493: document.getElementById(prefix+type).className = target;
3494: }
3495: count ++;
3496: } else {
3497: document.getElementById(prefix+type).style.display = 'none';
3498: }
3499: }
3500: }
3501: }
3502: return;
3503: }
3504:
3505: // ]]>
3506: </script>
3507:
3508: ENDSCRIPT
3509: }
3510:
3511: sub print_helpsettings {
3512: my ($position,$dom,$settings,$rowtotal) = @_;
3513: my $confname = $dom.'-domainconfig';
3514: my $formname = 'display';
3515: my ($datatable,$itemcount);
3516: if ($position eq 'top') {
3517: $itemcount = 1;
3518: my (%choices,%defaultchecked,@toggles);
3519: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3520: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3521: &mt('LON-CAPA bug tracker'),600,500));
3522: %defaultchecked = ('submitbugs' => 'on');
3523: @toggles = ('submitbugs');
3524: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3525: \%choices,$itemcount);
3526: $$rowtotal ++;
3527: } else {
3528: my $css_class;
3529: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
3530: my (%customroles,%ordered,%current);
3531: if (ref($settings) eq 'HASH') {
3532: if (ref($settings->{'adhoc'}) eq 'HASH') {
3533: %current = %{$settings->{'adhoc'}};
3534: }
3535: }
3536: my $count = 0;
3537: foreach my $key (sort(keys(%existing))) {
3538: if ($key=~/^rolesdef\_(\w+)$/) {
3539: my $rolename = $1;
3540: my (%privs,$order);
3541: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3542: $customroles{$rolename} = \%privs;
3543: if (ref($current{$rolename}) eq 'HASH') {
3544: $order = $current{$rolename}{'order'};
3545: }
3546: if ($order eq '') {
3547: $order = $count;
3548: }
3549: $ordered{$order} = $rolename;
3550: $count++;
3551: }
3552: }
3553: my $maxnum = scalar(keys(%ordered));
3554: my @roles_by_num = ();
3555: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3556: push(@roles_by_num,$item);
3557: }
3558: my $context = 'domprefs';
3559: my $crstype = 'Course';
3560: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3561: my @accesstypes = ('all','dh','da','none');
3562: my ($numstatustypes,@jsarray);
3563: if (ref($types) eq 'ARRAY') {
3564: if (@{$types} > 0) {
3565: $numstatustypes = scalar(@{$types});
3566: push(@accesstypes,'status');
3567: @jsarray = ('bystatus');
3568: }
3569: }
3570: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
3571: if (keys(%domhelpdesk)) {
3572: push(@accesstypes,('inc','exc'));
3573: push(@jsarray,('notinc','notexc'));
3574: }
3575: my $hiddenstr = join("','",@jsarray);
3576: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
3577: my $context = 'domprefs';
3578: my $crstype = 'Course';
3579: my $prefix = 'helproles_';
3580: my $add_class = 'LC_hidden';
3581: foreach my $num (@roles_by_num) {
3582: my $role = $ordered{$num};
3583: my ($desc,$access,@statuses);
3584: if (ref($current{$role}) eq 'HASH') {
3585: $desc = $current{$role}{'desc'};
3586: $access = $current{$role}{'access'};
3587: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3588: @statuses = @{$current{$role}{'insttypes'}};
3589: }
3590: }
3591: if ($desc eq '') {
3592: $desc = $role;
3593: }
3594: my $identifier = 'custhelp'.$num;
3595: my %full=();
3596: my %levels= (
3597: course => {},
3598: domain => {},
3599: system => {},
3600: );
3601: my %levelscurrent=(
3602: course => {},
3603: domain => {},
3604: system => {},
3605: );
3606: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3607: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3608: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3609: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3610: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3611: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3612: for (my $k=0; $k<=$maxnum; $k++) {
3613: my $vpos = $k+1;
3614: my $selstr;
3615: if ($k == $num) {
3616: $selstr = ' selected="selected" ';
3617: }
3618: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3619: }
3620: $datatable .= '</select>'.(' 'x2).
3621: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3622: '</td>'.
3623: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3624: &mt('Name shown to users:').
3625: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3626: '</fieldset>'.
3627: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3628: $othertitle,$usertypes,$types,\%domhelpdesk).
3629: '<fieldset>'.
3630: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
3631: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
3632: \%levelscurrent,$identifier,
3633: 'LC_hidden',$prefix.$num.'_privs').
3634: '</fieldset></td>';
3635: $itemcount ++;
3636: }
3637: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3638: my $newcust = 'custhelp'.$count;
3639: my (%privs,%levelscurrent);
3640: my %full=();
3641: my %levels= (
3642: course => {},
3643: domain => {},
3644: system => {},
3645: );
3646: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3647: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3648: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3649: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3650: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3651: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3652: for (my $k=0; $k<$maxnum+1; $k++) {
3653: my $vpos = $k+1;
3654: my $selstr;
3655: if ($k == $maxnum) {
3656: $selstr = ' selected="selected" ';
3657: }
3658: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3659: }
3660: $datatable .= '</select> '."\n".
3661: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3662: '</label></span></td>'.
3663: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3664: '<span class="LC_nobreak">'.
3665: &mt('Internal name:').
3666: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3667: '</span>'.(' 'x4).
3668: '<span class="LC_nobreak">'.
3669: &mt('Name shown to users:').
3670: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3671: '</span></fieldset>'.
3672: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3673: $usertypes,$types,\%domhelpdesk).
3674: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
3675: &Apache::lonuserutils::custom_role_header($context,$crstype,
3676: \@templateroles,$newcust).
3677: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3678: \%levelscurrent,$newcust).
3679: '</fieldset>'.
3680: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3681: '</td></tr>';
3682: $count ++;
3683: $$rowtotal += $count;
3684: }
3685: return $datatable;
3686: }
3687:
3688: sub adhocbutton {
3689: my ($prefix,$num,$field,$visibility) = @_;
3690: my %lt = &Apache::lonlocal::texthash(
3691: show => 'Show details',
3692: hide => 'Hide details',
3693: );
3694: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3695: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3696: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3697: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3698: }
3699:
3700: sub helpsettings_javascript {
3701: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3702: return unless(ref($roles_by_num) eq 'ARRAY');
3703: my %html_js_lt = &Apache::lonlocal::texthash(
3704: show => 'Show details',
3705: hide => 'Hide details',
3706: );
3707: &html_escape(\%html_js_lt);
3708: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3709: return <<"ENDSCRIPT";
3710: <script type="text/javascript">
3711: // <![CDATA[
3712:
3713: function reorderHelpRoles(form,item) {
3714: var changedVal;
3715: $jstext
3716: var newpos = 'helproles_${total}_pos';
3717: var maxh = 1 + $total;
3718: var current = new Array();
3719: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3720: if (item == newpos) {
3721: changedVal = newitemVal;
3722: } else {
3723: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3724: current[newitemVal] = newpos;
3725: }
3726: for (var i=0; i<helproles.length; i++) {
3727: var elementName = 'helproles_'+helproles[i]+'_pos';
3728: if (elementName != item) {
3729: if (form.elements[elementName]) {
3730: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3731: current[currVal] = elementName;
3732: }
3733: }
3734: }
3735: var oldVal;
3736: for (var j=0; j<maxh; j++) {
3737: if (current[j] == undefined) {
3738: oldVal = j;
3739: }
3740: }
3741: if (oldVal < changedVal) {
3742: for (var k=oldVal+1; k<=changedVal ; k++) {
3743: var elementName = current[k];
3744: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3745: }
3746: } else {
3747: for (var k=changedVal; k<oldVal; k++) {
3748: var elementName = current[k];
3749: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3750: }
3751: }
3752: return;
3753: }
3754:
3755: function helpdeskAccess(num) {
3756: var curraccess = null;
3757: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3758: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3759: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3760: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3761: }
3762: }
3763: }
3764: var shown = Array();
3765: var hidden = Array();
3766: if (curraccess == 'none') {
3767: hidden = Array('$hiddenstr');
3768: } else {
3769: if (curraccess == 'status') {
3770: shown = Array('bystatus');
3771: hidden = Array('notinc','notexc');
3772: } else {
3773: if (curraccess == 'exc') {
3774: shown = Array('notexc');
3775: hidden = Array('notinc','bystatus');
3776: }
3777: if (curraccess == 'inc') {
3778: shown = Array('notinc');
3779: hidden = Array('notexc','bystatus');
3780: }
3781: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
3782: hidden = Array('notinc','notexc','bystatus');
3783: }
3784: }
3785: }
3786: if (hidden.length > 0) {
3787: for (var i=0; i<hidden.length; i++) {
3788: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3789: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3790: }
3791: }
3792: }
3793: if (shown.length > 0) {
3794: for (var i=0; i<shown.length; i++) {
3795: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3796: if (shown[i] == 'privs') {
3797: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3798: } else {
3799: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3800: }
3801: }
3802: }
3803: }
3804: return;
3805: }
3806:
3807: function toggleHelpdeskItem(num,field) {
3808: if (document.getElementById('helproles_'+num+'_'+field)) {
3809: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3810: document.getElementById('helproles_'+num+'_'+field).className =
3811: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3812: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3813: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3814: }
3815: } else {
3816: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3817: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3818: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3819: }
3820: }
3821: }
3822: return;
3823: }
3824:
3825: // ]]>
3826: </script>
3827:
3828: ENDSCRIPT
3829: }
3830:
3831: sub helpdeskroles_access {
3832: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3833: $usertypes,$types,$domhelpdesk) = @_;
3834: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3835: my %lt = &Apache::lonlocal::texthash(
3836: 'rou' => 'Role usage',
3837: 'whi' => 'Which helpdesk personnel may use this role?',
3838: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3839: 'dh' => 'All with domain helpdesk role',
3840: 'da' => 'All with domain helpdesk assistant role',
3841: 'none' => 'None',
3842: 'status' => 'Determined based on institutional status',
3843: 'inc' => 'Include all, but exclude specific personnel',
3844: 'exc' => 'Exclude all, but include specific personnel',
3845: );
3846: my %usecheck = (
3847: all => ' checked="checked"',
3848: );
3849: my %displaydiv = (
3850: status => 'none',
3851: inc => 'none',
3852: exc => 'none',
3853: priv => 'block',
3854: );
3855: my $output;
3856: if (ref($current) eq 'HASH') {
3857: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3858: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3859: $usecheck{$current->{access}} = $usecheck{'all'};
3860: delete($usecheck{'all'});
3861: if ($current->{access} =~ /^(status|inc|exc)$/) {
3862: my $access = $1;
3863: $displaydiv{$access} = 'inline';
3864: } elsif ($current->{access} eq 'none') {
3865: $displaydiv{'priv'} = 'none';
3866: }
3867: }
3868: }
3869: }
3870: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3871: '<p>'.$lt{'whi'}.'</p>';
3872: foreach my $access (@{$accesstypes}) {
3873: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3874: ' onclick="helpdeskAccess('."'$num'".');" />'.
3875: $lt{$access}.'</label>';
3876: if ($access eq 'status') {
3877: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3878: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3879: $othertitle,$usertypes,$types).
3880: '</div>';
3881: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3882: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3883: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3884: '</div>';
3885: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3886: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3887: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3888: '</div>';
3889: }
3890: $output .= '</p>';
3891: }
3892: $output .= '</fieldset>';
3893: return $output;
3894: }
3895:
3896: sub radiobutton_prefs {
3897: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
3898: $additional,$align) = @_;
3899: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3900: (ref($choices) eq 'HASH'));
3901:
3902: my (%checkedon,%checkedoff,$datatable,$css_class);
3903:
3904: foreach my $item (@{$toggles}) {
3905: if ($defaultchecked->{$item} eq 'on') {
3906: $checkedon{$item} = ' checked="checked" ';
3907: $checkedoff{$item} = ' ';
3908: } elsif ($defaultchecked->{$item} eq 'off') {
3909: $checkedoff{$item} = ' checked="checked" ';
3910: $checkedon{$item} = ' ';
3911: }
3912: }
3913: if (ref($settings) eq 'HASH') {
3914: foreach my $item (@{$toggles}) {
3915: if ($settings->{$item} eq '1') {
3916: $checkedon{$item} = ' checked="checked" ';
3917: $checkedoff{$item} = ' ';
3918: } elsif ($settings->{$item} eq '0') {
3919: $checkedoff{$item} = ' checked="checked" ';
3920: $checkedon{$item} = ' ';
3921: }
3922: }
3923: }
3924: if ($onclick) {
3925: $onclick = ' onclick="'.$onclick.'"';
3926: }
3927: foreach my $item (@{$toggles}) {
3928: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3929: $datatable .=
3930: '<tr'.$css_class.'><td valign="top">'.
3931: '<span class="LC_nobreak">'.$choices->{$item}.
3932: '</span></td>';
3933: if ($align eq 'left') {
3934: $datatable .= '<td class="LC_left_item">';
3935: } else {
3936: $datatable .= '<td class="LC_right_item">';
3937: }
3938: $datatable .=
3939: '<span class="LC_nobreak">'.
3940: '<label><input type="radio" name="'.
3941: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
3942: '</label> <label><input type="radio" name="'.$item.'" '.
3943: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3944: '</span>'.$additional.
3945: '</td>'.
3946: '</tr>';
3947: $itemcount ++;
3948: }
3949: return ($datatable,$itemcount);
3950: }
3951:
3952: sub print_ltitools {
3953: my ($dom,$settings,$rowtotal) = @_;
3954: my $rownum = 0;
3955: my $css_class;
3956: my $itemcount = 1;
3957: my $maxnum = 0;
3958: my %ordered;
3959: if (ref($settings) eq 'HASH') {
3960: foreach my $item (keys(%{$settings})) {
3961: if (ref($settings->{$item}) eq 'HASH') {
3962: my $num = $settings->{$item}{'order'};
3963: $ordered{$num} = $item;
3964: }
3965: }
3966: }
3967: my $confname = $dom.'-domainconfig';
3968: my $switchserver = &check_switchserver($dom,$confname);
3969: my $maxnum = scalar(keys(%ordered));
3970: my $datatable;
3971: my %lt = <itools_names();
3972: my @courseroles = ('cc','in','ta','ep','st');
3973: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3974: my @fields = ('fullname','firstname','lastname','email','roles','user');
3975: if (keys(%ordered)) {
3976: my @items = sort { $a <=> $b } keys(%ordered);
3977: for (my $i=0; $i<@items; $i++) {
3978: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3979: my $item = $ordered{$items[$i]};
3980: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
3981: if (ref($settings->{$item}) eq 'HASH') {
3982: $title = $settings->{$item}->{'title'};
3983: $url = $settings->{$item}->{'url'};
3984: $key = $settings->{$item}->{'key'};
3985: $secret = $settings->{$item}->{'secret'};
3986: $lifetime = $settings->{$item}->{'lifetime'};
3987: my $image = $settings->{$item}->{'image'};
3988: if ($image ne '') {
3989: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3990: }
3991: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
3992: $sigsel{'HMAC-256'} = ' selected="selected"';
3993: } else {
3994: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
3995: }
3996: }
3997: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
3998: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3999: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4000: for (my $k=0; $k<=$maxnum; $k++) {
4001: my $vpos = $k+1;
4002: my $selstr;
4003: if ($k == $i) {
4004: $selstr = ' selected="selected" ';
4005: }
4006: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4007: }
4008: $datatable .= '</select>'.(' 'x2).
4009: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4010: &mt('Delete?').'</label></span></td>'.
4011: '<td colspan="2">'.
4012: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4013: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
4014: (' 'x2).
4015: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4016: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4017: (' 'x2).
4018: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4019: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4020: (' 'x2).
4021: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4022: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4023: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
4024: '<br /><br />'.
4025: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
4026: ' value="'.$url.'" /></span>'.
4027: (' 'x2).
4028: '<span class="LC_nobreak">'.$lt{'key'}.':'.
4029: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4030: (' 'x2).
4031: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4032: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4033: (' 'x2).
4034: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4035: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4036: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4037: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4038: '</fieldset>'.
4039: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4040: '<span class="LC_nobreak">'.&mt('Display target:');
4041: my %currdisp;
4042: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4043: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4044: $currdisp{'window'} = ' checked="checked"';
4045: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4046: $currdisp{'tab'} = ' checked="checked"';
4047: } else {
4048: $currdisp{'iframe'} = ' checked="checked"';
4049: }
4050: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4051: $currdisp{'width'} = $1;
4052: }
4053: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4054: $currdisp{'height'} = $1;
4055: }
4056: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4057: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
4058: } else {
4059: $currdisp{'iframe'} = ' checked="checked"';
4060: }
4061: foreach my $disp ('iframe','tab','window') {
4062: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4063: $lt{$disp}.'</label>'.(' 'x2);
4064: }
4065: $datatable .= (' 'x4);
4066: foreach my $dimen ('width','height') {
4067: $datatable .= '<label>'.$lt{$dimen}.' '.
4068: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4069: (' 'x2);
4070: }
4071: $datatable .= '</span><br />'.
4072: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4073: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
4074: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4075: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4076: '</textarea></div><div style=""></div>'.
4077: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4078: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
4079: if ($imgsrc) {
4080: $datatable .= $imgsrc.
4081: '<label><input type="checkbox" name="ltitools_image_del"'.
4082: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4083: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4084: } else {
4085: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4086: }
4087: if ($switchserver) {
4088: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4089: } else {
4090: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4091: }
4092: $datatable .= '</span></fieldset>';
4093: my (%checkedfields,%rolemaps,$userincdom);
4094: if (ref($settings->{$item}) eq 'HASH') {
4095: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4096: %checkedfields = %{$settings->{$item}->{'fields'}};
4097: }
4098: $userincdom = $settings->{$item}->{'incdom'};
4099: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4100: %rolemaps = %{$settings->{$item}->{'roles'}};
4101: $checkedfields{'roles'} = 1;
4102: }
4103: }
4104: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4105: '<span class="LC_nobreak">';
4106: my $userfieldstyle = 'display:none;';
4107: my $seluserdom = '';
4108: my $unseluserdom = ' selected="selected"';
4109: foreach my $field (@fields) {
4110: my ($checked,$onclick,$id,$spacer);
4111: if ($checkedfields{$field}) {
4112: $checked = ' checked="checked"';
4113: }
4114: if ($field eq 'user') {
4115: $id = ' id="ltitools_user_field_'.$i.'"';
4116: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4117: if ($checked) {
4118: $userfieldstyle = 'display:inline-block';
4119: if ($userincdom) {
4120: $seluserdom = $unseluserdom;
4121: $unseluserdom = '';
4122: }
4123: }
4124: } else {
4125: $spacer = (' ' x2);
4126: }
4127: $datatable .= '<label>'.
4128: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4129: $lt{$field}.'</label>'.$spacer;
4130: }
4131: $datatable .= '</span>';
4132: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4133: '<span class="LC_nobreak"> : '.
4134: '<select name="ltitools_userincdom_'.$i.'">'.
4135: '<option value="">'.&mt('Select').'</option>'.
4136: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4137: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4138: '</select></span></div>';
4139: $datatable .= '</fieldset>'.
4140: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4141: foreach my $role (@courseroles) {
4142: my ($selected,$selectnone);
4143: if (!$rolemaps{$role}) {
4144: $selectnone = ' selected="selected"';
4145: }
4146: $datatable .= '<td align="center">'.
4147: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4148: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4149: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4150: foreach my $ltirole (@ltiroles) {
4151: unless ($selectnone) {
4152: if ($rolemaps{$role} eq $ltirole) {
4153: $selected = ' selected="selected"';
4154: } else {
4155: $selected = '';
4156: }
4157: }
4158: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4159: }
4160: $datatable .= '</select></td>';
4161: }
4162: $datatable .= '</tr></table></fieldset>';
4163: my %courseconfig;
4164: if (ref($settings->{$item}) eq 'HASH') {
4165: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4166: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4167: }
4168: }
4169: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4170: foreach my $item ('label','title','target','linktext','explanation','append') {
4171: my $checked;
4172: if ($courseconfig{$item}) {
4173: $checked = ' checked="checked"';
4174: }
4175: $datatable .= '<label>'.
4176: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4177: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4178: }
4179: $datatable .= '</span></fieldset>'.
4180: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4181: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4182: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4183: my %custom = %{$settings->{$item}->{'custom'}};
4184: if (keys(%custom) > 0) {
4185: foreach my $key (sort(keys(%custom))) {
4186: $datatable .= '<tr><td><span class="LC_nobreak">'.
4187: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4188: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4189: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4190: ' value="'.$custom{$key}.'" /></td></tr>';
4191: }
4192: }
4193: }
4194: $datatable .= '<tr><td><span class="LC_nobreak">'.
4195: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4196: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4197: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4198: $datatable .= '</table></fieldset></td></tr>'."\n";
4199: $itemcount ++;
4200: }
4201: }
4202: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4203: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
4204: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4205: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4206: '<select name="ltitools_add_pos"'.$chgstr.'>';
4207: for (my $k=0; $k<$maxnum+1; $k++) {
4208: my $vpos = $k+1;
4209: my $selstr;
4210: if ($k == $maxnum) {
4211: $selstr = ' selected="selected" ';
4212: }
4213: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4214: }
4215: $datatable .= '</select> '."\n".
4216: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
4217: '<td colspan="2">'.
4218: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4219: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
4220: (' 'x2).
4221: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4222: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4223: (' 'x2).
4224: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4225: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4226: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4227: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4228: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
4229: '<br />'.
4230: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
4231: (' 'x2).
4232: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4233: (' 'x2).
4234: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4235: (' 'x2).
4236: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4237: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
4238: '</fieldset>'.
4239: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4240: '<span class="LC_nobreak">'.&mt('Display target:');
4241: my %defaultdisp;
4242: $defaultdisp{'iframe'} = ' checked="checked"';
4243: foreach my $disp ('iframe','tab','window') {
4244: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4245: $lt{$disp}.'</label>'.(' 'x2);
4246: }
4247: $datatable .= (' 'x4);
4248: foreach my $dimen ('width','height') {
4249: $datatable .= '<label>'.$lt{$dimen}.' '.
4250: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4251: (' 'x2);
4252: }
4253: $datatable .= '</span><br />'.
4254: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4255: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
4256: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4257: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4258: '</div><div style=""></div>'.
4259: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4260: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
4261: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4262: if ($switchserver) {
4263: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4264: } else {
4265: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4266: }
4267: $datatable .= '</span></fieldset>'.
4268: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4269: '<span class="LC_nobreak">';
4270: foreach my $field (@fields) {
4271: my ($id,$onclick,$spacer);
4272: if ($field eq 'user') {
4273: $id = ' id="ltitools_user_field_add"';
4274: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4275: } else {
4276: $spacer = (' ' x2);
4277: }
4278: $datatable .= '<label>'.
4279: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4280: $lt{$field}.'</label>'.$spacer;
4281: }
4282: $datatable .= '</span>'.
4283: '<div style="display:none;" id="ltitools_user_div_add">'.
4284: '<span class="LC_nobreak"> : '.
4285: '<select name="ltitools_userincdom_add">'.
4286: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4287: '<option value="0">'.&mt('username').'</option>'.
4288: '<option value="1">'.&mt('username:domain').'</option>'.
4289: '</select></span></div></fieldset>';
4290: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4291: foreach my $role (@courseroles) {
4292: my ($checked,$checkednone);
4293: $datatable .= '<td align="center">'.
4294: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4295: '<select name="ltitools_add_roles_'.$role.'">'.
4296: '<option value="" selected="selected">'.&mt('Select').'</option>';
4297: foreach my $ltirole (@ltiroles) {
4298: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4299: }
4300: $datatable .= '</select></td>';
4301: }
4302: $datatable .= '</tr></table></fieldset>'.
4303: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4304: foreach my $item ('label','title','target','linktext','explanation','append') {
4305: $datatable .= '<label>'.
4306: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4307: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4308: }
4309: $datatable .= '</span></fieldset>'.
4310: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4311: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4312: '<tr><td><span class="LC_nobreak">'.
4313: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4314: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4315: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4316: '</table></fieldset>'."\n".
4317: '</td>'."\n".
4318: '</tr>'."\n";
4319: $itemcount ++;
4320: return $datatable;
4321: }
4322:
4323: sub ltitools_names {
4324: my %lt = &Apache::lonlocal::texthash(
4325: 'title' => 'Title',
4326: 'version' => 'Version',
4327: 'msgtype' => 'Message Type',
4328: 'sigmethod' => 'Signature Method',
4329: 'url' => 'URL',
4330: 'key' => 'Key',
4331: 'lifetime' => 'Nonce lifetime (s)',
4332: 'secret' => 'Secret',
4333: 'icon' => 'Icon',
4334: 'user' => 'User',
4335: 'fullname' => 'Full Name',
4336: 'firstname' => 'First Name',
4337: 'lastname' => 'Last Name',
4338: 'email' => 'E-mail',
4339: 'roles' => 'Role',
4340: 'window' => 'Window',
4341: 'tab' => 'Tab',
4342: 'iframe' => 'iFrame',
4343: 'height' => 'Height',
4344: 'width' => 'Width',
4345: 'linktext' => 'Default Link Text',
4346: 'explanation' => 'Default Explanation',
4347: 'crstarget' => 'Display target',
4348: 'crslabel' => 'Course label',
4349: 'crstitle' => 'Course title',
4350: 'crslinktext' => 'Link Text',
4351: 'crsexplanation' => 'Explanation',
4352: 'crsappend' => 'Provider URL',
4353: );
4354:
4355: return %lt;
4356: }
4357:
4358: sub print_coursedefaults {
4359: my ($position,$dom,$settings,$rowtotal) = @_;
4360: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
4361: my $itemcount = 1;
4362: my %choices = &Apache::lonlocal::texthash (
4363: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
4364: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4365: coursecredits => 'Credits can be specified for courses',
4366: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4367: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4368: texengine => 'Default method to display mathematics',
4369: postsubmit => 'Disable submit button/keypress following student submission',
4370: canclone => "People who may clone a course (besides course's owner and coordinators)",
4371: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
4372: );
4373: my %staticdefaults = (
4374: anonsurvey_threshold => 10,
4375: uploadquota => 500,
4376: postsubmit => 60,
4377: mysqltables => 172800,
4378: );
4379: if ($position eq 'top') {
4380: %defaultchecked = (
4381: 'uselcmath' => 'on',
4382: 'usejsme' => 'on',
4383: 'canclone' => 'none',
4384: );
4385: @toggles = ('uselcmath','usejsme');
4386: my $deftex = $Apache::lonnet::deftex;
4387: if (ref($settings) eq 'HASH') {
4388: if ($settings->{'texengine'}) {
4389: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4390: $deftex = $settings->{'texengine'};
4391: }
4392: }
4393: }
4394: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4395: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4396: '<span class="LC_nobreak">'.$choices{'texengine'}.
4397: '</span></td><td class="LC_right_item">'.
4398: '<select name="texengine">'."\n";
4399: my %texoptions = (
4400: MathJax => 'MathJax',
4401: mimetex => &mt('Convert to Images'),
4402: tth => &mt('TeX to HTML'),
4403: );
4404: foreach my $renderer ('MathJax','mimetex','tth') {
4405: my $selected = '';
4406: if ($renderer eq $deftex) {
4407: $selected = ' selected="selected"';
4408: }
4409: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4410: }
4411: $mathdisp .= '</select></td></tr>'."\n";
4412: $itemcount ++;
4413: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4414: \%choices,$itemcount);
4415: $datatable = $mathdisp.$datatable;
4416: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4417: $datatable .=
4418: '<tr'.$css_class.'><td valign="top">'.
4419: '<span class="LC_nobreak">'.$choices{'canclone'}.
4420: '</span></td><td class="LC_left_item">';
4421: my $currcanclone = 'none';
4422: my $onclick;
4423: my @cloneoptions = ('none','domain');
4424: my %clonetitles = (
4425: none => 'No additional course requesters',
4426: domain => "Any course requester in course's domain",
4427: instcode => 'Course requests for official courses ...',
4428: );
4429: my (%codedefaults,@code_order,@posscodes);
4430: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4431: \@code_order) eq 'ok') {
4432: if (@code_order > 0) {
4433: push(@cloneoptions,'instcode');
4434: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4435: }
4436: }
4437: if (ref($settings) eq 'HASH') {
4438: if ($settings->{'canclone'}) {
4439: if (ref($settings->{'canclone'}) eq 'HASH') {
4440: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4441: if (@code_order > 0) {
4442: $currcanclone = 'instcode';
4443: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4444: }
4445: }
4446: } elsif ($settings->{'canclone'} eq 'domain') {
4447: $currcanclone = $settings->{'canclone'};
4448: }
4449: }
4450: }
4451: foreach my $option (@cloneoptions) {
4452: my ($checked,$additional);
4453: if ($currcanclone eq $option) {
4454: $checked = ' checked="checked"';
4455: }
4456: if ($option eq 'instcode') {
4457: if (@code_order) {
4458: my $show = 'none';
4459: if ($checked) {
4460: $show = 'block';
4461: }
4462: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4463: &mt('Institutional codes for new and cloned course have identical:').
4464: '<br />';
4465: foreach my $item (@code_order) {
4466: my $codechk;
4467: if ($checked) {
4468: if (grep(/^\Q$item\E$/,@posscodes)) {
4469: $codechk = ' checked="checked"';
4470: }
4471: }
4472: $additional .= '<label>'.
4473: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4474: $item.'</label>';
4475: }
4476: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4477: }
4478: }
4479: $datatable .=
4480: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4481: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4482: '</label> '.$additional.'</span><br />';
4483: }
4484: $datatable .= '</td>'.
4485: '</tr>';
4486: $itemcount ++;
4487: } else {
4488: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4489: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
4490: my $currusecredits = 0;
4491: my $postsubmitclient = 1;
4492: my @types = ('official','unofficial','community','textbook');
4493: if (ref($settings) eq 'HASH') {
4494: $currdefresponder = $settings->{'anonsurvey_threshold'};
4495: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4496: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4497: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4498: }
4499: }
4500: if (ref($settings->{'coursecredits'}) eq 'HASH') {
4501: foreach my $type (@types) {
4502: next if ($type eq 'community');
4503: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4504: if ($defcredits{$type} ne '') {
4505: $currusecredits = 1;
4506: }
4507: }
4508: }
4509: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4510: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4511: $postsubmitclient = 0;
4512: foreach my $type (@types) {
4513: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4514: }
4515: } else {
4516: foreach my $type (@types) {
4517: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4518: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4519: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4520: } else {
4521: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4522: }
4523: } else {
4524: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4525: }
4526: }
4527: }
4528: } else {
4529: foreach my $type (@types) {
4530: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4531: }
4532: }
4533: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4534: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4535: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4536: }
4537: } else {
4538: foreach my $type (@types) {
4539: $currmysql{$type} = $staticdefaults{'mysqltables'};
4540: }
4541: }
4542: } else {
4543: foreach my $type (@types) {
4544: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4545: }
4546: }
4547: if (!$currdefresponder) {
4548: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
4549: } elsif ($currdefresponder < 1) {
4550: $currdefresponder = 1;
4551: }
4552: foreach my $type (@types) {
4553: if ($curruploadquota{$type} eq '') {
4554: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4555: }
4556: }
4557: $datatable .=
4558: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4559: $choices{'anonsurvey_threshold'}.
4560: '</span></td>'.
4561: '<td class="LC_right_item"><span class="LC_nobreak">'.
4562: '<input type="text" name="anonsurvey_threshold"'.
4563: ' value="'.$currdefresponder.'" size="5" /></span>'.
4564: '</td></tr>'."\n";
4565: $itemcount ++;
4566: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4567: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4568: $choices{'uploadquota'}.
4569: '</span></td>'.
4570: '<td align="right" class="LC_right_item">'.
4571: '<table><tr>';
4572: foreach my $type (@types) {
4573: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4574: '<input type="text" name="uploadquota_'.$type.'"'.
4575: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4576: }
4577: $datatable .= '</tr></table></td></tr>'."\n";
4578: $itemcount ++;
4579: my $onclick = "toggleDisplay(this.form,'credits');";
4580: my $display = 'none';
4581: if ($currusecredits) {
4582: $display = 'block';
4583: }
4584: my $additional = '<div id="credits" style="display: '.$display.'">'.
4585: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4586: foreach my $type (@types) {
4587: next if ($type eq 'community');
4588: $additional .= '<td align="center">'.&mt($type).'<br />'.
4589: '<input type="text" name="'.$type.'_credits"'.
4590: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4591: }
4592: $additional .= '</tr></table></div>'."\n";
4593: %defaultchecked = ('coursecredits' => 'off');
4594: @toggles = ('coursecredits');
4595: my $current = {
4596: 'coursecredits' => $currusecredits,
4597: };
4598: (my $table,$itemcount) =
4599: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4600: \%choices,$itemcount,$onclick,$additional,'left');
4601: $datatable .= $table;
4602: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4603: my $display = 'none';
4604: if ($postsubmitclient) {
4605: $display = 'block';
4606: }
4607: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
4608: &mt('Number of seconds submit is disabled').'<br />'.
4609: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4610: '<table><tr>';
4611: foreach my $type (@types) {
4612: $additional .= '<td align="center">'.&mt($type).'<br />'.
4613: '<input type="text" name="'.$type.'_timeout" value="'.
4614: $deftimeout{$type}.'" size="5" /></td>';
4615: }
4616: $additional .= '</tr></table></div>'."\n";
4617: %defaultchecked = ('postsubmit' => 'on');
4618: @toggles = ('postsubmit');
4619: $current = {
4620: 'postsubmit' => $postsubmitclient,
4621: };
4622: ($table,$itemcount) =
4623: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4624: \%choices,$itemcount,$onclick,$additional,'left');
4625: $datatable .= $table;
4626: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4627: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4628: $choices{'mysqltables'}.
4629: '</span></td>'.
4630: '<td align="right" class="LC_right_item">'.
4631: '<table><tr>';
4632: foreach my $type (@types) {
4633: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4634: '<input type="text" name="mysqltables_'.$type.'"'.
4635: ' value="'.$currmysql{$type}.'" size="8" /></td>';
4636: }
4637: $datatable .= '</tr></table></td></tr>'."\n";
4638: $itemcount ++;
4639:
4640: }
4641: $$rowtotal += $itemcount;
4642: return $datatable;
4643: }
4644:
4645: sub print_selfenrollment {
4646: my ($position,$dom,$settings,$rowtotal) = @_;
4647: my ($css_class,$datatable);
4648: my $itemcount = 1;
4649: my @types = ('official','unofficial','community','textbook');
4650: if (($position eq 'top') || ($position eq 'middle')) {
4651: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4652: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4653: my @rows;
4654: my $key;
4655: if ($position eq 'top') {
4656: $key = 'admin';
4657: if (ref($rowsref) eq 'ARRAY') {
4658: @rows = @{$rowsref};
4659: }
4660: } elsif ($position eq 'middle') {
4661: $key = 'default';
4662: @rows = ('types','registered','approval','limit');
4663: }
4664: foreach my $row (@rows) {
4665: if (defined($titlesref->{$row})) {
4666: $itemcount ++;
4667: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4668: $datatable .= '<tr'.$css_class.'>'.
4669: '<td>'.$titlesref->{$row}.'</td>'.
4670: '<td class="LC_left_item">'.
4671: '<table><tr>';
4672: my (%current,%currentcap);
4673: if (ref($settings) eq 'HASH') {
4674: if (ref($settings->{$key}) eq 'HASH') {
4675: foreach my $type (@types) {
4676: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4677: $current{$type} = $settings->{$key}->{$type}->{$row};
4678: }
4679: if (($row eq 'limit') && ($key eq 'default')) {
4680: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4681: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4682: }
4683: }
4684: }
4685: }
4686: }
4687: my %roles = (
4688: '0' => &Apache::lonnet::plaintext('dc'),
4689: );
4690:
4691: foreach my $type (@types) {
4692: unless (($row eq 'registered') && ($key eq 'default')) {
4693: $datatable .= '<th>'.&mt($type).'</th>';
4694: }
4695: }
4696: unless (($row eq 'registered') && ($key eq 'default')) {
4697: $datatable .= '</tr><tr>';
4698: }
4699: foreach my $type (@types) {
4700: if ($type eq 'community') {
4701: $roles{'1'} = &mt('Community personnel');
4702: } else {
4703: $roles{'1'} = &mt('Course personnel');
4704: }
4705: $datatable .= '<td style="vertical-align: top">';
4706: if ($position eq 'top') {
4707: my %checked;
4708: if ($current{$type} eq '0') {
4709: $checked{'0'} = ' checked="checked"';
4710: } else {
4711: $checked{'1'} = ' checked="checked"';
4712: }
4713: foreach my $role ('1','0') {
4714: $datatable .= '<span class="LC_nobreak"><label>'.
4715: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4716: 'value="'.$role.'"'.$checked{$role}.' />'.
4717: $roles{$role}.'</label></span> ';
4718: }
4719: } else {
4720: if ($row eq 'types') {
4721: my %checked;
4722: if ($current{$type} =~ /^(all|dom)$/) {
4723: $checked{$1} = ' checked="checked"';
4724: } else {
4725: $checked{''} = ' checked="checked"';
4726: }
4727: foreach my $val ('','dom','all') {
4728: $datatable .= '<span class="LC_nobreak"><label>'.
4729: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4730: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4731: }
4732: } elsif ($row eq 'registered') {
4733: my %checked;
4734: if ($current{$type} eq '1') {
4735: $checked{'1'} = ' checked="checked"';
4736: } else {
4737: $checked{'0'} = ' checked="checked"';
4738: }
4739: foreach my $val ('0','1') {
4740: $datatable .= '<span class="LC_nobreak"><label>'.
4741: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4742: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4743: }
4744: } elsif ($row eq 'approval') {
4745: my %checked;
4746: if ($current{$type} =~ /^([12])$/) {
4747: $checked{$1} = ' checked="checked"';
4748: } else {
4749: $checked{'0'} = ' checked="checked"';
4750: }
4751: for my $val (0..2) {
4752: $datatable .= '<span class="LC_nobreak"><label>'.
4753: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4754: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4755: }
4756: } elsif ($row eq 'limit') {
4757: my %checked;
4758: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4759: $checked{$1} = ' checked="checked"';
4760: } else {
4761: $checked{'none'} = ' checked="checked"';
4762: }
4763: my $cap;
4764: if ($currentcap{$type} =~ /^\d+$/) {
4765: $cap = $currentcap{$type};
4766: }
4767: foreach my $val ('none','allstudents','selfenrolled') {
4768: $datatable .= '<span class="LC_nobreak"><label>'.
4769: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4770: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4771: }
4772: $datatable .= '<br />'.
4773: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4774: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4775: '</span>';
4776: }
4777: }
4778: $datatable .= '</td>';
4779: }
4780: $datatable .= '</tr>';
4781: }
4782: $datatable .= '</table></td></tr>';
4783: }
4784: } elsif ($position eq 'bottom') {
4785: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4786: }
4787: $$rowtotal += $itemcount;
4788: return $datatable;
4789: }
4790:
4791: sub print_validation_rows {
4792: my ($caller,$dom,$settings,$rowtotal) = @_;
4793: my ($itemsref,$namesref,$fieldsref);
4794: if ($caller eq 'selfenroll') {
4795: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4796: } elsif ($caller eq 'requestcourses') {
4797: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4798: }
4799: my %currvalidation;
4800: if (ref($settings) eq 'HASH') {
4801: if (ref($settings->{'validation'}) eq 'HASH') {
4802: %currvalidation = %{$settings->{'validation'}};
4803: }
4804: }
4805: my $datatable;
4806: my $itemcount = 0;
4807: foreach my $item (@{$itemsref}) {
4808: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4809: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4810: $namesref->{$item}.
4811: '</span></td>'.
4812: '<td class="LC_left_item">';
4813: if (($item eq 'url') || ($item eq 'button')) {
4814: $datatable .= '<span class="LC_nobreak">'.
4815: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4816: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4817: } elsif ($item eq 'fields') {
4818: my @currfields;
4819: if (ref($currvalidation{$item}) eq 'ARRAY') {
4820: @currfields = @{$currvalidation{$item}};
4821: }
4822: foreach my $field (@{$fieldsref}) {
4823: my $check = '';
4824: if (grep(/^\Q$field\E$/,@currfields)) {
4825: $check = ' checked="checked"';
4826: }
4827: $datatable .= '<span class="LC_nobreak"><label>'.
4828: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4829: ' value="'.$field.'"'.$check.' />'.$field.
4830: '</label></span> ';
4831: }
4832: } elsif ($item eq 'markup') {
4833: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
4834: $currvalidation{$item}.
4835: '</textarea>';
4836: }
4837: $datatable .= '</td></tr>'."\n";
4838: if (ref($rowtotal)) {
4839: $itemcount ++;
4840: }
4841: }
4842: if ($caller eq 'requestcourses') {
4843: my %currhash;
4844: if (ref($settings) eq 'HASH') {
4845: if (ref($settings->{'validation'}) eq 'HASH') {
4846: if ($settings->{'validation'}{'dc'} ne '') {
4847: $currhash{$settings->{'validation'}{'dc'}} = 1;
4848: }
4849: }
4850: }
4851: my $numinrow = 2;
4852: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4853: 'validationdc',%currhash);
4854: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4855: $datatable .= '<tr'.$css_class.'><td>';
4856: if ($numdc > 1) {
4857: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
4858: } else {
4859: $datatable .= &mt('Course creation processed as: ');
4860: }
4861: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
4862: $itemcount ++;
4863: }
4864: if (ref($rowtotal)) {
4865: $$rowtotal += $itemcount;
4866: }
4867: return $datatable;
4868: }
4869:
4870: sub print_passwords {
4871: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
4872: my ($datatable,$css_class);
4873: my $itemcount = 0;
4874: my %titles = &Apache::lonlocal::texthash (
4875: captcha => '"Forgot Password" CAPTCHA validation',
4876: link => 'Reset link expiration (hours)',
4877: case => 'Case-sensitive usernames/e-mail',
4878: prelink => 'Information required (form 1)',
4879: postlink => 'Information required (form 2)',
4880: emailsrc => 'LON-CAPA e-mail address type(s)',
4881: customtext => 'Domain specific text (HTML)',
4882: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
4883: intauth_check => 'Check bcrypt cost if authenticated',
4884: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
4885: permanent => 'Permanent e-mail address',
4886: critical => 'Critical notification address',
4887: notify => 'Notification address',
4888: min => 'Minimum password length',
4889: max => 'Maximum password length',
4890: chars => 'Required characters',
4891: numsaved => 'Number of previous passwords to save and disallow reuse',
4892: );
4893: if ($position eq 'top') {
4894: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4895: my $shownlinklife = 2;
4896: my $prelink = 'both';
4897: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
4898: if (ref($settings) eq 'HASH') {
4899: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
4900: $shownlinklife = $settings->{resetlink};
4901: }
4902: if (ref($settings->{resetcase}) eq 'ARRAY') {
4903: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
4904: }
4905: if ($settings->{resetprelink} =~ /^(both|either)$/) {
4906: $prelink = $settings->{resetprelink};
4907: }
4908: if (ref($settings->{resetpostlink}) eq 'HASH') {
4909: %postlink = %{$settings->{resetpostlink}};
4910: }
4911: if (ref($settings->{resetemail}) eq 'ARRAY') {
4912: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
4913: }
4914: if ($settings->{resetremove}) {
4915: $nostdtext = 1;
4916: }
4917: if ($settings->{resetcustom}) {
4918: $customurl = $settings->{resetcustom};
4919: }
4920: } else {
4921: if (ref($types) eq 'ARRAY') {
4922: foreach my $item (@{$types}) {
4923: $casesens{$item} = 1;
4924: $postlink{$item} = ['username','email'];
4925: }
4926: }
4927: $casesens{'default'} = 1;
4928: $postlink{'default'} = ['username','email'];
4929: $prelink = 'both';
4930: %emailsrc = (
4931: permanent => 1,
4932: critical => 1,
4933: notify => 1,
4934: );
4935: }
4936: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
4937: $itemcount ++;
4938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4939: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
4940: '<td class="LC_left_item">'.
4941: '<input type="textbox" value="'.$shownlinklife.'" '.
4942: 'name="passwords_link" size="3" /></td></tr>';
4943: $itemcount ++;
4944: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4945: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
4946: '<td class="LC_left_item">';
4947: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4948: foreach my $item (@{$types}) {
4949: my $checkedcase;
4950: if ($casesens{$item}) {
4951: $checkedcase = ' checked="checked"';
4952: }
4953: $datatable .= '<span class="LC_nobreak"><label>'.
4954: '<input type="checkbox" name="passwords_case_sensitive" value="'.
4955: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
4956: '</span> ';
4957: }
4958: }
4959: my $checkedcase;
4960: if ($casesens{'default'}) {
4961: $checkedcase = ' checked="checked"';
4962: }
4963: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
4964: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
4965: $othertitle.'</label></span></td>';
4966: $itemcount ++;
4967: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4968: my %checkedpre = (
4969: both => ' checked="checked"',
4970: either => '',
4971: );
4972: if ($prelink eq 'either') {
4973: $checkedpre{either} = ' checked="checked"';
4974: $checkedpre{both} = '';
4975: }
4976: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
4977: '<td class="LC_left_item"><span class="LC_nobreak">'.
4978: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
4979: &mt('Both username and e-mail address').'</label></span> '.
4980: '<span class="LC_nobreak"><label>'.
4981: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
4982: &mt('Either username or e-mail address').'</label></span></td></tr>';
4983: $itemcount ++;
4984: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4985: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
4986: '<td class="LC_left_item">';
4987: my %postlinked;
4988: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
4989: foreach my $item (@{$types}) {
4990: undef(%postlinked);
4991: $datatable .= '<fieldset style="display: inline-block;">'.
4992: '<legend>'.$usertypes->{$item}.'</legend>';
4993: if (ref($postlink{$item}) eq 'ARRAY') {
4994: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
4995: }
4996: foreach my $field ('email','username') {
4997: my $checked;
4998: if ($postlinked{$field}) {
4999: $checked = ' checked="checked"';
5000: }
5001: $datatable .= '<span class="LC_nobreak"><label>'.
5002: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5003: $field.'"'.$checked.' />'.$field.'</label>'.
5004: '<span> ';
5005: }
5006: $datatable .= '</fieldset>';
5007: }
5008: }
5009: if (ref($postlink{'default'}) eq 'ARRAY') {
5010: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5011: }
5012: $datatable .= '<fieldset style="display: inline-block;">'.
5013: '<legend>'.$othertitle.'</legend>';
5014: foreach my $field ('email','username') {
5015: my $checked;
5016: if ($postlinked{$field}) {
5017: $checked = ' checked="checked"';
5018: }
5019: $datatable .= '<span class="LC_nobreak"><label>'.
5020: '<input type="checkbox" name="passwords_postlink_default" value="'.
5021: $field.'"'.$checked.' />'.$field.'</label>'.
5022: '<span> ';
5023: }
5024: $datatable .= '</fieldset></td></tr>';
5025: $itemcount ++;
5026: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5027: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5028: '<td class="LC_left_item">';
5029: foreach my $type ('permanent','critical','notify') {
5030: my $checkedemail;
5031: if ($emailsrc{$type}) {
5032: $checkedemail = ' checked="checked"';
5033: }
5034: $datatable .= '<span class="LC_nobreak"><label>'.
5035: '<input type="checkbox" name="passwords_emailsrc" value="'.
5036: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5037: '<span> ';
5038: }
5039: $datatable .= '</td></tr>';
5040: $itemcount ++;
5041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5042: my $switchserver = &check_switchserver($dom,$confname);
5043: my ($showstd,$noshowstd);
5044: if ($nostdtext) {
5045: $noshowstd = ' checked="checked"';
5046: } else {
5047: $showstd = ' checked="checked"';
5048: }
5049: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5050: '<td class="LC_left_item"><span class="LC_nobreak">'.
5051: &mt('Retain standard text:').
5052: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5053: &mt('Yes').'</label>'.' '.
5054: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5055: &mt('No').'</label></span><br />'.
5056: '<span class="LC_fontsize_small">'.
5057: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5058: &mt('Include custom text:');
5059: if ($customurl) {
5060: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
5061: undef,undef,undef,undef,'background-color:#ffffff');
5062: $datatable .= '<span class="LC_nobreak"> '.$link.
5063: '<label><input type="checkbox" name="passwords_custom_del"'.
5064: ' value="1" />'.&mt('Delete?').'</label></span>'.
5065: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5066: }
5067: if ($switchserver) {
5068: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5069: } else {
5070: $datatable .='<span class="LC_nobreak"> '.
5071: '<input type="file" name="passwords_customfile" /></span>';
5072: }
5073: $datatable .= '</td></tr>';
5074: } elsif ($position eq 'middle') {
5075: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5076: my @items = ('intauth_cost','intauth_check','intauth_switch');
5077: my %defaults;
5078: if (ref($domconf{'defaults'}) eq 'HASH') {
5079: %defaults = %{$domconf{'defaults'}};
5080: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5081: $defaults{'intauth_cost'} = 10;
5082: }
5083: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5084: $defaults{'intauth_check'} = 0;
5085: }
5086: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5087: $defaults{'intauth_switch'} = 0;
5088: }
5089: } else {
5090: %defaults = (
5091: 'intauth_cost' => 10,
5092: 'intauth_check' => 0,
5093: 'intauth_switch' => 0,
5094: );
5095: }
5096: foreach my $item (@items) {
5097: if ($itemcount%2) {
5098: $css_class = '';
5099: } else {
5100: $css_class = ' class="LC_odd_row" ';
5101: }
5102: $datatable .= '<tr'.$css_class.'>'.
5103: '<td><span class="LC_nobreak">'.$titles{$item}.
5104: '</span></td><td class="LC_left_item" colspan="3">';
5105: if ($item eq 'intauth_switch') {
5106: my @options = (0,1,2);
5107: my %optiondesc = &Apache::lonlocal::texthash (
5108: 0 => 'No',
5109: 1 => 'Yes',
5110: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5111: );
5112: $datatable .= '<table width="100%">';
5113: foreach my $option (@options) {
5114: my $checked = ' ';
5115: if ($defaults{$item} eq $option) {
5116: $checked = ' checked="checked"';
5117: }
5118: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5119: '<label><input type="radio" name="'.$item.
5120: '" value="'.$option.'"'.$checked.' />'.
5121: $optiondesc{$option}.'</label></span></td></tr>';
5122: }
5123: $datatable .= '</table>';
5124: } elsif ($item eq 'intauth_check') {
5125: my @options = (0,1,2);
5126: my %optiondesc = &Apache::lonlocal::texthash (
5127: 0 => 'No',
5128: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5129: 2 => 'Yes, disallow login if stored cost is less than domain default',
5130: );
5131: $datatable .= '<table width="100%">';
5132: foreach my $option (@options) {
5133: my $checked = ' ';
5134: my $onclick;
5135: if ($defaults{$item} eq $option) {
5136: $checked = ' checked="checked"';
5137: }
5138: if ($option == 2) {
5139: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5140: }
5141: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5142: '<label><input type="radio" name="'.$item.
5143: '" value="'.$option.'"'.$checked.$onclick.' />'.
5144: $optiondesc{$option}.'</label></span></td></tr>';
5145: }
5146: $datatable .= '</table>';
5147: } else {
5148: $datatable .= '<input type="text" name="'.$item.'" value="'.
5149: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5150: }
5151: $datatable .= '</td></tr>';
5152: $itemcount ++;
5153: }
5154: } elsif ($position eq 'lower') {
5155: my ($min,$max,%chars,$numsaved);
5156: $min = $Apache::lonnet::passwdmin;
5157: if (ref($settings) eq 'HASH') {
5158: if ($settings->{min}) {
5159: $min = $settings->{min};
5160: }
5161: if ($settings->{max}) {
5162: $max = $settings->{max};
5163: }
5164: if (ref($settings->{chars}) eq 'ARRAY') {
5165: map { $chars{$_} = 1; } (@{$settings->{chars}});
5166: }
5167: if ($settings->{numsaved}) {
5168: $numsaved = $settings->{numsaved};
5169: }
5170: }
5171: my %rulenames = &Apache::lonlocal::texthash(
5172: uc => 'At least one upper case letter',
5173: lc => 'At least one lower case letter',
5174: num => 'At least one number',
5175: spec => 'At least one non-alphanumeric',
5176: );
5177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5178: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5179: '<td class="LC_left_item"><span class="LC_nobreak">'.
5180: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5181: 'onblur="javascript:warnIntPass(this);" />'.
5182: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
5183: '</span></td></tr>';
5184: $itemcount ++;
5185: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5186: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5187: '<td class="LC_left_item"><span class="LC_nobreak">'.
5188: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5189: 'onblur="javascript:warnIntPass(this);" />'.
5190: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5191: '</span></td></tr>';
5192: $itemcount ++;
5193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5194: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5195: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5196: '</span></td>';
5197: my $numinrow = 2;
5198: my @possrules = ('uc','lc','num','spec');
5199: $datatable .= '<td class="LC_left_item"><table>';
5200: for (my $i=0; $i<@possrules; $i++) {
5201: my ($rem,$checked);
5202: if ($chars{$possrules[$i]}) {
5203: $checked = ' checked="checked"';
5204: }
5205: $rem = $i%($numinrow);
5206: if ($rem == 0) {
5207: if ($i > 0) {
5208: $datatable .= '</tr>';
5209: }
5210: $datatable .= '<tr>';
5211: }
5212: $datatable .= '<td><span class="LC_nobreak"><label>'.
5213: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5214: $rulenames{$possrules[$i]}.'</label></span></td>';
5215: }
5216: my $rem = @possrules%($numinrow);
5217: my $colsleft = $numinrow - $rem;
5218: if ($colsleft > 1 ) {
5219: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5220: ' </td>';
5221: } elsif ($colsleft == 1) {
5222: $datatable .= '<td class="LC_left_item"> </td>';
5223: }
5224: $datatable .='</table></td></tr>';
5225: $itemcount ++;
5226: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5227: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5228: '<td class="LC_left_item"><span class="LC_nobreak">'.
5229: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
5230: 'onblur="javascript:warnIntPass(this);" />'.
5231: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5232: '</span></td></tr>';
5233: } else {
5234: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5235: my %ownerchg = (
5236: by => {},
5237: for => {},
5238: );
5239: my %ownertitles = &Apache::lonlocal::texthash (
5240: by => 'Course owner status(es) allowed',
5241: for => 'Student status(es) allowed',
5242: );
5243: if (ref($settings) eq 'HASH') {
5244: if (ref($settings->{crsownerchg}) eq 'HASH') {
5245: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5246: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5247: }
5248: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5249: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5250: }
5251: }
5252: }
5253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5254: $datatable .= '<tr '.$css_class.'>'.
5255: '<td>'.
5256: &mt('Requirements').'<ul>'.
5257: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5258: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5259: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5260: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5261: '</ul>'.
5262: '</td>'.
5263: '<td class="LC_left_item">';
5264: foreach my $item ('by','for') {
5265: $datatable .= '<fieldset style="display: inline-block;">'.
5266: '<legend>'.$ownertitles{$item}.'</legend>';
5267: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5268: foreach my $type (@{$types}) {
5269: my $checked;
5270: if ($ownerchg{$item}{$type}) {
5271: $checked = ' checked="checked"';
5272: }
5273: $datatable .= '<span class="LC_nobreak"><label>'.
5274: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5275: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
5276: '</span> ';
5277: }
5278: }
5279: my $checked;
5280: if ($ownerchg{$item}{'default'}) {
5281: $checked = ' checked="checked"';
5282: }
5283: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5284: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5285: $othertitle.'</label></span></fieldset>';
5286: }
5287: $datatable .= '</td></tr>';
5288: }
5289: return $datatable;
5290: }
5291:
5292: sub print_usersessions {
5293: my ($position,$dom,$settings,$rowtotal) = @_;
5294: my ($css_class,$datatable,%checked,%choices);
5295: my (%by_ip,%by_location,@intdoms);
5296: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
5297:
5298: my @alldoms = &Apache::lonnet::all_domains();
5299: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5300: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5301: my %altids = &id_for_thisdom(%servers);
5302: my $itemcount = 1;
5303: if ($position eq 'top') {
5304: if (keys(%serverhomes) > 1) {
5305: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
5306: my ($curroffloadnow,$curroffloadoth);
5307: if (ref($settings) eq 'HASH') {
5308: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5309: $curroffloadnow = $settings->{'offloadnow'};
5310: }
5311: if (ref($settings->{'offloadoth'}) eq 'HASH') {
5312: $curroffloadoth = $settings->{'offloadoth'};
5313: }
5314: }
5315: my $other_insts = scalar(keys(%by_location));
5316: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
5317: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
5318: } else {
5319: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
5320: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
5321: }
5322: } else {
5323: if (keys(%by_location) == 0) {
5324: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
5325: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
5326: } else {
5327: my %lt = &usersession_titles();
5328: my $numinrow = 5;
5329: my $prefix;
5330: my @types;
5331: if ($position eq 'bottom') {
5332: $prefix = 'remote';
5333: @types = ('version','excludedomain','includedomain');
5334: } else {
5335: $prefix = 'hosted';
5336: @types = ('excludedomain','includedomain');
5337: }
5338: my (%current,%checkedon,%checkedoff);
5339: my @lcversions = &Apache::lonnet::all_loncaparevs();
5340: my @locations = sort(keys(%by_location));
5341: foreach my $type (@types) {
5342: $checkedon{$type} = '';
5343: $checkedoff{$type} = ' checked="checked"';
5344: }
5345: if (ref($settings) eq 'HASH') {
5346: if (ref($settings->{$prefix}) eq 'HASH') {
5347: foreach my $key (keys(%{$settings->{$prefix}})) {
5348: $current{$key} = $settings->{$prefix}{$key};
5349: if ($key eq 'version') {
5350: if ($current{$key} ne '') {
5351: $checkedon{$key} = ' checked="checked"';
5352: $checkedoff{$key} = '';
5353: }
5354: } elsif (ref($current{$key}) eq 'ARRAY') {
5355: $checkedon{$key} = ' checked="checked"';
5356: $checkedoff{$key} = '';
5357: }
5358: }
5359: }
5360: }
5361: foreach my $type (@types) {
5362: next if ($type ne 'version' && !@locations);
5363: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5364: $datatable .= '<tr'.$css_class.'>
5365: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
5366: <span class="LC_nobreak">
5367: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5368: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5369: if ($type eq 'version') {
5370: my $selector = '<select name="'.$prefix.'_version">';
5371: foreach my $version (@lcversions) {
5372: my $selected = '';
5373: if ($current{'version'} eq $version) {
5374: $selected = ' selected="selected"';
5375: }
5376: $selector .= ' <option value="'.$version.'"'.
5377: $selected.'>'.$version.'</option>';
5378: }
5379: $selector .= '</select> ';
5380: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5381: } else {
5382: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5383: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5384: ' />'.(' 'x2).
5385: '<input type="button" value="'.&mt('uncheck all').'" '.
5386: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5387: "\n".
5388: '</div><div><table>';
5389: my $rem;
5390: for (my $i=0; $i<@locations; $i++) {
5391: my ($showloc,$value,$checkedtype);
5392: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
5393: my $ip = $by_location{$locations[$i]}->[0];
5394: if (ref($by_ip{$ip}) eq 'ARRAY') {
5395: $value = join(':',@{$by_ip{$ip}});
5396: $showloc = join(', ',@{$by_ip{$ip}});
5397: if (ref($current{$type}) eq 'ARRAY') {
5398: foreach my $loc (@{$by_ip{$ip}}) {
5399: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5400: $checkedtype = ' checked="checked"';
5401: last;
5402: }
5403: }
5404: }
5405: }
5406: }
5407: $rem = $i%($numinrow);
5408: if ($rem == 0) {
5409: if ($i > 0) {
5410: $datatable .= '</tr>';
5411: }
5412: $datatable .= '<tr>';
5413: }
5414: $datatable .= '<td class="LC_left_item">'.
5415: '<span class="LC_nobreak"><label>'.
5416: '<input type="checkbox" name="'.$prefix.'_'.$type.
5417: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5418: '</label></span></td>';
5419: }
5420: $rem = @locations%($numinrow);
5421: my $colsleft = $numinrow - $rem;
5422: if ($colsleft > 1 ) {
5423: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5424: ' </td>';
5425: } elsif ($colsleft == 1) {
5426: $datatable .= '<td class="LC_left_item"> </td>';
5427: }
5428: $datatable .= '</tr></table>';
5429: }
5430: $datatable .= '</td></tr>';
5431: $itemcount ++;
5432: }
5433: }
5434: }
5435: $$rowtotal += $itemcount;
5436: return $datatable;
5437: }
5438:
5439: sub build_location_hashes {
5440: my ($intdoms,$by_ip,$by_location) = @_;
5441: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
5442: (ref($by_location) eq 'HASH'));
5443: my %iphost = &Apache::lonnet::get_iphost();
5444: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5445: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5446: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5447: foreach my $id (@{$iphost{$primary_ip}}) {
5448: my $intdom = &Apache::lonnet::internet_dom($id);
5449: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5450: push(@{$intdoms},$intdom);
5451: }
5452: }
5453: }
5454: foreach my $ip (keys(%iphost)) {
5455: if (ref($iphost{$ip}) eq 'ARRAY') {
5456: foreach my $id (@{$iphost{$ip}}) {
5457: my $location = &Apache::lonnet::internet_dom($id);
5458: if ($location) {
5459: next if (grep(/^\Q$location\E$/,@{$intdoms}));
5460: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5461: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5462: push(@{$by_ip->{$ip}},$location);
5463: }
5464: } else {
5465: $by_ip->{$ip} = [$location];
5466: }
5467: }
5468: }
5469: }
5470: }
5471: foreach my $ip (sort(keys(%{$by_ip}))) {
5472: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5473: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5474: my $first = $by_ip->{$ip}->[0];
5475: if (ref($by_location->{$first}) eq 'ARRAY') {
5476: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5477: push(@{$by_location->{$first}},$ip);
5478: }
5479: } else {
5480: $by_location->{$first} = [$ip];
5481: }
5482: }
5483: }
5484: return;
5485: }
5486:
5487: sub current_offloads_to {
5488: my ($dom,$settings,$servers) = @_;
5489: my (%spareid,%otherdomconfigs);
5490: if (ref($servers) eq 'HASH') {
5491: foreach my $lonhost (sort(keys(%{$servers}))) {
5492: my $gotspares;
5493: if (ref($settings) eq 'HASH') {
5494: if (ref($settings->{'spares'}) eq 'HASH') {
5495: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5496: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5497: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5498: $gotspares = 1;
5499: }
5500: }
5501: }
5502: unless ($gotspares) {
5503: my $gotspares;
5504: my $serverhomeID =
5505: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5506: my $serverhomedom =
5507: &Apache::lonnet::host_domain($serverhomeID);
5508: if ($serverhomedom ne $dom) {
5509: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5510: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5511: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5512: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5513: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5514: $gotspares = 1;
5515: }
5516: }
5517: } else {
5518: $otherdomconfigs{$serverhomedom} =
5519: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5520: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5521: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5522: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5523: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5524: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5525: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5526: $gotspares = 1;
5527: }
5528: }
5529: }
5530: }
5531: }
5532: }
5533: }
5534: unless ($gotspares) {
5535: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5536: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5537: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5538: } else {
5539: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5540: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5541: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5542: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5543: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5544: } else {
5545: my %what = (
5546: spareid => 1,
5547: );
5548: my ($result,$returnhash) =
5549: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5550: if ($result eq 'ok') {
5551: if (ref($returnhash) eq 'HASH') {
5552: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5553: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5554: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5555: }
5556: }
5557: }
5558: }
5559: }
5560: }
5561: }
5562: }
5563: return %spareid;
5564: }
5565:
5566: sub spares_row {
5567: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
5568: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
5569: my $css_class;
5570: my $numinrow = 4;
5571: my $itemcount = 1;
5572: my $datatable;
5573: my %typetitles = &sparestype_titles();
5574: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
5575: foreach my $server (sort(keys(%{$servers}))) {
5576: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5577: my ($othercontrol,$serverdom);
5578: if ($serverhome ne $server) {
5579: $serverdom = &Apache::lonnet::host_domain($serverhome);
5580: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5581: } else {
5582: $serverdom = &Apache::lonnet::host_domain($server);
5583: if ($serverdom ne $dom) {
5584: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5585: }
5586: }
5587: next unless (ref($spareid->{$server}) eq 'HASH');
5588: my ($checkednow,$checkedoth);
5589: if (ref($curroffloadnow) eq 'HASH') {
5590: if ($curroffloadnow->{$server}) {
5591: $checkednow = ' checked="checked"';
5592: }
5593: }
5594: if (ref($curroffloadoth) eq 'HASH') {
5595: if ($curroffloadoth->{$server}) {
5596: $checkedoth = ' checked="checked"';
5597: }
5598: }
5599: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5600: $datatable .= '<tr'.$css_class.'>
5601: <td rowspan="2">
5602: <span class="LC_nobreak">'.
5603: &mt('[_1] when busy, offloads to:'
5604: ,'<b>'.$server.'</b>').'</span><br />'.
5605: '<span class="LC_nobreak">'."\n".
5606: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5607: ' '.&mt('Switch any active user on next access').'</label></span>'.
5608: "\n";
5609: if ($other_insts) {
5610: $datatable .= '<br />'.
5611: '<span class="LC_nobreak">'."\n".
5612: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
5613: ' '.&mt('Switch other institutions on next access').'</label></span>'.
5614: "\n";
5615: }
5616: my (%current,%canselect);
5617: my @choices =
5618: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5619: foreach my $type ('primary','default') {
5620: if (ref($spareid->{$server}) eq 'HASH') {
5621: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5622: my @spares = @{$spareid->{$server}{$type}};
5623: if (@spares > 0) {
5624: if ($othercontrol) {
5625: $current{$type} = join(', ',@spares);
5626: } else {
5627: $current{$type} .= '<table>';
5628: my $numspares = scalar(@spares);
5629: for (my $i=0; $i<@spares; $i++) {
5630: my $rem = $i%($numinrow);
5631: if ($rem == 0) {
5632: if ($i > 0) {
5633: $current{$type} .= '</tr>';
5634: }
5635: $current{$type} .= '<tr>';
5636: }
5637: $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'".');" /> '.
5638: $spareid->{$server}{$type}[$i].
5639: '</label></td>'."\n";
5640: }
5641: my $rem = @spares%($numinrow);
5642: my $colsleft = $numinrow - $rem;
5643: if ($colsleft > 1 ) {
5644: $current{$type} .= '<td colspan="'.$colsleft.
5645: '" class="LC_left_item">'.
5646: ' </td>';
5647: } elsif ($colsleft == 1) {
5648: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
5649: }
5650: $current{$type} .= '</tr></table>';
5651: }
5652: }
5653: }
5654: if ($current{$type} eq '') {
5655: $current{$type} = &mt('None specified');
5656: }
5657: if ($othercontrol) {
5658: if ($type eq 'primary') {
5659: $canselect{$type} = $othercontrol;
5660: }
5661: } else {
5662: $canselect{$type} =
5663: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5664: '<select name="newspare_'.$type.'_'.$server.'" '.
5665: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5666: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5667: if (@choices > 0) {
5668: foreach my $lonhost (@choices) {
5669: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5670: }
5671: }
5672: $canselect{$type} .= '</select>'."\n";
5673: }
5674: } else {
5675: $current{$type} = &mt('Could not be determined');
5676: if ($type eq 'primary') {
5677: $canselect{$type} = $othercontrol;
5678: }
5679: }
5680: if ($type eq 'default') {
5681: $datatable .= '<tr'.$css_class.'>';
5682: }
5683: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5684: '<td>'.$current{$type}.'</td>'."\n".
5685: '<td>'.$canselect{$type}.'</td></tr>'."\n";
5686: }
5687: $itemcount ++;
5688: }
5689: }
5690: $$rowtotal += $itemcount;
5691: return $datatable;
5692: }
5693:
5694: sub possible_newspares {
5695: my ($server,$currspares,$serverhomes,$altids) = @_;
5696: my $serverhostname = &Apache::lonnet::hostname($server);
5697: my %excluded;
5698: if ($serverhostname ne '') {
5699: %excluded = (
5700: $serverhostname => 1,
5701: );
5702: }
5703: if (ref($currspares) eq 'HASH') {
5704: foreach my $type (keys(%{$currspares})) {
5705: if (ref($currspares->{$type}) eq 'ARRAY') {
5706: if (@{$currspares->{$type}} > 0) {
5707: foreach my $curr (@{$currspares->{$type}}) {
5708: my $hostname = &Apache::lonnet::hostname($curr);
5709: $excluded{$hostname} = 1;
5710: }
5711: }
5712: }
5713: }
5714: }
5715: my @choices;
5716: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5717: if (keys(%{$serverhomes}) > 1) {
5718: foreach my $name (sort(keys(%{$serverhomes}))) {
5719: unless ($excluded{$name}) {
5720: if (exists($altids->{$serverhomes->{$name}})) {
5721: push(@choices,$altids->{$serverhomes->{$name}});
5722: } else {
5723: push(@choices,$serverhomes->{$name});
5724: }
5725: }
5726: }
5727: }
5728: }
5729: return sort(@choices);
5730: }
5731:
5732: sub print_loadbalancing {
5733: my ($dom,$settings,$rowtotal) = @_;
5734: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5735: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5736: my $numinrow = 1;
5737: my $datatable;
5738: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5739: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
5740: if (ref($settings) eq 'HASH') {
5741: %existing = %{$settings};
5742: }
5743: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5744: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5745: \%currtargets,\%currrules,\%currcookies);
5746: } else {
5747: return;
5748: }
5749: my ($othertitle,$usertypes,$types) =
5750: &Apache::loncommon::sorted_inst_types($dom);
5751: my $rownum = 8;
5752: if (ref($types) eq 'ARRAY') {
5753: $rownum += scalar(@{$types});
5754: }
5755: my @css_class = ('LC_odd_row','LC_even_row');
5756: my $balnum = 0;
5757: my $islast;
5758: my (@toshow,$disabledtext);
5759: if (keys(%currbalancer) > 0) {
5760: @toshow = sort(keys(%currbalancer));
5761: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5762: push(@toshow,'');
5763: }
5764: } else {
5765: @toshow = ('');
5766: $disabledtext = &mt('No existing load balancer');
5767: }
5768: foreach my $lonhost (@toshow) {
5769: if ($balnum == scalar(@toshow)-1) {
5770: $islast = 1;
5771: } else {
5772: $islast = 0;
5773: }
5774: my $cssidx = $balnum%2;
5775: my $targets_div_style = 'display: none';
5776: my $disabled_div_style = 'display: block';
5777: my $homedom_div_style = 'display: none';
5778: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5779: '<td rowspan="'.$rownum.'" valign="top">'.
5780: '<p>';
5781: if ($lonhost eq '') {
5782: $datatable .= '<span class="LC_nobreak">';
5783: if (keys(%currbalancer) > 0) {
5784: $datatable .= &mt('Add balancer:');
5785: } else {
5786: $datatable .= &mt('Enable balancer:');
5787: }
5788: $datatable .= ' '.
5789: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5790: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5791: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5792: '<option value="" selected="selected">'.&mt('None').
5793: '</option>'."\n";
5794: foreach my $server (sort(keys(%servers))) {
5795: next if ($currbalancer{$server});
5796: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5797: }
5798: $datatable .=
5799: '</select>'."\n".
5800: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5801: } else {
5802: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5803: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5804: &mt('Stop balancing').'</label>'.
5805: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5806: $targets_div_style = 'display: block';
5807: $disabled_div_style = 'display: none';
5808: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5809: $homedom_div_style = 'display: block';
5810: }
5811: }
5812: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5813: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5814: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5815: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5816: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5817: my @sparestypes = ('primary','default');
5818: my %typetitles = &sparestype_titles();
5819: my %hostherechecked = (
5820: no => ' checked="checked"',
5821: );
5822: my %balcookiechecked = (
5823: no => ' checked="checked"',
5824: );
5825: foreach my $sparetype (@sparestypes) {
5826: my $targettable;
5827: for (my $i=0; $i<$numspares; $i++) {
5828: my $checked;
5829: if (ref($currtargets{$lonhost}) eq 'HASH') {
5830: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5831: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5832: $checked = ' checked="checked"';
5833: }
5834: }
5835: }
5836: my ($chkboxval,$disabled);
5837: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5838: $chkboxval = $spares[$i];
5839: }
5840: if (exists($currbalancer{$spares[$i]})) {
5841: $disabled = ' disabled="disabled"';
5842: }
5843: $targettable .=
5844: '<td><span class="LC_nobreak"><label>'.
5845: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
5846: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
5847: '</span></label></span></td>';
5848: my $rem = $i%($numinrow);
5849: if ($rem == 0) {
5850: if (($i > 0) && ($i < $numspares-1)) {
5851: $targettable .= '</tr>';
5852: }
5853: if ($i < $numspares-1) {
5854: $targettable .= '<tr>';
5855: }
5856: }
5857: }
5858: if ($targettable ne '') {
5859: my $rem = $numspares%($numinrow);
5860: my $colsleft = $numinrow - $rem;
5861: if ($colsleft > 1 ) {
5862: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5863: ' </td>';
5864: } elsif ($colsleft == 1) {
5865: $targettable .= '<td class="LC_left_item"> </td>';
5866: }
5867: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5868: '<table><tr>'.$targettable.'</tr></table><br />';
5869: }
5870: $hostherechecked{$sparetype} = '';
5871: if (ref($currtargets{$lonhost}) eq 'HASH') {
5872: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5873: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5874: $hostherechecked{$sparetype} = ' checked="checked"';
5875: $hostherechecked{'no'} = '';
5876: }
5877: }
5878: }
5879: }
5880: if ($currcookies{$lonhost}) {
5881: %balcookiechecked = (
5882: yes => ' checked="checked"',
5883: );
5884: }
5885: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5886: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5887: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5888: foreach my $sparetype (@sparestypes) {
5889: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5890: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5891: '</i></label><br />';
5892: }
5893: $datatable .= &mt('Use balancer cookie').'<br />'.
5894: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
5895: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
5896: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
5897: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
5898: '</div></td></tr>'.
5899: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5900: $othertitle,$usertypes,$types,\%servers,
5901: \%currbalancer,$lonhost,
5902: $targets_div_style,$homedom_div_style,
5903: $css_class[$cssidx],$balnum,$islast);
5904: $$rowtotal += $rownum;
5905: $balnum ++;
5906: }
5907: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5908: return $datatable;
5909: }
5910:
5911: sub get_loadbalancers_config {
5912: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
5913: return unless ((ref($servers) eq 'HASH') &&
5914: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5915: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
5916: (ref($currcookies) eq 'HASH'));
5917: if (keys(%{$existing}) > 0) {
5918: my $oldlonhost;
5919: foreach my $key (sort(keys(%{$existing}))) {
5920: if ($key eq 'lonhost') {
5921: $oldlonhost = $existing->{'lonhost'};
5922: $currbalancer->{$oldlonhost} = 1;
5923: } elsif ($key eq 'targets') {
5924: if ($oldlonhost) {
5925: $currtargets->{$oldlonhost} = $existing->{'targets'};
5926: }
5927: } elsif ($key eq 'rules') {
5928: if ($oldlonhost) {
5929: $currrules->{$oldlonhost} = $existing->{'rules'};
5930: }
5931: } elsif (ref($existing->{$key}) eq 'HASH') {
5932: $currbalancer->{$key} = 1;
5933: $currtargets->{$key} = $existing->{$key}{'targets'};
5934: $currrules->{$key} = $existing->{$key}{'rules'};
5935: if ($existing->{$key}{'cookie'}) {
5936: $currcookies->{$key} = 1;
5937: }
5938: }
5939: }
5940: } else {
5941: my ($balancerref,$targetsref) =
5942: &Apache::lonnet::get_lonbalancer_config($servers);
5943: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5944: foreach my $server (sort(keys(%{$balancerref}))) {
5945: $currbalancer->{$server} = 1;
5946: $currtargets->{$server} = $targetsref->{$server};
5947: }
5948: }
5949: }
5950: return;
5951: }
5952:
5953: sub loadbalancing_rules {
5954: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
5955: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5956: $css_class,$balnum,$islast) = @_;
5957: my $output;
5958: my $num = 0;
5959: my ($alltypes,$othertypes,$titles) =
5960: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5961: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5962: foreach my $type (@{$alltypes}) {
5963: $num ++;
5964: my $current;
5965: if (ref($currrules) eq 'HASH') {
5966: $current = $currrules->{$type};
5967: }
5968: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
5969: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
5970: $current = '';
5971: }
5972: }
5973: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
5974: $servers,$currbalancer,$lonhost,$dom,
5975: $targets_div_style,$homedom_div_style,
5976: $css_class,$balnum,$num,$islast);
5977: }
5978: }
5979: return $output;
5980: }
5981:
5982: sub loadbalancing_titles {
5983: my ($dom,$intdom,$usertypes,$types) = @_;
5984: my %othertypes = (
5985: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5986: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5987: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5988: '_LC_external' => &mt('Users not from [_1]',$intdom),
5989: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5990: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
5991: );
5992: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
5993: my @available;
5994: if (ref($types) eq 'ARRAY') {
5995: @available = @{$types};
5996: }
5997: unless (grep(/^default$/,@available)) {
5998: push(@available,'default');
5999: }
6000: unshift(@alltypes,@available);
6001: my %titles;
6002: foreach my $type (@alltypes) {
6003: if ($type =~ /^_LC_/) {
6004: $titles{$type} = $othertypes{$type};
6005: } elsif ($type eq 'default') {
6006: $titles{$type} = &mt('All users from [_1]',$dom);
6007: if (ref($types) eq 'ARRAY') {
6008: if (@{$types} > 0) {
6009: $titles{$type} = &mt('Other users from [_1]',$dom);
6010: }
6011: }
6012: } elsif (ref($usertypes) eq 'HASH') {
6013: $titles{$type} = $usertypes->{$type};
6014: }
6015: }
6016: return (\@alltypes,\%othertypes,\%titles);
6017: }
6018:
6019: sub loadbalance_rule_row {
6020: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6021: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
6022: my @rulenames;
6023: my %ruletitles = &offloadtype_text();
6024: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
6025: @rulenames = ('balancer','offloadedto','specific');
6026: } else {
6027: @rulenames = ('default','homeserver');
6028: if ($type eq '_LC_external') {
6029: push(@rulenames,'externalbalancer');
6030: } else {
6031: push(@rulenames,'specific');
6032: }
6033: push(@rulenames,'none');
6034: }
6035: my $style = $targets_div_style;
6036: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
6037: $style = $homedom_div_style;
6038: }
6039: my $space;
6040: if ($islast && $num == 1) {
6041: $space = '<div display="inline-block"> </div>';
6042: }
6043: my $output =
6044: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
6045: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6046: '<td valaign="top">'.$space.
6047: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
6048: for (my $i=0; $i<@rulenames; $i++) {
6049: my $rule = $rulenames[$i];
6050: my ($checked,$extra);
6051: if ($rulenames[$i] eq 'default') {
6052: $rule = '';
6053: }
6054: if ($rulenames[$i] eq 'specific') {
6055: if (ref($servers) eq 'HASH') {
6056: my $default;
6057: if (($current ne '') && (exists($servers->{$current}))) {
6058: $checked = ' checked="checked"';
6059: }
6060: unless ($checked) {
6061: $default = ' selected="selected"';
6062: }
6063: $extra =
6064: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6065: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6066: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6067: '<option value=""'.$default.'></option>'."\n";
6068: foreach my $server (sort(keys(%{$servers}))) {
6069: if (ref($currbalancer) eq 'HASH') {
6070: next if (exists($currbalancer->{$server}));
6071: }
6072: my $selected;
6073: if ($server eq $current) {
6074: $selected = ' selected="selected"';
6075: }
6076: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
6077: }
6078: $extra .= '</select>';
6079: }
6080: } elsif ($rule eq $current) {
6081: $checked = ' checked="checked"';
6082: }
6083: $output .= '<span class="LC_nobreak"><label>'.
6084: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6085: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6086: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
6087: ')"'.$checked.' /> ';
6088: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6089: $output .= $ruletitles{'particular'};
6090: } else {
6091: $output .= $ruletitles{$rulenames[$i]};
6092: }
6093: $output .= '</label>'.$extra.'</span><br />'."\n";
6094: }
6095: $output .= '</div></td></tr>'."\n";
6096: return $output;
6097: }
6098:
6099: sub offloadtype_text {
6100: my %ruletitles = &Apache::lonlocal::texthash (
6101: 'default' => 'Offloads to default destinations',
6102: 'homeserver' => "Offloads to user's home server",
6103: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6104: 'specific' => 'Offloads to specific server',
6105: 'none' => 'No offload',
6106: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6107: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
6108: 'particular' => 'Session hosted (after re-auth) on server:',
6109: );
6110: return %ruletitles;
6111: }
6112:
6113: sub sparestype_titles {
6114: my %typestitles = &Apache::lonlocal::texthash (
6115: 'primary' => 'primary',
6116: 'default' => 'default',
6117: );
6118: return %typestitles;
6119: }
6120:
6121: sub contact_titles {
6122: my %titles = &Apache::lonlocal::texthash (
6123: 'supportemail' => 'Support E-mail address',
6124: 'adminemail' => 'Default Server Admin E-mail address',
6125: 'errormail' => 'Error reports to be e-mailed to',
6126: 'packagesmail' => 'Package update alerts to be e-mailed to',
6127: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6128: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
6129: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6130: 'requestsmail' => 'E-mail from course requests requiring approval',
6131: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
6132: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
6133: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
6134: 'errorthreshold' => 'Error/warning threshold for status e-mail',
6135: 'errorsysmail' => 'Error threshold for e-mail to core group',
6136: 'errorweights' => 'Weights used to compute error count',
6137: 'errorexcluded' => 'Servers with unsent updates excluded from count',
6138: );
6139: my %short_titles = &Apache::lonlocal::texthash (
6140: adminemail => 'Admin E-mail address',
6141: supportemail => 'Support E-mail',
6142: );
6143: return (\%titles,\%short_titles);
6144: }
6145:
6146: sub helpform_fields {
6147: my %titles = &Apache::lonlocal::texthash (
6148: 'username' => 'Name',
6149: 'user' => 'Username/domain',
6150: 'phone' => 'Phone',
6151: 'cc' => 'Cc e-mail',
6152: 'course' => 'Course Details',
6153: 'section' => 'Sections',
6154: 'screenshot' => 'File upload',
6155: );
6156: my @fields = ('username','phone','user','course','section','cc','screenshot');
6157: my %possoptions = (
6158: username => ['yes','no','req'],
6159: phone => ['yes','no','req'],
6160: user => ['yes','no'],
6161: cc => ['yes','no'],
6162: course => ['yes','no'],
6163: section => ['yes','no'],
6164: screenshot => ['yes','no'],
6165: );
6166: my %fieldoptions = &Apache::lonlocal::texthash (
6167: 'yes' => 'Optional',
6168: 'req' => 'Required',
6169: 'no' => "Not shown",
6170: );
6171: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6172: }
6173:
6174: sub tool_titles {
6175: my %titles = &Apache::lonlocal::texthash (
6176: aboutme => 'Personal web page',
6177: blog => 'Blog',
6178: webdav => 'WebDAV',
6179: portfolio => 'Portfolio',
6180: official => 'Official courses (with institutional codes)',
6181: unofficial => 'Unofficial courses',
6182: community => 'Communities',
6183: textbook => 'Textbook courses',
6184: );
6185: return %titles;
6186: }
6187:
6188: sub courserequest_titles {
6189: my %titles = &Apache::lonlocal::texthash (
6190: official => 'Official',
6191: unofficial => 'Unofficial',
6192: community => 'Communities',
6193: textbook => 'Textbook',
6194: norequest => 'Not allowed',
6195: approval => 'Approval by Dom. Coord.',
6196: validate => 'With validation',
6197: autolimit => 'Numerical limit',
6198: unlimited => '(blank for unlimited)',
6199: );
6200: return %titles;
6201: }
6202:
6203: sub authorrequest_titles {
6204: my %titles = &Apache::lonlocal::texthash (
6205: norequest => 'Not allowed',
6206: approval => 'Approval by Dom. Coord.',
6207: automatic => 'Automatic approval',
6208: );
6209: return %titles;
6210: }
6211:
6212: sub courserequest_conditions {
6213: my %conditions = &Apache::lonlocal::texthash (
6214: approval => '(Processing of request subject to approval by Domain Coordinator).',
6215: validate => '(Processing of request subject to institutional validation).',
6216: );
6217: return %conditions;
6218: }
6219:
6220:
6221: sub print_usercreation {
6222: my ($position,$dom,$settings,$rowtotal) = @_;
6223: my $numinrow = 4;
6224: my $datatable;
6225: if ($position eq 'top') {
6226: $$rowtotal ++;
6227: my $rowcount = 0;
6228: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
6229: if (ref($rules) eq 'HASH') {
6230: if (keys(%{$rules}) > 0) {
6231: $datatable .= &user_formats_row('username',$settings,$rules,
6232: $ruleorder,$numinrow,$rowcount);
6233: $$rowtotal ++;
6234: $rowcount ++;
6235: }
6236: }
6237: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6238: if (ref($idrules) eq 'HASH') {
6239: if (keys(%{$idrules}) > 0) {
6240: $datatable .= &user_formats_row('id',$settings,$idrules,
6241: $idruleorder,$numinrow,$rowcount);
6242: $$rowtotal ++;
6243: $rowcount ++;
6244: }
6245: }
6246: if ($rowcount == 0) {
6247: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6248: $$rowtotal ++;
6249: $rowcount ++;
6250: }
6251: } elsif ($position eq 'middle') {
6252: my @creators = ('author','course','requestcrs');
6253: my ($rules,$ruleorder) =
6254: &Apache::lonnet::inst_userrules($dom,'username');
6255: my %lt = &usercreation_types();
6256: my %checked;
6257: if (ref($settings) eq 'HASH') {
6258: if (ref($settings->{'cancreate'}) eq 'HASH') {
6259: foreach my $item (@creators) {
6260: $checked{$item} = $settings->{'cancreate'}{$item};
6261: }
6262: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6263: foreach my $item (@creators) {
6264: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6265: $checked{$item} = 'none';
6266: }
6267: }
6268: }
6269: }
6270: my $rownum = 0;
6271: foreach my $item (@creators) {
6272: $rownum ++;
6273: if ($checked{$item} eq '') {
6274: $checked{$item} = 'any';
6275: }
6276: my $css_class;
6277: if ($rownum%2) {
6278: $css_class = '';
6279: } else {
6280: $css_class = ' class="LC_odd_row" ';
6281: }
6282: $datatable .= '<tr'.$css_class.'>'.
6283: '<td><span class="LC_nobreak">'.$lt{$item}.
6284: '</span></td><td align="right">';
6285: my @options = ('any');
6286: if (ref($rules) eq 'HASH') {
6287: if (keys(%{$rules}) > 0) {
6288: push(@options,('official','unofficial'));
6289: }
6290: }
6291: push(@options,'none');
6292: foreach my $option (@options) {
6293: my $type = 'radio';
6294: my $check = ' ';
6295: if ($checked{$item} eq $option) {
6296: $check = ' checked="checked" ';
6297: }
6298: $datatable .= '<span class="LC_nobreak"><label>'.
6299: '<input type="'.$type.'" name="can_createuser_'.
6300: $item.'" value="'.$option.'"'.$check.'/> '.
6301: $lt{$option}.'</label> </span>';
6302: }
6303: $datatable .= '</td></tr>';
6304: }
6305: } else {
6306: my @contexts = ('author','course','domain');
6307: my @authtypes = ('int','krb4','krb5','loc');
6308: my %checked;
6309: if (ref($settings) eq 'HASH') {
6310: if (ref($settings->{'authtypes'}) eq 'HASH') {
6311: foreach my $item (@contexts) {
6312: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6313: foreach my $auth (@authtypes) {
6314: if ($settings->{'authtypes'}{$item}{$auth}) {
6315: $checked{$item}{$auth} = ' checked="checked" ';
6316: }
6317: }
6318: }
6319: }
6320: }
6321: } else {
6322: foreach my $item (@contexts) {
6323: foreach my $auth (@authtypes) {
6324: $checked{$item}{$auth} = ' checked="checked" ';
6325: }
6326: }
6327: }
6328: my %title = &context_names();
6329: my %authname = &authtype_names();
6330: my $rownum = 0;
6331: my $css_class;
6332: foreach my $item (@contexts) {
6333: if ($rownum%2) {
6334: $css_class = '';
6335: } else {
6336: $css_class = ' class="LC_odd_row" ';
6337: }
6338: $datatable .= '<tr'.$css_class.'>'.
6339: '<td>'.$title{$item}.
6340: '</td><td class="LC_left_item">'.
6341: '<span class="LC_nobreak">';
6342: foreach my $auth (@authtypes) {
6343: $datatable .= '<label>'.
6344: '<input type="checkbox" name="'.$item.'_auth" '.
6345: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6346: $authname{$auth}.'</label> ';
6347: }
6348: $datatable .= '</span></td></tr>';
6349: $rownum ++;
6350: }
6351: $$rowtotal += $rownum;
6352: }
6353: return $datatable;
6354: }
6355:
6356: sub print_selfcreation {
6357: my ($position,$dom,$settings,$rowtotal) = @_;
6358: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6359: $emaildomain,$datatable);
6360: if (ref($settings) eq 'HASH') {
6361: if (ref($settings->{'cancreate'}) eq 'HASH') {
6362: $createsettings = $settings->{'cancreate'};
6363: if (ref($createsettings) eq 'HASH') {
6364: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6365: @selfcreate = @{$createsettings->{'selfcreate'}};
6366: } elsif ($createsettings->{'selfcreate'} ne '') {
6367: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6368: @selfcreate = ('email','login','sso');
6369: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6370: @selfcreate = ($createsettings->{'selfcreate'});
6371: }
6372: }
6373: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6374: $processing = $createsettings->{'selfcreateprocessing'};
6375: }
6376: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6377: $emailoptions = $createsettings->{'emailoptions'};
6378: }
6379: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6380: $emailverified = $createsettings->{'emailverified'};
6381: }
6382: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6383: $emaildomain = $createsettings->{'emaildomain'};
6384: }
6385: }
6386: }
6387: }
6388: my %radiohash;
6389: my $numinrow = 4;
6390: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
6391: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6392: if ($position eq 'top') {
6393: my %choices = &Apache::lonlocal::texthash (
6394: cancreate_login => 'Institutional Login',
6395: cancreate_sso => 'Institutional Single Sign On',
6396: );
6397: my @toggles = sort(keys(%choices));
6398: my %defaultchecked = (
6399: 'cancreate_login' => 'off',
6400: 'cancreate_sso' => 'off',
6401: );
6402: my ($onclick,$itemcount);
6403: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6404: \%choices,$itemcount,$onclick);
6405: $$rowtotal += $itemcount;
6406:
6407: if (ref($usertypes) eq 'HASH') {
6408: if (keys(%{$usertypes}) > 0) {
6409: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6410: $dom,$numinrow,$othertitle,
6411: 'statustocreate',$rowtotal);
6412: $$rowtotal ++;
6413: }
6414: }
6415: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6416: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6417: $fieldtitles{'inststatus'} = &mt('Institutional status');
6418: my $rem;
6419: my $numperrow = 2;
6420: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6421: $datatable .= '<tr'.$css_class.'>'.
6422: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
6423: '<td class="LC_left_item">'."\n".
6424: '<table>'."\n";
6425: for (my $i=0; $i<@fields; $i++) {
6426: $rem = $i%($numperrow);
6427: if ($rem == 0) {
6428: if ($i > 0) {
6429: $datatable .= '</tr>';
6430: }
6431: $datatable .= '<tr>';
6432: }
6433: my $currval;
6434: if (ref($createsettings) eq 'HASH') {
6435: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6436: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6437: }
6438: }
6439: $datatable .= '<td class="LC_left_item">'.
6440: '<span class="LC_nobreak">'.
6441: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6442: 'value="'.$currval.'" size="10" /> '.
6443: $fieldtitles{$fields[$i]}.'</span></td>';
6444: }
6445: my $colsleft = $numperrow - $rem;
6446: if ($colsleft > 1 ) {
6447: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6448: ' </td>';
6449: } elsif ($colsleft == 1) {
6450: $datatable .= '<td class="LC_left_item"> </td>';
6451: }
6452: $datatable .= '</tr></table></td></tr>';
6453: $$rowtotal ++;
6454: } elsif ($position eq 'middle') {
6455: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
6456: my @posstypes;
6457: if (ref($types) eq 'ARRAY') {
6458: @posstypes = @{$types};
6459: }
6460: unless (grep(/^default$/,@posstypes)) {
6461: push(@posstypes,'default');
6462: }
6463: my %usertypeshash;
6464: if (ref($usertypes) eq 'HASH') {
6465: %usertypeshash = %{$usertypes};
6466: }
6467: $usertypeshash{'default'} = $othertitle;
6468: foreach my $status (@posstypes) {
6469: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6470: $numinrow,$$rowtotal,\%usertypeshash);
6471: $$rowtotal ++;
6472: }
6473: } else {
6474: my %choices = &Apache::lonlocal::texthash (
6475: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
6476: );
6477: my @toggles = sort(keys(%choices));
6478: my %defaultchecked = (
6479: 'cancreate_email' => 'off',
6480: );
6481: my $customclass = 'LC_selfcreate_email';
6482: my $classprefix = 'LC_canmodify_emailusername_';
6483: my $optionsprefix = 'LC_options_emailusername_';
6484: my $display = 'none';
6485: my $rowstyle = 'display:none';
6486: if (grep(/^\Qemail\E$/,@selfcreate)) {
6487: $display = 'block';
6488: $rowstyle = 'display:table-row';
6489: }
6490: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6491: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6492: \%choices,$$rowtotal,$onclick);
6493: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6494: $rowstyle);
6495: $$rowtotal ++;
6496: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6497: $rowstyle);
6498: $$rowtotal ++;
6499: my (@ordered,@posstypes,%usertypeshash);
6500: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6501: my ($emailrules,$emailruleorder) =
6502: &Apache::lonnet::inst_userrules($dom,'email');
6503: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6504: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6505: if (ref($types) eq 'ARRAY') {
6506: @posstypes = @{$types};
6507: }
6508: if (@posstypes) {
6509: unless (grep(/^default$/,@posstypes)) {
6510: push(@posstypes,'default');
6511: }
6512: if (ref($usertypes) eq 'HASH') {
6513: %usertypeshash = %{$usertypes};
6514: }
6515: my $currassign;
6516: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6517: $currassign = {
6518: selfassign => $domdefaults{'inststatusguest'},
6519: };
6520: @ordered = @{$domdefaults{'inststatusguest'}};
6521: } else {
6522: $currassign = { selfassign => [] };
6523: }
6524: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6525: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6526: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6527: $numinrow,$othertitle,'selfassign',
6528: $rowtotal,$onclicktypes,$customclass,
6529: $rowstyle);
6530: $$rowtotal ++;
6531: $usertypeshash{'default'} = $othertitle;
6532: foreach my $status (@posstypes) {
6533: my $css_class;
6534: if ($$rowtotal%2) {
6535: $css_class = 'LC_odd_row ';
6536: }
6537: $css_class .= $customclass;
6538: my $rowid = $optionsprefix.$status;
6539: my $hidden = 1;
6540: my $currstyle = 'display:none';
6541: if (grep(/^\Q$status\E$/,@ordered)) {
6542: $currstyle = $rowstyle;
6543: $hidden = 0;
6544: }
6545: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6546: $emailrules,$emailruleorder,$settings,$status,$rowid,
6547: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6548: unless ($hidden) {
6549: $$rowtotal ++;
6550: }
6551: }
6552: } else {
6553: my $css_class;
6554: if ($$rowtotal%2) {
6555: $css_class = 'LC_odd_row ';
6556: }
6557: $css_class .= $customclass;
6558: $usertypeshash{'default'} = $othertitle;
6559: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6560: $emailrules,$emailruleorder,$settings,'default','',
6561: $othertitle,$css_class,$rowstyle,$intdom);
6562: $$rowtotal ++;
6563: }
6564: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
6565: $numinrow = 1;
6566: if (@posstypes) {
6567: foreach my $status (@posstypes) {
6568: my $rowid = $classprefix.$status;
6569: my $datarowstyle = 'display:none';
6570: if (grep(/^\Q$status\E$/,@ordered)) {
6571: $datarowstyle = $rowstyle;
6572: }
6573: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6574: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6575: $infotitles,$rowid,$customclass,$datarowstyle);
6576: unless ($datarowstyle eq 'display:none') {
6577: $$rowtotal ++;
6578: }
6579: }
6580: } else {
6581: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6582: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6583: $infotitles,'',$customclass,$rowstyle);
6584: }
6585: }
6586: return $datatable;
6587: }
6588:
6589: sub selfcreate_javascript {
6590: return <<"ENDSCRIPT";
6591:
6592: <script type="text/javascript">
6593: // <![CDATA[
6594:
6595: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6596: var x = document.getElementsByClassName(target);
6597: var insttypes = 0;
6598: var insttypeRegExp = new RegExp(prefix);
6599: if ((x.length != undefined) && (x.length > 0)) {
6600: if (form.elements[radio].length != undefined) {
6601: for (var i=0; i<form.elements[radio].length; i++) {
6602: if (form.elements[radio][i].checked) {
6603: if (form.elements[radio][i].value == 1) {
6604: for (var j=0; j<x.length; j++) {
6605: if (x[j].id == 'undefined') {
6606: x[j].style.display = 'table-row';
6607: } else if (insttypeRegExp.test(x[j].id)) {
6608: insttypes ++;
6609: } else {
6610: x[j].style.display = 'table-row';
6611: }
6612: }
6613: } else {
6614: for (var j=0; j<x.length; j++) {
6615: x[j].style.display = 'none';
6616: }
6617: }
6618: break;
6619: }
6620: }
6621: if (insttypes > 0) {
6622: toggleDataRow(form,checkbox,target,altprefix);
6623: toggleDataRow(form,checkbox,target,prefix,1);
6624: }
6625: }
6626: }
6627: return;
6628: }
6629:
6630: function toggleDataRow(form,checkbox,target,prefix,docount) {
6631: if (form.elements[checkbox].length != undefined) {
6632: var count = 0;
6633: if (docount) {
6634: for (var i=0; i<form.elements[checkbox].length; i++) {
6635: if (form.elements[checkbox][i].checked) {
6636: count ++;
6637: }
6638: }
6639: }
6640: for (var i=0; i<form.elements[checkbox].length; i++) {
6641: var type = form.elements[checkbox][i].value;
6642: if (document.getElementById(prefix+type)) {
6643: if (form.elements[checkbox][i].checked) {
6644: document.getElementById(prefix+type).style.display = 'table-row';
6645: if (count % 2 == 1) {
6646: document.getElementById(prefix+type).className = target+' LC_odd_row';
6647: } else {
6648: document.getElementById(prefix+type).className = target;
6649: }
6650: count ++;
6651: } else {
6652: document.getElementById(prefix+type).style.display = 'none';
6653: }
6654: }
6655: }
6656: }
6657: return;
6658: }
6659:
6660: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6661: var caller = radio+'_'+status;
6662: if (form.elements[caller].length != undefined) {
6663: for (var i=0; i<form.elements[caller].length; i++) {
6664: if (form.elements[caller][i].checked) {
6665: if (document.getElementById(altprefix+'_inst_'+status)) {
6666: var curr = form.elements[caller][i].value;
6667: if (prefix) {
6668: document.getElementById(prefix+'_'+status).style.display = 'none';
6669: }
6670: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6671: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6672: if (curr == 'custom') {
6673: if (prefix) {
6674: document.getElementById(prefix+'_'+status).style.display = 'inline';
6675: }
6676: } else if (curr == 'inst') {
6677: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6678: } else if (curr == 'noninst') {
6679: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
6680: }
6681: break;
6682: }
6683: }
6684: }
6685: }
6686: }
6687:
6688: // ]]>
6689: </script>
6690:
6691: ENDSCRIPT
6692: }
6693:
6694: sub noninst_users {
6695: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6696: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6697: my $class = 'LC_left_item';
6698: if ($css_class) {
6699: $css_class = ' class="'.$css_class.'"';
6700: }
6701: if ($rowid) {
6702: $rowid = ' id="'.$rowid.'"';
6703: }
6704: if ($rowstyle) {
6705: $rowstyle = ' style="'.$rowstyle.'"';
6706: }
6707: my ($output,$description);
6708: if ($type eq 'default') {
6709: $description = &mt('Requests for: [_1]',$typetitle);
6710: } else {
6711: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6712: }
6713: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6714: "<td>$description</td>\n".
6715: '<td class="'.$class.'" colspan="2">'.
6716: '<table><tr>';
6717: my %headers = &Apache::lonlocal::texthash(
6718: approve => 'Processing',
6719: email => 'E-mail',
6720: username => 'Username',
6721: );
6722: foreach my $item ('approve','email','username') {
6723: $output .= '<th>'.$headers{$item}.'</th>';
6724: }
6725: $output .= '</tr><tr>';
6726: foreach my $item ('approve','email','username') {
6727: $output .= '<td valign="top">';
6728: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6729: if ($item eq 'approve') {
6730: %choices = &Apache::lonlocal::texthash (
6731: automatic => 'Automatically approved',
6732: approval => 'Queued for approval',
6733: );
6734: @options = ('automatic','approval');
6735: $hashref = $processing;
6736: $defoption = 'automatic';
6737: $name = 'cancreate_emailprocess_'.$type;
6738: } elsif ($item eq 'email') {
6739: %choices = &Apache::lonlocal::texthash (
6740: any => 'Any e-mail',
6741: inst => 'Institutional only',
6742: noninst => 'Non-institutional only',
6743: custom => 'Custom restrictions',
6744: );
6745: @options = ('any','inst','noninst');
6746: my $showcustom;
6747: if (ref($emailrules) eq 'HASH') {
6748: if (keys(%{$emailrules}) > 0) {
6749: push(@options,'custom');
6750: $showcustom = 'cancreate_emailrule';
6751: if (ref($settings) eq 'HASH') {
6752: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6753: foreach my $rule (@{$settings->{'email_rule'}}) {
6754: if (exists($emailrules->{$rule})) {
6755: $hascustom ++;
6756: }
6757: }
6758: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6759: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6760: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6761: if (exists($emailrules->{$rule})) {
6762: $hascustom ++;
6763: }
6764: }
6765: }
6766: }
6767: }
6768: }
6769: }
6770: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6771: "'cancreate_emaildomain','$type'".');"';
6772: $hashref = $emailoptions;
6773: $defoption = 'any';
6774: $name = 'cancreate_emailoptions_'.$type;
6775: } elsif ($item eq 'username') {
6776: %choices = &Apache::lonlocal::texthash (
6777: all => 'Same as e-mail',
6778: first => 'Omit @domain',
6779: free => 'Free to choose',
6780: );
6781: @options = ('all','first','free');
6782: $hashref = $emailverified;
6783: $defoption = 'all';
6784: $name = 'cancreate_usernameoptions_'.$type;
6785: }
6786: foreach my $option (@options) {
6787: my $checked;
6788: if (ref($hashref) eq 'HASH') {
6789: if ($type eq '') {
6790: if (!exists($hashref->{'default'})) {
6791: if ($option eq $defoption) {
6792: $checked = ' checked="checked"';
6793: }
6794: } else {
6795: if ($hashref->{'default'} eq $option) {
6796: $checked = ' checked="checked"';
6797: }
6798: }
6799: } else {
6800: if (!exists($hashref->{$type})) {
6801: if ($option eq $defoption) {
6802: $checked = ' checked="checked"';
6803: }
6804: } else {
6805: if ($hashref->{$type} eq $option) {
6806: $checked = ' checked="checked"';
6807: }
6808: }
6809: }
6810: } elsif (($item eq 'email') && ($hascustom)) {
6811: if ($option eq 'custom') {
6812: $checked = ' checked="checked"';
6813: }
6814: } elsif ($option eq $defoption) {
6815: $checked = ' checked="checked"';
6816: }
6817: $output .= '<span class="LC_nobreak"><label>'.
6818: '<input type="radio" name="'.$name.'"'.
6819: $checked.' value="'.$option.'"'.$onclick.' />'.
6820: $choices{$option}.'</label></span><br />';
6821: if ($item eq 'email') {
6822: if ($option eq 'custom') {
6823: my $id = 'cancreate_emailrule_'.$type;
6824: my $display = 'none';
6825: if ($checked) {
6826: $display = 'inline';
6827: }
6828: my $numinrow = 2;
6829: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6830: '<legend>'.&mt('Disallow').'</legend><table>'.
6831: &user_formats_row('email',$settings,$emailrules,
6832: $emailruleorder,$numinrow,'',$type);
6833: '</table></fieldset>';
6834: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6835: my %text = &Apache::lonlocal::texthash (
6836: inst => 'must end:',
6837: noninst => 'cannot end:',
6838: );
6839: my $value;
6840: if (ref($emaildomain) eq 'HASH') {
6841: if (ref($emaildomain->{$type}) eq 'HASH') {
6842: $value = $emaildomain->{$type}->{$option};
6843: }
6844: }
6845: if ($value eq '') {
6846: $value = '@'.$intdom;
6847: }
6848: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6849: my $display = 'none';
6850: if ($checked) {
6851: $display = 'inline';
6852: }
6853: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6854: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6855: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6856: '</div>';
6857: }
6858: }
6859: }
6860: $output .= '</td>'."\n";
6861: }
6862: $output .= "</tr></table></td></tr>\n";
6863: return $output;
6864: }
6865:
6866: sub captcha_choice {
6867: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
6868: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6869: $vertext,$currver);
6870: my %lt = &captcha_phrases();
6871: $keyentry = 'hidden';
6872: my $colspan=2;
6873: if ($context eq 'cancreate') {
6874: $rowname = &mt('CAPTCHA validation');
6875: } elsif ($context eq 'login') {
6876: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
6877: } elsif ($context eq 'passwords') {
6878: $rowname = &mt('"Forgot Password" CAPTCHA validation');
6879: $colspan=1;
6880: }
6881: if (ref($settings) eq 'HASH') {
6882: if ($settings->{'captcha'}) {
6883: $checked{$settings->{'captcha'}} = ' checked="checked"';
6884: } else {
6885: $checked{'original'} = ' checked="checked"';
6886: }
6887: if ($settings->{'captcha'} eq 'recaptcha') {
6888: $pubtext = $lt{'pub'};
6889: $privtext = $lt{'priv'};
6890: $keyentry = 'text';
6891: $vertext = $lt{'ver'};
6892: $currver = $settings->{'recaptchaversion'};
6893: if ($currver ne '2') {
6894: $currver = 1;
6895: }
6896: }
6897: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6898: $currpub = $settings->{'recaptchakeys'}{'public'};
6899: $currpriv = $settings->{'recaptchakeys'}{'private'};
6900: }
6901: } else {
6902: $checked{'original'} = ' checked="checked"';
6903: }
6904: my $css_class;
6905: if ($itemcount%2) {
6906: $css_class = 'LC_odd_row';
6907: }
6908: if ($customcss) {
6909: $css_class .= " $customcss";
6910: }
6911: $css_class =~ s/^\s+//;
6912: if ($css_class) {
6913: $css_class = ' class="'.$css_class.'"';
6914: }
6915: if ($rowstyle) {
6916: $css_class .= ' style="'.$rowstyle.'"';
6917: }
6918: my $output = '<tr'.$css_class.'>'.
6919: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
6920: '<table><tr><td>'."\n";
6921: foreach my $option ('original','recaptcha','notused') {
6922: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6923: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6924: $lt{$option}.'</label></span>';
6925: unless ($option eq 'notused') {
6926: $output .= (' 'x2)."\n";
6927: }
6928: }
6929: #
6930: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6931: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6932: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6933: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6934: #
6935: $output .= '</td></tr>'."\n".
6936: '<tr><td class="LC_zero_height">'."\n".
6937: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6938: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6939: $currpub.'" size="40" /></span><br />'."\n".
6940: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6941: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
6942: $currpriv.'" size="40" /></span><br />'.
6943: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6944: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6945: $currver.'" size="3" /></span><br />'.
6946: '</td></tr></table>'."\n".
6947: '</td></tr>';
6948: return $output;
6949: }
6950:
6951: sub user_formats_row {
6952: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
6953: my $output;
6954: my %text = (
6955: 'username' => 'new usernames',
6956: 'id' => 'IDs',
6957: );
6958: unless ($type eq 'email') {
6959: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6960: $output = '<tr '.$css_class.'>'.
6961: '<td><span class="LC_nobreak">'.
6962: &mt("Format rules to check for $text{$type}: ").
6963: '</td><td class="LC_left_item" colspan="2"><table>';
6964: }
6965: my $rem;
6966: if (ref($ruleorder) eq 'ARRAY') {
6967: for (my $i=0; $i<@{$ruleorder}; $i++) {
6968: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6969: my $rem = $i%($numinrow);
6970: if ($rem == 0) {
6971: if ($i > 0) {
6972: $output .= '</tr>';
6973: }
6974: $output .= '<tr>';
6975: }
6976: my $check = ' ';
6977: if (ref($settings) eq 'HASH') {
6978: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6979: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6980: $check = ' checked="checked" ';
6981: }
6982: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6983: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6984: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6985: $check = ' checked="checked" ';
6986: }
6987: }
6988: }
6989: }
6990: my $name = $type.'_rule';
6991: if ($type eq 'email') {
6992: $name .= '_'.$status;
6993: }
6994: $output .= '<td class="LC_left_item">'.
6995: '<span class="LC_nobreak"><label>'.
6996: '<input type="checkbox" name="'.$name.'" '.
6997: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6998: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6999: }
7000: }
7001: $rem = @{$ruleorder}%($numinrow);
7002: }
7003: my $colsleft;
7004: if ($rem) {
7005: $colsleft = $numinrow - $rem;
7006: }
7007: if ($colsleft > 1 ) {
7008: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7009: ' </td>';
7010: } elsif ($colsleft == 1) {
7011: $output .= '<td class="LC_left_item"> </td>';
7012: }
7013: $output .= '</tr></table>';
7014: unless ($type eq 'email') {
7015: $output .= '</td></tr>';
7016: }
7017: return $output;
7018: }
7019:
7020: sub usercreation_types {
7021: my %lt = &Apache::lonlocal::texthash (
7022: author => 'When adding a co-author',
7023: course => 'When adding a user to a course',
7024: requestcrs => 'When requesting a course',
7025: any => 'Any',
7026: official => 'Institutional only ',
7027: unofficial => 'Non-institutional only',
7028: none => 'None',
7029: );
7030: return %lt;
7031: }
7032:
7033: sub selfcreation_types {
7034: my %lt = &Apache::lonlocal::texthash (
7035: selfcreate => 'User creates own account',
7036: any => 'Any',
7037: official => 'Institutional only ',
7038: unofficial => 'Non-institutional only',
7039: email => 'E-mail address',
7040: login => 'Institutional Login',
7041: sso => 'SSO',
7042: );
7043: }
7044:
7045: sub authtype_names {
7046: my %lt = &Apache::lonlocal::texthash(
7047: int => 'Internal',
7048: krb4 => 'Kerberos 4',
7049: krb5 => 'Kerberos 5',
7050: loc => 'Local',
7051: );
7052: return %lt;
7053: }
7054:
7055: sub context_names {
7056: my %context_title = &Apache::lonlocal::texthash(
7057: author => 'Creating users when an Author',
7058: course => 'Creating users when in a course',
7059: domain => 'Creating users when a Domain Coordinator',
7060: );
7061: return %context_title;
7062: }
7063:
7064: sub print_usermodification {
7065: my ($position,$dom,$settings,$rowtotal) = @_;
7066: my $numinrow = 4;
7067: my ($context,$datatable,$rowcount);
7068: if ($position eq 'top') {
7069: $rowcount = 0;
7070: $context = 'author';
7071: foreach my $role ('ca','aa') {
7072: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7073: $numinrow,$rowcount);
7074: $$rowtotal ++;
7075: $rowcount ++;
7076: }
7077: } elsif ($position eq 'bottom') {
7078: $context = 'course';
7079: $rowcount = 0;
7080: foreach my $role ('st','ep','ta','in','cr') {
7081: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7082: $numinrow,$rowcount);
7083: $$rowtotal ++;
7084: $rowcount ++;
7085: }
7086: }
7087: return $datatable;
7088: }
7089:
7090: sub print_defaults {
7091: my ($position,$dom,$settings,$rowtotal) = @_;
7092: my $rownum = 0;
7093: my ($datatable,$css_class,$titles);
7094: unless ($position eq 'bottom') {
7095: $titles = &defaults_titles($dom);
7096: }
7097: if ($position eq 'top') {
7098: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7099: 'datelocale_def','portal_def');
7100: my %defaults;
7101: if (ref($settings) eq 'HASH') {
7102: %defaults = %{$settings};
7103: } else {
7104: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7105: foreach my $item (@items) {
7106: $defaults{$item} = $domdefaults{$item};
7107: }
7108: }
7109: foreach my $item (@items) {
7110: if ($rownum%2) {
7111: $css_class = '';
7112: } else {
7113: $css_class = ' class="LC_odd_row" ';
7114: }
7115: $datatable .= '<tr'.$css_class.'>'.
7116: '<td><span class="LC_nobreak">'.$titles->{$item}.
7117: '</span></td><td class="LC_right_item" colspan="3">';
7118: if ($item eq 'auth_def') {
7119: my @authtypes = ('internal','krb4','krb5','localauth');
7120: my %shortauth = (
7121: internal => 'int',
7122: krb4 => 'krb4',
7123: krb5 => 'krb5',
7124: localauth => 'loc'
7125: );
7126: my %authnames = &authtype_names();
7127: foreach my $auth (@authtypes) {
7128: my $checked = ' ';
7129: if ($defaults{$item} eq $auth) {
7130: $checked = ' checked="checked" ';
7131: }
7132: $datatable .= '<label><input type="radio" name="'.$item.
7133: '" value="'.$auth.'"'.$checked.'/>'.
7134: $authnames{$shortauth{$auth}}.'</label> ';
7135: }
7136: } elsif ($item eq 'timezone_def') {
7137: my $includeempty = 1;
7138: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7139: } elsif ($item eq 'datelocale_def') {
7140: my $includeempty = 1;
7141: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7142: } elsif ($item eq 'lang_def') {
7143: my $includeempty = 1;
7144: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
7145: } else {
7146: my $size;
7147: if ($item eq 'portal_def') {
7148: $size = ' size="25"';
7149: }
7150: $datatable .= '<input type="text" name="'.$item.'" value="'.
7151: $defaults{$item}.'"'.$size.' />';
7152: }
7153: $datatable .= '</td></tr>';
7154: $rownum ++;
7155: }
7156: } else {
7157: my %defaults;
7158: if (ref($settings) eq 'HASH') {
7159: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7160: my $maxnum = @{$settings->{'inststatusorder'}};
7161: for (my $i=0; $i<$maxnum; $i++) {
7162: $css_class = $rownum%2?' class="LC_odd_row"':'';
7163: my $item = $settings->{'inststatusorder'}->[$i];
7164: my $title = $settings->{'inststatustypes'}->{$item};
7165: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7166: $datatable .= '<tr'.$css_class.'>'.
7167: '<td><span class="LC_nobreak">'.
7168: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7169: for (my $k=0; $k<=$maxnum; $k++) {
7170: my $vpos = $k+1;
7171: my $selstr;
7172: if ($k == $i) {
7173: $selstr = ' selected="selected" ';
7174: }
7175: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7176: }
7177: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7178: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7179: &mt('delete').'</span></td>'.
7180: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
7181: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
7182: '</span></td></tr>';
7183: }
7184: $css_class = $rownum%2?' class="LC_odd_row"':'';
7185: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7186: $datatable .= '<tr '.$css_class.'>'.
7187: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7188: for (my $k=0; $k<=$maxnum; $k++) {
7189: my $vpos = $k+1;
7190: my $selstr;
7191: if ($k == $maxnum) {
7192: $selstr = ' selected="selected" ';
7193: }
7194: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7195: }
7196: $datatable .= '</select> '.&mt('Internal ID:').
7197: '<input type="text" size="10" name="addinststatus" value="" />'.
7198: ' '.&mt('(new)').
7199: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
7200: &mt('Name displayed:').
7201: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7202: '</tr>'."\n";
7203: $rownum ++;
7204: }
7205: }
7206: }
7207: $$rowtotal += $rownum;
7208: return $datatable;
7209: }
7210:
7211: sub get_languages_hash {
7212: my %langchoices;
7213: foreach my $id (&Apache::loncommon::languageids()) {
7214: my $code = &Apache::loncommon::supportedlanguagecode($id);
7215: if ($code ne '') {
7216: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7217: }
7218: }
7219: return %langchoices;
7220: }
7221:
7222: sub defaults_titles {
7223: my ($dom) = @_;
7224: my %titles = &Apache::lonlocal::texthash (
7225: 'auth_def' => 'Default authentication type',
7226: 'auth_arg_def' => 'Default authentication argument',
7227: 'lang_def' => 'Default language',
7228: 'timezone_def' => 'Default timezone',
7229: 'datelocale_def' => 'Default locale for dates',
7230: 'portal_def' => 'Portal/Default URL',
7231: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7232: 'intauth_check' => 'Check bcrypt cost if authenticated',
7233: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
7234: );
7235: if ($dom) {
7236: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7237: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7238: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7239: $protocol = 'http' if ($protocol ne 'https');
7240: if ($uint_dom) {
7241: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7242: $uint_dom);
7243: }
7244: }
7245: return (\%titles);
7246: }
7247:
7248: sub print_scantron {
7249: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
7250: if ($position eq 'top') {
7251: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
7252: } else {
7253: return &print_scantronconfig($dom,$settings,\$rowtotal);
7254: }
7255: }
7256:
7257: sub scantron_javascript {
7258: return <<"ENDSCRIPT";
7259:
7260: <script type="text/javascript">
7261: // <![CDATA[
7262:
7263: function toggleScantron(form) {
7264: var csvfieldset = new Array();
7265: if (document.getElementById('scantroncsv_cols')) {
7266: csvfieldset.push(document.getElementById('scantroncsv_cols'));
7267: }
7268: if (document.getElementById('scantroncsv_options')) {
7269: csvfieldset.push(document.getElementById('scantroncsv_options'));
7270: }
7271: if (csvfieldset.length) {
7272: if (document.getElementById('scantronconfcsv')) {
7273: var scantroncsv = document.getElementById('scantronconfcsv');
7274: if (scantroncsv.checked) {
7275: for (var i=0; i<csvfieldset.length; i++) {
7276: csvfieldset[i].style.display = 'block';
7277: }
7278: } else {
7279: for (var i=0; i<csvfieldset.length; i++) {
7280: csvfieldset[i].style.display = 'none';
7281: }
7282: var csvselects = document.getElementsByClassName('scantronconfig_csv');
7283: if (csvselects.length) {
7284: for (var j=0; j<csvselects.length; j++) {
7285: csvselects[j].selectedIndex = 0;
7286: }
7287: }
7288: }
7289: }
7290: }
7291: return;
7292: }
7293: // ]]>
7294: </script>
7295:
7296: ENDSCRIPT
7297:
7298: }
7299:
7300: sub print_scantronformat {
7301: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7302: my $itemcount = 1;
7303: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7304: %confhash);
7305: my $switchserver = &check_switchserver($dom,$confname);
7306: my %lt = &Apache::lonlocal::texthash (
7307: default => 'Default bubblesheet format file error',
7308: custom => 'Custom bubblesheet format file error',
7309: );
7310: my %scantronfiles = (
7311: default => 'default.tab',
7312: custom => 'custom.tab',
7313: );
7314: foreach my $key (keys(%scantronfiles)) {
7315: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7316: .$scantronfiles{$key};
7317: }
7318: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7319: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7320: if (!$switchserver) {
7321: my $servadm = $r->dir_config('lonAdmEMail');
7322: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7323: if ($configuserok eq 'ok') {
7324: if ($author_ok eq 'ok') {
7325: my %legacyfile = (
7326: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7327: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7328: );
7329: my %md5chk;
7330: foreach my $type (keys(%legacyfile)) {
7331: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7332: chomp($md5chk{$type});
7333: }
7334: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7335: foreach my $type (keys(%legacyfile)) {
7336: ($scantronurls{$type},my $error) =
7337: &legacy_scantronformat($r,$dom,$confname,
7338: $type,$legacyfile{$type},
7339: $scantronurls{$type},
7340: $scantronfiles{$type});
7341: if ($error ne '') {
7342: $error{$type} = $error;
7343: }
7344: }
7345: if (keys(%error) == 0) {
7346: $is_custom = 1;
7347: $confhash{'scantron'}{'scantronformat'} =
7348: $scantronurls{'custom'};
7349: my $putresult =
7350: &Apache::lonnet::put_dom('configuration',
7351: \%confhash,$dom);
7352: if ($putresult ne 'ok') {
7353: $error{'custom'} =
7354: '<span class="LC_error">'.
7355: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7356: }
7357: }
7358: } else {
7359: ($scantronurls{'default'},my $error) =
7360: &legacy_scantronformat($r,$dom,$confname,
7361: 'default',$legacyfile{'default'},
7362: $scantronurls{'default'},
7363: $scantronfiles{'default'});
7364: if ($error eq '') {
7365: $confhash{'scantron'}{'scantronformat'} = '';
7366: my $putresult =
7367: &Apache::lonnet::put_dom('configuration',
7368: \%confhash,$dom);
7369: if ($putresult ne 'ok') {
7370: $error{'default'} =
7371: '<span class="LC_error">'.
7372: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7373: }
7374: } else {
7375: $error{'default'} = $error;
7376: }
7377: }
7378: }
7379: }
7380: } else {
7381: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
7382: }
7383: }
7384: if (ref($settings) eq 'HASH') {
7385: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7386: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7387: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7388: $scantronurl = '';
7389: } else {
7390: $scantronurl = $settings->{'scantronformat'};
7391: }
7392: $is_custom = 1;
7393: } else {
7394: $scantronurl = $scantronurls{'default'};
7395: }
7396: } else {
7397: if ($is_custom) {
7398: $scantronurl = $scantronurls{'custom'};
7399: } else {
7400: $scantronurl = $scantronurls{'default'};
7401: }
7402: }
7403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7404: $datatable .= '<tr'.$css_class.'>';
7405: if (!$is_custom) {
7406: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7407: '<span class="LC_nobreak">';
7408: if ($scantronurl) {
7409: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7410: undef,undef,undef,undef,'background-color:#ffffff');
7411: } else {
7412: $datatable = &mt('File unavailable for display');
7413: }
7414: $datatable .= '</span></td>';
7415: if (keys(%error) == 0) {
7416: $datatable .= '<td valign="bottom">';
7417: if (!$switchserver) {
7418: $datatable .= &mt('Upload:').'<br />';
7419: }
7420: } else {
7421: my $errorstr;
7422: foreach my $key (sort(keys(%error))) {
7423: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7424: }
7425: $datatable .= '<td>'.$errorstr;
7426: }
7427: } else {
7428: if (keys(%error) > 0) {
7429: my $errorstr;
7430: foreach my $key (sort(keys(%error))) {
7431: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7432: }
7433: $datatable .= '<td>'.$errorstr.'</td><td> ';
7434: } elsif ($scantronurl) {
7435: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7436: undef,undef,undef,undef,'background-color:#ffffff');
7437: $datatable .= '<td><span class="LC_nobreak">'.
7438: $link.
7439: '<label><input type="checkbox" name="scantronformat_del"'.
7440: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
7441: '<td><span class="LC_nobreak"> '.
7442: &mt('Replace:').'</span><br />';
7443: }
7444: }
7445: if (keys(%error) == 0) {
7446: if ($switchserver) {
7447: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7448: } else {
7449: $datatable .='<span class="LC_nobreak"> '.
7450: '<input type="file" name="scantronformat" /></span>';
7451: }
7452: }
7453: $datatable .= '</td></tr>';
7454: $$rowtotal ++;
7455: return $datatable;
7456: }
7457:
7458: sub legacy_scantronformat {
7459: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7460: my ($url,$error);
7461: my @statinfo = &Apache::lonnet::stat_file($newurl);
7462: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7463: (my $result,$url) =
7464: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7465: '','',$newfile);
7466: if ($result ne 'ok') {
7467: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
7468: }
7469: }
7470: return ($url,$error);
7471: }
7472:
7473: sub print_scantronconfig {
7474: my ($dom,$settings,$rowtotal) = @_;
7475: my $itemcount = 2;
7476: my $is_checked = ' checked="checked"';
7477: my %optionson = (
7478: hdr => ' checked="checked"',
7479: pad => ' checked="checked"',
7480: rem => ' checked="checked"',
7481: );
7482: my %optionsoff = (
7483: hdr => '',
7484: pad => '',
7485: rem => '',
7486: );
7487: my $currcsvsty = 'none';
7488: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
7489: my @fields = &scantroncsv_fields();
7490: my %titles = &scantronconfig_titles();
7491: if (ref($settings) eq 'HASH') {
7492: if (ref($settings->{config}) eq 'HASH') {
7493: if ($settings->{config}->{dat}) {
7494: $checked{'dat'} = $is_checked;
7495: }
7496: if (ref($settings->{config}->{csv}) eq 'HASH') {
7497: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
7498: %csvfields = %{$settings->{config}->{csv}->{fields}};
7499: if (keys(%csvfields) > 0) {
7500: $checked{'csv'} = $is_checked;
7501: $currcsvsty = 'block';
7502: }
7503: }
7504: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
7505: %csvoptions = %{$settings->{config}->{csv}->{options}};
7506: foreach my $option (keys(%optionson)) {
7507: unless ($csvoptions{$option}) {
7508: $optionsoff{$option} = $optionson{$option};
7509: $optionson{$option} = '';
7510: }
7511: }
7512: }
7513: }
7514: } else {
7515: $checked{'dat'} = $is_checked;
7516: }
7517: } else {
7518: $checked{'dat'} = $is_checked;
7519: }
7520: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
7521: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7522: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
7523: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
7524: foreach my $item ('dat','csv') {
7525: my $id;
7526: if ($item eq 'csv') {
7527: $id = 'id="scantronconfcsv" ';
7528: }
7529: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
7530: $titles{$item}.'</label>'.(' 'x3);
7531: if ($item eq 'csv') {
7532: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
7533: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
7534: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
7535: foreach my $col (@fields) {
7536: my $selnone;
7537: if ($csvfields{$col} eq '') {
7538: $selnone = ' selected="selected"';
7539: }
7540: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
7541: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
7542: '<option value=""'.$selnone.'></option>';
7543: for (my $i=0; $i<20; $i++) {
7544: my $shown = $i+1;
7545: my $sel;
7546: unless ($selnone) {
7547: if (exists($csvfields{$col})) {
7548: if ($csvfields{$col} == $i) {
7549: $sel = ' selected="selected"';
7550: }
7551: }
7552: }
7553: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
7554: }
7555: $datatable .= '</select></td></tr>';
7556: }
7557: $datatable .= '</table></fieldset>'.
7558: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
7559: '<legend>'.&mt('CSV Options').'</legend>';
7560: foreach my $option ('hdr','pad','rem') {
7561: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
7562: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
7563: &mt('Yes').'</label>'.(' 'x2)."\n".
7564: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
7565: }
7566: $datatable .= '</fieldset>';
7567: $itemcount ++;
7568: }
7569: }
7570: $datatable .= '</td></tr>';
7571: $$rowtotal ++;
7572: return $datatable;
7573: }
7574:
7575: sub scantronconfig_titles {
7576: return &Apache::lonlocal::texthash(
7577: dat => 'Standard format (.dat)',
7578: csv => 'Comma separated values (.csv)',
7579: hdr => 'Remove first line in file (contains column titles)',
7580: pad => 'Prepend 0s to PaperID',
7581: rem => 'Remove leading spaces (except Question Response columns)',
7582: CODE => 'CODE',
7583: ID => 'Student ID',
7584: PaperID => 'Paper ID',
7585: FirstName => 'First Name',
7586: LastName => 'Last Name',
7587: FirstQuestion => 'First Question Response',
7588: Section => 'Section',
7589: );
7590: }
7591:
7592: sub scantroncsv_fields {
7593: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
7594: }
7595:
7596: sub print_coursecategories {
7597: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7598: my $datatable;
7599: if ($position eq 'top') {
7600: my (%checked);
7601: my @catitems = ('unauth','auth');
7602: my @cattypes = ('std','domonly','codesrch','none');
7603: $checked{'unauth'} = 'std';
7604: $checked{'auth'} = 'std';
7605: if (ref($settings) eq 'HASH') {
7606: foreach my $type (@cattypes) {
7607: if ($type eq $settings->{'unauth'}) {
7608: $checked{'unauth'} = $type;
7609: }
7610: if ($type eq $settings->{'auth'}) {
7611: $checked{'auth'} = $type;
7612: }
7613: }
7614: }
7615: my %lt = &Apache::lonlocal::texthash (
7616: unauth => 'Catalog type for unauthenticated users',
7617: auth => 'Catalog type for authenticated users',
7618: none => 'No catalog',
7619: std => 'Standard catalog',
7620: domonly => 'Domain-only catalog',
7621: codesrch => "Code search form",
7622: );
7623: my $itemcount = 0;
7624: foreach my $item (@catitems) {
7625: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7626: $datatable .= '<tr '.$css_class.'>'.
7627: '<td>'.$lt{$item}.'</td>'.
7628: '<td class="LC_right_item"><span class="LC_nobreak">';
7629: foreach my $type (@cattypes) {
7630: my $ischecked;
7631: if ($checked{$item} eq $type) {
7632: $ischecked=' checked="checked"';
7633: }
7634: $datatable .= '<label>'.
7635: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7636: ' />'.$lt{$type}.'</label> ';
7637: }
7638: $datatable .= '</span></td></tr>';
7639: $itemcount ++;
7640: }
7641: $$rowtotal += $itemcount;
7642: } elsif ($position eq 'middle') {
7643: my $toggle_cats_crs = ' ';
7644: my $toggle_cats_dom = ' checked="checked" ';
7645: my $can_cat_crs = ' ';
7646: my $can_cat_dom = ' checked="checked" ';
7647: my $toggle_catscomm_comm = ' ';
7648: my $toggle_catscomm_dom = ' checked="checked" ';
7649: my $can_catcomm_comm = ' ';
7650: my $can_catcomm_dom = ' checked="checked" ';
7651:
7652: if (ref($settings) eq 'HASH') {
7653: if ($settings->{'togglecats'} eq 'crs') {
7654: $toggle_cats_crs = $toggle_cats_dom;
7655: $toggle_cats_dom = ' ';
7656: }
7657: if ($settings->{'categorize'} eq 'crs') {
7658: $can_cat_crs = $can_cat_dom;
7659: $can_cat_dom = ' ';
7660: }
7661: if ($settings->{'togglecatscomm'} eq 'comm') {
7662: $toggle_catscomm_comm = $toggle_catscomm_dom;
7663: $toggle_catscomm_dom = ' ';
7664: }
7665: if ($settings->{'categorizecomm'} eq 'comm') {
7666: $can_catcomm_comm = $can_catcomm_dom;
7667: $can_catcomm_dom = ' ';
7668: }
7669: }
7670: my %title = &Apache::lonlocal::texthash (
7671: togglecats => 'Show/Hide a course in catalog',
7672: togglecatscomm => 'Show/Hide a community in catalog',
7673: categorize => 'Assign a category to a course',
7674: categorizecomm => 'Assign a category to a community',
7675: );
7676: my %level = &Apache::lonlocal::texthash (
7677: dom => 'Set in Domain',
7678: crs => 'Set in Course',
7679: comm => 'Set in Community',
7680: );
7681: $datatable = '<tr class="LC_odd_row">'.
7682: '<td>'.$title{'togglecats'}.'</td>'.
7683: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7684: '<input type="radio" name="togglecats"'.
7685: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7686: '<label><input type="radio" name="togglecats"'.
7687: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7688: '</tr><tr>'.
7689: '<td>'.$title{'categorize'}.'</td>'.
7690: '<td class="LC_right_item"><span class="LC_nobreak">'.
7691: '<label><input type="radio" name="categorize"'.
7692: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7693: '<label><input type="radio" name="categorize"'.
7694: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
7695: '</tr><tr class="LC_odd_row">'.
7696: '<td>'.$title{'togglecatscomm'}.'</td>'.
7697: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7698: '<input type="radio" name="togglecatscomm"'.
7699: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7700: '<label><input type="radio" name="togglecatscomm"'.
7701: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7702: '</tr><tr>'.
7703: '<td>'.$title{'categorizecomm'}.'</td>'.
7704: '<td class="LC_right_item"><span class="LC_nobreak">'.
7705: '<label><input type="radio" name="categorizecomm"'.
7706: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7707: '<label><input type="radio" name="categorizecomm"'.
7708: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
7709: '</tr>';
7710: $$rowtotal += 4;
7711: } else {
7712: my $css_class;
7713: my $itemcount = 1;
7714: my $cathash;
7715: if (ref($settings) eq 'HASH') {
7716: $cathash = $settings->{'cats'};
7717: }
7718: if (ref($cathash) eq 'HASH') {
7719: my (@cats,@trails,%allitems,%idx,@jsarray);
7720: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7721: \%allitems,\%idx,\@jsarray);
7722: my $maxdepth = scalar(@cats);
7723: my $colattrib = '';
7724: if ($maxdepth > 2) {
7725: $colattrib = ' colspan="2" ';
7726: }
7727: my @path;
7728: if (@cats > 0) {
7729: if (ref($cats[0]) eq 'ARRAY') {
7730: my $numtop = @{$cats[0]};
7731: my $maxnum = $numtop;
7732: my %default_names = (
7733: instcode => &mt('Official courses'),
7734: communities => &mt('Communities'),
7735: );
7736:
7737: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7738: ($cathash->{'instcode::0'} eq '') ||
7739: (!grep(/^communities$/,@{$cats[0]})) ||
7740: ($cathash->{'communities::0'} eq '')) {
7741: $maxnum ++;
7742: }
7743: my $lastidx;
7744: for (my $i=0; $i<$numtop; $i++) {
7745: my $parent = $cats[0][$i];
7746: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7747: my $item = &escape($parent).'::0';
7748: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7749: $lastidx = $idx{$item};
7750: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7751: .'<select name="'.$item.'"'.$chgstr.'>';
7752: for (my $k=0; $k<=$maxnum; $k++) {
7753: my $vpos = $k+1;
7754: my $selstr;
7755: if ($k == $i) {
7756: $selstr = ' selected="selected" ';
7757: }
7758: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7759: }
7760: $datatable .= '</select></span></td><td>';
7761: if ($parent eq 'instcode' || $parent eq 'communities') {
7762: $datatable .= '<span class="LC_nobreak">'
7763: .$default_names{$parent}.'</span>';
7764: if ($parent eq 'instcode') {
7765: $datatable .= '<br /><span class="LC_nobreak">('
7766: .&mt('with institutional codes')
7767: .')</span></td><td'.$colattrib.'>';
7768: } else {
7769: $datatable .= '<table><tr><td>';
7770: }
7771: $datatable .= '<span class="LC_nobreak">'
7772: .'<label><input type="radio" name="'
7773: .$parent.'" value="1" checked="checked" />'
7774: .&mt('Display').'</label>';
7775: if ($parent eq 'instcode') {
7776: $datatable .= ' ';
7777: } else {
7778: $datatable .= '</span></td></tr><tr><td>'
7779: .'<span class="LC_nobreak">';
7780: }
7781: $datatable .= '<label><input type="radio" name="'
7782: .$parent.'" value="0" />'
7783: .&mt('Do not display').'</label></span>';
7784: if ($parent eq 'communities') {
7785: $datatable .= '</td></tr></table>';
7786: }
7787: $datatable .= '</td>';
7788: } else {
7789: $datatable .= $parent
7790: .' <span class="LC_nobreak"><label>'
7791: .'<input type="checkbox" name="deletecategory" '
7792: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7793: }
7794: my $depth = 1;
7795: push(@path,$parent);
7796: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7797: pop(@path);
7798: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7799: $itemcount ++;
7800: }
7801: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7802: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7803: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
7804: for (my $k=0; $k<=$maxnum; $k++) {
7805: my $vpos = $k+1;
7806: my $selstr;
7807: if ($k == $numtop) {
7808: $selstr = ' selected="selected" ';
7809: }
7810: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7811: }
7812: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
7813: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7814: .'</tr>'."\n";
7815: $itemcount ++;
7816: foreach my $default ('instcode','communities') {
7817: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7818: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7819: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7820: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7821: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7822: for (my $k=0; $k<=$maxnum; $k++) {
7823: my $vpos = $k+1;
7824: my $selstr;
7825: if ($k == $maxnum) {
7826: $selstr = ' selected="selected" ';
7827: }
7828: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7829: }
7830: $datatable .= '</select></span></td>'.
7831: '<td><span class="LC_nobreak">'.
7832: $default_names{$default}.'</span>';
7833: if ($default eq 'instcode') {
7834: $datatable .= '<br /><span class="LC_nobreak">('
7835: .&mt('with institutional codes').')</span>';
7836: }
7837: $datatable .= '</td>'
7838: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7839: .&mt('Display').'</label> '
7840: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7841: .&mt('Do not display').'</label></span></td></tr>';
7842: }
7843: }
7844: }
7845: } else {
7846: $datatable .= &initialize_categories($itemcount);
7847: }
7848: } else {
7849: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
7850: .&initialize_categories($itemcount);
7851: }
7852: $$rowtotal += $itemcount;
7853: }
7854: return $datatable;
7855: }
7856:
7857: sub print_serverstatuses {
7858: my ($dom,$settings,$rowtotal) = @_;
7859: my $datatable;
7860: my @pages = &serverstatus_pages();
7861: my (%namedaccess,%machineaccess);
7862: foreach my $type (@pages) {
7863: $namedaccess{$type} = '';
7864: $machineaccess{$type}= '';
7865: }
7866: if (ref($settings) eq 'HASH') {
7867: foreach my $type (@pages) {
7868: if (exists($settings->{$type})) {
7869: if (ref($settings->{$type}) eq 'HASH') {
7870: foreach my $key (keys(%{$settings->{$type}})) {
7871: if ($key eq 'namedusers') {
7872: $namedaccess{$type} = $settings->{$type}->{$key};
7873: } elsif ($key eq 'machines') {
7874: $machineaccess{$type} = $settings->{$type}->{$key};
7875: }
7876: }
7877: }
7878: }
7879: }
7880: }
7881: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
7882: my $rownum = 0;
7883: my $css_class;
7884: foreach my $type (@pages) {
7885: $rownum ++;
7886: $css_class = $rownum%2?' class="LC_odd_row"':'';
7887: $datatable .= '<tr'.$css_class.'>'.
7888: '<td><span class="LC_nobreak">'.
7889: $titles->{$type}.'</span></td>'.
7890: '<td class="LC_left_item">'.
7891: '<input type="text" name="'.$type.'_namedusers" '.
7892: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7893: '<td class="LC_right_item">'.
7894: '<span class="LC_nobreak">'.
7895: '<input type="text" name="'.$type.'_machines" '.
7896: 'value="'.$machineaccess{$type}.'" size="10" />'.
7897: '</span></td></tr>'."\n";
7898: }
7899: $$rowtotal += $rownum;
7900: return $datatable;
7901: }
7902:
7903: sub serverstatus_pages {
7904: return ('userstatus','lonstatus','loncron','server-status','codeversions',
7905: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
7906: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
7907: 'uniquecodes','diskusage','coursecatalog');
7908: }
7909:
7910: sub defaults_javascript {
7911: my ($settings) = @_;
7912: return unless (ref($settings) eq 'HASH');
7913: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7914: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7915: if ($maxnum eq '') {
7916: $maxnum = 0;
7917: }
7918: $maxnum ++;
7919: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
7920: return <<"ENDSCRIPT";
7921: <script type="text/javascript">
7922: // <![CDATA[
7923: function reorderTypes(form,caller) {
7924: var changedVal;
7925: $jstext
7926: var newpos = 'addinststatus_pos';
7927: var current = new Array;
7928: var maxh = $maxnum;
7929: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7930: var oldVal;
7931: if (caller == newpos) {
7932: changedVal = newitemVal;
7933: } else {
7934: var curritem = 'inststatus_pos_'+caller;
7935: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7936: current[newitemVal] = newpos;
7937: }
7938: for (var i=0; i<inststatuses.length; i++) {
7939: if (inststatuses[i] != caller) {
7940: var elementName = 'inststatus_pos_'+inststatuses[i];
7941: if (form.elements[elementName]) {
7942: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7943: current[currVal] = elementName;
7944: }
7945: }
7946: }
7947: for (var j=0; j<maxh; j++) {
7948: if (current[j] == undefined) {
7949: oldVal = j;
7950: }
7951: }
7952: if (oldVal < changedVal) {
7953: for (var k=oldVal+1; k<=changedVal ; k++) {
7954: var elementName = current[k];
7955: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7956: }
7957: } else {
7958: for (var k=changedVal; k<oldVal; k++) {
7959: var elementName = current[k];
7960: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7961: }
7962: }
7963: return;
7964: }
7965:
7966: // ]]>
7967: </script>
7968:
7969: ENDSCRIPT
7970: }
7971: }
7972:
7973: sub passwords_javascript {
7974: my %intalert = &Apache::lonlocal::texthash (
7975: 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.',
7976: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
7977: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
7978: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
7979: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
7980: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
7981: );
7982: &js_escape(\%intalert);
7983: my $defmin = $Apache::lonnet::passwdmin;
7984: my $intauthjs = <<"ENDSCRIPT";
7985:
7986: function warnIntAuth(field) {
7987: if (field.name == 'intauth_check') {
7988: if (field.value == '2') {
7989: alert('$intalert{authcheck}');
7990: }
7991: }
7992: if (field.name == 'intauth_cost') {
7993: field.value.replace(/\s/g,'');
7994: if (field.value != '') {
7995: var regexdigit=/^\\d+\$/;
7996: if (!regexdigit.test(field.value)) {
7997: alert('$intalert{authcost}');
7998: }
7999: }
8000: }
8001: return;
8002: }
8003:
8004: function warnIntPass(field) {
8005: field.value.replace(/^\s+/,'');
8006: field.value.replace(/\s+\$/,'');
8007: var regexdigit=/^\\d+\$/;
8008: if (field.name == 'passwords_min') {
8009: if (field.value == '') {
8010: alert('$intalert{passmin}');
8011: field.value = '$defmin';
8012: } else {
8013: if (!regexdigit.test(field.value)) {
8014: alert('$intalert{passmin}');
8015: field.value = '$defmin';
8016: }
8017: var minval = parseInt(field.value,10);
8018: if (minval < $defmin) {
8019: alert('$intalert{passmin}');
8020: field.value = '$defmin';
8021: }
8022: }
8023: } else {
8024: if (field.value == '0') {
8025: field.value = '';
8026: }
8027: if (field.value != '') {
8028: if (field.name == 'passwords_expire') {
8029: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
8030: if (!regexpposnum.test(field.value)) {
8031: alert('$intalert{passexp}');
8032: field.value = '';
8033: } else {
8034: var expval = parseFloat(field.value);
8035: if (expval == 0) {
8036: alert('$intalert{passexp}');
8037: field.value = '';
8038: }
8039: }
8040: } else {
8041: if (!regexdigit.test(field.value)) {
8042: if (field.name == 'passwords_max') {
8043: alert('$intalert{passmax}');
8044: } else {
8045: if (field.name == 'passwords_numsaved') {
8046: alert('$intalert{passnum}');
8047: }
8048: }
8049: field.value = '';
8050: }
8051: }
8052: }
8053: }
8054: return;
8055: }
8056:
8057: ENDSCRIPT
8058: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8059: }
8060:
8061: sub coursecategories_javascript {
8062: my ($settings) = @_;
8063: my ($output,$jstext,$cathash);
8064: if (ref($settings) eq 'HASH') {
8065: $cathash = $settings->{'cats'};
8066: }
8067: if (ref($cathash) eq 'HASH') {
8068: my (@cats,@jsarray,%idx);
8069: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
8070: if (@jsarray > 0) {
8071: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8072: for (my $i=0; $i<@jsarray; $i++) {
8073: if (ref($jsarray[$i]) eq 'ARRAY') {
8074: my $catstr = join('","',@{$jsarray[$i]});
8075: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8076: }
8077: }
8078: }
8079: } else {
8080: $jstext = ' var categories = Array(1);'."\n".
8081: ' categories[0] = Array("instcode_pos");'."\n";
8082: }
8083: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8084: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
8085: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8086: &js_escape(\$instcode_reserved);
8087: &js_escape(\$communities_reserved);
8088: &js_escape(\$choose_again);
8089: $output = <<"ENDSCRIPT";
8090: <script type="text/javascript">
8091: // <![CDATA[
8092: function reorderCats(form,parent,item,idx) {
8093: var changedVal;
8094: $jstext
8095: var newpos = 'addcategory_pos';
8096: if (parent == '') {
8097: var has_instcode = 0;
8098: var maxtop = categories[idx].length;
8099: for (var j=0; j<maxtop; j++) {
8100: if (categories[idx][j] == 'instcode::0') {
8101: has_instcode == 1;
8102: }
8103: }
8104: if (has_instcode == 0) {
8105: categories[idx][maxtop] = 'instcode_pos';
8106: }
8107: } else {
8108: newpos += '_'+parent;
8109: }
8110: var maxh = 1 + categories[idx].length;
8111: var current = new Array;
8112: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8113: if (item == newpos) {
8114: changedVal = newitemVal;
8115: } else {
8116: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8117: current[newitemVal] = newpos;
8118: }
8119: for (var i=0; i<categories[idx].length; i++) {
8120: var elementName = categories[idx][i];
8121: if (elementName != item) {
8122: if (form.elements[elementName]) {
8123: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8124: current[currVal] = elementName;
8125: }
8126: }
8127: }
8128: var oldVal;
8129: for (var j=0; j<maxh; j++) {
8130: if (current[j] == undefined) {
8131: oldVal = j;
8132: }
8133: }
8134: if (oldVal < changedVal) {
8135: for (var k=oldVal+1; k<=changedVal ; k++) {
8136: var elementName = current[k];
8137: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8138: }
8139: } else {
8140: for (var k=changedVal; k<oldVal; k++) {
8141: var elementName = current[k];
8142: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8143: }
8144: }
8145: return;
8146: }
8147:
8148: function categoryCheck(form) {
8149: if (form.elements['addcategory_name'].value == 'instcode') {
8150: alert('$instcode_reserved\\n$choose_again');
8151: return false;
8152: }
8153: if (form.elements['addcategory_name'].value == 'communities') {
8154: alert('$communities_reserved\\n$choose_again');
8155: return false;
8156: }
8157: return true;
8158: }
8159:
8160: // ]]>
8161: </script>
8162:
8163: ENDSCRIPT
8164: return $output;
8165: }
8166:
8167: sub initialize_categories {
8168: my ($itemcount) = @_;
8169: my ($datatable,$css_class,$chgstr);
8170: my %default_names = (
8171: instcode => 'Official courses (with institutional codes)',
8172: communities => 'Communities',
8173: );
8174: my $select0 = ' selected="selected"';
8175: my $select1 = '';
8176: foreach my $default ('instcode','communities') {
8177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8178: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
8179: if ($default eq 'communities') {
8180: $select1 = $select0;
8181: $select0 = '';
8182: }
8183: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8184: .'<select name="'.$default.'_pos">'
8185: .'<option value="0"'.$select0.'>1</option>'
8186: .'<option value="1"'.$select1.'>2</option>'
8187: .'<option value="2">3</option></select> '
8188: .$default_names{$default}
8189: .'</span></td><td><span class="LC_nobreak">'
8190: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8191: .&mt('Display').'</label> <label>'
8192: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
8193: .'</label></span></td></tr>';
8194: $itemcount ++;
8195: }
8196: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8197: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
8198: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8199: .'<select name="addcategory_pos"'.$chgstr.'>'
8200: .'<option value="0">1</option>'
8201: .'<option value="1">2</option>'
8202: .'<option value="2" selected="selected">3</option></select> '
8203: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8204: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8205: .'</td></tr>';
8206: return $datatable;
8207: }
8208:
8209: sub build_category_rows {
8210: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8211: my ($text,$name,$item,$chgstr);
8212: if (ref($cats) eq 'ARRAY') {
8213: my $maxdepth = scalar(@{$cats});
8214: if (ref($cats->[$depth]) eq 'HASH') {
8215: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8216: my $numchildren = @{$cats->[$depth]{$parent}};
8217: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8218: $text .= '<td><table class="LC_data_table">';
8219: my ($idxnum,$parent_name,$parent_item);
8220: my $higher = $depth - 1;
8221: if ($higher == 0) {
8222: $parent_name = &escape($parent).'::'.$higher;
8223: } else {
8224: if (ref($path) eq 'ARRAY') {
8225: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8226: }
8227: }
8228: $parent_item = 'addcategory_pos_'.$parent_name;
8229: for (my $j=0; $j<=$numchildren; $j++) {
8230: if ($j < $numchildren) {
8231: $name = $cats->[$depth]{$parent}[$j];
8232: $item = &escape($name).':'.&escape($parent).':'.$depth;
8233: $idxnum = $idx->{$item};
8234: } else {
8235: $name = $parent_name;
8236: $item = $parent_item;
8237: }
8238: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8239: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
8240: for (my $i=0; $i<=$numchildren; $i++) {
8241: my $vpos = $i+1;
8242: my $selstr;
8243: if ($j == $i) {
8244: $selstr = ' selected="selected" ';
8245: }
8246: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8247: }
8248: $text .= '</select> ';
8249: if ($j < $numchildren) {
8250: my $deeper = $depth+1;
8251: $text .= $name.' '
8252: .'<label><input type="checkbox" name="deletecategory" value="'
8253: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8254: if(ref($path) eq 'ARRAY') {
8255: push(@{$path},$name);
8256: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
8257: pop(@{$path});
8258: }
8259: } else {
8260: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
8261: if ($j == $numchildren) {
8262: $text .= $name;
8263: } else {
8264: $text .= $item;
8265: }
8266: $text .= '" value="" />';
8267: }
8268: $text .= '</td></tr>';
8269: }
8270: $text .= '</table></td>';
8271: } else {
8272: my $higher = $depth-1;
8273: if ($higher == 0) {
8274: $name = &escape($parent).'::'.$higher;
8275: } else {
8276: if (ref($path) eq 'ARRAY') {
8277: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8278: }
8279: }
8280: my $colspan;
8281: if ($parent ne 'instcode') {
8282: $colspan = $maxdepth - $depth - 1;
8283: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
8284: }
8285: }
8286: }
8287: }
8288: return $text;
8289: }
8290:
8291: sub modifiable_userdata_row {
8292: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8293: $rowid,$customcss,$rowstyle) = @_;
8294: my ($role,$rolename,$statustype);
8295: $role = $item;
8296: if ($context eq 'cancreate') {
8297: if ($item =~ /^(emailusername)_(.+)$/) {
8298: $role = $1;
8299: $statustype = $2;
8300: if (ref($usertypes) eq 'HASH') {
8301: if ($usertypes->{$statustype}) {
8302: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8303: } else {
8304: $rolename = &mt('Data provided by user');
8305: }
8306: }
8307: }
8308: } elsif ($context eq 'selfcreate') {
8309: if (ref($usertypes) eq 'HASH') {
8310: $rolename = $usertypes->{$role};
8311: } else {
8312: $rolename = $role;
8313: }
8314: } else {
8315: if ($role eq 'cr') {
8316: $rolename = &mt('Custom role');
8317: } else {
8318: $rolename = &Apache::lonnet::plaintext($role);
8319: }
8320: }
8321: my (@fields,%fieldtitles);
8322: if (ref($fieldsref) eq 'ARRAY') {
8323: @fields = @{$fieldsref};
8324: } else {
8325: @fields = ('lastname','firstname','middlename','generation',
8326: 'permanentemail','id');
8327: }
8328: if ((ref($titlesref) eq 'HASH')) {
8329: %fieldtitles = %{$titlesref};
8330: } else {
8331: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8332: }
8333: my $output;
8334: my $css_class;
8335: if ($rowcount%2) {
8336: $css_class = 'LC_odd_row';
8337: }
8338: if ($customcss) {
8339: $css_class .= " $customcss";
8340: }
8341: $css_class =~ s/^\s+//;
8342: if ($css_class) {
8343: $css_class = ' class="'.$css_class.'"';
8344: }
8345: if ($rowstyle) {
8346: $css_class .= ' style="'.$rowstyle.'"';
8347: }
8348: if ($rowid) {
8349: $rowid = ' id="'.$rowid.'"';
8350: }
8351:
8352: $output = '<tr '.$css_class.$rowid.'>'.
8353: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8354: '<td class="LC_left_item" colspan="2"><table>';
8355: my $rem;
8356: my %checks;
8357: if (ref($settings) eq 'HASH') {
8358: if (ref($settings->{$context}) eq 'HASH') {
8359: if (ref($settings->{$context}->{$role}) eq 'HASH') {
8360: my $hashref = $settings->{$context}->{$role};
8361: if ($role eq 'emailusername') {
8362: if ($statustype) {
8363: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8364: $hashref = $settings->{$context}->{$role}->{$statustype};
8365: if (ref($hashref) eq 'HASH') {
8366: foreach my $field (@fields) {
8367: if ($hashref->{$field}) {
8368: $checks{$field} = $hashref->{$field};
8369: }
8370: }
8371: }
8372: }
8373: }
8374: } else {
8375: if (ref($hashref) eq 'HASH') {
8376: foreach my $field (@fields) {
8377: if ($hashref->{$field}) {
8378: $checks{$field} = ' checked="checked" ';
8379: }
8380: }
8381: }
8382: }
8383: }
8384: }
8385: }
8386:
8387: my $total = scalar(@fields);
8388: for (my $i=0; $i<$total; $i++) {
8389: $rem = $i%($numinrow);
8390: if ($rem == 0) {
8391: if ($i > 0) {
8392: $output .= '</tr>';
8393: }
8394: $output .= '<tr>';
8395: }
8396: my $check = ' ';
8397: unless ($role eq 'emailusername') {
8398: if (exists($checks{$fields[$i]})) {
8399: $check = $checks{$fields[$i]};
8400: } else {
8401: if ($role eq 'st') {
8402: if (ref($settings) ne 'HASH') {
8403: $check = ' checked="checked" ';
8404: }
8405: }
8406: }
8407: }
8408: $output .= '<td class="LC_left_item">'.
8409: '<span class="LC_nobreak">';
8410: if ($role eq 'emailusername') {
8411: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8412: $checks{$fields[$i]} = 'omit';
8413: }
8414: foreach my $option ('required','optional','omit') {
8415: my $checked='';
8416: if ($checks{$fields[$i]} eq $option) {
8417: $checked='checked="checked" ';
8418: }
8419: $output .= '<label>'.
8420: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8421: &mt($option).'</label>'.(' ' x2);
8422: }
8423: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8424: } else {
8425: $output .= '<label>'.
8426: '<input type="checkbox" name="canmodify_'.$role.'" '.
8427: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8428: '</label>';
8429: }
8430: $output .= '</span></td>';
8431: }
8432: $rem = $total%$numinrow;
8433: my $colsleft;
8434: if ($rem) {
8435: $colsleft = $numinrow - $rem;
8436: }
8437: if ($colsleft > 1) {
8438: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8439: ' </td>';
8440: } elsif ($colsleft == 1) {
8441: $output .= '<td class="LC_left_item"> </td>';
8442: }
8443: $output .= '</tr></table></td></tr>';
8444: return $output;
8445: }
8446:
8447: sub insttypes_row {
8448: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8449: $customcss,$rowstyle) = @_;
8450: my %lt = &Apache::lonlocal::texthash (
8451: cansearch => 'Users allowed to search',
8452: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
8453: lockablenames => 'User preference to lock name',
8454: selfassign => 'Self-reportable affiliations',
8455: overrides => "Override domain's helpdesk settings based on requester's affiliation",
8456: );
8457: my $showdom;
8458: if ($context eq 'cansearch') {
8459: $showdom = ' ('.$dom.')';
8460: }
8461: my $class = 'LC_left_item';
8462: if ($context eq 'statustocreate') {
8463: $class = 'LC_right_item';
8464: }
8465: my $css_class;
8466: if ($$rowtotal%2) {
8467: $css_class = 'LC_odd_row';
8468: }
8469: if ($customcss) {
8470: $css_class .= ' '.$customcss;
8471: }
8472: $css_class =~ s/^\s+//;
8473: if ($css_class) {
8474: $css_class = ' class="'.$css_class.'"';
8475: }
8476: if ($rowstyle) {
8477: $css_class .= ' style="'.$rowstyle.'"';
8478: }
8479: if ($onclick) {
8480: $onclick = 'onclick="'.$onclick.'" ';
8481: }
8482: my $output = '<tr'.$css_class.'>'.
8483: '<td>'.$lt{$context}.$showdom.
8484: '</td><td class="'.$class.'" colspan="2"><table>';
8485: my $rem;
8486: if (ref($types) eq 'ARRAY') {
8487: for (my $i=0; $i<@{$types}; $i++) {
8488: if (defined($usertypes->{$types->[$i]})) {
8489: my $rem = $i%($numinrow);
8490: if ($rem == 0) {
8491: if ($i > 0) {
8492: $output .= '</tr>';
8493: }
8494: $output .= '<tr>';
8495: }
8496: my $check = ' ';
8497: if (ref($settings) eq 'HASH') {
8498: if (ref($settings->{$context}) eq 'ARRAY') {
8499: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8500: $check = ' checked="checked" ';
8501: }
8502: } elsif (ref($settings->{$context}) eq 'HASH') {
8503: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8504: $check = ' checked="checked" ';
8505: }
8506: } elsif ($context eq 'statustocreate') {
8507: $check = ' checked="checked" ';
8508: }
8509: }
8510: $output .= '<td class="LC_left_item">'.
8511: '<span class="LC_nobreak"><label>'.
8512: '<input type="checkbox" name="'.$context.'" '.
8513: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
8514: $usertypes->{$types->[$i]}.'</label></span></td>';
8515: }
8516: }
8517: $rem = @{$types}%($numinrow);
8518: }
8519: my $colsleft = $numinrow - $rem;
8520: if ($context eq 'overrides') {
8521: if ($colsleft > 1) {
8522: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8523: } else {
8524: $output .= '<td class="LC_left_item">';
8525: }
8526: $output .= ' ';
8527: } else {
8528: if ($rem == 0) {
8529: $output .= '<tr>';
8530: }
8531: if ($colsleft > 1) {
8532: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8533: } else {
8534: $output .= '<td class="LC_left_item">';
8535: }
8536: my $defcheck = ' ';
8537: if (ref($settings) eq 'HASH') {
8538: if (ref($settings->{$context}) eq 'ARRAY') {
8539: if (grep(/^default$/,@{$settings->{$context}})) {
8540: $defcheck = ' checked="checked" ';
8541: }
8542: } elsif ($context eq 'statustocreate') {
8543: $defcheck = ' checked="checked" ';
8544: }
8545: }
8546: $output .= '<span class="LC_nobreak"><label>'.
8547: '<input type="checkbox" name="'.$context.'" '.
8548: 'value="default"'.$defcheck.$onclick.' />'.
8549: $othertitle.'</label></span>';
8550: }
8551: $output .= '</td></tr></table></td></tr>';
8552: return $output;
8553: }
8554:
8555: sub sorted_searchtitles {
8556: my %searchtitles = &Apache::lonlocal::texthash(
8557: 'uname' => 'username',
8558: 'lastname' => 'last name',
8559: 'lastfirst' => 'last name, first name',
8560: );
8561: my @titleorder = ('uname','lastname','lastfirst');
8562: return (\%searchtitles,\@titleorder);
8563: }
8564:
8565: sub sorted_searchtypes {
8566: my %srchtypes_desc = (
8567: exact => 'is exact match',
8568: contains => 'contains ..',
8569: begins => 'begins with ..',
8570: );
8571: my @srchtypeorder = ('exact','begins','contains');
8572: return (\%srchtypes_desc,\@srchtypeorder);
8573: }
8574:
8575: sub usertype_update_row {
8576: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8577: my $datatable;
8578: my $numinrow = 4;
8579: foreach my $type (@{$types}) {
8580: if (defined($usertypes->{$type})) {
8581: $$rownums ++;
8582: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8583: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8584: '</td><td class="LC_left_item"><table>';
8585: for (my $i=0; $i<@{$fields}; $i++) {
8586: my $rem = $i%($numinrow);
8587: if ($rem == 0) {
8588: if ($i > 0) {
8589: $datatable .= '</tr>';
8590: }
8591: $datatable .= '<tr>';
8592: }
8593: my $check = ' ';
8594: if (ref($settings) eq 'HASH') {
8595: if (ref($settings->{'fields'}) eq 'HASH') {
8596: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8597: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8598: $check = ' checked="checked" ';
8599: }
8600: }
8601: }
8602: }
8603:
8604: if ($i == @{$fields}-1) {
8605: my $colsleft = $numinrow - $rem;
8606: if ($colsleft > 1) {
8607: $datatable .= '<td colspan="'.$colsleft.'">';
8608: } else {
8609: $datatable .= '<td>';
8610: }
8611: } else {
8612: $datatable .= '<td>';
8613: }
8614: $datatable .= '<span class="LC_nobreak"><label>'.
8615: '<input type="checkbox" name="updateable_'.$type.
8616: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8617: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
8618: }
8619: $datatable .= '</tr></table></td></tr>';
8620: }
8621: }
8622: return $datatable;
8623: }
8624:
8625: sub modify_login {
8626: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
8627: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8628: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8629: %title = ( coursecatalog => 'Display course catalog',
8630: adminmail => 'Display administrator E-mail address',
8631: helpdesk => 'Display "Contact Helpdesk" link',
8632: newuser => 'Link for visitors to create a user account',
8633: loginheader => 'Log-in box header');
8634: @offon = ('off','on');
8635: if (ref($domconfig{login}) eq 'HASH') {
8636: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8637: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8638: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8639: }
8640: }
8641: }
8642: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8643: \%domconfig,\%loginhash);
8644: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
8645: foreach my $item (@toggles) {
8646: $loginhash{login}{$item} = $env{'form.'.$item};
8647: }
8648: $loginhash{login}{loginheader} = $env{'form.loginheader'};
8649: if (ref($colchanges{'login'}) eq 'HASH') {
8650: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8651: \%loginhash);
8652: }
8653:
8654: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8655: my %domservers = &Apache::lonnet::get_servers($dom);
8656: my @loginvia_attribs = ('serverpath','custompath','exempt');
8657: if (keys(%servers) > 1) {
8658: foreach my $lonhost (keys(%servers)) {
8659: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8660: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8661: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8662: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8663: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8664: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8665: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8666: $changes{'loginvia'}{$lonhost} = 1;
8667: } else {
8668: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8669: $changes{'loginvia'}{$lonhost} = 1;
8670: }
8671: } else {
8672: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8673: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8674: $changes{'loginvia'}{$lonhost} = 1;
8675: }
8676: }
8677: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8678: foreach my $item (@loginvia_attribs) {
8679: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8680: }
8681: } else {
8682: foreach my $item (@loginvia_attribs) {
8683: my $new = $env{'form.'.$lonhost.'_'.$item};
8684: if (($item eq 'serverpath') && ($new eq 'custom')) {
8685: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8686: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8687: $new = '/';
8688: }
8689: }
8690: if (($item eq 'custompath') &&
8691: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8692: $new = '';
8693: }
8694: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8695: $changes{'loginvia'}{$lonhost} = 1;
8696: }
8697: if ($item eq 'exempt') {
8698: $new = &check_exempt_addresses($new);
8699: }
8700: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8701: }
8702: }
8703: } else {
8704: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8705: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8706: $changes{'loginvia'}{$lonhost} = 1;
8707: foreach my $item (@loginvia_attribs) {
8708: my $new = $env{'form.'.$lonhost.'_'.$item};
8709: if (($item eq 'serverpath') && ($new eq 'custom')) {
8710: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8711: $new = '/';
8712: }
8713: }
8714: if (($item eq 'custompath') &&
8715: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8716: $new = '';
8717: }
8718: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8719: }
8720: }
8721: }
8722: }
8723: }
8724:
8725: my $servadm = $r->dir_config('lonAdmEMail');
8726: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8727: if (ref($domconfig{'login'}) eq 'HASH') {
8728: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8729: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8730: if ($lang eq 'nolang') {
8731: push(@currlangs,$lang);
8732: } elsif (defined($langchoices{$lang})) {
8733: push(@currlangs,$lang);
8734: } else {
8735: next;
8736: }
8737: }
8738: }
8739: }
8740: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8741: if (@currlangs > 0) {
8742: foreach my $lang (@currlangs) {
8743: if (grep(/^\Q$lang\E$/,@delurls)) {
8744: $changes{'helpurl'}{$lang} = 1;
8745: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8746: $changes{'helpurl'}{$lang} = 1;
8747: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8748: push(@newlangs,$lang);
8749: } else {
8750: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8751: }
8752: }
8753: }
8754: unless (grep(/^nolang$/,@currlangs)) {
8755: if ($env{'form.loginhelpurl_nolang.filename'}) {
8756: $changes{'helpurl'}{'nolang'} = 1;
8757: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8758: push(@newlangs,'nolang');
8759: }
8760: }
8761: if ($env{'form.loginhelpurl_add_lang'}) {
8762: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8763: ($env{'form.loginhelpurl_add_file.filename'})) {
8764: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8765: $addedfile = $env{'form.loginhelpurl_add_lang'};
8766: }
8767: }
8768: if ((@newlangs > 0) || ($addedfile)) {
8769: my $error;
8770: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8771: if ($configuserok eq 'ok') {
8772: if ($switchserver) {
8773: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8774: } elsif ($author_ok eq 'ok') {
8775: my @allnew = @newlangs;
8776: if ($addedfile ne '') {
8777: push(@allnew,$addedfile);
8778: }
8779: foreach my $lang (@allnew) {
8780: my $formelem = 'loginhelpurl_'.$lang;
8781: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8782: $formelem = 'loginhelpurl_add_file';
8783: }
8784: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8785: "help/$lang",'','',$newfile{$lang});
8786: if ($result eq 'ok') {
8787: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8788: $changes{'helpurl'}{$lang} = 1;
8789: } else {
8790: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8791: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8792: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
8793: (!grep(/^\Q$lang\E$/,@delurls))) {
8794: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8795: }
8796: }
8797: }
8798: } else {
8799: $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);
8800: }
8801: } else {
8802: $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);
8803: }
8804: if ($error) {
8805: &Apache::lonnet::logthis($error);
8806: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8807: }
8808: }
8809:
8810: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8811: if (ref($domconfig{'login'}) eq 'HASH') {
8812: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8813: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8814: if ($domservers{$lonhost}) {
8815: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8816: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
8817: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
8818: }
8819: }
8820: }
8821: }
8822: }
8823: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8824: foreach my $lonhost (sort(keys(%domservers))) {
8825: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8826: $changes{'headtag'}{$lonhost} = 1;
8827: } else {
8828: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8829: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8830: }
8831: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8832: push(@newhosts,$lonhost);
8833: } elsif ($currheadtagurls{$lonhost}) {
8834: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8835: if ($currexempt{$lonhost}) {
8836: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
8837: $changes{'headtag'}{$lonhost} = 1;
8838: }
8839: } elsif ($possexempt{$lonhost}) {
8840: $changes{'headtag'}{$lonhost} = 1;
8841: }
8842: if ($possexempt{$lonhost}) {
8843: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8844: }
8845: }
8846: }
8847: }
8848: if (@newhosts) {
8849: my $error;
8850: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8851: if ($configuserok eq 'ok') {
8852: if ($switchserver) {
8853: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8854: } elsif ($author_ok eq 'ok') {
8855: foreach my $lonhost (@newhosts) {
8856: my $formelem = 'loginheadtag_'.$lonhost;
8857: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8858: "login/headtag/$lonhost",'','',
8859: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8860: if ($result eq 'ok') {
8861: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8862: $changes{'headtag'}{$lonhost} = 1;
8863: if ($possexempt{$lonhost}) {
8864: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8865: }
8866: } else {
8867: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8868: $newheadtagurls{$lonhost},$result);
8869: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8870: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8871: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8872: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8873: }
8874: }
8875: }
8876: } else {
8877: $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);
8878: }
8879: } else {
8880: $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);
8881: }
8882: if ($error) {
8883: &Apache::lonnet::logthis($error);
8884: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8885: }
8886: }
8887: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
8888:
8889: my $defaulthelpfile = '/adm/loginproblems.html';
8890: my $defaulttext = &mt('Default in use');
8891:
8892: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8893: $dom);
8894: if ($putresult eq 'ok') {
8895: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
8896: my %defaultchecked = (
8897: 'coursecatalog' => 'on',
8898: 'helpdesk' => 'on',
8899: 'adminmail' => 'off',
8900: 'newuser' => 'off',
8901: );
8902: if (ref($domconfig{'login'}) eq 'HASH') {
8903: foreach my $item (@toggles) {
8904: if ($defaultchecked{$item} eq 'on') {
8905: if (($domconfig{'login'}{$item} eq '0') &&
8906: ($env{'form.'.$item} eq '1')) {
8907: $changes{$item} = 1;
8908: } elsif (($domconfig{'login'}{$item} eq '' ||
8909: $domconfig{'login'}{$item} eq '1') &&
8910: ($env{'form.'.$item} eq '0')) {
8911: $changes{$item} = 1;
8912: }
8913: } elsif ($defaultchecked{$item} eq 'off') {
8914: if (($domconfig{'login'}{$item} eq '1') &&
8915: ($env{'form.'.$item} eq '0')) {
8916: $changes{$item} = 1;
8917: } elsif (($domconfig{'login'}{$item} eq '' ||
8918: $domconfig{'login'}{$item} eq '0') &&
8919: ($env{'form.'.$item} eq '1')) {
8920: $changes{$item} = 1;
8921: }
8922: }
8923: }
8924: }
8925: if (keys(%changes) > 0 || $colchgtext) {
8926: &Apache::loncommon::devalidate_domconfig_cache($dom);
8927: if (ref($lastactref) eq 'HASH') {
8928: $lastactref->{'domainconfig'} = 1;
8929: }
8930: $resulttext = &mt('Changes made:').'<ul>';
8931: foreach my $item (sort(keys(%changes))) {
8932: if ($item eq 'loginvia') {
8933: if (ref($changes{$item}) eq 'HASH') {
8934: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8935: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8936: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8937: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8938: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8939: $protocol = 'http' if ($protocol ne 'https');
8940: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8941:
8942: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8943: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8944: } else {
8945: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8946: }
8947: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8948: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8949: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8950: }
8951: $resulttext .= '</li>';
8952: } else {
8953: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8954: }
8955: } else {
8956: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
8957: }
8958: }
8959: $resulttext .= '</ul></li>';
8960: }
8961: } elsif ($item eq 'helpurl') {
8962: if (ref($changes{$item}) eq 'HASH') {
8963: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8964: if (grep(/^\Q$lang\E$/,@delurls)) {
8965: my ($chg,$link);
8966: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8967: if ($lang eq 'nolang') {
8968: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8969: } else {
8970: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8971: }
8972: $resulttext .= '<li>'.$chg.'</li>';
8973: } else {
8974: my $chg;
8975: if ($lang eq 'nolang') {
8976: $chg = &mt('custom log-in help file for no preferred language');
8977: } else {
8978: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8979: }
8980: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8981: $loginhash{'login'}{'helpurl'}{$lang}.
8982: '?inhibitmenu=yes',$chg,600,500).
8983: '</li>';
8984: }
8985: }
8986: }
8987: } elsif ($item eq 'headtag') {
8988: if (ref($changes{$item}) eq 'HASH') {
8989: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8990: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8991: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8992: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8993: $resulttext .= '<li><a href="'.
8994: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8995: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8996: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8997: if ($possexempt{$lonhost}) {
8998: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8999: } else {
9000: $resulttext .= &mt('included for any client IP');
9001: }
9002: $resulttext .= '</li>';
9003: }
9004: }
9005: }
9006: } elsif ($item eq 'captcha') {
9007: if (ref($loginhash{'login'}) eq 'HASH') {
9008: my $chgtxt;
9009: if ($loginhash{'login'}{$item} eq 'notused') {
9010: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9011: } else {
9012: my %captchas = &captcha_phrases();
9013: if ($captchas{$loginhash{'login'}{$item}}) {
9014: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9015: } else {
9016: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9017: }
9018: }
9019: $resulttext .= '<li>'.$chgtxt.'</li>';
9020: }
9021: } elsif ($item eq 'recaptchakeys') {
9022: if (ref($loginhash{'login'}) eq 'HASH') {
9023: my ($privkey,$pubkey);
9024: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9025: $pubkey = $loginhash{'login'}{$item}{'public'};
9026: $privkey = $loginhash{'login'}{$item}{'private'};
9027: }
9028: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9029: if (!$pubkey) {
9030: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9031: } else {
9032: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9033: }
9034: if (!$privkey) {
9035: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9036: } else {
9037: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
9038: }
9039: $chgtxt .= '</ul>';
9040: $resulttext .= '<li>'.$chgtxt.'</li>';
9041: }
9042: } elsif ($item eq 'recaptchaversion') {
9043: if (ref($loginhash{'login'}) eq 'HASH') {
9044: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
9045: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
9046: '</li>';
9047: }
9048: }
9049: } else {
9050: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9051: }
9052: }
9053: $resulttext .= $colchgtext.'</ul>';
9054: } else {
9055: $resulttext = &mt('No changes made to log-in page settings');
9056: }
9057: } else {
9058: $resulttext = '<span class="LC_error">'.
9059: &mt('An error occurred: [_1]',$putresult).'</span>';
9060: }
9061: if ($errors) {
9062: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
9063: $errors.'</ul>';
9064: }
9065: return $resulttext;
9066: }
9067:
9068: sub check_exempt_addresses {
9069: my ($iplist) = @_;
9070: $iplist =~ s/^\s+//;
9071: $iplist =~ s/\s+$//;
9072: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9073: my (@okips,$new);
9074: foreach my $ip (@poss_ips) {
9075: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9076: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9077: push(@okips,$ip);
9078: }
9079: }
9080: }
9081: if (@okips > 0) {
9082: $new = join(',',@okips);
9083: } else {
9084: $new = '';
9085: }
9086: return $new;
9087: }
9088:
9089: sub color_font_choices {
9090: my %choices =
9091: &Apache::lonlocal::texthash (
9092: img => "Header",
9093: bgs => "Background colors",
9094: links => "Link colors",
9095: images => "Images",
9096: font => "Font color",
9097: fontmenu => "Font menu",
9098: pgbg => "Page",
9099: tabbg => "Header",
9100: sidebg => "Border",
9101: link => "Link",
9102: alink => "Active link",
9103: vlink => "Visited link",
9104: );
9105: return %choices;
9106: }
9107:
9108: sub modify_rolecolors {
9109: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
9110: my ($resulttext,%rolehash);
9111: $rolehash{'rolecolors'} = {};
9112: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9113: if ($domconfig{'rolecolors'} eq '') {
9114: $domconfig{'rolecolors'} = {};
9115: }
9116: }
9117: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
9118: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9119: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9120: $dom);
9121: if ($putresult eq 'ok') {
9122: if (keys(%changes) > 0) {
9123: &Apache::loncommon::devalidate_domconfig_cache($dom);
9124: if (ref($lastactref) eq 'HASH') {
9125: $lastactref->{'domainconfig'} = 1;
9126: }
9127: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9128: $rolehash{'rolecolors'});
9129: } else {
9130: $resulttext = &mt('No changes made to default color schemes');
9131: }
9132: } else {
9133: $resulttext = '<span class="LC_error">'.
9134: &mt('An error occurred: [_1]',$putresult).'</span>';
9135: }
9136: if ($errors) {
9137: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9138: $errors.'</ul>';
9139: }
9140: return $resulttext;
9141: }
9142:
9143: sub modify_colors {
9144: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
9145: my (%changes,%choices);
9146: my @bgs;
9147: my @links = ('link','alink','vlink');
9148: my @logintext;
9149: my @images;
9150: my $servadm = $r->dir_config('lonAdmEMail');
9151: my $errors;
9152: my %defaults;
9153: foreach my $role (@{$roles}) {
9154: if ($role eq 'login') {
9155: %choices = &login_choices();
9156: @logintext = ('textcol','bgcol');
9157: } else {
9158: %choices = &color_font_choices();
9159: }
9160: if ($role eq 'login') {
9161: @images = ('img','logo','domlogo','login');
9162: @bgs = ('pgbg','mainbg','sidebg');
9163: } else {
9164: @images = ('img');
9165: @bgs = ('pgbg','tabbg','sidebg');
9166: }
9167: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9168: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9169: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9170: }
9171: if ($role eq 'login') {
9172: foreach my $item (@logintext) {
9173: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9174: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9175: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9176: }
9177: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
9178: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9179: }
9180: }
9181: } else {
9182: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9183: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9184: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9185: }
9186: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
9187: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9188: }
9189: }
9190: foreach my $item (@bgs) {
9191: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9192: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9193: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9194: }
9195: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
9196: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9197: }
9198: }
9199: foreach my $item (@links) {
9200: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9201: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9202: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9203: }
9204: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
9205: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9206: }
9207: }
9208: my ($configuserok,$author_ok,$switchserver) =
9209: &config_check($dom,$confname,$servadm);
9210: my ($width,$height) = &thumb_dimensions();
9211: if (ref($domconfig->{$role}) ne 'HASH') {
9212: $domconfig->{$role} = {};
9213: }
9214: foreach my $img (@images) {
9215: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9216: if (defined($env{'form.login_showlogo_'.$img})) {
9217: $confhash->{$role}{'showlogo'}{$img} = 1;
9218: } else {
9219: $confhash->{$role}{'showlogo'}{$img} = 0;
9220: }
9221: }
9222: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9223: && !defined($domconfig->{$role}{$img})
9224: && !$env{'form.'.$role.'_del_'.$img}
9225: && $env{'form.'.$role.'_import_'.$img}) {
9226: # import the old configured image from the .tab setting
9227: # if they haven't provided a new one
9228: $domconfig->{$role}{$img} =
9229: $env{'form.'.$role.'_import_'.$img};
9230: }
9231: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
9232: my $error;
9233: if ($configuserok eq 'ok') {
9234: if ($switchserver) {
9235: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
9236: } else {
9237: if ($author_ok eq 'ok') {
9238: my ($result,$logourl) =
9239: &publishlogo($r,'upload',$role.'_'.$img,
9240: $dom,$confname,$img,$width,$height);
9241: if ($result eq 'ok') {
9242: $confhash->{$role}{$img} = $logourl;
9243: $changes{$role}{'images'}{$img} = 1;
9244: } else {
9245: $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);
9246: }
9247: } else {
9248: $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);
9249: }
9250: }
9251: } else {
9252: $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);
9253: }
9254: if ($error) {
9255: &Apache::lonnet::logthis($error);
9256: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9257: }
9258: } elsif ($domconfig->{$role}{$img} ne '') {
9259: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9260: my $error;
9261: if ($configuserok eq 'ok') {
9262: # is confname an author?
9263: if ($switchserver eq '') {
9264: if ($author_ok eq 'ok') {
9265: my ($result,$logourl) =
9266: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9267: $dom,$confname,$img,$width,$height);
9268: if ($result eq 'ok') {
9269: $confhash->{$role}{$img} = $logourl;
9270: $changes{$role}{'images'}{$img} = 1;
9271: }
9272: }
9273: }
9274: }
9275: }
9276: }
9277: }
9278: if (ref($domconfig) eq 'HASH') {
9279: if (ref($domconfig->{$role}) eq 'HASH') {
9280: foreach my $img (@images) {
9281: if ($domconfig->{$role}{$img} ne '') {
9282: if ($env{'form.'.$role.'_del_'.$img}) {
9283: $confhash->{$role}{$img} = '';
9284: $changes{$role}{'images'}{$img} = 1;
9285: } else {
9286: if ($confhash->{$role}{$img} eq '') {
9287: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9288: }
9289: }
9290: } else {
9291: if ($env{'form.'.$role.'_del_'.$img}) {
9292: $confhash->{$role}{$img} = '';
9293: $changes{$role}{'images'}{$img} = 1;
9294: }
9295: }
9296: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9297: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9298: if ($confhash->{$role}{'showlogo'}{$img} ne
9299: $domconfig->{$role}{'showlogo'}{$img}) {
9300: $changes{$role}{'showlogo'}{$img} = 1;
9301: }
9302: } else {
9303: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9304: $changes{$role}{'showlogo'}{$img} = 1;
9305: }
9306: }
9307: }
9308: }
9309: if ($domconfig->{$role}{'font'} ne '') {
9310: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9311: $changes{$role}{'font'} = 1;
9312: }
9313: } else {
9314: if ($confhash->{$role}{'font'}) {
9315: $changes{$role}{'font'} = 1;
9316: }
9317: }
9318: if ($role ne 'login') {
9319: if ($domconfig->{$role}{'fontmenu'} ne '') {
9320: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9321: $changes{$role}{'fontmenu'} = 1;
9322: }
9323: } else {
9324: if ($confhash->{$role}{'fontmenu'}) {
9325: $changes{$role}{'fontmenu'} = 1;
9326: }
9327: }
9328: }
9329: foreach my $item (@bgs) {
9330: if ($domconfig->{$role}{$item} ne '') {
9331: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9332: $changes{$role}{'bgs'}{$item} = 1;
9333: }
9334: } else {
9335: if ($confhash->{$role}{$item}) {
9336: $changes{$role}{'bgs'}{$item} = 1;
9337: }
9338: }
9339: }
9340: foreach my $item (@links) {
9341: if ($domconfig->{$role}{$item} ne '') {
9342: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9343: $changes{$role}{'links'}{$item} = 1;
9344: }
9345: } else {
9346: if ($confhash->{$role}{$item}) {
9347: $changes{$role}{'links'}{$item} = 1;
9348: }
9349: }
9350: }
9351: foreach my $item (@logintext) {
9352: if ($domconfig->{$role}{$item} ne '') {
9353: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9354: $changes{$role}{'logintext'}{$item} = 1;
9355: }
9356: } else {
9357: if ($confhash->{$role}{$item}) {
9358: $changes{$role}{'logintext'}{$item} = 1;
9359: }
9360: }
9361: }
9362: } else {
9363: &default_change_checker($role,\@images,\@links,\@bgs,
9364: \@logintext,$confhash,\%changes);
9365: }
9366: } else {
9367: &default_change_checker($role,\@images,\@links,\@bgs,
9368: \@logintext,$confhash,\%changes);
9369: }
9370: }
9371: return ($errors,%changes);
9372: }
9373:
9374: sub config_check {
9375: my ($dom,$confname,$servadm) = @_;
9376: my ($configuserok,$author_ok,$switchserver,%currroles);
9377: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9378: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9379: $confname,$servadm);
9380: if ($configuserok eq 'ok') {
9381: $switchserver = &check_switchserver($dom,$confname);
9382: if ($switchserver eq '') {
9383: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9384: }
9385: }
9386: return ($configuserok,$author_ok,$switchserver);
9387: }
9388:
9389: sub default_change_checker {
9390: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
9391: foreach my $item (@{$links}) {
9392: if ($confhash->{$role}{$item}) {
9393: $changes->{$role}{'links'}{$item} = 1;
9394: }
9395: }
9396: foreach my $item (@{$bgs}) {
9397: if ($confhash->{$role}{$item}) {
9398: $changes->{$role}{'bgs'}{$item} = 1;
9399: }
9400: }
9401: foreach my $item (@{$logintext}) {
9402: if ($confhash->{$role}{$item}) {
9403: $changes->{$role}{'logintext'}{$item} = 1;
9404: }
9405: }
9406: foreach my $img (@{$images}) {
9407: if ($env{'form.'.$role.'_del_'.$img}) {
9408: $confhash->{$role}{$img} = '';
9409: $changes->{$role}{'images'}{$img} = 1;
9410: }
9411: if ($role eq 'login') {
9412: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9413: $changes->{$role}{'showlogo'}{$img} = 1;
9414: }
9415: }
9416: }
9417: if ($confhash->{$role}{'font'}) {
9418: $changes->{$role}{'font'} = 1;
9419: }
9420: }
9421:
9422: sub display_colorchgs {
9423: my ($dom,$changes,$roles,$confhash) = @_;
9424: my (%choices,$resulttext);
9425: if (!grep(/^login$/,@{$roles})) {
9426: $resulttext = &mt('Changes made:').'<br />';
9427: }
9428: foreach my $role (@{$roles}) {
9429: if ($role eq 'login') {
9430: %choices = &login_choices();
9431: } else {
9432: %choices = &color_font_choices();
9433: }
9434: if (ref($changes->{$role}) eq 'HASH') {
9435: if ($role ne 'login') {
9436: $resulttext .= '<h4>'.&mt($role).'</h4>';
9437: }
9438: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9439: if ($role ne 'login') {
9440: $resulttext .= '<ul>';
9441: }
9442: if (ref($changes->{$role}{$key}) eq 'HASH') {
9443: if ($role ne 'login') {
9444: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9445: }
9446: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
9447: if (($role eq 'login') && ($key eq 'showlogo')) {
9448: if ($confhash->{$role}{$key}{$item}) {
9449: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9450: } else {
9451: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9452: }
9453: } elsif ($confhash->{$role}{$item} eq '') {
9454: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9455: } else {
9456: my $newitem = $confhash->{$role}{$item};
9457: if ($key eq 'images') {
9458: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
9459: }
9460: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
9461: }
9462: }
9463: if ($role ne 'login') {
9464: $resulttext .= '</ul></li>';
9465: }
9466: } else {
9467: if ($confhash->{$role}{$key} eq '') {
9468: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9469: } else {
9470: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9471: }
9472: }
9473: if ($role ne 'login') {
9474: $resulttext .= '</ul>';
9475: }
9476: }
9477: }
9478: }
9479: return $resulttext;
9480: }
9481:
9482: sub thumb_dimensions {
9483: return ('200','50');
9484: }
9485:
9486: sub check_dimensions {
9487: my ($inputfile) = @_;
9488: my ($fullwidth,$fullheight);
9489: if ($inputfile =~ m|^[/\w.\-]+$|) {
9490: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9491: my $imageinfo = <PIPE>;
9492: if (!close(PIPE)) {
9493: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9494: }
9495: chomp($imageinfo);
9496: my ($fullsize) =
9497: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
9498: if ($fullsize) {
9499: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9500: }
9501: }
9502: }
9503: return ($fullwidth,$fullheight);
9504: }
9505:
9506: sub check_configuser {
9507: my ($uhome,$dom,$confname,$servadm) = @_;
9508: my ($configuserok,%currroles);
9509: if ($uhome eq 'no_host') {
9510: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9511: my $configpass = &LONCAPA::Enrollment::create_password($dom);
9512: $configuserok =
9513: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9514: $configpass,'','','','','',undef,$servadm);
9515: } else {
9516: $configuserok = 'ok';
9517: %currroles =
9518: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9519: }
9520: return ($configuserok,%currroles);
9521: }
9522:
9523: sub check_authorstatus {
9524: my ($dom,$confname,%currroles) = @_;
9525: my $author_ok;
9526: if (!$currroles{':'.$dom.':au'}) {
9527: my $start = time;
9528: my $end = 0;
9529: $author_ok =
9530: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
9531: 'au',$end,$start,'','','domconfig');
9532: } else {
9533: $author_ok = 'ok';
9534: }
9535: return $author_ok;
9536: }
9537:
9538: sub publishlogo {
9539: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
9540: my ($output,$fname,$logourl);
9541: if ($action eq 'upload') {
9542: $fname=$env{'form.'.$formname.'.filename'};
9543: chop($env{'form.'.$formname});
9544: } else {
9545: ($fname) = ($formname =~ /([^\/]+)$/);
9546: }
9547: if ($savefileas ne '') {
9548: $fname = $savefileas;
9549: }
9550: $fname=&Apache::lonnet::clean_filename($fname);
9551: # See if there is anything left
9552: unless ($fname) { return ('error: no uploaded file'); }
9553: $fname="$subdir/$fname";
9554: my $docroot=$r->dir_config('lonDocRoot');
9555: my $filepath="$docroot/priv";
9556: my $relpath = "$dom/$confname";
9557: my ($fnamepath,$file,$fetchthumb);
9558: $file=$fname;
9559: if ($fname=~m|/|) {
9560: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9561: }
9562: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
9563: my $count;
9564: for ($count=5;$count<=$#parts;$count++) {
9565: $filepath.="/$parts[$count]";
9566: if ((-e $filepath)!=1) {
9567: mkdir($filepath,02770);
9568: }
9569: }
9570: # Check for bad extension and disallow upload
9571: if ($file=~/\.(\w+)$/ &&
9572: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9573: $output =
9574: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
9575: } elsif ($file=~/\.(\w+)$/ &&
9576: !defined(&Apache::loncommon::fileembstyle($1))) {
9577: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9578: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
9579: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
9580: } elsif (-d "$filepath/$file") {
9581: $output = &mt('Filename is a directory name - rename the file and re-upload');
9582: } else {
9583: my $source = $filepath.'/'.$file;
9584: my $logfile;
9585: if (!open($logfile,">>",$source.'.log')) {
9586: return (&mt('No write permission to Authoring Space'));
9587: }
9588: print $logfile
9589: "\n================= Publish ".localtime()." ================\n".
9590: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9591: # Save the file
9592: if (!open(FH,">",$source)) {
9593: &Apache::lonnet::logthis('Failed to create '.$source);
9594: return (&mt('Failed to create file'));
9595: }
9596: if ($action eq 'upload') {
9597: if (!print FH ($env{'form.'.$formname})) {
9598: &Apache::lonnet::logthis('Failed to write to '.$source);
9599: return (&mt('Failed to write file'));
9600: }
9601: } else {
9602: my $original = &Apache::lonnet::filelocation('',$formname);
9603: if(!copy($original,$source)) {
9604: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9605: return (&mt('Failed to write file'));
9606: }
9607: }
9608: close(FH);
9609: chmod(0660, $source); # Permissions to rw-rw---.
9610:
9611: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9612: my $copyfile=$targetdir.'/'.$file;
9613:
9614: my @parts=split(/\//,$targetdir);
9615: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9616: for (my $count=5;$count<=$#parts;$count++) {
9617: $path.="/$parts[$count]";
9618: if (!-e $path) {
9619: print $logfile "\nCreating directory ".$path;
9620: mkdir($path,02770);
9621: }
9622: }
9623: my $versionresult;
9624: if (-e $copyfile) {
9625: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9626: } else {
9627: $versionresult = 'ok';
9628: }
9629: if ($versionresult eq 'ok') {
9630: if (copy($source,$copyfile)) {
9631: print $logfile "\nCopied original source to ".$copyfile."\n";
9632: $output = 'ok';
9633: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
9634: push(@{$modified_urls},[$copyfile,$source]);
9635: my $metaoutput =
9636: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9637: unless ($registered_cleanup) {
9638: my $handlers = $r->get_handlers('PerlCleanupHandler');
9639: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9640: $registered_cleanup=1;
9641: }
9642: } else {
9643: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9644: $output = &mt('Failed to copy file to RES space').", $!";
9645: }
9646: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9647: my $inputfile = $filepath.'/'.$file;
9648: my $outfile = $filepath.'/'.'tn-'.$file;
9649: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9650: if ($fullwidth ne '' && $fullheight ne '') {
9651: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9652: my $thumbsize = $thumbwidth.'x'.$thumbheight;
9653: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9654: system({$args[0]} @args);
9655: chmod(0660, $filepath.'/tn-'.$file);
9656: if (-e $outfile) {
9657: my $copyfile=$targetdir.'/tn-'.$file;
9658: if (copy($outfile,$copyfile)) {
9659: print $logfile "\nCopied source to ".$copyfile."\n";
9660: my $thumb_metaoutput =
9661: &write_metadata($dom,$confname,$formname,
9662: $targetdir,'tn-'.$file,$logfile);
9663: push(@{$modified_urls},[$copyfile,$outfile]);
9664: unless ($registered_cleanup) {
9665: my $handlers = $r->get_handlers('PerlCleanupHandler');
9666: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9667: $registered_cleanup=1;
9668: }
9669: } else {
9670: print $logfile "\nUnable to write ".$copyfile.
9671: ':'.$!."\n";
9672: }
9673: }
9674: }
9675: }
9676: }
9677: } else {
9678: $output = $versionresult;
9679: }
9680: }
9681: return ($output,$logourl);
9682: }
9683:
9684: sub logo_versioning {
9685: my ($targetdir,$file,$logfile) = @_;
9686: my $target = $targetdir.'/'.$file;
9687: my ($maxversion,$fn,$extn,$output);
9688: $maxversion = 0;
9689: if ($file =~ /^(.+)\.(\w+)$/) {
9690: $fn=$1;
9691: $extn=$2;
9692: }
9693: opendir(DIR,$targetdir);
9694: while (my $filename=readdir(DIR)) {
9695: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9696: $maxversion=($1>$maxversion)?$1:$maxversion;
9697: }
9698: }
9699: $maxversion++;
9700: print $logfile "\nCreating old version ".$maxversion."\n";
9701: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9702: if (copy($target,$copyfile)) {
9703: print $logfile "Copied old target to ".$copyfile."\n";
9704: $copyfile=$copyfile.'.meta';
9705: if (copy($target.'.meta',$copyfile)) {
9706: print $logfile "Copied old target metadata to ".$copyfile."\n";
9707: $output = 'ok';
9708: } else {
9709: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9710: $output = &mt('Failed to copy old meta').", $!, ";
9711: }
9712: } else {
9713: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9714: $output = &mt('Failed to copy old target').", $!, ";
9715: }
9716: return $output;
9717: }
9718:
9719: sub write_metadata {
9720: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9721: my (%metadatafields,%metadatakeys,$output);
9722: $metadatafields{'title'}=$formname;
9723: $metadatafields{'creationdate'}=time;
9724: $metadatafields{'lastrevisiondate'}=time;
9725: $metadatafields{'copyright'}='public';
9726: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9727: $env{'user.domain'};
9728: $metadatafields{'authorspace'}=$confname.':'.$dom;
9729: $metadatafields{'domain'}=$dom;
9730: {
9731: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9732: my $mfh;
9733: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
9734: foreach (sort(keys(%metadatafields))) {
9735: unless ($_=~/\./) {
9736: my $unikey=$_;
9737: $unikey=~/^([A-Za-z]+)/;
9738: my $tag=$1;
9739: $tag=~tr/A-Z/a-z/;
9740: print $mfh "\n\<$tag";
9741: foreach (split(/\,/,$metadatakeys{$unikey})) {
9742: my $value=$metadatafields{$unikey.'.'.$_};
9743: $value=~s/\"/\'\'/g;
9744: print $mfh ' '.$_.'="'.$value.'"';
9745: }
9746: print $mfh '>'.
9747: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9748: .'</'.$tag.'>';
9749: }
9750: }
9751: $output = 'ok';
9752: print $logfile "\nWrote metadata";
9753: close($mfh);
9754: } else {
9755: print $logfile "\nFailed to open metadata file";
9756: $output = &mt('Could not write metadata');
9757: }
9758: }
9759: return $output;
9760: }
9761:
9762: sub notifysubscribed {
9763: foreach my $targetsource (@{$modified_urls}){
9764: next unless (ref($targetsource) eq 'ARRAY');
9765: my ($target,$source)=@{$targetsource};
9766: if ($source ne '') {
9767: if (open(my $logfh,">>",$source.'.log')) {
9768: print $logfh "\nCleanup phase: Notifications\n";
9769: my @subscribed=&subscribed_hosts($target);
9770: foreach my $subhost (@subscribed) {
9771: print $logfh "\nNotifying host ".$subhost.':';
9772: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9773: print $logfh $reply;
9774: }
9775: my @subscribedmeta=&subscribed_hosts("$target.meta");
9776: foreach my $subhost (@subscribedmeta) {
9777: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9778: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9779: $subhost);
9780: print $logfh $reply;
9781: }
9782: print $logfh "\n============ Done ============\n";
9783: close($logfh);
9784: }
9785: }
9786: }
9787: return OK;
9788: }
9789:
9790: sub subscribed_hosts {
9791: my ($target) = @_;
9792: my @subscribed;
9793: if (open(my $fh,"<","$target.subscription")) {
9794: while (my $subline=<$fh>) {
9795: if ($subline =~ /^($match_lonid):/) {
9796: my $host = $1;
9797: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9798: unless (grep(/^\Q$host\E$/,@subscribed)) {
9799: push(@subscribed,$host);
9800: }
9801: }
9802: }
9803: }
9804: }
9805: return @subscribed;
9806: }
9807:
9808: sub check_switchserver {
9809: my ($dom,$confname) = @_;
9810: my ($allowed,$switchserver);
9811: my $home = &Apache::lonnet::homeserver($confname,$dom);
9812: if ($home eq 'no_host') {
9813: $home = &Apache::lonnet::domain($dom,'primary');
9814: }
9815: my @ids=&Apache::lonnet::current_machine_ids();
9816: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9817: if (!$allowed) {
9818: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
9819: }
9820: return $switchserver;
9821: }
9822:
9823: sub modify_quotas {
9824: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9825: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
9826: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
9827: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9828: $validationfieldsref);
9829: if ($action eq 'quotas') {
9830: $context = 'tools';
9831: } else {
9832: $context = $action;
9833: }
9834: if ($context eq 'requestcourses') {
9835: @usertools = ('official','unofficial','community','textbook');
9836: @options =('norequest','approval','validate','autolimit');
9837: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9838: %titles = &courserequest_titles();
9839: $toolregexp = join('|',@usertools);
9840: %conditions = &courserequest_conditions();
9841: $confname = $dom.'-domainconfig';
9842: my $servadm = $r->dir_config('lonAdmEMail');
9843: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9844: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9845: &Apache::loncoursequeueadmin::requestcourses_validation_types();
9846: } elsif ($context eq 'requestauthor') {
9847: @usertools = ('author');
9848: %titles = &authorrequest_titles();
9849: } else {
9850: @usertools = ('aboutme','blog','webdav','portfolio');
9851: %titles = &tool_titles();
9852: }
9853: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9854: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9855: foreach my $key (keys(%env)) {
9856: if ($context eq 'requestcourses') {
9857: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9858: my $item = $1;
9859: my $type = $2;
9860: if ($type =~ /^limit_(.+)/) {
9861: $limithash{$item}{$1} = $env{$key};
9862: } else {
9863: $confhash{$item}{$type} = $env{$key};
9864: }
9865: }
9866: } elsif ($context eq 'requestauthor') {
9867: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9868: $confhash{$1} = $env{$key};
9869: }
9870: } else {
9871: if ($key =~ /^form\.quota_(.+)$/) {
9872: $confhash{'defaultquota'}{$1} = $env{$key};
9873: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9874: $confhash{'authorquota'}{$1} = $env{$key};
9875: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
9876: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9877: }
9878: }
9879: }
9880: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
9881: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
9882: @approvalnotify = sort(@approvalnotify);
9883: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
9884: my @crstypes = ('official','unofficial','community','textbook');
9885: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9886: foreach my $type (@hasuniquecode) {
9887: if (grep(/^\Q$type\E$/,@crstypes)) {
9888: $confhash{'uniquecode'}{$type} = 1;
9889: }
9890: }
9891: my (%newbook,%allpos);
9892: if ($context eq 'requestcourses') {
9893: foreach my $type ('textbooks','templates') {
9894: @{$allpos{$type}} = ();
9895: my $invalid;
9896: if ($type eq 'textbooks') {
9897: $invalid = &mt('Invalid LON-CAPA course for textbook');
9898: } else {
9899: $invalid = &mt('Invalid LON-CAPA course for template');
9900: }
9901: if ($env{'form.'.$type.'_addbook'}) {
9902: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9903: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9904: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9905: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9906: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9907: } else {
9908: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9909: my $position = $env{'form.'.$type.'_addbook_pos'};
9910: $position =~ s/\D+//g;
9911: if ($position ne '') {
9912: $allpos{$type}[$position] = $newbook{$type};
9913: }
9914: }
9915: } else {
9916: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9917: }
9918: }
9919: }
9920: }
9921: if (ref($domconfig{$action}) eq 'HASH') {
9922: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9923: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9924: $changes{'notify'}{'approval'} = 1;
9925: }
9926: } else {
9927: if ($confhash{'notify'}{'approval'}) {
9928: $changes{'notify'}{'approval'} = 1;
9929: }
9930: }
9931: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9932: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9933: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9934: unless ($confhash{'uniquecode'}{$crstype}) {
9935: $changes{'uniquecode'} = 1;
9936: }
9937: }
9938: unless ($changes{'uniquecode'}) {
9939: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9940: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9941: $changes{'uniquecode'} = 1;
9942: }
9943: }
9944: }
9945: } else {
9946: $changes{'uniquecode'} = 1;
9947: }
9948: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9949: $changes{'uniquecode'} = 1;
9950: }
9951: if ($context eq 'requestcourses') {
9952: foreach my $type ('textbooks','templates') {
9953: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9954: my %deletions;
9955: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9956: if (@todelete) {
9957: map { $deletions{$_} = 1; } @todelete;
9958: }
9959: my %imgdeletions;
9960: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9961: if (@todeleteimages) {
9962: map { $imgdeletions{$_} = 1; } @todeleteimages;
9963: }
9964: my $maxnum = $env{'form.'.$type.'_maxnum'};
9965: for (my $i=0; $i<=$maxnum; $i++) {
9966: my $itemid = $env{'form.'.$type.'_id_'.$i};
9967: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9968: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9969: if ($deletions{$key}) {
9970: if ($domconfig{$action}{$type}{$key}{'image'}) {
9971: #FIXME need to obsolete item in RES space
9972: }
9973: next;
9974: } else {
9975: my $newpos = $env{'form.'.$itemid};
9976: $newpos =~ s/\D+//g;
9977: foreach my $item ('subject','title','publisher','author') {
9978: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9979: ($type eq 'templates'));
9980: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9981: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9982: $changes{$type}{$key} = 1;
9983: }
9984: }
9985: $allpos{$type}[$newpos] = $key;
9986: }
9987: if ($imgdeletions{$key}) {
9988: $changes{$type}{$key} = 1;
9989: #FIXME need to obsolete item in RES space
9990: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9991: my ($cdom,$cnum) = split(/_/,$key);
9992: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9993: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9994: } else {
9995: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9996: $cdom,$cnum,$type,$configuserok,
9997: $switchserver,$author_ok);
9998: if ($imgurl) {
9999: $confhash{$type}{$key}{'image'} = $imgurl;
10000: $changes{$type}{$key} = 1;
10001: }
10002: if ($error) {
10003: &Apache::lonnet::logthis($error);
10004: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10005: }
10006: }
10007: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10008: $confhash{$type}{$key}{'image'} =
10009: $domconfig{$action}{$type}{$key}{'image'};
10010: }
10011: }
10012: }
10013: }
10014: }
10015: }
10016: } else {
10017: if ($confhash{'notify'}{'approval'}) {
10018: $changes{'notify'}{'approval'} = 1;
10019: }
10020: if (ref($confhash{'uniquecode'} eq 'HASH')) {
10021: $changes{'uniquecode'} = 1;
10022: }
10023: }
10024: if ($context eq 'requestcourses') {
10025: foreach my $type ('textbooks','templates') {
10026: if ($newbook{$type}) {
10027: $changes{$type}{$newbook{$type}} = 1;
10028: foreach my $item ('subject','title','publisher','author') {
10029: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10030: ($type eq 'template'));
10031: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10032: if ($env{'form.'.$type.'_addbook_'.$item}) {
10033: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10034: }
10035: }
10036: if ($type eq 'textbooks') {
10037: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10038: my ($cdom,$cnum) = split(/_/,$newbook{$type});
10039: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10040: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10041: } else {
10042: my ($imageurl,$error) =
10043: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10044: $configuserok,$switchserver,$author_ok);
10045: if ($imageurl) {
10046: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10047: }
10048: if ($error) {
10049: &Apache::lonnet::logthis($error);
10050: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10051: }
10052: }
10053: }
10054: }
10055: }
10056: if (@{$allpos{$type}} > 0) {
10057: my $idx = 0;
10058: foreach my $item (@{$allpos{$type}}) {
10059: if ($item ne '') {
10060: $confhash{$type}{$item}{'order'} = $idx;
10061: if (ref($domconfig{$action}) eq 'HASH') {
10062: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10063: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10064: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10065: $changes{$type}{$item} = 1;
10066: }
10067: }
10068: }
10069: }
10070: $idx ++;
10071: }
10072: }
10073: }
10074: }
10075: if (ref($validationitemsref) eq 'ARRAY') {
10076: foreach my $item (@{$validationitemsref}) {
10077: if ($item eq 'fields') {
10078: my @changed;
10079: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10080: if (@{$confhash{'validation'}{$item}} > 0) {
10081: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10082: }
10083: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10084: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10085: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10086: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10087: $domconfig{'requestcourses'}{'validation'}{$item});
10088: } else {
10089: @changed = @{$confhash{'validation'}{$item}};
10090: }
10091: } else {
10092: @changed = @{$confhash{'validation'}{$item}};
10093: }
10094: } else {
10095: @changed = @{$confhash{'validation'}{$item}};
10096: }
10097: if (@changed) {
10098: if ($confhash{'validation'}{$item}) {
10099: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10100: } else {
10101: $changes{'validation'}{$item} = &mt('None');
10102: }
10103: }
10104: } else {
10105: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10106: if ($item eq 'markup') {
10107: if ($env{'form.requestcourses_validation_'.$item}) {
10108: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10109: }
10110: }
10111: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10112: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10113: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10114: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10115: }
10116: } else {
10117: if ($confhash{'validation'}{$item} ne '') {
10118: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10119: }
10120: }
10121: } else {
10122: if ($confhash{'validation'}{$item} ne '') {
10123: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10124: }
10125: }
10126: }
10127: }
10128: }
10129: if ($env{'form.validationdc'}) {
10130: my $newval = $env{'form.validationdc'};
10131: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
10132: if (exists($domcoords{$newval})) {
10133: $confhash{'validation'}{'dc'} = $newval;
10134: }
10135: }
10136: if (ref($confhash{'validation'}) eq 'HASH') {
10137: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10138: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10139: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10140: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10141: if ($confhash{'validation'}{'dc'} eq '') {
10142: $changes{'validation'}{'dc'} = &mt('None');
10143: } else {
10144: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10145: }
10146: }
10147: } elsif ($confhash{'validation'}{'dc'} ne '') {
10148: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10149: }
10150: } elsif ($confhash{'validation'}{'dc'} ne '') {
10151: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10152: }
10153: } elsif ($confhash{'validation'}{'dc'} ne '') {
10154: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10155: }
10156: } else {
10157: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10158: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10159: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10160: $changes{'validation'}{'dc'} = &mt('None');
10161: }
10162: }
10163: }
10164: }
10165: }
10166: } else {
10167: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
10168: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
10169: }
10170: foreach my $item (@usertools) {
10171: foreach my $type (@{$types},'default','_LC_adv') {
10172: my $unset;
10173: if ($context eq 'requestcourses') {
10174: $unset = '0';
10175: if ($type eq '_LC_adv') {
10176: $unset = '';
10177: }
10178: if ($confhash{$item}{$type} eq 'autolimit') {
10179: $confhash{$item}{$type} .= '=';
10180: unless ($limithash{$item}{$type} =~ /\D/) {
10181: $confhash{$item}{$type} .= $limithash{$item}{$type};
10182: }
10183: }
10184: } elsif ($context eq 'requestauthor') {
10185: $unset = '0';
10186: if ($type eq '_LC_adv') {
10187: $unset = '';
10188: }
10189: } else {
10190: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10191: $confhash{$item}{$type} = 1;
10192: } else {
10193: $confhash{$item}{$type} = 0;
10194: }
10195: }
10196: if (ref($domconfig{$action}) eq 'HASH') {
10197: if ($action eq 'requestauthor') {
10198: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10199: $changes{$type} = 1;
10200: }
10201: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
10202: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10203: $changes{$item}{$type} = 1;
10204: }
10205: } else {
10206: if ($context eq 'requestcourses') {
10207: if ($confhash{$item}{$type} ne $unset) {
10208: $changes{$item}{$type} = 1;
10209: }
10210: } else {
10211: if (!$confhash{$item}{$type}) {
10212: $changes{$item}{$type} = 1;
10213: }
10214: }
10215: }
10216: } else {
10217: if ($context eq 'requestcourses') {
10218: if ($confhash{$item}{$type} ne $unset) {
10219: $changes{$item}{$type} = 1;
10220: }
10221: } elsif ($context eq 'requestauthor') {
10222: if ($confhash{$type} ne $unset) {
10223: $changes{$type} = 1;
10224: }
10225: } else {
10226: if (!$confhash{$item}{$type}) {
10227: $changes{$item}{$type} = 1;
10228: }
10229: }
10230: }
10231: }
10232: }
10233: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
10234: if (ref($domconfig{'quotas'}) eq 'HASH') {
10235: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10236: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10237: if (exists($confhash{'defaultquota'}{$key})) {
10238: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10239: $changes{'defaultquota'}{$key} = 1;
10240: }
10241: } else {
10242: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
10243: }
10244: }
10245: } else {
10246: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10247: if (exists($confhash{'defaultquota'}{$key})) {
10248: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10249: $changes{'defaultquota'}{$key} = 1;
10250: }
10251: } else {
10252: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
10253: }
10254: }
10255: }
10256: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10257: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10258: if (exists($confhash{'authorquota'}{$key})) {
10259: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10260: $changes{'authorquota'}{$key} = 1;
10261: }
10262: } else {
10263: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10264: }
10265: }
10266: }
10267: }
10268: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10269: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10270: if (ref($domconfig{'quotas'}) eq 'HASH') {
10271: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10272: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10273: $changes{'defaultquota'}{$key} = 1;
10274: }
10275: } else {
10276: if (!exists($domconfig{'quotas'}{$key})) {
10277: $changes{'defaultquota'}{$key} = 1;
10278: }
10279: }
10280: } else {
10281: $changes{'defaultquota'}{$key} = 1;
10282: }
10283: }
10284: }
10285: if (ref($confhash{'authorquota'}) eq 'HASH') {
10286: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10287: if (ref($domconfig{'quotas'}) eq 'HASH') {
10288: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10289: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10290: $changes{'authorquota'}{$key} = 1;
10291: }
10292: } else {
10293: $changes{'authorquota'}{$key} = 1;
10294: }
10295: } else {
10296: $changes{'authorquota'}{$key} = 1;
10297: }
10298: }
10299: }
10300: }
10301:
10302: if ($context eq 'requestauthor') {
10303: $domdefaults{'requestauthor'} = \%confhash;
10304: } else {
10305: foreach my $key (keys(%confhash)) {
10306: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
10307: $domdefaults{$key} = $confhash{$key};
10308: }
10309: }
10310: }
10311:
10312: my %quotahash = (
10313: $action => { %confhash }
10314: );
10315: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10316: $dom);
10317: if ($putresult eq 'ok') {
10318: if (keys(%changes) > 0) {
10319: my $cachetime = 24*60*60;
10320: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10321: if (ref($lastactref) eq 'HASH') {
10322: $lastactref->{'domdefaults'} = 1;
10323: }
10324: $resulttext = &mt('Changes made:').'<ul>';
10325: unless (($context eq 'requestcourses') ||
10326: ($context eq 'requestauthor')) {
10327: if (ref($changes{'defaultquota'}) eq 'HASH') {
10328: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10329: foreach my $type (@{$types},'default') {
10330: if (defined($changes{'defaultquota'}{$type})) {
10331: my $typetitle = $usertypes->{$type};
10332: if ($type eq 'default') {
10333: $typetitle = $othertitle;
10334: }
10335: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
10336: }
10337: }
10338: $resulttext .= '</ul></li>';
10339: }
10340: if (ref($changes{'authorquota'}) eq 'HASH') {
10341: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
10342: foreach my $type (@{$types},'default') {
10343: if (defined($changes{'authorquota'}{$type})) {
10344: my $typetitle = $usertypes->{$type};
10345: if ($type eq 'default') {
10346: $typetitle = $othertitle;
10347: }
10348: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
10349: }
10350: }
10351: $resulttext .= '</ul></li>';
10352: }
10353: }
10354: my %newenv;
10355: foreach my $item (@usertools) {
10356: my (%haschgs,%inconf);
10357: if ($context eq 'requestauthor') {
10358: %haschgs = %changes;
10359: %inconf = %confhash;
10360: } else {
10361: if (ref($changes{$item}) eq 'HASH') {
10362: %haschgs = %{$changes{$item}};
10363: }
10364: if (ref($confhash{$item}) eq 'HASH') {
10365: %inconf = %{$confhash{$item}};
10366: }
10367: }
10368: if (keys(%haschgs) > 0) {
10369: my $newacc =
10370: &Apache::lonnet::usertools_access($env{'user.name'},
10371: $env{'user.domain'},
10372: $item,'reload',$context);
10373: if (($context eq 'requestcourses') ||
10374: ($context eq 'requestauthor')) {
10375: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10376: $newenv{'environment.canrequest.'.$item} = $newacc;
10377: }
10378: } else {
10379: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10380: $newenv{'environment.availabletools.'.$item} = $newacc;
10381: }
10382: }
10383: unless ($context eq 'requestauthor') {
10384: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10385: }
10386: foreach my $type (@{$types},'default','_LC_adv') {
10387: if ($haschgs{$type}) {
10388: my $typetitle = $usertypes->{$type};
10389: if ($type eq 'default') {
10390: $typetitle = $othertitle;
10391: } elsif ($type eq '_LC_adv') {
10392: $typetitle = 'LON-CAPA Advanced Users';
10393: }
10394: if ($inconf{$type}) {
10395: if ($context eq 'requestcourses') {
10396: my $cond;
10397: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
10398: if ($1 eq '') {
10399: $cond = &mt('(Automatic processing of any request).');
10400: } else {
10401: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10402: }
10403: } else {
10404: $cond = $conditions{$inconf{$type}};
10405: }
10406: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
10407: } elsif ($context eq 'requestauthor') {
10408: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10409: $titles{$inconf{$type}},$typetitle);
10410:
10411: } else {
10412: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10413: }
10414: } else {
10415: if ($type eq '_LC_adv') {
10416: if ($inconf{$type} eq '0') {
10417: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10418: } else {
10419: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10420: }
10421: } else {
10422: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10423: }
10424: }
10425: }
10426: }
10427: unless ($context eq 'requestauthor') {
10428: $resulttext .= '</ul></li>';
10429: }
10430: }
10431: }
10432: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
10433: if (ref($changes{'notify'}) eq 'HASH') {
10434: if ($changes{'notify'}{'approval'}) {
10435: if (ref($confhash{'notify'}) eq 'HASH') {
10436: if ($confhash{'notify'}{'approval'}) {
10437: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10438: } else {
10439: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
10440: }
10441: }
10442: }
10443: }
10444: }
10445: if ($action eq 'requestcourses') {
10446: my @offon = ('off','on');
10447: if ($changes{'uniquecode'}) {
10448: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10449: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10450: $resulttext .= '<li>'.
10451: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10452: '</li>';
10453: } else {
10454: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10455: '</li>';
10456: }
10457: }
10458: foreach my $type ('textbooks','templates') {
10459: if (ref($changes{$type}) eq 'HASH') {
10460: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10461: foreach my $key (sort(keys(%{$changes{$type}}))) {
10462: my %coursehash = &Apache::lonnet::coursedescription($key);
10463: my $coursetitle = $coursehash{'description'};
10464: my $position = $confhash{$type}{$key}{'order'} + 1;
10465: $resulttext .= '<li>';
10466: foreach my $item ('subject','title','publisher','author') {
10467: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10468: ($type eq 'templates'));
10469: my $name = $item.':';
10470: $name =~ s/^(\w)/\U$1/;
10471: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10472: }
10473: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10474: if ($type eq 'textbooks') {
10475: if ($confhash{$type}{$key}{'image'}) {
10476: $resulttext .= ' '.&mt('Image: [_1]',
10477: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10478: ' alt="Textbook cover" />').'<br />';
10479: }
10480: }
10481: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
10482: }
10483: $resulttext .= '</ul></li>';
10484: }
10485: }
10486: if (ref($changes{'validation'}) eq 'HASH') {
10487: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10488: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10489: foreach my $item (@{$validationitemsref}) {
10490: if (exists($changes{'validation'}{$item})) {
10491: if ($item eq 'markup') {
10492: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10493: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10494: } else {
10495: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10496: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10497: }
10498: }
10499: }
10500: if (exists($changes{'validation'}{'dc'})) {
10501: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10502: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10503: }
10504: }
10505: }
10506: }
10507: $resulttext .= '</ul>';
10508: if (keys(%newenv)) {
10509: &Apache::lonnet::appenv(\%newenv);
10510: }
10511: } else {
10512: if ($context eq 'requestcourses') {
10513: $resulttext = &mt('No changes made to rights to request creation of courses.');
10514: } elsif ($context eq 'requestauthor') {
10515: $resulttext = &mt('No changes made to rights to request author space.');
10516: } else {
10517: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
10518: }
10519: }
10520: } else {
10521: $resulttext = '<span class="LC_error">'.
10522: &mt('An error occurred: [_1]',$putresult).'</span>';
10523: }
10524: if ($errors) {
10525: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10526: '<ul>'.$errors.'</ul></p>';
10527: }
10528: return $resulttext;
10529: }
10530:
10531: sub process_textbook_image {
10532: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
10533: my $filename = $env{'form.'.$caller.'.filename'};
10534: my ($error,$url);
10535: my ($width,$height) = (50,50);
10536: if ($configuserok eq 'ok') {
10537: if ($switchserver) {
10538: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10539: $switchserver);
10540: } elsif ($author_ok eq 'ok') {
10541: my ($result,$imageurl) =
10542: &publishlogo($r,'upload',$caller,$dom,$confname,
10543: "$type/$cdom/$cnum/cover",$width,$height);
10544: if ($result eq 'ok') {
10545: $url = $imageurl;
10546: } else {
10547: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10548: }
10549: } else {
10550: $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);
10551: }
10552: } else {
10553: $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);
10554: }
10555: return ($url,$error);
10556: }
10557:
10558: sub modify_ltitools {
10559: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10560: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10561: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
10562: my $confname = $dom.'-domainconfig';
10563: my $servadm = $r->dir_config('lonAdmEMail');
10564: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10565: my (%posslti,%possfield);
10566: my @courseroles = ('cc','in','ta','ep','st');
10567: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10568: map { $posslti{$_} = 1; } @ltiroles;
10569: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10570: map { $possfield{$_} = 1; } @allfields;
10571: my %lt = <itools_names();
10572: if ($env{'form.ltitools_add'}) {
10573: my $title = $env{'form.ltitools_add_title'};
10574: $title =~ s/(`)/'/g;
10575: ($newid,my $error) = &get_ltitools_id($dom,$title);
10576: if ($newid) {
10577: my $position = $env{'form.ltitools_add_pos'};
10578: $position =~ s/\D+//g;
10579: if ($position ne '') {
10580: $allpos[$position] = $newid;
10581: }
10582: $changes{$newid} = 1;
10583: foreach my $item ('title','url','key','secret','lifetime') {
10584: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
10585: if ($item eq 'lifetime') {
10586: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10587: }
10588: if ($env{'form.ltitools_add_'.$item}) {
10589: if (($item eq 'key') || ($item eq 'secret')) {
10590: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10591: } else {
10592: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10593: }
10594: }
10595: }
10596: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10597: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10598: }
10599: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10600: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10601: }
10602: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10603: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10604: } else {
10605: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10606: }
10607: foreach my $item ('width','height','linktext','explanation') {
10608: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10609: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
10610: if (($item eq 'width') || ($item eq 'height')) {
10611: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10612: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10613: }
10614: } else {
10615: if ($env{'form.ltitools_add_'.$item} ne '') {
10616: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10617: }
10618: }
10619: }
10620: if ($env{'form.ltitools_add_target'} eq 'window') {
10621: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
10622: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10623: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
10624: } else {
10625: $confhash{$newid}{'display'}{'target'} = 'iframe';
10626: }
10627: if ($env{'form.ltitools_add_image.filename'} ne '') {
10628: my ($imageurl,$error) =
10629: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
10630: $configuserok,$switchserver,$author_ok);
10631: if ($imageurl) {
10632: $confhash{$newid}{'image'} = $imageurl;
10633: }
10634: if ($error) {
10635: &Apache::lonnet::logthis($error);
10636: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10637: }
10638: }
10639: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10640: foreach my $field (@fields) {
10641: if ($possfield{$field}) {
10642: if ($field eq 'roles') {
10643: foreach my $role (@courseroles) {
10644: my $choice = $env{'form.ltitools_add_roles_'.$role};
10645: if (($choice ne '') && ($posslti{$choice})) {
10646: $confhash{$newid}{'roles'}{$role} = $choice;
10647: if ($role eq 'cc') {
10648: $confhash{$newid}{'roles'}{'co'} = $choice;
10649: }
10650: }
10651: }
10652: } else {
10653: $confhash{$newid}{'fields'}{$field} = 1;
10654: }
10655: }
10656: }
10657: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10658: if ($confhash{$newid}{'fields'}{'user'}) {
10659: if ($env{'form.ltitools_userincdom_add'}) {
10660: $confhash{$newid}{'incdom'} = 1;
10661: }
10662: }
10663: }
10664: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10665: foreach my $item (@courseconfig) {
10666: $confhash{$newid}{'crsconf'}{$item} = 1;
10667: }
10668: if ($env{'form.ltitools_add_custom'}) {
10669: my $name = $env{'form.ltitools_add_custom_name'};
10670: my $value = $env{'form.ltitools_add_custom_value'};
10671: $value =~ s/(`)/'/g;
10672: $name =~ s/(`)/'/g;
10673: $confhash{$newid}{'custom'}{$name} = $value;
10674: }
10675: } else {
10676: my $error = &mt('Failed to acquire unique ID for new external tool');
10677: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10678: }
10679: }
10680: if (ref($domconfig{$action}) eq 'HASH') {
10681: my %deletions;
10682: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10683: if (@todelete) {
10684: map { $deletions{$_} = 1; } @todelete;
10685: }
10686: my %customadds;
10687: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10688: if (@newcustom) {
10689: map { $customadds{$_} = 1; } @newcustom;
10690: }
10691: my %imgdeletions;
10692: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10693: if (@todeleteimages) {
10694: map { $imgdeletions{$_} = 1; } @todeleteimages;
10695: }
10696: my $maxnum = $env{'form.ltitools_maxnum'};
10697: for (my $i=0; $i<=$maxnum; $i++) {
10698: my $itemid = $env{'form.ltitools_id_'.$i};
10699: $itemid =~ s/\D+//g;
10700: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10701: if ($deletions{$itemid}) {
10702: if ($domconfig{$action}{$itemid}{'image'}) {
10703: #FIXME need to obsolete item in RES space
10704: }
10705: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10706: next;
10707: } else {
10708: my $newpos = $env{'form.ltitools_'.$itemid};
10709: $newpos =~ s/\D+//g;
10710: foreach my $item ('title','url','lifetime') {
10711: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10712: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10713: $changes{$itemid} = 1;
10714: }
10715: }
10716: foreach my $item ('key','secret') {
10717: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10718: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10719: $changes{$itemid} = 1;
10720: }
10721: }
10722: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10723: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10724: }
10725: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10726: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10727: }
10728: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
10729: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
10730: } else {
10731: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
10732: }
10733: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
10734: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
10735: $changes{$itemid} = 1;
10736: }
10737: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
10738: $changes{$itemid} = 1;
10739: }
10740: foreach my $size ('width','height') {
10741: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10742: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10743: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10744: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10745: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10746: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10747: $changes{$itemid} = 1;
10748: }
10749: } else {
10750: $changes{$itemid} = 1;
10751: }
10752: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10753: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10754: $changes{$itemid} = 1;
10755: }
10756: }
10757: }
10758: foreach my $item ('linktext','explanation') {
10759: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10760: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10761: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10762: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10763: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10764: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10765: $changes{$itemid} = 1;
10766: }
10767: } else {
10768: $changes{$itemid} = 1;
10769: }
10770: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10771: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10772: $changes{$itemid} = 1;
10773: }
10774: }
10775: }
10776: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10777: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10778: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10779: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10780: } else {
10781: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10782: }
10783: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10784: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10785: $changes{$itemid} = 1;
10786: }
10787: } else {
10788: $changes{$itemid} = 1;
10789: }
10790: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
10791: foreach my $item ('label','title','target','linktext','explanation','append') {
10792: if (grep(/^\Q$item\E$/,@courseconfig)) {
10793: $confhash{$itemid}{'crsconf'}{$item} = 1;
10794: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10795: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10796: $changes{$itemid} = 1;
10797: }
10798: } else {
10799: $changes{$itemid} = 1;
10800: }
10801: }
10802: }
10803: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10804: foreach my $field (@fields) {
10805: if ($possfield{$field}) {
10806: if ($field eq 'roles') {
10807: foreach my $role (@courseroles) {
10808: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10809: if (($choice ne '') && ($posslti{$choice})) {
10810: $confhash{$itemid}{'roles'}{$role} = $choice;
10811: if ($role eq 'cc') {
10812: $confhash{$itemid}{'roles'}{'co'} = $choice;
10813: }
10814: }
10815: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10816: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10817: $changes{$itemid} = 1;
10818: }
10819: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10820: $changes{$itemid} = 1;
10821: }
10822: }
10823: } else {
10824: $confhash{$itemid}{'fields'}{$field} = 1;
10825: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10826: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10827: $changes{$itemid} = 1;
10828: }
10829: } else {
10830: $changes{$itemid} = 1;
10831: }
10832: }
10833: }
10834: }
10835: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10836: if ($confhash{$itemid}{'fields'}{'user'}) {
10837: if ($env{'form.ltitools_userincdom_'.$i}) {
10838: $confhash{$itemid}{'incdom'} = 1;
10839: }
10840: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
10841: $changes{$itemid} = 1;
10842: }
10843: }
10844: }
10845: $allpos[$newpos] = $itemid;
10846: }
10847: if ($imgdeletions{$itemid}) {
10848: $changes{$itemid} = 1;
10849: #FIXME need to obsolete item in RES space
10850: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10851: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10852: $itemid,$configuserok,$switchserver,
10853: $author_ok);
10854: if ($imgurl) {
10855: $confhash{$itemid}{'image'} = $imgurl;
10856: $changes{$itemid} = 1;
10857: }
10858: if ($error) {
10859: &Apache::lonnet::logthis($error);
10860: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10861: }
10862: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10863: $confhash{$itemid}{'image'} =
10864: $domconfig{$action}{$itemid}{'image'};
10865: }
10866: if ($customadds{$i}) {
10867: my $name = $env{'form.ltitools_custom_name_'.$i};
10868: $name =~ s/(`)/'/g;
10869: $name =~ s/^\s+//;
10870: $name =~ s/\s+$//;
10871: my $value = $env{'form.ltitools_custom_value_'.$i};
10872: $value =~ s/(`)/'/g;
10873: $value =~ s/^\s+//;
10874: $value =~ s/\s+$//;
10875: if ($name ne '') {
10876: $confhash{$itemid}{'custom'}{$name} = $value;
10877: $changes{$itemid} = 1;
10878: }
10879: }
10880: my %customdels;
10881: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10882: if (@customdeletions) {
10883: $changes{$itemid} = 1;
10884: }
10885: map { $customdels{$_} = 1; } @customdeletions;
10886: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10887: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10888: unless ($customdels{$key}) {
10889: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10890: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10891: }
10892: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10893: $changes{$itemid} = 1;
10894: }
10895: }
10896: }
10897: }
10898: unless ($changes{$itemid}) {
10899: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10900: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10901: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10902: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10903: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10904: $changes{$itemid} = 1;
10905: last;
10906: }
10907: }
10908: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10909: $changes{$itemid} = 1;
10910: }
10911: }
10912: last if ($changes{$itemid});
10913: }
10914: }
10915: }
10916: }
10917: }
10918: if (@allpos > 0) {
10919: my $idx = 0;
10920: foreach my $itemid (@allpos) {
10921: if ($itemid ne '') {
10922: $confhash{$itemid}{'order'} = $idx;
10923: if (ref($domconfig{$action}) eq 'HASH') {
10924: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10925: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10926: $changes{$itemid} = 1;
10927: }
10928: }
10929: }
10930: $idx ++;
10931: }
10932: }
10933: }
10934: my %ltitoolshash = (
10935: $action => { %confhash }
10936: );
10937: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10938: $dom);
10939: if ($putresult eq 'ok') {
10940: my %ltienchash = (
10941: $action => { %encconfig }
10942: );
10943: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
10944: if (keys(%changes) > 0) {
10945: my $cachetime = 24*60*60;
10946: my %ltiall = %confhash;
10947: foreach my $id (keys(%ltiall)) {
10948: if (ref($encconfig{$id}) eq 'HASH') {
10949: foreach my $item ('key','secret') {
10950: $ltiall{$id}{$item} = $encconfig{$id}{$item};
10951: }
10952: }
10953: }
10954: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
10955: if (ref($lastactref) eq 'HASH') {
10956: $lastactref->{'ltitools'} = 1;
10957: }
10958: $resulttext = &mt('Changes made:').'<ul>';
10959: my %bynum;
10960: foreach my $itemid (sort(keys(%changes))) {
10961: my $position = $confhash{$itemid}{'order'};
10962: $bynum{$position} = $itemid;
10963: }
10964: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10965: my $itemid = $bynum{$pos};
10966: if (ref($confhash{$itemid}) ne 'HASH') {
10967: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10968: } else {
10969: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10970: if ($confhash{$itemid}{'image'}) {
10971: $resulttext .= ' '.
10972: '<img src="'.$confhash{$itemid}{'image'}.'"'.
10973: ' alt="'.&mt('Tool Provider icon').'" />';
10974: }
10975: $resulttext .= '</li><ul>';
10976: my $position = $pos + 1;
10977: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10978: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
10979: if ($confhash{$itemid}{$item} ne '') {
10980: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10981: }
10982: }
10983: if ($encconfig{$itemid}{'key'} ne '') {
10984: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10985: }
10986: if ($encconfig{$itemid}{'secret'} ne '') {
10987: $resulttext .= '<li>'.$lt{'secret'}.': ';
10988: my $num = length($encconfig{$itemid}{'secret'});
10989: $resulttext .= ('*'x$num).'</li>';
10990: }
10991: $resulttext .= '<li>'.&mt('Configurable in course:');
10992: my @possconfig = ('label','title','target','linktext','explanation','append');
10993: my $numconfig = 0;
10994: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10995: foreach my $item (@possconfig) {
10996: if ($confhash{$itemid}{'crsconf'}{$item}) {
10997: $numconfig ++;
10998: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
10999: }
11000: }
11001: }
11002: if (!$numconfig) {
11003: $resulttext .= &mt('None');
11004: }
11005: $resulttext .= '</li>';
11006: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11007: my $displaylist;
11008: if ($confhash{$itemid}{'display'}{'target'}) {
11009: $displaylist = &mt('Display target').': '.
11010: $confhash{$itemid}{'display'}{'target'}.',';
11011: }
11012: foreach my $size ('width','height') {
11013: if ($confhash{$itemid}{'display'}{$size}) {
11014: $displaylist .= (' 'x2).$lt{$size}.': '.
11015: $confhash{$itemid}{'display'}{$size}.',';
11016: }
11017: }
11018: if ($displaylist) {
11019: $displaylist =~ s/,$//;
11020: $resulttext .= '<li>'.$displaylist.'</li>';
11021: }
11022: foreach my $item ('linktext','explanation') {
11023: if ($confhash{$itemid}{'display'}{$item}) {
11024: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11025: }
11026: }
11027: }
11028: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11029: my $fieldlist;
11030: foreach my $field (@allfields) {
11031: if ($confhash{$itemid}{'fields'}{$field}) {
11032: $fieldlist .= (' 'x2).$lt{$field}.',';
11033: }
11034: }
11035: if ($fieldlist) {
11036: $fieldlist =~ s/,$//;
11037: if ($confhash{$itemid}{'fields'}{'user'}) {
11038: if ($confhash{$itemid}{'incdom'}) {
11039: $fieldlist .= ' ('.&mt('username:domain').')';
11040: } else {
11041: $fieldlist .= ' ('.&mt('username').')';
11042: }
11043: }
11044: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11045: }
11046: }
11047: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11048: my $rolemaps;
11049: foreach my $role (@courseroles) {
11050: if ($confhash{$itemid}{'roles'}{$role}) {
11051: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11052: $confhash{$itemid}{'roles'}{$role}.',';
11053: }
11054: }
11055: if ($rolemaps) {
11056: $rolemaps =~ s/,$//;
11057: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11058: }
11059: }
11060: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11061: my $customlist;
11062: if (keys(%{$confhash{$itemid}{'custom'}})) {
11063: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11064: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11065: }
11066: }
11067: if ($customlist) {
11068: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
11069: }
11070: }
11071: $resulttext .= '</ul></li>';
11072: }
11073: }
11074: $resulttext .= '</ul>';
11075: } else {
11076: $resulttext = &mt('No changes made.');
11077: }
11078: } else {
11079: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11080: }
11081: if ($errors) {
11082: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11083: $errors.'</ul>';
11084: }
11085: return $resulttext;
11086: }
11087:
11088: sub process_ltitools_image {
11089: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11090: my $filename = $env{'form.'.$caller.'.filename'};
11091: my ($error,$url);
11092: my ($width,$height) = (21,21);
11093: if ($configuserok eq 'ok') {
11094: if ($switchserver) {
11095: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11096: $switchserver);
11097: } elsif ($author_ok eq 'ok') {
11098: my ($result,$imageurl,$madethumb) =
11099: &publishlogo($r,'upload',$caller,$dom,$confname,
11100: "ltitools/$itemid/icon",$width,$height);
11101: if ($result eq 'ok') {
11102: if ($madethumb) {
11103: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11104: my $imagethumb = "$path/tn-".$imagefile;
11105: $url = $imagethumb;
11106: } else {
11107: $url = $imageurl;
11108: }
11109: } else {
11110: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11111: }
11112: } else {
11113: $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);
11114: }
11115: } else {
11116: $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);
11117: }
11118: return ($url,$error);
11119: }
11120:
11121: sub get_ltitools_id {
11122: my ($cdom,$title) = @_;
11123: # get lock on ltitools db
11124: my $lockhash = {
11125: lock => $env{'user.name'}.
11126: ':'.$env{'user.domain'},
11127: };
11128: my $tries = 0;
11129: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11130: my ($id,$error);
11131:
11132: while (($gotlock ne 'ok') && ($tries<10)) {
11133: $tries ++;
11134: sleep (0.1);
11135: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11136: }
11137: if ($gotlock eq 'ok') {
11138: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11139: if ($currids{'lock'}) {
11140: delete($currids{'lock'});
11141: if (keys(%currids)) {
11142: my @curr = sort { $a <=> $b } keys(%currids);
11143: if ($curr[-1] =~ /^\d+$/) {
11144: $id = 1 + $curr[-1];
11145: }
11146: } else {
11147: $id = 1;
11148: }
11149: if ($id) {
11150: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11151: $error = 'nostore';
11152: }
11153: } else {
11154: $error = 'nonumber';
11155: }
11156: }
11157: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11158: } else {
11159: $error = 'nolock';
11160: }
11161: return ($id,$error);
11162: }
11163:
11164: sub modify_autoenroll {
11165: my ($dom,$lastactref,%domconfig) = @_;
11166: my ($resulttext,%changes);
11167: my %currautoenroll;
11168: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11169: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11170: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11171: }
11172: }
11173: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11174: my %title = ( run => 'Auto-enrollment active',
11175: sender => 'Sender for notification messages',
11176: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11177: failsafe => 'Failsafe for no drops if institutional data missing for a section');
11178: my @offon = ('off','on');
11179: my $sender_uname = $env{'form.sender_uname'};
11180: my $sender_domain = $env{'form.sender_domain'};
11181: if ($sender_domain eq '') {
11182: $sender_uname = '';
11183: } elsif ($sender_uname eq '') {
11184: $sender_domain = '';
11185: }
11186: my $coowners = $env{'form.autoassign_coowners'};
11187: my $failsafe = $env{'form.autoenroll_failsafe'};
11188: $failsafe =~ s{^\s+|\s+$}{}g;
11189: if ($failsafe =~ /\D/) {
11190: undef($failsafe);
11191: }
11192: my %autoenrollhash = (
11193: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11194: 'sender_uname' => $sender_uname,
11195: 'sender_domain' => $sender_domain,
11196: 'co-owners' => $coowners,
11197: 'autofailsafe' => $failsafe,
11198: }
11199: );
11200: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11201: $dom);
11202: if ($putresult eq 'ok') {
11203: if (exists($currautoenroll{'run'})) {
11204: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11205: $changes{'run'} = 1;
11206: }
11207: } elsif ($autorun) {
11208: if ($env{'form.autoenroll_run'} ne '1') {
11209: $changes{'run'} = 1;
11210: }
11211: }
11212: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
11213: $changes{'sender'} = 1;
11214: }
11215: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
11216: $changes{'sender'} = 1;
11217: }
11218: if ($currautoenroll{'co-owners'} ne '') {
11219: if ($currautoenroll{'co-owners'} ne $coowners) {
11220: $changes{'coowners'} = 1;
11221: }
11222: } elsif ($coowners) {
11223: $changes{'coowners'} = 1;
11224: }
11225: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11226: $changes{'autofailsafe'} = 1;
11227: }
11228: if (keys(%changes) > 0) {
11229: $resulttext = &mt('Changes made:').'<ul>';
11230: if ($changes{'run'}) {
11231: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11232: }
11233: if ($changes{'sender'}) {
11234: if ($sender_uname eq '' || $sender_domain eq '') {
11235: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11236: } else {
11237: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11238: }
11239: }
11240: if ($changes{'coowners'}) {
11241: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11242: &Apache::loncommon::devalidate_domconfig_cache($dom);
11243: if (ref($lastactref) eq 'HASH') {
11244: $lastactref->{'domainconfig'} = 1;
11245: }
11246: }
11247: if ($changes{'autofailsafe'}) {
11248: if ($failsafe ne '') {
11249: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
11250: } else {
11251: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
11252: }
11253: &Apache::lonnet::get_domain_defaults($dom,1);
11254: if (ref($lastactref) eq 'HASH') {
11255: $lastactref->{'domdefaults'} = 1;
11256: }
11257: }
11258: $resulttext .= '</ul>';
11259: } else {
11260: $resulttext = &mt('No changes made to auto-enrollment settings');
11261: }
11262: } else {
11263: $resulttext = '<span class="LC_error">'.
11264: &mt('An error occurred: [_1]',$putresult).'</span>';
11265: }
11266: return $resulttext;
11267: }
11268:
11269: sub modify_autoupdate {
11270: my ($dom,%domconfig) = @_;
11271: my ($resulttext,%currautoupdate,%fields,%changes);
11272: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11273: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11274: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11275: }
11276: }
11277: my @offon = ('off','on');
11278: my %title = &Apache::lonlocal::texthash (
11279: run => 'Auto-update:',
11280: classlists => 'Updates to user information in classlists?'
11281: );
11282: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11283: my %fieldtitles = &Apache::lonlocal::texthash (
11284: id => 'Student/Employee ID',
11285: permanentemail => 'E-mail address',
11286: lastname => 'Last Name',
11287: firstname => 'First Name',
11288: middlename => 'Middle Name',
11289: generation => 'Generation',
11290: );
11291: $othertitle = &mt('All users');
11292: if (keys(%{$usertypes}) > 0) {
11293: $othertitle = &mt('Other users');
11294: }
11295: foreach my $key (keys(%env)) {
11296: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
11297: my ($usertype,$item) = ($1,$2);
11298: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11299: if ($usertype eq 'default') {
11300: push(@{$fields{$1}},$2);
11301: } elsif (ref($types) eq 'ARRAY') {
11302: if (grep(/^\Q$usertype\E$/,@{$types})) {
11303: push(@{$fields{$1}},$2);
11304: }
11305: }
11306: }
11307: }
11308: }
11309: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11310: @lockablenames = sort(@lockablenames);
11311: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11312: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11313: if (@changed) {
11314: $changes{'lockablenames'} = 1;
11315: }
11316: } else {
11317: if (@lockablenames) {
11318: $changes{'lockablenames'} = 1;
11319: }
11320: }
11321: my %updatehash = (
11322: autoupdate => { run => $env{'form.autoupdate_run'},
11323: classlists => $env{'form.classlists'},
11324: fields => {%fields},
11325: lockablenames => \@lockablenames,
11326: }
11327: );
11328: foreach my $key (keys(%currautoupdate)) {
11329: if (($key eq 'run') || ($key eq 'classlists')) {
11330: if (exists($updatehash{autoupdate}{$key})) {
11331: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11332: $changes{$key} = 1;
11333: }
11334: }
11335: } elsif ($key eq 'fields') {
11336: if (ref($currautoupdate{$key}) eq 'HASH') {
11337: foreach my $item (@{$types},'default') {
11338: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11339: my $change = 0;
11340: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11341: if (!exists($fields{$item})) {
11342: $change = 1;
11343: last;
11344: } elsif (ref($fields{$item}) eq 'ARRAY') {
11345: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
11346: $change = 1;
11347: last;
11348: }
11349: }
11350: }
11351: if ($change) {
11352: push(@{$changes{$key}},$item);
11353: }
11354: }
11355: }
11356: }
11357: } elsif ($key eq 'lockablenames') {
11358: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11359: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11360: if (@changed) {
11361: $changes{'lockablenames'} = 1;
11362: }
11363: } else {
11364: if (@lockablenames) {
11365: $changes{'lockablenames'} = 1;
11366: }
11367: }
11368: }
11369: }
11370: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11371: if (@lockablenames) {
11372: $changes{'lockablenames'} = 1;
11373: }
11374: }
11375: foreach my $item (@{$types},'default') {
11376: if (defined($fields{$item})) {
11377: if (ref($currautoupdate{'fields'}) eq 'HASH') {
11378: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11379: my $change = 0;
11380: if (ref($fields{$item}) eq 'ARRAY') {
11381: foreach my $type (@{$fields{$item}}) {
11382: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11383: $change = 1;
11384: last;
11385: }
11386: }
11387: }
11388: if ($change) {
11389: push(@{$changes{'fields'}},$item);
11390: }
11391: } else {
11392: push(@{$changes{'fields'}},$item);
11393: }
11394: } else {
11395: push(@{$changes{'fields'}},$item);
11396: }
11397: }
11398: }
11399: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11400: $dom);
11401: if ($putresult eq 'ok') {
11402: if (keys(%changes) > 0) {
11403: $resulttext = &mt('Changes made:').'<ul>';
11404: foreach my $key (sort(keys(%changes))) {
11405: if ($key eq 'lockablenames') {
11406: $resulttext .= '<li>';
11407: if (@lockablenames) {
11408: $usertypes->{'default'} = $othertitle;
11409: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11410: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11411: } else {
11412: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11413: }
11414: $resulttext .= '</li>';
11415: } elsif (ref($changes{$key}) eq 'ARRAY') {
11416: foreach my $item (@{$changes{$key}}) {
11417: my @newvalues;
11418: foreach my $type (@{$fields{$item}}) {
11419: push(@newvalues,$fieldtitles{$type});
11420: }
11421: my $newvaluestr;
11422: if (@newvalues > 0) {
11423: $newvaluestr = join(', ',@newvalues);
11424: } else {
11425: $newvaluestr = &mt('none');
11426: }
11427: if ($item eq 'default') {
11428: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
11429: } else {
11430: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
11431: }
11432: }
11433: } else {
11434: my $newvalue;
11435: if ($key eq 'run') {
11436: $newvalue = $offon[$env{'form.autoupdate_run'}];
11437: } else {
11438: $newvalue = $offon[$env{'form.'.$key}];
11439: }
11440: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11441: }
11442: }
11443: $resulttext .= '</ul>';
11444: } else {
11445: $resulttext = &mt('No changes made to autoupdates');
11446: }
11447: } else {
11448: $resulttext = '<span class="LC_error">'.
11449: &mt('An error occurred: [_1]',$putresult).'</span>';
11450: }
11451: return $resulttext;
11452: }
11453:
11454: sub modify_autocreate {
11455: my ($dom,%domconfig) = @_;
11456: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11457: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11458: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11459: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11460: }
11461: }
11462: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11463: req => 'Auto-creation of validated requests for official courses',
11464: xmldc => 'Identity of course creator of courses from XML files',
11465: );
11466: my @types = ('xml','req');
11467: foreach my $item (@types) {
11468: $newvals{$item} = $env{'form.autocreate_'.$item};
11469: $newvals{$item} =~ s/\D//g;
11470: $newvals{$item} = 0 if ($newvals{$item} eq '');
11471: }
11472: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
11473: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
11474: unless (exists($domcoords{$newvals{'xmldc'}})) {
11475: $newvals{'xmldc'} = '';
11476: }
11477: %autocreatehash = (
11478: autocreate => { xml => $newvals{'xml'},
11479: req => $newvals{'req'},
11480: }
11481: );
11482: if ($newvals{'xmldc'} ne '') {
11483: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11484: }
11485: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11486: $dom);
11487: if ($putresult eq 'ok') {
11488: my @items = @types;
11489: if ($newvals{'xml'}) {
11490: push(@items,'xmldc');
11491: }
11492: foreach my $item (@items) {
11493: if (exists($currautocreate{$item})) {
11494: if ($currautocreate{$item} ne $newvals{$item}) {
11495: $changes{$item} = 1;
11496: }
11497: } elsif ($newvals{$item}) {
11498: $changes{$item} = 1;
11499: }
11500: }
11501: if (keys(%changes) > 0) {
11502: my @offon = ('off','on');
11503: $resulttext = &mt('Changes made:').'<ul>';
11504: foreach my $item (@types) {
11505: if ($changes{$item}) {
11506: my $newtxt = $offon[$newvals{$item}];
11507: $resulttext .= '<li>'.
11508: &mt("$title{$item} set to [_1]$newtxt [_2]",
11509: '<b>','</b>').
11510: '</li>';
11511: }
11512: }
11513: if ($changes{'xmldc'}) {
11514: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
11515: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
11516: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
11517: }
11518: $resulttext .= '</ul>';
11519: } else {
11520: $resulttext = &mt('No changes made to auto-creation settings');
11521: }
11522: } else {
11523: $resulttext = '<span class="LC_error">'.
11524: &mt('An error occurred: [_1]',$putresult).'</span>';
11525: }
11526: return $resulttext;
11527: }
11528:
11529: sub modify_directorysrch {
11530: my ($dom,$lastactref,%domconfig) = @_;
11531: my ($resulttext,%changes);
11532: my %currdirsrch;
11533: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
11534: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
11535: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
11536: }
11537: }
11538: my %title = ( available => 'Institutional directory search available',
11539: localonly => 'Other domains can search institution',
11540: lcavailable => 'LON-CAPA directory search available',
11541: lclocalonly => 'Other domains can search LON-CAPA domain',
11542: searchby => 'Search types',
11543: searchtypes => 'Search latitude');
11544: my @offon = ('off','on');
11545: my @otherdoms = ('Yes','No');
11546:
11547: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
11548: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11549: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11550:
11551: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11552: if (keys(%{$usertypes}) == 0) {
11553: @cansearch = ('default');
11554: } else {
11555: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11556: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11557: if (!grep(/^\Q$type\E$/,@cansearch)) {
11558: push(@{$changes{'cansearch'}},$type);
11559: }
11560: }
11561: foreach my $type (@cansearch) {
11562: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11563: push(@{$changes{'cansearch'}},$type);
11564: }
11565: }
11566: } else {
11567: push(@{$changes{'cansearch'}},@cansearch);
11568: }
11569: }
11570:
11571: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11572: foreach my $by (@{$currdirsrch{'searchby'}}) {
11573: if (!grep(/^\Q$by\E$/,@searchby)) {
11574: push(@{$changes{'searchby'}},$by);
11575: }
11576: }
11577: foreach my $by (@searchby) {
11578: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11579: push(@{$changes{'searchby'}},$by);
11580: }
11581: }
11582: } else {
11583: push(@{$changes{'searchby'}},@searchby);
11584: }
11585:
11586: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11587: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11588: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11589: push(@{$changes{'searchtypes'}},$type);
11590: }
11591: }
11592: foreach my $type (@searchtypes) {
11593: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11594: push(@{$changes{'searchtypes'}},$type);
11595: }
11596: }
11597: } else {
11598: if (exists($currdirsrch{'searchtypes'})) {
11599: foreach my $type (@searchtypes) {
11600: if ($type ne $currdirsrch{'searchtypes'}) {
11601: push(@{$changes{'searchtypes'}},$type);
11602: }
11603: }
11604: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11605: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11606: }
11607: } else {
11608: push(@{$changes{'searchtypes'}},@searchtypes);
11609: }
11610: }
11611:
11612: my %dirsrch_hash = (
11613: directorysrch => { available => $env{'form.dirsrch_available'},
11614: cansearch => \@cansearch,
11615: localonly => $env{'form.dirsrch_instlocalonly'},
11616: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11617: lcavailable => $env{'form.dirsrch_domavailable'},
11618: searchby => \@searchby,
11619: searchtypes => \@searchtypes,
11620: }
11621: );
11622: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11623: $dom);
11624: if ($putresult eq 'ok') {
11625: if (exists($currdirsrch{'available'})) {
11626: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11627: $changes{'available'} = 1;
11628: }
11629: } else {
11630: if ($env{'form.dirsrch_available'} eq '1') {
11631: $changes{'available'} = 1;
11632: }
11633: }
11634: if (exists($currdirsrch{'lcavailable'})) {
11635: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11636: $changes{'lcavailable'} = 1;
11637: }
11638: } else {
11639: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11640: $changes{'lcavailable'} = 1;
11641: }
11642: }
11643: if (exists($currdirsrch{'localonly'})) {
11644: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
11645: $changes{'localonly'} = 1;
11646: }
11647: } else {
11648: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
11649: $changes{'localonly'} = 1;
11650: }
11651: }
11652: if (exists($currdirsrch{'lclocalonly'})) {
11653: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11654: $changes{'lclocalonly'} = 1;
11655: }
11656: } else {
11657: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11658: $changes{'lclocalonly'} = 1;
11659: }
11660: }
11661: if (keys(%changes) > 0) {
11662: $resulttext = &mt('Changes made:').'<ul>';
11663: if ($changes{'available'}) {
11664: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11665: }
11666: if ($changes{'lcavailable'}) {
11667: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11668: }
11669: if ($changes{'localonly'}) {
11670: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
11671: }
11672: if ($changes{'lclocalonly'}) {
11673: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
11674: }
11675: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11676: my $chgtext;
11677: if (ref($usertypes) eq 'HASH') {
11678: if (keys(%{$usertypes}) > 0) {
11679: foreach my $type (@{$types}) {
11680: if (grep(/^\Q$type\E$/,@cansearch)) {
11681: $chgtext .= $usertypes->{$type}.'; ';
11682: }
11683: }
11684: if (grep(/^default$/,@cansearch)) {
11685: $chgtext .= $othertitle;
11686: } else {
11687: $chgtext =~ s/\; $//;
11688: }
11689: $resulttext .=
11690: '<li>'.
11691: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11692: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11693: '</li>';
11694: }
11695: }
11696: }
11697: if (ref($changes{'searchby'}) eq 'ARRAY') {
11698: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11699: my $chgtext;
11700: foreach my $type (@{$titleorder}) {
11701: if (grep(/^\Q$type\E$/,@searchby)) {
11702: if (defined($searchtitles->{$type})) {
11703: $chgtext .= $searchtitles->{$type}.'; ';
11704: }
11705: }
11706: }
11707: $chgtext =~ s/\; $//;
11708: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11709: }
11710: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11711: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11712: my $chgtext;
11713: foreach my $type (@{$srchtypeorder}) {
11714: if (grep(/^\Q$type\E$/,@searchtypes)) {
11715: if (defined($srchtypes_desc->{$type})) {
11716: $chgtext .= $srchtypes_desc->{$type}.'; ';
11717: }
11718: }
11719: }
11720: $chgtext =~ s/\; $//;
11721: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
11722: }
11723: $resulttext .= '</ul>';
11724: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11725: if (ref($lastactref) eq 'HASH') {
11726: $lastactref->{'directorysrch'} = 1;
11727: }
11728: } else {
11729: $resulttext = &mt('No changes made to directory search settings');
11730: }
11731: } else {
11732: $resulttext = '<span class="LC_error">'.
11733: &mt('An error occurred: [_1]',$putresult).'</span>';
11734: }
11735: return $resulttext;
11736: }
11737:
11738: sub modify_contacts {
11739: my ($dom,$lastactref,%domconfig) = @_;
11740: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11741: if (ref($domconfig{'contacts'}) eq 'HASH') {
11742: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11743: $currsetting{$key} = $domconfig{'contacts'}{$key};
11744: }
11745: }
11746: my (%others,%to,%bcc,%includestr,%includeloc);
11747: my @contacts = ('supportemail','adminemail');
11748: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
11749: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
11750: my @toggles = ('reporterrors','reportupdates','reportstatus');
11751: my @lonstatus = ('threshold','sysmail','weights','excluded');
11752: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
11753: foreach my $type (@mailings) {
11754: @{$newsetting{$type}} =
11755: &Apache::loncommon::get_env_multiple('form.'.$type);
11756: foreach my $item (@contacts) {
11757: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11758: $contacts_hash{contacts}{$type}{$item} = 1;
11759: } else {
11760: $contacts_hash{contacts}{$type}{$item} = 0;
11761: }
11762: }
11763: $others{$type} = $env{'form.'.$type.'_others'};
11764: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
11765: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
11766: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11767: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
11768: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11769: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11770: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11771: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11772: }
11773: }
11774: }
11775: foreach my $item (@contacts) {
11776: $to{$item} = $env{'form.'.$item};
11777: $contacts_hash{'contacts'}{$item} = $to{$item};
11778: }
11779: foreach my $item (@toggles) {
11780: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11781: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11782: }
11783: }
11784: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
11785: foreach my $item (@lonstatus) {
11786: if ($item eq 'excluded') {
11787: my (%serverhomes,@excluded);
11788: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
11789: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
11790: if (@possexcluded) {
11791: foreach my $id (sort(@possexcluded)) {
11792: if ($serverhomes{$id}) {
11793: push(@excluded,$id);
11794: }
11795: }
11796: }
11797: if (@excluded) {
11798: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
11799: }
11800: } elsif ($item eq 'weights') {
11801: foreach my $type ('E','W','N','U') {
11802: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
11803: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
11804: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
11805: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
11806: $env{'form.error'.$item.'_'.$type};
11807: }
11808: }
11809: }
11810: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
11811: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
11812: if ($env{'form.error'.$item} =~ /^\d+$/) {
11813: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
11814: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
11815: }
11816: }
11817: }
11818: }
11819: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11820: foreach my $field (@{$fields}) {
11821: if (ref($possoptions->{$field}) eq 'ARRAY') {
11822: my $value = $env{'form.helpform_'.$field};
11823: $value =~ s/^\s+|\s+$//g;
11824: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
11825: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
11826: if ($field eq 'screenshot') {
11827: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11828: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
11829: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
11830: }
11831: }
11832: }
11833: }
11834: }
11835: }
11836: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11837: my (@statuses,%usertypeshash,@overrides);
11838: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
11839: @statuses = @{$types};
11840: if (ref($usertypes) eq 'HASH') {
11841: %usertypeshash = %{$usertypes};
11842: }
11843: }
11844: if (@statuses) {
11845: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
11846: foreach my $type (@possoverrides) {
11847: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
11848: push(@overrides,$type);
11849: }
11850: }
11851: if (@overrides) {
11852: foreach my $type (@overrides) {
11853: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
11854: foreach my $item (@contacts) {
11855: if (grep(/^\Q$item\E$/,@standard)) {
11856: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
11857: $newsetting{'override_'.$type}{$item} = 1;
11858: } else {
11859: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
11860: $newsetting{'override_'.$type}{$item} = 0;
11861: }
11862: }
11863: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
11864: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11865: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
11866: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
11867: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
11868: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
11869: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
11870: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11871: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
11872: }
11873: }
11874: }
11875: }
11876: if (keys(%currsetting) > 0) {
11877: foreach my $item (@contacts) {
11878: if ($to{$item} ne $currsetting{$item}) {
11879: $changes{$item} = 1;
11880: }
11881: }
11882: foreach my $type (@mailings) {
11883: foreach my $item (@contacts) {
11884: if (ref($currsetting{$type}) eq 'HASH') {
11885: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11886: push(@{$changes{$type}},$item);
11887: }
11888: } else {
11889: push(@{$changes{$type}},@{$newsetting{$type}});
11890: }
11891: }
11892: if ($others{$type} ne $currsetting{$type}{'others'}) {
11893: push(@{$changes{$type}},'others');
11894: }
11895: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
11896: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11897: push(@{$changes{$type}},'bcc');
11898: }
11899: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11900: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11901: push(@{$changes{$type}},'include');
11902: }
11903: }
11904: }
11905: if (ref($fields) eq 'ARRAY') {
11906: if (ref($currsetting{'helpform'}) eq 'HASH') {
11907: foreach my $field (@{$fields}) {
11908: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11909: push(@{$changes{'helpform'}},$field);
11910: }
11911: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11912: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11913: push(@{$changes{'helpform'}},'maxsize');
11914: }
11915: }
11916: }
11917: } else {
11918: foreach my $field (@{$fields}) {
11919: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11920: push(@{$changes{'helpform'}},$field);
11921: }
11922: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11923: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11924: push(@{$changes{'helpform'}},'maxsize');
11925: }
11926: }
11927: }
11928: }
11929: }
11930: if (@statuses) {
11931: if (ref($currsetting{'overrides'}) eq 'HASH') {
11932: foreach my $key (keys(%{$currsetting{'overrides'}})) {
11933: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
11934: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
11935: foreach my $item (@contacts,'bcc','others','include') {
11936: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
11937: push(@{$changes{'overrides'}},$key);
11938: last;
11939: }
11940: }
11941: } else {
11942: push(@{$changes{'overrides'}},$key);
11943: }
11944: }
11945: }
11946: foreach my $key (@overrides) {
11947: unless (exists($currsetting{'overrides'}{$key})) {
11948: push(@{$changes{'overrides'}},$key);
11949: }
11950: }
11951: } else {
11952: foreach my $key (@overrides) {
11953: push(@{$changes{'overrides'}},$key);
11954: }
11955: }
11956: }
11957: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
11958: foreach my $key ('excluded','weights','threshold','sysmail') {
11959: if ($key eq 'excluded') {
11960: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
11961: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
11962: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
11963: (@{$currsetting{'lonstatus'}{$key}})) {
11964: my @diffs =
11965: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
11966: $currsetting{'lonstatus'}{$key});
11967: if (@diffs) {
11968: push(@{$changes{'lonstatus'}},$key);
11969: }
11970: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
11971: push(@{$changes{'lonstatus'}},$key);
11972: }
11973: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
11974: (@{$currsetting{'lonstatus'}{$key}})) {
11975: push(@{$changes{'lonstatus'}},$key);
11976: }
11977: } elsif ($key eq 'weights') {
11978: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
11979: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
11980: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
11981: foreach my $type ('E','W','N','U') {
11982: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
11983: $currsetting{'lonstatus'}{$key}{$type}) {
11984: push(@{$changes{'lonstatus'}},$key);
11985: last;
11986: }
11987: }
11988: } else {
11989: foreach my $type ('E','W','N','U') {
11990: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
11991: push(@{$changes{'lonstatus'}},$key);
11992: last;
11993: }
11994: }
11995: }
11996: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
11997: foreach my $type ('E','W','N','U') {
11998: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
11999: push(@{$changes{'lonstatus'}},$key);
12000: last;
12001: }
12002: }
12003: }
12004: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
12005: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12006: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12007: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
12008: push(@{$changes{'lonstatus'}},$key);
12009: }
12010: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
12011: push(@{$changes{'lonstatus'}},$key);
12012: }
12013: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
12014: push(@{$changes{'lonstatus'}},$key);
12015: }
12016: }
12017: }
12018: } else {
12019: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12020: foreach my $key ('excluded','weights','threshold','sysmail') {
12021: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12022: push(@{$changes{'lonstatus'}},$key);
12023: }
12024: }
12025: }
12026: }
12027: } else {
12028: my %default;
12029: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12030: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12031: $default{'errormail'} = 'adminemail';
12032: $default{'packagesmail'} = 'adminemail';
12033: $default{'helpdeskmail'} = 'supportemail';
12034: $default{'otherdomsmail'} = 'supportemail';
12035: $default{'lonstatusmail'} = 'adminemail';
12036: $default{'requestsmail'} = 'adminemail';
12037: $default{'updatesmail'} = 'adminemail';
12038: $default{'hostipmail'} = 'adminemail';
12039: foreach my $item (@contacts) {
12040: if ($to{$item} ne $default{$item}) {
12041: $changes{$item} = 1;
12042: }
12043: }
12044: foreach my $type (@mailings) {
12045: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12046: push(@{$changes{$type}},@{$newsetting{$type}});
12047: }
12048: if ($others{$type} ne '') {
12049: push(@{$changes{$type}},'others');
12050: }
12051: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12052: if ($bcc{$type} ne '') {
12053: push(@{$changes{$type}},'bcc');
12054: }
12055: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12056: push(@{$changes{$type}},'include');
12057: }
12058: }
12059: }
12060: if (ref($fields) eq 'ARRAY') {
12061: foreach my $field (@{$fields}) {
12062: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12063: push(@{$changes{'helpform'}},$field);
12064: }
12065: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12066: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12067: push(@{$changes{'helpform'}},'maxsize');
12068: }
12069: }
12070: }
12071: }
12072: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
12073: foreach my $key ('excluded','weights','threshold','sysmail') {
12074: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
12075: push(@{$changes{'lonstatus'}},$key);
12076: }
12077: }
12078: }
12079: }
12080: foreach my $item (@toggles) {
12081: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12082: $changes{$item} = 1;
12083: } elsif ((!$env{'form.'.$item}) &&
12084: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12085: $changes{$item} = 1;
12086: }
12087: }
12088: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12089: $dom);
12090: if ($putresult eq 'ok') {
12091: if (keys(%changes) > 0) {
12092: &Apache::loncommon::devalidate_domconfig_cache($dom);
12093: if (ref($lastactref) eq 'HASH') {
12094: $lastactref->{'domainconfig'} = 1;
12095: }
12096: my ($titles,$short_titles) = &contact_titles();
12097: $resulttext = &mt('Changes made:').'<ul>';
12098: foreach my $item (@contacts) {
12099: if ($changes{$item}) {
12100: $resulttext .= '<li>'.$titles->{$item}.
12101: &mt(' set to: ').
12102: '<span class="LC_cusr_emph">'.
12103: $to{$item}.'</span></li>';
12104: }
12105: }
12106: foreach my $type (@mailings) {
12107: if (ref($changes{$type}) eq 'ARRAY') {
12108: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12109: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
12110: } else {
12111: $resulttext .= '<li>'.$titles->{$type}.': ';
12112: }
12113: my @text;
12114: foreach my $item (@{$newsetting{$type}}) {
12115: push(@text,$short_titles->{$item});
12116: }
12117: if ($others{$type} ne '') {
12118: push(@text,$others{$type});
12119: }
12120: if (@text) {
12121: $resulttext .= '<span class="LC_cusr_emph">'.
12122: join(', ',@text).'</span>';
12123: }
12124: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
12125: if ($bcc{$type} ne '') {
12126: my $bcctext;
12127: if (@text) {
12128: $bcctext = ' '.&mt('with Bcc to');
12129: } else {
12130: $bcctext = '(Bcc)';
12131: }
12132: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12133: } elsif (!@text) {
12134: $resulttext .= &mt('No one');
12135: }
12136: if ($includestr{$type} ne '') {
12137: if ($includeloc{$type} eq 'b') {
12138: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12139: } elsif ($includeloc{$type} eq 's') {
12140: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12141: }
12142: }
12143: } elsif (!@text) {
12144: $resulttext .= &mt('No recipients');
12145: }
12146: $resulttext .= '</li>';
12147: }
12148: }
12149: if (ref($changes{'overrides'}) eq 'ARRAY') {
12150: my @deletions;
12151: foreach my $type (@{$changes{'overrides'}}) {
12152: if ($usertypeshash{$type}) {
12153: if (grep(/^\Q$type\E/,@overrides)) {
12154: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12155: $usertypeshash{$type}).'<ul><li>';
12156: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12157: my @text;
12158: foreach my $item (@contacts) {
12159: if ($newsetting{'override_'.$type}{$item}) {
12160: push(@text,$short_titles->{$item});
12161: }
12162: }
12163: if ($newsetting{'override_'.$type}{'others'} ne '') {
12164: push(@text,$newsetting{'override_'.$type}{'others'});
12165: }
12166:
12167: if (@text) {
12168: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12169: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12170: }
12171: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12172: my $bcctext;
12173: if (@text) {
12174: $bcctext = ' '.&mt('with Bcc to');
12175: } else {
12176: $bcctext = '(Bcc)';
12177: }
12178: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12179: } elsif (!@text) {
12180: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12181: }
12182: $resulttext .= '</li>';
12183: if ($newsetting{'override_'.$type}{'include'} ne '') {
12184: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12185: if ($loc eq 'b') {
12186: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12187: } elsif ($loc eq 's') {
12188: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12189: }
12190: }
12191: }
12192: $resulttext .= '</li></ul></li>';
12193: } else {
12194: push(@deletions,$usertypeshash{$type});
12195: }
12196: }
12197: }
12198: if (@deletions) {
12199: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12200: join(', ',@deletions)).'</li>';
12201: }
12202: }
12203: my @offon = ('off','on');
12204: my $corelink = &core_link_msu();
12205: if ($changes{'reporterrors'}) {
12206: $resulttext .= '<li>'.
12207: &mt('E-mail error reports to [_1] set to "'.
12208: $offon[$env{'form.reporterrors'}].'".',
12209: $corelink).
12210: '</li>';
12211: }
12212: if ($changes{'reportupdates'}) {
12213: $resulttext .= '<li>'.
12214: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12215: $offon[$env{'form.reportupdates'}].'".',
12216: $corelink).
12217: '</li>';
12218: }
12219: if ($changes{'reportstatus'}) {
12220: $resulttext .= '<li>'.
12221: &mt('E-mail status if errors above threshold to [_1] set to "'.
12222: $offon[$env{'form.reportstatus'}].'".',
12223: $corelink).
12224: '</li>';
12225: }
12226: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
12227: $resulttext .= '<li>'.
12228: &mt('Nightly status check e-mail settings').':<ul>';
12229: my (%defval,%use_def,%shown);
12230: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
12231: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
12232: $defval{'weights'} =
12233: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
12234: $defval{'excluded'} = &mt('None');
12235: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
12236: foreach my $item ('threshold','sysmail','weights','excluded') {
12237: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
12238: if (($item eq 'threshold') || ($item eq 'sysmail')) {
12239: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
12240: } elsif ($item eq 'weights') {
12241: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
12242: foreach my $type ('E','W','N','U') {
12243: $shown{$item} .= $lonstatus_names->{$type}.'=';
12244: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
12245: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
12246: } else {
12247: $shown{$item} .= $lonstatus_defs->{$type};
12248: }
12249: $shown{$item} .= ', ';
12250: }
12251: $shown{$item} =~ s/, $//;
12252: } else {
12253: $shown{$item} = $defval{$item};
12254: }
12255: } elsif ($item eq 'excluded') {
12256: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
12257: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
12258: } else {
12259: $shown{$item} = $defval{$item};
12260: }
12261: }
12262: } else {
12263: $shown{$item} = $defval{$item};
12264: }
12265: }
12266: } else {
12267: foreach my $item ('threshold','weights','excluded','sysmail') {
12268: $shown{$item} = $defval{$item};
12269: }
12270: }
12271: foreach my $item ('threshold','weights','excluded','sysmail') {
12272: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
12273: $shown{$item}).'</li>';
12274: }
12275: $resulttext .= '</ul></li>';
12276: }
12277: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12278: my (@optional,@required,@unused,$maxsizechg);
12279: foreach my $field (@{$changes{'helpform'}}) {
12280: if ($field eq 'maxsize') {
12281: $maxsizechg = 1;
12282: next;
12283: }
12284: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
12285: push(@optional,$field);
12286: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12287: push(@unused,$field);
12288: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
12289: push(@required,$field);
12290: }
12291: }
12292: if (@optional) {
12293: $resulttext .= '<li>'.
12294: &mt('Help form fields changed to "Optional": [_1].',
12295: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12296: '</li>';
12297: }
12298: if (@required) {
12299: $resulttext .= '<li>'.
12300: &mt('Help form fields changed to "Required": [_1].',
12301: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12302: '</li>';
12303: }
12304: if (@unused) {
12305: $resulttext .= '<li>'.
12306: &mt('Help form fields changed to "Not shown": [_1].',
12307: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12308: '</li>';
12309: }
12310: if ($maxsizechg) {
12311: $resulttext .= '<li>'.
12312: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12313: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12314: '</li>';
12315: }
12316: }
12317: $resulttext .= '</ul>';
12318: } else {
12319: $resulttext = &mt('No changes made to contacts and form settings');
12320: }
12321: } else {
12322: $resulttext = '<span class="LC_error">'.
12323: &mt('An error occurred: [_1].',$putresult).'</span>';
12324: }
12325: return $resulttext;
12326: }
12327:
12328: sub modify_passwords {
12329: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12330: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
12331: $updatedefaults,$updateconf);
12332: my $customfn = 'resetpw.html';
12333: if (ref($domconfig{'passwords'}) eq 'HASH') {
12334: %current = %{$domconfig{'passwords'}};
12335: }
12336: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12337: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12338: if (ref($types) eq 'ARRAY') {
12339: @oktypes = @{$types};
12340: }
12341: push(@oktypes,'default');
12342:
12343: my %titles = &Apache::lonlocal::texthash (
12344: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
12345: intauth_check => 'Check bcrypt cost if authenticated',
12346: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
12347: permanent => 'Permanent e-mail address',
12348: critical => 'Critical notification address',
12349: notify => 'Notification address',
12350: min => 'Minimum password length',
12351: max => 'Maximum password length',
12352: chars => 'Required characters',
12353: numsaved => 'Number of previous passwords to save',
12354: reset => 'Resetting Forgotten Password',
12355: intauth => 'Encryption of Stored Passwords (Internal Auth)',
12356: rules => 'Rules for LON-CAPA Passwords',
12357: crsownerchg => 'Course Owner Changing Student Passwords',
12358: username => 'Username',
12359: email => 'E-mail address',
12360: );
12361:
12362: #
12363: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
12364: #
12365: my (%curr_defaults,%save_defaults);
12366: if (ref($domconfig{'defaults'}) eq 'HASH') {
12367: foreach my $key (keys(%{$domconfig{'defaults'}})) {
12368: if ($key =~ /^intauth_(cost|check|switch)$/) {
12369: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
12370: } else {
12371: $save_defaults{$key} = $domconfig{'defaults'}{$key};
12372: }
12373: }
12374: }
12375: my %staticdefaults = (
12376: 'resetlink' => 2,
12377: 'resetcase' => \@oktypes,
12378: 'resetprelink' => 'both',
12379: 'resetemail' => ['critical','notify','permanent'],
12380: 'intauth_cost' => 10,
12381: 'intauth_check' => 0,
12382: 'intauth_switch' => 0,
12383: );
12384: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
12385: foreach my $type (@oktypes) {
12386: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
12387: }
12388: my $linklife = $env{'form.passwords_link'};
12389: $linklife =~ s/^\s+|\s+$//g;
12390: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
12391: $newvalues{'resetlink'} = $linklife;
12392: if ($current{'resetlink'}) {
12393: if ($current{'resetlink'} ne $linklife) {
12394: $changes{'reset'} = 1;
12395: }
12396: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12397: if ($staticdefaults{'resetlink'} ne $linklife) {
12398: $changes{'reset'} = 1;
12399: }
12400: }
12401: } elsif ($current{'resetlink'}) {
12402: $changes{'reset'} = 1;
12403: }
12404: my @casesens;
12405: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
12406: foreach my $case (sort(@posscase)) {
12407: if (grep(/^\Q$case\E$/,@oktypes)) {
12408: push(@casesens,$case);
12409: }
12410: }
12411: $newvalues{'resetcase'} = \@casesens;
12412: if (ref($current{'resetcase'}) eq 'ARRAY') {
12413: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
12414: if (@diffs > 0) {
12415: $changes{'reset'} = 1;
12416: }
12417: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12418: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
12419: if (@diffs > 0) {
12420: $changes{'reset'} = 1;
12421: }
12422: }
12423: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
12424: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
12425: if (exists($current{'resetprelink'})) {
12426: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
12427: $changes{'reset'} = 1;
12428: }
12429: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12430: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
12431: $changes{'reset'} = 1;
12432: }
12433: }
12434: } elsif ($current{'resetprelink'}) {
12435: $changes{'reset'} = 1;
12436: }
12437: foreach my $type (@oktypes) {
12438: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
12439: my @postlink;
12440: foreach my $item (sort(@possplink)) {
12441: if ($item =~ /^(email|username)$/) {
12442: push(@postlink,$item);
12443: }
12444: }
12445: $newvalues{'resetpostlink'}{$type} = \@postlink;
12446: unless ($changes{'reset'}) {
12447: if (ref($current{'resetpostlink'}) eq 'HASH') {
12448: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
12449: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
12450: if (@diffs > 0) {
12451: $changes{'reset'} = 1;
12452: }
12453: } else {
12454: $changes{'reset'} = 1;
12455: }
12456: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12457: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
12458: if (@diffs > 0) {
12459: $changes{'reset'} = 1;
12460: }
12461: }
12462: }
12463: }
12464: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
12465: my @resetemail;
12466: foreach my $item (sort(@possemailsrc)) {
12467: if ($item =~ /^(permanent|critical|notify)$/) {
12468: push(@resetemail,$item);
12469: }
12470: }
12471: $newvalues{'resetemail'} = \@resetemail;
12472: unless ($changes{'reset'}) {
12473: if (ref($current{'resetemail'}) eq 'ARRAY') {
12474: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
12475: if (@diffs > 0) {
12476: $changes{'reset'} = 1;
12477: }
12478: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
12479: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
12480: if (@diffs > 0) {
12481: $changes{'reset'} = 1;
12482: }
12483: }
12484: }
12485: if ($env{'form.passwords_stdtext'} == 0) {
12486: $newvalues{'resetremove'} = 1;
12487: unless ($current{'resetremove'}) {
12488: $changes{'reset'} = 1;
12489: }
12490: } elsif ($current{'resetremove'}) {
12491: $changes{'reset'} = 1;
12492: }
12493: if ($env{'form.passwords_customfile.filename'} ne '') {
12494: my $servadm = $r->dir_config('lonAdmEMail');
12495: my $servadm = $r->dir_config('lonAdmEMail');
12496: my ($configuserok,$author_ok,$switchserver) =
12497: &config_check($dom,$confname,$servadm);
12498: my $error;
12499: if ($configuserok eq 'ok') {
12500: if ($switchserver) {
12501: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
12502: } else {
12503: if ($author_ok eq 'ok') {
12504: my ($result,$customurl) =
12505: &publishlogo($r,'upload','passwords_customfile',$dom,
12506: $confname,'customtext/resetpw','','',$customfn);
12507: if ($result eq 'ok') {
12508: $newvalues{'resetcustom'} = $customurl;
12509: $changes{'reset'} = 1;
12510: } else {
12511: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
12512: }
12513: } else {
12514: $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);
12515: }
12516: }
12517: } else {
12518: $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);
12519: }
12520: if ($error) {
12521: &Apache::lonnet::logthis($error);
12522: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12523: }
12524: } elsif ($current{'resetcustom'}) {
12525: if ($env{'form.passwords_custom_del'}) {
12526: $changes{'reset'} = 1;
12527: } else {
12528: $newvalues{'resetcustom'} = $current{'resetcustom'};
12529: }
12530: }
12531: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
12532: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
12533: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
12534: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
12535: $changes{'intauth'} = 1;
12536: }
12537: } else {
12538: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
12539: }
12540: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
12541: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
12542: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
12543: $changes{'intauth'} = 1;
12544: }
12545: } else {
12546: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12547: }
12548: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
12549: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
12550: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
12551: $changes{'intauth'} = 1;
12552: }
12553: } else {
12554: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
12555: }
12556: foreach my $item ('cost','check','switch') {
12557: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
12558: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
12559: $updatedefaults = 1;
12560: }
12561: }
12562: foreach my $rule ('min','max','numsaved') {
12563: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
12564: my $ruleok;
12565: if ($rule eq 'min') {
12566: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
12567: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
12568: $ruleok = 1;
12569: }
12570: }
12571: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
12572: ($env{'form.passwords_'.$rule} ne '0')) {
12573: $ruleok = 1;
12574: }
12575: if ($ruleok) {
12576: $newvalues{$rule} = $env{'form.passwords_'.$rule};
12577: if (exists($current{$rule})) {
12578: if ($newvalues{$rule} ne $current{$rule}) {
12579: $changes{'rules'} = 1;
12580: }
12581: } elsif ($rule eq 'min') {
12582: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
12583: $changes{'rules'} = 1;
12584: }
12585: } else {
12586: $changes{'rules'} = 1;
12587: }
12588: } elsif (exists($current{$rule})) {
12589: $changes{'rules'} = 1;
12590: }
12591: }
12592: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
12593: my @chars;
12594: foreach my $item (sort(@posschars)) {
12595: if ($item =~ /^(uc|lc|num|spec)$/) {
12596: push(@chars,$item);
12597: }
12598: }
12599: $newvalues{'chars'} = \@chars;
12600: unless ($changes{'rules'}) {
12601: if (ref($current{'chars'}) eq 'ARRAY') {
12602: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
12603: if (@diffs > 0) {
12604: $changes{'rules'} = 1;
12605: }
12606: } else {
12607: if (@chars > 0) {
12608: $changes{'rules'} = 1;
12609: }
12610: }
12611: }
12612: my %crsownerchg = (
12613: by => [],
12614: for => [],
12615: );
12616: foreach my $item ('by','for') {
12617: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
12618: foreach my $type (sort(@posstypes)) {
12619: if (grep(/^\Q$type\E$/,@oktypes)) {
12620: push(@{$crsownerchg{$item}},$type);
12621: }
12622: }
12623: }
12624: $newvalues{'crsownerchg'} = \%crsownerchg;
12625: if (ref($current{'crsownerchg'}) eq 'HASH') {
12626: foreach my $item ('by','for') {
12627: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
12628: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
12629: if (@diffs > 0) {
12630: $changes{'crsownerchg'} = 1;
12631: last;
12632: }
12633: }
12634: }
12635: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
12636: foreach my $item ('by','for') {
12637: if (@{$crsownerchg{$item}} > 0) {
12638: $changes{'crsownerchg'} = 1;
12639: last;
12640: }
12641: }
12642: }
12643:
12644: my %confighash = (
12645: defaults => \%save_defaults,
12646: passwords => \%newvalues,
12647: );
12648: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
12649:
12650: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
12651: if ($putresult eq 'ok') {
12652: if (keys(%changes) > 0) {
12653: $resulttext = &mt('Changes made: ').'<ul>';
12654: foreach my $key ('reset','intauth','rules','crsownerchg') {
12655: if ($changes{$key}) {
12656: unless ($key eq 'intauth') {
12657: $updateconf = 1;
12658: }
12659: $resulttext .= '<li>'.$titles{$key}.':<ul>';
12660: if ($key eq 'reset') {
12661: if ($confighash{'passwords'}{'captcha'} eq 'original') {
12662: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
12663: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
12664: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
12665: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
12666: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
12667: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
12668: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
12669: }
12670: } else {
12671: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
12672: }
12673: if ($confighash{'passwords'}{'resetlink'}) {
12674: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
12675: } else {
12676: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
12677: &mt('Will default to 2 hours').'</li>';
12678: }
12679: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
12680: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
12681: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
12682: } else {
12683: my $casesens;
12684: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
12685: if ($type eq 'default') {
12686: $casesens .= $othertitle.', ';
12687: } elsif ($usertypes->{$type} ne '') {
12688: $casesens .= $usertypes->{$type}.', ';
12689: }
12690: }
12691: $casesens =~ s/\Q, \E$//;
12692: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
12693: }
12694: } else {
12695: $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>';
12696: }
12697: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
12698: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
12699: } else {
12700: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
12701: }
12702: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
12703: my $output;
12704: if (ref($types) eq 'ARRAY') {
12705: foreach my $type (@{$types}) {
12706: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
12707: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
12708: $output .= $usertypes->{$type}.' -- '.&mt('none');
12709: } else {
12710: $output .= $usertypes->{$type}.' -- '.
12711: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
12712: }
12713: }
12714: }
12715: }
12716: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
12717: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
12718: $output .= $othertitle.' -- '.&mt('none');
12719: } else {
12720: $output .= $othertitle.' -- '.
12721: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
12722: }
12723: }
12724: if ($output) {
12725: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
12726: } else {
12727: $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>';
12728: }
12729: } else {
12730: $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>';
12731: }
12732: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
12733: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
12734: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
12735: } else {
12736: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12737: }
12738: } else {
12739: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
12740: }
12741: if ($confighash{'passwords'}{'resetremove'}) {
12742: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
12743: } else {
12744: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
12745: }
12746: if ($confighash{'passwords'}{'resetcustom'}) {
12747: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
12748: &mt('custom text'),600,500,undef,undef,
12749: undef,undef,'background-color:#ffffff');
12750: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
12751: } else {
12752: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
12753: }
12754: } elsif ($key eq 'intauth') {
12755: foreach my $item ('cost','switch','check') {
12756: my $value = $save_defaults{$key.'_'.$item};
12757: if ($item eq 'switch') {
12758: my %optiondesc = &Apache::lonlocal::texthash (
12759: 0 => 'No',
12760: 1 => 'Yes',
12761: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12762: );
12763: if ($value =~ /^(0|1|2)$/) {
12764: $value = $optiondesc{$value};
12765: } else {
12766: $value = &mt('none -- defaults to No');
12767: }
12768: } elsif ($item eq 'check') {
12769: my %optiondesc = &Apache::lonlocal::texthash (
12770: 0 => 'No',
12771: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12772: 2 => 'Yes, disallow login if stored cost is less than domain default',
12773: );
12774: if ($value =~ /^(0|1|2)$/) {
12775: $value = $optiondesc{$value};
12776: } else {
12777: $value = &mt('none -- defaults to No');
12778: }
12779: }
12780: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
12781: }
12782: } elsif ($key eq 'rules') {
12783: foreach my $rule ('min','max','numsaved') {
12784: if ($confighash{'passwords'}{$rule} eq '') {
12785: if ($rule eq 'min') {
12786: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
12787: ' '.&mt('Default of [_1] will be used',
12788: $Apache::lonnet::passwdmin).'</li>';
12789: } else {
12790: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
12791: }
12792: } else {
12793: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
12794: }
12795: }
12796: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
12797: if (@{$confighash{'passwords'}{'chars'}} > 0) {
12798: my %rulenames = &Apache::lonlocal::texthash(
12799: uc => 'At least one upper case letter',
12800: lc => 'At least one lower case letter',
12801: num => 'At least one number',
12802: spec => 'At least one non-alphanumeric',
12803: );
12804: my $needed = '<ul><li>'.
12805: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
12806: '</li></ul>';
12807: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
12808: } else {
12809: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
12810: }
12811: } else {
12812: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
12813: }
12814: } elsif ($key eq 'crsownerchg') {
12815: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
12816: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
12817: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
12818: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
12819: } else {
12820: my %crsownerstr;
12821: foreach my $item ('by','for') {
12822: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
12823: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
12824: if ($type eq 'default') {
12825: $crsownerstr{$item} .= $othertitle.', ';
12826: } elsif ($usertypes->{$type} ne '') {
12827: $crsownerstr{$item} .= $usertypes->{$type}.', ';
12828: }
12829: }
12830: $crsownerstr{$item} =~ s/\Q, \E$//;
12831: }
12832: }
12833: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
12834: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
12835: }
12836: } else {
12837: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
12838: }
12839: }
12840: $resulttext .= '</ul></li>';
12841: }
12842: }
12843: $resulttext .= '</ul>';
12844: } else {
12845: $resulttext = &mt('No changes made to password settings');
12846: }
12847: my $cachetime = 24*60*60;
12848: if ($updatedefaults) {
12849: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12850: if (ref($lastactref) eq 'HASH') {
12851: $lastactref->{'domdefaults'} = 1;
12852: }
12853: }
12854: if ($updateconf) {
12855: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
12856: if (ref($lastactref) eq 'HASH') {
12857: $lastactref->{'passwdconf'} = 1;
12858: }
12859: }
12860: } else {
12861: $resulttext = '<span class="LC_error">'.
12862: &mt('An error occurred: [_1]',$putresult).'</span>';
12863: }
12864: if ($errors) {
12865: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12866: $errors.'</ul></p>';
12867: }
12868: return $resulttext;
12869: }
12870:
12871: sub modify_usercreation {
12872: my ($dom,%domconfig) = @_;
12873: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
12874: my $warningmsg;
12875: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12876: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
12877: if ($key eq 'cancreate') {
12878: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12879: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
12880: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
12881: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12882: } else {
12883: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12884: }
12885: }
12886: }
12887: } elsif ($key eq 'email_rule') {
12888: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12889: } else {
12890: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12891: }
12892: }
12893: }
12894: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
12895: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
12896: my @contexts = ('author','course','requestcrs');
12897: foreach my $item(@contexts) {
12898: $cancreate{$item} = $env{'form.can_createuser_'.$item};
12899: }
12900: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12901: foreach my $item (@contexts) {
12902: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
12903: push(@{$changes{'cancreate'}},$item);
12904: }
12905: }
12906: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
12907: foreach my $item (@contexts) {
12908: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
12909: if ($cancreate{$item} ne 'any') {
12910: push(@{$changes{'cancreate'}},$item);
12911: }
12912: } else {
12913: if ($cancreate{$item} ne 'none') {
12914: push(@{$changes{'cancreate'}},$item);
12915: }
12916: }
12917: }
12918: } else {
12919: foreach my $item (@contexts) {
12920: push(@{$changes{'cancreate'}},$item);
12921: }
12922: }
12923:
12924: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
12925: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
12926: if (!grep(/^\Q$type\E$/,@username_rule)) {
12927: push(@{$changes{'username_rule'}},$type);
12928: }
12929: }
12930: foreach my $type (@username_rule) {
12931: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
12932: push(@{$changes{'username_rule'}},$type);
12933: }
12934: }
12935: } else {
12936: push(@{$changes{'username_rule'}},@username_rule);
12937: }
12938:
12939: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
12940: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
12941: if (!grep(/^\Q$type\E$/,@id_rule)) {
12942: push(@{$changes{'id_rule'}},$type);
12943: }
12944: }
12945: foreach my $type (@id_rule) {
12946: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
12947: push(@{$changes{'id_rule'}},$type);
12948: }
12949: }
12950: } else {
12951: push(@{$changes{'id_rule'}},@id_rule);
12952: }
12953:
12954: my @authen_contexts = ('author','course','domain');
12955: my @authtypes = ('int','krb4','krb5','loc');
12956: my %authhash;
12957: foreach my $item (@authen_contexts) {
12958: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
12959: foreach my $auth (@authtypes) {
12960: if (grep(/^\Q$auth\E$/,@authallowed)) {
12961: $authhash{$item}{$auth} = 1;
12962: } else {
12963: $authhash{$item}{$auth} = 0;
12964: }
12965: }
12966: }
12967: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
12968: foreach my $item (@authen_contexts) {
12969: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
12970: foreach my $auth (@authtypes) {
12971: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
12972: push(@{$changes{'authtypes'}},$item);
12973: last;
12974: }
12975: }
12976: }
12977: }
12978: } else {
12979: foreach my $item (@authen_contexts) {
12980: push(@{$changes{'authtypes'}},$item);
12981: }
12982: }
12983:
12984: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
12985: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
12986: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
12987: $save_usercreate{'id_rule'} = \@id_rule;
12988: $save_usercreate{'username_rule'} = \@username_rule,
12989: $save_usercreate{'authtypes'} = \%authhash;
12990:
12991: my %usercreation_hash = (
12992: usercreation => \%save_usercreate,
12993: );
12994:
12995: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
12996: $dom);
12997:
12998: if ($putresult eq 'ok') {
12999: if (keys(%changes) > 0) {
13000: $resulttext = &mt('Changes made:').'<ul>';
13001: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13002: my %lt = &usercreation_types();
13003: foreach my $type (@{$changes{'cancreate'}}) {
13004: my $chgtext = $lt{$type}.', ';
13005: if ($cancreate{$type} eq 'none') {
13006: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13007: } elsif ($cancreate{$type} eq 'any') {
13008: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13009: } elsif ($cancreate{$type} eq 'official') {
13010: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13011: } elsif ($cancreate{$type} eq 'unofficial') {
13012: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13013: }
13014: $resulttext .= '<li>'.$chgtext.'</li>';
13015: }
13016: }
13017: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13018: my ($rules,$ruleorder) =
13019: &Apache::lonnet::inst_userrules($dom,'username');
13020: my $chgtext = '<ul>';
13021: foreach my $type (@username_rule) {
13022: if (ref($rules->{$type}) eq 'HASH') {
13023: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13024: }
13025: }
13026: $chgtext .= '</ul>';
13027: if (@username_rule > 0) {
13028: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13029: } else {
13030: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13031: }
13032: }
13033: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13034: my ($idrules,$idruleorder) =
13035: &Apache::lonnet::inst_userrules($dom,'id');
13036: my $chgtext = '<ul>';
13037: foreach my $type (@id_rule) {
13038: if (ref($idrules->{$type}) eq 'HASH') {
13039: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13040: }
13041: }
13042: $chgtext .= '</ul>';
13043: if (@id_rule > 0) {
13044: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13045: } else {
13046: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13047: }
13048: }
13049: my %authname = &authtype_names();
13050: my %context_title = &context_names();
13051: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13052: my $chgtext = '<ul>';
13053: foreach my $type (@{$changes{'authtypes'}}) {
13054: my @allowed;
13055: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13056: foreach my $auth (@authtypes) {
13057: if ($authhash{$type}{$auth}) {
13058: push(@allowed,$authname{$auth});
13059: }
13060: }
13061: if (@allowed > 0) {
13062: $chgtext .= join(', ',@allowed).'</li>';
13063: } else {
13064: $chgtext .= &mt('none').'</li>';
13065: }
13066: }
13067: $chgtext .= '</ul>';
13068: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13069: $resulttext .= '</li>';
13070: }
13071: $resulttext .= '</ul>';
13072: } else {
13073: $resulttext = &mt('No changes made to user creation settings');
13074: }
13075: } else {
13076: $resulttext = '<span class="LC_error">'.
13077: &mt('An error occurred: [_1]',$putresult).'</span>';
13078: }
13079: if ($warningmsg ne '') {
13080: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13081: }
13082: return $resulttext;
13083: }
13084:
13085: sub modify_selfcreation {
13086: my ($dom,$lastactref,%domconfig) = @_;
13087: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13088: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13089: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13090: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13091: if (ref($typesref) eq 'ARRAY') {
13092: @types = @{$typesref};
13093: }
13094: if (ref($usertypesref) eq 'HASH') {
13095: %usertypes = %{$usertypesref};
13096: }
13097: $usertypes{'default'} = $othertitle;
13098: #
13099: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13100: #
13101: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13102: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13103: if ($key eq 'cancreate') {
13104: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13105: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13106: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
13107: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13108: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13109: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13110: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
13111: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
13112: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13113: } else {
13114: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13115: }
13116: }
13117: }
13118: } elsif ($key eq 'email_rule') {
13119: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13120: } else {
13121: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13122: }
13123: }
13124: }
13125: #
13126: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13127: #
13128: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13129: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13130: if ($key eq 'selfcreate') {
13131: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13132: } else {
13133: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13134: }
13135: }
13136: }
13137: #
13138: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13139: #
13140: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13141: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13142: if ($key eq 'inststatusguest') {
13143: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13144: } else {
13145: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13146: }
13147: }
13148: }
13149:
13150: my @contexts = ('selfcreate');
13151: @{$cancreate{'selfcreate'}} = ();
13152: %{$cancreate{'emailusername'}} = ();
13153: if (@types) {
13154: @{$cancreate{'statustocreate'}} = ();
13155: }
13156: %{$cancreate{'selfcreateprocessing'}} = ();
13157: %{$cancreate{'shibenv'}} = ();
13158: %{$cancreate{'emailverified'}} = ();
13159: %{$cancreate{'emailoptions'}} = ();
13160: %{$cancreate{'emaildomain'}} = ();
13161: my %selfcreatetypes = (
13162: sso => 'users authenticated by institutional single sign on',
13163: login => 'users authenticated by institutional log-in',
13164: email => 'users verified by e-mail',
13165: );
13166: #
13167: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13168: # is permitted.
13169: #
13170:
13171: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
13172:
13173: my (@statuses,%email_rule);
13174: foreach my $item ('login','sso','email') {
13175: if ($item eq 'email') {
13176: if ($env{'form.cancreate_email'}) {
13177: if (@types) {
13178: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13179: foreach my $status (@poss_statuses) {
13180: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13181: push(@statuses,$status);
13182: }
13183: }
13184: $save_inststatus{'inststatusguest'} = \@statuses;
13185: } else {
13186: push(@statuses,'default');
13187: }
13188: if (@statuses) {
13189: my %curr_rule;
13190: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13191: foreach my $type (@statuses) {
13192: $curr_rule{$type} = $curr_usercreation{'email_rule'};
13193: }
13194: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13195: foreach my $type (@statuses) {
13196: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13197: }
13198: }
13199: push(@{$cancreate{'selfcreate'}},'email');
13200: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13201: my %curremaildom;
13202: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13203: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13204: }
13205: foreach my $type (@statuses) {
13206: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13207: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13208: }
13209: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13210: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13211: }
13212: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13213: #
13214: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13215: #
13216: my $chosen = $1;
13217: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13218: my $emaildom;
13219: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13220: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13221: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13222: if (ref($curremaildom{$type}) eq 'HASH') {
13223: if (exists($curremaildom{$type}{$chosen})) {
13224: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13225: push(@{$changes{'cancreate'}},'emaildomain');
13226: }
13227: } elsif ($emaildom ne '') {
13228: push(@{$changes{'cancreate'}},'emaildomain');
13229: }
13230: } elsif ($emaildom ne '') {
13231: push(@{$changes{'cancreate'}},'emaildomain');
13232: }
13233: }
13234: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13235: } elsif ($chosen eq 'custom') {
13236: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13237: $email_rule{$type} = [];
13238: if (ref($emailrules) eq 'HASH') {
13239: foreach my $rule (@possemail_rules) {
13240: if (exists($emailrules->{$rule})) {
13241: push(@{$email_rule{$type}},$rule);
13242: }
13243: }
13244: }
13245: if (@{$email_rule{$type}}) {
13246: $cancreate{'emailoptions'}{$type} = 'custom';
13247: if (ref($curr_rule{$type}) eq 'ARRAY') {
13248: if (@{$curr_rule{$type}} > 0) {
13249: foreach my $rule (@{$curr_rule{$type}}) {
13250: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13251: push(@{$changes{'email_rule'}},$type);
13252: }
13253: }
13254: }
13255: foreach my $type (@{$email_rule{$type}}) {
13256: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13257: push(@{$changes{'email_rule'}},$type);
13258: }
13259: }
13260: } else {
13261: push(@{$changes{'email_rule'}},$type);
13262: }
13263: }
13264: } else {
13265: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13266: }
13267: }
13268: }
13269: if (@types) {
13270: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13271: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13272: if (@changed) {
13273: push(@{$changes{'inststatus'}},'inststatusguest');
13274: }
13275: } else {
13276: push(@{$changes{'inststatus'}},'inststatusguest');
13277: }
13278: }
13279: } else {
13280: delete($env{'form.cancreate_email'});
13281: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13282: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13283: push(@{$changes{'inststatus'}},'inststatusguest');
13284: }
13285: }
13286: }
13287: } else {
13288: $save_inststatus{'inststatusguest'} = [];
13289: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13290: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13291: push(@{$changes{'inststatus'}},'inststatusguest');
13292: }
13293: }
13294: }
13295: } else {
13296: if ($env{'form.cancreate_'.$item}) {
13297: push(@{$cancreate{'selfcreate'}},$item);
13298: }
13299: }
13300: }
13301: my (%userinfo,%savecaptcha);
13302: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13303: #
13304: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13305: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
13306: #
13307:
13308: if ($env{'form.cancreate_email'}) {
13309: push(@contexts,'emailusername');
13310: if (@statuses) {
13311: foreach my $type (@statuses) {
13312: if (ref($infofields) eq 'ARRAY') {
13313: foreach my $field (@{$infofields}) {
13314: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13315: $cancreate{'emailusername'}{$type}{$field} = $1;
13316: }
13317: }
13318: }
13319: }
13320: }
13321: #
13322: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
13323: # queued requests for self-creation of account verified by e-mail.
13324: #
13325:
13326: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13327: @approvalnotify = sort(@approvalnotify);
13328: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13329: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13330: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13331: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13332: push(@{$changes{'cancreate'}},'notify');
13333: }
13334: } else {
13335: if ($cancreate{'notify'}{'approval'}) {
13336: push(@{$changes{'cancreate'}},'notify');
13337: }
13338: }
13339: } elsif ($cancreate{'notify'}{'approval'}) {
13340: push(@{$changes{'cancreate'}},'notify');
13341: }
13342:
13343: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13344: }
13345: #
13346: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
13347: # institutional log-in.
13348: #
13349: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13350: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13351: ($domdefaults{'auth_def'} eq 'localauth'))) {
13352: $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.').' '.
13353: &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.');
13354: }
13355: }
13356: my @fields = ('lastname','firstname','middlename','generation',
13357: 'permanentemail','id');
13358: my @shibfields = (@fields,'inststatus');
13359: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13360: #
13361: # Where usernames may created for institutional log-in and/or institutional single sign on:
13362: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13363: # may self-create accounts
13364: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13365: # which the user may supply, if institutional data is unavailable.
13366: #
13367: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
13368: if (@types) {
13369: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13370: push(@contexts,'statustocreate');
13371: foreach my $type (@types) {
13372: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13373: foreach my $field (@fields) {
13374: if (grep(/^\Q$field\E$/,@modifiable)) {
13375: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13376: } else {
13377: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13378: }
13379: }
13380: }
13381: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
13382: foreach my $type (@types) {
13383: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13384: foreach my $field (@fields) {
13385: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13386: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13387: push(@{$changes{'selfcreate'}},$type);
13388: last;
13389: }
13390: }
13391: }
13392: }
13393: } else {
13394: foreach my $type (@types) {
13395: push(@{$changes{'selfcreate'}},$type);
13396: }
13397: }
13398: }
13399: foreach my $field (@shibfields) {
13400: if ($env{'form.shibenv_'.$field} ne '') {
13401: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13402: }
13403: }
13404: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13405: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13406: foreach my $field (@shibfields) {
13407: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13408: push(@{$changes{'cancreate'}},'shibenv');
13409: }
13410: }
13411: } else {
13412: foreach my $field (@shibfields) {
13413: if ($env{'form.shibenv_'.$field}) {
13414: push(@{$changes{'cancreate'}},'shibenv');
13415: last;
13416: }
13417: }
13418: }
13419: }
13420: }
13421: foreach my $item (@contexts) {
13422: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13423: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13424: if (ref($cancreate{$item}) eq 'ARRAY') {
13425: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13426: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13427: push(@{$changes{'cancreate'}},$item);
13428: }
13429: }
13430: }
13431: }
13432: if (ref($cancreate{$item}) eq 'ARRAY') {
13433: foreach my $type (@{$cancreate{$item}}) {
13434: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13435: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13436: push(@{$changes{'cancreate'}},$item);
13437: }
13438: }
13439: }
13440: }
13441: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13442: if (ref($cancreate{$item}) eq 'HASH') {
13443: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13444: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13445: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13446: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
13447: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13448: push(@{$changes{'cancreate'}},$item);
13449: }
13450: }
13451: }
13452: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13453: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
13454: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13455: push(@{$changes{'cancreate'}},$item);
13456: }
13457: }
13458: }
13459: }
13460: foreach my $type (keys(%{$cancreate{$item}})) {
13461: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13462: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13463: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13464: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
13465: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13466: push(@{$changes{'cancreate'}},$item);
13467: }
13468: }
13469: } else {
13470: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13471: push(@{$changes{'cancreate'}},$item);
13472: }
13473: }
13474: }
13475: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13476: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
13477: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13478: push(@{$changes{'cancreate'}},$item);
13479: }
13480: }
13481: }
13482: }
13483: }
13484: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13485: if (ref($cancreate{$item}) eq 'ARRAY') {
13486: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13487: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13488: push(@{$changes{'cancreate'}},$item);
13489: }
13490: }
13491: }
13492: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13493: if (ref($cancreate{$item}) eq 'HASH') {
13494: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13495: push(@{$changes{'cancreate'}},$item);
13496: }
13497: }
13498: } elsif ($item eq 'emailusername') {
13499: if (ref($cancreate{$item}) eq 'HASH') {
13500: foreach my $type (keys(%{$cancreate{$item}})) {
13501: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13502: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13503: if ($cancreate{$item}{$type}{$field}) {
13504: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13505: push(@{$changes{'cancreate'}},$item);
13506: }
13507: last;
13508: }
13509: }
13510: }
13511: }
13512: }
13513: }
13514: }
13515: #
13516: # Populate %save_usercreate hash with updates to self-creation configuration.
13517: #
13518: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13519: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
13520: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
13521: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13522: if (ref($cancreate{'notify'}) eq 'HASH') {
13523: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13524: }
13525: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13526: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13527: }
13528: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13529: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13530: }
13531: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13532: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13533: }
13534: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13535: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13536: }
13537: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13538: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13539: }
13540: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13541: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13542: }
13543: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
13544: $save_usercreate{'email_rule'} = \%email_rule;
13545:
13546: my %userconfig_hash = (
13547: usercreation => \%save_usercreate,
13548: usermodification => \%save_usermodify,
13549: inststatus => \%save_inststatus,
13550: );
13551:
13552: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13553: $dom);
13554: #
13555: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
13556: #
13557: if ($putresult eq 'ok') {
13558: if (keys(%changes) > 0) {
13559: $resulttext = &mt('Changes made:').'<ul>';
13560: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13561: my %lt = &selfcreation_types();
13562: foreach my $type (@{$changes{'cancreate'}}) {
13563: my $chgtext = '';
13564: if ($type eq 'selfcreate') {
13565: if (@{$cancreate{$type}} == 0) {
13566: $chgtext .= &mt('Self creation of a new user account is not permitted.');
13567: } else {
13568: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13569: '<ul>';
13570: foreach my $case (@{$cancreate{$type}}) {
13571: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13572: }
13573: $chgtext .= '</ul>';
13574: if (ref($cancreate{$type}) eq 'ARRAY') {
13575: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13576: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13577: if (@{$cancreate{'statustocreate'}} == 0) {
13578: $chgtext .= '<span class="LC_warning">'.
13579: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13580: '</span><br />';
13581: }
13582: }
13583: }
13584: if (grep(/^email$/,@{$cancreate{$type}})) {
13585: if (!@statuses) {
13586: $chgtext .= '<span class="LC_warning">'.
13587: &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.").
13588: '</span><br />';
13589:
13590: }
13591: }
13592: }
13593: }
13594: } elsif ($type eq 'shibenv') {
13595: if (keys(%{$cancreate{$type}}) == 0) {
13596: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
13597: } else {
13598: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13599: '<ul>';
13600: foreach my $field (@shibfields) {
13601: next if ($cancreate{$type}{$field} eq '');
13602: if ($field eq 'inststatus') {
13603: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13604: } else {
13605: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13606: }
13607: }
13608: $chgtext .= '</ul>';
13609: }
13610: } elsif ($type eq 'statustocreate') {
13611: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13612: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13613: if (@{$cancreate{'selfcreate'}} > 0) {
13614: if (@{$cancreate{'statustocreate'}} == 0) {
13615: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
13616: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
13617: $chgtext .= '<br />'.
13618: '<span class="LC_warning">'.
13619: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13620: '</span>';
13621: }
13622: } elsif (keys(%usertypes) > 0) {
13623: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
13624: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13625: } else {
13626: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13627: }
13628: $chgtext .= '<ul>';
13629: foreach my $case (@{$cancreate{$type}}) {
13630: if ($case eq 'default') {
13631: $chgtext .= '<li>'.$othertitle.'</li>';
13632: } else {
13633: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
13634: }
13635: }
13636: $chgtext .= '</ul>';
13637: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
13638: $chgtext .= '<span class="LC_warning">'.
13639: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13640: '</span>';
13641: }
13642: }
13643: } else {
13644: if (@{$cancreate{$type}} == 0) {
13645: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13646: } else {
13647: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
13648: }
13649: }
13650: $chgtext .= '<br />';
13651: }
13652: } elsif ($type eq 'selfcreateprocessing') {
13653: my %choices = &Apache::lonlocal::texthash (
13654: automatic => 'Automatic approval',
13655: approval => 'Queued for approval',
13656: );
13657: if (@types) {
13658: if (@statuses) {
13659: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
13660: '<ul>';
13661: foreach my $status (@statuses) {
13662: if ($status eq 'default') {
13663: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13664: } else {
13665: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
13666: }
13667: }
13668: $chgtext .= '</ul>';
13669: }
13670: } else {
13671: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13672: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13673: }
13674: } elsif ($type eq 'emailverified') {
13675: my %options = &Apache::lonlocal::texthash (
13676: all => 'Same as e-mail',
13677: first => 'Omit @domain',
13678: free => 'Free to choose',
13679: );
13680: if (@types) {
13681: if (@statuses) {
13682: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13683: '<ul>';
13684: foreach my $status (@statuses) {
13685: if ($status eq 'default') {
13686: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13687: } else {
13688: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
13689: }
13690: }
13691: $chgtext .= '</ul>';
13692: }
13693: } else {
13694: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
13695: $options{$cancreate{'emailverified'}{'default'}});
13696: }
13697: } elsif ($type eq 'emailoptions') {
13698: my %options = &Apache::lonlocal::texthash (
13699: any => 'Any e-mail',
13700: inst => 'Institutional only',
13701: noninst => 'Non-institutional only',
13702: custom => 'Custom restrictions',
13703: );
13704: if (@types) {
13705: if (@statuses) {
13706: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13707: '<ul>';
13708: foreach my $status (@statuses) {
13709: if ($type eq 'default') {
13710: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13711: } else {
13712: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13713: }
13714: }
13715: $chgtext .= '</ul>';
13716: }
13717: } else {
13718: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13719: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13720: } else {
13721: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13722: $options{$cancreate{'emailoptions'}{'default'}});
13723: }
13724: }
13725: } elsif ($type eq 'emaildomain') {
13726: my $output;
13727: if (@statuses) {
13728: foreach my $type (@statuses) {
13729: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13730: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13731: if ($type eq 'default') {
13732: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13733: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13734: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13735: } else {
13736: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13737: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13738: }
13739: } else {
13740: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13741: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13742: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13743: } else {
13744: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13745: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13746: }
13747: }
13748: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13749: if ($type eq 'default') {
13750: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13751: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13752: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13753: } else {
13754: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13755: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13756: }
13757: } else {
13758: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13759: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13760: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13761: } else {
13762: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13763: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13764: }
13765: }
13766: }
13767: }
13768: }
13769: }
13770: if ($output ne '') {
13771: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13772: '<ul>'.$output.'</ul>';
13773: }
13774: } elsif ($type eq 'captcha') {
13775: if ($savecaptcha{$type} eq 'notused') {
13776: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13777: } else {
13778: my %captchas = &captcha_phrases();
13779: if ($captchas{$savecaptcha{$type}}) {
13780: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
13781: } else {
13782: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
13783: }
13784: }
13785: } elsif ($type eq 'recaptchakeys') {
13786: my ($privkey,$pubkey);
13787: if (ref($savecaptcha{$type}) eq 'HASH') {
13788: $pubkey = $savecaptcha{$type}{'public'};
13789: $privkey = $savecaptcha{$type}{'private'};
13790: }
13791: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13792: if (!$pubkey) {
13793: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13794: } else {
13795: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13796: }
13797: if (!$privkey) {
13798: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13799: } else {
13800: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13801: }
13802: $chgtext .= '</ul>';
13803: } elsif ($type eq 'recaptchaversion') {
13804: if ($savecaptcha{'captcha'} eq 'recaptcha') {
13805: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
13806: }
13807: } elsif ($type eq 'emailusername') {
13808: if (ref($cancreate{'emailusername'}) eq 'HASH') {
13809: if (@statuses) {
13810: foreach my $type (@statuses) {
13811: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13812: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
13813: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
13814: '<ul>';
13815: foreach my $field (@{$infofields}) {
13816: if ($cancreate{'emailusername'}{$type}{$field}) {
13817: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13818: }
13819: }
13820: $chgtext .= '</ul>';
13821: } else {
13822: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
13823: }
13824: } else {
13825: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
13826: }
13827: }
13828: }
13829: }
13830: } elsif ($type eq 'notify') {
13831: my $numapprove = 0;
13832: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13833: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13834: if ($cancreate{'notify'}{'approval'}) {
13835: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13836: $numapprove ++;
13837: }
13838: }
13839: }
13840: unless ($numapprove) {
13841: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13842: }
13843: }
13844: if ($chgtext) {
13845: $resulttext .= '<li>'.$chgtext.'</li>';
13846: }
13847: }
13848: }
13849: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
13850: my ($emailrules,$emailruleorder) =
13851: &Apache::lonnet::inst_userrules($dom,'email');
13852: foreach my $type (@{$changes{'email_rule'}}) {
13853: if (ref($email_rule{$type}) eq 'ARRAY') {
13854: my $chgtext = '<ul>';
13855: foreach my $rule (@{$email_rule{$type}}) {
13856: if (ref($emailrules->{$rule}) eq 'HASH') {
13857: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13858: }
13859: }
13860: $chgtext .= '</ul>';
13861: my $typename;
13862: if (@types) {
13863: if ($type eq 'default') {
13864: $typename = $othertitle;
13865: } else {
13866: $typename = $usertypes{$type};
13867: }
13868: $chgtext .= &mt('(Affiliation: [_1])',$typename);
13869: }
13870: if (@{$email_rule{$type}} > 0) {
13871: $resulttext .= '<li>'.
13872: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
13873: $usertypes{$type}).
13874: $chgtext.
13875: '</li>';
13876: } else {
13877: $resulttext .= '<li>'.
13878: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
13879: '</li>'.
13880: &mt('(Affiliation: [_1])',$typename);
13881: }
13882: }
13883: }
13884: }
13885: if (ref($changes{'inststatus'}) eq 'ARRAY') {
13886: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
13887: if (@{$save_inststatus{'inststatusguest'}} > 0) {
13888: my $chgtext = '<ul>';
13889: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
13890: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
13891: }
13892: $chgtext .= '</ul>';
13893: $resulttext .= '<li>'.
13894: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
13895: $chgtext.
13896: '</li>';
13897: } else {
13898: $resulttext .= '<li>'.
13899: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
13900: '</li>';
13901: }
13902: }
13903: }
13904: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
13905: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
13906: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13907: foreach my $type (@{$changes{'selfcreate'}}) {
13908: my $typename = $type;
13909: if (keys(%usertypes) > 0) {
13910: if ($usertypes{$type} ne '') {
13911: $typename = $usertypes{$type};
13912: }
13913: }
13914: my @modifiable;
13915: $resulttext .= '<li>'.
13916: &mt('Self-creation of account by users with status: [_1]',
13917: '<span class="LC_cusr_emph">'.$typename.'</span>').
13918: ' - '.&mt('modifiable fields (if institutional data blank): ');
13919: foreach my $field (@fields) {
13920: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
13921: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
13922: }
13923: }
13924: if (@modifiable > 0) {
13925: $resulttext .= join(', ',@modifiable);
13926: } else {
13927: $resulttext .= &mt('none');
13928: }
13929: $resulttext .= '</li>';
13930: }
13931: $resulttext .= '</ul></li>';
13932: }
13933: $resulttext .= '</ul>';
13934: my $cachetime = 24*60*60;
13935: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
13936: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13937: if (ref($lastactref) eq 'HASH') {
13938: $lastactref->{'domdefaults'} = 1;
13939: }
13940: } else {
13941: $resulttext = &mt('No changes made to self-creation settings');
13942: }
13943: } else {
13944: $resulttext = '<span class="LC_error">'.
13945: &mt('An error occurred: [_1]',$putresult).'</span>';
13946: }
13947: if ($warningmsg ne '') {
13948: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13949: }
13950: return $resulttext;
13951: }
13952:
13953: sub process_captcha {
13954: my ($container,$changes,$newsettings,$currsettings) = @_;
13955: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
13956: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
13957: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
13958: $newsettings->{'captcha'} = 'original';
13959: }
13960: my %current;
13961: if (ref($currsettings) eq 'HASH') {
13962: %current = %{$currsettings};
13963: }
13964: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
13965: if ($container eq 'cancreate') {
13966: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13967: push(@{$changes->{'cancreate'}},'captcha');
13968: } elsif (!defined($changes->{'cancreate'})) {
13969: $changes->{'cancreate'} = ['captcha'];
13970: }
13971: } elsif ($container eq 'passwords') {
13972: $changes->{'reset'} = 1;
13973: } else {
13974: $changes->{'captcha'} = 1;
13975: }
13976: }
13977: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
13978: if ($newsettings->{'captcha'} eq 'recaptcha') {
13979: $newpub = $env{'form.'.$container.'_recaptchapub'};
13980: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
13981: $newpub =~ s/[^\w\-]//g;
13982: $newpriv =~ s/[^\w\-]//g;
13983: $newsettings->{'recaptchakeys'} = {
13984: public => $newpub,
13985: private => $newpriv,
13986: };
13987: $newversion = $env{'form.'.$container.'_recaptchaversion'};
13988: $newversion =~ s/\D//g;
13989: if ($newversion ne '2') {
13990: $newversion = 1;
13991: }
13992: $newsettings->{'recaptchaversion'} = $newversion;
13993: }
13994: if (ref($current{'recaptchakeys'}) eq 'HASH') {
13995: $currpub = $current{'recaptchakeys'}{'public'};
13996: $currpriv = $current{'recaptchakeys'}{'private'};
13997: unless ($newsettings->{'captcha'} eq 'recaptcha') {
13998: $newsettings->{'recaptchakeys'} = {
13999: public => '',
14000: private => '',
14001: }
14002: }
14003: }
14004: if ($current{'captcha'} eq 'recaptcha') {
14005: $currversion = $current{'recaptchaversion'};
14006: if ($currversion ne '2') {
14007: $currversion = 1;
14008: }
14009: }
14010: if ($currversion ne $newversion) {
14011: if ($container eq 'cancreate') {
14012: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14013: push(@{$changes->{'cancreate'}},'recaptchaversion');
14014: } elsif (!defined($changes->{'cancreate'})) {
14015: $changes->{'cancreate'} = ['recaptchaversion'];
14016: }
14017: } elsif ($container eq 'passwords') {
14018: $changes->{'reset'} = 1;
14019: } else {
14020: $changes->{'recaptchaversion'} = 1;
14021: }
14022: }
14023: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
14024: if ($container eq 'cancreate') {
14025: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14026: push(@{$changes->{'cancreate'}},'recaptchakeys');
14027: } elsif (!defined($changes->{'cancreate'})) {
14028: $changes->{'cancreate'} = ['recaptchakeys'];
14029: }
14030: } elsif ($container eq 'passwords') {
14031: $changes->{'reset'} = 1;
14032: } else {
14033: $changes->{'recaptchakeys'} = 1;
14034: }
14035: }
14036: return;
14037: }
14038:
14039: sub modify_usermodification {
14040: my ($dom,%domconfig) = @_;
14041: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
14042: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14043: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
14044: if ($key eq 'selfcreate') {
14045: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14046: } else {
14047: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14048: }
14049: }
14050: }
14051: my @contexts = ('author','course');
14052: my %context_title = (
14053: author => 'In author context',
14054: course => 'In course context',
14055: );
14056: my @fields = ('lastname','firstname','middlename','generation',
14057: 'permanentemail','id');
14058: my %roles = (
14059: author => ['ca','aa'],
14060: course => ['st','ep','ta','in','cr'],
14061: );
14062: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14063: foreach my $context (@contexts) {
14064: foreach my $role (@{$roles{$context}}) {
14065: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14066: foreach my $item (@fields) {
14067: if (grep(/^\Q$item\E$/,@modifiable)) {
14068: $modifyhash{$context}{$role}{$item} = 1;
14069: } else {
14070: $modifyhash{$context}{$role}{$item} = 0;
14071: }
14072: }
14073: }
14074: if (ref($curr_usermodification{$context}) eq 'HASH') {
14075: foreach my $role (@{$roles{$context}}) {
14076: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14077: foreach my $field (@fields) {
14078: if ($modifyhash{$context}{$role}{$field} ne
14079: $curr_usermodification{$context}{$role}{$field}) {
14080: push(@{$changes{$context}},$role);
14081: last;
14082: }
14083: }
14084: }
14085: }
14086: } else {
14087: foreach my $context (@contexts) {
14088: foreach my $role (@{$roles{$context}}) {
14089: push(@{$changes{$context}},$role);
14090: }
14091: }
14092: }
14093: }
14094: my %usermodification_hash = (
14095: usermodification => \%modifyhash,
14096: );
14097: my $putresult = &Apache::lonnet::put_dom('configuration',
14098: \%usermodification_hash,$dom);
14099: if ($putresult eq 'ok') {
14100: if (keys(%changes) > 0) {
14101: $resulttext = &mt('Changes made: ').'<ul>';
14102: foreach my $context (@contexts) {
14103: if (ref($changes{$context}) eq 'ARRAY') {
14104: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14105: if (ref($changes{$context}) eq 'ARRAY') {
14106: foreach my $role (@{$changes{$context}}) {
14107: my $rolename;
14108: if ($role eq 'cr') {
14109: $rolename = &mt('Custom');
14110: } else {
14111: $rolename = &Apache::lonnet::plaintext($role);
14112: }
14113: my @modifiable;
14114: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
14115: foreach my $field (@fields) {
14116: if ($modifyhash{$context}{$role}{$field}) {
14117: push(@modifiable,$fieldtitles{$field});
14118: }
14119: }
14120: if (@modifiable > 0) {
14121: $resulttext .= join(', ',@modifiable);
14122: } else {
14123: $resulttext .= &mt('none');
14124: }
14125: $resulttext .= '</li>';
14126: }
14127: $resulttext .= '</ul></li>';
14128: }
14129: }
14130: }
14131: $resulttext .= '</ul>';
14132: } else {
14133: $resulttext = &mt('No changes made to user modification settings');
14134: }
14135: } else {
14136: $resulttext = '<span class="LC_error">'.
14137: &mt('An error occurred: [_1]',$putresult).'</span>';
14138: }
14139: return $resulttext;
14140: }
14141:
14142: sub modify_defaults {
14143: my ($dom,$lastactref,%domconfig) = @_;
14144: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
14145: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14146: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14147: 'portal_def');
14148: my @authtypes = ('internal','krb4','krb5','localauth');
14149: foreach my $item (@items) {
14150: $newvalues{$item} = $env{'form.'.$item};
14151: if ($item eq 'auth_def') {
14152: if ($newvalues{$item} ne '') {
14153: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14154: push(@errors,$item);
14155: }
14156: }
14157: } elsif ($item eq 'lang_def') {
14158: if ($newvalues{$item} ne '') {
14159: if ($newvalues{$item} =~ /^(\w+)/) {
14160: my $langcode = $1;
14161: if ($langcode ne 'x_chef') {
14162: if (code2language($langcode) eq '') {
14163: push(@errors,$item);
14164: }
14165: }
14166: } else {
14167: push(@errors,$item);
14168: }
14169: }
14170: } elsif ($item eq 'timezone_def') {
14171: if ($newvalues{$item} ne '') {
14172: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
14173: push(@errors,$item);
14174: }
14175: }
14176: } elsif ($item eq 'datelocale_def') {
14177: if ($newvalues{$item} ne '') {
14178: my @datelocale_ids = DateTime::Locale->ids();
14179: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14180: push(@errors,$item);
14181: }
14182: }
14183: } elsif ($item eq 'portal_def') {
14184: if ($newvalues{$item} ne '') {
14185: 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])\/?$/) {
14186: push(@errors,$item);
14187: }
14188: }
14189: }
14190: if (grep(/^\Q$item\E$/,@errors)) {
14191: $newvalues{$item} = $domdefaults{$item};
14192: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14193: $changes{$item} = 1;
14194: }
14195: $domdefaults{$item} = $newvalues{$item};
14196: }
14197: my %staticdefaults = (
14198: 'intauth_cost' => 10,
14199: 'intauth_check' => 0,
14200: 'intauth_switch' => 0,
14201: );
14202: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
14203: if (exists($domdefaults{$item})) {
14204: $newvalues{$item} = $domdefaults{$item};
14205: } else {
14206: $newvalues{$item} = $staticdefaults{$item};
14207: }
14208: }
14209: my %defaults_hash = (
14210: defaults => \%newvalues,
14211: );
14212: my $title = &defaults_titles();
14213:
14214: my $currinststatus;
14215: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14216: $currinststatus = $domconfig{'inststatus'};
14217: } else {
14218: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14219: $currinststatus = {
14220: inststatustypes => $usertypes,
14221: inststatusorder => $types,
14222: inststatusguest => [],
14223: };
14224: }
14225: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14226: my @allpos;
14227: my %alltypes;
14228: my @inststatusguest;
14229: if (ref($currinststatus) eq 'HASH') {
14230: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14231: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14232: unless (grep(/^\Q$type\E$/,@todelete)) {
14233: push(@inststatusguest,$type);
14234: }
14235: }
14236: }
14237: }
14238: my ($currtitles,$currorder);
14239: if (ref($currinststatus) eq 'HASH') {
14240: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14241: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14242: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14243: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14244: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14245: }
14246: }
14247: unless (grep(/^\Q$type\E$/,@todelete)) {
14248: my $position = $env{'form.inststatus_pos_'.$type};
14249: $position =~ s/\D+//g;
14250: $allpos[$position] = $type;
14251: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14252: $alltypes{$type} =~ s/`//g;
14253: }
14254: }
14255: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14256: $currtitles =~ s/,$//;
14257: }
14258: }
14259: if ($env{'form.addinststatus'}) {
14260: my $newtype = $env{'form.addinststatus'};
14261: $newtype =~ s/\W//g;
14262: unless (exists($alltypes{$newtype})) {
14263: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14264: $alltypes{$newtype} =~ s/`//g;
14265: my $position = $env{'form.addinststatus_pos'};
14266: $position =~ s/\D+//g;
14267: if ($position ne '') {
14268: $allpos[$position] = $newtype;
14269: }
14270: }
14271: }
14272: my @orderedstatus;
14273: foreach my $type (@allpos) {
14274: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14275: push(@orderedstatus,$type);
14276: }
14277: }
14278: foreach my $type (keys(%alltypes)) {
14279: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14280: delete($alltypes{$type});
14281: }
14282: }
14283: $defaults_hash{'inststatus'} = {
14284: inststatustypes => \%alltypes,
14285: inststatusorder => \@orderedstatus,
14286: inststatusguest => \@inststatusguest,
14287: };
14288: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14289: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14290: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14291: }
14292: }
14293: if ($currorder ne join(',',@orderedstatus)) {
14294: $changes{'inststatus'}{'inststatusorder'} = 1;
14295: }
14296: my $newtitles;
14297: foreach my $item (@orderedstatus) {
14298: $newtitles .= $alltypes{$item}.',';
14299: }
14300: $newtitles =~ s/,$//;
14301: if ($currtitles ne $newtitles) {
14302: $changes{'inststatus'}{'inststatustypes'} = 1;
14303: }
14304: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14305: $dom);
14306: if ($putresult eq 'ok') {
14307: if (keys(%changes) > 0) {
14308: $resulttext = &mt('Changes made:').'<ul>';
14309: my $version = &Apache::lonnet::get_server_loncaparev($dom);
14310: 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";
14311: foreach my $item (sort(keys(%changes))) {
14312: if ($item eq 'inststatus') {
14313: if (ref($changes{'inststatus'}) eq 'HASH') {
14314: if (@orderedstatus) {
14315: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14316: foreach my $type (@orderedstatus) {
14317: $resulttext .= $alltypes{$type}.', ';
14318: }
14319: $resulttext =~ s/, $//;
14320: $resulttext .= '</li>';
14321: } else {
14322: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
14323: }
14324: }
14325: } else {
14326: my $value = $env{'form.'.$item};
14327: if ($value eq '') {
14328: $value = &mt('none');
14329: } elsif ($item eq 'auth_def') {
14330: my %authnames = &authtype_names();
14331: my %shortauth = (
14332: internal => 'int',
14333: krb4 => 'krb4',
14334: krb5 => 'krb5',
14335: localauth => 'loc',
14336: );
14337: $value = $authnames{$shortauth{$value}};
14338: }
14339: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14340: $mailmsgtext .= "$title->{$item} set to $value\n";
14341: }
14342: }
14343: $resulttext .= '</ul>';
14344: $mailmsgtext .= "\n";
14345: my $cachetime = 24*60*60;
14346: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14347: if (ref($lastactref) eq 'HASH') {
14348: $lastactref->{'domdefaults'} = 1;
14349: }
14350: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
14351: my $notify = 1;
14352: if (ref($domconfig{'contacts'}) eq 'HASH') {
14353: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14354: $notify = 0;
14355: }
14356: }
14357: if ($notify) {
14358: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14359: "LON-CAPA Domain Settings Change - $dom",
14360: $mailmsgtext);
14361: }
14362: }
14363: } else {
14364: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
14365: }
14366: } else {
14367: $resulttext = '<span class="LC_error">'.
14368: &mt('An error occurred: [_1]',$putresult).'</span>';
14369: }
14370: if (@errors > 0) {
14371: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14372: foreach my $item (@errors) {
14373: $resulttext .= ' "'.$title->{$item}.'",';
14374: }
14375: $resulttext =~ s/,$//;
14376: }
14377: return $resulttext;
14378: }
14379:
14380: sub modify_scantron {
14381: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
14382: my ($resulttext,%confhash,%changes,$errors);
14383: my $custom = 'custom.tab';
14384: my $default = 'default.tab';
14385: my $servadm = $r->dir_config('lonAdmEMail');
14386: my ($configuserok,$author_ok,$switchserver) =
14387: &config_check($dom,$confname,$servadm);
14388: if ($env{'form.scantronformat.filename'} ne '') {
14389: my $error;
14390: if ($configuserok eq 'ok') {
14391: if ($switchserver) {
14392: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
14393: } else {
14394: if ($author_ok eq 'ok') {
14395: my ($result,$scantronurl) =
14396: &publishlogo($r,'upload','scantronformat',$dom,
14397: $confname,'scantron','','',$custom);
14398: if ($result eq 'ok') {
14399: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
14400: $changes{'scantronformat'} = 1;
14401: } else {
14402: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14403: }
14404: } else {
14405: $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);
14406: }
14407: }
14408: } else {
14409: $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);
14410: }
14411: if ($error) {
14412: &Apache::lonnet::logthis($error);
14413: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14414: }
14415: }
14416: if (ref($domconfig{'scantron'}) eq 'HASH') {
14417: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14418: if ($env{'form.scantronformat_del'}) {
14419: $confhash{'scantron'}{'scantronformat'} = '';
14420: $changes{'scantronformat'} = 1;
14421: } else {
14422: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
14423: }
14424: }
14425: }
14426: my @options = ('hdr','pad','rem');
14427: my @fields = &scantroncsv_fields();
14428: my %titles = &scantronconfig_titles();
14429: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
14430: my ($newdat,$currdat,%newcol,%currcol);
14431: if (grep(/^dat$/,@formats)) {
14432: $confhash{'scantron'}{config}{dat} = 1;
14433: $newdat = 1;
14434: } else {
14435: $newdat = 0;
14436: }
14437: if (grep(/^csv$/,@formats)) {
14438: my %bynum;
14439: foreach my $field (@fields) {
14440: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
14441: my $posscol = $1;
14442: if (($posscol < 20) && (!$bynum{$posscol})) {
14443: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
14444: $bynum{$posscol} = $field;
14445: $newcol{$field} = $posscol;
14446: }
14447: }
14448: }
14449: if (keys(%newcol)) {
14450: foreach my $option (@options) {
14451: if ($env{'form.scantroncsv_'.$option}) {
14452: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
14453: }
14454: }
14455: }
14456: }
14457: $currdat = 1;
14458: if (ref($domconfig{'scantron'}) eq 'HASH') {
14459: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
14460: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
14461: $currdat = 0;
14462: }
14463: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14464: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14465: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
14466: }
14467: }
14468: }
14469: }
14470: if ($currdat != $newdat) {
14471: $changes{'config'} = 1;
14472: } else {
14473: foreach my $field (@fields) {
14474: if ($currcol{$field} ne '') {
14475: if ($currcol{$field} ne $newcol{$field}) {
14476: $changes{'config'} = 1;
14477: last;
14478: }
14479: } elsif ($newcol{$field} ne '') {
14480: $changes{'config'} = 1;
14481: last;
14482: }
14483: }
14484: }
14485: if (keys(%confhash) > 0) {
14486: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14487: $dom);
14488: if ($putresult eq 'ok') {
14489: if (keys(%changes) > 0) {
14490: if (ref($confhash{'scantron'}) eq 'HASH') {
14491: $resulttext = &mt('Changes made:').'<ul>';
14492: if ($changes{'scantronformat'}) {
14493: if ($confhash{'scantron'}{'scantronformat'} eq '') {
14494: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
14495: } else {
14496: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
14497: }
14498: }
14499: if ($changes{'config'}) {
14500: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
14501: if ($confhash{'scantron'}{'config'}{'dat'}) {
14502: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
14503: }
14504: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
14505: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
14506: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
14507: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
14508: foreach my $field (@fields) {
14509: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
14510: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
14511: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
14512: }
14513: }
14514: $resulttext .= '</ul></li>';
14515: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
14516: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
14517: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
14518: foreach my $option (@options) {
14519: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
14520: $resulttext .= '<li>'.$titles{$option}.'</li>';
14521: }
14522: }
14523: $resulttext .= '</ul></li>';
14524: }
14525: }
14526: }
14527: }
14528: }
14529: } else {
14530: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
14531: }
14532: }
14533: $resulttext .= '</ul>';
14534: } else {
14535: $resulttext = &mt('Changes made to bubblesheet format file.');
14536: }
14537: &Apache::loncommon::devalidate_domconfig_cache($dom);
14538: if (ref($lastactref) eq 'HASH') {
14539: $lastactref->{'domainconfig'} = 1;
14540: }
14541: } else {
14542: $resulttext = &mt('No changes made to bubblesheet format settings');
14543: }
14544: } else {
14545: $resulttext = '<span class="LC_error">'.
14546: &mt('An error occurred: [_1]',$putresult).'</span>';
14547: }
14548: } else {
14549: $resulttext = &mt('No changes made to bubblesheet format settings');
14550: }
14551: if ($errors) {
14552: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14553: $errors.'</ul>';
14554: }
14555: return $resulttext;
14556: }
14557:
14558: sub modify_coursecategories {
14559: my ($dom,$lastactref,%domconfig) = @_;
14560: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14561: $cathash);
14562: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
14563: my @catitems = ('unauth','auth');
14564: my @cattypes = ('std','domonly','codesrch','none');
14565: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14566: $cathash = $domconfig{'coursecategories'}{'cats'};
14567: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14568: $changes{'togglecats'} = 1;
14569: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14570: }
14571: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14572: $changes{'categorize'} = 1;
14573: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14574: }
14575: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14576: $changes{'togglecatscomm'} = 1;
14577: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14578: }
14579: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14580: $changes{'categorizecomm'} = 1;
14581: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
14582: }
14583: foreach my $item (@catitems) {
14584: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14585: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14586: $changes{$item} = 1;
14587: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14588: }
14589: }
14590: }
14591: } else {
14592: $changes{'togglecats'} = 1;
14593: $changes{'categorize'} = 1;
14594: $changes{'togglecatscomm'} = 1;
14595: $changes{'categorizecomm'} = 1;
14596: $domconfig{'coursecategories'} = {
14597: togglecats => $env{'form.togglecats'},
14598: categorize => $env{'form.categorize'},
14599: togglecatscomm => $env{'form.togglecatscomm'},
14600: categorizecomm => $env{'form.categorizecomm'},
14601: };
14602: foreach my $item (@catitems) {
14603: if ($env{'form.coursecat_'.$item} ne 'std') {
14604: $changes{$item} = 1;
14605: }
14606: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14607: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14608: }
14609: }
14610: }
14611: if (ref($cathash) eq 'HASH') {
14612: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
14613: push (@deletecategory,'instcode::0');
14614: }
14615: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14616: push(@deletecategory,'communities::0');
14617: }
14618: }
14619: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14620: if (ref($cathash) eq 'HASH') {
14621: if (@deletecategory > 0) {
14622: #FIXME Need to remove category from all courses using a deleted category
14623: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
14624: foreach my $item (@deletecategory) {
14625: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14626: delete($domconfig{'coursecategories'}{'cats'}{$item});
14627: $deletions{$item} = 1;
14628: &recurse_cat_deletes($item,$cathash,\%deletions);
14629: }
14630: }
14631: }
14632: foreach my $item (keys(%{$cathash})) {
14633: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14634: if ($cathash->{$item} ne $env{'form.'.$item}) {
14635: $reorderings{$item} = 1;
14636: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
14637: }
14638: if ($env{'form.addcategory_name_'.$item} ne '') {
14639: my $newcat = $env{'form.addcategory_name_'.$item};
14640: my $newdepth = $depth+1;
14641: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
14642: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
14643: $adds{$newitem} = 1;
14644: }
14645: if ($env{'form.subcat_'.$item} ne '') {
14646: my $newcat = $env{'form.subcat_'.$item};
14647: my $newdepth = $depth+1;
14648: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
14649: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
14650: $adds{$newitem} = 1;
14651: }
14652: }
14653: }
14654: if ($env{'form.instcode'} eq '1') {
14655: if (ref($cathash) eq 'HASH') {
14656: my $newitem = 'instcode::0';
14657: if ($cathash->{$newitem} eq '') {
14658: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
14659: $adds{$newitem} = 1;
14660: }
14661: } else {
14662: my $newitem = 'instcode::0';
14663: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
14664: $adds{$newitem} = 1;
14665: }
14666: }
14667: if ($env{'form.communities'} eq '1') {
14668: if (ref($cathash) eq 'HASH') {
14669: my $newitem = 'communities::0';
14670: if ($cathash->{$newitem} eq '') {
14671: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14672: $adds{$newitem} = 1;
14673: }
14674: } else {
14675: my $newitem = 'communities::0';
14676: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14677: $adds{$newitem} = 1;
14678: }
14679: }
14680: if ($env{'form.addcategory_name'} ne '') {
14681: if (($env{'form.addcategory_name'} ne 'instcode') &&
14682: ($env{'form.addcategory_name'} ne 'communities')) {
14683: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14684: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14685: $adds{$newitem} = 1;
14686: }
14687: }
14688: my $putresult;
14689: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14690: if (keys(%deletions) > 0) {
14691: foreach my $key (keys(%deletions)) {
14692: if ($predelallitems{$key} ne '') {
14693: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14694: }
14695: }
14696: }
14697: my (@chkcats,@chktrails,%chkallitems);
14698: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
14699: if (ref($chkcats[0]) eq 'ARRAY') {
14700: my $depth = 0;
14701: my $chg = 0;
14702: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14703: my $name = $chkcats[0][$i];
14704: my $item;
14705: if ($name eq '') {
14706: $chg ++;
14707: } else {
14708: $item = &escape($name).'::0';
14709: if ($chg) {
14710: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
14711: }
14712: $depth ++;
14713: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
14714: $depth --;
14715: }
14716: }
14717: }
14718: }
14719: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14720: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
14721: if ($putresult eq 'ok') {
14722: my %title = (
14723: togglecats => 'Show/Hide a course in catalog',
14724: categorize => 'Assign a category to a course',
14725: togglecatscomm => 'Show/Hide a community in catalog',
14726: categorizecomm => 'Assign a category to a community',
14727: );
14728: my %level = (
14729: dom => 'set in Domain ("Modify Course/Community")',
14730: crs => 'set in Course ("Course Configuration")',
14731: comm => 'set in Community ("Community Configuration")',
14732: none => 'No catalog',
14733: std => 'Standard catalog',
14734: domonly => 'Domain-only catalog',
14735: codesrch => 'Code search form',
14736: );
14737: $resulttext = &mt('Changes made:').'<ul>';
14738: if ($changes{'togglecats'}) {
14739: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14740: }
14741: if ($changes{'categorize'}) {
14742: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
14743: }
14744: if ($changes{'togglecatscomm'}) {
14745: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14746: }
14747: if ($changes{'categorizecomm'}) {
14748: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14749: }
14750: if ($changes{'unauth'}) {
14751: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14752: }
14753: if ($changes{'auth'}) {
14754: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14755: }
14756: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14757: my $cathash;
14758: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14759: $cathash = $domconfig{'coursecategories'}{'cats'};
14760: } else {
14761: $cathash = {};
14762: }
14763: my (@cats,@trails,%allitems);
14764: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14765: if (keys(%deletions) > 0) {
14766: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14767: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14768: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14769: }
14770: $resulttext .= '</ul></li>';
14771: }
14772: if (keys(%reorderings) > 0) {
14773: my %sort_by_trail;
14774: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14775: foreach my $key (keys(%reorderings)) {
14776: if ($allitems{$key} ne '') {
14777: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14778: }
14779: }
14780: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14781: $resulttext .= '<li>'.$trails[$trail].'</li>';
14782: }
14783: $resulttext .= '</ul></li>';
14784: }
14785: if (keys(%adds) > 0) {
14786: my %sort_by_trail;
14787: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14788: foreach my $key (keys(%adds)) {
14789: if ($allitems{$key} ne '') {
14790: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14791: }
14792: }
14793: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14794: $resulttext .= '<li>'.$trails[$trail].'</li>';
14795: }
14796: $resulttext .= '</ul></li>';
14797: }
14798: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
14799: if (ref($lastactref) eq 'HASH') {
14800: $lastactref->{'cats'} = 1;
14801: }
14802: }
14803: $resulttext .= '</ul>';
14804: if ($changes{'unauth'} || $changes{'auth'}) {
14805: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14806: if ($changes{'auth'}) {
14807: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14808: }
14809: if ($changes{'unauth'}) {
14810: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14811: }
14812: my $cachetime = 24*60*60;
14813: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14814: if (ref($lastactref) eq 'HASH') {
14815: $lastactref->{'domdefaults'} = 1;
14816: }
14817: }
14818: } else {
14819: $resulttext = '<span class="LC_error">'.
14820: &mt('An error occurred: [_1]',$putresult).'</span>';
14821: }
14822: } else {
14823: $resulttext = &mt('No changes made to course and community categories');
14824: }
14825: return $resulttext;
14826: }
14827:
14828: sub modify_serverstatuses {
14829: my ($dom,%domconfig) = @_;
14830: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14831: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14832: %currserverstatus = %{$domconfig{'serverstatuses'}};
14833: }
14834: my @pages = &serverstatus_pages();
14835: foreach my $type (@pages) {
14836: $newserverstatus{$type}{'namedusers'} = '';
14837: $newserverstatus{$type}{'machines'} = '';
14838: if (defined($env{'form.'.$type.'_namedusers'})) {
14839: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14840: my @okusers;
14841: foreach my $user (@users) {
14842: my ($uname,$udom) = split(/:/,$user);
14843: if (($udom =~ /^$match_domain$/) &&
14844: (&Apache::lonnet::domain($udom)) &&
14845: ($uname =~ /^$match_username$/)) {
14846: if (!grep(/^\Q$user\E/,@okusers)) {
14847: push(@okusers,$user);
14848: }
14849: }
14850: }
14851: if (@okusers > 0) {
14852: @okusers = sort(@okusers);
14853: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14854: }
14855: }
14856: if (defined($env{'form.'.$type.'_machines'})) {
14857: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14858: my @okmachines;
14859: foreach my $ip (@machines) {
14860: my @parts = split(/\./,$ip);
14861: next if (@parts < 4);
14862: my $badip = 0;
14863: for (my $i=0; $i<4; $i++) {
14864: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14865: $badip = 1;
14866: last;
14867: }
14868: }
14869: if (!$badip) {
14870: push(@okmachines,$ip);
14871: }
14872: }
14873: @okmachines = sort(@okmachines);
14874: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14875: }
14876: }
14877: my %serverstatushash = (
14878: serverstatuses => \%newserverstatus,
14879: );
14880: foreach my $type (@pages) {
14881: foreach my $setting ('namedusers','machines') {
14882: my (@current,@new);
14883: if (ref($currserverstatus{$type}) eq 'HASH') {
14884: if ($currserverstatus{$type}{$setting} ne '') {
14885: @current = split(/,/,$currserverstatus{$type}{$setting});
14886: }
14887: }
14888: if ($newserverstatus{$type}{$setting} ne '') {
14889: @new = split(/,/,$newserverstatus{$type}{$setting});
14890: }
14891: if (@current > 0) {
14892: if (@new > 0) {
14893: foreach my $item (@current) {
14894: if (!grep(/^\Q$item\E$/,@new)) {
14895: $changes{$type}{$setting} = 1;
14896: last;
14897: }
14898: }
14899: foreach my $item (@new) {
14900: if (!grep(/^\Q$item\E$/,@current)) {
14901: $changes{$type}{$setting} = 1;
14902: last;
14903: }
14904: }
14905: } else {
14906: $changes{$type}{$setting} = 1;
14907: }
14908: } elsif (@new > 0) {
14909: $changes{$type}{$setting} = 1;
14910: }
14911: }
14912: }
14913: if (keys(%changes) > 0) {
14914: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
14915: my $putresult = &Apache::lonnet::put_dom('configuration',
14916: \%serverstatushash,$dom);
14917: if ($putresult eq 'ok') {
14918: $resulttext .= &mt('Changes made:').'<ul>';
14919: foreach my $type (@pages) {
14920: if (ref($changes{$type}) eq 'HASH') {
14921: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
14922: if ($changes{$type}{'namedusers'}) {
14923: if ($newserverstatus{$type}{'namedusers'} eq '') {
14924: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
14925: } else {
14926: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
14927: }
14928: }
14929: if ($changes{$type}{'machines'}) {
14930: if ($newserverstatus{$type}{'machines'} eq '') {
14931: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
14932: } else {
14933: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
14934: }
14935:
14936: }
14937: $resulttext .= '</ul></li>';
14938: }
14939: }
14940: $resulttext .= '</ul>';
14941: } else {
14942: $resulttext = '<span class="LC_error">'.
14943: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
14944:
14945: }
14946: } else {
14947: $resulttext = &mt('No changes made to access to server status pages');
14948: }
14949: return $resulttext;
14950: }
14951:
14952: sub modify_helpsettings {
14953: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
14954: my ($resulttext,$errors,%changes,%helphash);
14955: my %defaultchecked = ('submitbugs' => 'on');
14956: my @offon = ('off','on');
14957: my @toggles = ('submitbugs');
14958: my %current = ('submitbugs' => '',
14959: 'adhoc' => {},
14960: );
14961: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
14962: %current = %{$domconfig{'helpsettings'}};
14963: }
14964: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14965: foreach my $item (@toggles) {
14966: if ($defaultchecked{$item} eq 'on') {
14967: if ($current{$item} eq '') {
14968: if ($env{'form.'.$item} eq '0') {
14969: $changes{$item} = 1;
14970: }
14971: } elsif ($current{$item} ne $env{'form.'.$item}) {
14972: $changes{$item} = 1;
14973: }
14974: } elsif ($defaultchecked{$item} eq 'off') {
14975: if ($current{$item} eq '') {
14976: if ($env{'form.'.$item} eq '1') {
14977: $changes{$item} = 1;
14978: }
14979: } elsif ($current{$item} ne $env{'form.'.$item}) {
14980: $changes{$item} = 1;
14981: }
14982: }
14983: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
14984: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
14985: }
14986: }
14987: my $maxnum = $env{'form.helproles_maxnum'};
14988: my $confname = $dom.'-domainconfig';
14989: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
14990: my (@allpos,%newsettings,%changedprivs,$newrole);
14991: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14992: my @accesstypes = ('all','dh','da','none','status','inc','exc');
14993: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
14994: my %lt = &Apache::lonlocal::texthash(
14995: s => 'system',
14996: d => 'domain',
14997: order => 'Display order',
14998: access => 'Role usage',
14999: all => 'All with domain helpdesk or helpdesk assistant role',
15000: dh => 'All with domain helpdesk role',
15001: da => 'All with domain helpdesk assistant role',
15002: none => 'None',
15003: status => 'Determined based on institutional status',
15004: inc => 'Include all, but exclude specific personnel',
15005: exc => 'Exclude all, but include specific personnel',
15006: );
15007: for (my $num=0; $num<=$maxnum; $num++) {
15008: my ($prefix,$identifier,$rolename,%curr);
15009: if ($num == $maxnum) {
15010: next unless ($env{'form.newcusthelp'} == $maxnum);
15011: $identifier = 'custhelp'.$num;
15012: $prefix = 'helproles_'.$num;
15013: $rolename = $env{'form.custhelpname'.$num};
15014: $rolename=~s/[^A-Za-z0-9]//gs;
15015: next if ($rolename eq '');
15016: next if (exists($existing{'rolesdef_'.$rolename}));
15017: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15018: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15019: $newprivs{'c'},$confname,$dom);
15020: if ($result ne 'ok') {
15021: $errors .= '<li><span class="LC_error">'.
15022: &mt('An error occurred storing the new custom role: [_1]',
15023: $result).'</span></li>';
15024: next;
15025: } else {
15026: $changedprivs{$rolename} = \%newprivs;
15027: $newrole = $rolename;
15028: }
15029: } else {
15030: $prefix = 'helproles_'.$num;
15031: $rolename = $env{'form.'.$prefix};
15032: next if ($rolename eq '');
15033: next unless (exists($existing{'rolesdef_'.$rolename}));
15034: $identifier = 'custhelp'.$num;
15035: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15036: my %currprivs;
15037: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
15038: split(/\_/,$existing{'rolesdef_'.$rolename});
15039: foreach my $level ('c','d','s') {
15040: if ($newprivs{$level} ne $currprivs{$level}) {
15041: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15042: $newprivs{'c'},$confname,$dom);
15043: if ($result ne 'ok') {
15044: $errors .= '<li><span class="LC_error">'.
15045: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15046: $rolename,$result).'</span></li>';
15047: } else {
15048: $changedprivs{$rolename} = \%newprivs;
15049: }
15050: last;
15051: }
15052: }
15053: if (ref($current{'adhoc'}) eq 'HASH') {
15054: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15055: %curr = %{$current{'adhoc'}{$rolename}};
15056: }
15057: }
15058: }
15059: my $newpos = $env{'form.'.$prefix.'_pos'};
15060: $newpos =~ s/\D+//g;
15061: $allpos[$newpos] = $rolename;
15062: my $newdesc = $env{'form.'.$prefix.'_desc'};
15063: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15064: if ($curr{'desc'}) {
15065: if ($curr{'desc'} ne $newdesc) {
15066: $changes{'customrole'}{$rolename}{'desc'} = 1;
15067: $newsettings{$rolename}{'desc'} = $newdesc;
15068: }
15069: } elsif ($newdesc ne '') {
15070: $changes{'customrole'}{$rolename}{'desc'} = 1;
15071: $newsettings{$rolename}{'desc'} = $newdesc;
15072: }
15073: my $access = $env{'form.'.$prefix.'_access'};
15074: if (grep(/^\Q$access\E$/,@accesstypes)) {
15075: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15076: if ($access eq 'status') {
15077: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15078: if (scalar(@statuses) == 0) {
15079: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
15080: } else {
15081: my (@shownstatus,$numtypes);
15082: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15083: if (ref($types) eq 'ARRAY') {
15084: $numtypes = scalar(@{$types});
15085: foreach my $type (sort(@statuses)) {
15086: if ($type eq 'default') {
15087: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15088: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15089: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15090: push(@shownstatus,$usertypes->{$type});
15091: }
15092: }
15093: }
15094: if (grep(/^default$/,@statuses)) {
15095: push(@shownstatus,$othertitle);
15096: }
15097: if (scalar(@shownstatus) == 1+$numtypes) {
15098: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15099: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15100: } else {
15101: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15102: if (ref($curr{'status'}) eq 'ARRAY') {
15103: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15104: if (@diffs) {
15105: $changes{'customrole'}{$rolename}{$access} = 1;
15106: }
15107: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15108: $changes{'customrole'}{$rolename}{$access} = 1;
15109: }
15110: }
15111: }
15112: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15113: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15114: my @newspecstaff;
15115: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15116: foreach my $person (sort(@personnel)) {
15117: if ($domhelpdesk{$person}) {
15118: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15119: }
15120: }
15121: if (ref($curr{$access}) eq 'ARRAY') {
15122: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15123: if (@diffs) {
15124: $changes{'customrole'}{$rolename}{$access} = 1;
15125: }
15126: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15127: $changes{'customrole'}{$rolename}{$access} = 1;
15128: }
15129: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15130: my ($uname,$udom) = split(/:/,$person);
15131: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15132: }
15133: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
15134: }
15135: } else {
15136: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15137: }
15138: unless ($curr{'access'} eq $access) {
15139: $changes{'customrole'}{$rolename}{'access'} = 1;
15140: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
15141: }
15142: }
15143: if (@allpos > 0) {
15144: my $idx = 0;
15145: foreach my $rolename (@allpos) {
15146: if ($rolename ne '') {
15147: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15148: if (ref($current{'adhoc'}) eq 'HASH') {
15149: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15150: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15151: $changes{'customrole'}{$rolename}{'order'} = 1;
15152: $newsettings{$rolename}{'order'} = $idx+1;
15153: }
15154: }
15155: }
15156: $idx ++;
15157: }
15158: }
15159: }
15160: my $putresult;
15161: if (keys(%changes) > 0) {
15162: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
15163: if ($putresult eq 'ok') {
15164: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15165: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15166: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15167: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15168: }
15169: }
15170: my $cachetime = 24*60*60;
15171: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15172: if (ref($lastactref) eq 'HASH') {
15173: $lastactref->{'domdefaults'} = 1;
15174: }
15175: } else {
15176: $errors .= '<li><span class="LC_error">'.
15177: &mt('An error occurred storing the settings: [_1]',
15178: $putresult).'</span></li>';
15179: }
15180: }
15181: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15182: $resulttext = &mt('Changes made:').'<ul>';
15183: my (%shownprivs,@levelorder);
15184: @levelorder = ('c','d','s');
15185: if ((keys(%changes)) && ($putresult eq 'ok')) {
15186: foreach my $item (sort(keys(%changes))) {
15187: if ($item eq 'submitbugs') {
15188: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15189: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15190: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
15191: } elsif ($item eq 'customrole') {
15192: if (ref($changes{'customrole'}) eq 'HASH') {
15193: my @keyorder = ('order','desc','access','status','exc','inc');
15194: my %keytext = &Apache::lonlocal::texthash(
15195: order => 'Order',
15196: desc => 'Role description',
15197: access => 'Role usage',
15198: status => 'Allowed institutional types',
15199: exc => 'Allowed personnel',
15200: inc => 'Disallowed personnel',
15201: );
15202: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
15203: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15204: if ($role eq $newrole) {
15205: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15206: $role).'<ul>';
15207: } else {
15208: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15209: $role).'<ul>';
15210: }
15211: foreach my $key (@keyorder) {
15212: if ($changes{'customrole'}{$role}{$key}) {
15213: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15214: $keytext{$key},$newsettings{$role}{$key}).
15215: '</li>';
15216: }
15217: }
15218: if (ref($changedprivs{$role}) eq 'HASH') {
15219: $shownprivs{$role} = 1;
15220: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15221: foreach my $level (@levelorder) {
15222: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15223: next if ($item eq '');
15224: my ($priv) = split(/\&/,$item,2);
15225: if (&Apache::lonnet::plaintext($priv)) {
15226: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15227: unless ($level eq 'c') {
15228: $resulttext .= ' ('.$lt{$level}.')';
15229: }
15230: $resulttext .= '</li>';
15231: }
15232: }
15233: }
15234: $resulttext .= '</ul>';
15235: }
15236: $resulttext .= '</ul></li>';
15237: }
15238: }
15239: }
15240: }
15241: }
15242: }
15243: if (keys(%changedprivs)) {
15244: foreach my $role (sort(keys(%changedprivs))) {
15245: unless ($shownprivs{$role}) {
15246: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15247: $role).'<ul>'.
15248: '<li>'.&mt('Privileges set to :').'<ul>';
15249: foreach my $level (@levelorder) {
15250: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15251: next if ($item eq '');
15252: my ($priv) = split(/\&/,$item,2);
15253: if (&Apache::lonnet::plaintext($priv)) {
15254: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15255: unless ($level eq 'c') {
15256: $resulttext .= ' ('.$lt{$level}.')';
15257: }
15258: $resulttext .= '</li>';
15259: }
15260: }
15261: }
15262: $resulttext .= '</ul></li></ul></li>';
15263: }
15264: }
15265: }
15266: $resulttext .= '</ul>';
15267: } else {
15268: $resulttext = &mt('No changes made to help settings');
15269: }
15270: if ($errors) {
15271: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
15272: $errors.'</ul>';
15273: }
15274: return $resulttext;
15275: }
15276:
15277: sub modify_coursedefaults {
15278: my ($dom,$lastactref,%domconfig) = @_;
15279: my ($resulttext,$errors,%changes,%defaultshash);
15280: my %defaultchecked = (
15281: 'uselcmath' => 'on',
15282: 'usejsme' => 'on'
15283: );
15284: my @toggles = ('uselcmath','usejsme');
15285: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
15286: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
15287: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
15288: my @types = ('official','unofficial','community','textbook');
15289: my %staticdefaults = (
15290: anonsurvey_threshold => 10,
15291: uploadquota => 500,
15292: postsubmit => 60,
15293: mysqltables => 172800,
15294: );
15295: my %texoptions = (
15296: MathJax => 'MathJax',
15297: mimetex => &mt('Convert to Images'),
15298: tth => &mt('TeX to HTML'),
15299: );
15300: $defaultshash{'coursedefaults'} = {};
15301:
15302: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15303: if ($domconfig{'coursedefaults'} eq '') {
15304: $domconfig{'coursedefaults'} = {};
15305: }
15306: }
15307:
15308: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15309: foreach my $item (@toggles) {
15310: if ($defaultchecked{$item} eq 'on') {
15311: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15312: ($env{'form.'.$item} eq '0')) {
15313: $changes{$item} = 1;
15314: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15315: $changes{$item} = 1;
15316: }
15317: } elsif ($defaultchecked{$item} eq 'off') {
15318: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15319: ($env{'form.'.$item} eq '1')) {
15320: $changes{$item} = 1;
15321: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15322: $changes{$item} = 1;
15323: }
15324: }
15325: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15326: }
15327: foreach my $item (@numbers) {
15328: my ($currdef,$newdef);
15329: $newdef = $env{'form.'.$item};
15330: if ($item eq 'anonsurvey_threshold') {
15331: $currdef = $domconfig{'coursedefaults'}{$item};
15332: $newdef =~ s/\D//g;
15333: if ($newdef eq '' || $newdef < 1) {
15334: $newdef = 1;
15335: }
15336: $defaultshash{'coursedefaults'}{$item} = $newdef;
15337: } else {
15338: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15339: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15340: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
15341: }
15342: $newdef =~ s/[^\w.\-]//g;
15343: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
15344: }
15345: if ($currdef ne $newdef) {
15346: if ($item eq 'anonsurvey_threshold') {
15347: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15348: $changes{$item} = 1;
15349: }
15350: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
15351: my $setting = $1;
15352: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15353: $changes{$setting} = 1;
15354: }
15355: }
15356: }
15357: }
15358: my $texengine;
15359: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15360: $texengine = $env{'form.texengine'};
15361: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
15362: if ($currdef eq '') {
15363: unless ($texengine eq $Apache::lonnet::deftex) {
15364: $changes{'texengine'} = 1;
15365: }
15366: } elsif ($currdef ne $texengine) {
15367: $changes{'texengine'} = 1;
15368: }
15369: }
15370: if ($texengine ne '') {
15371: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15372: }
15373: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15374: my @currclonecode;
15375: if (ref($currclone) eq 'HASH') {
15376: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15377: @currclonecode = @{$currclone->{'instcode'}};
15378: }
15379: }
15380: my $newclone;
15381: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
15382: $newclone = $env{'form.canclone'};
15383: }
15384: if ($newclone eq 'instcode') {
15385: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15386: my (%codedefaults,@code_order,@clonecode);
15387: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15388: \@code_order);
15389: foreach my $item (@code_order) {
15390: if (grep(/^\Q$item\E$/,@newcodes)) {
15391: push(@clonecode,$item);
15392: }
15393: }
15394: if (@clonecode) {
15395: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15396: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15397: if (@diffs) {
15398: $changes{'canclone'} = 1;
15399: }
15400: } else {
15401: $newclone eq '';
15402: }
15403: } elsif ($newclone ne '') {
15404: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15405: }
15406: if ($newclone ne $currclone) {
15407: $changes{'canclone'} = 1;
15408: }
15409: my %credits;
15410: foreach my $type (@types) {
15411: unless ($type eq 'community') {
15412: $credits{$type} = $env{'form.'.$type.'_credits'};
15413: $credits{$type} =~ s/[^\d.]+//g;
15414: }
15415: }
15416: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15417: ($env{'form.coursecredits'} eq '1')) {
15418: $changes{'coursecredits'} = 1;
15419: foreach my $type (keys(%credits)) {
15420: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15421: }
15422: } else {
15423: if ($env{'form.coursecredits'} eq '1') {
15424: foreach my $type (@types) {
15425: unless ($type eq 'community') {
15426: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
15427: $changes{'coursecredits'} = 1;
15428: }
15429: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15430: }
15431: }
15432: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15433: foreach my $type (@types) {
15434: unless ($type eq 'community') {
15435: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15436: $changes{'coursecredits'} = 1;
15437: last;
15438: }
15439: }
15440: }
15441: }
15442: }
15443: if ($env{'form.postsubmit'} eq '1') {
15444: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15445: my %currtimeout;
15446: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15447: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15448: $changes{'postsubmit'} = 1;
15449: }
15450: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15451: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15452: }
15453: } else {
15454: $changes{'postsubmit'} = 1;
15455: }
15456: foreach my $type (@types) {
15457: my $timeout = $env{'form.'.$type.'_timeout'};
15458: $timeout =~ s/\D//g;
15459: if ($timeout == $staticdefaults{'postsubmit'}) {
15460: $timeout = '';
15461: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15462: $timeout = '0';
15463: }
15464: unless ($timeout eq '') {
15465: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15466: }
15467: if (exists($currtimeout{$type})) {
15468: if ($timeout ne $currtimeout{$type}) {
15469: $changes{'postsubmit'} = 1;
15470: }
15471: } elsif ($timeout ne '') {
15472: $changes{'postsubmit'} = 1;
15473: }
15474: }
15475: } else {
15476: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15477: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15478: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15479: $changes{'postsubmit'} = 1;
15480: }
15481: } else {
15482: $changes{'postsubmit'} = 1;
15483: }
15484: }
15485: }
15486: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15487: $dom);
15488: if ($putresult eq 'ok') {
15489: if (keys(%changes) > 0) {
15490: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15491: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
15492: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
15493: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15494: foreach my $item ('uselcmath','usejsme','texengine') {
15495: if ($changes{$item}) {
15496: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15497: }
15498: }
15499: if ($changes{'coursecredits'}) {
15500: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15501: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15502: $domdefaults{$type.'credits'} =
15503: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15504: }
15505: }
15506: }
15507: if ($changes{'postsubmit'}) {
15508: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15509: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15510: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15511: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15512: $domdefaults{$type.'postsubtimeout'} =
15513: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15514: }
15515: }
15516: }
15517: }
15518: if ($changes{'uploadquota'}) {
15519: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15520: foreach my $type (@types) {
15521: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15522: }
15523: }
15524: }
15525: if ($changes{'canclone'}) {
15526: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15527: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15528: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15529: if (@clonecodes) {
15530: $domdefaults{'canclone'} = join('+',@clonecodes);
15531: }
15532: }
15533: } else {
15534: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15535: }
15536: }
15537: my $cachetime = 24*60*60;
15538: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15539: if (ref($lastactref) eq 'HASH') {
15540: $lastactref->{'domdefaults'} = 1;
15541: }
15542: }
15543: $resulttext = &mt('Changes made:').'<ul>';
15544: foreach my $item (sort(keys(%changes))) {
15545: if ($item eq 'uselcmath') {
15546: if ($env{'form.'.$item} eq '1') {
15547: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15548: } else {
15549: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15550: }
15551: } elsif ($item eq 'usejsme') {
15552: if ($env{'form.'.$item} eq '1') {
15553: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15554: } else {
15555: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
15556: }
15557: } elsif ($item eq 'texengine') {
15558: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15559: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15560: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15561: }
15562: } elsif ($item eq 'anonsurvey_threshold') {
15563: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
15564: } elsif ($item eq 'uploadquota') {
15565: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15566: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15567: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15568: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
15569: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
15570:
15571: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15572: '</ul>'.
15573: '</li>';
15574: } else {
15575: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15576: }
15577: } elsif ($item eq 'mysqltables') {
15578: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15579: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15580: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15581: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15582: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15583: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15584: '</ul>'.
15585: '</li>';
15586: } else {
15587: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15588: }
15589: } elsif ($item eq 'postsubmit') {
15590: if ($domdefaults{'postsubmit'} eq 'off') {
15591: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15592: } else {
15593: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
15594: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15595: $resulttext .= &mt('durations:').'<ul>';
15596: foreach my $type (@types) {
15597: $resulttext .= '<li>';
15598: my $timeout;
15599: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15600: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15601: }
15602: my $display;
15603: if ($timeout eq '0') {
15604: $display = &mt('unlimited');
15605: } elsif ($timeout eq '') {
15606: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15607: } else {
15608: $display = &mt('[quant,_1,second]',$timeout);
15609: }
15610: if ($type eq 'community') {
15611: $resulttext .= &mt('Communities');
15612: } elsif ($type eq 'official') {
15613: $resulttext .= &mt('Official courses');
15614: } elsif ($type eq 'unofficial') {
15615: $resulttext .= &mt('Unofficial courses');
15616: } elsif ($type eq 'textbook') {
15617: $resulttext .= &mt('Textbook courses');
15618: }
15619: $resulttext .= ' -- '.$display.'</li>';
15620: }
15621: $resulttext .= '</ul>';
15622: }
15623: $resulttext .= '</li>';
15624: }
15625: } elsif ($item eq 'coursecredits') {
15626: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15627: if (($domdefaults{'officialcredits'} eq '') &&
15628: ($domdefaults{'unofficialcredits'} eq '') &&
15629: ($domdefaults{'textbookcredits'} eq '')) {
15630: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15631: } else {
15632: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15633: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15634: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
15635: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
15636: '</ul>'.
15637: '</li>';
15638: }
15639: } else {
15640: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15641: }
15642: } elsif ($item eq 'canclone') {
15643: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15644: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15645: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15646: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15647: }
15648: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15649: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15650: } else {
15651: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
15652: }
15653: }
15654: }
15655: $resulttext .= '</ul>';
15656: } else {
15657: $resulttext = &mt('No changes made to course defaults');
15658: }
15659: } else {
15660: $resulttext = '<span class="LC_error">'.
15661: &mt('An error occurred: [_1]',$putresult).'</span>';
15662: }
15663: return $resulttext;
15664: }
15665:
15666: sub modify_selfenrollment {
15667: my ($dom,$lastactref,%domconfig) = @_;
15668: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
15669: my @types = ('official','unofficial','community','textbook');
15670: my %titles = &tool_titles();
15671: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15672: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
15673: $ordered{'default'} = ['types','registered','approval','limit'];
15674:
15675: my (%roles,%shown,%toplevel);
15676: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15677:
15678: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15679: if ($domconfig{'selfenrollment'} eq '') {
15680: $domconfig{'selfenrollment'} = {};
15681: }
15682: }
15683: %toplevel = (
15684: admin => 'Configuration Rights',
15685: default => 'Default settings',
15686: validation => 'Validation of self-enrollment requests',
15687: );
15688: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
15689:
15690: if (ref($ordered{'admin'}) eq 'ARRAY') {
15691: foreach my $item (@{$ordered{'admin'}}) {
15692: foreach my $type (@types) {
15693: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15694: $selfenrollhash{'admin'}{$type}{$item} = 1;
15695: } else {
15696: $selfenrollhash{'admin'}{$type}{$item} = 0;
15697: }
15698: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15699: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15700: if ($selfenrollhash{'admin'}{$type}{$item} ne
15701: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15702: push(@{$changes{'admin'}{$type}},$item);
15703: }
15704: } else {
15705: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15706: push(@{$changes{'admin'}{$type}},$item);
15707: }
15708: }
15709: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15710: push(@{$changes{'admin'}{$type}},$item);
15711: }
15712: }
15713: }
15714: }
15715:
15716: foreach my $item (@{$ordered{'default'}}) {
15717: foreach my $type (@types) {
15718: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15719: if ($item eq 'types') {
15720: unless (($value eq 'all') || ($value eq 'dom')) {
15721: $value = '';
15722: }
15723: } elsif ($item eq 'registered') {
15724: unless ($value eq '1') {
15725: $value = 0;
15726: }
15727: } elsif ($item eq 'approval') {
15728: unless ($value =~ /^[012]$/) {
15729: $value = 0;
15730: }
15731: } else {
15732: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15733: $value = 'none';
15734: }
15735: }
15736: $selfenrollhash{'default'}{$type}{$item} = $value;
15737: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15738: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15739: if ($selfenrollhash{'default'}{$type}{$item} ne
15740: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15741: push(@{$changes{'default'}{$type}},$item);
15742: }
15743: } else {
15744: push(@{$changes{'default'}{$type}},$item);
15745: }
15746: } else {
15747: push(@{$changes{'default'}{$type}},$item);
15748: }
15749: if ($item eq 'limit') {
15750: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15751: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15752: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15753: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15754: }
15755: } else {
15756: $selfenrollhash{'default'}{$type}{'cap'} = '';
15757: }
15758: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15759: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15760: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15761: push(@{$changes{'default'}{$type}},'cap');
15762: }
15763: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15764: push(@{$changes{'default'}{$type}},'cap');
15765: }
15766: }
15767: }
15768: }
15769:
15770: foreach my $item (@{$itemsref}) {
15771: if ($item eq 'fields') {
15772: my @changed;
15773: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15774: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15775: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15776: }
15777: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15778: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15779: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15780: $domconfig{'selfenrollment'}{'validation'}{$item});
15781: } else {
15782: @changed = @{$selfenrollhash{'validation'}{$item}};
15783: }
15784: } else {
15785: @changed = @{$selfenrollhash{'validation'}{$item}};
15786: }
15787: if (@changed) {
15788: if ($selfenrollhash{'validation'}{$item}) {
15789: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15790: } else {
15791: $changes{'validation'}{$item} = &mt('None');
15792: }
15793: }
15794: } else {
15795: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15796: if ($item eq 'markup') {
15797: if ($env{'form.selfenroll_validation_'.$item}) {
15798: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15799: }
15800: }
15801: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15802: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15803: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15804: }
15805: }
15806: }
15807: }
15808:
15809: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15810: $dom);
15811: if ($putresult eq 'ok') {
15812: if (keys(%changes) > 0) {
15813: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15814: $resulttext = &mt('Changes made:').'<ul>';
15815: foreach my $key ('admin','default','validation') {
15816: if (ref($changes{$key}) eq 'HASH') {
15817: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15818: if ($key eq 'validation') {
15819: foreach my $item (@{$itemsref}) {
15820: if (exists($changes{$key}{$item})) {
15821: if ($item eq 'markup') {
15822: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15823: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15824: } else {
15825: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15826: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15827: }
15828: }
15829: }
15830: } else {
15831: foreach my $type (@types) {
15832: if ($type eq 'community') {
15833: $roles{'1'} = &mt('Community personnel');
15834: } else {
15835: $roles{'1'} = &mt('Course personnel');
15836: }
15837: if (ref($changes{$key}{$type}) eq 'ARRAY') {
15838: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15839: if ($key eq 'admin') {
15840: my @mgrdc = ();
15841: if (ref($ordered{$key}) eq 'ARRAY') {
15842: foreach my $item (@{$ordered{'admin'}}) {
15843: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15844: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15845: push(@mgrdc,$item);
15846: }
15847: }
15848: }
15849: if (@mgrdc) {
15850: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15851: } else {
15852: delete($domdefaults{$type.'selfenrolladmdc'});
15853: }
15854: }
15855: } else {
15856: if (ref($ordered{$key}) eq 'ARRAY') {
15857: foreach my $item (@{$ordered{$key}}) {
15858: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15859: $domdefaults{$type.'selfenroll'.$item} =
15860: $selfenrollhash{$key}{$type}{$item};
15861: }
15862: }
15863: }
15864: }
15865: }
15866: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15867: foreach my $item (@{$ordered{$key}}) {
15868: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15869: $resulttext .= '<li>';
15870: if ($key eq 'admin') {
15871: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15872: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15873: } else {
15874: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15875: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15876: }
15877: $resulttext .= '</li>';
15878: }
15879: }
15880: $resulttext .= '</ul></li>';
15881: }
15882: }
15883: $resulttext .= '</ul></li>';
15884: }
15885: }
15886: }
15887: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15888: my $cachetime = 24*60*60;
15889: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15890: if (ref($lastactref) eq 'HASH') {
15891: $lastactref->{'domdefaults'} = 1;
15892: }
15893: }
15894: $resulttext .= '</ul>';
15895: } else {
15896: $resulttext = &mt('No changes made to self-enrollment settings');
15897: }
15898: } else {
15899: $resulttext = '<span class="LC_error">'.
15900: &mt('An error occurred: [_1]',$putresult).'</span>';
15901: }
15902: return $resulttext;
15903: }
15904:
15905: sub modify_usersessions {
15906: my ($dom,$lastactref,%domconfig) = @_;
15907: my @hostingtypes = ('version','excludedomain','includedomain');
15908: my @offloadtypes = ('primary','default');
15909: my %types = (
15910: remote => \@hostingtypes,
15911: hosted => \@hostingtypes,
15912: spares => \@offloadtypes,
15913: );
15914: my @prefixes = ('remote','hosted','spares');
15915: my @lcversions = &Apache::lonnet::all_loncaparevs();
15916: my (%by_ip,%by_location,@intdoms);
15917: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
15918: my @locations = sort(keys(%by_location));
15919: my (%defaultshash,%changes);
15920: foreach my $prefix (@prefixes) {
15921: $defaultshash{'usersessions'}{$prefix} = {};
15922: }
15923: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15924: my $resulttext;
15925: my %iphost = &Apache::lonnet::get_iphost();
15926: foreach my $prefix (@prefixes) {
15927: next if ($prefix eq 'spares');
15928: foreach my $type (@{$types{$prefix}}) {
15929: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15930: if ($type eq 'version') {
15931: my $value = $env{'form.'.$prefix.'_'.$type};
15932: my $okvalue;
15933: if ($value ne '') {
15934: if (grep(/^\Q$value\E$/,@lcversions)) {
15935: $okvalue = $value;
15936: }
15937: }
15938: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15939: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15940: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
15941: if ($inuse == 0) {
15942: $changes{$prefix}{$type} = 1;
15943: } else {
15944: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
15945: $changes{$prefix}{$type} = 1;
15946: }
15947: if ($okvalue ne '') {
15948: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15949: }
15950: }
15951: } else {
15952: if (($inuse == 1) && ($okvalue ne '')) {
15953: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15954: $changes{$prefix}{$type} = 1;
15955: }
15956: }
15957: } else {
15958: if (($inuse == 1) && ($okvalue ne '')) {
15959: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15960: $changes{$prefix}{$type} = 1;
15961: }
15962: }
15963: } else {
15964: if (($inuse == 1) && ($okvalue ne '')) {
15965: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15966: $changes{$prefix}{$type} = 1;
15967: }
15968: }
15969: } else {
15970: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15971: my @okvals;
15972: foreach my $val (@vals) {
15973: if ($val =~ /:/) {
15974: my @items = split(/:/,$val);
15975: foreach my $item (@items) {
15976: if (ref($by_location{$item}) eq 'ARRAY') {
15977: push(@okvals,$item);
15978: }
15979: }
15980: } else {
15981: if (ref($by_location{$val}) eq 'ARRAY') {
15982: push(@okvals,$val);
15983: }
15984: }
15985: }
15986: @okvals = sort(@okvals);
15987: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15988: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15989: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15990: if ($inuse == 0) {
15991: $changes{$prefix}{$type} = 1;
15992: } else {
15993: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15994: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
15995: if (@changed > 0) {
15996: $changes{$prefix}{$type} = 1;
15997: }
15998: }
15999: } else {
16000: if ($inuse == 1) {
16001: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16002: $changes{$prefix}{$type} = 1;
16003: }
16004: }
16005: } else {
16006: if ($inuse == 1) {
16007: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16008: $changes{$prefix}{$type} = 1;
16009: }
16010: }
16011: } else {
16012: if ($inuse == 1) {
16013: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16014: $changes{$prefix}{$type} = 1;
16015: }
16016: }
16017: }
16018: }
16019: }
16020:
16021: my @alldoms = &Apache::lonnet::all_domains();
16022: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16023: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16024: my $savespares;
16025:
16026: foreach my $lonhost (sort(keys(%servers))) {
16027: my $serverhomeID =
16028: &Apache::lonnet::get_server_homeID($servers{$lonhost});
16029: my $serverhostname = &Apache::lonnet::hostname($lonhost);
16030: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16031: my %spareschg;
16032: foreach my $type (@{$types{'spares'}}) {
16033: my @okspares;
16034: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16035: foreach my $server (@checked) {
16036: if (&Apache::lonnet::hostname($server) ne '') {
16037: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16038: unless (grep(/^\Q$server\E$/,@okspares)) {
16039: push(@okspares,$server);
16040: }
16041: }
16042: }
16043: }
16044: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16045: my $newspare;
16046: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16047: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
16048: $newspare = $new;
16049: }
16050: }
16051: my @spares;
16052: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16053: @spares = sort(@okspares,$newspare);
16054: } else {
16055: @spares = sort(@okspares);
16056: }
16057: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
16058: if (ref($spareid{$lonhost}) eq 'HASH') {
16059: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
16060: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
16061: if (@diffs > 0) {
16062: $spareschg{$type} = 1;
16063: }
16064: }
16065: }
16066: }
16067: if (keys(%spareschg) > 0) {
16068: $changes{'spares'}{$lonhost} = \%spareschg;
16069: }
16070: }
16071: $defaultshash{'usersessions'}{'offloadnow'} = {};
16072: $defaultshash{'usersessions'}{'offloadoth'} = {};
16073: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16074: my @okoffload;
16075: if (@offloadnow) {
16076: foreach my $server (@offloadnow) {
16077: if (&Apache::lonnet::hostname($server) ne '') {
16078: unless (grep(/^\Q$server\E$/,@okoffload)) {
16079: push(@okoffload,$server);
16080: }
16081: }
16082: }
16083: if (@okoffload) {
16084: foreach my $lonhost (@okoffload) {
16085: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16086: }
16087: }
16088: }
16089: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
16090: my @okoffloadoth;
16091: if (@offloadoth) {
16092: foreach my $server (@offloadoth) {
16093: if (&Apache::lonnet::hostname($server) ne '') {
16094: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
16095: push(@okoffloadoth,$server);
16096: }
16097: }
16098: }
16099: if (@okoffloadoth) {
16100: foreach my $lonhost (@okoffloadoth) {
16101: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
16102: }
16103: }
16104: }
16105: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16106: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16107: if (ref($changes{'spares'}) eq 'HASH') {
16108: if (keys(%{$changes{'spares'}}) > 0) {
16109: $savespares = 1;
16110: }
16111: }
16112: } else {
16113: $savespares = 1;
16114: }
16115: foreach my $offload ('offloadnow','offloadoth') {
16116: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
16117: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
16118: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
16119: $changes{$offload} = 1;
16120: last;
16121: }
16122: }
16123: unless ($changes{$offload}) {
16124: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
16125: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
16126: $changes{$offload} = 1;
16127: last;
16128: }
16129: }
16130: }
16131: } else {
16132: if (($offload eq 'offloadnow') && (@okoffload)) {
16133: $changes{'offloadnow'} = 1;
16134: }
16135: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
16136: $changes{'offloadoth'} = 1;
16137: }
16138: }
16139: }
16140: } else {
16141: if (@okoffload) {
16142: $changes{'offloadnow'} = 1;
16143: }
16144: if (@okoffloadoth) {
16145: $changes{'offloadoth'} = 1;
16146: }
16147: }
16148: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16149: if ((keys(%changes) > 0) || ($savespares)) {
16150: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16151: $dom);
16152: if ($putresult eq 'ok') {
16153: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16154: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16155: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16156: }
16157: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16158: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16159: }
16160: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16161: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16162: }
16163: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16164: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
16165: }
16166: }
16167: my $cachetime = 24*60*60;
16168: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16169: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
16170: if (ref($lastactref) eq 'HASH') {
16171: $lastactref->{'domdefaults'} = 1;
16172: $lastactref->{'usersessions'} = 1;
16173: }
16174: if (keys(%changes) > 0) {
16175: my %lt = &usersession_titles();
16176: $resulttext = &mt('Changes made:').'<ul>';
16177: foreach my $prefix (@prefixes) {
16178: if (ref($changes{$prefix}) eq 'HASH') {
16179: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16180: if ($prefix eq 'spares') {
16181: if (ref($changes{$prefix}) eq 'HASH') {
16182: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16183: $resulttext .= '<li><b>'.$lonhost.'</b> ';
16184: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
16185: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16186: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16187: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16188: foreach my $type (@{$types{$prefix}}) {
16189: if ($changes{$prefix}{$lonhost}{$type}) {
16190: my $offloadto = &mt('None');
16191: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16192: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16193: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16194: }
16195: }
16196: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
16197: }
16198: }
16199: }
16200: $resulttext .= '</li>';
16201: }
16202: }
16203: } else {
16204: foreach my $type (@{$types{$prefix}}) {
16205: if (defined($changes{$prefix}{$type})) {
16206: my $newvalue;
16207: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16208: if (ref($defaultshash{'usersessions'}{$prefix})) {
16209: if ($type eq 'version') {
16210: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16211: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16212: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16213: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16214: }
16215: }
16216: }
16217: }
16218: if ($newvalue eq '') {
16219: if ($type eq 'version') {
16220: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16221: } else {
16222: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16223: }
16224: } else {
16225: if ($type eq 'version') {
16226: $newvalue .= ' '.&mt('(or later)');
16227: }
16228: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16229: }
16230: }
16231: }
16232: }
16233: $resulttext .= '</ul>';
16234: }
16235: }
16236: if ($changes{'offloadnow'}) {
16237: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16238: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16239: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
16240: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16241: $resulttext .= '<li>'.$lonhost.'</li>';
16242: }
16243: $resulttext .= '</ul>';
16244: } else {
16245: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
16246: }
16247: } else {
16248: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
16249: }
16250: }
16251: if ($changes{'offloadoth'}) {
16252: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
16253: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
16254: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
16255: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
16256: $resulttext .= '<li>'.$lonhost.'</li>';
16257: }
16258: $resulttext .= '</ul>';
16259: } else {
16260: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
16261: }
16262: } else {
16263: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
16264: }
16265: }
16266: $resulttext .= '</ul>';
16267: } else {
16268: $resulttext = $nochgmsg;
16269: }
16270: } else {
16271: $resulttext = '<span class="LC_error">'.
16272: &mt('An error occurred: [_1]',$putresult).'</span>';
16273: }
16274: } else {
16275: $resulttext = $nochgmsg;
16276: }
16277: return $resulttext;
16278: }
16279:
16280: sub modify_loadbalancing {
16281: my ($dom,%domconfig) = @_;
16282: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16283: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16284: my ($othertitle,$usertypes,$types) =
16285: &Apache::loncommon::sorted_inst_types($dom);
16286: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16287: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
16288: my @sparestypes = ('primary','default');
16289: my %typetitles = &sparestype_titles();
16290: my $resulttext;
16291: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
16292: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16293: %existing = %{$domconfig{'loadbalancing'}};
16294: }
16295: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16296: \%currtargets,\%currrules,\%currcookies);
16297: my ($saveloadbalancing,%defaultshash,%changes);
16298: my ($alltypes,$othertypes,$titles) =
16299: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16300: my %ruletitles = &offloadtype_text();
16301: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16302: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16303: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16304: if ($balancer eq '') {
16305: next;
16306: }
16307: if (!exists($servers{$balancer})) {
16308: if (exists($currbalancer{$balancer})) {
16309: push(@{$changes{'delete'}},$balancer);
16310: }
16311: next;
16312: }
16313: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16314: push(@{$changes{'delete'}},$balancer);
16315: next;
16316: }
16317: if (!exists($currbalancer{$balancer})) {
16318: push(@{$changes{'add'}},$balancer);
16319: }
16320: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16321: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16322: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16323: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16324: $saveloadbalancing = 1;
16325: }
16326: foreach my $sparetype (@sparestypes) {
16327: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16328: my @offloadto;
16329: foreach my $target (@targets) {
16330: if (($servers{$target}) && ($target ne $balancer)) {
16331: if ($sparetype eq 'default') {
16332: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16333: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
16334: }
16335: }
16336: unless(grep(/^\Q$target\E$/,@offloadto)) {
16337: push(@offloadto,$target);
16338: }
16339: }
16340: }
16341: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16342: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16343: push(@offloadto,$balancer);
16344: }
16345: }
16346: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
16347: }
16348: if ($env{'form.loadbalancing_cookie_'.$i}) {
16349: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
16350: if (exists($currbalancer{$balancer})) {
16351: unless ($currcookies{$balancer}) {
16352: $changes{'curr'}{$balancer}{'cookie'} = 1;
16353: }
16354: }
16355: } elsif (exists($currbalancer{$balancer})) {
16356: if ($currcookies{$balancer}) {
16357: $changes{'curr'}{$balancer}{'cookie'} = 1;
16358: }
16359: }
16360: if (ref($currtargets{$balancer}) eq 'HASH') {
16361: foreach my $sparetype (@sparestypes) {
16362: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16363: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
16364: if (@targetdiffs > 0) {
16365: $changes{'curr'}{$balancer}{'targets'} = 1;
16366: }
16367: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16368: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16369: $changes{'curr'}{$balancer}{'targets'} = 1;
16370: }
16371: }
16372: }
16373: } else {
16374: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
16375: foreach my $sparetype (@sparestypes) {
16376: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16377: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16378: $changes{'curr'}{$balancer}{'targets'} = 1;
16379: }
16380: }
16381: }
16382: }
16383: }
16384: my $ishomedom;
16385: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16386: $ishomedom = 1;
16387: }
16388: if (ref($alltypes) eq 'ARRAY') {
16389: foreach my $type (@{$alltypes}) {
16390: my $rule;
16391: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
16392: (!$ishomedom)) {
16393: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16394: }
16395: if ($rule eq 'specific') {
16396: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
16397: if (exists($servers{$specifiedhost})) {
16398: $rule = $specifiedhost;
16399: }
16400: }
16401: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16402: if (ref($currrules{$balancer}) eq 'HASH') {
16403: if ($rule ne $currrules{$balancer}{$type}) {
16404: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
16405: }
16406: } elsif ($rule ne '') {
16407: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
16408: }
16409: }
16410: }
16411: }
16412: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16413: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16414: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16415: $defaultshash{'loadbalancing'} = {};
16416: }
16417: my $putresult = &Apache::lonnet::put_dom('configuration',
16418: \%defaultshash,$dom);
16419: if ($putresult eq 'ok') {
16420: if (keys(%changes) > 0) {
16421: my %toupdate;
16422: if (ref($changes{'delete'}) eq 'ARRAY') {
16423: foreach my $balancer (sort(@{$changes{'delete'}})) {
16424: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
16425: $toupdate{$balancer} = 1;
16426: }
16427: }
16428: if (ref($changes{'add'}) eq 'ARRAY') {
16429: foreach my $balancer (sort(@{$changes{'add'}})) {
16430: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
16431: $toupdate{$balancer} = 1;
16432: }
16433: }
16434: if (ref($changes{'curr'}) eq 'HASH') {
16435: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
16436: $toupdate{$balancer} = 1;
16437: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16438: if ($changes{'curr'}{$balancer}{'targets'}) {
16439: my %offloadstr;
16440: foreach my $sparetype (@sparestypes) {
16441: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16442: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16443: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16444: }
16445: }
16446: }
16447: if (keys(%offloadstr) == 0) {
16448: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
16449: } else {
16450: my $showoffload;
16451: foreach my $sparetype (@sparestypes) {
16452: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16453: if (defined($offloadstr{$sparetype})) {
16454: $showoffload .= $offloadstr{$sparetype};
16455: } else {
16456: $showoffload .= &mt('None');
16457: }
16458: $showoffload .= (' 'x3);
16459: }
16460: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
16461: }
16462: }
16463: }
16464: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16465: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16466: foreach my $type (@{$alltypes}) {
16467: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16468: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16469: my $balancetext;
16470: if ($rule eq '') {
16471: $balancetext = $ruletitles{'default'};
16472: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
16473: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
16474: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
16475: foreach my $sparetype (@sparestypes) {
16476: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16477: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16478: }
16479: }
16480: foreach my $item (@{$alltypes}) {
16481: next if ($item =~ /^_LC_ipchange/);
16482: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16483: if ($hasrule eq 'homeserver') {
16484: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16485: } else {
16486: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16487: if ($servers{$hasrule}) {
16488: $toupdate{$hasrule} = 1;
16489: }
16490: }
16491: }
16492: }
16493: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16494: $balancetext = $ruletitles{$rule};
16495: } else {
16496: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16497: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16498: if ($receiver) {
16499: $toupdate{$receiver};
16500: }
16501: }
16502: } else {
16503: $balancetext = $ruletitles{$rule};
16504: }
16505: } else {
16506: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16507: }
16508: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
16509: }
16510: }
16511: }
16512: }
16513: if ($changes{'curr'}{$balancer}{'cookie'}) {
16514: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
16515: $balancer).'</li>';
16516: }
16517: }
16518: }
16519: if (keys(%toupdate)) {
16520: my %thismachine;
16521: my $updatedhere;
16522: my $cachetime = 60*60*24;
16523: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16524: foreach my $lonhost (keys(%toupdate)) {
16525: if ($thismachine{$lonhost}) {
16526: unless ($updatedhere) {
16527: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16528: $defaultshash{'loadbalancing'},
16529: $cachetime);
16530: $updatedhere = 1;
16531: }
16532: } else {
16533: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16534: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16535: }
16536: }
16537: }
16538: if ($resulttext ne '') {
16539: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
16540: } else {
16541: $resulttext = $nochgmsg;
16542: }
16543: } else {
16544: $resulttext = $nochgmsg;
16545: }
16546: } else {
16547: $resulttext = '<span class="LC_error">'.
16548: &mt('An error occurred: [_1]',$putresult).'</span>';
16549: }
16550: } else {
16551: $resulttext = $nochgmsg;
16552: }
16553: return $resulttext;
16554: }
16555:
16556: sub recurse_check {
16557: my ($chkcats,$categories,$depth,$name) = @_;
16558: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16559: my $chg = 0;
16560: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16561: my $category = $chkcats->[$depth]{$name}[$j];
16562: my $item;
16563: if ($category eq '') {
16564: $chg ++;
16565: } else {
16566: my $deeper = $depth + 1;
16567: $item = &escape($category).':'.&escape($name).':'.$depth;
16568: if ($chg) {
16569: $categories->{$item} -= $chg;
16570: }
16571: &recurse_check($chkcats,$categories,$deeper,$category);
16572: $deeper --;
16573: }
16574: }
16575: }
16576: return;
16577: }
16578:
16579: sub recurse_cat_deletes {
16580: my ($item,$coursecategories,$deletions) = @_;
16581: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16582: my $subdepth = $depth + 1;
16583: if (ref($coursecategories) eq 'HASH') {
16584: foreach my $subitem (keys(%{$coursecategories})) {
16585: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16586: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16587: delete($coursecategories->{$subitem});
16588: $deletions->{$subitem} = 1;
16589: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
16590: }
16591: }
16592: }
16593: return;
16594: }
16595:
16596: sub active_dc_picker {
16597: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
16598: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
16599: my @domcoord = keys(%domcoords);
16600: if (keys(%currhash)) {
16601: foreach my $dc (keys(%currhash)) {
16602: unless (exists($domcoords{$dc})) {
16603: push(@domcoord,$dc);
16604: }
16605: }
16606: }
16607: @domcoord = sort(@domcoord);
16608: my $numdcs = scalar(@domcoord);
16609: my $rows = 0;
16610: my $table;
16611: if ($numdcs > 1) {
16612: $table = '<table>';
16613: for (my $i=0; $i<@domcoord; $i++) {
16614: my $rem = $i%($numinrow);
16615: if ($rem == 0) {
16616: if ($i > 0) {
16617: $table .= '</tr>';
16618: }
16619: $table .= '<tr>';
16620: $rows ++;
16621: }
16622: my $check = '';
16623: if ($inputtype eq 'radio') {
16624: if (keys(%currhash) == 0) {
16625: if (!$i) {
16626: $check = ' checked="checked"';
16627: }
16628: } elsif (exists($currhash{$domcoord[$i]})) {
16629: $check = ' checked="checked"';
16630: }
16631: } else {
16632: if (exists($currhash{$domcoord[$i]})) {
16633: $check = ' checked="checked"';
16634: }
16635: }
16636: if ($i == @domcoord - 1) {
16637: my $colsleft = $numinrow - $rem;
16638: if ($colsleft > 1) {
16639: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
16640: } else {
16641: $table .= '<td class="LC_left_item">';
16642: }
16643: } else {
16644: $table .= '<td class="LC_left_item">';
16645: }
16646: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16647: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16648: $table .= '<span class="LC_nobreak"><label>'.
16649: '<input type="'.$inputtype.'" name="'.$name.'"'.
16650: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16651: if ($user ne $dcname.':'.$dcdom) {
16652: $table .= ' ('.$dcname.':'.$dcdom.')';
16653: }
16654: $table .= '</label></span></td>';
16655: }
16656: $table .= '</tr></table>';
16657: } elsif ($numdcs == 1) {
16658: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16659: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16660: if ($inputtype eq 'radio') {
16661: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
16662: if ($user ne $dcname.':'.$dcdom) {
16663: $table .= ' ('.$dcname.':'.$dcdom.')';
16664: }
16665: } else {
16666: my $check;
16667: if (exists($currhash{$domcoord[0]})) {
16668: $check = ' checked="checked"';
16669: }
16670: $table = '<span class="LC_nobreak"><label>'.
16671: '<input type="checkbox" name="'.$name.'" '.
16672: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
16673: if ($user ne $dcname.':'.$dcdom) {
16674: $table .= ' ('.$dcname.':'.$dcdom.')';
16675: }
16676: $table .= '</label></span>';
16677: $rows ++;
16678: }
16679: }
16680: return ($numdcs,$table,$rows);
16681: }
16682:
16683: sub usersession_titles {
16684: return &Apache::lonlocal::texthash(
16685: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
16686: remote => 'Hosting of sessions for users in this domain on servers in other domains',
16687: spares => 'Servers offloaded to, when busy',
16688: version => 'LON-CAPA version requirement',
16689: excludedomain => 'Allow all, but exclude specific domains',
16690: includedomain => 'Deny all, but include specific domains',
16691: primary => 'Primary (checked first)',
16692: default => 'Default',
16693: );
16694: }
16695:
16696: sub id_for_thisdom {
16697: my (%servers) = @_;
16698: my %altids;
16699: foreach my $server (keys(%servers)) {
16700: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16701: if ($serverhome ne $server) {
16702: $altids{$serverhome} = $server;
16703: }
16704: }
16705: return %altids;
16706: }
16707:
16708: sub count_servers {
16709: my ($currbalancer,%servers) = @_;
16710: my (@spares,$numspares);
16711: foreach my $lonhost (sort(keys(%servers))) {
16712: next if ($currbalancer eq $lonhost);
16713: push(@spares,$lonhost);
16714: }
16715: if ($currbalancer) {
16716: $numspares = scalar(@spares);
16717: } else {
16718: $numspares = scalar(@spares) - 1;
16719: }
16720: return ($numspares,@spares);
16721: }
16722:
16723: sub lonbalance_targets_js {
16724: my ($dom,$types,$servers,$settings) = @_;
16725: my $select = &mt('Select');
16726: my ($alltargets,$allishome,$allinsttypes,@alltypes);
16727: if (ref($servers) eq 'HASH') {
16728: $alltargets = join("','",sort(keys(%{$servers})));
16729: my @homedoms;
16730: foreach my $server (sort(keys(%{$servers}))) {
16731: if (&Apache::lonnet::host_domain($server) eq $dom) {
16732: push(@homedoms,'1');
16733: } else {
16734: push(@homedoms,'0');
16735: }
16736: }
16737: $allishome = join("','",@homedoms);
16738: }
16739: if (ref($types) eq 'ARRAY') {
16740: if (@{$types} > 0) {
16741: @alltypes = @{$types};
16742: }
16743: }
16744: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
16745: $allinsttypes = join("','",@alltypes);
16746: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
16747: if (ref($settings) eq 'HASH') {
16748: %existing = %{$settings};
16749: }
16750: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
16751: \%currtargets,\%currrules,\%currcookies);
16752: my $balancers = join("','",sort(keys(%currbalancer)));
16753: return <<"END";
16754:
16755: <script type="text/javascript">
16756: // <![CDATA[
16757:
16758: currBalancers = new Array('$balancers');
16759:
16760: function toggleTargets(balnum) {
16761: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16762: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
16763: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
16764: var prevbalancer = prevhostitem.value;
16765: var baltotal = document.getElementById('loadbalancing_total').value;
16766: prevhostitem.value = balancer;
16767: if (prevbalancer != '') {
16768: var prevIdx = currBalancers.indexOf(prevbalancer);
16769: if (prevIdx != -1) {
16770: currBalancers.splice(prevIdx,1);
16771: }
16772: }
16773: if (balancer == '') {
16774: hideSpares(balnum);
16775: } else {
16776: var currIdx = currBalancers.indexOf(balancer);
16777: if (currIdx == -1) {
16778: currBalancers.push(balancer);
16779: }
16780: var homedoms = new Array('$allishome');
16781: var ishomedom = homedoms[lonhostitem.selectedIndex];
16782: showSpares(balancer,ishomedom,balnum);
16783: }
16784: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
16785: return;
16786: }
16787:
16788: function showSpares(balancer,ishomedom,balnum) {
16789: var alltargets = new Array('$alltargets');
16790: var insttypes = new Array('$allinsttypes');
16791: var offloadtypes = new Array('primary','default');
16792:
16793: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
16794: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
16795:
16796: for (var i=0; i<offloadtypes.length; i++) {
16797: var count = 0;
16798: for (var j=0; j<alltargets.length; j++) {
16799: if (alltargets[j] != balancer) {
16800: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
16801: item.value = alltargets[j];
16802: item.style.textAlign='left';
16803: item.style.textFace='normal';
16804: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
16805: if (currBalancers.indexOf(alltargets[j]) == -1) {
16806: item.disabled = '';
16807: } else {
16808: item.disabled = 'disabled';
16809: item.checked = false;
16810: }
16811: count ++;
16812: }
16813: }
16814: }
16815: for (var k=0; k<insttypes.length; k++) {
16816: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
16817: if (ishomedom == 1) {
16818: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16819: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
16820: } else {
16821: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16822: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
16823: }
16824: } else {
16825: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16826: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
16827: }
16828: if ((insttypes[k] != '_LC_external') &&
16829: ((insttypes[k] != '_LC_internetdom') ||
16830: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
16831: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
16832: item.options.length = 0;
16833: item.options[0] = new Option("","",true,true);
16834: var idx = 0;
16835: for (var m=0; m<alltargets.length; m++) {
16836: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
16837: idx ++;
16838: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
16839: }
16840: }
16841: }
16842: }
16843: return;
16844: }
16845:
16846: function hideSpares(balnum) {
16847: var alltargets = new Array('$alltargets');
16848: var insttypes = new Array('$allinsttypes');
16849: var offloadtypes = new Array('primary','default');
16850:
16851: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
16852: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
16853:
16854: var total = alltargets.length - 1;
16855: for (var i=0; i<offloadtypes; i++) {
16856: for (var j=0; j<total; j++) {
16857: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
16858: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
16859: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
16860: }
16861: }
16862: for (var k=0; k<insttypes.length; k++) {
16863: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16864: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
16865: if (insttypes[k] != '_LC_external') {
16866: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
16867: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
16868: }
16869: }
16870: return;
16871: }
16872:
16873: function checkOffloads(item,balnum,type) {
16874: var alltargets = new Array('$alltargets');
16875: var offloadtypes = new Array('primary','default');
16876: if (item.checked) {
16877: var total = alltargets.length - 1;
16878: var other;
16879: if (type == offloadtypes[0]) {
16880: other = offloadtypes[1];
16881: } else {
16882: other = offloadtypes[0];
16883: }
16884: for (var i=0; i<total; i++) {
16885: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
16886: if (server == item.value) {
16887: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
16888: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
16889: }
16890: }
16891: }
16892: }
16893: return;
16894: }
16895:
16896: function singleServerToggle(balnum,type) {
16897: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
16898: if (offloadtoSelIdx == 0) {
16899: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
16900: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
16901:
16902: } else {
16903: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
16904: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
16905: }
16906: return;
16907: }
16908:
16909: function balanceruleChange(formname,balnum,type) {
16910: if (type == '_LC_external') {
16911: return;
16912: }
16913: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
16914: for (var i=0; i<typesRules.length; i++) {
16915: if (formname.elements[typesRules[i]].checked) {
16916: if (formname.elements[typesRules[i]].value != 'specific') {
16917: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
16918: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
16919: } else {
16920: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
16921: }
16922: }
16923: }
16924: return;
16925: }
16926:
16927: function balancerDeleteChange(balnum) {
16928: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16929: var baltotal = document.getElementById('loadbalancing_total').value;
16930: var addtarget;
16931: var removetarget;
16932: var action = 'delete';
16933: if (document.getElementById('loadbalancing_delete_'+balnum)) {
16934: var lonhost = hostitem.value;
16935: var currIdx = currBalancers.indexOf(lonhost);
16936: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
16937: if (currIdx != -1) {
16938: currBalancers.splice(currIdx,1);
16939: }
16940: addtarget = lonhost;
16941: } else {
16942: if (currIdx == -1) {
16943: currBalancers.push(lonhost);
16944: }
16945: removetarget = lonhost;
16946: action = 'undelete';
16947: }
16948: balancerChange(balnum,baltotal,action,addtarget,removetarget);
16949: }
16950: return;
16951: }
16952:
16953: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
16954: if (baltotal > 1) {
16955: var offloadtypes = new Array('primary','default');
16956: var alltargets = new Array('$alltargets');
16957: var insttypes = new Array('$allinsttypes');
16958: for (var i=0; i<baltotal; i++) {
16959: if (i != balnum) {
16960: for (var j=0; j<offloadtypes.length; j++) {
16961: var total = alltargets.length - 1;
16962: for (var k=0; k<total; k++) {
16963: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
16964: var server = serveritem.value;
16965: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16966: if (server == addtarget) {
16967: serveritem.disabled = '';
16968: }
16969: }
16970: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16971: if (server == removetarget) {
16972: serveritem.disabled = 'disabled';
16973: serveritem.checked = false;
16974: }
16975: }
16976: }
16977: }
16978: for (var j=0; j<insttypes.length; j++) {
16979: if (insttypes[j] != '_LC_external') {
16980: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
16981: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
16982: var currSel = singleserver.selectedIndex;
16983: var currVal = singleserver.options[currSel].value;
16984: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16985: var numoptions = singleserver.options.length;
16986: var needsnew = 1;
16987: for (var k=0; k<numoptions; k++) {
16988: if (singleserver.options[k] == addtarget) {
16989: needsnew = 0;
16990: break;
16991: }
16992: }
16993: if (needsnew == 1) {
16994: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
16995: }
16996: }
16997: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16998: singleserver.options.length = 0;
16999: if ((currVal) && (currVal != removetarget)) {
17000: singleserver.options[0] = new Option("","",false,false);
17001: } else {
17002: singleserver.options[0] = new Option("","",true,true);
17003: }
17004: var idx = 0;
17005: for (var m=0; m<alltargets.length; m++) {
17006: if (currBalancers.indexOf(alltargets[m]) == -1) {
17007: idx ++;
17008: if (currVal == alltargets[m]) {
17009: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17010: } else {
17011: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17012: }
17013: }
17014: }
17015: }
17016: }
17017: }
17018: }
17019: }
17020: }
17021: }
17022: return;
17023: }
17024:
17025: // ]]>
17026: </script>
17027:
17028: END
17029: }
17030:
17031: sub new_spares_js {
17032: my @sparestypes = ('primary','default');
17033: my $types = join("','",@sparestypes);
17034: my $select = &mt('Select');
17035: return <<"END";
17036:
17037: <script type="text/javascript">
17038: // <![CDATA[
17039:
17040: function updateNewSpares(formname,lonhost) {
17041: var types = new Array('$types');
17042: var include = new Array();
17043: var exclude = new Array();
17044: for (var i=0; i<types.length; i++) {
17045: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17046: for (var j=0; j<spareboxes.length; j++) {
17047: if (formname.elements[spareboxes[j]].checked) {
17048: exclude.push(formname.elements[spareboxes[j]].value);
17049: } else {
17050: include.push(formname.elements[spareboxes[j]].value);
17051: }
17052: }
17053: }
17054: for (var i=0; i<types.length; i++) {
17055: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17056: var selIdx = newSpare.selectedIndex;
17057: var currnew = newSpare.options[selIdx].value;
17058: var okSpares = new Array();
17059: for (var j=0; j<newSpare.options.length; j++) {
17060: var possible = newSpare.options[j].value;
17061: if (possible != '') {
17062: if (exclude.indexOf(possible) == -1) {
17063: okSpares.push(possible);
17064: } else {
17065: if (currnew == possible) {
17066: selIdx = 0;
17067: }
17068: }
17069: }
17070: }
17071: for (var k=0; k<include.length; k++) {
17072: if (okSpares.indexOf(include[k]) == -1) {
17073: okSpares.push(include[k]);
17074: }
17075: }
17076: okSpares.sort();
17077: newSpare.options.length = 0;
17078: if (selIdx == 0) {
17079: newSpare.options[0] = new Option("$select","",true,true);
17080: } else {
17081: newSpare.options[0] = new Option("$select","",false,false);
17082: }
17083: for (var m=0; m<okSpares.length; m++) {
17084: var idx = m+1;
17085: var selThis = 0;
17086: if (selIdx != 0) {
17087: if (okSpares[m] == currnew) {
17088: selThis = 1;
17089: }
17090: }
17091: if (selThis == 1) {
17092: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17093: } else {
17094: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17095: }
17096: }
17097: }
17098: return;
17099: }
17100:
17101: function checkNewSpares(lonhost,type) {
17102: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17103: var chosen = newSpare.options[newSpare.selectedIndex].value;
17104: if (chosen != '') {
17105: var othertype;
17106: var othernewSpare;
17107: if (type == 'primary') {
17108: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17109: }
17110: if (type == 'default') {
17111: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17112: }
17113: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17114: othernewSpare.selectedIndex = 0;
17115: }
17116: }
17117: return;
17118: }
17119:
17120: // ]]>
17121: </script>
17122:
17123: END
17124:
17125: }
17126:
17127: sub common_domprefs_js {
17128: return <<"END";
17129:
17130: <script type="text/javascript">
17131: // <![CDATA[
17132:
17133: function getIndicesByName(formname,item) {
17134: var group = new Array();
17135: for (var i=0;i<formname.elements.length;i++) {
17136: if (formname.elements[i].name == item) {
17137: group.push(formname.elements[i].id);
17138: }
17139: }
17140: return group;
17141: }
17142:
17143: // ]]>
17144: </script>
17145:
17146: END
17147:
17148: }
17149:
17150: sub recaptcha_js {
17151: my %lt = &captcha_phrases();
17152: return <<"END";
17153:
17154: <script type="text/javascript">
17155: // <![CDATA[
17156:
17157: function updateCaptcha(caller,context) {
17158: var privitem;
17159: var pubitem;
17160: var privtext;
17161: var pubtext;
17162: var versionitem;
17163: var versiontext;
17164: if (document.getElementById(context+'_recaptchapub')) {
17165: pubitem = document.getElementById(context+'_recaptchapub');
17166: } else {
17167: return;
17168: }
17169: if (document.getElementById(context+'_recaptchapriv')) {
17170: privitem = document.getElementById(context+'_recaptchapriv');
17171: } else {
17172: return;
17173: }
17174: if (document.getElementById(context+'_recaptchapubtxt')) {
17175: pubtext = document.getElementById(context+'_recaptchapubtxt');
17176: } else {
17177: return;
17178: }
17179: if (document.getElementById(context+'_recaptchaprivtxt')) {
17180: privtext = document.getElementById(context+'_recaptchaprivtxt');
17181: } else {
17182: return;
17183: }
17184: if (document.getElementById(context+'_recaptchaversion')) {
17185: versionitem = document.getElementById(context+'_recaptchaversion');
17186: } else {
17187: return;
17188: }
17189: if (document.getElementById(context+'_recaptchavertxt')) {
17190: versiontext = document.getElementById(context+'_recaptchavertxt');
17191: } else {
17192: return;
17193: }
17194: if (caller.checked) {
17195: if (caller.value == 'recaptcha') {
17196: pubitem.type = 'text';
17197: privitem.type = 'text';
17198: pubitem.size = '40';
17199: privitem.size = '40';
17200: pubtext.innerHTML = "$lt{'pub'}";
17201: privtext.innerHTML = "$lt{'priv'}";
17202: versionitem.type = 'text';
17203: versionitem.size = '3';
17204: versiontext.innerHTML = "$lt{'ver'}";
17205: } else {
17206: pubitem.type = 'hidden';
17207: privitem.type = 'hidden';
17208: versionitem.type = 'hidden';
17209: pubtext.innerHTML = '';
17210: privtext.innerHTML = '';
17211: versiontext.innerHTML = '';
17212: }
17213: }
17214: return;
17215: }
17216:
17217: // ]]>
17218: </script>
17219:
17220: END
17221:
17222: }
17223:
17224: sub toggle_display_js {
17225: return <<"END";
17226:
17227: <script type="text/javascript">
17228: // <![CDATA[
17229:
17230: function toggleDisplay(domForm,caller) {
17231: if (document.getElementById(caller)) {
17232: var divitem = document.getElementById(caller);
17233: var optionsElement = domForm.coursecredits;
17234: var checkval = 1;
17235: var dispval = 'block';
17236: var selfcreateRegExp = /^cancreate_emailverified/;
17237: if (caller == 'emailoptions') {
17238: optionsElement = domForm.cancreate_email;
17239: }
17240: if (caller == 'studentsubmission') {
17241: optionsElement = domForm.postsubmit;
17242: }
17243: if (caller == 'cloneinstcode') {
17244: optionsElement = domForm.canclone;
17245: checkval = 'instcode';
17246: }
17247: if (selfcreateRegExp.test(caller)) {
17248: optionsElement = domForm.elements[caller];
17249: checkval = 'other';
17250: dispval = 'inline'
17251: }
17252: if (optionsElement.length) {
17253: var currval;
17254: for (var i=0; i<optionsElement.length; i++) {
17255: if (optionsElement[i].checked) {
17256: currval = optionsElement[i].value;
17257: }
17258: }
17259: if (currval == checkval) {
17260: divitem.style.display = dispval;
17261: } else {
17262: divitem.style.display = 'none';
17263: }
17264: }
17265: }
17266: return;
17267: }
17268:
17269: // ]]>
17270: </script>
17271:
17272: END
17273:
17274: }
17275:
17276: sub captcha_phrases {
17277: return &Apache::lonlocal::texthash (
17278: priv => 'Private key',
17279: pub => 'Public key',
17280: original => 'original (CAPTCHA)',
17281: recaptcha => 'successor (ReCAPTCHA)',
17282: notused => 'unused',
17283: ver => 'ReCAPTCHA version (1 or 2)',
17284: );
17285: }
17286:
17287: sub devalidate_remote_domconfs {
17288: my ($dom,$cachekeys) = @_;
17289: return unless (ref($cachekeys) eq 'HASH');
17290: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17291: my %thismachine;
17292: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17293: my @posscached = ('domainconfig','domdefaults','usersessions',
17294: 'ltitools','directorysrch','passwdconf','cats');
17295: if (keys(%servers)) {
17296: foreach my $server (keys(%servers)) {
17297: next if ($thismachine{$server});
17298: my @cached;
17299: foreach my $name (@posscached) {
17300: if ($cachekeys->{$name}) {
17301: push(@cached,&escape($name).':'.&escape($dom));
17302: }
17303: }
17304: if (@cached) {
17305: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17306: }
17307: }
17308: }
17309: return;
17310: }
17311:
17312: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>