1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.307 2017/08/15 21:01:06 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ###############################################################
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
49: for use by individuals affiliated with the institution. Accordingly, each domain
50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
90: number of rows displayed on the page, and $action is the context (quotas,
91: requestcourses or requestauthor).
92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
98: used by course owners to request creation of a course, and to display/store
99: default quota sizes for Authoring Spaces.
100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
107: (official, unofficial, community, textbook, and placement).
108: In each case the radio buttons allow the selection of one of four values:
109:
110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
121: approval
122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
145: - course requests will be processed automatically up to a limit of
146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
166: use Apache::lonmsg();
167: use Apache::lonconfigsettings;
168: use Apache::lonuserutils();
169: use Apache::loncoursequeueadmin();
170: use LONCAPA qw(:DEFAULT :match);
171: use LONCAPA::Enrollment;
172: use LONCAPA::lonauthcgi();
173: use LONCAPA::SSL;
174: use File::Copy;
175: use Locale::Language;
176: use DateTime::TimeZone;
177: use DateTime::Locale;
178: use Time::HiRes qw( sleep );
179:
180: my $registered_cleanup;
181: my $modified_urls;
182:
183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
191: my $context = 'domain';
192: my $dom = $env{'request.role.domain'};
193: my $domdesc = &Apache::lonnet::domain($dom,'description');
194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
208: ['phase','actions']);
209: my $phase = 'pickactions';
210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
214: my %domconfig =
215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
220: 'coursedefaults','usersessions','loadbalancing',
221: 'requestauthor','selfenrollment','inststatus',
222: 'ltitools','ssl','trust'],$dom);
223: if (ref($domconfig{'ltitools'}) eq 'HASH') {
224: my %encconfig =
225: &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
228: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
229: foreach my $item ('key','secret') {
230: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
231: }
232: }
233: }
234: }
235: }
236: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
237: 'autoupdate','autocreate','directorysrch','contacts',
238: 'usercreation','selfcreation','usermodification','scantron',
239: 'requestcourses','requestauthor','coursecategories',
240: 'serverstatuses','helpsettings','coursedefaults',
241: 'ltitools','selfenrollment','usersessions','ssl','trust');
242: my %existing;
243: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
244: %existing = %{$domconfig{'loadbalancing'}};
245: }
246: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
247: push(@prefs_order,'loadbalancing');
248: }
249: my %prefs = (
250: 'rolecolors' =>
251: { text => 'Default color schemes',
252: help => 'Domain_Configuration_Color_Schemes',
253: header => [{col1 => 'Student Settings',
254: col2 => '',},
255: {col1 => 'Coordinator Settings',
256: col2 => '',},
257: {col1 => 'Author Settings',
258: col2 => '',},
259: {col1 => 'Administrator Settings',
260: col2 => '',}],
261: print => \&print_rolecolors,
262: modify => \&modify_rolecolors,
263: },
264: 'login' =>
265: { text => 'Log-in page options',
266: help => 'Domain_Configuration_Login_Page',
267: header => [{col1 => 'Log-in Page Items',
268: col2 => '',},
269: {col1 => 'Log-in Help',
270: col2 => 'Value'},
271: {col1 => 'Custom HTML in document head',
272: col2 => 'Value'}],
273: print => \&print_login,
274: modify => \&modify_login,
275: },
276: 'defaults' =>
277: { text => 'Default authentication/language/timezone/portal/types',
278: help => 'Domain_Configuration_LangTZAuth',
279: header => [{col1 => 'Setting',
280: col2 => 'Value'},
281: {col1 => 'Internal Authentication',
282: col2 => 'Value'},
283: {col1 => 'Institutional user types',
284: col2 => 'Name displayed'}],
285: print => \&print_defaults,
286: modify => \&modify_defaults,
287: },
288: 'quotas' =>
289: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
290: help => 'Domain_Configuration_Quotas',
291: header => [{col1 => 'User affiliation',
292: col2 => 'Available tools',
293: col3 => 'Quotas, MB; (Authoring requires role)',}],
294: print => \&print_quotas,
295: modify => \&modify_quotas,
296: },
297: 'autoenroll' =>
298: { text => 'Auto-enrollment settings',
299: help => 'Domain_Configuration_Auto_Enrollment',
300: header => [{col1 => 'Configuration setting',
301: col2 => 'Value(s)'}],
302: print => \&print_autoenroll,
303: modify => \&modify_autoenroll,
304: },
305: 'autoupdate' =>
306: { text => 'Auto-update settings',
307: help => 'Domain_Configuration_Auto_Updates',
308: header => [{col1 => 'Setting',
309: col2 => 'Value',},
310: {col1 => 'Setting',
311: col2 => 'Affiliation'},
312: {col1 => 'User population',
313: col2 => 'Updatable user data'}],
314: print => \&print_autoupdate,
315: modify => \&modify_autoupdate,
316: },
317: 'autocreate' =>
318: { text => 'Auto-course creation settings',
319: help => 'Domain_Configuration_Auto_Creation',
320: header => [{col1 => 'Configuration Setting',
321: col2 => 'Value',}],
322: print => \&print_autocreate,
323: modify => \&modify_autocreate,
324: },
325: 'directorysrch' =>
326: { text => 'Directory searches',
327: help => 'Domain_Configuration_InstDirectory_Search',
328: header => [{col1 => 'Institutional Directory Setting',
329: col2 => 'Value',},
330: {col1 => 'LON-CAPA Directory Setting',
331: col2 => 'Value',}],
332: print => \&print_directorysrch,
333: modify => \&modify_directorysrch,
334: },
335: 'contacts' =>
336: { text => 'E-mail addresses and helpform',
337: help => 'Domain_Configuration_Contact_Info',
338: header => [{col1 => 'Default e-mail addresses',
339: col2 => 'Value',},
340: {col1 => 'Recipient(s) for notifications',
341: col2 => 'Value',},
342: {col1 => 'Ask helpdesk form settings',
343: col2 => 'Value',},],
344: print => \&print_contacts,
345: modify => \&modify_contacts,
346: },
347: 'usercreation' =>
348: { text => 'User creation',
349: help => 'Domain_Configuration_User_Creation',
350: header => [{col1 => 'Format rule type',
351: col2 => 'Format rules in force'},
352: {col1 => 'User account creation',
353: col2 => 'Usernames which may be created',},
354: {col1 => 'Context',
355: col2 => 'Assignable authentication types'}],
356: print => \&print_usercreation,
357: modify => \&modify_usercreation,
358: },
359: 'selfcreation' =>
360: { text => 'Users self-creating accounts',
361: help => 'Domain_Configuration_Self_Creation',
362: header => [{col1 => 'Self-creation with institutional username',
363: col2 => 'Enabled?'},
364: {col1 => 'Institutional user type (login/SSO self-creation)',
365: col2 => 'Information user can enter'},
366: {col1 => 'Self-creation with e-mail verification',
367: col2 => 'Settings'}],
368: print => \&print_selfcreation,
369: modify => \&modify_selfcreation,
370: },
371: 'usermodification' =>
372: { text => 'User modification',
373: help => 'Domain_Configuration_User_Modification',
374: header => [{col1 => 'Target user has role',
375: col2 => 'User information updatable in author context'},
376: {col1 => 'Target user has role',
377: col2 => 'User information updatable in course context'}],
378: print => \&print_usermodification,
379: modify => \&modify_usermodification,
380: },
381: 'scantron' =>
382: { text => 'Bubblesheet format file',
383: help => 'Domain_Configuration_Scantron_Format',
384: header => [ {col1 => 'Item',
385: col2 => '',
386: }],
387: print => \&print_scantron,
388: modify => \&modify_scantron,
389: },
390: 'requestcourses' =>
391: {text => 'Request creation of courses',
392: help => 'Domain_Configuration_Request_Courses',
393: header => [{col1 => 'User affiliation',
394: col2 => 'Availability/Processing of requests',},
395: {col1 => 'Setting',
396: col2 => 'Value'},
397: {col1 => 'Available textbooks',
398: col2 => ''},
399: {col1 => 'Available templates',
400: col2 => ''},
401: {col1 => 'Validation (not official courses)',
402: col2 => 'Value'},],
403: print => \&print_quotas,
404: modify => \&modify_quotas,
405: },
406: 'requestauthor' =>
407: {text => 'Request Authoring Space',
408: help => 'Domain_Configuration_Request_Author',
409: header => [{col1 => 'User affiliation',
410: col2 => 'Availability/Processing of requests',},
411: {col1 => 'Setting',
412: col2 => 'Value'}],
413: print => \&print_quotas,
414: modify => \&modify_quotas,
415: },
416: 'coursecategories' =>
417: { text => 'Cataloging of courses/communities',
418: help => 'Domain_Configuration_Cataloging_Courses',
419: header => [{col1 => 'Catalog type/availability',
420: col2 => '',},
421: {col1 => 'Category settings for standard catalog',
422: col2 => '',},
423: {col1 => 'Categories',
424: col2 => '',
425: }],
426: print => \&print_coursecategories,
427: modify => \&modify_coursecategories,
428: },
429: 'serverstatuses' =>
430: {text => 'Access to server status pages',
431: help => 'Domain_Configuration_Server_Status',
432: header => [{col1 => 'Status Page',
433: col2 => 'Other named users',
434: col3 => 'Specific IPs',
435: }],
436: print => \&print_serverstatuses,
437: modify => \&modify_serverstatuses,
438: },
439: 'helpsettings' =>
440: {text => 'Support settings',
441: help => 'Domain_Configuration_Help_Settings',
442: header => [{col1 => 'Help Page Settings (logged-in users)',
443: col2 => 'Value'},
444: {col1 => 'Helpdesk Roles',
445: col2 => 'Settings'},],
446: print => \&print_helpsettings,
447: modify => \&modify_helpsettings,
448: },
449: 'coursedefaults' =>
450: {text => 'Course/Community defaults',
451: help => 'Domain_Configuration_Course_Defaults',
452: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
453: col2 => 'Value',},
454: {col1 => 'Defaults which can be overridden for each course by a DC',
455: col2 => 'Value',},],
456: print => \&print_coursedefaults,
457: modify => \&modify_coursedefaults,
458: },
459: 'selfenrollment' =>
460: {text => 'Self-enrollment in Course/Community',
461: help => 'Domain_Configuration_Selfenrollment',
462: header => [{col1 => 'Configuration Rights',
463: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
464: {col1 => 'Defaults',
465: col2 => 'Value'},
466: {col1 => 'Self-enrollment validation (optional)',
467: col2 => 'Value'},],
468: print => \&print_selfenrollment,
469: modify => \&modify_selfenrollment,
470: },
471: 'privacy' =>
472: {text => 'User Privacy',
473: help => 'Domain_Configuration_User_Privacy',
474: header => [{col1 => 'Setting',
475: col2 => 'Value',}],
476: print => \&print_privacy,
477: modify => \&modify_privacy,
478: },
479: 'usersessions' =>
480: {text => 'User session hosting/offloading',
481: help => 'Domain_Configuration_User_Sessions',
482: header => [{col1 => 'Domain server',
483: col2 => 'Servers to offload sessions to when busy'},
484: {col1 => 'Hosting of users from other domains',
485: col2 => 'Rules'},
486: {col1 => "Hosting domain's own users elsewhere",
487: col2 => 'Rules'}],
488: print => \&print_usersessions,
489: modify => \&modify_usersessions,
490: },
491: 'loadbalancing' =>
492: {text => 'Dedicated Load Balancer(s)',
493: help => 'Domain_Configuration_Load_Balancing',
494: header => [{col1 => 'Balancers',
495: col2 => 'Default destinations',
496: col3 => 'User affiliation',
497: col4 => 'Overrides'},
498: ],
499: print => \&print_loadbalancing,
500: modify => \&modify_loadbalancing,
501: },
502: 'ltitools' =>
503: {text => 'External Tools (LTI)',
504: help => 'Domain_Configuration_LTI_Tools',
505: header => [{col1 => 'Setting',
506: col2 => 'Value',}],
507: print => \&print_ltitools,
508: modify => \&modify_ltitools,
509: },
510: 'ssl' =>
511: {text => 'LON-CAPA Network (SSL)',
512: help => 'Domain_Configuration_Network_SSL',
513: header => [{col1 => 'Server',
514: col2 => 'Certificate Status'},
515: {col1 => 'Connections to other servers',
516: col2 => 'Rules'},
517: {col1 => 'Connections from other servers',
518: col2 => 'Rules'},
519: {col1 => "Replicating domain's published content",
520: col2 => 'Rules'}],
521: print => \&print_ssl,
522: modify => \&modify_ssl,
523: },
524: 'trust' =>
525: {text => 'Trust Settings',
526: help => 'Domain_Configuration_Trust',
527: header => [{col1 => "Access to this domain's content by others",
528: col2 => 'Rules'},
529: {col1 => "Access to other domain's content by this domain",
530: col2 => 'Rules'},
531: {col1 => "Enrollment in this domain's courses by others",
532: col2 => 'Rules',},
533: {col1 => "Co-author roles in this domain for others",
534: col2 => 'Rules',},
535: {col1 => "Co-author roles for this domain's users elsewhere",
536: col2 => 'Rules',},
537: {col1 => "Domain roles in this domain assignable to others",
538: col2 => 'Rules'},
539: {col1 => "Course catalog for this domain displayed elsewhere",
540: col2 => 'Rules'},
541: {col1 => "Requests for creation of courses in this domain by others",
542: col2 => 'Rules'},
543: {col1 => "Users in other domains can send messages to this domain",
544: col2 => 'Rules'},],
545: print => \&print_trust,
546: modify => \&modify_trust,
547: },
548: );
549: if (keys(%servers) > 1) {
550: $prefs{'login'} = { text => 'Log-in page options',
551: help => 'Domain_Configuration_Login_Page',
552: header => [{col1 => 'Log-in Service',
553: col2 => 'Server Setting',},
554: {col1 => 'Log-in Page Items',
555: col2 => ''},
556: {col1 => 'Log-in Help',
557: col2 => 'Value'},
558: {col1 => 'Custom HTML in document head',
559: col2 => 'Value'}],
560: print => \&print_login,
561: modify => \&modify_login,
562: };
563: }
564:
565: my @roles = ('student','coordinator','author','admin');
566: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
567: &Apache::lonhtmlcommon::add_breadcrumb
568: ({href=>"javascript:changePage(document.$phase,'pickactions')",
569: text=>"Settings to display/modify"});
570: my $confname = $dom.'-domainconfig';
571:
572: if ($phase eq 'process') {
573: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
574: \%prefs,\%domconfig,$confname,\@roles);
575: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
576: $r->rflush();
577: &devalidate_remote_domconfs($dom,$result);
578: }
579: } elsif ($phase eq 'display') {
580: my $js = &recaptcha_js().
581: &toggle_display_js();
582: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
583: my ($othertitle,$usertypes,$types) =
584: &Apache::loncommon::sorted_inst_types($dom);
585: $js .= &lonbalance_targets_js($dom,$types,\%servers,
586: $domconfig{'loadbalancing'}).
587: &new_spares_js().
588: &common_domprefs_js().
589: &Apache::loncommon::javascript_array_indexof();
590: }
591: if (grep(/^requestcourses$/,@actions)) {
592: my $javascript_validations;
593: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
594: $js .= <<END;
595: <script type="text/javascript">
596: $javascript_validations
597: </script>
598: $coursebrowserjs
599: END
600: }
601: if (grep(/^selfcreation$/,@actions)) {
602: $js .= &selfcreate_javascript();
603: }
604: if (grep(/^contacts$/,@actions)) {
605: $js .= &contacts_javascript();
606: }
607: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
608: } else {
609: # check if domconfig user exists for the domain.
610: my $servadm = $r->dir_config('lonAdmEMail');
611: my ($configuserok,$author_ok,$switchserver) =
612: &config_check($dom,$confname,$servadm);
613: unless ($configuserok eq 'ok') {
614: &Apache::lonconfigsettings::print_header($r,$phase,$context);
615: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
616: $confname).
617: '<br />'
618: );
619: if ($switchserver) {
620: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
621: '<br />'.
622: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
623: '<br />'.
624: &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).
625: '<br />'.
626: &mt('To do that now, use the following link: [_1]',$switchserver)
627: );
628: } else {
629: $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.').
630: '<br />'.
631: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
632: );
633: }
634: $r->print(&Apache::loncommon::end_page());
635: return OK;
636: }
637: if (keys(%domconfig) == 0) {
638: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
639: my @ids=&Apache::lonnet::current_machine_ids();
640: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
641: my %designhash = &Apache::loncommon::get_domainconf($dom);
642: my @loginimages = ('img','logo','domlogo','login');
643: my $custom_img_count = 0;
644: foreach my $img (@loginimages) {
645: if ($designhash{$dom.'.login.'.$img} ne '') {
646: $custom_img_count ++;
647: }
648: }
649: foreach my $role (@roles) {
650: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
651: $custom_img_count ++;
652: }
653: }
654: if ($custom_img_count > 0) {
655: &Apache::lonconfigsettings::print_header($r,$phase,$context);
656: my $switch_server = &check_switchserver($dom,$confname);
657: $r->print(
658: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
659: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
660: &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 />'.
661: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
662: if ($switch_server) {
663: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
664: }
665: $r->print(&Apache::loncommon::end_page());
666: return OK;
667: }
668: }
669: }
670: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
671: }
672: return OK;
673: }
674:
675: sub process_changes {
676: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
677: my %domconfig;
678: if (ref($values) eq 'HASH') {
679: %domconfig = %{$values};
680: }
681: my $output;
682: if ($action eq 'login') {
683: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
684: } elsif ($action eq 'rolecolors') {
685: $output = &modify_rolecolors($r,$dom,$confname,$roles,
686: $lastactref,%domconfig);
687: } elsif ($action eq 'quotas') {
688: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
689: } elsif ($action eq 'autoenroll') {
690: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
691: } elsif ($action eq 'autoupdate') {
692: $output = &modify_autoupdate($dom,%domconfig);
693: } elsif ($action eq 'autocreate') {
694: $output = &modify_autocreate($dom,%domconfig);
695: } elsif ($action eq 'directorysrch') {
696: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
697: } elsif ($action eq 'usercreation') {
698: $output = &modify_usercreation($dom,%domconfig);
699: } elsif ($action eq 'selfcreation') {
700: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
701: } elsif ($action eq 'usermodification') {
702: $output = &modify_usermodification($dom,%domconfig);
703: } elsif ($action eq 'contacts') {
704: $output = &modify_contacts($dom,$lastactref,%domconfig);
705: } elsif ($action eq 'defaults') {
706: $output = &modify_defaults($dom,$lastactref,%domconfig);
707: } elsif ($action eq 'scantron') {
708: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
709: } elsif ($action eq 'coursecategories') {
710: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
711: } elsif ($action eq 'serverstatuses') {
712: $output = &modify_serverstatuses($dom,%domconfig);
713: } elsif ($action eq 'requestcourses') {
714: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
715: } elsif ($action eq 'requestauthor') {
716: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
717: } elsif ($action eq 'helpsettings') {
718: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
719: } elsif ($action eq 'coursedefaults') {
720: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
721: } elsif ($action eq 'selfenrollment') {
722: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
723: } elsif ($action eq 'usersessions') {
724: $output = &modify_usersessions($dom,$lastactref,%domconfig);
725: } elsif ($action eq 'loadbalancing') {
726: $output = &modify_loadbalancing($dom,%domconfig);
727: } elsif ($action eq 'ltitools') {
728: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
729: } elsif ($action eq 'ssl') {
730: $output = &modify_ssl($dom,$lastactref,%domconfig);
731: } elsif ($action eq 'trust') {
732: $output = &modify_trust($dom,$lastactref,%domconfig);
733: }
734: return $output;
735: }
736:
737: sub print_config_box {
738: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
739: my $rowtotal = 0;
740: my $output;
741: if ($action eq 'coursecategories') {
742: $output = &coursecategories_javascript($settings);
743: } elsif ($action eq 'defaults') {
744: $output = &defaults_javascript($settings);
745: } elsif ($action eq 'helpsettings') {
746: my (%privs,%levelscurrent);
747: my %full=();
748: my %levels=(
749: course => {},
750: domain => {},
751: system => {},
752: );
753: my $context = 'domain';
754: my $crstype = 'Course';
755: my $formname = 'display';
756: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
757: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
758: $output =
759: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
760: \@templateroles);
761: }
762: $output .=
763: '<table class="LC_nested_outer">
764: <tr>
765: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
766: &mt($item->{text}).' '.
767: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
768: '</tr>';
769: $rowtotal ++;
770: my $numheaders = 1;
771: if (ref($item->{'header'}) eq 'ARRAY') {
772: $numheaders = scalar(@{$item->{'header'}});
773: }
774: if ($numheaders > 1) {
775: my $colspan = '';
776: my $rightcolspan = '';
777: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
778: ($action eq 'directorysrch') ||
779: (($action eq 'login') && ($numheaders < 4))) {
780: $colspan = ' colspan="2"';
781: }
782: if ($action eq 'usersessions') {
783: $rightcolspan = ' colspan="3"';
784: }
785: $output .= '
786: <tr>
787: <td>
788: <table class="LC_nested">
789: <tr class="LC_info_row">
790: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
791: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
792: </tr>';
793: $rowtotal ++;
794: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
795: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
796: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
797: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
798: ($action eq 'contacts')) {
799: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
800: } elsif ($action eq 'coursecategories') {
801: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
802: } elsif ($action eq 'login') {
803: if ($numheaders == 4) {
804: $colspan = ' colspan="2"';
805: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
806: } else {
807: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
808: }
809: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
810: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
811: } elsif ($action eq 'rolecolors') {
812: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
813: }
814: $output .= '
815: </table>
816: </td>
817: </tr>
818: <tr>
819: <td>
820: <table class="LC_nested">
821: <tr class="LC_info_row">
822: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
823: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
824: </tr>';
825: $rowtotal ++;
826: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
827: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
828: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
829: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
830: if ($action eq 'coursecategories') {
831: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
832: $colspan = ' colspan="2"';
833: } elsif ($action eq 'trust') {
834: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
835: } else {
836: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
837: }
838: if ($action eq 'trust') {
839: $output .= '
840: </table>
841: </td>
842: </tr>';
843: my @trusthdrs = qw(2 3 4 5 6 7);
844: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
845: for (my $i=0; $i<@trusthdrs; $i++) {
846: $output .= '
847: <tr>
848: <td>
849: <table class="LC_nested">
850: <tr class="LC_info_row">
851: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
852: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
853: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
854: </table>
855: </td>
856: </tr>';
857: }
858: $output .= '
859: <tr>
860: <td>
861: <table class="LC_nested">
862: <tr class="LC_info_row">
863: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
864: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
865: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
866: } else {
867: $output .= '
868: </table>
869: </td>
870: </tr>
871: <tr>
872: <td>
873: <table class="LC_nested">
874: <tr class="LC_info_row">
875: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
876: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
877: </tr>'."\n";
878: if ($action eq 'coursecategories') {
879: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
880: } else {
881: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
882: }
883: }
884: $rowtotal ++;
885: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
886: ($action eq 'defaults') || ($action eq 'directorysrch') ||
887: ($action eq 'helpsettings')) {
888: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
889: } elsif ($action eq 'ssl') {
890: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
899: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
900: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
901: </table>
902: </td>
903: </tr>
904: <tr>
905: <td>
906: <table class="LC_nested">
907: <tr class="LC_info_row">
908: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
909: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
910: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
911: } elsif ($action eq 'login') {
912: if ($numheaders == 4) {
913: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
921: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
923: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
924: $rowtotal ++;
925: } else {
926: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
927: }
928: $output .= '
929: </table>
930: </td>
931: </tr>
932: <tr>
933: <td>
934: <table class="LC_nested">
935: <tr class="LC_info_row">';
936: if ($numheaders == 4) {
937: $output .= '
938: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
939: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
940: </tr>';
941: } else {
942: $output .= '
943: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
944: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
945: </tr>';
946: }
947: $rowtotal ++;
948: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
949: } elsif ($action eq 'requestcourses') {
950: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
951: $rowtotal ++;
952: $output .= &print_studentcode($settings,\$rowtotal).'
953: </table>
954: </td>
955: </tr>
956: <tr>
957: <td>
958: <table class="LC_nested">
959: <tr class="LC_info_row">
960: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
961: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
962: &textbookcourses_javascript($settings).
963: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
964: </table>
965: </td>
966: </tr>
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">
971: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
972: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
973: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
974: </table>
975: </td>
976: </tr>
977: <tr>
978: <td>
979: <table class="LC_nested">
980: <tr class="LC_info_row">
981: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
982: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
983: </tr>'.
984: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
985: } elsif ($action eq 'requestauthor') {
986: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
987: $rowtotal ++;
988: } elsif ($action eq 'rolecolors') {
989: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
990: </table>
991: </td>
992: </tr>
993: <tr>
994: <td>
995: <table class="LC_nested">
996: <tr class="LC_info_row">
997: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
998: &mt($item->{'header'}->[2]->{'col1'}).'</td>
999: <td class="LC_right_item" style="vertical-align: top">'.
1000: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1001: </tr>'.
1002: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1003: </table>
1004: </td>
1005: </tr>
1006: <tr>
1007: <td>
1008: <table class="LC_nested">
1009: <tr class="LC_info_row">
1010: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1011: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1012: </tr>'.
1013: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1014: $rowtotal += 2;
1015: }
1016: } else {
1017: $output .= '
1018: <tr>
1019: <td>
1020: <table class="LC_nested">
1021: <tr class="LC_info_row">';
1022: if ($action eq 'login') {
1023: $output .= '
1024: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1025: } elsif ($action eq 'serverstatuses') {
1026: $output .= '
1027: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1028: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1029:
1030: } else {
1031: $output .= '
1032: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1033: }
1034: if (defined($item->{'header'}->[0]->{'col3'})) {
1035: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1036: &mt($item->{'header'}->[0]->{'col2'});
1037: if ($action eq 'serverstatuses') {
1038: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1039: }
1040: } else {
1041: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1042: &mt($item->{'header'}->[0]->{'col2'});
1043: }
1044: $output .= '</td>';
1045: if ($item->{'header'}->[0]->{'col3'}) {
1046: if (defined($item->{'header'}->[0]->{'col4'})) {
1047: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1048: &mt($item->{'header'}->[0]->{'col3'});
1049: } else {
1050: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1051: &mt($item->{'header'}->[0]->{'col3'});
1052: }
1053: if ($action eq 'serverstatuses') {
1054: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1055: }
1056: $output .= '</td>';
1057: }
1058: if ($item->{'header'}->[0]->{'col4'}) {
1059: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1060: &mt($item->{'header'}->[0]->{'col4'});
1061: }
1062: $output .= '</tr>';
1063: $rowtotal ++;
1064: if ($action eq 'quotas') {
1065: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1066: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1067: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1068: ($action eq 'ltitools')) {
1069: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1070: } elsif ($action eq 'scantron') {
1071: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1072: }
1073: }
1074: $output .= '
1075: </table>
1076: </td>
1077: </tr>
1078: </table><br />';
1079: return ($output,$rowtotal);
1080: }
1081:
1082: sub print_login {
1083: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1084: my ($css_class,$datatable);
1085: my %choices = &login_choices();
1086:
1087: if ($caller eq 'service') {
1088: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1089: my $choice = $choices{'disallowlogin'};
1090: $css_class = ' class="LC_odd_row"';
1091: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1092: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1093: '<th>'.$choices{'server'}.'</th>'.
1094: '<th>'.$choices{'serverpath'}.'</th>'.
1095: '<th>'.$choices{'custompath'}.'</th>'.
1096: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1097: my %disallowed;
1098: if (ref($settings) eq 'HASH') {
1099: if (ref($settings->{'loginvia'}) eq 'HASH') {
1100: %disallowed = %{$settings->{'loginvia'}};
1101: }
1102: }
1103: foreach my $lonhost (sort(keys(%servers))) {
1104: my $direct = 'selected="selected"';
1105: if (ref($disallowed{$lonhost}) eq 'HASH') {
1106: if ($disallowed{$lonhost}{'server'} ne '') {
1107: $direct = '';
1108: }
1109: }
1110: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1111: '<td><select name="'.$lonhost.'_server">'.
1112: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1113: '</option>';
1114: foreach my $hostid (sort(keys(%servers))) {
1115: next if ($servers{$hostid} eq $servers{$lonhost});
1116: my $selected = '';
1117: if (ref($disallowed{$lonhost}) eq 'HASH') {
1118: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1119: $selected = 'selected="selected"';
1120: }
1121: }
1122: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1123: $servers{$hostid}.'</option>';
1124: }
1125: $datatable .= '</select></td>'.
1126: '<td><select name="'.$lonhost.'_serverpath">';
1127: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1128: my $pathname = $path;
1129: if ($path eq 'custom') {
1130: $pathname = &mt('Custom Path').' ->';
1131: }
1132: my $selected = '';
1133: if (ref($disallowed{$lonhost}) eq 'HASH') {
1134: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1135: $selected = 'selected="selected"';
1136: }
1137: } elsif ($path eq '') {
1138: $selected = 'selected="selected"';
1139: }
1140: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1141: }
1142: $datatable .= '</select></td>';
1143: my ($custom,$exempt);
1144: if (ref($disallowed{$lonhost}) eq 'HASH') {
1145: $custom = $disallowed{$lonhost}{'custompath'};
1146: $exempt = $disallowed{$lonhost}{'exempt'};
1147: }
1148: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1149: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1150: '</tr>';
1151: }
1152: $datatable .= '</table></td></tr>';
1153: return $datatable;
1154: } elsif ($caller eq 'page') {
1155: my %defaultchecked = (
1156: 'coursecatalog' => 'on',
1157: 'helpdesk' => 'on',
1158: 'adminmail' => 'off',
1159: 'newuser' => 'off',
1160: );
1161: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1162: my (%checkedon,%checkedoff);
1163: foreach my $item (@toggles) {
1164: if ($defaultchecked{$item} eq 'on') {
1165: $checkedon{$item} = ' checked="checked" ';
1166: $checkedoff{$item} = ' ';
1167: } elsif ($defaultchecked{$item} eq 'off') {
1168: $checkedoff{$item} = ' checked="checked" ';
1169: $checkedon{$item} = ' ';
1170: }
1171: }
1172: my @images = ('img','logo','domlogo','login');
1173: my @logintext = ('textcol','bgcol');
1174: my @bgs = ('pgbg','mainbg','sidebg');
1175: my @links = ('link','alink','vlink');
1176: my %designhash = &Apache::loncommon::get_domainconf($dom);
1177: my %defaultdesign = %Apache::loncommon::defaultdesign;
1178: my (%is_custom,%designs);
1179: my %defaults = (
1180: font => $defaultdesign{'login.font'},
1181: );
1182: foreach my $item (@images) {
1183: $defaults{$item} = $defaultdesign{'login.'.$item};
1184: $defaults{'showlogo'}{$item} = 1;
1185: }
1186: foreach my $item (@bgs) {
1187: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1188: }
1189: foreach my $item (@logintext) {
1190: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1191: }
1192: foreach my $item (@links) {
1193: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1194: }
1195: if (ref($settings) eq 'HASH') {
1196: foreach my $item (@toggles) {
1197: if ($settings->{$item} eq '1') {
1198: $checkedon{$item} = ' checked="checked" ';
1199: $checkedoff{$item} = ' ';
1200: } elsif ($settings->{$item} eq '0') {
1201: $checkedoff{$item} = ' checked="checked" ';
1202: $checkedon{$item} = ' ';
1203: }
1204: }
1205: foreach my $item (@images) {
1206: if (defined($settings->{$item})) {
1207: $designs{$item} = $settings->{$item};
1208: $is_custom{$item} = 1;
1209: }
1210: if (defined($settings->{'showlogo'}{$item})) {
1211: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1212: }
1213: }
1214: foreach my $item (@logintext) {
1215: if ($settings->{$item} ne '') {
1216: $designs{'logintext'}{$item} = $settings->{$item};
1217: $is_custom{$item} = 1;
1218: }
1219: }
1220: if ($settings->{'font'} ne '') {
1221: $designs{'font'} = $settings->{'font'};
1222: $is_custom{'font'} = 1;
1223: }
1224: foreach my $item (@bgs) {
1225: if ($settings->{$item} ne '') {
1226: $designs{'bgs'}{$item} = $settings->{$item};
1227: $is_custom{$item} = 1;
1228: }
1229: }
1230: foreach my $item (@links) {
1231: if ($settings->{$item} ne '') {
1232: $designs{'links'}{$item} = $settings->{$item};
1233: $is_custom{$item} = 1;
1234: }
1235: }
1236: } else {
1237: if ($designhash{$dom.'.login.font'} ne '') {
1238: $designs{'font'} = $designhash{$dom.'.login.font'};
1239: $is_custom{'font'} = 1;
1240: }
1241: foreach my $item (@images) {
1242: if ($designhash{$dom.'.login.'.$item} ne '') {
1243: $designs{$item} = $designhash{$dom.'.login.'.$item};
1244: $is_custom{$item} = 1;
1245: }
1246: }
1247: foreach my $item (@bgs) {
1248: if ($designhash{$dom.'.login.'.$item} ne '') {
1249: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1250: $is_custom{$item} = 1;
1251: }
1252: }
1253: foreach my $item (@links) {
1254: if ($designhash{$dom.'.login.'.$item} ne '') {
1255: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1256: $is_custom{$item} = 1;
1257: }
1258: }
1259: }
1260: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1261: logo => 'Institution Logo',
1262: domlogo => 'Domain Logo',
1263: login => 'Login box');
1264: my $itemcount = 1;
1265: foreach my $item (@toggles) {
1266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1267: $datatable .=
1268: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1269: '</td><td>'.
1270: '<span class="LC_nobreak"><label><input type="radio" name="'.
1271: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1272: '</label> <label><input type="radio" name="'.$item.'"'.
1273: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1274: '</tr>';
1275: $itemcount ++;
1276: }
1277: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1278: $datatable .= '</tr></table></td></tr>';
1279: } elsif ($caller eq 'help') {
1280: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1281: my $switchserver = &check_switchserver($dom,$confname);
1282: my $itemcount = 1;
1283: $defaulturl = '/adm/loginproblems.html';
1284: $defaulttype = 'default';
1285: %lt = &Apache::lonlocal::texthash (
1286: del => 'Delete?',
1287: rep => 'Replace:',
1288: upl => 'Upload:',
1289: default => 'Default',
1290: custom => 'Custom',
1291: );
1292: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1293: my @currlangs;
1294: if (ref($settings) eq 'HASH') {
1295: if (ref($settings->{'helpurl'}) eq 'HASH') {
1296: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1297: next if ($settings->{'helpurl'}{$key} eq '');
1298: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1299: $type{$key} = 'custom';
1300: unless ($key eq 'nolang') {
1301: push(@currlangs,$key);
1302: }
1303: }
1304: } elsif ($settings->{'helpurl'} ne '') {
1305: $type{'nolang'} = 'custom';
1306: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1307: }
1308: }
1309: foreach my $lang ('nolang',sort(@currlangs)) {
1310: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1311: $datatable .= '<tr'.$css_class.'>';
1312: if ($url{$lang} eq '') {
1313: $url{$lang} = $defaulturl;
1314: }
1315: if ($type{$lang} eq '') {
1316: $type{$lang} = $defaulttype;
1317: }
1318: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1319: if ($lang eq 'nolang') {
1320: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1321: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1322: } else {
1323: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1324: $langchoices{$lang},
1325: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1326: }
1327: $datatable .= '</span></td>'."\n".
1328: '<td class="LC_left_item">';
1329: if ($type{$lang} eq 'custom') {
1330: $datatable .= '<span class="LC_nobreak"><label>'.
1331: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1332: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1333: } else {
1334: $datatable .= $lt{'upl'};
1335: }
1336: $datatable .='<br />';
1337: if ($switchserver) {
1338: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1339: } else {
1340: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1341: }
1342: $datatable .= '</td></tr>';
1343: $itemcount ++;
1344: }
1345: my @addlangs;
1346: foreach my $lang (sort(keys(%langchoices))) {
1347: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1348: push(@addlangs,$lang);
1349: }
1350: if (@addlangs > 0) {
1351: my %toadd;
1352: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1353: $toadd{''} = &mt('Select');
1354: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1355: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1356: &mt('Add log-in help page for a specific language:').' '.
1357: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1358: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1359: if ($switchserver) {
1360: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1361: } else {
1362: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1363: }
1364: $datatable .= '</td></tr>';
1365: $itemcount ++;
1366: }
1367: $datatable .= &captcha_choice('login',$settings,$itemcount);
1368: } elsif ($caller eq 'headtag') {
1369: my %domservers = &Apache::lonnet::get_servers($dom);
1370: my $choice = $choices{'headtag'};
1371: $css_class = ' class="LC_odd_row"';
1372: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1373: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1374: '<th>'.$choices{'current'}.'</th>'.
1375: '<th>'.$choices{'action'}.'</th>'.
1376: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1377: my (%currurls,%currexempt);
1378: if (ref($settings) eq 'HASH') {
1379: if (ref($settings->{'headtag'}) eq 'HASH') {
1380: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1381: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1382: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1383: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1384: }
1385: }
1386: }
1387: }
1388: my %lt = &Apache::lonlocal::texthash(
1389: del => 'Delete?',
1390: rep => 'Replace:',
1391: upl => 'Upload:',
1392: curr => 'View contents',
1393: none => 'None',
1394: );
1395: my $switchserver = &check_switchserver($dom,$confname);
1396: foreach my $lonhost (sort(keys(%domservers))) {
1397: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1398: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1399: if ($currurls{$lonhost}) {
1400: $datatable .= '<td class="LC_right_item"><a href="'.
1401: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1402: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1403: '">'.$lt{'curr'}.'</a></td>'.
1404: '<td><span class="LC_nobreak"><label>'.
1405: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1406: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1407: } else {
1408: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1409: }
1410: $datatable .='<br />';
1411: if ($switchserver) {
1412: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1413: } else {
1414: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1415: }
1416: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1417: }
1418: $datatable .= '</table></td></tr>';
1419: }
1420: return $datatable;
1421: }
1422:
1423: sub login_choices {
1424: my %choices =
1425: &Apache::lonlocal::texthash (
1426: coursecatalog => 'Display Course/Community Catalog link?',
1427: adminmail => "Display Administrator's E-mail Address?",
1428: helpdesk => 'Display "Contact Helpdesk" link',
1429: disallowlogin => "Login page requests redirected",
1430: hostid => "Server",
1431: server => "Redirect to:",
1432: serverpath => "Path",
1433: custompath => "Custom",
1434: exempt => "Exempt IP(s)",
1435: directlogin => "No redirect",
1436: newuser => "Link to create a user account",
1437: img => "Header",
1438: logo => "Main Logo",
1439: domlogo => "Domain Logo",
1440: login => "Log-in Header",
1441: textcol => "Text color",
1442: bgcol => "Box color",
1443: bgs => "Background colors",
1444: links => "Link colors",
1445: font => "Font color",
1446: pgbg => "Header",
1447: mainbg => "Page",
1448: sidebg => "Login box",
1449: link => "Link",
1450: alink => "Active link",
1451: vlink => "Visited link",
1452: headtag => "Custom markup",
1453: action => "Action",
1454: current => "Current",
1455: );
1456: return %choices;
1457: }
1458:
1459: sub print_rolecolors {
1460: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1461: my %choices = &color_font_choices();
1462: my @bgs = ('pgbg','tabbg','sidebg');
1463: my @links = ('link','alink','vlink');
1464: my @images = ('img');
1465: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1466: my %designhash = &Apache::loncommon::get_domainconf($dom);
1467: my %defaultdesign = %Apache::loncommon::defaultdesign;
1468: my (%is_custom,%designs);
1469: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1470: if (ref($settings) eq 'HASH') {
1471: if (ref($settings->{$role}) eq 'HASH') {
1472: if ($settings->{$role}->{'img'} ne '') {
1473: $designs{'img'} = $settings->{$role}->{'img'};
1474: $is_custom{'img'} = 1;
1475: }
1476: if ($settings->{$role}->{'font'} ne '') {
1477: $designs{'font'} = $settings->{$role}->{'font'};
1478: $is_custom{'font'} = 1;
1479: }
1480: if ($settings->{$role}->{'fontmenu'} ne '') {
1481: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1482: $is_custom{'fontmenu'} = 1;
1483: }
1484: foreach my $item (@bgs) {
1485: if ($settings->{$role}->{$item} ne '') {
1486: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1487: $is_custom{$item} = 1;
1488: }
1489: }
1490: foreach my $item (@links) {
1491: if ($settings->{$role}->{$item} ne '') {
1492: $designs{'links'}{$item} = $settings->{$role}->{$item};
1493: $is_custom{$item} = 1;
1494: }
1495: }
1496: }
1497: } else {
1498: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1499: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1500: $is_custom{'img'} = 1;
1501: }
1502: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1503: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1504: $is_custom{'fontmenu'} = 1;
1505: }
1506: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1507: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1508: $is_custom{'font'} = 1;
1509: }
1510: foreach my $item (@bgs) {
1511: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1512: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1513: $is_custom{$item} = 1;
1514:
1515: }
1516: }
1517: foreach my $item (@links) {
1518: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1519: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1520: $is_custom{$item} = 1;
1521: }
1522: }
1523: }
1524: my $itemcount = 1;
1525: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1526: $datatable .= '</tr></table></td></tr>';
1527: return $datatable;
1528: }
1529:
1530: sub role_defaults {
1531: my ($role,$bgs,$links,$images,$logintext) = @_;
1532: my %defaults;
1533: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1534: return %defaults;
1535: }
1536: my %defaultdesign = %Apache::loncommon::defaultdesign;
1537: if ($role eq 'login') {
1538: %defaults = (
1539: font => $defaultdesign{$role.'.font'},
1540: );
1541: if (ref($logintext) eq 'ARRAY') {
1542: foreach my $item (@{$logintext}) {
1543: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1544: }
1545: }
1546: foreach my $item (@{$images}) {
1547: $defaults{'showlogo'}{$item} = 1;
1548: }
1549: } else {
1550: %defaults = (
1551: img => $defaultdesign{$role.'.img'},
1552: font => $defaultdesign{$role.'.font'},
1553: fontmenu => $defaultdesign{$role.'.fontmenu'},
1554: );
1555: }
1556: foreach my $item (@{$bgs}) {
1557: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1558: }
1559: foreach my $item (@{$links}) {
1560: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1561: }
1562: foreach my $item (@{$images}) {
1563: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1564: }
1565: return %defaults;
1566: }
1567:
1568: sub display_color_options {
1569: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1570: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1571: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1572: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1573: my $datatable = '<tr'.$css_class.'>'.
1574: '<td>'.$choices->{'font'}.'</td>';
1575: if (!$is_custom->{'font'}) {
1576: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1577: } else {
1578: $datatable .= '<td> </td>';
1579: }
1580: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1581:
1582: $datatable .= '<td><span class="LC_nobreak">'.
1583: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1584: ' value="'.$current_color.'" /> '.
1585: ' </td></tr>';
1586: unless ($role eq 'login') {
1587: $datatable .= '<tr'.$css_class.'>'.
1588: '<td>'.$choices->{'fontmenu'}.'</td>';
1589: if (!$is_custom->{'fontmenu'}) {
1590: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1591: } else {
1592: $datatable .= '<td> </td>';
1593: }
1594: $current_color = $designs->{'fontmenu'} ?
1595: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1596: $datatable .= '<td><span class="LC_nobreak">'.
1597: '<input class="colorchooser" type="text" size="10" name="'
1598: .$role.'_fontmenu"'.
1599: ' value="'.$current_color.'" /> '.
1600: ' </td></tr>';
1601: }
1602: my $switchserver = &check_switchserver($dom,$confname);
1603: foreach my $img (@{$images}) {
1604: $itemcount ++;
1605: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1606: $datatable .= '<tr'.$css_class.'>'.
1607: '<td>'.$choices->{$img};
1608: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1609: if ($role eq 'login') {
1610: if ($img eq 'login') {
1611: $login_hdr_pick =
1612: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1613: $logincolors =
1614: &login_text_colors($img,$role,$logintext,$phase,$choices,
1615: $designs,$defaults);
1616: } elsif ($img ne 'domlogo') {
1617: $datatable.= &logo_display_options($img,$defaults,$designs);
1618: }
1619: }
1620: $datatable .= '</td>';
1621: if ($designs->{$img} ne '') {
1622: $imgfile = $designs->{$img};
1623: $img_import = ($imgfile =~ m{^/adm/});
1624: } else {
1625: $imgfile = $defaults->{$img};
1626: }
1627: if ($imgfile) {
1628: my ($showfile,$fullsize);
1629: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1630: my $urldir = $1;
1631: my $filename = $2;
1632: my @info = &Apache::lonnet::stat_file($designs->{$img});
1633: if (@info) {
1634: my $thumbfile = 'tn-'.$filename;
1635: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1636: if (@thumb) {
1637: $showfile = $urldir.'/'.$thumbfile;
1638: } else {
1639: $showfile = $imgfile;
1640: }
1641: } else {
1642: $showfile = '';
1643: }
1644: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1645: $showfile = $imgfile;
1646: my $imgdir = $1;
1647: my $filename = $2;
1648: if (-e "$londocroot/$imgdir/tn-".$filename) {
1649: $showfile = "/$imgdir/tn-".$filename;
1650: } else {
1651: my $input = $londocroot.$imgfile;
1652: my $output = "$londocroot/$imgdir/tn-".$filename;
1653: if (!-e $output) {
1654: my ($width,$height) = &thumb_dimensions();
1655: my ($fullwidth,$fullheight) = &check_dimensions($input);
1656: if ($fullwidth ne '' && $fullheight ne '') {
1657: if ($fullwidth > $width && $fullheight > $height) {
1658: my $size = $width.'x'.$height;
1659: system("convert -sample $size $input $output");
1660: $showfile = "/$imgdir/tn-".$filename;
1661: }
1662: }
1663: }
1664: }
1665: }
1666: if ($showfile) {
1667: if ($showfile =~ m{^/(adm|res)/}) {
1668: if ($showfile =~ m{^/res/}) {
1669: my $local_showfile =
1670: &Apache::lonnet::filelocation('',$showfile);
1671: &Apache::lonnet::repcopy($local_showfile);
1672: }
1673: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1674: }
1675: if ($imgfile) {
1676: if ($imgfile =~ m{^/(adm|res)/}) {
1677: if ($imgfile =~ m{^/res/}) {
1678: my $local_imgfile =
1679: &Apache::lonnet::filelocation('',$imgfile);
1680: &Apache::lonnet::repcopy($local_imgfile);
1681: }
1682: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1683: } else {
1684: $fullsize = $imgfile;
1685: }
1686: }
1687: $datatable .= '<td>';
1688: if ($img eq 'login') {
1689: $datatable .= $login_hdr_pick;
1690: }
1691: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1692: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1693: } else {
1694: $datatable .= '<td> </td><td class="LC_left_item">'.
1695: &mt('Upload:').'<br />';
1696: }
1697: } else {
1698: $datatable .= '<td> </td><td class="LC_left_item">'.
1699: &mt('Upload:').'<br />';
1700: }
1701: if ($switchserver) {
1702: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1703: } else {
1704: if ($img ne 'login') { # suppress file selection for Log-in header
1705: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1706: }
1707: }
1708: $datatable .= '</td></tr>';
1709: }
1710: $itemcount ++;
1711: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1712: $datatable .= '<tr'.$css_class.'>'.
1713: '<td>'.$choices->{'bgs'}.'</td>';
1714: my $bgs_def;
1715: foreach my $item (@{$bgs}) {
1716: if (!$is_custom->{$item}) {
1717: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1718: }
1719: }
1720: if ($bgs_def) {
1721: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1722: } else {
1723: $datatable .= '<td> </td>';
1724: }
1725: $datatable .= '<td class="LC_right_item">'.
1726: '<table border="0"><tr>';
1727:
1728: foreach my $item (@{$bgs}) {
1729: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1730: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1731: if ($designs->{'bgs'}{$item}) {
1732: $datatable .= ' ';
1733: }
1734: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1735: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1736: }
1737: $datatable .= '</tr></table></td></tr>';
1738: $itemcount ++;
1739: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1740: $datatable .= '<tr'.$css_class.'>'.
1741: '<td>'.$choices->{'links'}.'</td>';
1742: my $links_def;
1743: foreach my $item (@{$links}) {
1744: if (!$is_custom->{$item}) {
1745: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1746: }
1747: }
1748: if ($links_def) {
1749: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1750: } else {
1751: $datatable .= '<td> </td>';
1752: }
1753: $datatable .= '<td class="LC_right_item">'.
1754: '<table border="0"><tr>';
1755: foreach my $item (@{$links}) {
1756: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1757: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1758: if ($designs->{'links'}{$item}) {
1759: $datatable.=' ';
1760: }
1761: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1762: '" /></td>';
1763: }
1764: $$rowtotal += $itemcount;
1765: return $datatable;
1766: }
1767:
1768: sub logo_display_options {
1769: my ($img,$defaults,$designs) = @_;
1770: my $checkedon;
1771: if (ref($defaults) eq 'HASH') {
1772: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1773: if ($defaults->{'showlogo'}{$img}) {
1774: $checkedon = 'checked="checked" ';
1775: }
1776: }
1777: }
1778: if (ref($designs) eq 'HASH') {
1779: if (ref($designs->{'showlogo'}) eq 'HASH') {
1780: if (defined($designs->{'showlogo'}{$img})) {
1781: if ($designs->{'showlogo'}{$img} == 0) {
1782: $checkedon = '';
1783: } elsif ($designs->{'showlogo'}{$img} == 1) {
1784: $checkedon = 'checked="checked" ';
1785: }
1786: }
1787: }
1788: }
1789: return '<br /><label> <input type="checkbox" name="'.
1790: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1791: &mt('show').'</label>'."\n";
1792: }
1793:
1794: sub login_header_options {
1795: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1796: my $output = '';
1797: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1798: $output .= &mt('Text default(s):').'<br />';
1799: if (!$is_custom->{'textcol'}) {
1800: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1801: ' ';
1802: }
1803: if (!$is_custom->{'bgcol'}) {
1804: $output .= $choices->{'bgcol'}.': '.
1805: '<span id="css_'.$role.'_font" style="background-color: '.
1806: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1807: }
1808: $output .= '<br />';
1809: }
1810: $output .='<br />';
1811: return $output;
1812: }
1813:
1814: sub login_text_colors {
1815: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1816: my $color_menu = '<table border="0"><tr>';
1817: foreach my $item (@{$logintext}) {
1818: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1819: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1820: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1821: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1822: }
1823: $color_menu .= '</tr></table><br />';
1824: return $color_menu;
1825: }
1826:
1827: sub image_changes {
1828: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1829: my $output;
1830: if ($img eq 'login') {
1831: # suppress image for Log-in header
1832: } elsif (!$is_custom) {
1833: if ($img ne 'domlogo') {
1834: $output .= &mt('Default image:').'<br />';
1835: } else {
1836: $output .= &mt('Default in use:').'<br />';
1837: }
1838: }
1839: if ($img eq 'login') { # suppress image for Log-in header
1840: $output .= '<td>'.$logincolors;
1841: } else {
1842: if ($img_import) {
1843: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1844: }
1845: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1846: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1847: if ($is_custom) {
1848: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1849: '<input type="checkbox" name="'.
1850: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1851: '</label> '.&mt('Replace:').'</span><br />';
1852: } else {
1853: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1854: }
1855: }
1856: return $output;
1857: }
1858:
1859: sub print_quotas {
1860: my ($dom,$settings,$rowtotal,$action) = @_;
1861: my $context;
1862: if ($action eq 'quotas') {
1863: $context = 'tools';
1864: } else {
1865: $context = $action;
1866: }
1867: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1868: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1869: my $typecount = 0;
1870: my ($css_class,%titles);
1871: if ($context eq 'requestcourses') {
1872: @usertools = ('official','unofficial','community','textbook','placement');
1873: @options =('norequest','approval','validate','autolimit');
1874: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1875: %titles = &courserequest_titles();
1876: } elsif ($context eq 'requestauthor') {
1877: @usertools = ('author');
1878: @options = ('norequest','approval','automatic');
1879: %titles = &authorrequest_titles();
1880: } else {
1881: @usertools = ('aboutme','blog','webdav','portfolio');
1882: %titles = &tool_titles();
1883: }
1884: if (ref($types) eq 'ARRAY') {
1885: foreach my $type (@{$types}) {
1886: my ($currdefquota,$currauthorquota);
1887: unless (($context eq 'requestcourses') ||
1888: ($context eq 'requestauthor')) {
1889: if (ref($settings) eq 'HASH') {
1890: if (ref($settings->{defaultquota}) eq 'HASH') {
1891: $currdefquota = $settings->{defaultquota}->{$type};
1892: } else {
1893: $currdefquota = $settings->{$type};
1894: }
1895: if (ref($settings->{authorquota}) eq 'HASH') {
1896: $currauthorquota = $settings->{authorquota}->{$type};
1897: }
1898: }
1899: }
1900: if (defined($usertypes->{$type})) {
1901: $typecount ++;
1902: $css_class = $typecount%2?' class="LC_odd_row"':'';
1903: $datatable .= '<tr'.$css_class.'>'.
1904: '<td>'.$usertypes->{$type}.'</td>'.
1905: '<td class="LC_left_item">';
1906: if ($context eq 'requestcourses') {
1907: $datatable .= '<table><tr>';
1908: }
1909: my %cell;
1910: foreach my $item (@usertools) {
1911: if ($context eq 'requestcourses') {
1912: my ($curroption,$currlimit);
1913: if (ref($settings) eq 'HASH') {
1914: if (ref($settings->{$item}) eq 'HASH') {
1915: $curroption = $settings->{$item}->{$type};
1916: if ($curroption =~ /^autolimit=(\d*)$/) {
1917: $currlimit = $1;
1918: }
1919: }
1920: }
1921: if (!$curroption) {
1922: $curroption = 'norequest';
1923: }
1924: $datatable .= '<th>'.$titles{$item}.'</th>';
1925: foreach my $option (@options) {
1926: my $val = $option;
1927: if ($option eq 'norequest') {
1928: $val = 0;
1929: }
1930: if ($option eq 'validate') {
1931: my $canvalidate = 0;
1932: if (ref($validations{$item}) eq 'HASH') {
1933: if ($validations{$item}{$type}) {
1934: $canvalidate = 1;
1935: }
1936: }
1937: next if (!$canvalidate);
1938: }
1939: my $checked = '';
1940: if ($option eq $curroption) {
1941: $checked = ' checked="checked"';
1942: } elsif ($option eq 'autolimit') {
1943: if ($curroption =~ /^autolimit/) {
1944: $checked = ' checked="checked"';
1945: }
1946: }
1947: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1948: '<input type="radio" name="crsreq_'.$item.
1949: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1950: $titles{$option}.'</label>';
1951: if ($option eq 'autolimit') {
1952: $cell{$item} .= ' <input type="text" name="crsreq_'.
1953: $item.'_limit_'.$type.'" size="1" '.
1954: 'value="'.$currlimit.'" />';
1955: }
1956: $cell{$item} .= '</span> ';
1957: if ($option eq 'autolimit') {
1958: $cell{$item} .= $titles{'unlimited'};
1959: }
1960: }
1961: } elsif ($context eq 'requestauthor') {
1962: my $curroption;
1963: if (ref($settings) eq 'HASH') {
1964: $curroption = $settings->{$type};
1965: }
1966: if (!$curroption) {
1967: $curroption = 'norequest';
1968: }
1969: foreach my $option (@options) {
1970: my $val = $option;
1971: if ($option eq 'norequest') {
1972: $val = 0;
1973: }
1974: my $checked = '';
1975: if ($option eq $curroption) {
1976: $checked = ' checked="checked"';
1977: }
1978: $datatable .= '<span class="LC_nobreak"><label>'.
1979: '<input type="radio" name="authorreq_'.$type.
1980: '" value="'.$val.'"'.$checked.' />'.
1981: $titles{$option}.'</label></span> ';
1982: }
1983: } else {
1984: my $checked = 'checked="checked" ';
1985: if (ref($settings) eq 'HASH') {
1986: if (ref($settings->{$item}) eq 'HASH') {
1987: if ($settings->{$item}->{$type} == 0) {
1988: $checked = '';
1989: } elsif ($settings->{$item}->{$type} == 1) {
1990: $checked = 'checked="checked" ';
1991: }
1992: }
1993: }
1994: $datatable .= '<span class="LC_nobreak"><label>'.
1995: '<input type="checkbox" name="'.$context.'_'.$item.
1996: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1997: '</label></span> ';
1998: }
1999: }
2000: if ($context eq 'requestcourses') {
2001: $datatable .= '</tr><tr>';
2002: foreach my $item (@usertools) {
2003: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
2004: }
2005: $datatable .= '</tr></table>';
2006: }
2007: $datatable .= '</td>';
2008: unless (($context eq 'requestcourses') ||
2009: ($context eq 'requestauthor')) {
2010: $datatable .=
2011: '<td class="LC_right_item">'.
2012: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2013: '<input type="text" name="quota_'.$type.
2014: '" value="'.$currdefquota.
2015: '" size="5" /></span>'.(' ' x 2).
2016: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2017: '<input type="text" name="authorquota_'.$type.
2018: '" value="'.$currauthorquota.
2019: '" size="5" /></span></td>';
2020: }
2021: $datatable .= '</tr>';
2022: }
2023: }
2024: }
2025: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2026: $defaultquota = '20';
2027: $authorquota = '500';
2028: if (ref($settings) eq 'HASH') {
2029: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2030: $defaultquota = $settings->{'defaultquota'}->{'default'};
2031: } elsif (defined($settings->{'default'})) {
2032: $defaultquota = $settings->{'default'};
2033: }
2034: if (ref($settings->{'authorquota'}) eq 'HASH') {
2035: $authorquota = $settings->{'authorquota'}->{'default'};
2036: }
2037: }
2038: }
2039: $typecount ++;
2040: $css_class = $typecount%2?' class="LC_odd_row"':'';
2041: $datatable .= '<tr'.$css_class.'>'.
2042: '<td>'.$othertitle.'</td>'.
2043: '<td class="LC_left_item">';
2044: if ($context eq 'requestcourses') {
2045: $datatable .= '<table><tr>';
2046: }
2047: my %defcell;
2048: foreach my $item (@usertools) {
2049: if ($context eq 'requestcourses') {
2050: my ($curroption,$currlimit);
2051: if (ref($settings) eq 'HASH') {
2052: if (ref($settings->{$item}) eq 'HASH') {
2053: $curroption = $settings->{$item}->{'default'};
2054: if ($curroption =~ /^autolimit=(\d*)$/) {
2055: $currlimit = $1;
2056: }
2057: }
2058: }
2059: if (!$curroption) {
2060: $curroption = 'norequest';
2061: }
2062: $datatable .= '<th>'.$titles{$item}.'</th>';
2063: foreach my $option (@options) {
2064: my $val = $option;
2065: if ($option eq 'norequest') {
2066: $val = 0;
2067: }
2068: if ($option eq 'validate') {
2069: my $canvalidate = 0;
2070: if (ref($validations{$item}) eq 'HASH') {
2071: if ($validations{$item}{'default'}) {
2072: $canvalidate = 1;
2073: }
2074: }
2075: next if (!$canvalidate);
2076: }
2077: my $checked = '';
2078: if ($option eq $curroption) {
2079: $checked = ' checked="checked"';
2080: } elsif ($option eq 'autolimit') {
2081: if ($curroption =~ /^autolimit/) {
2082: $checked = ' checked="checked"';
2083: }
2084: }
2085: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2086: '<input type="radio" name="crsreq_'.$item.
2087: '_default" value="'.$val.'"'.$checked.' />'.
2088: $titles{$option}.'</label>';
2089: if ($option eq 'autolimit') {
2090: $defcell{$item} .= ' <input type="text" name="crsreq_'.
2091: $item.'_limit_default" size="1" '.
2092: 'value="'.$currlimit.'" />';
2093: }
2094: $defcell{$item} .= '</span> ';
2095: if ($option eq 'autolimit') {
2096: $defcell{$item} .= $titles{'unlimited'};
2097: }
2098: }
2099: } elsif ($context eq 'requestauthor') {
2100: my $curroption;
2101: if (ref($settings) eq 'HASH') {
2102: $curroption = $settings->{'default'};
2103: }
2104: if (!$curroption) {
2105: $curroption = 'norequest';
2106: }
2107: foreach my $option (@options) {
2108: my $val = $option;
2109: if ($option eq 'norequest') {
2110: $val = 0;
2111: }
2112: my $checked = '';
2113: if ($option eq $curroption) {
2114: $checked = ' checked="checked"';
2115: }
2116: $datatable .= '<span class="LC_nobreak"><label>'.
2117: '<input type="radio" name="authorreq_default"'.
2118: ' value="'.$val.'"'.$checked.' />'.
2119: $titles{$option}.'</label></span> ';
2120: }
2121: } else {
2122: my $checked = 'checked="checked" ';
2123: if (ref($settings) eq 'HASH') {
2124: if (ref($settings->{$item}) eq 'HASH') {
2125: if ($settings->{$item}->{'default'} == 0) {
2126: $checked = '';
2127: } elsif ($settings->{$item}->{'default'} == 1) {
2128: $checked = 'checked="checked" ';
2129: }
2130: }
2131: }
2132: $datatable .= '<span class="LC_nobreak"><label>'.
2133: '<input type="checkbox" name="'.$context.'_'.$item.
2134: '" value="default" '.$checked.'/>'.$titles{$item}.
2135: '</label></span> ';
2136: }
2137: }
2138: if ($context eq 'requestcourses') {
2139: $datatable .= '</tr><tr>';
2140: foreach my $item (@usertools) {
2141: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
2142: }
2143: $datatable .= '</tr></table>';
2144: }
2145: $datatable .= '</td>';
2146: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2147: $datatable .= '<td class="LC_right_item">'.
2148: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2149: '<input type="text" name="defaultquota" value="'.
2150: $defaultquota.'" size="5" /></span>'.(' ' x2).
2151: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2152: '<input type="text" name="authorquota" value="'.
2153: $authorquota.'" size="5" /></span></td>';
2154: }
2155: $datatable .= '</tr>';
2156: $typecount ++;
2157: $css_class = $typecount%2?' class="LC_odd_row"':'';
2158: $datatable .= '<tr'.$css_class.'>'.
2159: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
2160: if ($context eq 'requestcourses') {
2161: $datatable .= &mt('(overrides affiliation, if set)').
2162: '</td>'.
2163: '<td class="LC_left_item">'.
2164: '<table><tr>';
2165: } else {
2166: $datatable .= &mt('(overrides affiliation, if checked)').
2167: '</td>'.
2168: '<td class="LC_left_item" colspan="2">'.
2169: '<br />';
2170: }
2171: my %advcell;
2172: foreach my $item (@usertools) {
2173: if ($context eq 'requestcourses') {
2174: my ($curroption,$currlimit);
2175: if (ref($settings) eq 'HASH') {
2176: if (ref($settings->{$item}) eq 'HASH') {
2177: $curroption = $settings->{$item}->{'_LC_adv'};
2178: if ($curroption =~ /^autolimit=(\d*)$/) {
2179: $currlimit = $1;
2180: }
2181: }
2182: }
2183: $datatable .= '<th>'.$titles{$item}.'</th>';
2184: my $checked = '';
2185: if ($curroption eq '') {
2186: $checked = ' checked="checked"';
2187: }
2188: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2189: '<input type="radio" name="crsreq_'.$item.
2190: '__LC_adv" value=""'.$checked.' />'.
2191: &mt('No override set').'</label></span> ';
2192: foreach my $option (@options) {
2193: my $val = $option;
2194: if ($option eq 'norequest') {
2195: $val = 0;
2196: }
2197: if ($option eq 'validate') {
2198: my $canvalidate = 0;
2199: if (ref($validations{$item}) eq 'HASH') {
2200: if ($validations{$item}{'_LC_adv'}) {
2201: $canvalidate = 1;
2202: }
2203: }
2204: next if (!$canvalidate);
2205: }
2206: my $checked = '';
2207: if ($val eq $curroption) {
2208: $checked = ' checked="checked"';
2209: } elsif ($option eq 'autolimit') {
2210: if ($curroption =~ /^autolimit/) {
2211: $checked = ' checked="checked"';
2212: }
2213: }
2214: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2215: '<input type="radio" name="crsreq_'.$item.
2216: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2217: $titles{$option}.'</label>';
2218: if ($option eq 'autolimit') {
2219: $advcell{$item} .= ' <input type="text" name="crsreq_'.
2220: $item.'_limit__LC_adv" size="1" '.
2221: 'value="'.$currlimit.'" />';
2222: }
2223: $advcell{$item} .= '</span> ';
2224: if ($option eq 'autolimit') {
2225: $advcell{$item} .= $titles{'unlimited'};
2226: }
2227: }
2228: } elsif ($context eq 'requestauthor') {
2229: my $curroption;
2230: if (ref($settings) eq 'HASH') {
2231: $curroption = $settings->{'_LC_adv'};
2232: }
2233: my $checked = '';
2234: if ($curroption eq '') {
2235: $checked = ' checked="checked"';
2236: }
2237: $datatable .= '<span class="LC_nobreak"><label>'.
2238: '<input type="radio" name="authorreq__LC_adv"'.
2239: ' value=""'.$checked.' />'.
2240: &mt('No override set').'</label></span> ';
2241: foreach my $option (@options) {
2242: my $val = $option;
2243: if ($option eq 'norequest') {
2244: $val = 0;
2245: }
2246: my $checked = '';
2247: if ($val eq $curroption) {
2248: $checked = ' checked="checked"';
2249: }
2250: $datatable .= '<span class="LC_nobreak"><label>'.
2251: '<input type="radio" name="authorreq__LC_adv"'.
2252: ' value="'.$val.'"'.$checked.' />'.
2253: $titles{$option}.'</label></span> ';
2254: }
2255: } else {
2256: my $checked = 'checked="checked" ';
2257: if (ref($settings) eq 'HASH') {
2258: if (ref($settings->{$item}) eq 'HASH') {
2259: if ($settings->{$item}->{'_LC_adv'} == 0) {
2260: $checked = '';
2261: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2262: $checked = 'checked="checked" ';
2263: }
2264: }
2265: }
2266: $datatable .= '<span class="LC_nobreak"><label>'.
2267: '<input type="checkbox" name="'.$context.'_'.$item.
2268: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2269: '</label></span> ';
2270: }
2271: }
2272: if ($context eq 'requestcourses') {
2273: $datatable .= '</tr><tr>';
2274: foreach my $item (@usertools) {
2275: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2276: }
2277: $datatable .= '</tr></table>';
2278: }
2279: $datatable .= '</td></tr>';
2280: $$rowtotal += $typecount;
2281: return $datatable;
2282: }
2283:
2284: sub print_requestmail {
2285: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
2286: my ($now,$datatable,%currapp);
2287: $now = time;
2288: if (ref($settings) eq 'HASH') {
2289: if (ref($settings->{'notify'}) eq 'HASH') {
2290: if ($settings->{'notify'}{'approval'} ne '') {
2291: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2292: }
2293: }
2294: }
2295: my $numinrow = 2;
2296: my $css_class;
2297: if ($$rowtotal%2) {
2298: $css_class = 'LC_odd_row';
2299: }
2300: if ($customcss) {
2301: $css_class .= " $customcss";
2302: }
2303: $css_class =~ s/^\s+//;
2304: if ($css_class) {
2305: $css_class = ' class="'.$css_class.'"';
2306: }
2307: if ($rowstyle) {
2308: $css_class .= ' style="'.$rowstyle.'"';
2309: }
2310: my $text;
2311: if ($action eq 'requestcourses') {
2312: $text = &mt('Receive notification of course requests requiring approval');
2313: } elsif ($action eq 'requestauthor') {
2314: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2315: } else {
2316: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2317: }
2318: $datatable = '<tr'.$css_class.'>'.
2319: ' <td>'.$text.'</td>'.
2320: ' <td class="LC_left_item">';
2321: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2322: $action.'notifyapproval',%currapp);
2323: if ($numdc > 0) {
2324: $datatable .= $table;
2325: } else {
2326: $datatable .= &mt('There are no active Domain Coordinators');
2327: }
2328: $datatable .='</td></tr>';
2329: return $datatable;
2330: }
2331:
2332: sub print_studentcode {
2333: my ($settings,$rowtotal) = @_;
2334: my $rownum = 0;
2335: my ($output,%current);
2336: my @crstypes = ('official','unofficial','community','textbook','placement');
2337: if (ref($settings) eq 'HASH') {
2338: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2339: foreach my $type (@crstypes) {
2340: $current{$type} = $settings->{'uniquecode'}{$type};
2341: }
2342: }
2343: }
2344: $output .= '<tr>'.
2345: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2346: '<td class="LC_left_item">';
2347: foreach my $type (@crstypes) {
2348: my $check = ' ';
2349: if ($current{$type}) {
2350: $check = ' checked="checked" ';
2351: }
2352: $output .= '<span class="LC_nobreak"><label>'.
2353: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2354: &mt($type).'</label></span>'.(' 'x2).' ';
2355: }
2356: $output .= '</td></tr>';
2357: $$rowtotal ++;
2358: return $output;
2359: }
2360:
2361: sub print_textbookcourses {
2362: my ($dom,$type,$settings,$rowtotal) = @_;
2363: my $rownum = 0;
2364: my $css_class;
2365: my $itemcount = 1;
2366: my $maxnum = 0;
2367: my $bookshash;
2368: if (ref($settings) eq 'HASH') {
2369: $bookshash = $settings->{$type};
2370: }
2371: my %ordered;
2372: if (ref($bookshash) eq 'HASH') {
2373: foreach my $item (keys(%{$bookshash})) {
2374: if (ref($bookshash->{$item}) eq 'HASH') {
2375: my $num = $bookshash->{$item}{'order'};
2376: $ordered{$num} = $item;
2377: }
2378: }
2379: }
2380: my $confname = $dom.'-domainconfig';
2381: my $switchserver = &check_switchserver($dom,$confname);
2382: my $maxnum = scalar(keys(%ordered));
2383: my $datatable;
2384: if (keys(%ordered)) {
2385: my @items = sort { $a <=> $b } keys(%ordered);
2386: for (my $i=0; $i<@items; $i++) {
2387: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2388: my $key = $ordered{$items[$i]};
2389: my %coursehash=&Apache::lonnet::coursedescription($key);
2390: my $coursetitle = $coursehash{'description'};
2391: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2392: if (ref($bookshash->{$key}) eq 'HASH') {
2393: $subject = $bookshash->{$key}->{'subject'};
2394: $title = $bookshash->{$key}->{'title'};
2395: if ($type eq 'textbooks') {
2396: $publisher = $bookshash->{$key}->{'publisher'};
2397: $author = $bookshash->{$key}->{'author'};
2398: $image = $bookshash->{$key}->{'image'};
2399: if ($image ne '') {
2400: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2401: my $imagethumb = "$path/tn-".$imagefile;
2402: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2403: }
2404: }
2405: }
2406: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2407: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2408: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2409: for (my $k=0; $k<=$maxnum; $k++) {
2410: my $vpos = $k+1;
2411: my $selstr;
2412: if ($k == $i) {
2413: $selstr = ' selected="selected" ';
2414: }
2415: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2416: }
2417: $datatable .= '</select>'.(' 'x2).
2418: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2419: &mt('Delete?').'</label></span></td>'.
2420: '<td colspan="2">'.
2421: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2422: (' 'x2).
2423: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2424: if ($type eq 'textbooks') {
2425: $datatable .= (' 'x2).
2426: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2427: (' 'x2).
2428: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2429: (' 'x2).
2430: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2431: if ($image) {
2432: $datatable .= $imgsrc.
2433: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2434: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2435: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2436: }
2437: if ($switchserver) {
2438: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2439: } else {
2440: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2441: }
2442: }
2443: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2444: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2445: $coursetitle.'</span></td></tr>'."\n";
2446: $itemcount ++;
2447: }
2448: }
2449: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2450: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2451: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2452: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2453: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2454: for (my $k=0; $k<$maxnum+1; $k++) {
2455: my $vpos = $k+1;
2456: my $selstr;
2457: if ($k == $maxnum) {
2458: $selstr = ' selected="selected" ';
2459: }
2460: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2461: }
2462: $datatable .= '</select> '."\n".
2463: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
2464: '<td colspan="2">'.
2465: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2466: (' 'x2).
2467: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2468: (' 'x2);
2469: if ($type eq 'textbooks') {
2470: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2471: (' 'x2).
2472: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2473: (' 'x2).
2474: '<span class="LC_nobreak">'.&mt('Image:').' ';
2475: if ($switchserver) {
2476: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2477: } else {
2478: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2479: }
2480: }
2481: $datatable .= '</span>'."\n".
2482: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2483: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2484: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2485: &Apache::loncommon::selectcourse_link
2486: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
2487: '</span></td>'."\n".
2488: '</tr>'."\n";
2489: $itemcount ++;
2490: return $datatable;
2491: }
2492:
2493: sub textbookcourses_javascript {
2494: my ($settings) = @_;
2495: return unless(ref($settings) eq 'HASH');
2496: my (%ordered,%total,%jstext);
2497: foreach my $type ('textbooks','templates') {
2498: $total{$type} = 0;
2499: if (ref($settings->{$type}) eq 'HASH') {
2500: foreach my $item (keys(%{$settings->{$type}})) {
2501: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2502: my $num = $settings->{$type}->{$item}{'order'};
2503: $ordered{$type}{$num} = $item;
2504: }
2505: }
2506: $total{$type} = scalar(keys(%{$settings->{$type}}));
2507: }
2508: my @jsarray = ();
2509: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2510: push(@jsarray,$ordered{$type}{$item});
2511: }
2512: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2513: }
2514: return <<"ENDSCRIPT";
2515: <script type="text/javascript">
2516: // <![CDATA[
2517: function reorderBooks(form,item,caller) {
2518: var changedVal;
2519: $jstext{'textbooks'};
2520: $jstext{'templates'};
2521: var newpos;
2522: var maxh;
2523: if (caller == 'textbooks') {
2524: newpos = 'textbooks_addbook_pos';
2525: maxh = 1 + $total{'textbooks'};
2526: } else {
2527: newpos = 'templates_addbook_pos';
2528: maxh = 1 + $total{'templates'};
2529: }
2530: var current = new Array;
2531: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2532: if (item == newpos) {
2533: changedVal = newitemVal;
2534: } else {
2535: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2536: current[newitemVal] = newpos;
2537: }
2538: if (caller == 'textbooks') {
2539: for (var i=0; i<textbooks.length; i++) {
2540: var elementName = 'textbooks_'+textbooks[i];
2541: if (elementName != item) {
2542: if (form.elements[elementName]) {
2543: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2544: current[currVal] = elementName;
2545: }
2546: }
2547: }
2548: }
2549: if (caller == 'templates') {
2550: for (var i=0; i<templates.length; i++) {
2551: var elementName = 'templates_'+templates[i];
2552: if (elementName != item) {
2553: if (form.elements[elementName]) {
2554: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2555: current[currVal] = elementName;
2556: }
2557: }
2558: }
2559: }
2560: var oldVal;
2561: for (var j=0; j<maxh; j++) {
2562: if (current[j] == undefined) {
2563: oldVal = j;
2564: }
2565: }
2566: if (oldVal < changedVal) {
2567: for (var k=oldVal+1; k<=changedVal ; k++) {
2568: var elementName = current[k];
2569: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2570: }
2571: } else {
2572: for (var k=changedVal; k<oldVal; k++) {
2573: var elementName = current[k];
2574: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2575: }
2576: }
2577: return;
2578: }
2579:
2580: // ]]>
2581: </script>
2582:
2583: ENDSCRIPT
2584: }
2585:
2586: sub ltitools_javascript {
2587: my ($settings) = @_;
2588: return unless(ref($settings) eq 'HASH');
2589: my (%ordered,$total,%jstext);
2590: $total = 0;
2591: foreach my $item (keys(%{$settings})) {
2592: if (ref($settings->{$item}) eq 'HASH') {
2593: my $num = $settings->{$item}{'order'};
2594: $ordered{$num} = $item;
2595: }
2596: }
2597: $total = scalar(keys(%{$settings}));
2598: my @jsarray = ();
2599: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2600: push(@jsarray,$ordered{$item});
2601: }
2602: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2603: return <<"ENDSCRIPT";
2604: <script type="text/javascript">
2605: // <![CDATA[
2606: function reorderLTI(form,item) {
2607: var changedVal;
2608: $jstext
2609: var newpos = 'ltitools_add_pos';
2610: var maxh = 1 + $total;
2611: var current = new Array;
2612: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2613: if (item == newpos) {
2614: changedVal = newitemVal;
2615: } else {
2616: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2617: current[newitemVal] = newpos;
2618: }
2619: for (var i=0; i<ltitools.length; i++) {
2620: var elementName = 'ltitools_'+ltitools[i];
2621: if (elementName != item) {
2622: if (form.elements[elementName]) {
2623: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2624: current[currVal] = elementName;
2625: }
2626: }
2627: }
2628: var oldVal;
2629: for (var j=0; j<maxh; j++) {
2630: if (current[j] == undefined) {
2631: oldVal = j;
2632: }
2633: }
2634: if (oldVal < changedVal) {
2635: for (var k=oldVal+1; k<=changedVal ; k++) {
2636: var elementName = current[k];
2637: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2638: }
2639: } else {
2640: for (var k=changedVal; k<oldVal; k++) {
2641: var elementName = current[k];
2642: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2643: }
2644: }
2645: return;
2646: }
2647:
2648: // ]]>
2649: </script>
2650:
2651: ENDSCRIPT
2652: }
2653:
2654: sub print_autoenroll {
2655: my ($dom,$settings,$rowtotal) = @_;
2656: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2657: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
2658: if (ref($settings) eq 'HASH') {
2659: if (exists($settings->{'run'})) {
2660: if ($settings->{'run'} eq '0') {
2661: $runoff = ' checked="checked" ';
2662: $runon = ' ';
2663: } else {
2664: $runon = ' checked="checked" ';
2665: $runoff = ' ';
2666: }
2667: } else {
2668: if ($autorun) {
2669: $runon = ' checked="checked" ';
2670: $runoff = ' ';
2671: } else {
2672: $runoff = ' checked="checked" ';
2673: $runon = ' ';
2674: }
2675: }
2676: if (exists($settings->{'co-owners'})) {
2677: if ($settings->{'co-owners'} eq '0') {
2678: $coownersoff = ' checked="checked" ';
2679: $coownerson = ' ';
2680: } else {
2681: $coownerson = ' checked="checked" ';
2682: $coownersoff = ' ';
2683: }
2684: } else {
2685: $coownersoff = ' checked="checked" ';
2686: $coownerson = ' ';
2687: }
2688: if (exists($settings->{'sender_domain'})) {
2689: $defdom = $settings->{'sender_domain'};
2690: }
2691: if (exists($settings->{'autofailsafe'})) {
2692: $failsafe = $settings->{'autofailsafe'};
2693: }
2694: } else {
2695: if ($autorun) {
2696: $runon = ' checked="checked" ';
2697: $runoff = ' ';
2698: } else {
2699: $runoff = ' checked="checked" ';
2700: $runon = ' ';
2701: }
2702: }
2703: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
2704: my $notif_sender;
2705: if (ref($settings) eq 'HASH') {
2706: $notif_sender = $settings->{'sender_uname'};
2707: }
2708: my $datatable='<tr class="LC_odd_row">'.
2709: '<td>'.&mt('Auto-enrollment active?').'</td>'.
2710: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2711: '<input type="radio" name="autoenroll_run"'.
2712: $runon.' value="1" />'.&mt('Yes').'</label> '.
2713: '<label><input type="radio" name="autoenroll_run"'.
2714: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
2715: '</tr><tr>'.
2716: '<td>'.&mt('Notification messages - sender').
2717: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
2718: &mt('username').': '.
2719: '<input type="text" name="sender_uname" value="'.
2720: $notif_sender.'" size="10" /> '.&mt('domain').
2721: ': '.$domform.'</span></td></tr>'.
2722: '<tr class="LC_odd_row">'.
2723: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2724: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2725: '<input type="radio" name="autoassign_coowners"'.
2726: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2727: '<label><input type="radio" name="autoassign_coowners"'.
2728: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2729: '</tr><tr>'.
2730: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2731: '<td class="LC_right_item"><span class="LC_nobreak">'.
2732: '<input type="text" name="autoenroll_failsafe"'.
2733: ' value="'.$failsafe.'" size="4" /></td></tr>';
2734: $$rowtotal += 4;
2735: return $datatable;
2736: }
2737:
2738: sub print_autoupdate {
2739: my ($position,$dom,$settings,$rowtotal) = @_;
2740: my $datatable;
2741: if ($position eq 'top') {
2742: my $updateon = ' ';
2743: my $updateoff = ' checked="checked" ';
2744: my $classlistson = ' ';
2745: my $classlistsoff = ' checked="checked" ';
2746: if (ref($settings) eq 'HASH') {
2747: if ($settings->{'run'} eq '1') {
2748: $updateon = $updateoff;
2749: $updateoff = ' ';
2750: }
2751: if ($settings->{'classlists'} eq '1') {
2752: $classlistson = $classlistsoff;
2753: $classlistsoff = ' ';
2754: }
2755: }
2756: my %title = (
2757: run => 'Auto-update active?',
2758: classlists => 'Update information in classlists?',
2759: );
2760: $datatable = '<tr class="LC_odd_row">'.
2761: '<td>'.&mt($title{'run'}).'</td>'.
2762: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2763: '<input type="radio" name="autoupdate_run"'.
2764: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2765: '<label><input type="radio" name="autoupdate_run"'.
2766: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
2767: '</tr><tr>'.
2768: '<td>'.&mt($title{'classlists'}).'</td>'.
2769: '<td class="LC_right_item"><span class="LC_nobreak">'.
2770: '<label><input type="radio" name="classlists"'.
2771: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2772: '<label><input type="radio" name="classlists"'.
2773: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
2774: '</tr>';
2775: $$rowtotal += 2;
2776: } elsif ($position eq 'middle') {
2777: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2778: my $numinrow = 3;
2779: my $locknamesettings;
2780: $datatable .= &insttypes_row($settings,$types,$usertypes,
2781: $dom,$numinrow,$othertitle,
2782: 'lockablenames',$rowtotal);
2783: $$rowtotal ++;
2784: } else {
2785: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2786: my @fields = ('lastname','firstname','middlename','generation',
2787: 'permanentemail','id');
2788: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2789: my $numrows = 0;
2790: if (ref($types) eq 'ARRAY') {
2791: if (@{$types} > 0) {
2792: $datatable =
2793: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2794: \@fields,$types,\$numrows);
2795: $$rowtotal += @{$types};
2796: }
2797: }
2798: $datatable .=
2799: &usertype_update_row($settings,{'default' => $othertitle},
2800: \%fieldtitles,\@fields,['default'],
2801: \$numrows);
2802: $$rowtotal ++;
2803: }
2804: return $datatable;
2805: }
2806:
2807: sub print_autocreate {
2808: my ($dom,$settings,$rowtotal) = @_;
2809: my (%createon,%createoff,%currhash);
2810: my @types = ('xml','req');
2811: if (ref($settings) eq 'HASH') {
2812: foreach my $item (@types) {
2813: $createoff{$item} = ' checked="checked" ';
2814: $createon{$item} = ' ';
2815: if (exists($settings->{$item})) {
2816: if ($settings->{$item}) {
2817: $createon{$item} = ' checked="checked" ';
2818: $createoff{$item} = ' ';
2819: }
2820: }
2821: }
2822: if ($settings->{'xmldc'} ne '') {
2823: $currhash{$settings->{'xmldc'}} = 1;
2824: }
2825: } else {
2826: foreach my $item (@types) {
2827: $createoff{$item} = ' checked="checked" ';
2828: $createon{$item} = ' ';
2829: }
2830: }
2831: $$rowtotal += 2;
2832: my $numinrow = 2;
2833: my $datatable='<tr class="LC_odd_row">'.
2834: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2835: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2836: '<input type="radio" name="autocreate_xml"'.
2837: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2838: '<label><input type="radio" name="autocreate_xml"'.
2839: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2840: '</td></tr><tr>'.
2841: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2842: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2843: '<input type="radio" name="autocreate_req"'.
2844: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2845: '<label><input type="radio" name="autocreate_req"'.
2846: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2847: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2848: 'autocreate_xmldc',%currhash);
2849: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
2850: if ($numdc > 1) {
2851: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2852: '</td><td class="LC_left_item">';
2853: } else {
2854: $datatable .= &mt('Course creation processed as:').
2855: '</td><td class="LC_right_item">';
2856: }
2857: $datatable .= $dctable.'</td></tr>';
2858: $$rowtotal += $rows;
2859: return $datatable;
2860: }
2861:
2862: sub print_directorysrch {
2863: my ($position,$dom,$settings,$rowtotal) = @_;
2864: my $datatable;
2865: if ($position eq 'top') {
2866: my $instsrchon = ' ';
2867: my $instsrchoff = ' checked="checked" ';
2868: my ($exacton,$containson,$beginson);
2869: my $instlocalon = ' ';
2870: my $instlocaloff = ' checked="checked" ';
2871: if (ref($settings) eq 'HASH') {
2872: if ($settings->{'available'} eq '1') {
2873: $instsrchon = $instsrchoff;
2874: $instsrchoff = ' ';
2875: }
2876: if ($settings->{'localonly'} eq '1') {
2877: $instlocalon = $instlocaloff;
2878: $instlocaloff = ' ';
2879: }
2880: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2881: foreach my $type (@{$settings->{'searchtypes'}}) {
2882: if ($type eq 'exact') {
2883: $exacton = ' checked="checked" ';
2884: } elsif ($type eq 'contains') {
2885: $containson = ' checked="checked" ';
2886: } elsif ($type eq 'begins') {
2887: $beginson = ' checked="checked" ';
2888: }
2889: }
2890: } else {
2891: if ($settings->{'searchtypes'} eq 'exact') {
2892: $exacton = ' checked="checked" ';
2893: } elsif ($settings->{'searchtypes'} eq 'contains') {
2894: $containson = ' checked="checked" ';
2895: } elsif ($settings->{'searchtypes'} eq 'specify') {
2896: $exacton = ' checked="checked" ';
2897: $containson = ' checked="checked" ';
2898: }
2899: }
2900: }
2901: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2902: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2903:
2904: my $numinrow = 4;
2905: my $cansrchrow = 0;
2906: $datatable='<tr class="LC_odd_row">'.
2907: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2908: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2909: '<input type="radio" name="dirsrch_available"'.
2910: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2911: '<label><input type="radio" name="dirsrch_available"'.
2912: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2913: '</tr><tr>'.
2914: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2915: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2916: '<input type="radio" name="dirsrch_instlocalonly"'.
2917: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2918: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2919: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2920: '</tr>';
2921: $$rowtotal += 2;
2922: if (ref($usertypes) eq 'HASH') {
2923: if (keys(%{$usertypes}) > 0) {
2924: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2925: $numinrow,$othertitle,'cansearch',
2926: $rowtotal);
2927: $cansrchrow = 1;
2928: }
2929: }
2930: if ($cansrchrow) {
2931: $$rowtotal ++;
2932: $datatable .= '<tr>';
2933: } else {
2934: $datatable .= '<tr class="LC_odd_row">';
2935: }
2936: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2937: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2938: foreach my $title (@{$titleorder}) {
2939: if (defined($searchtitles->{$title})) {
2940: my $check = ' ';
2941: if (ref($settings) eq 'HASH') {
2942: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2943: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2944: $check = ' checked="checked" ';
2945: }
2946: }
2947: }
2948: $datatable .= '<td class="LC_left_item">'.
2949: '<span class="LC_nobreak"><label>'.
2950: '<input type="checkbox" name="searchby" '.
2951: 'value="'.$title.'"'.$check.'/>'.
2952: $searchtitles->{$title}.'</label></span></td>';
2953: }
2954: }
2955: $datatable .= '</tr></table></td></tr>';
2956: $$rowtotal ++;
2957: if ($cansrchrow) {
2958: $datatable .= '<tr class="LC_odd_row">';
2959: } else {
2960: $datatable .= '<tr>';
2961: }
2962: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2963: '<td class="LC_left_item" colspan="2">'.
2964: '<span class="LC_nobreak"><label>'.
2965: '<input type="checkbox" name="searchtypes" '.
2966: $exacton.' value="exact" />'.&mt('Exact match').
2967: '</label> '.
2968: '<label><input type="checkbox" name="searchtypes" '.
2969: $beginson.' value="begins" />'.&mt('Begins with').
2970: '</label> '.
2971: '<label><input type="checkbox" name="searchtypes" '.
2972: $containson.' value="contains" />'.&mt('Contains').
2973: '</label></span></td></tr>';
2974: $$rowtotal ++;
2975: } else {
2976: my $domsrchon = ' checked="checked" ';
2977: my $domsrchoff = ' ';
2978: my $domlocalon = ' ';
2979: my $domlocaloff = ' checked="checked" ';
2980: if (ref($settings) eq 'HASH') {
2981: if ($settings->{'lclocalonly'} eq '1') {
2982: $domlocalon = $domlocaloff;
2983: $domlocaloff = ' ';
2984: }
2985: if ($settings->{'lcavailable'} eq '0') {
2986: $domsrchoff = $domsrchon;
2987: $domsrchon = ' ';
2988: }
2989: }
2990: $datatable='<tr class="LC_odd_row">'.
2991: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2992: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2993: '<input type="radio" name="dirsrch_domavailable"'.
2994: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2995: '<label><input type="radio" name="dirsrch_domavailable"'.
2996: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2997: '</tr><tr>'.
2998: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2999: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3000: '<input type="radio" name="dirsrch_domlocalonly"'.
3001: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3002: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3003: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3004: '</tr>';
3005: $$rowtotal += 2;
3006: }
3007: return $datatable;
3008: }
3009:
3010: sub print_contacts {
3011: my ($position,$dom,$settings,$rowtotal) = @_;
3012: my $datatable;
3013: my @contacts = ('adminemail','supportemail');
3014: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3015: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3016: if ($position eq 'top') {
3017: if (ref($settings) eq 'HASH') {
3018: foreach my $item (@contacts) {
3019: if (exists($settings->{$item})) {
3020: $to{$item} = $settings->{$item};
3021: }
3022: }
3023: }
3024: } elsif ($position eq 'middle') {
3025: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3026: 'updatesmail','idconflictsmail');
3027: foreach my $type (@mailings) {
3028: $otheremails{$type} = '';
3029: }
3030: } else {
3031: @mailings = ('helpdeskmail','otherdomsmail');
3032: foreach my $type (@mailings) {
3033: $otheremails{$type} = '';
3034: }
3035: $bccemails{'helpdeskmail'} = '';
3036: $bccemails{'otherdomsmail'} = '';
3037: $includestr{'helpdeskmail'} = '';
3038: $includestr{'otherdomsmail'} = '';
3039: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3040: }
3041: if (ref($settings) eq 'HASH') {
3042: unless ($position eq 'top') {
3043: foreach my $type (@mailings) {
3044: if (exists($settings->{$type})) {
3045: if (ref($settings->{$type}) eq 'HASH') {
3046: foreach my $item (@contacts) {
3047: if ($settings->{$type}{$item}) {
3048: $checked{$type}{$item} = ' checked="checked" ';
3049: }
3050: }
3051: $otheremails{$type} = $settings->{$type}{'others'};
3052: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3053: $bccemails{$type} = $settings->{$type}{'bcc'};
3054: if ($settings->{$type}{'include'} ne '') {
3055: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3056: $includestr{$type} = &unescape($includestr{$type});
3057: }
3058: }
3059: }
3060: } elsif ($type eq 'lonstatusmail') {
3061: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3062: }
3063: }
3064: }
3065: if ($position eq 'bottom') {
3066: foreach my $type (@mailings) {
3067: $bccemails{$type} = $settings->{$type}{'bcc'};
3068: if ($settings->{$type}{'include'} ne '') {
3069: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3070: $includestr{$type} = &unescape($includestr{$type});
3071: }
3072: }
3073: if (ref($settings->{'helpform'}) eq 'HASH') {
3074: if (ref($fields) eq 'ARRAY') {
3075: foreach my $field (@{$fields}) {
3076: $currfield{$field} = $settings->{'helpform'}{$field};
3077: }
3078: }
3079: if (exists($settings->{'helpform'}{'maxsize'})) {
3080: $maxsize = $settings->{'helpform'}{'maxsize'};
3081: } else {
3082: $maxsize = '1.0';
3083: }
3084: } else {
3085: if (ref($fields) eq 'ARRAY') {
3086: foreach my $field (@{$fields}) {
3087: $currfield{$field} = 'yes';
3088: }
3089: }
3090: $maxsize = '1.0';
3091: }
3092: }
3093: } else {
3094: if ($position eq 'top') {
3095: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3096: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3097: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3098: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3099: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3100: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3101: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3102: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3103: } elsif ($position eq 'bottom') {
3104: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3105: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3106: if (ref($fields) eq 'ARRAY') {
3107: foreach my $field (@{$fields}) {
3108: $currfield{$field} = 'yes';
3109: }
3110: }
3111: $maxsize = '1.0';
3112: }
3113: }
3114: my ($titles,$short_titles) = &contact_titles();
3115: my $rownum = 0;
3116: my $css_class;
3117: if ($position eq 'top') {
3118: foreach my $item (@contacts) {
3119: $css_class = $rownum%2?' class="LC_odd_row"':'';
3120: $datatable .= '<tr'.$css_class.'>'.
3121: '<td><span class="LC_nobreak">'.$titles->{$item}.
3122: '</span></td><td class="LC_right_item">'.
3123: '<input type="text" name="'.$item.'" value="'.
3124: $to{$item}.'" /></td></tr>';
3125: $rownum ++;
3126: }
3127: } else {
3128: foreach my $type (@mailings) {
3129: $css_class = $rownum%2?' class="LC_odd_row"':'';
3130: $datatable .= '<tr'.$css_class.'>'.
3131: '<td><span class="LC_nobreak">'.
3132: $titles->{$type}.': </span></td>'.
3133: '<td class="LC_left_item">';
3134: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3135: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3136: }
3137: $datatable .= '<span class="LC_nobreak">';
3138: foreach my $item (@contacts) {
3139: $datatable .= '<label>'.
3140: '<input type="checkbox" name="'.$type.'"'.
3141: $checked{$type}{$item}.
3142: ' value="'.$item.'" />'.$short_titles->{$item}.
3143: '</label> ';
3144: }
3145: $datatable .= '</span><br />'.&mt('Others').': '.
3146: '<input type="text" name="'.$type.'_others" '.
3147: 'value="'.$otheremails{$type}.'" />';
3148: my %locchecked;
3149: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3150: foreach my $loc ('s','b') {
3151: if ($includeloc{$type} eq $loc) {
3152: $locchecked{$loc} = ' checked="checked"';
3153: last;
3154: }
3155: }
3156: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3157: '<input type="text" name="'.$type.'_bcc" '.
3158: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3159: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3160: &mt('Text automatically added to e-mail:').' '.
3161: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3162: '<span class="LC_nobreak">'.&mt('Location:').' '.
3163: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3164: (' 'x2).
3165: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3166: '</span></fieldset>';
3167: }
3168: $datatable .= '</td></tr>'."\n";
3169: $rownum ++;
3170: }
3171: }
3172: if ($position eq 'middle') {
3173: my %choices;
3174: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3175: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3176: &mt('LON-CAPA core group - MSU'),600,500));
3177: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3178: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3179: &mt('LON-CAPA core group - MSU'),600,500));
3180: my @toggles = ('reporterrors','reportupdates');
3181: my %defaultchecked = ('reporterrors' => 'on',
3182: 'reportupdates' => 'on');
3183: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3184: \%choices,$rownum);
3185: $datatable .= $reports;
3186: } elsif ($position eq 'bottom') {
3187: $css_class = $rownum%2?' class="LC_odd_row"':'';
3188: $datatable .= '<tr'.$css_class.'>'.
3189: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3190: &mt('(e-mail, subject, and description always shown)').
3191: '</td><td class="LC_left_item">';
3192: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3193: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3194: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3195: foreach my $field (@{$fields}) {
3196: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3197: if (($field eq 'screenshot') || ($field eq 'cc')) {
3198: $datatable .= ' '.&mt('(logged-in users)');
3199: }
3200: $datatable .='</td><td>';
3201: my $clickaction;
3202: if ($field eq 'screenshot') {
3203: $clickaction = ' onclick="screenshotSize(this);"';
3204: }
3205: if (ref($possoptions->{$field}) eq 'ARRAY') {
3206: foreach my $option (@{$possoptions->{$field}}) {
3207: my $checked;
3208: if ($currfield{$field} eq $option) {
3209: $checked = ' checked="checked"';
3210: }
3211: $datatable .= '<span class="LC_nobreak"><label>'.
3212: '<input type="radio" name="helpform_'.$field.'" '.
3213: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3214: '</label></span>'.(' 'x2);
3215: }
3216: }
3217: if ($field eq 'screenshot') {
3218: my $display;
3219: if ($currfield{$field} eq 'no') {
3220: $display = ' style="display:none"';
3221: }
3222: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3223: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3224: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3225: }
3226: $datatable .= '</td></tr>';
3227: }
3228: $datatable .= '</table>';
3229: }
3230: $datatable .= '</td></tr>'."\n";
3231: $rownum ++;
3232: }
3233: $$rowtotal += $rownum;
3234: return $datatable;
3235: }
3236:
3237: sub contacts_javascript {
3238: return <<"ENDSCRIPT";
3239:
3240: <script type="text/javascript">
3241: // <![CDATA[
3242:
3243: function screenshotSize(field) {
3244: if (document.getElementById('help_screenshotsize')) {
3245: if (field.value == 'no') {
3246: document.getElementById('help_screenshotsize').style.display="none";
3247: } else {
3248: document.getElementById('help_screenshotsize').style.display="";
3249: }
3250: }
3251: return;
3252: }
3253:
3254: // ]]>
3255: </script>
3256:
3257: ENDSCRIPT
3258: }
3259:
3260: sub print_helpsettings {
3261: my ($position,$dom,$settings,$rowtotal) = @_;
3262: my $confname = $dom.'-domainconfig';
3263: my $formname = 'display';
3264: my ($datatable,$itemcount);
3265: if ($position eq 'top') {
3266: $itemcount = 1;
3267: my (%choices,%defaultchecked,@toggles);
3268: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3269: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3270: &mt('LON-CAPA bug tracker'),600,500));
3271: %defaultchecked = ('submitbugs' => 'on');
3272: @toggles = ('submitbugs');
3273: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3274: \%choices,$itemcount);
3275: $$rowtotal ++;
3276: } else {
3277: my $css_class;
3278: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
3279: my (%customroles,%ordered,%current);
3280: if (ref($settings) eq 'HASH') {
3281: if (ref($settings->{'adhoc'}) eq 'HASH') {
3282: %current = %{$settings->{'adhoc'}};
3283: }
3284: }
3285: my $count = 0;
3286: foreach my $key (sort(keys(%existing))) {
3287: if ($key=~/^rolesdef\_(\w+)$/) {
3288: my $rolename = $1;
3289: my (%privs,$order);
3290: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3291: $customroles{$rolename} = \%privs;
3292: if (ref($current{$rolename}) eq 'HASH') {
3293: $order = $current{$rolename}{'order'};
3294: }
3295: if ($order eq '') {
3296: $order = $count;
3297: }
3298: $ordered{$order} = $rolename;
3299: $count++;
3300: }
3301: }
3302: my $maxnum = scalar(keys(%ordered));
3303: my @roles_by_num = ();
3304: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3305: push(@roles_by_num,$item);
3306: }
3307: my $context = 'domprefs';
3308: my $crstype = 'Course';
3309: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3310: my @accesstypes = ('all','dh','da','none');
3311: my ($numstatustypes,@jsarray);
3312: if (ref($types) eq 'ARRAY') {
3313: if (@{$types} > 0) {
3314: $numstatustypes = scalar(@{$types});
3315: push(@accesstypes,'status');
3316: @jsarray = ('bystatus');
3317: }
3318: }
3319: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
3320: if (keys(%domhelpdesk)) {
3321: push(@accesstypes,('inc','exc'));
3322: push(@jsarray,('notinc','notexc'));
3323: }
3324: my $hiddenstr = join("','",@jsarray);
3325: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
3326: my $context = 'domprefs';
3327: my $crstype = 'Course';
3328: my $prefix = 'helproles_';
3329: my $add_class = 'LC_hidden';
3330: foreach my $num (@roles_by_num) {
3331: my $role = $ordered{$num};
3332: my ($desc,$access,@statuses);
3333: if (ref($current{$role}) eq 'HASH') {
3334: $desc = $current{$role}{'desc'};
3335: $access = $current{$role}{'access'};
3336: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3337: @statuses = @{$current{$role}{'insttypes'}};
3338: }
3339: }
3340: if ($desc eq '') {
3341: $desc = $role;
3342: }
3343: my $identifier = 'custhelp'.$num;
3344: my %full=();
3345: my %levels= (
3346: course => {},
3347: domain => {},
3348: system => {},
3349: );
3350: my %levelscurrent=(
3351: course => {},
3352: domain => {},
3353: system => {},
3354: );
3355: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3356: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3358: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3359: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
3360: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3361: for (my $k=0; $k<=$maxnum; $k++) {
3362: my $vpos = $k+1;
3363: my $selstr;
3364: if ($k == $num) {
3365: $selstr = ' selected="selected" ';
3366: }
3367: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3368: }
3369: $datatable .= '</select>'.(' 'x2).
3370: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3371: '</td>'.
3372: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3373: &mt('Name shown to users:').
3374: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3375: '</fieldset>'.
3376: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3377: $othertitle,$usertypes,$types,\%domhelpdesk).
3378: '<fieldset>'.
3379: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
3380: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
3381: \%levelscurrent,$identifier,
3382: 'LC_hidden',$prefix.$num.'_privs').
3383: '</fieldset></td>';
3384: $itemcount ++;
3385: }
3386: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3387: my $newcust = 'custhelp'.$count;
3388: my (%privs,%levelscurrent);
3389: my %full=();
3390: my %levels= (
3391: course => {},
3392: domain => {},
3393: system => {},
3394: );
3395: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3396: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3397: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3398: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
3399: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3400: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3401: for (my $k=0; $k<$maxnum+1; $k++) {
3402: my $vpos = $k+1;
3403: my $selstr;
3404: if ($k == $maxnum) {
3405: $selstr = ' selected="selected" ';
3406: }
3407: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3408: }
3409: $datatable .= '</select> '."\n".
3410: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3411: '</label></span></td>'.
3412: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3413: '<span class="LC_nobreak">'.
3414: &mt('Internal name:').
3415: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3416: '</span>'.(' 'x4).
3417: '<span class="LC_nobreak">'.
3418: &mt('Name shown to users:').
3419: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3420: '</span></fieldset>'.
3421: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3422: $usertypes,$types,\%domhelpdesk).
3423: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
3424: &Apache::lonuserutils::custom_role_header($context,$crstype,
3425: \@templateroles,$newcust).
3426: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3427: \%levelscurrent,$newcust).
3428: '</fieldset></td></tr>';
3429: $count ++;
3430: $$rowtotal += $count;
3431: }
3432: return $datatable;
3433: }
3434:
3435: sub adhocbutton {
3436: my ($prefix,$num,$field,$visibility) = @_;
3437: my %lt = &Apache::lonlocal::texthash(
3438: show => 'Show details',
3439: hide => 'Hide details',
3440: );
3441: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3442: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3443: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3444: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3445: }
3446:
3447: sub helpsettings_javascript {
3448: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3449: return unless(ref($roles_by_num) eq 'ARRAY');
3450: my %html_js_lt = &Apache::lonlocal::texthash(
3451: show => 'Show details',
3452: hide => 'Hide details',
3453: );
3454: &html_escape(\%html_js_lt);
3455: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3456: return <<"ENDSCRIPT";
3457: <script type="text/javascript">
3458: // <![CDATA[
3459:
3460: function reorderHelpRoles(form,item) {
3461: var changedVal;
3462: $jstext
3463: var newpos = 'helproles_${total}_pos';
3464: var maxh = 1 + $total;
3465: var current = new Array();
3466: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3467: if (item == newpos) {
3468: changedVal = newitemVal;
3469: } else {
3470: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3471: current[newitemVal] = newpos;
3472: }
3473: for (var i=0; i<helproles.length; i++) {
3474: var elementName = 'helproles_'+helproles[i]+'_pos';
3475: if (elementName != item) {
3476: if (form.elements[elementName]) {
3477: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3478: current[currVal] = elementName;
3479: }
3480: }
3481: }
3482: var oldVal;
3483: for (var j=0; j<maxh; j++) {
3484: if (current[j] == undefined) {
3485: oldVal = j;
3486: }
3487: }
3488: if (oldVal < changedVal) {
3489: for (var k=oldVal+1; k<=changedVal ; k++) {
3490: var elementName = current[k];
3491: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3492: }
3493: } else {
3494: for (var k=changedVal; k<oldVal; k++) {
3495: var elementName = current[k];
3496: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3497: }
3498: }
3499: return;
3500: }
3501:
3502: function helpdeskAccess(num) {
3503: var curraccess = null;
3504: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3505: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3506: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3507: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3508: }
3509: }
3510: }
3511: var shown = Array();
3512: var hidden = Array();
3513: if (curraccess == 'none') {
3514: hidden = Array('$hiddenstr');
3515: } else {
3516: if (curraccess == 'status') {
3517: shown = Array('bystatus');
3518: hidden = Array('notinc','notexc');
3519: } else {
3520: if (curraccess == 'exc') {
3521: shown = Array('notexc');
3522: hidden = Array('notinc','bystatus');
3523: }
3524: if (curraccess == 'inc') {
3525: shown = Array('notinc');
3526: hidden = Array('notexc','bystatus');
3527: }
3528: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
3529: hidden = Array('notinc','notexc','bystatus');
3530: }
3531: }
3532: }
3533: if (hidden.length > 0) {
3534: for (var i=0; i<hidden.length; i++) {
3535: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3536: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3537: }
3538: }
3539: }
3540: if (shown.length > 0) {
3541: for (var i=0; i<shown.length; i++) {
3542: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3543: if (shown[i] == 'privs') {
3544: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3545: } else {
3546: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3547: }
3548: }
3549: }
3550: }
3551: return;
3552: }
3553:
3554: function toggleHelpdeskItem(num,field) {
3555: if (document.getElementById('helproles_'+num+'_'+field)) {
3556: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3557: document.getElementById('helproles_'+num+'_'+field).className =
3558: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3559: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3560: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3561: }
3562: } else {
3563: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3564: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3565: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3566: }
3567: }
3568: }
3569: return;
3570: }
3571:
3572: // ]]>
3573: </script>
3574:
3575: ENDSCRIPT
3576: }
3577:
3578: sub helpdeskroles_access {
3579: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3580: $usertypes,$types,$domhelpdesk) = @_;
3581: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3582: my %lt = &Apache::lonlocal::texthash(
3583: 'rou' => 'Role usage',
3584: 'whi' => 'Which helpdesk personnel may use this role?',
3585: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3586: 'dh' => 'All with domain helpdesk role',
3587: 'da' => 'All with domain helpdesk assistant role',
3588: 'none' => 'None',
3589: 'status' => 'Determined based on institutional status',
3590: 'inc' => 'Include all, but exclude specific personnel',
3591: 'exc' => 'Exclude all, but include specific personnel',
3592: );
3593: my %usecheck = (
3594: all => ' checked="checked"',
3595: );
3596: my %displaydiv = (
3597: status => 'none',
3598: inc => 'none',
3599: exc => 'none',
3600: priv => 'block',
3601: );
3602: my $output;
3603: if (ref($current) eq 'HASH') {
3604: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3605: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3606: $usecheck{$current->{access}} = $usecheck{'all'};
3607: delete($usecheck{'all'});
3608: if ($current->{access} =~ /^(status|inc|exc)$/) {
3609: my $access = $1;
3610: $displaydiv{$access} = 'inline';
3611: } elsif ($current->{access} eq 'none') {
3612: $displaydiv{'priv'} = 'none';
3613: }
3614: }
3615: }
3616: }
3617: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3618: '<p>'.$lt{'whi'}.'</p>';
3619: foreach my $access (@{$accesstypes}) {
3620: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3621: ' onclick="helpdeskAccess('."'$num'".');" />'.
3622: $lt{$access}.'</label>';
3623: if ($access eq 'status') {
3624: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3625: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3626: $othertitle,$usertypes,$types).
3627: '</div>';
3628: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3629: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3630: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3631: '</div>';
3632: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3633: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3634: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3635: '</div>';
3636: }
3637: $output .= '</p>';
3638: }
3639: $output .= '</fieldset>';
3640: return $output;
3641: }
3642:
3643: sub radiobutton_prefs {
3644: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
3645: $additional,$align) = @_;
3646: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3647: (ref($choices) eq 'HASH'));
3648:
3649: my (%checkedon,%checkedoff,$datatable,$css_class);
3650:
3651: foreach my $item (@{$toggles}) {
3652: if ($defaultchecked->{$item} eq 'on') {
3653: $checkedon{$item} = ' checked="checked" ';
3654: $checkedoff{$item} = ' ';
3655: } elsif ($defaultchecked->{$item} eq 'off') {
3656: $checkedoff{$item} = ' checked="checked" ';
3657: $checkedon{$item} = ' ';
3658: }
3659: }
3660: if (ref($settings) eq 'HASH') {
3661: foreach my $item (@{$toggles}) {
3662: if ($settings->{$item} eq '1') {
3663: $checkedon{$item} = ' checked="checked" ';
3664: $checkedoff{$item} = ' ';
3665: } elsif ($settings->{$item} eq '0') {
3666: $checkedoff{$item} = ' checked="checked" ';
3667: $checkedon{$item} = ' ';
3668: }
3669: }
3670: }
3671: if ($onclick) {
3672: $onclick = ' onclick="'.$onclick.'"';
3673: }
3674: foreach my $item (@{$toggles}) {
3675: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3676: $datatable .=
3677: '<tr'.$css_class.'><td style="vertical-align: top">'.
3678: '<span class="LC_nobreak">'.$choices->{$item}.
3679: '</span></td>';
3680: if ($align eq 'left') {
3681: $datatable .= '<td class="LC_left_item">';
3682: } else {
3683: $datatable .= '<td class="LC_right_item">';
3684: }
3685: $datatable .=
3686: '<span class="LC_nobreak">'.
3687: '<label><input type="radio" name="'.
3688: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
3689: '</label> <label><input type="radio" name="'.$item.'" '.
3690: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3691: '</span>'.$additional.
3692: '</td>'.
3693: '</tr>';
3694: $itemcount ++;
3695: }
3696: return ($datatable,$itemcount);
3697: }
3698:
3699: sub print_ltitools {
3700: my ($dom,$settings,$rowtotal) = @_;
3701: my $rownum = 0;
3702: my $css_class;
3703: my $itemcount = 1;
3704: my $maxnum = 0;
3705: my %ordered;
3706: if (ref($settings) eq 'HASH') {
3707: foreach my $item (keys(%{$settings})) {
3708: if (ref($settings->{$item}) eq 'HASH') {
3709: my $num = $settings->{$item}{'order'};
3710: $ordered{$num} = $item;
3711: }
3712: }
3713: }
3714: my $confname = $dom.'-domainconfig';
3715: my $switchserver = &check_switchserver($dom,$confname);
3716: my $maxnum = scalar(keys(%ordered));
3717: my $datatable = <itools_javascript($settings);
3718: my %lt = <itools_names();
3719: my @courseroles = ('cc','in','ta','ep','st');
3720: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3721: my @fields = ('fullname','firstname','lastname','email','user','roles');
3722: if (keys(%ordered)) {
3723: my @items = sort { $a <=> $b } keys(%ordered);
3724: for (my $i=0; $i<@items; $i++) {
3725: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3726: my $item = $ordered{$items[$i]};
3727: my ($title,$key,$secret,$url,$imgsrc,$version);
3728: if (ref($settings->{$item}) eq 'HASH') {
3729: $title = $settings->{$item}->{'title'};
3730: $url = $settings->{$item}->{'url'};
3731: $key = $settings->{$item}->{'key'};
3732: $secret = $settings->{$item}->{'secret'};
3733: my $image = $settings->{$item}->{'image'};
3734: if ($image ne '') {
3735: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3736: }
3737: }
3738: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3739: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3740: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3741: for (my $k=0; $k<=$maxnum; $k++) {
3742: my $vpos = $k+1;
3743: my $selstr;
3744: if ($k == $i) {
3745: $selstr = ' selected="selected" ';
3746: }
3747: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3748: }
3749: $datatable .= '</select>'.(' 'x2).
3750: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3751: &mt('Delete?').'</label></span></td>'.
3752: '<td colspan="2">'.
3753: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3754: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3755: (' 'x2).
3756: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3757: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3758: (' 'x2).
3759: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3760: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3761: '<br /><br />'.
3762: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3763: ' value="'.$url.'" /></span>'.
3764: (' 'x2).
3765: '<span class="LC_nobreak">'.$lt{'key'}.
3766: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3767: (' 'x2).
3768: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3769: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3770: '<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>'.
3771: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3772: '</fieldset>'.
3773: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3774: '<span class="LC_nobreak">'.&mt('Display target:');
3775: my %currdisp;
3776: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3777: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3778: $currdisp{'window'} = ' checked="checked"';
3779: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3780: $currdisp{'tab'} = ' checked="checked"';
3781: } else {
3782: $currdisp{'iframe'} = ' checked="checked"';
3783: }
3784: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3785: $currdisp{'width'} = $1;
3786: }
3787: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3788: $currdisp{'height'} = $1;
3789: }
3790: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3791: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
3792: } else {
3793: $currdisp{'iframe'} = ' checked="checked"';
3794: }
3795: foreach my $disp ('iframe','tab','window') {
3796: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3797: $lt{$disp}.'</label>'.(' 'x2);
3798: }
3799: $datatable .= (' 'x4);
3800: foreach my $dimen ('width','height') {
3801: $datatable .= '<label>'.$lt{$dimen}.' '.
3802: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3803: (' 'x2);
3804: }
3805: $datatable .= '<br />'.
3806: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3807: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3808: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3809: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3810: '</textarea></div><div style=""></div><br />';
3811: $datatable .= '<br />';
3812: foreach my $extra ('passback','roster') {
3813: my $checkedon = '';
3814: my $checkedoff = ' checked="checked"';
3815: if ($settings->{$item}->{$extra}) {
3816: $checkedon = $checkedoff;
3817: $checkedoff = '';
3818: }
3819: $datatable .= $lt{$extra}.' '.
3820: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3821: &mt('Yes').'</label>'.(' 'x2).
3822: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3823: &mt('No').'</label>'.(' 'x4);
3824: }
3825: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3826: if ($imgsrc) {
3827: $datatable .= $imgsrc.
3828: '<label><input type="checkbox" name="ltitools_image_del"'.
3829: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3830: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3831: } else {
3832: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3833: }
3834: if ($switchserver) {
3835: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3836: } else {
3837: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3838: }
3839: $datatable .= '</span></fieldset>';
3840: my (%checkedfields,%rolemaps);
3841: if (ref($settings->{$item}) eq 'HASH') {
3842: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3843: %checkedfields = %{$settings->{$item}->{'fields'}};
3844: }
3845: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3846: %rolemaps = %{$settings->{$item}->{'roles'}};
3847: $checkedfields{'roles'} = 1;
3848: }
3849: }
3850: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3851: '<span class="LC_nobreak">';
3852: foreach my $field (@fields) {
3853: my $checked;
3854: if ($checkedfields{$field}) {
3855: $checked = ' checked="checked"';
3856: }
3857: $datatable .= '<label>'.
3858: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3859: $lt{$field}.'</label>'.(' ' x2);
3860: }
3861: $datatable .= '</span></fieldset>'.
3862: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3863: foreach my $role (@courseroles) {
3864: my ($selected,$selectnone);
3865: if (!$rolemaps{$role}) {
3866: $selectnone = ' selected="selected"';
3867: }
3868: $datatable .= '<td style="text-align: center">'.
3869: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3870: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3871: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3872: foreach my $ltirole (@ltiroles) {
3873: unless ($selectnone) {
3874: if ($rolemaps{$role} eq $ltirole) {
3875: $selected = ' selected="selected"';
3876: } else {
3877: $selected = '';
3878: }
3879: }
3880: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3881: }
3882: $datatable .= '</select></td>';
3883: }
3884: $datatable .= '</tr></table></fieldset>';
3885: my %courseconfig;
3886: if (ref($settings->{$item}) eq 'HASH') {
3887: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3888: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3889: }
3890: }
3891: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3892: foreach my $item ('label','title','target','linktext','explanation') {
3893: my $checked;
3894: if ($courseconfig{$item}) {
3895: $checked = ' checked="checked"';
3896: }
3897: $datatable .= '<label>'.
3898: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3899: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3900: }
3901: $datatable .= '</span></fieldset>'.
3902: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3903: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3904: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3905: my %custom = %{$settings->{$item}->{'custom'}};
3906: if (keys(%custom) > 0) {
3907: foreach my $key (sort(keys(%custom))) {
3908: $datatable .= '<tr><td><span class="LC_nobreak">'.
3909: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3910: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3911: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3912: ' value="'.$custom{$key}.'" /></td></tr>';
3913: }
3914: }
3915: }
3916: $datatable .= '<tr><td><span class="LC_nobreak">'.
3917: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3918: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3919: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3920: $datatable .= '</table></fieldset></td></tr>'."\n";
3921: $itemcount ++;
3922: }
3923: }
3924: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3925: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3926: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3927: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3928: '<select name="ltitools_add_pos"'.$chgstr.'>';
3929: for (my $k=0; $k<$maxnum+1; $k++) {
3930: my $vpos = $k+1;
3931: my $selstr;
3932: if ($k == $maxnum) {
3933: $selstr = ' selected="selected" ';
3934: }
3935: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3936: }
3937: $datatable .= '</select> '."\n".
3938: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3939: '<td colspan="2">'.
3940: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3941: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3942: (' 'x2).
3943: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3944: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3945: (' 'x2).
3946: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3947: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3948: '<br />'.
3949: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3950: (' 'x2).
3951: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3952: (' 'x2).
3953: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3954: '<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".
3955: '</fieldset>'.
3956: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3957: '<span class="LC_nobreak">'.&mt('Display target:');
3958: my %defaultdisp;
3959: $defaultdisp{'iframe'} = ' checked="checked"';
3960: foreach my $disp ('iframe','tab','window') {
3961: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3962: $lt{$disp}.'</label>'.(' 'x2);
3963: }
3964: $datatable .= (' 'x4);
3965: foreach my $dimen ('width','height') {
3966: $datatable .= '<label>'.$lt{$dimen}.' '.
3967: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3968: (' 'x2);
3969: }
3970: $datatable .= '<br />'.
3971: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3972: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
3973: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3974: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
3975: '</div><div style=""></div><br />';
3976: foreach my $extra ('passback','roster') {
3977: $datatable .= $lt{$extra}.' '.
3978: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3979: &mt('Yes').'</label>'.(' 'x2).
3980: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3981: &mt('No').'</label>'.(' 'x4);
3982: }
3983: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3984: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3985: if ($switchserver) {
3986: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3987: } else {
3988: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3989: }
3990: $datatable .= '</span></fieldset>'.
3991: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3992: '<span class="LC_nobreak">';
3993: foreach my $field (@fields) {
3994: $datatable .= '<label>'.
3995: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3996: $lt{$field}.'</label>'.(' ' x2);
3997: }
3998: $datatable .= '</span></fieldset>'.
3999: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4000: foreach my $role (@courseroles) {
4001: my ($checked,$checkednone);
4002: $datatable .= '<td style="text-align: center">'.
4003: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4004: '<select name="ltitools_add_roles_'.$role.'">'.
4005: '<option value="" selected="selected">'.&mt('Select').'</option>';
4006: foreach my $ltirole (@ltiroles) {
4007: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4008: }
4009: $datatable .= '</select></td>';
4010: }
4011: $datatable .= '</tr></table></fieldset>'.
4012: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4013: foreach my $item ('label','title','target','linktext','explanation') {
4014: $datatable .= '<label>'.
4015: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4016: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4017: }
4018: $datatable .= '</span></fieldset>'.
4019: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4020: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4021: '<tr><td><span class="LC_nobreak">'.
4022: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4023: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4024: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4025: '</table></fieldset></td></tr>'."\n".
4026: '</td>'."\n".
4027: '</tr>'."\n";
4028: $itemcount ++;
4029: return $datatable;
4030: }
4031:
4032: sub ltitools_names {
4033: my %lt = &Apache::lonlocal::texthash(
4034: 'title' => 'Title',
4035: 'version' => 'Version',
4036: 'msgtype' => 'Message Type',
4037: 'url' => 'URL',
4038: 'key' => 'Key',
4039: 'secret' => 'Secret',
4040: 'icon' => 'Icon',
4041: 'user' => 'Username:domain',
4042: 'fullname' => 'Full Name',
4043: 'firstname' => 'First Name',
4044: 'lastname' => 'Last Name',
4045: 'email' => 'E-mail',
4046: 'roles' => 'Role',
4047: 'window' => 'Window',
4048: 'tab' => 'Tab',
4049: 'iframe' => 'iFrame',
4050: 'height' => 'Height',
4051: 'width' => 'Width',
4052: 'linktext' => 'Default Link Text',
4053: 'explanation' => 'Default Explanation',
4054: 'passback' => 'Tool can return grades:',
4055: 'roster' => 'Tool can retrieve roster:',
4056: 'crstarget' => 'Display target',
4057: 'crslabel' => 'Course label',
4058: 'crstitle' => 'Course title',
4059: 'crslinktext' => 'Link Text',
4060: 'crsexplanation' => 'Explanation',
4061: );
4062: return %lt;
4063: }
4064:
4065: sub print_coursedefaults {
4066: my ($position,$dom,$settings,$rowtotal) = @_;
4067: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
4068: my $itemcount = 1;
4069: my %choices = &Apache::lonlocal::texthash (
4070: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
4071: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
4072: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4073: coursecredits => 'Credits can be specified for courses',
4074: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4075: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4076: postsubmit => 'Disable submit button/keypress following student submission',
4077: canclone => "People who may clone a course (besides course's owner and coordinators)",
4078: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
4079: );
4080: my %staticdefaults = (
4081: anonsurvey_threshold => 10,
4082: uploadquota => 500,
4083: postsubmit => 60,
4084: mysqltables => 172800,
4085: );
4086: if ($position eq 'top') {
4087: %defaultchecked = (
4088: 'canuse_pdfforms' => 'off',
4089: 'uselcmath' => 'on',
4090: 'usejsme' => 'on',
4091: 'canclone' => 'none',
4092: );
4093: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
4094: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4095: \%choices,$itemcount);
4096: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4097: $datatable .=
4098: '<tr'.$css_class.'><td style="vertical-align: top">'.
4099: '<span class="LC_nobreak">'.$choices{'canclone'}.
4100: '</span></td><td class="LC_left_item">';
4101: my $currcanclone = 'none';
4102: my $onclick;
4103: my @cloneoptions = ('none','domain');
4104: my %clonetitles = (
4105: none => 'No additional course requesters',
4106: domain => "Any course requester in course's domain",
4107: instcode => 'Course requests for official courses ...',
4108: );
4109: my (%codedefaults,@code_order,@posscodes);
4110: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4111: \@code_order) eq 'ok') {
4112: if (@code_order > 0) {
4113: push(@cloneoptions,'instcode');
4114: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4115: }
4116: }
4117: if (ref($settings) eq 'HASH') {
4118: if ($settings->{'canclone'}) {
4119: if (ref($settings->{'canclone'}) eq 'HASH') {
4120: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4121: if (@code_order > 0) {
4122: $currcanclone = 'instcode';
4123: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4124: }
4125: }
4126: } elsif ($settings->{'canclone'} eq 'domain') {
4127: $currcanclone = $settings->{'canclone'};
4128: }
4129: }
4130: }
4131: foreach my $option (@cloneoptions) {
4132: my ($checked,$additional);
4133: if ($currcanclone eq $option) {
4134: $checked = ' checked="checked"';
4135: }
4136: if ($option eq 'instcode') {
4137: if (@code_order) {
4138: my $show = 'none';
4139: if ($checked) {
4140: $show = 'block';
4141: }
4142: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4143: &mt('Institutional codes for new and cloned course have identical:').
4144: '<br />';
4145: foreach my $item (@code_order) {
4146: my $codechk;
4147: if ($checked) {
4148: if (grep(/^\Q$item\E$/,@posscodes)) {
4149: $codechk = ' checked="checked"';
4150: }
4151: }
4152: $additional .= '<label>'.
4153: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4154: $item.'</label>';
4155: }
4156: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4157: }
4158: }
4159: $datatable .=
4160: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4161: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4162: '</label> '.$additional.'</span><br />';
4163: }
4164: $datatable .= '</td>'.
4165: '</tr>';
4166: $itemcount ++;
4167: } else {
4168: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4169: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
4170: my $currusecredits = 0;
4171: my $postsubmitclient = 1;
4172: my @types = ('official','unofficial','community','textbook','placement');
4173: if (ref($settings) eq 'HASH') {
4174: $currdefresponder = $settings->{'anonsurvey_threshold'};
4175: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4176: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4177: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4178: }
4179: }
4180: if (ref($settings->{'coursecredits'}) eq 'HASH') {
4181: foreach my $type (@types) {
4182: next if ($type eq 'community');
4183: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4184: if ($defcredits{$type} ne '') {
4185: $currusecredits = 1;
4186: }
4187: }
4188: }
4189: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4190: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4191: $postsubmitclient = 0;
4192: foreach my $type (@types) {
4193: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4194: }
4195: } else {
4196: foreach my $type (@types) {
4197: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4198: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4199: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4200: } else {
4201: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4202: }
4203: } else {
4204: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4205: }
4206: }
4207: }
4208: } else {
4209: foreach my $type (@types) {
4210: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4211: }
4212: }
4213: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4214: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4215: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4216: }
4217: } else {
4218: foreach my $type (@types) {
4219: $currmysql{$type} = $staticdefaults{'mysqltables'};
4220: }
4221: }
4222: } else {
4223: foreach my $type (@types) {
4224: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4225: }
4226: }
4227: if (!$currdefresponder) {
4228: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
4229: } elsif ($currdefresponder < 1) {
4230: $currdefresponder = 1;
4231: }
4232: foreach my $type (@types) {
4233: if ($curruploadquota{$type} eq '') {
4234: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4235: }
4236: }
4237: $datatable .=
4238: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4239: $choices{'anonsurvey_threshold'}.
4240: '</span></td>'.
4241: '<td class="LC_right_item"><span class="LC_nobreak">'.
4242: '<input type="text" name="anonsurvey_threshold"'.
4243: ' value="'.$currdefresponder.'" size="5" /></span>'.
4244: '</td></tr>'."\n";
4245: $itemcount ++;
4246: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4247: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4248: $choices{'uploadquota'}.
4249: '</span></td>'.
4250: '<td style="text-align: right" class="LC_right_item">'.
4251: '<table><tr>';
4252: foreach my $type (@types) {
4253: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
4254: '<input type="text" name="uploadquota_'.$type.'"'.
4255: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4256: }
4257: $datatable .= '</tr></table></td></tr>'."\n";
4258: $itemcount ++;
4259: my $onclick = "toggleDisplay(this.form,'credits');";
4260: my $display = 'none';
4261: if ($currusecredits) {
4262: $display = 'block';
4263: }
4264: my $additional = '<div id="credits" style="display: '.$display.'">'.
4265: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4266: foreach my $type (@types) {
4267: next if ($type eq 'community');
4268: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
4269: '<input type="text" name="'.$type.'_credits"'.
4270: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4271: }
4272: $additional .= '</tr></table></div>'."\n";
4273: %defaultchecked = ('coursecredits' => 'off');
4274: @toggles = ('coursecredits');
4275: my $current = {
4276: 'coursecredits' => $currusecredits,
4277: };
4278: (my $table,$itemcount) =
4279: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4280: \%choices,$itemcount,$onclick,$additional,'left');
4281: $datatable .= $table;
4282: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4283: my $display = 'none';
4284: if ($postsubmitclient) {
4285: $display = 'block';
4286: }
4287: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
4288: &mt('Number of seconds submit is disabled').'<br />'.
4289: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4290: '<table><tr>';
4291: foreach my $type (@types) {
4292: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
4293: '<input type="text" name="'.$type.'_timeout" value="'.
4294: $deftimeout{$type}.'" size="5" /></td>';
4295: }
4296: $additional .= '</tr></table></div>'."\n";
4297: %defaultchecked = ('postsubmit' => 'on');
4298: @toggles = ('postsubmit');
4299: $current = {
4300: 'postsubmit' => $postsubmitclient,
4301: };
4302: ($table,$itemcount) =
4303: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4304: \%choices,$itemcount,$onclick,$additional,'left');
4305: $datatable .= $table;
4306: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4307: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4308: $choices{'mysqltables'}.
4309: '</span></td>'.
4310: '<td style="text-align: right" class="LC_right_item">'.
4311: '<table><tr>';
4312: foreach my $type (@types) {
4313: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
4314: '<input type="text" name="mysqltables_'.$type.'"'.
4315: ' value="'.$currmysql{$type}.'" size="8" /></td>';
4316: }
4317: $datatable .= '</tr></table></td></tr>'."\n";
4318: $itemcount ++;
4319:
4320: }
4321: $$rowtotal += $itemcount;
4322: return $datatable;
4323: }
4324:
4325: sub print_selfenrollment {
4326: my ($position,$dom,$settings,$rowtotal) = @_;
4327: my ($css_class,$datatable);
4328: my $itemcount = 1;
4329: my @types = ('official','unofficial','community','textbook','placement');
4330: if (($position eq 'top') || ($position eq 'middle')) {
4331: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4332: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4333: my @rows;
4334: my $key;
4335: if ($position eq 'top') {
4336: $key = 'admin';
4337: if (ref($rowsref) eq 'ARRAY') {
4338: @rows = @{$rowsref};
4339: }
4340: } elsif ($position eq 'middle') {
4341: $key = 'default';
4342: @rows = ('types','registered','approval','limit');
4343: }
4344: foreach my $row (@rows) {
4345: if (defined($titlesref->{$row})) {
4346: $itemcount ++;
4347: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4348: $datatable .= '<tr'.$css_class.'>'.
4349: '<td>'.$titlesref->{$row}.'</td>'.
4350: '<td class="LC_left_item">'.
4351: '<table><tr>';
4352: my (%current,%currentcap);
4353: if (ref($settings) eq 'HASH') {
4354: if (ref($settings->{$key}) eq 'HASH') {
4355: foreach my $type (@types) {
4356: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4357: $current{$type} = $settings->{$key}->{$type}->{$row};
4358: }
4359: if (($row eq 'limit') && ($key eq 'default')) {
4360: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4361: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4362: }
4363: }
4364: }
4365: }
4366: }
4367: my %roles = (
4368: '0' => &Apache::lonnet::plaintext('dc'),
4369: );
4370:
4371: foreach my $type (@types) {
4372: unless (($row eq 'registered') && ($key eq 'default')) {
4373: $datatable .= '<th>'.&mt($type).'</th>';
4374: }
4375: }
4376: unless (($row eq 'registered') && ($key eq 'default')) {
4377: $datatable .= '</tr><tr>';
4378: }
4379: foreach my $type (@types) {
4380: if ($type eq 'community') {
4381: $roles{'1'} = &mt('Community personnel');
4382: } else {
4383: $roles{'1'} = &mt('Course personnel');
4384: }
4385: $datatable .= '<td style="vertical-align: top">';
4386: if ($position eq 'top') {
4387: my %checked;
4388: if ($current{$type} eq '0') {
4389: $checked{'0'} = ' checked="checked"';
4390: } else {
4391: $checked{'1'} = ' checked="checked"';
4392: }
4393: foreach my $role ('1','0') {
4394: $datatable .= '<span class="LC_nobreak"><label>'.
4395: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4396: 'value="'.$role.'"'.$checked{$role}.' />'.
4397: $roles{$role}.'</label></span> ';
4398: }
4399: } else {
4400: if ($row eq 'types') {
4401: my %checked;
4402: if ($current{$type} =~ /^(all|dom)$/) {
4403: $checked{$1} = ' checked="checked"';
4404: } else {
4405: $checked{''} = ' checked="checked"';
4406: }
4407: foreach my $val ('','dom','all') {
4408: $datatable .= '<span class="LC_nobreak"><label>'.
4409: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4410: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4411: }
4412: } elsif ($row eq 'registered') {
4413: my %checked;
4414: if ($current{$type} eq '1') {
4415: $checked{'1'} = ' checked="checked"';
4416: } else {
4417: $checked{'0'} = ' checked="checked"';
4418: }
4419: foreach my $val ('0','1') {
4420: $datatable .= '<span class="LC_nobreak"><label>'.
4421: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4422: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4423: }
4424: } elsif ($row eq 'approval') {
4425: my %checked;
4426: if ($current{$type} =~ /^([12])$/) {
4427: $checked{$1} = ' checked="checked"';
4428: } else {
4429: $checked{'0'} = ' checked="checked"';
4430: }
4431: for my $val (0..2) {
4432: $datatable .= '<span class="LC_nobreak"><label>'.
4433: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4434: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4435: }
4436: } elsif ($row eq 'limit') {
4437: my %checked;
4438: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4439: $checked{$1} = ' checked="checked"';
4440: } else {
4441: $checked{'none'} = ' checked="checked"';
4442: }
4443: my $cap;
4444: if ($currentcap{$type} =~ /^\d+$/) {
4445: $cap = $currentcap{$type};
4446: }
4447: foreach my $val ('none','allstudents','selfenrolled') {
4448: $datatable .= '<span class="LC_nobreak"><label>'.
4449: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4450: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4451: }
4452: $datatable .= '<br />'.
4453: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4454: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4455: '</span>';
4456: }
4457: }
4458: $datatable .= '</td>';
4459: }
4460: $datatable .= '</tr>';
4461: }
4462: $datatable .= '</table></td></tr>';
4463: }
4464: } elsif ($position eq 'bottom') {
4465: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4466: }
4467: $$rowtotal += $itemcount;
4468: return $datatable;
4469: }
4470:
4471: sub print_validation_rows {
4472: my ($caller,$dom,$settings,$rowtotal) = @_;
4473: my ($itemsref,$namesref,$fieldsref);
4474: if ($caller eq 'selfenroll') {
4475: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4476: } elsif ($caller eq 'requestcourses') {
4477: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4478: }
4479: my %currvalidation;
4480: if (ref($settings) eq 'HASH') {
4481: if (ref($settings->{'validation'}) eq 'HASH') {
4482: %currvalidation = %{$settings->{'validation'}};
4483: }
4484: }
4485: my $datatable;
4486: my $itemcount = 0;
4487: foreach my $item (@{$itemsref}) {
4488: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4489: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4490: $namesref->{$item}.
4491: '</span></td>'.
4492: '<td class="LC_left_item">';
4493: if (($item eq 'url') || ($item eq 'button')) {
4494: $datatable .= '<span class="LC_nobreak">'.
4495: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4496: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4497: } elsif ($item eq 'fields') {
4498: my @currfields;
4499: if (ref($currvalidation{$item}) eq 'ARRAY') {
4500: @currfields = @{$currvalidation{$item}};
4501: }
4502: foreach my $field (@{$fieldsref}) {
4503: my $check = '';
4504: if (grep(/^\Q$field\E$/,@currfields)) {
4505: $check = ' checked="checked"';
4506: }
4507: $datatable .= '<span class="LC_nobreak"><label>'.
4508: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4509: ' value="'.$field.'"'.$check.' />'.$field.
4510: '</label></span> ';
4511: }
4512: } elsif ($item eq 'markup') {
4513: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4514: $currvalidation{$item}.
4515: '</textarea>';
4516: }
4517: $datatable .= '</td></tr>'."\n";
4518: if (ref($rowtotal)) {
4519: $itemcount ++;
4520: }
4521: }
4522: if ($caller eq 'requestcourses') {
4523: my %currhash;
4524: if (ref($settings) eq 'HASH') {
4525: if (ref($settings->{'validation'}) eq 'HASH') {
4526: if ($settings->{'validation'}{'dc'} ne '') {
4527: $currhash{$settings->{'validation'}{'dc'}} = 1;
4528: }
4529: }
4530: }
4531: my $numinrow = 2;
4532: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4533: 'validationdc',%currhash);
4534: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4535: $datatable .= '</td></tr><tr'.$css_class.'><td>';
4536: if ($numdc > 1) {
4537: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
4538: } else {
4539: $datatable .= &mt('Course creation processed as: ');
4540: }
4541: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
4542: $itemcount ++;
4543: }
4544: if (ref($rowtotal)) {
4545: $$rowtotal += $itemcount;
4546: }
4547: return $datatable;
4548: }
4549:
4550: sub print_usersessions {
4551: my ($position,$dom,$settings,$rowtotal) = @_;
4552: my ($css_class,$datatable,$itemcount,%checked,%choices);
4553: my (%by_ip,%by_location,@intdoms,@instdoms);
4554: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4555:
4556: my @alldoms = &Apache::lonnet::all_domains();
4557: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4558: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4559: my %altids = &id_for_thisdom(%servers);
4560: if ($position eq 'top') {
4561: if (keys(%serverhomes) > 1) {
4562: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
4563: my $curroffloadnow;
4564: if (ref($settings) eq 'HASH') {
4565: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4566: $curroffloadnow = $settings->{'offloadnow'};
4567: }
4568: }
4569: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
4570: } else {
4571: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
4572: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4573: '</td></tr>';
4574: }
4575: } else {
4576: my %titles = &usersession_titles();
4577: my ($prefix,@types);
4578: if ($position eq 'bottom') {
4579: $prefix = 'remote';
4580: @types = ('version','excludedomain','includedomain');
4581: } else {
4582: $prefix = 'hosted';
4583: @types = ('excludedomain','includedomain');
4584: }
4585: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4586: }
4587: $$rowtotal += $itemcount;
4588: return $datatable;
4589: }
4590:
4591: sub rules_by_location {
4592: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4593: my ($datatable,$itemcount,$css_class);
4594: if (keys(%{$by_location}) == 0) {
4595: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4596: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4597: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4598: '</td></tr>';
4599: $itemcount = 1;
4600: } else {
4601: $itemcount = 0;
4602: my $numinrow = 5;
4603: my (%current,%checkedon,%checkedoff);
4604: my @locations = sort(keys(%{$by_location}));
4605: foreach my $type (@{$types}) {
4606: $checkedon{$type} = '';
4607: $checkedoff{$type} = ' checked="checked"';
4608: }
4609: if (ref($settings) eq 'HASH') {
4610: if (ref($settings->{$prefix}) eq 'HASH') {
4611: foreach my $key (keys(%{$settings->{$prefix}})) {
4612: $current{$key} = $settings->{$prefix}{$key};
4613: if ($key eq 'version') {
4614: if ($current{$key} ne '') {
4615: $checkedon{$key} = ' checked="checked"';
4616: $checkedoff{$key} = '';
4617: }
4618: } elsif (ref($current{$key}) eq 'ARRAY') {
4619: $checkedon{$key} = ' checked="checked"';
4620: $checkedoff{$key} = '';
4621: }
4622: }
4623: }
4624: }
4625: foreach my $type (@{$types}) {
4626: next if ($type ne 'version' && !@locations);
4627: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4628: $datatable .= '<tr'.$css_class.'>
4629: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4630: <span class="LC_nobreak">
4631: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4632: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4633: if ($type eq 'version') {
4634: my @lcversions = &Apache::lonnet::all_loncaparevs();
4635: my $selector = '<select name="'.$prefix.'_version">';
4636: foreach my $version (@lcversions) {
4637: my $selected = '';
4638: if ($current{'version'} eq $version) {
4639: $selected = ' selected="selected"';
4640: }
4641: $selector .= ' <option value="'.$version.'"'.
4642: $selected.'>'.$version.'</option>';
4643: }
4644: $selector .= '</select> ';
4645: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4646: } else {
4647: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4648: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4649: ' />'.(' 'x2).
4650: '<input type="button" value="'.&mt('uncheck all').'" '.
4651: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4652: "\n".
4653: '</div><div><table>';
4654: my $rem;
4655: for (my $i=0; $i<@locations; $i++) {
4656: my ($showloc,$value,$checkedtype);
4657: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4658: my $ip = $by_location->{$locations[$i]}->[0];
4659: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4660: $value = join(':',@{$by_ip->{$ip}});
4661: $showloc = join(', ',@{$by_ip->{$ip}});
4662: if (ref($current{$type}) eq 'ARRAY') {
4663: foreach my $loc (@{$by_ip->{$ip}}) {
4664: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4665: $checkedtype = ' checked="checked"';
4666: last;
4667: }
4668: }
4669: }
4670: }
4671: }
4672: $rem = $i%($numinrow);
4673: if ($rem == 0) {
4674: if ($i > 0) {
4675: $datatable .= '</tr>';
4676: }
4677: $datatable .= '<tr>';
4678: }
4679: $datatable .= '<td class="LC_left_item">'.
4680: '<span class="LC_nobreak"><label>'.
4681: '<input type="checkbox" name="'.$prefix.'_'.$type.
4682: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4683: '</label></span></td>';
4684: }
4685: $rem = @locations%($numinrow);
4686: my $colsleft = $numinrow - $rem;
4687: if ($colsleft > 1 ) {
4688: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4689: ' </td>';
4690: } elsif ($colsleft == 1) {
4691: $datatable .= '<td class="LC_left_item"> </td>';
4692: }
4693: $datatable .= '</tr></table>';
4694: }
4695: $datatable .= '</td></tr>';
4696: $itemcount ++;
4697: }
4698: }
4699: return ($datatable,$itemcount);
4700: }
4701:
4702: sub print_ssl {
4703: my ($position,$dom,$settings,$rowtotal) = @_;
4704: my ($css_class,$datatable);
4705: my $itemcount = 1;
4706: if ($position eq 'top') {
4707: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4708: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4709: my $same_institution;
4710: if ($intdom ne '') {
4711: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4712: if (ref($internet_names) eq 'ARRAY') {
4713: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4714: $same_institution = 1;
4715: }
4716: }
4717: }
4718: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4719: $datatable = '<tr'.$css_class.'><td colspan="2">';
4720: if ($same_institution) {
4721: my %domservers = &Apache::lonnet::get_servers($dom);
4722: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4723: } else {
4724: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
4725: }
4726: $datatable .= '</td></tr>';
4727: $itemcount ++;
4728: } else {
4729: my %titles = &ssl_titles();
4730: my (%by_ip,%by_location,@intdoms,@instdoms);
4731: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4732: my @alldoms = &Apache::lonnet::all_domains();
4733: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4734: my @domservers = &Apache::lonnet::get_servers($dom);
4735: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4736: my %altids = &id_for_thisdom(%servers);
4737: if (($position eq 'connto') || ($position eq 'connfrom')) {
4738: my $legacy;
4739: unless (ref($settings) eq 'HASH') {
4740: my $name;
4741: if ($position eq 'connto') {
4742: $name = 'loncAllowInsecure';
4743: } else {
4744: $name = 'londAllowInsecure';
4745: }
4746: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4747: my @ids=&Apache::lonnet::current_machine_ids();
4748: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4749: my %what = (
4750: $name => 1,
4751: );
4752: my ($result,$returnhash) =
4753: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4754: if ($result eq 'ok') {
4755: if (ref($returnhash) eq 'HASH') {
4756: $legacy = $returnhash->{$name};
4757: }
4758: }
4759: } else {
4760: $legacy = $Apache::lonnet::perlvar{$name};
4761: }
4762: }
4763: foreach my $type ('dom','intdom','other') {
4764: my %checked;
4765: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4766: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4767: '<td class="LC_right_item">';
4768: my $skip;
4769: if ($type eq 'dom') {
4770: unless (keys(%servers) > 1) {
4771: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4772: $skip = 1;
4773: }
4774: }
4775: if ($type eq 'intdom') {
4776: unless (@instdoms > 1) {
4777: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4778: $skip = 1;
4779: }
4780: } elsif ($type eq 'other') {
4781: if (keys(%by_location) == 0) {
4782: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4783: $skip = 1;
4784: }
4785: }
4786: unless ($skip) {
4787: $checked{'yes'} = ' checked="checked"';
4788: if (ref($settings) eq 'HASH') {
4789: if (ref($settings->{$position}) eq 'HASH') {
4790: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
4791: $checked{$1} = $checked{'yes'};
4792: delete($checked{'yes'});
4793: }
4794: }
4795: } else {
4796: if ($legacy == 0) {
4797: $checked{'req'} = $checked{'yes'};
4798: delete($checked{'yes'});
4799: }
4800: }
4801: foreach my $option ('no','yes','req') {
4802: $datatable .= '<span class="LC_nobreak"><label>'.
4803: '<input type="radio" name="'.$position.'_'.$type.'" '.
4804: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4805: '</label></span>'.(' 'x2);
4806: }
4807: }
4808: $datatable .= '</td></tr>';
4809: $itemcount ++;
4810: }
4811: } else {
4812: my $prefix = 'replication';
4813: my @types = ('certreq','nocertreq');
4814: if (keys(%by_location) == 0) {
4815: $datatable .= '<tr'.$css_class.'><td>'.
4816: &mt('Nothing to set here, as there are no other institutions').
4817: '</td></tr>';
4818: $itemcount ++;
4819: } else {
4820: ($datatable,$itemcount) =
4821: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4822: }
4823: }
4824: }
4825: $$rowtotal += $itemcount;
4826: return $datatable;
4827: }
4828:
4829: sub ssl_titles {
4830: return &Apache::lonlocal::texthash (
4831: dom => 'LON-CAPA servers/VMs from same domain',
4832: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4833: other => 'External LON-CAPA servers/VMs',
4834: connto => 'Connections to other servers',
4835: connfrom => 'Connections from other servers',
4836: replication => 'Replicating content to other institutions',
4837: certreq => 'Client certificate required, but specific domains exempt',
4838: nocertreq => 'No client certificate required, except for specific domains',
4839: no => 'SSL not used',
4840: yes => 'SSL Optional (used if available)',
4841: req => 'SSL Required',
4842: );
4843: }
4844:
4845: sub print_trust {
4846: my ($prefix,$dom,$settings,$rowtotal) = @_;
4847: my ($css_class,$datatable,%checked,%choices);
4848: my (%by_ip,%by_location,@intdoms,@instdoms);
4849: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4850: my $itemcount = 1;
4851: my %titles = &trust_titles();
4852: my @types = ('exc','inc');
4853: if ($prefix eq 'top') {
4854: $prefix = 'content';
4855: } elsif ($prefix eq 'bottom') {
4856: $prefix = 'msg';
4857: }
4858: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4859: $$rowtotal += $itemcount;
4860: return $datatable;
4861: }
4862:
4863: sub trust_titles {
4864: return &Apache::lonlocal::texthash(
4865: content => "Access to this domain's content by others",
4866: shared => "Access to other domain's content by this domain",
4867: enroll => "Enrollment in this domain's courses by others",
4868: othcoau => "Co-author roles in this domain for others",
4869: coaurem => "Co-author roles for this domain's users elsewhere",
4870: domroles => "Domain roles in this domain assignable to others",
4871: catalog => "Course Catalog for this domain displayed elsewhere",
4872: reqcrs => "Requests for creation of courses in this domain by others",
4873: msg => "Users in other domains can send messages to this domain",
4874: exc => "Allow all, but exclude specific domains",
4875: inc => "Deny all, but include specific domains",
4876: );
4877: }
4878:
4879: sub build_location_hashes {
4880: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
4881: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4882: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
4883: my %iphost = &Apache::lonnet::get_iphost();
4884: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4885: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4886: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4887: foreach my $id (@{$iphost{$primary_ip}}) {
4888: my $intdom = &Apache::lonnet::internet_dom($id);
4889: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4890: push(@{$intdoms},$intdom);
4891: }
4892: }
4893: }
4894: foreach my $ip (keys(%iphost)) {
4895: if (ref($iphost{$ip}) eq 'ARRAY') {
4896: foreach my $id (@{$iphost{$ip}}) {
4897: my $location = &Apache::lonnet::internet_dom($id);
4898: if ($location) {
4899: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4900: my $dom = &Apache::lonnet::host_domain($id);
4901: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4902: push(@{$instdoms},$dom);
4903: }
4904: next;
4905: }
4906: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4907: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4908: push(@{$by_ip->{$ip}},$location);
4909: }
4910: } else {
4911: $by_ip->{$ip} = [$location];
4912: }
4913: }
4914: }
4915: }
4916: }
4917: foreach my $ip (sort(keys(%{$by_ip}))) {
4918: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4919: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4920: my $first = $by_ip->{$ip}->[0];
4921: if (ref($by_location->{$first}) eq 'ARRAY') {
4922: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4923: push(@{$by_location->{$first}},$ip);
4924: }
4925: } else {
4926: $by_location->{$first} = [$ip];
4927: }
4928: }
4929: }
4930: return;
4931: }
4932:
4933: sub current_offloads_to {
4934: my ($dom,$settings,$servers) = @_;
4935: my (%spareid,%otherdomconfigs);
4936: if (ref($servers) eq 'HASH') {
4937: foreach my $lonhost (sort(keys(%{$servers}))) {
4938: my $gotspares;
4939: if (ref($settings) eq 'HASH') {
4940: if (ref($settings->{'spares'}) eq 'HASH') {
4941: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4942: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4943: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4944: $gotspares = 1;
4945: }
4946: }
4947: }
4948: unless ($gotspares) {
4949: my $gotspares;
4950: my $serverhomeID =
4951: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4952: my $serverhomedom =
4953: &Apache::lonnet::host_domain($serverhomeID);
4954: if ($serverhomedom ne $dom) {
4955: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4956: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4957: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4958: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4959: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4960: $gotspares = 1;
4961: }
4962: }
4963: } else {
4964: $otherdomconfigs{$serverhomedom} =
4965: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4966: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4967: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4968: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4969: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4970: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4971: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4972: $gotspares = 1;
4973: }
4974: }
4975: }
4976: }
4977: }
4978: }
4979: }
4980: unless ($gotspares) {
4981: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4982: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4983: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4984: } else {
4985: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4986: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4987: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4988: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4989: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4990: } else {
4991: my %what = (
4992: spareid => 1,
4993: );
4994: my ($result,$returnhash) =
4995: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4996: if ($result eq 'ok') {
4997: if (ref($returnhash) eq 'HASH') {
4998: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4999: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5000: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5001: }
5002: }
5003: }
5004: }
5005: }
5006: }
5007: }
5008: }
5009: return %spareid;
5010: }
5011:
5012: sub spares_row {
5013: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
5014: my $css_class;
5015: my $numinrow = 4;
5016: my $itemcount = 1;
5017: my $datatable;
5018: my %typetitles = &sparestype_titles();
5019: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
5020: foreach my $server (sort(keys(%{$servers}))) {
5021: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5022: my ($othercontrol,$serverdom);
5023: if ($serverhome ne $server) {
5024: $serverdom = &Apache::lonnet::host_domain($serverhome);
5025: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5026: } else {
5027: $serverdom = &Apache::lonnet::host_domain($server);
5028: if ($serverdom ne $dom) {
5029: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5030: }
5031: }
5032: next unless (ref($spareid->{$server}) eq 'HASH');
5033: my $checkednow;
5034: if (ref($curroffloadnow) eq 'HASH') {
5035: if ($curroffloadnow->{$server}) {
5036: $checkednow = ' checked="checked"';
5037: }
5038: }
5039: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5040: $datatable .= '<tr'.$css_class.'>
5041: <td rowspan="2">
5042: <span class="LC_nobreak">'.
5043: &mt('[_1] when busy, offloads to:'
5044: ,'<b>'.$server.'</b>').'</span><br />'.
5045: '<span class="LC_nobreak">'."\n".
5046: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5047: ' '.&mt('Switch active users on next access').'</label></span>'.
5048: "\n";
5049: my (%current,%canselect);
5050: my @choices =
5051: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5052: foreach my $type ('primary','default') {
5053: if (ref($spareid->{$server}) eq 'HASH') {
5054: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5055: my @spares = @{$spareid->{$server}{$type}};
5056: if (@spares > 0) {
5057: if ($othercontrol) {
5058: $current{$type} = join(', ',@spares);
5059: } else {
5060: $current{$type} .= '<table>';
5061: my $numspares = scalar(@spares);
5062: for (my $i=0; $i<@spares; $i++) {
5063: my $rem = $i%($numinrow);
5064: if ($rem == 0) {
5065: if ($i > 0) {
5066: $current{$type} .= '</tr>';
5067: }
5068: $current{$type} .= '<tr>';
5069: }
5070: $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'".');" /> '.
5071: $spareid->{$server}{$type}[$i].
5072: '</label></td>'."\n";
5073: }
5074: my $rem = @spares%($numinrow);
5075: my $colsleft = $numinrow - $rem;
5076: if ($colsleft > 1 ) {
5077: $current{$type} .= '<td colspan="'.$colsleft.
5078: '" class="LC_left_item">'.
5079: ' </td>';
5080: } elsif ($colsleft == 1) {
5081: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
5082: }
5083: $current{$type} .= '</tr></table>';
5084: }
5085: }
5086: }
5087: if ($current{$type} eq '') {
5088: $current{$type} = &mt('None specified');
5089: }
5090: if ($othercontrol) {
5091: if ($type eq 'primary') {
5092: $canselect{$type} = $othercontrol;
5093: }
5094: } else {
5095: $canselect{$type} =
5096: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5097: '<select name="newspare_'.$type.'_'.$server.'" '.
5098: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5099: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5100: if (@choices > 0) {
5101: foreach my $lonhost (@choices) {
5102: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5103: }
5104: }
5105: $canselect{$type} .= '</select>'."\n";
5106: }
5107: } else {
5108: $current{$type} = &mt('Could not be determined');
5109: if ($type eq 'primary') {
5110: $canselect{$type} = $othercontrol;
5111: }
5112: }
5113: if ($type eq 'default') {
5114: $datatable .= '<tr'.$css_class.'>';
5115: }
5116: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5117: '<td>'.$current{$type}.'</td>'."\n".
5118: '<td>'.$canselect{$type}.'</td></tr>'."\n";
5119: }
5120: $itemcount ++;
5121: }
5122: }
5123: $$rowtotal += $itemcount;
5124: return $datatable;
5125: }
5126:
5127: sub possible_newspares {
5128: my ($server,$currspares,$serverhomes,$altids) = @_;
5129: my $serverhostname = &Apache::lonnet::hostname($server);
5130: my %excluded;
5131: if ($serverhostname ne '') {
5132: %excluded = (
5133: $serverhostname => 1,
5134: );
5135: }
5136: if (ref($currspares) eq 'HASH') {
5137: foreach my $type (keys(%{$currspares})) {
5138: if (ref($currspares->{$type}) eq 'ARRAY') {
5139: if (@{$currspares->{$type}} > 0) {
5140: foreach my $curr (@{$currspares->{$type}}) {
5141: my $hostname = &Apache::lonnet::hostname($curr);
5142: $excluded{$hostname} = 1;
5143: }
5144: }
5145: }
5146: }
5147: }
5148: my @choices;
5149: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5150: if (keys(%{$serverhomes}) > 1) {
5151: foreach my $name (sort(keys(%{$serverhomes}))) {
5152: unless ($excluded{$name}) {
5153: if (exists($altids->{$serverhomes->{$name}})) {
5154: push(@choices,$altids->{$serverhomes->{$name}});
5155: } else {
5156: push(@choices,$serverhomes->{$name});
5157: }
5158: }
5159: }
5160: }
5161: }
5162: return sort(@choices);
5163: }
5164:
5165: sub print_loadbalancing {
5166: my ($dom,$settings,$rowtotal) = @_;
5167: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5168: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5169: my $numinrow = 1;
5170: my $datatable;
5171: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5172: my (%currbalancer,%currtargets,%currrules,%existing);
5173: if (ref($settings) eq 'HASH') {
5174: %existing = %{$settings};
5175: }
5176: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5177: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5178: \%currtargets,\%currrules);
5179: } else {
5180: return;
5181: }
5182: my ($othertitle,$usertypes,$types) =
5183: &Apache::loncommon::sorted_inst_types($dom);
5184: my $rownum = 8;
5185: if (ref($types) eq 'ARRAY') {
5186: $rownum += scalar(@{$types});
5187: }
5188: my @css_class = ('LC_odd_row','LC_even_row');
5189: my $balnum = 0;
5190: my $islast;
5191: my (@toshow,$disabledtext);
5192: if (keys(%currbalancer) > 0) {
5193: @toshow = sort(keys(%currbalancer));
5194: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5195: push(@toshow,'');
5196: }
5197: } else {
5198: @toshow = ('');
5199: $disabledtext = &mt('No existing load balancer');
5200: }
5201: foreach my $lonhost (@toshow) {
5202: if ($balnum == scalar(@toshow)-1) {
5203: $islast = 1;
5204: } else {
5205: $islast = 0;
5206: }
5207: my $cssidx = $balnum%2;
5208: my $targets_div_style = 'display: none';
5209: my $disabled_div_style = 'display: block';
5210: my $homedom_div_style = 'display: none';
5211: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5212: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
5213: '<p>';
5214: if ($lonhost eq '') {
5215: $datatable .= '<span class="LC_nobreak">';
5216: if (keys(%currbalancer) > 0) {
5217: $datatable .= &mt('Add balancer:');
5218: } else {
5219: $datatable .= &mt('Enable balancer:');
5220: }
5221: $datatable .= ' '.
5222: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5223: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5224: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5225: '<option value="" selected="selected">'.&mt('None').
5226: '</option>'."\n";
5227: foreach my $server (sort(keys(%servers))) {
5228: next if ($currbalancer{$server});
5229: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5230: }
5231: $datatable .=
5232: '</select>'."\n".
5233: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5234: } else {
5235: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5236: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5237: &mt('Stop balancing').'</label>'.
5238: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5239: $targets_div_style = 'display: block';
5240: $disabled_div_style = 'display: none';
5241: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5242: $homedom_div_style = 'display: block';
5243: }
5244: }
5245: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
5246: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5247: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5248: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5249: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5250: my @sparestypes = ('primary','default');
5251: my %typetitles = &sparestype_titles();
5252: my %hostherechecked = (
5253: no => ' checked="checked"',
5254: );
5255: foreach my $sparetype (@sparestypes) {
5256: my $targettable;
5257: for (my $i=0; $i<$numspares; $i++) {
5258: my $checked;
5259: if (ref($currtargets{$lonhost}) eq 'HASH') {
5260: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5261: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5262: $checked = ' checked="checked"';
5263: }
5264: }
5265: }
5266: my ($chkboxval,$disabled);
5267: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5268: $chkboxval = $spares[$i];
5269: }
5270: if (exists($currbalancer{$spares[$i]})) {
5271: $disabled = ' disabled="disabled"';
5272: }
5273: $targettable .=
5274: '<td><span class="LC_nobreak"><label>'.
5275: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
5276: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
5277: '</span></label></span></td>';
5278: my $rem = $i%($numinrow);
5279: if ($rem == 0) {
5280: if (($i > 0) && ($i < $numspares-1)) {
5281: $targettable .= '</tr>';
5282: }
5283: if ($i < $numspares-1) {
5284: $targettable .= '<tr>';
5285: }
5286: }
5287: }
5288: if ($targettable ne '') {
5289: my $rem = $numspares%($numinrow);
5290: my $colsleft = $numinrow - $rem;
5291: if ($colsleft > 1 ) {
5292: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5293: ' </td>';
5294: } elsif ($colsleft == 1) {
5295: $targettable .= '<td class="LC_left_item"> </td>';
5296: }
5297: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5298: '<table><tr>'.$targettable.'</tr></table><br />';
5299: }
5300: $hostherechecked{$sparetype} = '';
5301: if (ref($currtargets{$lonhost}) eq 'HASH') {
5302: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5303: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5304: $hostherechecked{$sparetype} = ' checked="checked"';
5305: $hostherechecked{'no'} = '';
5306: }
5307: }
5308: }
5309: }
5310: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5311: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5312: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5313: foreach my $sparetype (@sparestypes) {
5314: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5315: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5316: '</i></label><br />';
5317: }
5318: $datatable .= '</div></td></tr>'.
5319: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5320: $othertitle,$usertypes,$types,\%servers,
5321: \%currbalancer,$lonhost,
5322: $targets_div_style,$homedom_div_style,
5323: $css_class[$cssidx],$balnum,$islast);
5324: $$rowtotal += $rownum;
5325: $balnum ++;
5326: }
5327: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5328: return $datatable;
5329: }
5330:
5331: sub get_loadbalancers_config {
5332: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5333: return unless ((ref($servers) eq 'HASH') &&
5334: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5335: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5336: if (keys(%{$existing}) > 0) {
5337: my $oldlonhost;
5338: foreach my $key (sort(keys(%{$existing}))) {
5339: if ($key eq 'lonhost') {
5340: $oldlonhost = $existing->{'lonhost'};
5341: $currbalancer->{$oldlonhost} = 1;
5342: } elsif ($key eq 'targets') {
5343: if ($oldlonhost) {
5344: $currtargets->{$oldlonhost} = $existing->{'targets'};
5345: }
5346: } elsif ($key eq 'rules') {
5347: if ($oldlonhost) {
5348: $currrules->{$oldlonhost} = $existing->{'rules'};
5349: }
5350: } elsif (ref($existing->{$key}) eq 'HASH') {
5351: $currbalancer->{$key} = 1;
5352: $currtargets->{$key} = $existing->{$key}{'targets'};
5353: $currrules->{$key} = $existing->{$key}{'rules'};
5354: }
5355: }
5356: } else {
5357: my ($balancerref,$targetsref) =
5358: &Apache::lonnet::get_lonbalancer_config($servers);
5359: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5360: foreach my $server (sort(keys(%{$balancerref}))) {
5361: $currbalancer->{$server} = 1;
5362: $currtargets->{$server} = $targetsref->{$server};
5363: }
5364: }
5365: }
5366: return;
5367: }
5368:
5369: sub loadbalancing_rules {
5370: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
5371: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5372: $css_class,$balnum,$islast) = @_;
5373: my $output;
5374: my $num = 0;
5375: my ($alltypes,$othertypes,$titles) =
5376: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5377: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5378: foreach my $type (@{$alltypes}) {
5379: $num ++;
5380: my $current;
5381: if (ref($currrules) eq 'HASH') {
5382: $current = $currrules->{$type};
5383: }
5384: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
5385: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
5386: $current = '';
5387: }
5388: }
5389: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
5390: $servers,$currbalancer,$lonhost,$dom,
5391: $targets_div_style,$homedom_div_style,
5392: $css_class,$balnum,$num,$islast);
5393: }
5394: }
5395: return $output;
5396: }
5397:
5398: sub loadbalancing_titles {
5399: my ($dom,$intdom,$usertypes,$types) = @_;
5400: my %othertypes = (
5401: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5402: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5403: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5404: '_LC_external' => &mt('Users not from [_1]',$intdom),
5405: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5406: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
5407: );
5408: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
5409: my @available;
5410: if (ref($types) eq 'ARRAY') {
5411: @available = @{$types};
5412: }
5413: unless (grep(/^default$/,@available)) {
5414: push(@available,'default');
5415: }
5416: unshift(@alltypes,@available);
5417: my %titles;
5418: foreach my $type (@alltypes) {
5419: if ($type =~ /^_LC_/) {
5420: $titles{$type} = $othertypes{$type};
5421: } elsif ($type eq 'default') {
5422: $titles{$type} = &mt('All users from [_1]',$dom);
5423: if (ref($types) eq 'ARRAY') {
5424: if (@{$types} > 0) {
5425: $titles{$type} = &mt('Other users from [_1]',$dom);
5426: }
5427: }
5428: } elsif (ref($usertypes) eq 'HASH') {
5429: $titles{$type} = $usertypes->{$type};
5430: }
5431: }
5432: return (\@alltypes,\%othertypes,\%titles);
5433: }
5434:
5435: sub loadbalance_rule_row {
5436: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5437: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
5438: my @rulenames;
5439: my %ruletitles = &offloadtype_text();
5440: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
5441: @rulenames = ('balancer','offloadedto','specific');
5442: } else {
5443: @rulenames = ('default','homeserver');
5444: if ($type eq '_LC_external') {
5445: push(@rulenames,'externalbalancer');
5446: } else {
5447: push(@rulenames,'specific');
5448: }
5449: push(@rulenames,'none');
5450: }
5451: my $style = $targets_div_style;
5452: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
5453: $style = $homedom_div_style;
5454: }
5455: my $space;
5456: if ($islast && $num == 1) {
5457: $space = '<div display="inline-block"> </div>';
5458: }
5459: my $output =
5460: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
5461: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5462: '<td valaign="top">'.$space.
5463: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
5464: for (my $i=0; $i<@rulenames; $i++) {
5465: my $rule = $rulenames[$i];
5466: my ($checked,$extra);
5467: if ($rulenames[$i] eq 'default') {
5468: $rule = '';
5469: }
5470: if ($rulenames[$i] eq 'specific') {
5471: if (ref($servers) eq 'HASH') {
5472: my $default;
5473: if (($current ne '') && (exists($servers->{$current}))) {
5474: $checked = ' checked="checked"';
5475: }
5476: unless ($checked) {
5477: $default = ' selected="selected"';
5478: }
5479: $extra =
5480: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5481: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5482: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5483: '<option value=""'.$default.'></option>'."\n";
5484: foreach my $server (sort(keys(%{$servers}))) {
5485: if (ref($currbalancer) eq 'HASH') {
5486: next if (exists($currbalancer->{$server}));
5487: }
5488: my $selected;
5489: if ($server eq $current) {
5490: $selected = ' selected="selected"';
5491: }
5492: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
5493: }
5494: $extra .= '</select>';
5495: }
5496: } elsif ($rule eq $current) {
5497: $checked = ' checked="checked"';
5498: }
5499: $output .= '<span class="LC_nobreak"><label>'.
5500: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5501: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5502: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
5503: ')"'.$checked.' /> ';
5504: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5505: $output .= $ruletitles{'particular'};
5506: } else {
5507: $output .= $ruletitles{$rulenames[$i]};
5508: }
5509: $output .= '</label>'.$extra.'</span><br />'."\n";
5510: }
5511: $output .= '</div></td></tr>'."\n";
5512: return $output;
5513: }
5514:
5515: sub offloadtype_text {
5516: my %ruletitles = &Apache::lonlocal::texthash (
5517: 'default' => 'Offloads to default destinations',
5518: 'homeserver' => "Offloads to user's home server",
5519: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5520: 'specific' => 'Offloads to specific server',
5521: 'none' => 'No offload',
5522: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5523: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
5524: 'particular' => 'Session hosted (after re-auth) on server:',
5525: );
5526: return %ruletitles;
5527: }
5528:
5529: sub sparestype_titles {
5530: my %typestitles = &Apache::lonlocal::texthash (
5531: 'primary' => 'primary',
5532: 'default' => 'default',
5533: );
5534: return %typestitles;
5535: }
5536:
5537: sub contact_titles {
5538: my %titles = &Apache::lonlocal::texthash (
5539: 'supportemail' => 'Support E-mail address',
5540: 'adminemail' => 'Default Server Admin E-mail address',
5541: 'errormail' => 'Error reports to be e-mailed to',
5542: 'packagesmail' => 'Package update alerts to be e-mailed to',
5543: 'helpdeskmail' => "Helpdesk requests for this domain's users",
5544: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
5545: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5546: 'requestsmail' => 'E-mail from course requests requiring approval',
5547: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
5548: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
5549: );
5550: my %short_titles = &Apache::lonlocal::texthash (
5551: adminemail => 'Admin E-mail address',
5552: supportemail => 'Support E-mail',
5553: );
5554: return (\%titles,\%short_titles);
5555: }
5556:
5557: sub helpform_fields {
5558: my %titles = &Apache::lonlocal::texthash (
5559: 'username' => 'Name',
5560: 'user' => 'Username/domain',
5561: 'phone' => 'Phone',
5562: 'cc' => 'Cc e-mail',
5563: 'course' => 'Course Details',
5564: 'section' => 'Sections',
5565: 'screenshot' => 'File upload',
5566: );
5567: my @fields = ('username','phone','user','course','section','cc','screenshot');
5568: my %possoptions = (
5569: username => ['yes','no','req'],
5570: phone => ['yes','no','req'],
5571: user => ['yes','no'],
5572: cc => ['yes','no'],
5573: course => ['yes','no'],
5574: section => ['yes','no'],
5575: screenshot => ['yes','no'],
5576: );
5577: my %fieldoptions = &Apache::lonlocal::texthash (
5578: 'yes' => 'Optional',
5579: 'req' => 'Required',
5580: 'no' => "Not shown",
5581: );
5582: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5583: }
5584:
5585: sub tool_titles {
5586: my %titles = &Apache::lonlocal::texthash (
5587: aboutme => 'Personal web page',
5588: blog => 'Blog',
5589: webdav => 'WebDAV',
5590: portfolio => 'Portfolio',
5591: official => 'Official courses (with institutional codes)',
5592: unofficial => 'Unofficial courses',
5593: community => 'Communities',
5594: textbook => 'Textbook courses',
5595: placement => 'Placement tests',
5596: );
5597: return %titles;
5598: }
5599:
5600: sub courserequest_titles {
5601: my %titles = &Apache::lonlocal::texthash (
5602: official => 'Official',
5603: unofficial => 'Unofficial',
5604: community => 'Communities',
5605: textbook => 'Textbook',
5606: placement => 'Placement tests',
5607: norequest => 'Not allowed',
5608: approval => 'Approval by Dom. Coord.',
5609: validate => 'With validation',
5610: autolimit => 'Numerical limit',
5611: unlimited => '(blank for unlimited)',
5612: );
5613: return %titles;
5614: }
5615:
5616: sub authorrequest_titles {
5617: my %titles = &Apache::lonlocal::texthash (
5618: norequest => 'Not allowed',
5619: approval => 'Approval by Dom. Coord.',
5620: automatic => 'Automatic approval',
5621: );
5622: return %titles;
5623: }
5624:
5625: sub courserequest_conditions {
5626: my %conditions = &Apache::lonlocal::texthash (
5627: approval => '(Processing of request subject to approval by Domain Coordinator).',
5628: validate => '(Processing of request subject to institutional validation).',
5629: );
5630: return %conditions;
5631: }
5632:
5633:
5634: sub print_usercreation {
5635: my ($position,$dom,$settings,$rowtotal) = @_;
5636: my $numinrow = 4;
5637: my $datatable;
5638: if ($position eq 'top') {
5639: $$rowtotal ++;
5640: my $rowcount = 0;
5641: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
5642: if (ref($rules) eq 'HASH') {
5643: if (keys(%{$rules}) > 0) {
5644: $datatable .= &user_formats_row('username',$settings,$rules,
5645: $ruleorder,$numinrow,$rowcount);
5646: $$rowtotal ++;
5647: $rowcount ++;
5648: }
5649: }
5650: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5651: if (ref($idrules) eq 'HASH') {
5652: if (keys(%{$idrules}) > 0) {
5653: $datatable .= &user_formats_row('id',$settings,$idrules,
5654: $idruleorder,$numinrow,$rowcount);
5655: $$rowtotal ++;
5656: $rowcount ++;
5657: }
5658: }
5659: if ($rowcount == 0) {
5660: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5661: $$rowtotal ++;
5662: $rowcount ++;
5663: }
5664: } elsif ($position eq 'middle') {
5665: my @creators = ('author','course','requestcrs');
5666: my ($rules,$ruleorder) =
5667: &Apache::lonnet::inst_userrules($dom,'username');
5668: my %lt = &usercreation_types();
5669: my %checked;
5670: if (ref($settings) eq 'HASH') {
5671: if (ref($settings->{'cancreate'}) eq 'HASH') {
5672: foreach my $item (@creators) {
5673: $checked{$item} = $settings->{'cancreate'}{$item};
5674: }
5675: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5676: foreach my $item (@creators) {
5677: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5678: $checked{$item} = 'none';
5679: }
5680: }
5681: }
5682: }
5683: my $rownum = 0;
5684: foreach my $item (@creators) {
5685: $rownum ++;
5686: if ($checked{$item} eq '') {
5687: $checked{$item} = 'any';
5688: }
5689: my $css_class;
5690: if ($rownum%2) {
5691: $css_class = '';
5692: } else {
5693: $css_class = ' class="LC_odd_row" ';
5694: }
5695: $datatable .= '<tr'.$css_class.'>'.
5696: '<td><span class="LC_nobreak">'.$lt{$item}.
5697: '</span></td><td style="text-align: right">';
5698: my @options = ('any');
5699: if (ref($rules) eq 'HASH') {
5700: if (keys(%{$rules}) > 0) {
5701: push(@options,('official','unofficial'));
5702: }
5703: }
5704: push(@options,'none');
5705: foreach my $option (@options) {
5706: my $type = 'radio';
5707: my $check = ' ';
5708: if ($checked{$item} eq $option) {
5709: $check = ' checked="checked" ';
5710: }
5711: $datatable .= '<span class="LC_nobreak"><label>'.
5712: '<input type="'.$type.'" name="can_createuser_'.
5713: $item.'" value="'.$option.'"'.$check.'/> '.
5714: $lt{$option}.'</label> </span>';
5715: }
5716: $datatable .= '</td></tr>';
5717: }
5718: } else {
5719: my @contexts = ('author','course','domain');
5720: my @authtypes = ('int','krb4','krb5','loc');
5721: my %checked;
5722: if (ref($settings) eq 'HASH') {
5723: if (ref($settings->{'authtypes'}) eq 'HASH') {
5724: foreach my $item (@contexts) {
5725: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5726: foreach my $auth (@authtypes) {
5727: if ($settings->{'authtypes'}{$item}{$auth}) {
5728: $checked{$item}{$auth} = ' checked="checked" ';
5729: }
5730: }
5731: }
5732: }
5733: }
5734: } else {
5735: foreach my $item (@contexts) {
5736: foreach my $auth (@authtypes) {
5737: $checked{$item}{$auth} = ' checked="checked" ';
5738: }
5739: }
5740: }
5741: my %title = &context_names();
5742: my %authname = &authtype_names();
5743: my $rownum = 0;
5744: my $css_class;
5745: foreach my $item (@contexts) {
5746: if ($rownum%2) {
5747: $css_class = '';
5748: } else {
5749: $css_class = ' class="LC_odd_row" ';
5750: }
5751: $datatable .= '<tr'.$css_class.'>'.
5752: '<td>'.$title{$item}.
5753: '</td><td class="LC_left_item">'.
5754: '<span class="LC_nobreak">';
5755: foreach my $auth (@authtypes) {
5756: $datatable .= '<label>'.
5757: '<input type="checkbox" name="'.$item.'_auth" '.
5758: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5759: $authname{$auth}.'</label> ';
5760: }
5761: $datatable .= '</span></td></tr>';
5762: $rownum ++;
5763: }
5764: $$rowtotal += $rownum;
5765: }
5766: return $datatable;
5767: }
5768:
5769: sub print_selfcreation {
5770: my ($position,$dom,$settings,$rowtotal) = @_;
5771: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5772: $emaildomain,$datatable);
5773: if (ref($settings) eq 'HASH') {
5774: if (ref($settings->{'cancreate'}) eq 'HASH') {
5775: $createsettings = $settings->{'cancreate'};
5776: if (ref($createsettings) eq 'HASH') {
5777: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5778: @selfcreate = @{$createsettings->{'selfcreate'}};
5779: } elsif ($createsettings->{'selfcreate'} ne '') {
5780: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5781: @selfcreate = ('email','login','sso');
5782: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5783: @selfcreate = ($createsettings->{'selfcreate'});
5784: }
5785: }
5786: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5787: $processing = $createsettings->{'selfcreateprocessing'};
5788: }
5789: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5790: $emailoptions = $createsettings->{'emailoptions'};
5791: }
5792: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5793: $emailverified = $createsettings->{'emailverified'};
5794: }
5795: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5796: $emaildomain = $createsettings->{'emaildomain'};
5797: }
5798: }
5799: }
5800: }
5801: my %radiohash;
5802: my $numinrow = 4;
5803: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5804: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5805: if ($position eq 'top') {
5806: my %choices = &Apache::lonlocal::texthash (
5807: cancreate_login => 'Institutional Login',
5808: cancreate_sso => 'Institutional Single Sign On',
5809: );
5810: my @toggles = sort(keys(%choices));
5811: my %defaultchecked = (
5812: 'cancreate_login' => 'off',
5813: 'cancreate_sso' => 'off',
5814: );
5815: my ($onclick,$itemcount);
5816: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5817: \%choices,$itemcount,$onclick);
5818: $$rowtotal += $itemcount;
5819:
5820: if (ref($usertypes) eq 'HASH') {
5821: if (keys(%{$usertypes}) > 0) {
5822: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5823: $dom,$numinrow,$othertitle,
5824: 'statustocreate',$rowtotal);
5825: $$rowtotal ++;
5826: }
5827: }
5828: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5829: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5830: $fieldtitles{'inststatus'} = &mt('Institutional status');
5831: my $rem;
5832: my $numperrow = 2;
5833: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5834: $datatable .= '<tr'.$css_class.'>'.
5835: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
5836: '<td class="LC_left_item">'."\n".
5837: '<table><tr><td>'."\n";
5838: for (my $i=0; $i<@fields; $i++) {
5839: $rem = $i%($numperrow);
5840: if ($rem == 0) {
5841: if ($i > 0) {
5842: $datatable .= '</tr>';
5843: }
5844: $datatable .= '<tr>';
5845: }
5846: my $currval;
5847: if (ref($createsettings) eq 'HASH') {
5848: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5849: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5850: }
5851: }
5852: $datatable .= '<td class="LC_left_item">'.
5853: '<span class="LC_nobreak">'.
5854: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5855: 'value="'.$currval.'" size="10" /> '.
5856: $fieldtitles{$fields[$i]}.'</span></td>';
5857: }
5858: my $colsleft = $numperrow - $rem;
5859: if ($colsleft > 1 ) {
5860: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5861: ' </td>';
5862: } elsif ($colsleft == 1) {
5863: $datatable .= '<td class="LC_left_item"> </td>';
5864: }
5865: $datatable .= '</tr></table></td></tr>';
5866: $$rowtotal ++;
5867: } elsif ($position eq 'middle') {
5868: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5869: my @posstypes;
5870: if (ref($types) eq 'ARRAY') {
5871: @posstypes = @{$types};
5872: }
5873: unless (grep(/^default$/,@posstypes)) {
5874: push(@posstypes,'default');
5875: }
5876: my %usertypeshash;
5877: if (ref($usertypes) eq 'HASH') {
5878: %usertypeshash = %{$usertypes};
5879: }
5880: $usertypeshash{'default'} = $othertitle;
5881: foreach my $status (@posstypes) {
5882: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5883: $numinrow,$$rowtotal,\%usertypeshash);
5884: $$rowtotal ++;
5885: }
5886: } else {
5887: my %choices = &Apache::lonlocal::texthash (
5888: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
5889: );
5890: my @toggles = sort(keys(%choices));
5891: my %defaultchecked = (
5892: 'cancreate_email' => 'off',
5893: );
5894: my $customclass = 'LC_selfcreate_email';
5895: my $classprefix = 'LC_canmodify_emailusername_';
5896: my $optionsprefix = 'LC_options_emailusername_';
5897: my $display = 'none';
5898: my $rowstyle = 'display:none';
5899: if (grep(/^\Qemail\E$/,@selfcreate)) {
5900: $display = 'block';
5901: $rowstyle = 'display:table-row';
5902: }
5903: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5904: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5905: \%choices,$$rowtotal,$onclick);
5906: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5907: $rowstyle);
5908: $$rowtotal ++;
5909: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5910: $rowstyle);
5911: $$rowtotal ++;
5912: my (@ordered,@posstypes,%usertypeshash);
5913: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5914: my ($emailrules,$emailruleorder) =
5915: &Apache::lonnet::inst_userrules($dom,'email');
5916: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5917: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5918: if (ref($types) eq 'ARRAY') {
5919: @posstypes = @{$types};
5920: }
5921: if (@posstypes) {
5922: unless (grep(/^default$/,@posstypes)) {
5923: push(@posstypes,'default');
5924: }
5925: if (ref($usertypes) eq 'HASH') {
5926: %usertypeshash = %{$usertypes};
5927: }
5928: my $currassign;
5929: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5930: $currassign = {
5931: selfassign => $domdefaults{'inststatusguest'},
5932: };
5933: @ordered = @{$domdefaults{'inststatusguest'}};
5934: } else {
5935: $currassign = { selfassign => [] };
5936: }
5937: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5938: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5939: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5940: $numinrow,$othertitle,'selfassign',
5941: $rowtotal,$onclicktypes,$customclass,
5942: $rowstyle);
5943: $$rowtotal ++;
5944: $usertypeshash{'default'} = $othertitle;
5945: foreach my $status (@posstypes) {
5946: my $css_class;
5947: if ($$rowtotal%2) {
5948: $css_class = 'LC_odd_row ';
5949: }
5950: $css_class .= $customclass;
5951: my $rowid = $optionsprefix.$status;
5952: my $hidden = 1;
5953: my $currstyle = 'display:none';
5954: if (grep(/^\Q$status\E$/,@ordered)) {
5955: $currstyle = $rowstyle;
5956: $hidden = 0;
5957: }
5958: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5959: $emailrules,$emailruleorder,$settings,$status,$rowid,
5960: $usertypeshash{$status},$css_class,$currstyle,$intdom);
5961: unless ($hidden) {
5962: $$rowtotal ++;
5963: }
5964: }
5965: } else {
5966: my $css_class;
5967: if ($$rowtotal%2) {
5968: $css_class = 'LC_odd_row ';
5969: }
5970: $css_class .= $customclass;
5971: $usertypeshash{'default'} = $othertitle;
5972: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5973: $emailrules,$emailruleorder,$settings,'default','',
5974: $othertitle,$css_class,$rowstyle,$intdom);
5975: $$rowtotal ++;
5976: }
5977: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5978: $numinrow = 1;
5979: if (@posstypes) {
5980: foreach my $status (@posstypes) {
5981: my $rowid = $classprefix.$status;
5982: my $datarowstyle = 'display:none';
5983: if (grep(/^\Q$status\E$/,@ordered)) {
5984: $datarowstyle = $rowstyle;
5985: }
5986: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5987: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5988: $infotitles,$rowid,$customclass,$datarowstyle);
5989: unless ($datarowstyle eq 'display:none') {
5990: $$rowtotal ++;
5991: }
5992: }
5993: } else {
5994: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
5995: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5996: $infotitles,'',$customclass,$rowstyle);
5997: }
5998: }
5999: return $datatable;
6000: }
6001:
6002: sub selfcreate_javascript {
6003: return <<"ENDSCRIPT";
6004:
6005: <script type="text/javascript">
6006: // <![CDATA[
6007:
6008: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6009: var x = document.getElementsByClassName(target);
6010: var insttypes = 0;
6011: var insttypeRegExp = new RegExp(prefix);
6012: if ((x.length != undefined) && (x.length > 0)) {
6013: if (form.elements[radio].length != undefined) {
6014: for (var i=0; i<form.elements[radio].length; i++) {
6015: if (form.elements[radio][i].checked) {
6016: if (form.elements[radio][i].value == 1) {
6017: for (var j=0; j<x.length; j++) {
6018: if (x[j].id == 'undefined') {
6019: x[j].style.display = 'table-row';
6020: } else if (insttypeRegExp.test(x[j].id)) {
6021: insttypes ++;
6022: } else {
6023: x[j].style.display = 'table-row';
6024: }
6025: }
6026: } else {
6027: for (var j=0; j<x.length; j++) {
6028: x[j].style.display = 'none';
6029: }
6030: }
6031: break;
6032: }
6033: }
6034: if (insttypes > 0) {
6035: toggleDataRow(form,checkbox,target,altprefix);
6036: toggleDataRow(form,checkbox,target,prefix,1);
6037: }
6038: }
6039: }
6040: return;
6041: }
6042:
6043: function toggleDataRow(form,checkbox,target,prefix,docount) {
6044: if (form.elements[checkbox].length != undefined) {
6045: var count = 0;
6046: if (docount) {
6047: for (var i=0; i<form.elements[checkbox].length; i++) {
6048: if (form.elements[checkbox][i].checked) {
6049: count ++;
6050: }
6051: }
6052: }
6053: for (var i=0; i<form.elements[checkbox].length; i++) {
6054: var type = form.elements[checkbox][i].value;
6055: if (document.getElementById(prefix+type)) {
6056: if (form.elements[checkbox][i].checked) {
6057: document.getElementById(prefix+type).style.display = 'table-row';
6058: if (count % 2 == 1) {
6059: document.getElementById(prefix+type).className = target+' LC_odd_row';
6060: } else {
6061: document.getElementById(prefix+type).className = target;
6062: }
6063: count ++;
6064: } else {
6065: document.getElementById(prefix+type).style.display = 'none';
6066: }
6067: }
6068: }
6069: }
6070: return;
6071: }
6072:
6073: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6074: var caller = radio+'_'+status;
6075: if (form.elements[caller].length != undefined) {
6076: for (var i=0; i<form.elements[caller].length; i++) {
6077: if (form.elements[caller][i].checked) {
6078: if (document.getElementById(altprefix+'_inst_'+status)) {
6079: var curr = form.elements[caller][i].value;
6080: if (prefix) {
6081: document.getElementById(prefix+'_'+status).style.display = 'none';
6082: }
6083: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6084: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6085: if (curr == 'custom') {
6086: if (prefix) {
6087: document.getElementById(prefix+'_'+status).style.display = 'inline';
6088: }
6089: } else if (curr == 'inst') {
6090: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6091: } else if (curr == 'noninst') {
6092: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
6093: }
6094: break;
6095: }
6096: }
6097: }
6098: }
6099: }
6100:
6101: // ]]>
6102: </script>
6103:
6104: ENDSCRIPT
6105: }
6106:
6107: sub noninst_users {
6108: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6109: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6110: my $class = 'LC_left_item';
6111: if ($css_class) {
6112: $css_class = ' class="'.$css_class.'"';
6113: }
6114: if ($rowid) {
6115: $rowid = ' id="'.$rowid.'"';
6116: }
6117: if ($rowstyle) {
6118: $rowstyle = ' style="'.$rowstyle.'"';
6119: }
6120: my ($output,$description);
6121: if ($type eq 'default') {
6122: $description = &mt('Requests for: [_1]',$typetitle);
6123: } else {
6124: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6125: }
6126: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6127: "<td>$description</td>\n".
6128: '<td class="'.$class.'" colspan="2">'.
6129: '<table><tr>';
6130: my %headers = &Apache::lonlocal::texthash(
6131: approve => 'Processing',
6132: email => 'E-mail',
6133: username => 'Username',
6134: );
6135: foreach my $item ('approve','email','username') {
6136: $output .= '<th>'.$headers{$item}.'</th>';
6137: }
6138: $output .= '</tr><tr>';
6139: foreach my $item ('approve','email','username') {
6140: $output .= '<td style="vertical-align: top">';
6141: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6142: if ($item eq 'approve') {
6143: %choices = &Apache::lonlocal::texthash (
6144: automatic => 'Automatically approved',
6145: approval => 'Queued for approval',
6146: );
6147: @options = ('automatic','approval');
6148: $hashref = $processing;
6149: $defoption = 'automatic';
6150: $name = 'cancreate_emailprocess_'.$type;
6151: } elsif ($item eq 'email') {
6152: %choices = &Apache::lonlocal::texthash (
6153: any => 'Any e-mail',
6154: inst => 'Institutional only',
6155: noninst => 'Non-institutional only',
6156: custom => 'Custom restrictions',
6157: );
6158: @options = ('any','inst','noninst');
6159: my $showcustom;
6160: if (ref($emailrules) eq 'HASH') {
6161: if (keys(%{$emailrules}) > 0) {
6162: push(@options,'custom');
6163: $showcustom = 'cancreate_emailrule';
6164: if (ref($settings) eq 'HASH') {
6165: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6166: foreach my $rule (@{$settings->{'email_rule'}}) {
6167: if (exists($emailrules->{$rule})) {
6168: $hascustom ++;
6169: }
6170: }
6171: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6172: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6173: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6174: if (exists($emailrules->{$rule})) {
6175: $hascustom ++;
6176: }
6177: }
6178: }
6179: }
6180: }
6181: }
6182: }
6183: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6184: "'cancreate_emaildomain','$type'".');"';
6185: $hashref = $emailoptions;
6186: $defoption = 'any';
6187: $name = 'cancreate_emailoptions_'.$type;
6188: } elsif ($item eq 'username') {
6189: %choices = &Apache::lonlocal::texthash (
6190: all => 'Same as e-mail',
6191: first => 'Omit @domain',
6192: free => 'Free to choose',
6193: );
6194: @options = ('all','first','free');
6195: $hashref = $emailverified;
6196: $defoption = 'all';
6197: $name = 'cancreate_usernameoptions_'.$type;
6198: }
6199: foreach my $option (@options) {
6200: my $checked;
6201: if (ref($hashref) eq 'HASH') {
6202: if ($type eq '') {
6203: if (!exists($hashref->{'default'})) {
6204: if ($option eq $defoption) {
6205: $checked = ' checked="checked"';
6206: }
6207: } else {
6208: if ($hashref->{'default'} eq $option) {
6209: $checked = ' checked="checked"';
6210: }
6211: }
6212: } else {
6213: if (!exists($hashref->{$type})) {
6214: if ($option eq $defoption) {
6215: $checked = ' checked="checked"';
6216: }
6217: } else {
6218: if ($hashref->{$type} eq $option) {
6219: $checked = ' checked="checked"';
6220: }
6221: }
6222: }
6223: } elsif (($item eq 'email') && ($hascustom)) {
6224: if ($option eq 'custom') {
6225: $checked = ' checked="checked"';
6226: }
6227: } elsif ($option eq $defoption) {
6228: $checked = ' checked="checked"';
6229: }
6230: $output .= '<span class="LC_nobreak"><label>'.
6231: '<input type="radio" name="'.$name.'"'.
6232: $checked.' value="'.$option.'"'.$onclick.' />'.
6233: $choices{$option}.'</label></span><br />';
6234: if ($item eq 'email') {
6235: if ($option eq 'custom') {
6236: my $id = 'cancreate_emailrule_'.$type;
6237: my $display = 'none';
6238: if ($checked) {
6239: $display = 'inline';
6240: }
6241: my $numinrow = 2;
6242: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6243: '<legend>'.&mt('Disallow').'</legend><table>'.
6244: &user_formats_row('email',$settings,$emailrules,
6245: $emailruleorder,$numinrow,'',$type);
6246: '</table></fieldset>';
6247: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6248: my %text = &Apache::lonlocal::texthash (
6249: inst => 'must end:',
6250: noninst => 'cannot end:',
6251: );
6252: my $value;
6253: if (ref($emaildomain) eq 'HASH') {
6254: if (ref($emaildomain->{$type}) eq 'HASH') {
6255: $value = $emaildomain->{$type}->{$option};
6256: }
6257: }
6258: if ($value eq '') {
6259: $value = '@'.$intdom;
6260: }
6261: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6262: my $display = 'none';
6263: if ($checked) {
6264: $display = 'inline';
6265: }
6266: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6267: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6268: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6269: '</div>';
6270: }
6271: }
6272: }
6273: $output .= '</td>'."\n";
6274: }
6275: $output .= "</tr></table></td></tr>\n";
6276: return $output;
6277: }
6278:
6279: sub captcha_choice {
6280: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
6281: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6282: $vertext,$currver);
6283: my %lt = &captcha_phrases();
6284: $keyentry = 'hidden';
6285: if ($context eq 'cancreate') {
6286: $rowname = &mt('CAPTCHA validation');
6287: } elsif ($context eq 'login') {
6288: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
6289: }
6290: if (ref($settings) eq 'HASH') {
6291: if ($settings->{'captcha'}) {
6292: $checked{$settings->{'captcha'}} = ' checked="checked"';
6293: } else {
6294: $checked{'original'} = ' checked="checked"';
6295: }
6296: if ($settings->{'captcha'} eq 'recaptcha') {
6297: $pubtext = $lt{'pub'};
6298: $privtext = $lt{'priv'};
6299: $keyentry = 'text';
6300: $vertext = $lt{'ver'};
6301: $currver = $settings->{'recaptchaversion'};
6302: if ($currver ne '2') {
6303: $currver = 1;
6304: }
6305: }
6306: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6307: $currpub = $settings->{'recaptchakeys'}{'public'};
6308: $currpriv = $settings->{'recaptchakeys'}{'private'};
6309: }
6310: } else {
6311: $checked{'original'} = ' checked="checked"';
6312: }
6313: my $css_class;
6314: if ($itemcount%2) {
6315: $css_class = 'LC_odd_row';
6316: }
6317: if ($customcss) {
6318: $css_class .= " $customcss";
6319: }
6320: $css_class =~ s/^\s+//;
6321: if ($css_class) {
6322: $css_class = ' class="'.$css_class.'"';
6323: }
6324: if ($rowstyle) {
6325: $css_class .= ' style="'.$rowstyle.'"';
6326: }
6327: my $output = '<tr'.$css_class.'>'.
6328: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
6329: '<table><tr><td>'."\n";
6330: foreach my $option ('original','recaptcha','notused') {
6331: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6332: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6333: $lt{$option}.'</label></span>';
6334: unless ($option eq 'notused') {
6335: $output .= (' 'x2)."\n";
6336: }
6337: }
6338: #
6339: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6340: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
6341: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
6342: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
6343: #
6344: $output .= '</td></tr>'."\n".
6345: '<tr><td class="LC_zero_height">'."\n".
6346: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6347: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6348: $currpub.'" size="40" /></span><br />'."\n".
6349: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6350: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
6351: $currpriv.'" size="40" /></span><br />'.
6352: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6353: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6354: $currver.'" size="3" /></span><br />'.
6355: '</td></tr></table>'."\n".
6356: '</td></tr>';
6357: return $output;
6358: }
6359:
6360: sub user_formats_row {
6361: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
6362: my $output;
6363: my %text = (
6364: 'username' => 'new usernames',
6365: 'id' => 'IDs',
6366: );
6367: unless ($type eq 'email') {
6368: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6369: $output = '<tr '.$css_class.'>'.
6370: '<td><span class="LC_nobreak">'.
6371: &mt("Format rules to check for $text{$type}: ").
6372: '</td><td class="LC_left_item" colspan="2"><table>';
6373: }
6374: my $rem;
6375: if (ref($ruleorder) eq 'ARRAY') {
6376: for (my $i=0; $i<@{$ruleorder}; $i++) {
6377: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6378: my $rem = $i%($numinrow);
6379: if ($rem == 0) {
6380: if ($i > 0) {
6381: $output .= '</tr>';
6382: }
6383: $output .= '<tr>';
6384: }
6385: my $check = ' ';
6386: if (ref($settings) eq 'HASH') {
6387: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6388: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6389: $check = ' checked="checked" ';
6390: }
6391: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6392: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6393: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6394: $check = ' checked="checked" ';
6395: }
6396: }
6397: }
6398: }
6399: my $name = $type.'_rule';
6400: if ($type eq 'email') {
6401: $name .= '_'.$status;
6402: }
6403: $output .= '<td class="LC_left_item">'.
6404: '<span class="LC_nobreak"><label>'.
6405: '<input type="checkbox" name="'.$name.'"'.
6406: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6407: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6408: }
6409: }
6410: $rem = @{$ruleorder}%($numinrow);
6411: }
6412: my $colsleft;
6413: if ($rem) {
6414: $colsleft = $numinrow - $rem;
6415: }
6416: if ($colsleft > 1 ) {
6417: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6418: ' </td>';
6419: } elsif ($colsleft == 1) {
6420: $output .= '<td class="LC_left_item"> </td>';
6421: }
6422: $output .= '</tr></table>';
6423: unless ($type eq 'email') {
6424: $output .= '</td></tr>';
6425: }
6426: return $output;
6427: }
6428:
6429: sub usercreation_types {
6430: my %lt = &Apache::lonlocal::texthash (
6431: author => 'When adding a co-author',
6432: course => 'When adding a user to a course',
6433: requestcrs => 'When requesting a course',
6434: any => 'Any',
6435: official => 'Institutional only ',
6436: unofficial => 'Non-institutional only',
6437: none => 'None',
6438: );
6439: return %lt;
6440: }
6441:
6442: sub selfcreation_types {
6443: my %lt = &Apache::lonlocal::texthash (
6444: selfcreate => 'User creates own account',
6445: any => 'Any',
6446: official => 'Institutional only ',
6447: unofficial => 'Non-institutional only',
6448: email => 'E-mail address',
6449: login => 'Institutional Login',
6450: sso => 'SSO',
6451: );
6452: }
6453:
6454: sub authtype_names {
6455: my %lt = &Apache::lonlocal::texthash(
6456: int => 'Internal',
6457: krb4 => 'Kerberos 4',
6458: krb5 => 'Kerberos 5',
6459: loc => 'Local',
6460: );
6461: return %lt;
6462: }
6463:
6464: sub context_names {
6465: my %context_title = &Apache::lonlocal::texthash(
6466: author => 'Creating users when an Author',
6467: course => 'Creating users when in a course',
6468: domain => 'Creating users when a Domain Coordinator',
6469: );
6470: return %context_title;
6471: }
6472:
6473: sub print_usermodification {
6474: my ($position,$dom,$settings,$rowtotal) = @_;
6475: my $numinrow = 4;
6476: my ($context,$datatable,$rowcount);
6477: if ($position eq 'top') {
6478: $rowcount = 0;
6479: $context = 'author';
6480: foreach my $role ('ca','aa') {
6481: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6482: $numinrow,$rowcount);
6483: $$rowtotal ++;
6484: $rowcount ++;
6485: }
6486: } elsif ($position eq 'bottom') {
6487: $context = 'course';
6488: $rowcount = 0;
6489: foreach my $role ('st','ep','ta','in','cr') {
6490: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6491: $numinrow,$rowcount);
6492: $$rowtotal ++;
6493: $rowcount ++;
6494: }
6495: }
6496: return $datatable;
6497: }
6498:
6499: sub print_defaults {
6500: my ($position,$dom,$settings,$rowtotal) = @_;
6501: my $rownum = 0;
6502: my ($datatable,$css_class,$titles);
6503: unless ($position eq 'bottom') {
6504: $titles = &defaults_titles($dom);
6505: }
6506: if ($position eq 'top') {
6507: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6508: 'datelocale_def','portal_def');
6509: my %defaults;
6510: if (ref($settings) eq 'HASH') {
6511: %defaults = %{$settings};
6512: } else {
6513: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6514: foreach my $item (@items) {
6515: $defaults{$item} = $domdefaults{$item};
6516: }
6517: }
6518: foreach my $item (@items) {
6519: if ($rownum%2) {
6520: $css_class = '';
6521: } else {
6522: $css_class = ' class="LC_odd_row" ';
6523: }
6524: $datatable .= '<tr'.$css_class.'>'.
6525: '<td><span class="LC_nobreak">'.$titles->{$item}.
6526: '</span></td><td class="LC_right_item" colspan="3">';
6527: if ($item eq 'auth_def') {
6528: my @authtypes = ('internal','krb4','krb5','localauth');
6529: my %shortauth = (
6530: internal => 'int',
6531: krb4 => 'krb4',
6532: krb5 => 'krb5',
6533: localauth => 'loc'
6534: );
6535: my %authnames = &authtype_names();
6536: foreach my $auth (@authtypes) {
6537: my $checked = ' ';
6538: if ($defaults{$item} eq $auth) {
6539: $checked = ' checked="checked" ';
6540: }
6541: $datatable .= '<label><input type="radio" name="'.$item.
6542: '" value="'.$auth.'"'.$checked.'/>'.
6543: $authnames{$shortauth{$auth}}.'</label> ';
6544: }
6545: } elsif ($item eq 'timezone_def') {
6546: my $includeempty = 1;
6547: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6548: } elsif ($item eq 'datelocale_def') {
6549: my $includeempty = 1;
6550: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6551: } elsif ($item eq 'lang_def') {
6552: my $includeempty = 1;
6553: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
6554: } else {
6555: my $size;
6556: if ($item eq 'portal_def') {
6557: $size = ' size="25"';
6558: }
6559: $datatable .= '<input type="text" name="'.$item.'" value="'.
6560: $defaults{$item}.'"'.$size.' />';
6561: }
6562: $datatable .= '</td></tr>';
6563: $rownum ++;
6564: }
6565: } elsif ($position eq 'middle') {
6566: my @items = ('intauth_cost','intauth_check','intauth_switch');
6567: my %defaults;
6568: if (ref($settings) eq 'HASH') {
6569: %defaults = %{$settings};
6570: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6571: $defaults{'intauth_cost'} = 10;
6572: }
6573: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6574: $defaults{'intauth_check'} = 0;
6575: }
6576: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6577: $defaults{'intauth_switch'} = 0;
6578: }
6579: } else {
6580: %defaults = (
6581: 'intauth_cost' => 10,
6582: 'intauth_check' => 0,
6583: 'intauth_switch' => 0,
6584: );
6585: }
6586: foreach my $item (@items) {
6587: if ($rownum%2) {
6588: $css_class = '';
6589: } else {
6590: $css_class = ' class="LC_odd_row" ';
6591: }
6592: $datatable .= '<tr'.$css_class.'>'.
6593: '<td><span class="LC_nobreak">'.$titles->{$item}.
6594: '</span></td><td class="LC_left_item" colspan="3">';
6595: if ($item eq 'intauth_switch') {
6596: my @options = (0,1,2);
6597: my %optiondesc = &Apache::lonlocal::texthash (
6598: 0 => 'No',
6599: 1 => 'Yes',
6600: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6601: );
6602: $datatable .= '<table width="100%">';
6603: foreach my $option (@options) {
6604: my $checked = ' ';
6605: if ($defaults{$item} eq $option) {
6606: $checked = ' checked="checked"';
6607: }
6608: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6609: '<label><input type="radio" name="'.$item.
6610: '" value="'.$option.'"'.$checked.' />'.
6611: $optiondesc{$option}.'</label></span></td></tr>';
6612: }
6613: $datatable .= '</table>';
6614: } elsif ($item eq 'intauth_check') {
6615: my @options = (0,1,2);
6616: my %optiondesc = &Apache::lonlocal::texthash (
6617: 0 => 'No',
6618: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6619: 2 => 'Yes, disallow login if stored cost is less than domain default',
6620: );
6621: $datatable .= '<table wisth="100%">';
6622: foreach my $option (@options) {
6623: my $checked = ' ';
6624: my $onclick;
6625: if ($defaults{$item} eq $option) {
6626: $checked = ' checked="checked"';
6627: }
6628: if ($option == 2) {
6629: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6630: }
6631: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6632: '<label><input type="radio" name="'.$item.
6633: '" value="'.$option.'"'.$checked.$onclick.' />'.
6634: $optiondesc{$option}.'</label></span></td></tr>';
6635: }
6636: $datatable .= '</table>';
6637: } else {
6638: $datatable .= '<input type="text" name="'.$item.'" value="'.
6639: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6640: }
6641: $datatable .= '</td></tr>';
6642: $rownum ++;
6643: }
6644: } else {
6645: my %defaults;
6646: if (ref($settings) eq 'HASH') {
6647: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6648: my $maxnum = @{$settings->{'inststatusorder'}};
6649: for (my $i=0; $i<$maxnum; $i++) {
6650: $css_class = $rownum%2?' class="LC_odd_row"':'';
6651: my $item = $settings->{'inststatusorder'}->[$i];
6652: my $title = $settings->{'inststatustypes'}->{$item};
6653: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6654: $datatable .= '<tr'.$css_class.'>'.
6655: '<td><span class="LC_nobreak">'.
6656: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6657: for (my $k=0; $k<=$maxnum; $k++) {
6658: my $vpos = $k+1;
6659: my $selstr;
6660: if ($k == $i) {
6661: $selstr = ' selected="selected" ';
6662: }
6663: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6664: }
6665: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6666: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6667: &mt('delete').'</span></td>'.
6668: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
6669: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6670: '</span></td></tr>';
6671: }
6672: $css_class = $rownum%2?' class="LC_odd_row"':'';
6673: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6674: $datatable .= '<tr '.$css_class.'>'.
6675: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6676: for (my $k=0; $k<=$maxnum; $k++) {
6677: my $vpos = $k+1;
6678: my $selstr;
6679: if ($k == $maxnum) {
6680: $selstr = ' selected="selected" ';
6681: }
6682: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6683: }
6684: $datatable .= '</select> '.&mt('Internal ID:').
6685: '<input type="text" size="10" name="addinststatus" value="" />'.
6686: ' '.&mt('(new)').
6687: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
6688: &mt('Name displayed:').
6689: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6690: '</tr>'."\n";
6691: $rownum ++;
6692: }
6693: }
6694: }
6695: $$rowtotal += $rownum;
6696: return $datatable;
6697: }
6698:
6699: sub get_languages_hash {
6700: my %langchoices;
6701: foreach my $id (&Apache::loncommon::languageids()) {
6702: my $code = &Apache::loncommon::supportedlanguagecode($id);
6703: if ($code ne '') {
6704: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6705: }
6706: }
6707: return %langchoices;
6708: }
6709:
6710: sub defaults_titles {
6711: my ($dom) = @_;
6712: my %titles = &Apache::lonlocal::texthash (
6713: 'auth_def' => 'Default authentication type',
6714: 'auth_arg_def' => 'Default authentication argument',
6715: 'lang_def' => 'Default language',
6716: 'timezone_def' => 'Default timezone',
6717: 'datelocale_def' => 'Default locale for dates',
6718: 'portal_def' => 'Portal/Default URL',
6719: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6720: 'intauth_check' => 'Check bcrypt cost if authenticated',
6721: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
6722: );
6723: if ($dom) {
6724: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6725: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6726: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6727: $protocol = 'http' if ($protocol ne 'https');
6728: if ($uint_dom) {
6729: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6730: $uint_dom);
6731: }
6732: }
6733: return (\%titles);
6734: }
6735:
6736: sub print_scantronformat {
6737: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6738: my $itemcount = 1;
6739: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6740: %confhash);
6741: my $switchserver = &check_switchserver($dom,$confname);
6742: my %lt = &Apache::lonlocal::texthash (
6743: default => 'Default bubblesheet format file error',
6744: custom => 'Custom bubblesheet format file error',
6745: );
6746: my %scantronfiles = (
6747: default => 'default.tab',
6748: custom => 'custom.tab',
6749: );
6750: foreach my $key (keys(%scantronfiles)) {
6751: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6752: .$scantronfiles{$key};
6753: }
6754: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6755: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6756: if (!$switchserver) {
6757: my $servadm = $r->dir_config('lonAdmEMail');
6758: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6759: if ($configuserok eq 'ok') {
6760: if ($author_ok eq 'ok') {
6761: my %legacyfile = (
6762: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6763: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6764: );
6765: my %md5chk;
6766: foreach my $type (keys(%legacyfile)) {
6767: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6768: chomp($md5chk{$type});
6769: }
6770: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6771: foreach my $type (keys(%legacyfile)) {
6772: ($scantronurls{$type},my $error) =
6773: &legacy_scantronformat($r,$dom,$confname,
6774: $type,$legacyfile{$type},
6775: $scantronurls{$type},
6776: $scantronfiles{$type});
6777: if ($error ne '') {
6778: $error{$type} = $error;
6779: }
6780: }
6781: if (keys(%error) == 0) {
6782: $is_custom = 1;
6783: $confhash{'scantron'}{'scantronformat'} =
6784: $scantronurls{'custom'};
6785: my $putresult =
6786: &Apache::lonnet::put_dom('configuration',
6787: \%confhash,$dom);
6788: if ($putresult ne 'ok') {
6789: $error{'custom'} =
6790: '<span class="LC_error">'.
6791: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6792: }
6793: }
6794: } else {
6795: ($scantronurls{'default'},my $error) =
6796: &legacy_scantronformat($r,$dom,$confname,
6797: 'default',$legacyfile{'default'},
6798: $scantronurls{'default'},
6799: $scantronfiles{'default'});
6800: if ($error eq '') {
6801: $confhash{'scantron'}{'scantronformat'} = '';
6802: my $putresult =
6803: &Apache::lonnet::put_dom('configuration',
6804: \%confhash,$dom);
6805: if ($putresult ne 'ok') {
6806: $error{'default'} =
6807: '<span class="LC_error">'.
6808: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6809: }
6810: } else {
6811: $error{'default'} = $error;
6812: }
6813: }
6814: }
6815: }
6816: } else {
6817: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
6818: }
6819: }
6820: if (ref($settings) eq 'HASH') {
6821: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6822: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6823: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6824: $scantronurl = '';
6825: } else {
6826: $scantronurl = $settings->{'scantronformat'};
6827: }
6828: $is_custom = 1;
6829: } else {
6830: $scantronurl = $scantronurls{'default'};
6831: }
6832: } else {
6833: if ($is_custom) {
6834: $scantronurl = $scantronurls{'custom'};
6835: } else {
6836: $scantronurl = $scantronurls{'default'};
6837: }
6838: }
6839: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6840: $datatable .= '<tr'.$css_class.'>';
6841: if (!$is_custom) {
6842: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6843: '<span class="LC_nobreak">';
6844: if ($scantronurl) {
6845: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6846: undef,undef,undef,undef,'background-color:#ffffff');
6847: } else {
6848: $datatable = &mt('File unavailable for display');
6849: }
6850: $datatable .= '</span></td>';
6851: if (keys(%error) == 0) {
6852: $datatable .= '<td style="vertical-align: bottom">';
6853: if (!$switchserver) {
6854: $datatable .= &mt('Upload:').'<br />';
6855: }
6856: } else {
6857: my $errorstr;
6858: foreach my $key (sort(keys(%error))) {
6859: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6860: }
6861: $datatable .= '<td>'.$errorstr;
6862: }
6863: } else {
6864: if (keys(%error) > 0) {
6865: my $errorstr;
6866: foreach my $key (sort(keys(%error))) {
6867: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6868: }
6869: $datatable .= '<td>'.$errorstr.'</td><td> ';
6870: } elsif ($scantronurl) {
6871: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6872: undef,undef,undef,undef,'background-color:#ffffff');
6873: $datatable .= '<td><span class="LC_nobreak">'.
6874: $link.
6875: '<label><input type="checkbox" name="scantronformat_del"'.
6876: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
6877: '<td><span class="LC_nobreak"> '.
6878: &mt('Replace:').'</span><br />';
6879: }
6880: }
6881: if (keys(%error) == 0) {
6882: if ($switchserver) {
6883: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6884: } else {
6885: $datatable .='<span class="LC_nobreak"> '.
6886: '<input type="file" name="scantronformat" /></span>';
6887: }
6888: }
6889: $datatable .= '</td></tr>';
6890: $$rowtotal ++;
6891: return $datatable;
6892: }
6893:
6894: sub legacy_scantronformat {
6895: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6896: my ($url,$error);
6897: my @statinfo = &Apache::lonnet::stat_file($newurl);
6898: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6899: (my $result,$url) =
6900: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6901: '','',$newfile);
6902: if ($result ne 'ok') {
6903: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
6904: }
6905: }
6906: return ($url,$error);
6907: }
6908:
6909: sub print_coursecategories {
6910: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6911: my $datatable;
6912: if ($position eq 'top') {
6913: my (%checked);
6914: my @catitems = ('unauth','auth');
6915: my @cattypes = ('std','domonly','codesrch','none');
6916: $checked{'unauth'} = 'std';
6917: $checked{'auth'} = 'std';
6918: if (ref($settings) eq 'HASH') {
6919: foreach my $type (@cattypes) {
6920: if ($type eq $settings->{'unauth'}) {
6921: $checked{'unauth'} = $type;
6922: }
6923: if ($type eq $settings->{'auth'}) {
6924: $checked{'auth'} = $type;
6925: }
6926: }
6927: }
6928: my %lt = &Apache::lonlocal::texthash (
6929: unauth => 'Catalog type for unauthenticated users',
6930: auth => 'Catalog type for authenticated users',
6931: none => 'No catalog',
6932: std => 'Standard catalog',
6933: domonly => 'Domain-only catalog',
6934: codesrch => "Code search form",
6935: );
6936: my $itemcount = 0;
6937: foreach my $item (@catitems) {
6938: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6939: $datatable .= '<tr '.$css_class.'>'.
6940: '<td>'.$lt{$item}.'</td>'.
6941: '<td class="LC_right_item"><span class="LC_nobreak">';
6942: foreach my $type (@cattypes) {
6943: my $ischecked;
6944: if ($checked{$item} eq $type) {
6945: $ischecked=' checked="checked"';
6946: }
6947: $datatable .= '<label>'.
6948: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6949: ' />'.$lt{$type}.'</label> ';
6950: }
6951: $datatable .= '</td></tr>';
6952: $itemcount ++;
6953: }
6954: $$rowtotal += $itemcount;
6955: } elsif ($position eq 'middle') {
6956: my $toggle_cats_crs = ' ';
6957: my $toggle_cats_dom = ' checked="checked" ';
6958: my $can_cat_crs = ' ';
6959: my $can_cat_dom = ' checked="checked" ';
6960: my $toggle_catscomm_comm = ' ';
6961: my $toggle_catscomm_dom = ' checked="checked" ';
6962: my $can_catcomm_comm = ' ';
6963: my $can_catcomm_dom = ' checked="checked" ';
6964: my $toggle_catsplace_place = ' ';
6965: my $toggle_catsplace_dom = ' checked="checked" ';
6966: my $can_catplace_place = ' ';
6967: my $can_catplace_dom = ' checked="checked" ';
6968:
6969: if (ref($settings) eq 'HASH') {
6970: if ($settings->{'togglecats'} eq 'crs') {
6971: $toggle_cats_crs = $toggle_cats_dom;
6972: $toggle_cats_dom = ' ';
6973: }
6974: if ($settings->{'categorize'} eq 'crs') {
6975: $can_cat_crs = $can_cat_dom;
6976: $can_cat_dom = ' ';
6977: }
6978: if ($settings->{'togglecatscomm'} eq 'comm') {
6979: $toggle_catscomm_comm = $toggle_catscomm_dom;
6980: $toggle_catscomm_dom = ' ';
6981: }
6982: if ($settings->{'categorizecomm'} eq 'comm') {
6983: $can_catcomm_comm = $can_catcomm_dom;
6984: $can_catcomm_dom = ' ';
6985: }
6986: if ($settings->{'togglecatsplace'} eq 'place') {
6987: $toggle_catsplace_place = $toggle_catsplace_dom;
6988: $toggle_catsplace_dom = ' ';
6989: }
6990: if ($settings->{'categorizeplace'} eq 'place') {
6991: $can_catplace_place = $can_catplace_dom;
6992: $can_catplace_dom = ' ';
6993: }
6994: }
6995: my %title = &Apache::lonlocal::texthash (
6996: togglecats => 'Show/Hide a course in catalog',
6997: togglecatscomm => 'Show/Hide a community in catalog',
6998: togglecatsplace => 'Show/Hide a placement test in catalog',
6999: categorize => 'Assign a category to a course',
7000: categorizecomm => 'Assign a category to a community',
7001: categorizeplace => 'Assign a category to a placement test',
7002: );
7003: my %level = &Apache::lonlocal::texthash (
7004: dom => 'Set in Domain',
7005: crs => 'Set in Course',
7006: comm => 'Set in Community',
7007: place => 'Set in Placement Test',
7008: );
7009: $datatable = '<tr class="LC_odd_row">'.
7010: '<td>'.$title{'togglecats'}.'</td>'.
7011: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7012: '<input type="radio" name="togglecats"'.
7013: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7014: '<label><input type="radio" name="togglecats"'.
7015: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7016: '</tr><tr>'.
7017: '<td>'.$title{'categorize'}.'</td>'.
7018: '<td class="LC_right_item"><span class="LC_nobreak">'.
7019: '<label><input type="radio" name="categorize"'.
7020: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7021: '<label><input type="radio" name="categorize"'.
7022: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
7023: '</tr><tr class="LC_odd_row">'.
7024: '<td>'.$title{'togglecatscomm'}.'</td>'.
7025: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7026: '<input type="radio" name="togglecatscomm"'.
7027: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7028: '<label><input type="radio" name="togglecatscomm"'.
7029: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7030: '</tr><tr>'.
7031: '<td>'.$title{'categorizecomm'}.'</td>'.
7032: '<td class="LC_right_item"><span class="LC_nobreak">'.
7033: '<label><input type="radio" name="categorizecomm"'.
7034: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7035: '<label><input type="radio" name="categorizecomm"'.
7036: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
7037: '</tr><tr>'.
7038: '<td>'.$title{'togglecatsplace'}.'</td>'.
7039: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7040: '<input type="radio" name="togglecatsplace"'.
7041: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7042: '<label><input type="radio" name="togglecatscomm"'.
7043: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
7044: '</tr><tr>'.
7045: '<td>'.$title{'categorizeplace'}.'</td>'.
7046: '<td class="LC_right_item"><span class="LC_nobreak">'.
7047: '<label><input type="radio" name="categorizeplace"'.
7048: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7049: '<label><input type="radio" name="categorizeplace"'.
7050: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
7051: '</tr>';
7052: $$rowtotal += 6;
7053: } else {
7054: my $css_class;
7055: my $itemcount = 1;
7056: my $cathash;
7057: if (ref($settings) eq 'HASH') {
7058: $cathash = $settings->{'cats'};
7059: }
7060: if (ref($cathash) eq 'HASH') {
7061: my (@cats,@trails,%allitems,%idx,@jsarray);
7062: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7063: \%allitems,\%idx,\@jsarray);
7064: my $maxdepth = scalar(@cats);
7065: my $colattrib = '';
7066: if ($maxdepth > 2) {
7067: $colattrib = ' colspan="2" ';
7068: }
7069: my @path;
7070: if (@cats > 0) {
7071: if (ref($cats[0]) eq 'ARRAY') {
7072: my $numtop = @{$cats[0]};
7073: my $maxnum = $numtop;
7074: my %default_names = (
7075: instcode => &mt('Official courses'),
7076: communities => &mt('Communities'),
7077: placement => &mt('Placement Tests'),
7078: );
7079:
7080: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7081: ($cathash->{'instcode::0'} eq '') ||
7082: (!grep(/^communities$/,@{$cats[0]})) ||
7083: ($cathash->{'communities::0'} eq '') ||
7084: (!grep(/^placement$/,@{$cats[0]})) ||
7085: ($cathash->{'placement::0'} eq '')) {
7086: $maxnum ++;
7087: }
7088: my $lastidx;
7089: for (my $i=0; $i<$numtop; $i++) {
7090: my $parent = $cats[0][$i];
7091: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7092: my $item = &escape($parent).'::0';
7093: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7094: $lastidx = $idx{$item};
7095: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7096: .'<select name="'.$item.'"'.$chgstr.'>';
7097: for (my $k=0; $k<=$maxnum; $k++) {
7098: my $vpos = $k+1;
7099: my $selstr;
7100: if ($k == $i) {
7101: $selstr = ' selected="selected" ';
7102: }
7103: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7104: }
7105: $datatable .= '</select></span></td><td>';
7106: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
7107: $datatable .= '<span class="LC_nobreak">'
7108: .$default_names{$parent}.'</span>';
7109: if ($parent eq 'instcode') {
7110: $datatable .= '<br /><span class="LC_nobreak">('
7111: .&mt('with institutional codes')
7112: .')</span></td><td'.$colattrib.'>';
7113: } else {
7114: $datatable .= '<table><tr><td>';
7115: }
7116: $datatable .= '<span class="LC_nobreak">'
7117: .'<label><input type="radio" name="'
7118: .$parent.'" value="1" checked="checked" />'
7119: .&mt('Display').'</label>';
7120: if ($parent eq 'instcode') {
7121: $datatable .= ' ';
7122: } else {
7123: $datatable .= '</span></td></tr><tr><td>'
7124: .'<span class="LC_nobreak">';
7125: }
7126: $datatable .= '<label><input type="radio" name="'
7127: .$parent.'" value="0" />'
7128: .&mt('Do not display').'</label></span>';
7129: if (($parent eq 'communities') || ($parent eq 'placement')) {
7130: $datatable .= '</td></tr></table>';
7131: }
7132: $datatable .= '</td>';
7133: } else {
7134: $datatable .= $parent
7135: .' <span class="LC_nobreak"><label>'
7136: .'<input type="checkbox" name="deletecategory" '
7137: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7138: }
7139: my $depth = 1;
7140: push(@path,$parent);
7141: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7142: pop(@path);
7143: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7144: $itemcount ++;
7145: }
7146: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7147: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7148: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
7149: for (my $k=0; $k<=$maxnum; $k++) {
7150: my $vpos = $k+1;
7151: my $selstr;
7152: if ($k == $numtop) {
7153: $selstr = ' selected="selected" ';
7154: }
7155: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7156: }
7157: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
7158: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7159: .'</tr>'."\n";
7160: $itemcount ++;
7161: foreach my $default ('instcode','communities','placement') {
7162: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7164: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7165: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7166: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7167: for (my $k=0; $k<=$maxnum; $k++) {
7168: my $vpos = $k+1;
7169: my $selstr;
7170: if ($k == $maxnum) {
7171: $selstr = ' selected="selected" ';
7172: }
7173: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7174: }
7175: $datatable .= '</select></span></td>'.
7176: '<td><span class="LC_nobreak">'.
7177: $default_names{$default}.'</span>';
7178: if ($default eq 'instcode') {
7179: $datatable .= '<br /><span class="LC_nobreak">('
7180: .&mt('with institutional codes').')</span>';
7181: }
7182: $datatable .= '</td>'
7183: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7184: .&mt('Display').'</label> '
7185: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7186: .&mt('Do not display').'</label></span></td></tr>';
7187: }
7188: }
7189: }
7190: } else {
7191: $datatable .= &initialize_categories($itemcount);
7192: }
7193: } else {
7194: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
7195: .&initialize_categories($itemcount);
7196: }
7197: $$rowtotal += $itemcount;
7198: }
7199: return $datatable;
7200: }
7201:
7202: sub print_serverstatuses {
7203: my ($dom,$settings,$rowtotal) = @_;
7204: my $datatable;
7205: my @pages = &serverstatus_pages();
7206: my (%namedaccess,%machineaccess);
7207: foreach my $type (@pages) {
7208: $namedaccess{$type} = '';
7209: $machineaccess{$type}= '';
7210: }
7211: if (ref($settings) eq 'HASH') {
7212: foreach my $type (@pages) {
7213: if (exists($settings->{$type})) {
7214: if (ref($settings->{$type}) eq 'HASH') {
7215: foreach my $key (keys(%{$settings->{$type}})) {
7216: if ($key eq 'namedusers') {
7217: $namedaccess{$type} = $settings->{$type}->{$key};
7218: } elsif ($key eq 'machines') {
7219: $machineaccess{$type} = $settings->{$type}->{$key};
7220: }
7221: }
7222: }
7223: }
7224: }
7225: }
7226: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
7227: my $rownum = 0;
7228: my $css_class;
7229: foreach my $type (@pages) {
7230: $rownum ++;
7231: $css_class = $rownum%2?' class="LC_odd_row"':'';
7232: $datatable .= '<tr'.$css_class.'>'.
7233: '<td><span class="LC_nobreak">'.
7234: $titles->{$type}.'</span></td>'.
7235: '<td class="LC_left_item">'.
7236: '<input type="text" name="'.$type.'_namedusers" '.
7237: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7238: '<td class="LC_right_item">'.
7239: '<span class="LC_nobreak">'.
7240: '<input type="text" name="'.$type.'_machines" '.
7241: 'value="'.$machineaccess{$type}.'" size="10" />'.
7242: '</td></tr>'."\n";
7243: }
7244: $$rowtotal += $rownum;
7245: return $datatable;
7246: }
7247:
7248: sub serverstatus_pages {
7249: return ('userstatus','lonstatus','loncron','server-status','codeversions',
7250: 'checksums','clusterstatus','certstatus','metadata_keywords',
7251: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
7252: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
7253: }
7254:
7255: sub defaults_javascript {
7256: my ($settings) = @_;
7257: my $intauthcheck = &mt('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.');
7258: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
7259: &js_escape(\$intauthcheck);
7260: &js_escape(\$intauthcost);
7261: my $intauthjs = <<"ENDSCRIPT";
7262:
7263: function warnIntAuth(field) {
7264: if (field.name == 'intauth_check') {
7265: if (field.value == '2') {
7266: alert('$intauthcheck');
7267: }
7268: }
7269: if (field.name == 'intauth_cost') {
7270: field.value.replace(/\s/g,'');
7271: if (field.value != '') {
7272: var regexdigit=/^\\d+\$/;
7273: if (!regexdigit.test(field.value)) {
7274: alert('$intauthcost');
7275: }
7276: }
7277: }
7278: return;
7279: }
7280:
7281: ENDSCRIPT
7282:
7283: if (ref($settings) ne 'HASH') {
7284: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7285: }
7286: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7287: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7288: if ($maxnum eq '') {
7289: $maxnum = 0;
7290: }
7291: $maxnum ++;
7292: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
7293: return <<"ENDSCRIPT";
7294: <script type="text/javascript">
7295: // <![CDATA[
7296: function reorderTypes(form,caller) {
7297: var changedVal;
7298: $jstext
7299: var newpos = 'addinststatus_pos';
7300: var current = new Array;
7301: var maxh = $maxnum;
7302: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7303: var oldVal;
7304: if (caller == newpos) {
7305: changedVal = newitemVal;
7306: } else {
7307: var curritem = 'inststatus_pos_'+caller;
7308: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7309: current[newitemVal] = newpos;
7310: }
7311: for (var i=0; i<inststatuses.length; i++) {
7312: if (inststatuses[i] != caller) {
7313: var elementName = 'inststatus_pos_'+inststatuses[i];
7314: if (form.elements[elementName]) {
7315: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7316: current[currVal] = elementName;
7317: }
7318: }
7319: }
7320: for (var j=0; j<maxh; j++) {
7321: if (current[j] == undefined) {
7322: oldVal = j;
7323: }
7324: }
7325: if (oldVal < changedVal) {
7326: for (var k=oldVal+1; k<=changedVal ; k++) {
7327: var elementName = current[k];
7328: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7329: }
7330: } else {
7331: for (var k=changedVal; k<oldVal; k++) {
7332: var elementName = current[k];
7333: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7334: }
7335: }
7336: return;
7337: }
7338:
7339: $intauthjs
7340:
7341: // ]]>
7342: </script>
7343:
7344: ENDSCRIPT
7345: } else {
7346: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7347: }
7348: }
7349:
7350: sub coursecategories_javascript {
7351: my ($settings) = @_;
7352: my ($output,$jstext,$cathash);
7353: if (ref($settings) eq 'HASH') {
7354: $cathash = $settings->{'cats'};
7355: }
7356: if (ref($cathash) eq 'HASH') {
7357: my (@cats,@jsarray,%idx);
7358: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
7359: if (@jsarray > 0) {
7360: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7361: for (my $i=0; $i<@jsarray; $i++) {
7362: if (ref($jsarray[$i]) eq 'ARRAY') {
7363: my $catstr = join('","',@{$jsarray[$i]});
7364: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7365: }
7366: }
7367: }
7368: } else {
7369: $jstext = ' var categories = Array(1);'."\n".
7370: ' categories[0] = Array("instcode_pos");'."\n";
7371: }
7372: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7373: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
7374: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
7375: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7376: &js_escape(\$instcode_reserved);
7377: &js_escape(\$communities_reserved);
7378: &js_escape(\$placement_reserved);
7379: &js_escape(\$choose_again);
7380: $output = <<"ENDSCRIPT";
7381: <script type="text/javascript">
7382: // <![CDATA[
7383: function reorderCats(form,parent,item,idx) {
7384: var changedVal;
7385: $jstext
7386: var newpos = 'addcategory_pos';
7387: if (parent == '') {
7388: var has_instcode = 0;
7389: var maxtop = categories[idx].length;
7390: for (var j=0; j<maxtop; j++) {
7391: if (categories[idx][j] == 'instcode::0') {
7392: has_instcode == 1;
7393: }
7394: }
7395: if (has_instcode == 0) {
7396: categories[idx][maxtop] = 'instcode_pos';
7397: }
7398: } else {
7399: newpos += '_'+parent;
7400: }
7401: var maxh = 1 + categories[idx].length;
7402: var current = new Array;
7403: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7404: if (item == newpos) {
7405: changedVal = newitemVal;
7406: } else {
7407: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7408: current[newitemVal] = newpos;
7409: }
7410: for (var i=0; i<categories[idx].length; i++) {
7411: var elementName = categories[idx][i];
7412: if (elementName != item) {
7413: if (form.elements[elementName]) {
7414: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7415: current[currVal] = elementName;
7416: }
7417: }
7418: }
7419: var oldVal;
7420: for (var j=0; j<maxh; j++) {
7421: if (current[j] == undefined) {
7422: oldVal = j;
7423: }
7424: }
7425: if (oldVal < changedVal) {
7426: for (var k=oldVal+1; k<=changedVal ; k++) {
7427: var elementName = current[k];
7428: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7429: }
7430: } else {
7431: for (var k=changedVal; k<oldVal; k++) {
7432: var elementName = current[k];
7433: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7434: }
7435: }
7436: return;
7437: }
7438:
7439: function categoryCheck(form) {
7440: if (form.elements['addcategory_name'].value == 'instcode') {
7441: alert('$instcode_reserved\\n$choose_again');
7442: return false;
7443: }
7444: if (form.elements['addcategory_name'].value == 'communities') {
7445: alert('$communities_reserved\\n$choose_again');
7446: return false;
7447: }
7448: if (form.elements['addcategory_name'].value == 'placement') {
7449: alert('$placement_reserved\\n$choose_again');
7450: return false;
7451: }
7452: return true;
7453: }
7454:
7455: // ]]>
7456: </script>
7457:
7458: ENDSCRIPT
7459: return $output;
7460: }
7461:
7462: sub initialize_categories {
7463: my ($itemcount) = @_;
7464: my ($datatable,$css_class,$chgstr);
7465: my %default_names = (
7466: instcode => 'Official courses (with institutional codes)',
7467: communities => 'Communities',
7468: placement => 'Placement Tests',
7469: );
7470: my $select0 = ' selected="selected"';
7471: my $select1 = '';
7472: foreach my $default ('instcode','communities','placement') {
7473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7474: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
7475: if (($default eq 'communities') || ($default eq 'placement')) {
7476: $select1 = $select0;
7477: $select0 = '';
7478: }
7479: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7480: .'<select name="'.$default.'_pos">'
7481: .'<option value="0"'.$select0.'>1</option>'
7482: .'<option value="1"'.$select1.'>2</option>'
7483: .'<option value="2">3</option></select> '
7484: .$default_names{$default}
7485: .'</span></td><td><span class="LC_nobreak">'
7486: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7487: .&mt('Display').'</label> <label>'
7488: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
7489: .'</label></span></td></tr>';
7490: $itemcount ++;
7491: }
7492: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7493: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
7494: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7495: .'<select name="addcategory_pos"'.$chgstr.'>'
7496: .'<option value="0">1</option>'
7497: .'<option value="1">2</option>'
7498: .'<option value="2" selected="selected">3</option></select> '
7499: .&mt('Add category').'</td><td>'.&mt('Name:')
7500: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7501: return $datatable;
7502: }
7503:
7504: sub build_category_rows {
7505: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7506: my ($text,$name,$item,$chgstr);
7507: if (ref($cats) eq 'ARRAY') {
7508: my $maxdepth = scalar(@{$cats});
7509: if (ref($cats->[$depth]) eq 'HASH') {
7510: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7511: my $numchildren = @{$cats->[$depth]{$parent}};
7512: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7513: $text .= '<td><table class="LC_data_table">';
7514: my ($idxnum,$parent_name,$parent_item);
7515: my $higher = $depth - 1;
7516: if ($higher == 0) {
7517: $parent_name = &escape($parent).'::'.$higher;
7518: } else {
7519: if (ref($path) eq 'ARRAY') {
7520: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7521: }
7522: }
7523: $parent_item = 'addcategory_pos_'.$parent_name;
7524: for (my $j=0; $j<=$numchildren; $j++) {
7525: if ($j < $numchildren) {
7526: $name = $cats->[$depth]{$parent}[$j];
7527: $item = &escape($name).':'.&escape($parent).':'.$depth;
7528: $idxnum = $idx->{$item};
7529: } else {
7530: $name = $parent_name;
7531: $item = $parent_item;
7532: }
7533: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7534: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
7535: for (my $i=0; $i<=$numchildren; $i++) {
7536: my $vpos = $i+1;
7537: my $selstr;
7538: if ($j == $i) {
7539: $selstr = ' selected="selected" ';
7540: }
7541: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7542: }
7543: $text .= '</select> ';
7544: if ($j < $numchildren) {
7545: my $deeper = $depth+1;
7546: $text .= $name.' '
7547: .'<label><input type="checkbox" name="deletecategory" value="'
7548: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7549: if(ref($path) eq 'ARRAY') {
7550: push(@{$path},$name);
7551: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
7552: pop(@{$path});
7553: }
7554: } else {
7555: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
7556: if ($j == $numchildren) {
7557: $text .= $name;
7558: } else {
7559: $text .= $item;
7560: }
7561: $text .= '" value="" />';
7562: }
7563: $text .= '</td></tr>';
7564: }
7565: $text .= '</table></td>';
7566: } else {
7567: my $higher = $depth-1;
7568: if ($higher == 0) {
7569: $name = &escape($parent).'::'.$higher;
7570: } else {
7571: if (ref($path) eq 'ARRAY') {
7572: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7573: }
7574: }
7575: my $colspan;
7576: if ($parent ne 'instcode') {
7577: $colspan = $maxdepth - $depth - 1;
7578: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7579: }
7580: }
7581: }
7582: }
7583: return $text;
7584: }
7585:
7586: sub modifiable_userdata_row {
7587: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7588: $rowid,$customcss,$rowstyle) = @_;
7589: my ($role,$rolename,$statustype);
7590: $role = $item;
7591: if ($context eq 'cancreate') {
7592: if ($item =~ /^(emailusername)_(.+)$/) {
7593: $role = $1;
7594: $statustype = $2;
7595: if (ref($usertypes) eq 'HASH') {
7596: if ($usertypes->{$statustype}) {
7597: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7598: } else {
7599: $rolename = &mt('Data provided by user');
7600: }
7601: }
7602: }
7603: } elsif ($context eq 'selfcreate') {
7604: if (ref($usertypes) eq 'HASH') {
7605: $rolename = $usertypes->{$role};
7606: } else {
7607: $rolename = $role;
7608: }
7609: } else {
7610: if ($role eq 'cr') {
7611: $rolename = &mt('Custom role');
7612: } else {
7613: $rolename = &Apache::lonnet::plaintext($role);
7614: }
7615: }
7616: my (@fields,%fieldtitles);
7617: if (ref($fieldsref) eq 'ARRAY') {
7618: @fields = @{$fieldsref};
7619: } else {
7620: @fields = ('lastname','firstname','middlename','generation',
7621: 'permanentemail','id');
7622: }
7623: if ((ref($titlesref) eq 'HASH')) {
7624: %fieldtitles = %{$titlesref};
7625: } else {
7626: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7627: }
7628: my $output;
7629: my $css_class;
7630: if ($rowcount%2) {
7631: $css_class = 'LC_odd_row';
7632: }
7633: if ($customcss) {
7634: $css_class .= " $customcss";
7635: }
7636: $css_class =~ s/^\s+//;
7637: if ($css_class) {
7638: $css_class = ' class="'.$css_class.'"';
7639: }
7640: if ($rowstyle) {
7641: $css_class .= ' style="'.$rowstyle.'"';
7642: }
7643: if ($rowid) {
7644: $rowid = ' id="'.$rowid.'"';
7645: }
7646:
7647: $output = '<tr '.$css_class.$rowid.'>'.
7648: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7649: '<td class="LC_left_item" colspan="2"><table>';
7650: my $rem;
7651: my %checks;
7652: if (ref($settings) eq 'HASH') {
7653: if (ref($settings->{$context}) eq 'HASH') {
7654: if (ref($settings->{$context}->{$role}) eq 'HASH') {
7655: my $hashref = $settings->{$context}->{$role};
7656: if ($role eq 'emailusername') {
7657: if ($statustype) {
7658: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7659: $hashref = $settings->{$context}->{$role}->{$statustype};
7660: if (ref($hashref) eq 'HASH') {
7661: foreach my $field (@fields) {
7662: if ($hashref->{$field}) {
7663: $checks{$field} = $hashref->{$field};
7664: }
7665: }
7666: }
7667: }
7668: }
7669: } else {
7670: if (ref($hashref) eq 'HASH') {
7671: foreach my $field (@fields) {
7672: if ($hashref->{$field}) {
7673: $checks{$field} = ' checked="checked" ';
7674: }
7675: }
7676: }
7677: }
7678: }
7679: }
7680: }
7681:
7682: my $total = scalar(@fields);
7683: for (my $i=0; $i<$total; $i++) {
7684: $rem = $i%($numinrow);
7685: if ($rem == 0) {
7686: if ($i > 0) {
7687: $output .= '</tr>';
7688: }
7689: $output .= '<tr>';
7690: }
7691: my $check = ' ';
7692: unless ($role eq 'emailusername') {
7693: if (exists($checks{$fields[$i]})) {
7694: $check = $checks{$fields[$i]}
7695: } else {
7696: if ($role eq 'st') {
7697: if (ref($settings) ne 'HASH') {
7698: $check = ' checked="checked" ';
7699: }
7700: }
7701: }
7702: }
7703: $output .= '<td class="LC_left_item">'.
7704: '<span class="LC_nobreak">';
7705: if ($role eq 'emailusername') {
7706: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7707: $checks{$fields[$i]} = 'omit';
7708: }
7709: foreach my $option ('required','optional','omit') {
7710: my $checked='';
7711: if ($checks{$fields[$i]} eq $option) {
7712: $checked='checked="checked" ';
7713: }
7714: $output .= '<label>'.
7715: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7716: &mt($option).'</label>'.(' ' x2);
7717: }
7718: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7719: } else {
7720: $output .= '<label>'.
7721: '<input type="checkbox" name="canmodify_'.$role.'" '.
7722: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7723: '</label>';
7724: }
7725: $output .= '</span></td>';
7726: }
7727: $rem = $total%$numinrow;
7728: my $colsleft;
7729: if ($rem) {
7730: $colsleft = $numinrow - $rem;
7731: }
7732: if ($colsleft > 1) {
7733: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7734: ' </td>';
7735: } elsif ($colsleft == 1) {
7736: $output .= '<td class="LC_left_item"> </td>';
7737: }
7738: $output .= '</tr></table></td></tr>';
7739: return $output;
7740: }
7741:
7742: sub insttypes_row {
7743: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7744: $customcss,$rowstyle) = @_;
7745: my %lt = &Apache::lonlocal::texthash (
7746: cansearch => 'Users allowed to search',
7747: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
7748: lockablenames => 'User preference to lock name',
7749: selfassign => 'Self-reportable affiliations',
7750: );
7751: my $showdom;
7752: if ($context eq 'cansearch') {
7753: $showdom = ' ('.$dom.')';
7754: }
7755: my $class = 'LC_left_item';
7756: if ($context eq 'statustocreate') {
7757: $class = 'LC_right_item';
7758: }
7759: my $css_class;
7760: if ($$rowtotal%2) {
7761: $css_class = 'LC_odd_row';
7762: }
7763: if ($customcss) {
7764: $css_class .= ' '.$customcss;
7765: }
7766: $css_class =~ s/^\s+//;
7767: if ($css_class) {
7768: $css_class = ' class="'.$css_class.'"';
7769: }
7770: if ($rowstyle) {
7771: $css_class .= ' style="'.$rowstyle.'"';
7772: }
7773: if ($onclick) {
7774: $onclick = 'onclick="'.$onclick.'" ';
7775: }
7776: my $output = '<tr'.$css_class.'>'.
7777: '<td>'.$lt{$context}.$showdom.
7778: '</td><td class="'.$class.'" colspan="2"><table>';
7779: my $rem;
7780: if (ref($types) eq 'ARRAY') {
7781: for (my $i=0; $i<@{$types}; $i++) {
7782: if (defined($usertypes->{$types->[$i]})) {
7783: my $rem = $i%($numinrow);
7784: if ($rem == 0) {
7785: if ($i > 0) {
7786: $output .= '</tr>';
7787: }
7788: $output .= '<tr>';
7789: }
7790: my $check = ' ';
7791: if (ref($settings) eq 'HASH') {
7792: if (ref($settings->{$context}) eq 'ARRAY') {
7793: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7794: $check = ' checked="checked" ';
7795: }
7796: } elsif ($context eq 'statustocreate') {
7797: $check = ' checked="checked" ';
7798: }
7799: }
7800: $output .= '<td class="LC_left_item">'.
7801: '<span class="LC_nobreak"><label>'.
7802: '<input type="checkbox" name="'.$context.'" '.
7803: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
7804: $usertypes->{$types->[$i]}.'</label></span></td>';
7805: }
7806: }
7807: $rem = @{$types}%($numinrow);
7808: }
7809: my $colsleft = $numinrow - $rem;
7810: if (($rem == 0) && (@{$types} > 0)) {
7811: $output .= '<tr>';
7812: }
7813: if ($colsleft > 1) {
7814: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7815: } else {
7816: $output .= '<td class="LC_left_item">';
7817: }
7818: my $defcheck = ' ';
7819: if (ref($settings) eq 'HASH') {
7820: if (ref($settings->{$context}) eq 'ARRAY') {
7821: if (grep(/^default$/,@{$settings->{$context}})) {
7822: $defcheck = ' checked="checked" ';
7823: }
7824: } elsif ($context eq 'statustocreate') {
7825: $defcheck = ' checked="checked" ';
7826: }
7827: }
7828: $output .= '<span class="LC_nobreak"><label>'.
7829: '<input type="checkbox" name="'.$context.'" '.
7830: 'value="default"'.$defcheck.$onclick.' />'.
7831: $othertitle.'</label></span></td>'.
7832: '</tr></table></td></tr>';
7833: return $output;
7834: }
7835:
7836: sub sorted_searchtitles {
7837: my %searchtitles = &Apache::lonlocal::texthash(
7838: 'uname' => 'username',
7839: 'lastname' => 'last name',
7840: 'lastfirst' => 'last name, first name',
7841: );
7842: my @titleorder = ('uname','lastname','lastfirst');
7843: return (\%searchtitles,\@titleorder);
7844: }
7845:
7846: sub sorted_searchtypes {
7847: my %srchtypes_desc = (
7848: exact => 'is exact match',
7849: contains => 'contains ..',
7850: begins => 'begins with ..',
7851: );
7852: my @srchtypeorder = ('exact','begins','contains');
7853: return (\%srchtypes_desc,\@srchtypeorder);
7854: }
7855:
7856: sub usertype_update_row {
7857: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7858: my $datatable;
7859: my $numinrow = 4;
7860: foreach my $type (@{$types}) {
7861: if (defined($usertypes->{$type})) {
7862: $$rownums ++;
7863: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7864: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7865: '</td><td class="LC_left_item"><table>';
7866: for (my $i=0; $i<@{$fields}; $i++) {
7867: my $rem = $i%($numinrow);
7868: if ($rem == 0) {
7869: if ($i > 0) {
7870: $datatable .= '</tr>';
7871: }
7872: $datatable .= '<tr>';
7873: }
7874: my $check = ' ';
7875: if (ref($settings) eq 'HASH') {
7876: if (ref($settings->{'fields'}) eq 'HASH') {
7877: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7878: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7879: $check = ' checked="checked" ';
7880: }
7881: }
7882: }
7883: }
7884:
7885: if ($i == @{$fields}-1) {
7886: my $colsleft = $numinrow - $rem;
7887: if ($colsleft > 1) {
7888: $datatable .= '<td colspan="'.$colsleft.'">';
7889: } else {
7890: $datatable .= '<td>';
7891: }
7892: } else {
7893: $datatable .= '<td>';
7894: }
7895: $datatable .= '<span class="LC_nobreak"><label>'.
7896: '<input type="checkbox" name="updateable_'.$type.
7897: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7898: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
7899: }
7900: $datatable .= '</tr></table></td></tr>';
7901: }
7902: }
7903: return $datatable;
7904: }
7905:
7906: sub modify_login {
7907: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
7908: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7909: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7910: %title = ( coursecatalog => 'Display course catalog',
7911: adminmail => 'Display administrator E-mail address',
7912: helpdesk => 'Display "Contact Helpdesk" link',
7913: newuser => 'Link for visitors to create a user account',
7914: loginheader => 'Log-in box header');
7915: @offon = ('off','on');
7916: if (ref($domconfig{login}) eq 'HASH') {
7917: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7918: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7919: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7920: }
7921: }
7922: }
7923: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7924: \%domconfig,\%loginhash);
7925: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
7926: foreach my $item (@toggles) {
7927: $loginhash{login}{$item} = $env{'form.'.$item};
7928: }
7929: $loginhash{login}{loginheader} = $env{'form.loginheader'};
7930: if (ref($colchanges{'login'}) eq 'HASH') {
7931: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7932: \%loginhash);
7933: }
7934:
7935: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7936: my %domservers = &Apache::lonnet::get_servers($dom);
7937: my @loginvia_attribs = ('serverpath','custompath','exempt');
7938: if (keys(%servers) > 1) {
7939: foreach my $lonhost (keys(%servers)) {
7940: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7941: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7942: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7943: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7944: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7945: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7946: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7947: $changes{'loginvia'}{$lonhost} = 1;
7948: } else {
7949: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7950: $changes{'loginvia'}{$lonhost} = 1;
7951: }
7952: } else {
7953: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7954: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7955: $changes{'loginvia'}{$lonhost} = 1;
7956: }
7957: }
7958: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7959: foreach my $item (@loginvia_attribs) {
7960: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7961: }
7962: } else {
7963: foreach my $item (@loginvia_attribs) {
7964: my $new = $env{'form.'.$lonhost.'_'.$item};
7965: if (($item eq 'serverpath') && ($new eq 'custom')) {
7966: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7967: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7968: $new = '/';
7969: }
7970: }
7971: if (($item eq 'custompath') &&
7972: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7973: $new = '';
7974: }
7975: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7976: $changes{'loginvia'}{$lonhost} = 1;
7977: }
7978: if ($item eq 'exempt') {
7979: $new = &check_exempt_addresses($new);
7980: }
7981: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7982: }
7983: }
7984: } else {
7985: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7986: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7987: $changes{'loginvia'}{$lonhost} = 1;
7988: foreach my $item (@loginvia_attribs) {
7989: my $new = $env{'form.'.$lonhost.'_'.$item};
7990: if (($item eq 'serverpath') && ($new eq 'custom')) {
7991: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7992: $new = '/';
7993: }
7994: }
7995: if (($item eq 'custompath') &&
7996: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7997: $new = '';
7998: }
7999: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8000: }
8001: }
8002: }
8003: }
8004: }
8005:
8006: my $servadm = $r->dir_config('lonAdmEMail');
8007: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8008: if (ref($domconfig{'login'}) eq 'HASH') {
8009: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8010: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8011: if ($lang eq 'nolang') {
8012: push(@currlangs,$lang);
8013: } elsif (defined($langchoices{$lang})) {
8014: push(@currlangs,$lang);
8015: } else {
8016: next;
8017: }
8018: }
8019: }
8020: }
8021: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8022: if (@currlangs > 0) {
8023: foreach my $lang (@currlangs) {
8024: if (grep(/^\Q$lang\E$/,@delurls)) {
8025: $changes{'helpurl'}{$lang} = 1;
8026: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8027: $changes{'helpurl'}{$lang} = 1;
8028: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8029: push(@newlangs,$lang);
8030: } else {
8031: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8032: }
8033: }
8034: }
8035: unless (grep(/^nolang$/,@currlangs)) {
8036: if ($env{'form.loginhelpurl_nolang.filename'}) {
8037: $changes{'helpurl'}{'nolang'} = 1;
8038: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8039: push(@newlangs,'nolang');
8040: }
8041: }
8042: if ($env{'form.loginhelpurl_add_lang'}) {
8043: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8044: ($env{'form.loginhelpurl_add_file.filename'})) {
8045: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8046: $addedfile = $env{'form.loginhelpurl_add_lang'};
8047: }
8048: }
8049: if ((@newlangs > 0) || ($addedfile)) {
8050: my $error;
8051: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8052: if ($configuserok eq 'ok') {
8053: if ($switchserver) {
8054: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8055: } elsif ($author_ok eq 'ok') {
8056: my @allnew = @newlangs;
8057: if ($addedfile ne '') {
8058: push(@allnew,$addedfile);
8059: }
8060: foreach my $lang (@allnew) {
8061: my $formelem = 'loginhelpurl_'.$lang;
8062: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8063: $formelem = 'loginhelpurl_add_file';
8064: }
8065: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8066: "help/$lang",'','',$newfile{$lang});
8067: if ($result eq 'ok') {
8068: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8069: $changes{'helpurl'}{$lang} = 1;
8070: } else {
8071: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8072: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8073: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
8074: (!grep(/^\Q$lang\E$/,@delurls))) {
8075: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8076: }
8077: }
8078: }
8079: } else {
8080: $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);
8081: }
8082: } else {
8083: $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);
8084: }
8085: if ($error) {
8086: &Apache::lonnet::logthis($error);
8087: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8088: }
8089: }
8090:
8091: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8092: if (ref($domconfig{'login'}) eq 'HASH') {
8093: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8094: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8095: if ($domservers{$lonhost}) {
8096: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8097: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
8098: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
8099: }
8100: }
8101: }
8102: }
8103: }
8104: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8105: foreach my $lonhost (sort(keys(%domservers))) {
8106: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8107: $changes{'headtag'}{$lonhost} = 1;
8108: } else {
8109: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8110: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8111: }
8112: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8113: push(@newhosts,$lonhost);
8114: } elsif ($currheadtagurls{$lonhost}) {
8115: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8116: if ($currexempt{$lonhost}) {
8117: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
8118: $changes{'headtag'}{$lonhost} = 1;
8119: }
8120: } elsif ($possexempt{$lonhost}) {
8121: $changes{'headtag'}{$lonhost} = 1;
8122: }
8123: if ($possexempt{$lonhost}) {
8124: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8125: }
8126: }
8127: }
8128: }
8129: if (@newhosts) {
8130: my $error;
8131: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8132: if ($configuserok eq 'ok') {
8133: if ($switchserver) {
8134: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8135: } elsif ($author_ok eq 'ok') {
8136: foreach my $lonhost (@newhosts) {
8137: my $formelem = 'loginheadtag_'.$lonhost;
8138: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8139: "login/headtag/$lonhost",'','',
8140: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8141: if ($result eq 'ok') {
8142: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8143: $changes{'headtag'}{$lonhost} = 1;
8144: if ($possexempt{$lonhost}) {
8145: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8146: }
8147: } else {
8148: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8149: $newheadtagurls{$lonhost},$result);
8150: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8151: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8152: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8153: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8154: }
8155: }
8156: }
8157: } else {
8158: $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);
8159: }
8160: } else {
8161: $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);
8162: }
8163: if ($error) {
8164: &Apache::lonnet::logthis($error);
8165: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8166: }
8167: }
8168: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
8169:
8170: my $defaulthelpfile = '/adm/loginproblems.html';
8171: my $defaulttext = &mt('Default in use');
8172:
8173: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8174: $dom);
8175: if ($putresult eq 'ok') {
8176: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
8177: my %defaultchecked = (
8178: 'coursecatalog' => 'on',
8179: 'helpdesk' => 'on',
8180: 'adminmail' => 'off',
8181: 'newuser' => 'off',
8182: );
8183: if (ref($domconfig{'login'}) eq 'HASH') {
8184: foreach my $item (@toggles) {
8185: if ($defaultchecked{$item} eq 'on') {
8186: if (($domconfig{'login'}{$item} eq '0') &&
8187: ($env{'form.'.$item} eq '1')) {
8188: $changes{$item} = 1;
8189: } elsif (($domconfig{'login'}{$item} eq '' ||
8190: $domconfig{'login'}{$item} eq '1') &&
8191: ($env{'form.'.$item} eq '0')) {
8192: $changes{$item} = 1;
8193: }
8194: } elsif ($defaultchecked{$item} eq 'off') {
8195: if (($domconfig{'login'}{$item} eq '1') &&
8196: ($env{'form.'.$item} eq '0')) {
8197: $changes{$item} = 1;
8198: } elsif (($domconfig{'login'}{$item} eq '' ||
8199: $domconfig{'login'}{$item} eq '0') &&
8200: ($env{'form.'.$item} eq '1')) {
8201: $changes{$item} = 1;
8202: }
8203: }
8204: }
8205: }
8206: if (keys(%changes) > 0 || $colchgtext) {
8207: &Apache::loncommon::devalidate_domconfig_cache($dom);
8208: if (ref($lastactref) eq 'HASH') {
8209: $lastactref->{'domainconfig'} = 1;
8210: }
8211: $resulttext = &mt('Changes made:').'<ul>';
8212: foreach my $item (sort(keys(%changes))) {
8213: if ($item eq 'loginvia') {
8214: if (ref($changes{$item}) eq 'HASH') {
8215: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8216: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8217: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8218: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8219: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8220: $protocol = 'http' if ($protocol ne 'https');
8221: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8222:
8223: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8224: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8225: } else {
8226: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8227: }
8228: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8229: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8230: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8231: }
8232: $resulttext .= '</li>';
8233: } else {
8234: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8235: }
8236: } else {
8237: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
8238: }
8239: }
8240: $resulttext .= '</ul></li>';
8241: }
8242: } elsif ($item eq 'helpurl') {
8243: if (ref($changes{$item}) eq 'HASH') {
8244: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8245: if (grep(/^\Q$lang\E$/,@delurls)) {
8246: my ($chg,$link);
8247: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8248: if ($lang eq 'nolang') {
8249: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8250: } else {
8251: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8252: }
8253: $resulttext .= '<li>'.$chg.'</li>';
8254: } else {
8255: my $chg;
8256: if ($lang eq 'nolang') {
8257: $chg = &mt('custom log-in help file for no preferred language');
8258: } else {
8259: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8260: }
8261: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8262: $loginhash{'login'}{'helpurl'}{$lang}.
8263: '?inhibitmenu=yes',$chg,600,500).
8264: '</li>';
8265: }
8266: }
8267: }
8268: } elsif ($item eq 'headtag') {
8269: if (ref($changes{$item}) eq 'HASH') {
8270: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8271: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8272: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8273: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8274: $resulttext .= '<li><a href="'.
8275: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8276: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8277: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8278: if ($possexempt{$lonhost}) {
8279: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8280: } else {
8281: $resulttext .= &mt('included for any client IP');
8282: }
8283: $resulttext .= '</li>';
8284: }
8285: }
8286: }
8287: } elsif ($item eq 'captcha') {
8288: if (ref($loginhash{'login'}) eq 'HASH') {
8289: my $chgtxt;
8290: if ($loginhash{'login'}{$item} eq 'notused') {
8291: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8292: } else {
8293: my %captchas = &captcha_phrases();
8294: if ($captchas{$loginhash{'login'}{$item}}) {
8295: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8296: } else {
8297: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8298: }
8299: }
8300: $resulttext .= '<li>'.$chgtxt.'</li>';
8301: }
8302: } elsif ($item eq 'recaptchakeys') {
8303: if (ref($loginhash{'login'}) eq 'HASH') {
8304: my ($privkey,$pubkey);
8305: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8306: $pubkey = $loginhash{'login'}{$item}{'public'};
8307: $privkey = $loginhash{'login'}{$item}{'private'};
8308: }
8309: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8310: if (!$pubkey) {
8311: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8312: } else {
8313: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8314: }
8315: if (!$privkey) {
8316: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8317: } else {
8318: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
8319: }
8320: $chgtxt .= '</ul>';
8321: $resulttext .= '<li>'.$chgtxt.'</li>';
8322: }
8323: } elsif ($item eq 'recaptchaversion') {
8324: if (ref($loginhash{'login'}) eq 'HASH') {
8325: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
8326: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
8327: '</li>';
8328: }
8329: }
8330: } else {
8331: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8332: }
8333: }
8334: $resulttext .= $colchgtext.'</ul>';
8335: } else {
8336: $resulttext = &mt('No changes made to log-in page settings');
8337: }
8338: } else {
8339: $resulttext = '<span class="LC_error">'.
8340: &mt('An error occurred: [_1]',$putresult).'</span>';
8341: }
8342: if ($errors) {
8343: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
8344: $errors.'</ul>';
8345: }
8346: return $resulttext;
8347: }
8348:
8349: sub check_exempt_addresses {
8350: my ($iplist) = @_;
8351: $iplist =~ s/^\s+//;
8352: $iplist =~ s/\s+$//;
8353: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8354: my (@okips,$new);
8355: foreach my $ip (@poss_ips) {
8356: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8357: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8358: push(@okips,$ip);
8359: }
8360: }
8361: }
8362: if (@okips > 0) {
8363: $new = join(',',@okips);
8364: } else {
8365: $new = '';
8366: }
8367: return $new;
8368: }
8369:
8370: sub color_font_choices {
8371: my %choices =
8372: &Apache::lonlocal::texthash (
8373: img => "Header",
8374: bgs => "Background colors",
8375: links => "Link colors",
8376: images => "Images",
8377: font => "Font color",
8378: fontmenu => "Font menu",
8379: pgbg => "Page",
8380: tabbg => "Header",
8381: sidebg => "Border",
8382: link => "Link",
8383: alink => "Active link",
8384: vlink => "Visited link",
8385: );
8386: return %choices;
8387: }
8388:
8389: sub modify_rolecolors {
8390: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
8391: my ($resulttext,%rolehash);
8392: $rolehash{'rolecolors'} = {};
8393: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8394: if ($domconfig{'rolecolors'} eq '') {
8395: $domconfig{'rolecolors'} = {};
8396: }
8397: }
8398: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
8399: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8400: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8401: $dom);
8402: if ($putresult eq 'ok') {
8403: if (keys(%changes) > 0) {
8404: &Apache::loncommon::devalidate_domconfig_cache($dom);
8405: if (ref($lastactref) eq 'HASH') {
8406: $lastactref->{'domainconfig'} = 1;
8407: }
8408: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8409: $rolehash{'rolecolors'});
8410: } else {
8411: $resulttext = &mt('No changes made to default color schemes');
8412: }
8413: } else {
8414: $resulttext = '<span class="LC_error">'.
8415: &mt('An error occurred: [_1]',$putresult).'</span>';
8416: }
8417: if ($errors) {
8418: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8419: $errors.'</ul>';
8420: }
8421: return $resulttext;
8422: }
8423:
8424: sub modify_colors {
8425: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
8426: my (%changes,%choices);
8427: my @bgs;
8428: my @links = ('link','alink','vlink');
8429: my @logintext;
8430: my @images;
8431: my $servadm = $r->dir_config('lonAdmEMail');
8432: my $errors;
8433: my %defaults;
8434: foreach my $role (@{$roles}) {
8435: if ($role eq 'login') {
8436: %choices = &login_choices();
8437: @logintext = ('textcol','bgcol');
8438: } else {
8439: %choices = &color_font_choices();
8440: }
8441: if ($role eq 'login') {
8442: @images = ('img','logo','domlogo','login');
8443: @bgs = ('pgbg','mainbg','sidebg');
8444: } else {
8445: @images = ('img');
8446: @bgs = ('pgbg','tabbg','sidebg');
8447: }
8448: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8449: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8450: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8451: }
8452: if ($role eq 'login') {
8453: foreach my $item (@logintext) {
8454: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8455: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8456: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8457: }
8458: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
8459: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8460: }
8461: }
8462: } else {
8463: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8464: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8465: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8466: }
8467: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
8468: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8469: }
8470: }
8471: foreach my $item (@bgs) {
8472: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8473: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8474: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8475: }
8476: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
8477: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8478: }
8479: }
8480: foreach my $item (@links) {
8481: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8482: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8483: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8484: }
8485: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
8486: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8487: }
8488: }
8489: my ($configuserok,$author_ok,$switchserver) =
8490: &config_check($dom,$confname,$servadm);
8491: my ($width,$height) = &thumb_dimensions();
8492: if (ref($domconfig->{$role}) ne 'HASH') {
8493: $domconfig->{$role} = {};
8494: }
8495: foreach my $img (@images) {
8496: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8497: if (defined($env{'form.login_showlogo_'.$img})) {
8498: $confhash->{$role}{'showlogo'}{$img} = 1;
8499: } else {
8500: $confhash->{$role}{'showlogo'}{$img} = 0;
8501: }
8502: }
8503: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8504: && !defined($domconfig->{$role}{$img})
8505: && !$env{'form.'.$role.'_del_'.$img}
8506: && $env{'form.'.$role.'_import_'.$img}) {
8507: # import the old configured image from the .tab setting
8508: # if they haven't provided a new one
8509: $domconfig->{$role}{$img} =
8510: $env{'form.'.$role.'_import_'.$img};
8511: }
8512: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
8513: my $error;
8514: if ($configuserok eq 'ok') {
8515: if ($switchserver) {
8516: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
8517: } else {
8518: if ($author_ok eq 'ok') {
8519: my ($result,$logourl) =
8520: &publishlogo($r,'upload',$role.'_'.$img,
8521: $dom,$confname,$img,$width,$height);
8522: if ($result eq 'ok') {
8523: $confhash->{$role}{$img} = $logourl;
8524: $changes{$role}{'images'}{$img} = 1;
8525: } else {
8526: $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);
8527: }
8528: } else {
8529: $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);
8530: }
8531: }
8532: } else {
8533: $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);
8534: }
8535: if ($error) {
8536: &Apache::lonnet::logthis($error);
8537: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8538: }
8539: } elsif ($domconfig->{$role}{$img} ne '') {
8540: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8541: my $error;
8542: if ($configuserok eq 'ok') {
8543: # is confname an author?
8544: if ($switchserver eq '') {
8545: if ($author_ok eq 'ok') {
8546: my ($result,$logourl) =
8547: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8548: $dom,$confname,$img,$width,$height);
8549: if ($result eq 'ok') {
8550: $confhash->{$role}{$img} = $logourl;
8551: $changes{$role}{'images'}{$img} = 1;
8552: }
8553: }
8554: }
8555: }
8556: }
8557: }
8558: }
8559: if (ref($domconfig) eq 'HASH') {
8560: if (ref($domconfig->{$role}) eq 'HASH') {
8561: foreach my $img (@images) {
8562: if ($domconfig->{$role}{$img} ne '') {
8563: if ($env{'form.'.$role.'_del_'.$img}) {
8564: $confhash->{$role}{$img} = '';
8565: $changes{$role}{'images'}{$img} = 1;
8566: } else {
8567: if ($confhash->{$role}{$img} eq '') {
8568: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8569: }
8570: }
8571: } else {
8572: if ($env{'form.'.$role.'_del_'.$img}) {
8573: $confhash->{$role}{$img} = '';
8574: $changes{$role}{'images'}{$img} = 1;
8575: }
8576: }
8577: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8578: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8579: if ($confhash->{$role}{'showlogo'}{$img} ne
8580: $domconfig->{$role}{'showlogo'}{$img}) {
8581: $changes{$role}{'showlogo'}{$img} = 1;
8582: }
8583: } else {
8584: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8585: $changes{$role}{'showlogo'}{$img} = 1;
8586: }
8587: }
8588: }
8589: }
8590: if ($domconfig->{$role}{'font'} ne '') {
8591: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8592: $changes{$role}{'font'} = 1;
8593: }
8594: } else {
8595: if ($confhash->{$role}{'font'}) {
8596: $changes{$role}{'font'} = 1;
8597: }
8598: }
8599: if ($role ne 'login') {
8600: if ($domconfig->{$role}{'fontmenu'} ne '') {
8601: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8602: $changes{$role}{'fontmenu'} = 1;
8603: }
8604: } else {
8605: if ($confhash->{$role}{'fontmenu'}) {
8606: $changes{$role}{'fontmenu'} = 1;
8607: }
8608: }
8609: }
8610: foreach my $item (@bgs) {
8611: if ($domconfig->{$role}{$item} ne '') {
8612: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8613: $changes{$role}{'bgs'}{$item} = 1;
8614: }
8615: } else {
8616: if ($confhash->{$role}{$item}) {
8617: $changes{$role}{'bgs'}{$item} = 1;
8618: }
8619: }
8620: }
8621: foreach my $item (@links) {
8622: if ($domconfig->{$role}{$item} ne '') {
8623: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8624: $changes{$role}{'links'}{$item} = 1;
8625: }
8626: } else {
8627: if ($confhash->{$role}{$item}) {
8628: $changes{$role}{'links'}{$item} = 1;
8629: }
8630: }
8631: }
8632: foreach my $item (@logintext) {
8633: if ($domconfig->{$role}{$item} ne '') {
8634: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8635: $changes{$role}{'logintext'}{$item} = 1;
8636: }
8637: } else {
8638: if ($confhash->{$role}{$item}) {
8639: $changes{$role}{'logintext'}{$item} = 1;
8640: }
8641: }
8642: }
8643: } else {
8644: &default_change_checker($role,\@images,\@links,\@bgs,
8645: \@logintext,$confhash,\%changes);
8646: }
8647: } else {
8648: &default_change_checker($role,\@images,\@links,\@bgs,
8649: \@logintext,$confhash,\%changes);
8650: }
8651: }
8652: return ($errors,%changes);
8653: }
8654:
8655: sub config_check {
8656: my ($dom,$confname,$servadm) = @_;
8657: my ($configuserok,$author_ok,$switchserver,%currroles);
8658: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8659: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8660: $confname,$servadm);
8661: if ($configuserok eq 'ok') {
8662: $switchserver = &check_switchserver($dom,$confname);
8663: if ($switchserver eq '') {
8664: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8665: }
8666: }
8667: return ($configuserok,$author_ok,$switchserver);
8668: }
8669:
8670: sub default_change_checker {
8671: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
8672: foreach my $item (@{$links}) {
8673: if ($confhash->{$role}{$item}) {
8674: $changes->{$role}{'links'}{$item} = 1;
8675: }
8676: }
8677: foreach my $item (@{$bgs}) {
8678: if ($confhash->{$role}{$item}) {
8679: $changes->{$role}{'bgs'}{$item} = 1;
8680: }
8681: }
8682: foreach my $item (@{$logintext}) {
8683: if ($confhash->{$role}{$item}) {
8684: $changes->{$role}{'logintext'}{$item} = 1;
8685: }
8686: }
8687: foreach my $img (@{$images}) {
8688: if ($env{'form.'.$role.'_del_'.$img}) {
8689: $confhash->{$role}{$img} = '';
8690: $changes->{$role}{'images'}{$img} = 1;
8691: }
8692: if ($role eq 'login') {
8693: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8694: $changes->{$role}{'showlogo'}{$img} = 1;
8695: }
8696: }
8697: }
8698: if ($confhash->{$role}{'font'}) {
8699: $changes->{$role}{'font'} = 1;
8700: }
8701: }
8702:
8703: sub display_colorchgs {
8704: my ($dom,$changes,$roles,$confhash) = @_;
8705: my (%choices,$resulttext);
8706: if (!grep(/^login$/,@{$roles})) {
8707: $resulttext = &mt('Changes made:').'<br />';
8708: }
8709: foreach my $role (@{$roles}) {
8710: if ($role eq 'login') {
8711: %choices = &login_choices();
8712: } else {
8713: %choices = &color_font_choices();
8714: }
8715: if (ref($changes->{$role}) eq 'HASH') {
8716: if ($role ne 'login') {
8717: $resulttext .= '<h4>'.&mt($role).'</h4>';
8718: }
8719: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8720: if ($role ne 'login') {
8721: $resulttext .= '<ul>';
8722: }
8723: if (ref($changes->{$role}{$key}) eq 'HASH') {
8724: if ($role ne 'login') {
8725: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8726: }
8727: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
8728: if (($role eq 'login') && ($key eq 'showlogo')) {
8729: if ($confhash->{$role}{$key}{$item}) {
8730: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8731: } else {
8732: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8733: }
8734: } elsif ($confhash->{$role}{$item} eq '') {
8735: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8736: } else {
8737: my $newitem = $confhash->{$role}{$item};
8738: if ($key eq 'images') {
8739: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
8740: }
8741: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
8742: }
8743: }
8744: if ($role ne 'login') {
8745: $resulttext .= '</ul></li>';
8746: }
8747: } else {
8748: if ($confhash->{$role}{$key} eq '') {
8749: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8750: } else {
8751: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8752: }
8753: }
8754: if ($role ne 'login') {
8755: $resulttext .= '</ul>';
8756: }
8757: }
8758: }
8759: }
8760: return $resulttext;
8761: }
8762:
8763: sub thumb_dimensions {
8764: return ('200','50');
8765: }
8766:
8767: sub check_dimensions {
8768: my ($inputfile) = @_;
8769: my ($fullwidth,$fullheight);
8770: if ($inputfile =~ m|^[/\w.\-]+$|) {
8771: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8772: my $imageinfo = <PIPE>;
8773: if (!close(PIPE)) {
8774: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8775: }
8776: chomp($imageinfo);
8777: my ($fullsize) =
8778: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
8779: if ($fullsize) {
8780: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8781: }
8782: }
8783: }
8784: return ($fullwidth,$fullheight);
8785: }
8786:
8787: sub check_configuser {
8788: my ($uhome,$dom,$confname,$servadm) = @_;
8789: my ($configuserok,%currroles);
8790: if ($uhome eq 'no_host') {
8791: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8792: my $configpass = &LONCAPA::Enrollment::create_password();
8793: $configuserok =
8794: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8795: $configpass,'','','','','',undef,$servadm);
8796: } else {
8797: $configuserok = 'ok';
8798: %currroles =
8799: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8800: }
8801: return ($configuserok,%currroles);
8802: }
8803:
8804: sub check_authorstatus {
8805: my ($dom,$confname,%currroles) = @_;
8806: my $author_ok;
8807: if (!$currroles{':'.$dom.':au'}) {
8808: my $start = time;
8809: my $end = 0;
8810: $author_ok =
8811: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
8812: 'au',$end,$start,'','','domconfig');
8813: } else {
8814: $author_ok = 'ok';
8815: }
8816: return $author_ok;
8817: }
8818:
8819: sub publishlogo {
8820: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
8821: my ($output,$fname,$logourl,$madethumb);
8822: if ($action eq 'upload') {
8823: $fname=$env{'form.'.$formname.'.filename'};
8824: chop($env{'form.'.$formname});
8825: } else {
8826: ($fname) = ($formname =~ /([^\/]+)$/);
8827: }
8828: if ($savefileas ne '') {
8829: $fname = $savefileas;
8830: }
8831: $fname=&Apache::lonnet::clean_filename($fname);
8832: # See if there is anything left
8833: unless ($fname) { return ('error: no uploaded file'); }
8834: $fname="$subdir/$fname";
8835: my $docroot=$r->dir_config('lonDocRoot');
8836: my $filepath="$docroot/priv";
8837: my $relpath = "$dom/$confname";
8838: my ($fnamepath,$file,$fetchthumb);
8839: $file=$fname;
8840: if ($fname=~m|/|) {
8841: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8842: }
8843: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
8844: my $count;
8845: for ($count=5;$count<=$#parts;$count++) {
8846: $filepath.="/$parts[$count]";
8847: if ((-e $filepath)!=1) {
8848: mkdir($filepath,02770);
8849: }
8850: }
8851: # Check for bad extension and disallow upload
8852: if ($file=~/\.(\w+)$/ &&
8853: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8854: $output =
8855: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
8856: } elsif ($file=~/\.(\w+)$/ &&
8857: !defined(&Apache::loncommon::fileembstyle($1))) {
8858: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8859: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
8860: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8861: } elsif (-d "$filepath/$file") {
8862: $output = &mt('Filename is a directory name - rename the file and re-upload');
8863: } else {
8864: my $source = $filepath.'/'.$file;
8865: my $logfile;
8866: if (!open($logfile,">>$source".'.log')) {
8867: return (&mt('No write permission to Authoring Space'));
8868: }
8869: print $logfile
8870: "\n================= Publish ".localtime()." ================\n".
8871: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8872: # Save the file
8873: if (!open(FH,'>'.$source)) {
8874: &Apache::lonnet::logthis('Failed to create '.$source);
8875: return (&mt('Failed to create file'));
8876: }
8877: if ($action eq 'upload') {
8878: if (!print FH ($env{'form.'.$formname})) {
8879: &Apache::lonnet::logthis('Failed to write to '.$source);
8880: return (&mt('Failed to write file'));
8881: }
8882: } else {
8883: my $original = &Apache::lonnet::filelocation('',$formname);
8884: if(!copy($original,$source)) {
8885: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8886: return (&mt('Failed to write file'));
8887: }
8888: }
8889: close(FH);
8890: chmod(0660, $source); # Permissions to rw-rw---.
8891:
8892: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8893: my $copyfile=$targetdir.'/'.$file;
8894:
8895: my @parts=split(/\//,$targetdir);
8896: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8897: for (my $count=5;$count<=$#parts;$count++) {
8898: $path.="/$parts[$count]";
8899: if (!-e $path) {
8900: print $logfile "\nCreating directory ".$path;
8901: mkdir($path,02770);
8902: }
8903: }
8904: my $versionresult;
8905: if (-e $copyfile) {
8906: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8907: } else {
8908: $versionresult = 'ok';
8909: }
8910: if ($versionresult eq 'ok') {
8911: if (copy($source,$copyfile)) {
8912: print $logfile "\nCopied original source to ".$copyfile."\n";
8913: $output = 'ok';
8914: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
8915: push(@{$modified_urls},[$copyfile,$source]);
8916: my $metaoutput =
8917: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8918: unless ($registered_cleanup) {
8919: my $handlers = $r->get_handlers('PerlCleanupHandler');
8920: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8921: $registered_cleanup=1;
8922: }
8923: } else {
8924: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8925: $output = &mt('Failed to copy file to RES space').", $!";
8926: }
8927: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8928: my $inputfile = $filepath.'/'.$file;
8929: my $outfile = $filepath.'/'.'tn-'.$file;
8930: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8931: if ($fullwidth ne '' && $fullheight ne '') {
8932: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8933: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8934: system("convert -sample $thumbsize $inputfile $outfile");
8935: chmod(0660, $filepath.'/tn-'.$file);
8936: if (-e $outfile) {
8937: my $copyfile=$targetdir.'/tn-'.$file;
8938: if (copy($outfile,$copyfile)) {
8939: print $logfile "\nCopied source to ".$copyfile."\n";
8940: my $thumb_metaoutput =
8941: &write_metadata($dom,$confname,$formname,
8942: $targetdir,'tn-'.$file,$logfile);
8943: push(@{$modified_urls},[$copyfile,$outfile]);
8944: unless ($registered_cleanup) {
8945: my $handlers = $r->get_handlers('PerlCleanupHandler');
8946: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8947: $registered_cleanup=1;
8948: }
8949: $madethumb = 1;
8950: } else {
8951: print $logfile "\nUnable to write ".$copyfile.
8952: ':'.$!."\n";
8953: }
8954: }
8955: }
8956: }
8957: }
8958: } else {
8959: $output = $versionresult;
8960: }
8961: }
8962: return ($output,$logourl,$madethumb);
8963: }
8964:
8965: sub logo_versioning {
8966: my ($targetdir,$file,$logfile) = @_;
8967: my $target = $targetdir.'/'.$file;
8968: my ($maxversion,$fn,$extn,$output);
8969: $maxversion = 0;
8970: if ($file =~ /^(.+)\.(\w+)$/) {
8971: $fn=$1;
8972: $extn=$2;
8973: }
8974: opendir(DIR,$targetdir);
8975: while (my $filename=readdir(DIR)) {
8976: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8977: $maxversion=($1>$maxversion)?$1:$maxversion;
8978: }
8979: }
8980: $maxversion++;
8981: print $logfile "\nCreating old version ".$maxversion."\n";
8982: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8983: if (copy($target,$copyfile)) {
8984: print $logfile "Copied old target to ".$copyfile."\n";
8985: $copyfile=$copyfile.'.meta';
8986: if (copy($target.'.meta',$copyfile)) {
8987: print $logfile "Copied old target metadata to ".$copyfile."\n";
8988: $output = 'ok';
8989: } else {
8990: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8991: $output = &mt('Failed to copy old meta').", $!, ";
8992: }
8993: } else {
8994: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8995: $output = &mt('Failed to copy old target').", $!, ";
8996: }
8997: return $output;
8998: }
8999:
9000: sub write_metadata {
9001: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9002: my (%metadatafields,%metadatakeys,$output);
9003: $metadatafields{'title'}=$formname;
9004: $metadatafields{'creationdate'}=time;
9005: $metadatafields{'lastrevisiondate'}=time;
9006: $metadatafields{'copyright'}='public';
9007: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9008: $env{'user.domain'};
9009: $metadatafields{'authorspace'}=$confname.':'.$dom;
9010: $metadatafields{'domain'}=$dom;
9011: {
9012: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9013: my $mfh;
9014: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
9015: foreach (sort(keys(%metadatafields))) {
9016: unless ($_=~/\./) {
9017: my $unikey=$_;
9018: $unikey=~/^([A-Za-z]+)/;
9019: my $tag=$1;
9020: $tag=~tr/A-Z/a-z/;
9021: print $mfh "\n\<$tag";
9022: foreach (split(/\,/,$metadatakeys{$unikey})) {
9023: my $value=$metadatafields{$unikey.'.'.$_};
9024: $value=~s/\"/\'\'/g;
9025: print $mfh ' '.$_.'="'.$value.'"';
9026: }
9027: print $mfh '>'.
9028: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9029: .'</'.$tag.'>';
9030: }
9031: }
9032: $output = 'ok';
9033: print $logfile "\nWrote metadata";
9034: close($mfh);
9035: } else {
9036: print $logfile "\nFailed to open metadata file";
9037: $output = &mt('Could not write metadata');
9038: }
9039: }
9040: return $output;
9041: }
9042:
9043: sub notifysubscribed {
9044: foreach my $targetsource (@{$modified_urls}){
9045: next unless (ref($targetsource) eq 'ARRAY');
9046: my ($target,$source)=@{$targetsource};
9047: if ($source ne '') {
9048: if (open(my $logfh,'>>'.$source.'.log')) {
9049: print $logfh "\nCleanup phase: Notifications\n";
9050: my @subscribed=&subscribed_hosts($target);
9051: foreach my $subhost (@subscribed) {
9052: print $logfh "\nNotifying host ".$subhost.':';
9053: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9054: print $logfh $reply;
9055: }
9056: my @subscribedmeta=&subscribed_hosts("$target.meta");
9057: foreach my $subhost (@subscribedmeta) {
9058: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9059: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9060: $subhost);
9061: print $logfh $reply;
9062: }
9063: print $logfh "\n============ Done ============\n";
9064: close($logfh);
9065: }
9066: }
9067: }
9068: return OK;
9069: }
9070:
9071: sub subscribed_hosts {
9072: my ($target) = @_;
9073: my @subscribed;
9074: if (open(my $fh,"<$target.subscription")) {
9075: while (my $subline=<$fh>) {
9076: if ($subline =~ /^($match_lonid):/) {
9077: my $host = $1;
9078: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9079: unless (grep(/^\Q$host\E$/,@subscribed)) {
9080: push(@subscribed,$host);
9081: }
9082: }
9083: }
9084: }
9085: }
9086: return @subscribed;
9087: }
9088:
9089: sub check_switchserver {
9090: my ($dom,$confname) = @_;
9091: my ($allowed,$switchserver);
9092: my $home = &Apache::lonnet::homeserver($confname,$dom);
9093: if ($home eq 'no_host') {
9094: $home = &Apache::lonnet::domain($dom,'primary');
9095: }
9096: my @ids=&Apache::lonnet::current_machine_ids();
9097: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9098: if (!$allowed) {
9099: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
9100: }
9101: return $switchserver;
9102: }
9103:
9104: sub modify_quotas {
9105: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9106: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
9107: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
9108: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9109: $validationfieldsref);
9110: if ($action eq 'quotas') {
9111: $context = 'tools';
9112: } else {
9113: $context = $action;
9114: }
9115: if ($context eq 'requestcourses') {
9116: @usertools = ('official','unofficial','community','textbook','placement');
9117: @options =('norequest','approval','validate','autolimit');
9118: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9119: %titles = &courserequest_titles();
9120: $toolregexp = join('|',@usertools);
9121: %conditions = &courserequest_conditions();
9122: $confname = $dom.'-domainconfig';
9123: my $servadm = $r->dir_config('lonAdmEMail');
9124: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9125: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9126: &Apache::loncoursequeueadmin::requestcourses_validation_types();
9127: } elsif ($context eq 'requestauthor') {
9128: @usertools = ('author');
9129: %titles = &authorrequest_titles();
9130: } else {
9131: @usertools = ('aboutme','blog','webdav','portfolio');
9132: %titles = &tool_titles();
9133: }
9134: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9135: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9136: foreach my $key (keys(%env)) {
9137: if ($context eq 'requestcourses') {
9138: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9139: my $item = $1;
9140: my $type = $2;
9141: if ($type =~ /^limit_(.+)/) {
9142: $limithash{$item}{$1} = $env{$key};
9143: } else {
9144: $confhash{$item}{$type} = $env{$key};
9145: }
9146: }
9147: } elsif ($context eq 'requestauthor') {
9148: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9149: $confhash{$1} = $env{$key};
9150: }
9151: } else {
9152: if ($key =~ /^form\.quota_(.+)$/) {
9153: $confhash{'defaultquota'}{$1} = $env{$key};
9154: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9155: $confhash{'authorquota'}{$1} = $env{$key};
9156: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
9157: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9158: }
9159: }
9160: }
9161: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
9162: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
9163: @approvalnotify = sort(@approvalnotify);
9164: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
9165: my @crstypes = ('official','unofficial','community','textbook','placement');
9166: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9167: foreach my $type (@hasuniquecode) {
9168: if (grep(/^\Q$type\E$/,@crstypes)) {
9169: $confhash{'uniquecode'}{$type} = 1;
9170: }
9171: }
9172: my (%newbook,%allpos);
9173: if ($context eq 'requestcourses') {
9174: foreach my $type ('textbooks','templates') {
9175: @{$allpos{$type}} = ();
9176: my $invalid;
9177: if ($type eq 'textbooks') {
9178: $invalid = &mt('Invalid LON-CAPA course for textbook');
9179: } else {
9180: $invalid = &mt('Invalid LON-CAPA course for template');
9181: }
9182: if ($env{'form.'.$type.'_addbook'}) {
9183: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9184: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9185: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9186: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9187: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9188: } else {
9189: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9190: my $position = $env{'form.'.$type.'_addbook_pos'};
9191: $position =~ s/\D+//g;
9192: if ($position ne '') {
9193: $allpos{$type}[$position] = $newbook{$type};
9194: }
9195: }
9196: } else {
9197: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9198: }
9199: }
9200: }
9201: }
9202: if (ref($domconfig{$action}) eq 'HASH') {
9203: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9204: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9205: $changes{'notify'}{'approval'} = 1;
9206: }
9207: } else {
9208: if ($confhash{'notify'}{'approval'}) {
9209: $changes{'notify'}{'approval'} = 1;
9210: }
9211: }
9212: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9213: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9214: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9215: unless ($confhash{'uniquecode'}{$crstype}) {
9216: $changes{'uniquecode'} = 1;
9217: }
9218: }
9219: unless ($changes{'uniquecode'}) {
9220: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9221: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9222: $changes{'uniquecode'} = 1;
9223: }
9224: }
9225: }
9226: } else {
9227: $changes{'uniquecode'} = 1;
9228: }
9229: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9230: $changes{'uniquecode'} = 1;
9231: }
9232: if ($context eq 'requestcourses') {
9233: foreach my $type ('textbooks','templates') {
9234: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9235: my %deletions;
9236: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9237: if (@todelete) {
9238: map { $deletions{$_} = 1; } @todelete;
9239: }
9240: my %imgdeletions;
9241: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9242: if (@todeleteimages) {
9243: map { $imgdeletions{$_} = 1; } @todeleteimages;
9244: }
9245: my $maxnum = $env{'form.'.$type.'_maxnum'};
9246: for (my $i=0; $i<=$maxnum; $i++) {
9247: my $itemid = $env{'form.'.$type.'_id_'.$i};
9248: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9249: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9250: if ($deletions{$key}) {
9251: if ($domconfig{$action}{$type}{$key}{'image'}) {
9252: #FIXME need to obsolete item in RES space
9253: }
9254: next;
9255: } else {
9256: my $newpos = $env{'form.'.$itemid};
9257: $newpos =~ s/\D+//g;
9258: foreach my $item ('subject','title','publisher','author') {
9259: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9260: ($type eq 'templates'));
9261: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9262: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9263: $changes{$type}{$key} = 1;
9264: }
9265: }
9266: $allpos{$type}[$newpos] = $key;
9267: }
9268: if ($imgdeletions{$key}) {
9269: $changes{$type}{$key} = 1;
9270: #FIXME need to obsolete item in RES space
9271: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9272: my ($cdom,$cnum) = split(/_/,$key);
9273: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9274: $cdom,$cnum,$type,$configuserok,
9275: $switchserver,$author_ok);
9276: if ($imgurl) {
9277: $confhash{$type}{$key}{'image'} = $imgurl;
9278: $changes{$type}{$key} = 1;
9279: }
9280: if ($error) {
9281: &Apache::lonnet::logthis($error);
9282: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9283: }
9284: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9285: $confhash{$type}{$key}{'image'} =
9286: $domconfig{$action}{$type}{$key}{'image'};
9287: }
9288: }
9289: }
9290: }
9291: }
9292: }
9293: } else {
9294: if ($confhash{'notify'}{'approval'}) {
9295: $changes{'notify'}{'approval'} = 1;
9296: }
9297: if (ref($confhash{'uniquecode'} eq 'HASH')) {
9298: $changes{'uniquecode'} = 1;
9299: }
9300: }
9301: if ($context eq 'requestcourses') {
9302: foreach my $type ('textbooks','templates') {
9303: if ($newbook{$type}) {
9304: $changes{$type}{$newbook{$type}} = 1;
9305: foreach my $item ('subject','title','publisher','author') {
9306: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9307: ($type eq 'template'));
9308: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9309: if ($env{'form.'.$type.'_addbook_'.$item}) {
9310: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9311: }
9312: }
9313: if ($type eq 'textbooks') {
9314: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9315: my ($cdom,$cnum) = split(/_/,$newbook{$type});
9316: my ($imageurl,$error) =
9317: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9318: $configuserok,$switchserver,$author_ok);
9319: if ($imageurl) {
9320: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9321: }
9322: if ($error) {
9323: &Apache::lonnet::logthis($error);
9324: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9325: }
9326: }
9327: }
9328: }
9329: if (@{$allpos{$type}} > 0) {
9330: my $idx = 0;
9331: foreach my $item (@{$allpos{$type}}) {
9332: if ($item ne '') {
9333: $confhash{$type}{$item}{'order'} = $idx;
9334: if (ref($domconfig{$action}) eq 'HASH') {
9335: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9336: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9337: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9338: $changes{$type}{$item} = 1;
9339: }
9340: }
9341: }
9342: }
9343: $idx ++;
9344: }
9345: }
9346: }
9347: }
9348: if (ref($validationitemsref) eq 'ARRAY') {
9349: foreach my $item (@{$validationitemsref}) {
9350: if ($item eq 'fields') {
9351: my @changed;
9352: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9353: if (@{$confhash{'validation'}{$item}} > 0) {
9354: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9355: }
9356: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9357: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9358: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9359: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9360: $domconfig{'requestcourses'}{'validation'}{$item});
9361: } else {
9362: @changed = @{$confhash{'validation'}{$item}};
9363: }
9364: } else {
9365: @changed = @{$confhash{'validation'}{$item}};
9366: }
9367: } else {
9368: @changed = @{$confhash{'validation'}{$item}};
9369: }
9370: if (@changed) {
9371: if ($confhash{'validation'}{$item}) {
9372: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9373: } else {
9374: $changes{'validation'}{$item} = &mt('None');
9375: }
9376: }
9377: } else {
9378: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9379: if ($item eq 'markup') {
9380: if ($env{'form.requestcourses_validation_'.$item}) {
9381: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9382: }
9383: }
9384: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9385: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9386: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9387: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9388: }
9389: } else {
9390: if ($confhash{'validation'}{$item} ne '') {
9391: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9392: }
9393: }
9394: } else {
9395: if ($confhash{'validation'}{$item} ne '') {
9396: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9397: }
9398: }
9399: }
9400: }
9401: }
9402: if ($env{'form.validationdc'}) {
9403: my $newval = $env{'form.validationdc'};
9404: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
9405: if (exists($domcoords{$newval})) {
9406: $confhash{'validation'}{'dc'} = $newval;
9407: }
9408: }
9409: if (ref($confhash{'validation'}) eq 'HASH') {
9410: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9411: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9412: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9413: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9414: if ($confhash{'validation'}{'dc'} eq '') {
9415: $changes{'validation'}{'dc'} = &mt('None');
9416: } else {
9417: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9418: }
9419: }
9420: } elsif ($confhash{'validation'}{'dc'} ne '') {
9421: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9422: }
9423: } elsif ($confhash{'validation'}{'dc'} ne '') {
9424: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9425: }
9426: } elsif ($confhash{'validation'}{'dc'} ne '') {
9427: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9428: }
9429: } else {
9430: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9431: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9432: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9433: $changes{'validation'}{'dc'} = &mt('None');
9434: }
9435: }
9436: }
9437: }
9438: }
9439: } else {
9440: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
9441: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
9442: }
9443: foreach my $item (@usertools) {
9444: foreach my $type (@{$types},'default','_LC_adv') {
9445: my $unset;
9446: if ($context eq 'requestcourses') {
9447: $unset = '0';
9448: if ($type eq '_LC_adv') {
9449: $unset = '';
9450: }
9451: if ($confhash{$item}{$type} eq 'autolimit') {
9452: $confhash{$item}{$type} .= '=';
9453: unless ($limithash{$item}{$type} =~ /\D/) {
9454: $confhash{$item}{$type} .= $limithash{$item}{$type};
9455: }
9456: }
9457: } elsif ($context eq 'requestauthor') {
9458: $unset = '0';
9459: if ($type eq '_LC_adv') {
9460: $unset = '';
9461: }
9462: } else {
9463: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9464: $confhash{$item}{$type} = 1;
9465: } else {
9466: $confhash{$item}{$type} = 0;
9467: }
9468: }
9469: if (ref($domconfig{$action}) eq 'HASH') {
9470: if ($action eq 'requestauthor') {
9471: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9472: $changes{$type} = 1;
9473: }
9474: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
9475: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9476: $changes{$item}{$type} = 1;
9477: }
9478: } else {
9479: if ($context eq 'requestcourses') {
9480: if ($confhash{$item}{$type} ne $unset) {
9481: $changes{$item}{$type} = 1;
9482: }
9483: } else {
9484: if (!$confhash{$item}{$type}) {
9485: $changes{$item}{$type} = 1;
9486: }
9487: }
9488: }
9489: } else {
9490: if ($context eq 'requestcourses') {
9491: if ($confhash{$item}{$type} ne $unset) {
9492: $changes{$item}{$type} = 1;
9493: }
9494: } elsif ($context eq 'requestauthor') {
9495: if ($confhash{$type} ne $unset) {
9496: $changes{$type} = 1;
9497: }
9498: } else {
9499: if (!$confhash{$item}{$type}) {
9500: $changes{$item}{$type} = 1;
9501: }
9502: }
9503: }
9504: }
9505: }
9506: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
9507: if (ref($domconfig{'quotas'}) eq 'HASH') {
9508: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9509: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9510: if (exists($confhash{'defaultquota'}{$key})) {
9511: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9512: $changes{'defaultquota'}{$key} = 1;
9513: }
9514: } else {
9515: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
9516: }
9517: }
9518: } else {
9519: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9520: if (exists($confhash{'defaultquota'}{$key})) {
9521: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9522: $changes{'defaultquota'}{$key} = 1;
9523: }
9524: } else {
9525: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
9526: }
9527: }
9528: }
9529: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9530: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9531: if (exists($confhash{'authorquota'}{$key})) {
9532: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9533: $changes{'authorquota'}{$key} = 1;
9534: }
9535: } else {
9536: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9537: }
9538: }
9539: }
9540: }
9541: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9542: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9543: if (ref($domconfig{'quotas'}) eq 'HASH') {
9544: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9545: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9546: $changes{'defaultquota'}{$key} = 1;
9547: }
9548: } else {
9549: if (!exists($domconfig{'quotas'}{$key})) {
9550: $changes{'defaultquota'}{$key} = 1;
9551: }
9552: }
9553: } else {
9554: $changes{'defaultquota'}{$key} = 1;
9555: }
9556: }
9557: }
9558: if (ref($confhash{'authorquota'}) eq 'HASH') {
9559: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9560: if (ref($domconfig{'quotas'}) eq 'HASH') {
9561: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9562: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9563: $changes{'authorquota'}{$key} = 1;
9564: }
9565: } else {
9566: $changes{'authorquota'}{$key} = 1;
9567: }
9568: } else {
9569: $changes{'authorquota'}{$key} = 1;
9570: }
9571: }
9572: }
9573: }
9574:
9575: if ($context eq 'requestauthor') {
9576: $domdefaults{'requestauthor'} = \%confhash;
9577: } else {
9578: foreach my $key (keys(%confhash)) {
9579: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
9580: $domdefaults{$key} = $confhash{$key};
9581: }
9582: }
9583: }
9584:
9585: my %quotahash = (
9586: $action => { %confhash }
9587: );
9588: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9589: $dom);
9590: if ($putresult eq 'ok') {
9591: if (keys(%changes) > 0) {
9592: my $cachetime = 24*60*60;
9593: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
9594: if (ref($lastactref) eq 'HASH') {
9595: $lastactref->{'domdefaults'} = 1;
9596: }
9597: $resulttext = &mt('Changes made:').'<ul>';
9598: unless (($context eq 'requestcourses') ||
9599: ($context eq 'requestauthor')) {
9600: if (ref($changes{'defaultquota'}) eq 'HASH') {
9601: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9602: foreach my $type (@{$types},'default') {
9603: if (defined($changes{'defaultquota'}{$type})) {
9604: my $typetitle = $usertypes->{$type};
9605: if ($type eq 'default') {
9606: $typetitle = $othertitle;
9607: }
9608: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
9609: }
9610: }
9611: $resulttext .= '</ul></li>';
9612: }
9613: if (ref($changes{'authorquota'}) eq 'HASH') {
9614: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
9615: foreach my $type (@{$types},'default') {
9616: if (defined($changes{'authorquota'}{$type})) {
9617: my $typetitle = $usertypes->{$type};
9618: if ($type eq 'default') {
9619: $typetitle = $othertitle;
9620: }
9621: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
9622: }
9623: }
9624: $resulttext .= '</ul></li>';
9625: }
9626: }
9627: my %newenv;
9628: foreach my $item (@usertools) {
9629: my (%haschgs,%inconf);
9630: if ($context eq 'requestauthor') {
9631: %haschgs = %changes;
9632: %inconf = %confhash;
9633: } else {
9634: if (ref($changes{$item}) eq 'HASH') {
9635: %haschgs = %{$changes{$item}};
9636: }
9637: if (ref($confhash{$item}) eq 'HASH') {
9638: %inconf = %{$confhash{$item}};
9639: }
9640: }
9641: if (keys(%haschgs) > 0) {
9642: my $newacc =
9643: &Apache::lonnet::usertools_access($env{'user.name'},
9644: $env{'user.domain'},
9645: $item,'reload',$context);
9646: if (($context eq 'requestcourses') ||
9647: ($context eq 'requestauthor')) {
9648: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9649: $newenv{'environment.canrequest.'.$item} = $newacc;
9650: }
9651: } else {
9652: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9653: $newenv{'environment.availabletools.'.$item} = $newacc;
9654: }
9655: }
9656: unless ($context eq 'requestauthor') {
9657: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9658: }
9659: foreach my $type (@{$types},'default','_LC_adv') {
9660: if ($haschgs{$type}) {
9661: my $typetitle = $usertypes->{$type};
9662: if ($type eq 'default') {
9663: $typetitle = $othertitle;
9664: } elsif ($type eq '_LC_adv') {
9665: $typetitle = 'LON-CAPA Advanced Users';
9666: }
9667: if ($inconf{$type}) {
9668: if ($context eq 'requestcourses') {
9669: my $cond;
9670: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
9671: if ($1 eq '') {
9672: $cond = &mt('(Automatic processing of any request).');
9673: } else {
9674: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9675: }
9676: } else {
9677: $cond = $conditions{$inconf{$type}};
9678: }
9679: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
9680: } elsif ($context eq 'requestauthor') {
9681: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9682: $titles{$inconf{$type}},$typetitle);
9683:
9684: } else {
9685: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9686: }
9687: } else {
9688: if ($type eq '_LC_adv') {
9689: if ($inconf{$type} eq '0') {
9690: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9691: } else {
9692: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9693: }
9694: } else {
9695: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9696: }
9697: }
9698: }
9699: }
9700: unless ($context eq 'requestauthor') {
9701: $resulttext .= '</ul></li>';
9702: }
9703: }
9704: }
9705: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
9706: if (ref($changes{'notify'}) eq 'HASH') {
9707: if ($changes{'notify'}{'approval'}) {
9708: if (ref($confhash{'notify'}) eq 'HASH') {
9709: if ($confhash{'notify'}{'approval'}) {
9710: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9711: } else {
9712: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
9713: }
9714: }
9715: }
9716: }
9717: }
9718: if ($action eq 'requestcourses') {
9719: my @offon = ('off','on');
9720: if ($changes{'uniquecode'}) {
9721: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9722: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9723: $resulttext .= '<li>'.
9724: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9725: '</li>';
9726: } else {
9727: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9728: '</li>';
9729: }
9730: }
9731: foreach my $type ('textbooks','templates') {
9732: if (ref($changes{$type}) eq 'HASH') {
9733: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9734: foreach my $key (sort(keys(%{$changes{$type}}))) {
9735: my %coursehash = &Apache::lonnet::coursedescription($key);
9736: my $coursetitle = $coursehash{'description'};
9737: my $position = $confhash{$type}{$key}{'order'} + 1;
9738: $resulttext .= '<li>';
9739: foreach my $item ('subject','title','publisher','author') {
9740: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9741: ($type eq 'templates'));
9742: my $name = $item.':';
9743: $name =~ s/^(\w)/\U$1/;
9744: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9745: }
9746: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9747: if ($type eq 'textbooks') {
9748: if ($confhash{$type}{$key}{'image'}) {
9749: $resulttext .= ' '.&mt('Image: [_1]',
9750: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9751: ' alt="Textbook cover" />').'<br />';
9752: }
9753: }
9754: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
9755: }
9756: $resulttext .= '</ul></li>';
9757: }
9758: }
9759: if (ref($changes{'validation'}) eq 'HASH') {
9760: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9761: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9762: foreach my $item (@{$validationitemsref}) {
9763: if (exists($changes{'validation'}{$item})) {
9764: if ($item eq 'markup') {
9765: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9766: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9767: } else {
9768: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9769: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9770: }
9771: }
9772: }
9773: if (exists($changes{'validation'}{'dc'})) {
9774: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9775: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9776: }
9777: }
9778: }
9779: }
9780: $resulttext .= '</ul>';
9781: if (keys(%newenv)) {
9782: &Apache::lonnet::appenv(\%newenv);
9783: }
9784: } else {
9785: if ($context eq 'requestcourses') {
9786: $resulttext = &mt('No changes made to rights to request creation of courses.');
9787: } elsif ($context eq 'requestauthor') {
9788: $resulttext = &mt('No changes made to rights to request author space.');
9789: } else {
9790: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
9791: }
9792: }
9793: } else {
9794: $resulttext = '<span class="LC_error">'.
9795: &mt('An error occurred: [_1]',$putresult).'</span>';
9796: }
9797: if ($errors) {
9798: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9799: '<ul>'.$errors.'</ul></p>';
9800: }
9801: return $resulttext;
9802: }
9803:
9804: sub process_textbook_image {
9805: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
9806: my $filename = $env{'form.'.$caller.'.filename'};
9807: my ($error,$url);
9808: my ($width,$height) = (50,50);
9809: if ($configuserok eq 'ok') {
9810: if ($switchserver) {
9811: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9812: $switchserver);
9813: } elsif ($author_ok eq 'ok') {
9814: my ($result,$imageurl) =
9815: &publishlogo($r,'upload',$caller,$dom,$confname,
9816: "$type/$dom/$cnum/cover",$width,$height);
9817: if ($result eq 'ok') {
9818: $url = $imageurl;
9819: } else {
9820: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9821: }
9822: } else {
9823: $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);
9824: }
9825: } else {
9826: $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);
9827: }
9828: return ($url,$error);
9829: }
9830:
9831: sub modify_ltitools {
9832: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9833: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9834: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
9835: my $confname = $dom.'-domainconfig';
9836: my $servadm = $r->dir_config('lonAdmEMail');
9837: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9838: my (%posslti,%possfield);
9839: my @courseroles = ('cc','in','ta','ep','st');
9840: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9841: map { $posslti{$_} = 1; } @ltiroles;
9842: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9843: map { $possfield{$_} = 1; } @allfields;
9844: my %lt = <itools_names();
9845: if ($env{'form.ltitools_add'}) {
9846: my $title = $env{'form.ltitools_add_title'};
9847: $title =~ s/(`)/'/g;
9848: ($newid,my $error) = &get_ltitools_id($dom,$title);
9849: if ($newid) {
9850: my $position = $env{'form.ltitools_add_pos'};
9851: $position =~ s/\D+//g;
9852: if ($position ne '') {
9853: $allpos[$position] = $newid;
9854: }
9855: $changes{$newid} = 1;
9856: foreach my $item ('title','url','key','secret') {
9857: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9858: if ($env{'form.ltitools_add_'.$item}) {
9859: if (($item eq 'key') || ($item eq 'secret')) {
9860: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9861: } else {
9862: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9863: }
9864: }
9865: }
9866: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9867: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9868: }
9869: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9870: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9871: }
9872: foreach my $item ('width','height','linktext','explanation') {
9873: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9874: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9875: if (($item eq 'width') || ($item eq 'height')) {
9876: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9877: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9878: }
9879: } else {
9880: if ($env{'form.ltitools_add_'.$item} ne '') {
9881: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9882: }
9883: }
9884: }
9885: if ($env{'form.ltitools_add_target'} eq 'window') {
9886: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9887: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9888: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9889: } else {
9890: $confhash{$newid}{'display'}{'target'} = 'iframe';
9891: }
9892: foreach my $item ('passback','roster') {
9893: if ($env{'form.ltitools_add_'.$item}) {
9894: $confhash{$newid}{$item} = 1;
9895: }
9896: }
9897: if ($env{'form.ltitools_add_image.filename'} ne '') {
9898: my ($imageurl,$error) =
9899: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
9900: $configuserok,$switchserver,$author_ok);
9901: if ($imageurl) {
9902: $confhash{$newid}{'image'} = $imageurl;
9903: }
9904: if ($error) {
9905: &Apache::lonnet::logthis($error);
9906: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9907: }
9908: }
9909: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9910: foreach my $field (@fields) {
9911: if ($possfield{$field}) {
9912: if ($field eq 'roles') {
9913: foreach my $role (@courseroles) {
9914: my $choice = $env{'form.ltitools_add_roles_'.$role};
9915: if (($choice ne '') && ($posslti{$choice})) {
9916: $confhash{$newid}{'roles'}{$role} = $choice;
9917: if ($role eq 'cc') {
9918: $confhash{$newid}{'roles'}{'co'} = $choice;
9919: }
9920: }
9921: }
9922: } else {
9923: $confhash{$newid}{'fields'}{$field} = 1;
9924: }
9925: }
9926: }
9927: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9928: foreach my $item (@courseconfig) {
9929: $confhash{$newid}{'crsconf'}{$item} = 1;
9930: }
9931: if ($env{'form.ltitools_add_custom'}) {
9932: my $name = $env{'form.ltitools_add_custom_name'};
9933: my $value = $env{'form.ltitools_add_custom_value'};
9934: $value =~ s/(`)/'/g;
9935: $name =~ s/(`)/'/g;
9936: $confhash{$newid}{'custom'}{$name} = $value;
9937: }
9938: } else {
9939: my $error = &mt('Failed to acquire unique ID for new external tool');
9940: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9941: }
9942: }
9943: if (ref($domconfig{$action}) eq 'HASH') {
9944: my %deletions;
9945: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9946: if (@todelete) {
9947: map { $deletions{$_} = 1; } @todelete;
9948: }
9949: my %customadds;
9950: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9951: if (@newcustom) {
9952: map { $customadds{$_} = 1; } @newcustom;
9953: }
9954: my %imgdeletions;
9955: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9956: if (@todeleteimages) {
9957: map { $imgdeletions{$_} = 1; } @todeleteimages;
9958: }
9959: my $maxnum = $env{'form.ltitools_maxnum'};
9960: for (my $i=0; $i<=$maxnum; $i++) {
9961: my $itemid = $env{'form.ltitools_id_'.$i};
9962: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9963: if ($deletions{$itemid}) {
9964: if ($domconfig{$action}{$itemid}{'image'}) {
9965: #FIXME need to obsolete item in RES space
9966: }
9967: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9968: next;
9969: } else {
9970: my $newpos = $env{'form.ltitools_'.$itemid};
9971: $newpos =~ s/\D+//g;
9972: foreach my $item ('title','url') {
9973: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9974: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9975: $changes{$itemid} = 1;
9976: }
9977: }
9978: foreach my $item ('key','secret') {
9979: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9980: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9981: $changes{$itemid} = 1;
9982: }
9983: }
9984: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9985: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9986: }
9987: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9988: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9989: }
9990: foreach my $size ('width','height') {
9991: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9992: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9993: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9994: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9995: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9996: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9997: $changes{$itemid} = 1;
9998: }
9999: } else {
10000: $changes{$itemid} = 1;
10001: }
10002: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10003: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10004: $changes{$itemid} = 1;
10005: }
10006: }
10007: }
10008: foreach my $item ('linktext','explanation') {
10009: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10010: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10011: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10012: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10013: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10014: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10015: $changes{$itemid} = 1;
10016: }
10017: } else {
10018: $changes{$itemid} = 1;
10019: }
10020: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10021: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10022: $changes{$itemid} = 1;
10023: }
10024: }
10025: }
10026: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10027: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10028: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10029: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
10030: } else {
10031: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10032: }
10033: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10034: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10035: $changes{$itemid} = 1;
10036: }
10037: } else {
10038: $changes{$itemid} = 1;
10039: }
10040: foreach my $extra ('passback','roster') {
10041: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10042: $confhash{$itemid}{$extra} = 1;
10043: }
10044: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10045: $changes{$itemid} = 1;
10046: }
10047: }
10048: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
10049: foreach my $item ('label','title','target','linktext','explanation') {
10050: if (grep(/^\Q$item\E$/,@courseconfig)) {
10051: $confhash{$itemid}{'crsconf'}{$item} = 1;
10052: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10053: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10054: $changes{$itemid} = 1;
10055: }
10056: } else {
10057: $changes{$itemid} = 1;
10058: }
10059: }
10060: }
10061: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10062: foreach my $field (@fields) {
10063: if ($possfield{$field}) {
10064: if ($field eq 'roles') {
10065: foreach my $role (@courseroles) {
10066: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10067: if (($choice ne '') && ($posslti{$choice})) {
10068: $confhash{$itemid}{'roles'}{$role} = $choice;
10069: if ($role eq 'cc') {
10070: $confhash{$itemid}{'roles'}{'co'} = $choice;
10071: }
10072: }
10073: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10074: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10075: $changes{$itemid} = 1;
10076: }
10077: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10078: $changes{$itemid} = 1;
10079: }
10080: }
10081: } else {
10082: $confhash{$itemid}{'fields'}{$field} = 1;
10083: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10084: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10085: $changes{$itemid} = 1;
10086: }
10087: } else {
10088: $changes{$itemid} = 1;
10089: }
10090: }
10091: }
10092: }
10093: $allpos[$newpos] = $itemid;
10094: }
10095: if ($imgdeletions{$itemid}) {
10096: $changes{$itemid} = 1;
10097: #FIXME need to obsolete item in RES space
10098: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10099: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10100: $itemid,$configuserok,$switchserver,
10101: $author_ok);
10102: if ($imgurl) {
10103: $confhash{$itemid}{'image'} = $imgurl;
10104: $changes{$itemid} = 1;
10105: }
10106: if ($error) {
10107: &Apache::lonnet::logthis($error);
10108: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10109: }
10110: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10111: $confhash{$itemid}{'image'} =
10112: $domconfig{$action}{$itemid}{'image'};
10113: }
10114: if ($customadds{$i}) {
10115: my $name = $env{'form.ltitools_custom_name_'.$i};
10116: $name =~ s/(`)/'/g;
10117: $name =~ s/^\s+//;
10118: $name =~ s/\s+$//;
10119: my $value = $env{'form.ltitools_custom_value_'.$i};
10120: $value =~ s/(`)/'/g;
10121: $value =~ s/^\s+//;
10122: $value =~ s/\s+$//;
10123: if ($name ne '') {
10124: $confhash{$itemid}{'custom'}{$name} = $value;
10125: $changes{$itemid} = 1;
10126: }
10127: }
10128: my %customdels;
10129: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10130: if (@customdeletions) {
10131: $changes{$itemid} = 1;
10132: }
10133: map { $customdels{$_} = 1; } @customdeletions;
10134: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10135: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10136: unless ($customdels{$key}) {
10137: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10138: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10139: }
10140: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10141: $changes{$itemid} = 1;
10142: }
10143: }
10144: }
10145: }
10146: unless ($changes{$itemid}) {
10147: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10148: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10149: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10150: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10151: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10152: $changes{$itemid} = 1;
10153: last;
10154: }
10155: }
10156: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10157: $changes{$itemid} = 1;
10158: }
10159: }
10160: last if ($changes{$itemid});
10161: }
10162: }
10163: }
10164: }
10165: }
10166: if (@allpos > 0) {
10167: my $idx = 0;
10168: foreach my $itemid (@allpos) {
10169: if ($itemid ne '') {
10170: $confhash{$itemid}{'order'} = $idx;
10171: if (ref($domconfig{$action}) eq 'HASH') {
10172: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10173: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10174: $changes{$itemid} = 1;
10175: }
10176: }
10177: }
10178: $idx ++;
10179: }
10180: }
10181: }
10182: my %ltitoolshash = (
10183: $action => { %confhash }
10184: );
10185: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10186: $dom);
10187: if ($putresult eq 'ok') {
10188: my %ltienchash = (
10189: $action => { %encconfig }
10190: );
10191: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
10192: if (keys(%changes) > 0) {
10193: my $cachetime = 24*60*60;
10194: my %ltiall = %confhash;
10195: foreach my $id (keys(%ltiall)) {
10196: if (ref($encconfig{$id}) eq 'HASH') {
10197: foreach my $item ('key','secret') {
10198: $ltiall{$id}{$item} = $encconfig{$id}{$item};
10199: }
10200: }
10201: }
10202: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
10203: if (ref($lastactref) eq 'HASH') {
10204: $lastactref->{'ltitools'} = 1;
10205: }
10206: $resulttext = &mt('Changes made:').'<ul>';
10207: my %bynum;
10208: foreach my $itemid (sort(keys(%changes))) {
10209: my $position = $confhash{$itemid}{'order'};
10210: $bynum{$position} = $itemid;
10211: }
10212: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10213: my $itemid = $bynum{$pos};
10214: if (ref($confhash{$itemid}) ne 'HASH') {
10215: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10216: } else {
10217: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10218: if ($confhash{$itemid}{'image'}) {
10219: $resulttext .= ' '.
10220: '<img src="'.$confhash{$itemid}{'image'}.'"'.
10221: ' alt="'.&mt('Tool Provider icon').'" />';
10222: }
10223: $resulttext .= '</li><ul>';
10224: my $position = $pos + 1;
10225: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10226: foreach my $item ('version','msgtype','url') {
10227: if ($confhash{$itemid}{$item} ne '') {
10228: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10229: }
10230: }
10231: if ($encconfig{$itemid}{'key'} ne '') {
10232: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10233: }
10234: if ($encconfig{$itemid}{'secret'} ne '') {
10235: $resulttext .= '<li>'.$lt{'secret'}.': ';
10236: my $num = length($encconfig{$itemid}{'secret'});
10237: $resulttext .= ('*'x$num).'</li>';
10238: }
10239: $resulttext .= '<li>'.&mt('Configurable in course:');
10240: my @possconfig = ('label','title','target','linktext','explanation');
10241: my $numconfig = 0;
10242: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10243: foreach my $item (@possconfig) {
10244: if ($confhash{$itemid}{'crsconf'}{$item}) {
10245: $numconfig ++;
10246: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
10247: }
10248: }
10249: }
10250: if (!$numconfig) {
10251: $resulttext .= &mt('None');
10252: }
10253: $resulttext .= '</li>';
10254: foreach my $item ('passback','roster') {
10255: $resulttext .= '<li>'.$lt{$item}.' ';
10256: if ($confhash{$itemid}{$item}) {
10257: $resulttext .= &mt('Yes');
10258: } else {
10259: $resulttext .= &mt('No');
10260: }
10261: $resulttext .= '</li>';
10262: }
10263: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
10264: my $displaylist;
10265: if ($confhash{$itemid}{'display'}{'target'}) {
10266: $displaylist = &mt('Display target').': '.
10267: $confhash{$itemid}{'display'}{'target'}.',';
10268: }
10269: foreach my $size ('width','height') {
10270: if ($confhash{$itemid}{'display'}{$size}) {
10271: $displaylist .= (' 'x2).$lt{$size}.': '.
10272: $confhash{$itemid}{'display'}{$size}.',';
10273: }
10274: }
10275: if ($displaylist) {
10276: $displaylist =~ s/,$//;
10277: $resulttext .= '<li>'.$displaylist.'</li>';
10278: }
10279: foreach my $item ('linktext','explanation') {
10280: if ($confhash{$itemid}{'display'}{$item}) {
10281: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
10282: }
10283: }
10284: }
10285: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10286: my $fieldlist;
10287: foreach my $field (@allfields) {
10288: if ($confhash{$itemid}{'fields'}{$field}) {
10289: $fieldlist .= (' 'x2).$lt{$field}.',';
10290: }
10291: }
10292: if ($fieldlist) {
10293: $fieldlist =~ s/,$//;
10294: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
10295: }
10296: }
10297: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
10298: my $rolemaps;
10299: foreach my $role (@courseroles) {
10300: if ($confhash{$itemid}{'roles'}{$role}) {
10301: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
10302: $confhash{$itemid}{'roles'}{$role}.',';
10303: }
10304: }
10305: if ($rolemaps) {
10306: $rolemaps =~ s/,$//;
10307: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
10308: }
10309: }
10310: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
10311: my $customlist;
10312: if (keys(%{$confhash{$itemid}{'custom'}})) {
10313: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
10314: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
10315: }
10316: }
10317: if ($customlist) {
10318: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
10319: }
10320: }
10321: $resulttext .= '</ul></li>';
10322: }
10323: }
10324: $resulttext .= '</ul>';
10325: } else {
10326: $resulttext = &mt('No changes made.');
10327: }
10328: } else {
10329: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10330: }
10331: if ($errors) {
10332: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10333: $errors.'</ul>';
10334: }
10335: return $resulttext;
10336: }
10337:
10338: sub process_ltitools_image {
10339: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
10340: my $filename = $env{'form.'.$caller.'.filename'};
10341: my ($error,$url);
10342: my ($width,$height) = (21,21);
10343: if ($configuserok eq 'ok') {
10344: if ($switchserver) {
10345: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
10346: $switchserver);
10347: } elsif ($author_ok eq 'ok') {
10348: my ($result,$imageurl,$madethumb) =
10349: &publishlogo($r,'upload',$caller,$dom,$confname,
10350: "ltitools/$itemid/icon",$width,$height);
10351: if ($result eq 'ok') {
10352: if ($madethumb) {
10353: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10354: my $imagethumb = "$path/tn-".$imagefile;
10355: $url = $imagethumb;
10356: } else {
10357: $url = $imageurl;
10358: }
10359: } else {
10360: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10361: }
10362: } else {
10363: $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);
10364: }
10365: } else {
10366: $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);
10367: }
10368: return ($url,$error);
10369: }
10370:
10371: sub get_ltitools_id {
10372: my ($cdom,$title) = @_;
10373: # get lock on ltitools db
10374: my $lockhash = {
10375: lock => $env{'user.name'}.
10376: ':'.$env{'user.domain'},
10377: };
10378: my $tries = 0;
10379: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10380: my ($id,$error);
10381:
10382: while (($gotlock ne 'ok') && ($tries<10)) {
10383: $tries ++;
10384: sleep (0.1);
10385: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10386: }
10387: if ($gotlock eq 'ok') {
10388: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10389: if ($currids{'lock'}) {
10390: delete($currids{'lock'});
10391: if (keys(%currids)) {
10392: my @curr = sort { $a <=> $b } keys(%currids);
10393: if ($curr[-1] =~ /^\d+$/) {
10394: $id = 1 + $curr[-1];
10395: }
10396: } else {
10397: $id = 1;
10398: }
10399: if ($id) {
10400: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10401: $error = 'nostore';
10402: }
10403: } else {
10404: $error = 'nonumber';
10405: }
10406: }
10407: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10408: } else {
10409: $error = 'nolock';
10410: }
10411: return ($id,$error);
10412: }
10413:
10414: sub modify_autoenroll {
10415: my ($dom,$lastactref,%domconfig) = @_;
10416: my ($resulttext,%changes);
10417: my %currautoenroll;
10418: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10419: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10420: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10421: }
10422: }
10423: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10424: my %title = ( run => 'Auto-enrollment active',
10425: sender => 'Sender for notification messages',
10426: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10427: failsafe => 'Failsafe for no drops if institutional data missing for a section');
10428: my @offon = ('off','on');
10429: my $sender_uname = $env{'form.sender_uname'};
10430: my $sender_domain = $env{'form.sender_domain'};
10431: if ($sender_domain eq '') {
10432: $sender_uname = '';
10433: } elsif ($sender_uname eq '') {
10434: $sender_domain = '';
10435: }
10436: my $coowners = $env{'form.autoassign_coowners'};
10437: my $failsafe = $env{'form.autoenroll_failsafe'};
10438: $failsafe =~ s{^\s+|\s+$}{}g;
10439: if ($failsafe =~ /\D/) {
10440: undef($failsafe);
10441: }
10442: my %autoenrollhash = (
10443: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10444: 'sender_uname' => $sender_uname,
10445: 'sender_domain' => $sender_domain,
10446: 'co-owners' => $coowners,
10447: 'autofailsafe' => $failsafe,
10448: }
10449: );
10450: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10451: $dom);
10452: if ($putresult eq 'ok') {
10453: if (exists($currautoenroll{'run'})) {
10454: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10455: $changes{'run'} = 1;
10456: }
10457: } elsif ($autorun) {
10458: if ($env{'form.autoenroll_run'} ne '1') {
10459: $changes{'run'} = 1;
10460: }
10461: }
10462: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
10463: $changes{'sender'} = 1;
10464: }
10465: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
10466: $changes{'sender'} = 1;
10467: }
10468: if ($currautoenroll{'co-owners'} ne '') {
10469: if ($currautoenroll{'co-owners'} ne $coowners) {
10470: $changes{'coowners'} = 1;
10471: }
10472: } elsif ($coowners) {
10473: $changes{'coowners'} = 1;
10474: }
10475: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10476: $changes{'autofailsafe'} = 1;
10477: }
10478: if (keys(%changes) > 0) {
10479: $resulttext = &mt('Changes made:').'<ul>';
10480: if ($changes{'run'}) {
10481: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10482: }
10483: if ($changes{'sender'}) {
10484: if ($sender_uname eq '' || $sender_domain eq '') {
10485: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10486: } else {
10487: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10488: }
10489: }
10490: if ($changes{'coowners'}) {
10491: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10492: &Apache::loncommon::devalidate_domconfig_cache($dom);
10493: if (ref($lastactref) eq 'HASH') {
10494: $lastactref->{'domainconfig'} = 1;
10495: }
10496: }
10497: if ($changes{'autofailsafe'}) {
10498: if ($failsafe ne '') {
10499: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
10500: } else {
10501: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
10502: }
10503: &Apache::lonnet::get_domain_defaults($dom,1);
10504: if (ref($lastactref) eq 'HASH') {
10505: $lastactref->{'domdefaults'} = 1;
10506: }
10507: }
10508: $resulttext .= '</ul>';
10509: } else {
10510: $resulttext = &mt('No changes made to auto-enrollment settings');
10511: }
10512: } else {
10513: $resulttext = '<span class="LC_error">'.
10514: &mt('An error occurred: [_1]',$putresult).'</span>';
10515: }
10516: return $resulttext;
10517: }
10518:
10519: sub modify_autoupdate {
10520: my ($dom,%domconfig) = @_;
10521: my ($resulttext,%currautoupdate,%fields,%changes);
10522: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10523: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10524: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10525: }
10526: }
10527: my @offon = ('off','on');
10528: my %title = &Apache::lonlocal::texthash (
10529: run => 'Auto-update:',
10530: classlists => 'Updates to user information in classlists?'
10531: );
10532: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10533: my %fieldtitles = &Apache::lonlocal::texthash (
10534: id => 'Student/Employee ID',
10535: permanentemail => 'E-mail address',
10536: lastname => 'Last Name',
10537: firstname => 'First Name',
10538: middlename => 'Middle Name',
10539: generation => 'Generation',
10540: );
10541: $othertitle = &mt('All users');
10542: if (keys(%{$usertypes}) > 0) {
10543: $othertitle = &mt('Other users');
10544: }
10545: foreach my $key (keys(%env)) {
10546: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
10547: my ($usertype,$item) = ($1,$2);
10548: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10549: if ($usertype eq 'default') {
10550: push(@{$fields{$1}},$2);
10551: } elsif (ref($types) eq 'ARRAY') {
10552: if (grep(/^\Q$usertype\E$/,@{$types})) {
10553: push(@{$fields{$1}},$2);
10554: }
10555: }
10556: }
10557: }
10558: }
10559: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10560: @lockablenames = sort(@lockablenames);
10561: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10562: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10563: if (@changed) {
10564: $changes{'lockablenames'} = 1;
10565: }
10566: } else {
10567: if (@lockablenames) {
10568: $changes{'lockablenames'} = 1;
10569: }
10570: }
10571: my %updatehash = (
10572: autoupdate => { run => $env{'form.autoupdate_run'},
10573: classlists => $env{'form.classlists'},
10574: fields => {%fields},
10575: lockablenames => \@lockablenames,
10576: }
10577: );
10578: foreach my $key (keys(%currautoupdate)) {
10579: if (($key eq 'run') || ($key eq 'classlists')) {
10580: if (exists($updatehash{autoupdate}{$key})) {
10581: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10582: $changes{$key} = 1;
10583: }
10584: }
10585: } elsif ($key eq 'fields') {
10586: if (ref($currautoupdate{$key}) eq 'HASH') {
10587: foreach my $item (@{$types},'default') {
10588: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10589: my $change = 0;
10590: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10591: if (!exists($fields{$item})) {
10592: $change = 1;
10593: last;
10594: } elsif (ref($fields{$item}) eq 'ARRAY') {
10595: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
10596: $change = 1;
10597: last;
10598: }
10599: }
10600: }
10601: if ($change) {
10602: push(@{$changes{$key}},$item);
10603: }
10604: }
10605: }
10606: }
10607: } elsif ($key eq 'lockablenames') {
10608: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10609: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10610: if (@changed) {
10611: $changes{'lockablenames'} = 1;
10612: }
10613: } else {
10614: if (@lockablenames) {
10615: $changes{'lockablenames'} = 1;
10616: }
10617: }
10618: }
10619: }
10620: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10621: if (@lockablenames) {
10622: $changes{'lockablenames'} = 1;
10623: }
10624: }
10625: foreach my $item (@{$types},'default') {
10626: if (defined($fields{$item})) {
10627: if (ref($currautoupdate{'fields'}) eq 'HASH') {
10628: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10629: my $change = 0;
10630: if (ref($fields{$item}) eq 'ARRAY') {
10631: foreach my $type (@{$fields{$item}}) {
10632: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10633: $change = 1;
10634: last;
10635: }
10636: }
10637: }
10638: if ($change) {
10639: push(@{$changes{'fields'}},$item);
10640: }
10641: } else {
10642: push(@{$changes{'fields'}},$item);
10643: }
10644: } else {
10645: push(@{$changes{'fields'}},$item);
10646: }
10647: }
10648: }
10649: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10650: $dom);
10651: if ($putresult eq 'ok') {
10652: if (keys(%changes) > 0) {
10653: $resulttext = &mt('Changes made:').'<ul>';
10654: foreach my $key (sort(keys(%changes))) {
10655: if ($key eq 'lockablenames') {
10656: $resulttext .= '<li>';
10657: if (@lockablenames) {
10658: $usertypes->{'default'} = $othertitle;
10659: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10660: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10661: } else {
10662: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10663: }
10664: $resulttext .= '</li>';
10665: } elsif (ref($changes{$key}) eq 'ARRAY') {
10666: foreach my $item (@{$changes{$key}}) {
10667: my @newvalues;
10668: foreach my $type (@{$fields{$item}}) {
10669: push(@newvalues,$fieldtitles{$type});
10670: }
10671: my $newvaluestr;
10672: if (@newvalues > 0) {
10673: $newvaluestr = join(', ',@newvalues);
10674: } else {
10675: $newvaluestr = &mt('none');
10676: }
10677: if ($item eq 'default') {
10678: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
10679: } else {
10680: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
10681: }
10682: }
10683: } else {
10684: my $newvalue;
10685: if ($key eq 'run') {
10686: $newvalue = $offon[$env{'form.autoupdate_run'}];
10687: } else {
10688: $newvalue = $offon[$env{'form.'.$key}];
10689: }
10690: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10691: }
10692: }
10693: $resulttext .= '</ul>';
10694: } else {
10695: $resulttext = &mt('No changes made to autoupdates');
10696: }
10697: } else {
10698: $resulttext = '<span class="LC_error">'.
10699: &mt('An error occurred: [_1]',$putresult).'</span>';
10700: }
10701: return $resulttext;
10702: }
10703:
10704: sub modify_autocreate {
10705: my ($dom,%domconfig) = @_;
10706: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10707: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10708: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10709: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10710: }
10711: }
10712: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10713: req => 'Auto-creation of validated requests for official courses',
10714: xmldc => 'Identity of course creator of courses from XML files',
10715: );
10716: my @types = ('xml','req');
10717: foreach my $item (@types) {
10718: $newvals{$item} = $env{'form.autocreate_'.$item};
10719: $newvals{$item} =~ s/\D//g;
10720: $newvals{$item} = 0 if ($newvals{$item} eq '');
10721: }
10722: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
10723: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
10724: unless (exists($domcoords{$newvals{'xmldc'}})) {
10725: $newvals{'xmldc'} = '';
10726: }
10727: %autocreatehash = (
10728: autocreate => { xml => $newvals{'xml'},
10729: req => $newvals{'req'},
10730: }
10731: );
10732: if ($newvals{'xmldc'} ne '') {
10733: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10734: }
10735: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10736: $dom);
10737: if ($putresult eq 'ok') {
10738: my @items = @types;
10739: if ($newvals{'xml'}) {
10740: push(@items,'xmldc');
10741: }
10742: foreach my $item (@items) {
10743: if (exists($currautocreate{$item})) {
10744: if ($currautocreate{$item} ne $newvals{$item}) {
10745: $changes{$item} = 1;
10746: }
10747: } elsif ($newvals{$item}) {
10748: $changes{$item} = 1;
10749: }
10750: }
10751: if (keys(%changes) > 0) {
10752: my @offon = ('off','on');
10753: $resulttext = &mt('Changes made:').'<ul>';
10754: foreach my $item (@types) {
10755: if ($changes{$item}) {
10756: my $newtxt = $offon[$newvals{$item}];
10757: $resulttext .= '<li>'.
10758: &mt("$title{$item} set to [_1]$newtxt [_2]",
10759: '<b>','</b>').
10760: '</li>';
10761: }
10762: }
10763: if ($changes{'xmldc'}) {
10764: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10765: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
10766: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
10767: }
10768: $resulttext .= '</ul>';
10769: } else {
10770: $resulttext = &mt('No changes made to auto-creation settings');
10771: }
10772: } else {
10773: $resulttext = '<span class="LC_error">'.
10774: &mt('An error occurred: [_1]',$putresult).'</span>';
10775: }
10776: return $resulttext;
10777: }
10778:
10779: sub modify_directorysrch {
10780: my ($dom,$lastactref,%domconfig) = @_;
10781: my ($resulttext,%changes);
10782: my %currdirsrch;
10783: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10784: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10785: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10786: }
10787: }
10788: my %title = ( available => 'Institutional directory search available',
10789: localonly => 'Other domains can search institution',
10790: lcavailable => 'LON-CAPA directory search available',
10791: lclocalonly => 'Other domains can search LON-CAPA domain',
10792: searchby => 'Search types',
10793: searchtypes => 'Search latitude');
10794: my @offon = ('off','on');
10795: my @otherdoms = ('Yes','No');
10796:
10797: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
10798: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10799: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10800:
10801: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10802: if (keys(%{$usertypes}) == 0) {
10803: @cansearch = ('default');
10804: } else {
10805: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10806: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10807: if (!grep(/^\Q$type\E$/,@cansearch)) {
10808: push(@{$changes{'cansearch'}},$type);
10809: }
10810: }
10811: foreach my $type (@cansearch) {
10812: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10813: push(@{$changes{'cansearch'}},$type);
10814: }
10815: }
10816: } else {
10817: push(@{$changes{'cansearch'}},@cansearch);
10818: }
10819: }
10820:
10821: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10822: foreach my $by (@{$currdirsrch{'searchby'}}) {
10823: if (!grep(/^\Q$by\E$/,@searchby)) {
10824: push(@{$changes{'searchby'}},$by);
10825: }
10826: }
10827: foreach my $by (@searchby) {
10828: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10829: push(@{$changes{'searchby'}},$by);
10830: }
10831: }
10832: } else {
10833: push(@{$changes{'searchby'}},@searchby);
10834: }
10835:
10836: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10837: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10838: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10839: push(@{$changes{'searchtypes'}},$type);
10840: }
10841: }
10842: foreach my $type (@searchtypes) {
10843: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10844: push(@{$changes{'searchtypes'}},$type);
10845: }
10846: }
10847: } else {
10848: if (exists($currdirsrch{'searchtypes'})) {
10849: foreach my $type (@searchtypes) {
10850: if ($type ne $currdirsrch{'searchtypes'}) {
10851: push(@{$changes{'searchtypes'}},$type);
10852: }
10853: }
10854: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10855: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10856: }
10857: } else {
10858: push(@{$changes{'searchtypes'}},@searchtypes);
10859: }
10860: }
10861:
10862: my %dirsrch_hash = (
10863: directorysrch => { available => $env{'form.dirsrch_available'},
10864: cansearch => \@cansearch,
10865: localonly => $env{'form.dirsrch_instlocalonly'},
10866: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10867: lcavailable => $env{'form.dirsrch_domavailable'},
10868: searchby => \@searchby,
10869: searchtypes => \@searchtypes,
10870: }
10871: );
10872: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10873: $dom);
10874: if ($putresult eq 'ok') {
10875: if (exists($currdirsrch{'available'})) {
10876: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10877: $changes{'available'} = 1;
10878: }
10879: } else {
10880: if ($env{'form.dirsrch_available'} eq '1') {
10881: $changes{'available'} = 1;
10882: }
10883: }
10884: if (exists($currdirsrch{'lcavailable'})) {
10885: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10886: $changes{'lcavailable'} = 1;
10887: }
10888: } else {
10889: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10890: $changes{'lcavailable'} = 1;
10891: }
10892: }
10893: if (exists($currdirsrch{'localonly'})) {
10894: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10895: $changes{'localonly'} = 1;
10896: }
10897: } else {
10898: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10899: $changes{'localonly'} = 1;
10900: }
10901: }
10902: if (exists($currdirsrch{'lclocalonly'})) {
10903: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10904: $changes{'lclocalonly'} = 1;
10905: }
10906: } else {
10907: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10908: $changes{'lclocalonly'} = 1;
10909: }
10910: }
10911: if (keys(%changes) > 0) {
10912: $resulttext = &mt('Changes made:').'<ul>';
10913: if ($changes{'available'}) {
10914: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10915: }
10916: if ($changes{'lcavailable'}) {
10917: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10918: }
10919: if ($changes{'localonly'}) {
10920: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10921: }
10922: if ($changes{'lclocalonly'}) {
10923: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
10924: }
10925: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10926: my $chgtext;
10927: if (ref($usertypes) eq 'HASH') {
10928: if (keys(%{$usertypes}) > 0) {
10929: foreach my $type (@{$types}) {
10930: if (grep(/^\Q$type\E$/,@cansearch)) {
10931: $chgtext .= $usertypes->{$type}.'; ';
10932: }
10933: }
10934: if (grep(/^default$/,@cansearch)) {
10935: $chgtext .= $othertitle;
10936: } else {
10937: $chgtext =~ s/\; $//;
10938: }
10939: $resulttext .=
10940: '<li>'.
10941: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10942: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10943: '</li>';
10944: }
10945: }
10946: }
10947: if (ref($changes{'searchby'}) eq 'ARRAY') {
10948: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10949: my $chgtext;
10950: foreach my $type (@{$titleorder}) {
10951: if (grep(/^\Q$type\E$/,@searchby)) {
10952: if (defined($searchtitles->{$type})) {
10953: $chgtext .= $searchtitles->{$type}.'; ';
10954: }
10955: }
10956: }
10957: $chgtext =~ s/\; $//;
10958: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10959: }
10960: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10961: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10962: my $chgtext;
10963: foreach my $type (@{$srchtypeorder}) {
10964: if (grep(/^\Q$type\E$/,@searchtypes)) {
10965: if (defined($srchtypes_desc->{$type})) {
10966: $chgtext .= $srchtypes_desc->{$type}.'; ';
10967: }
10968: }
10969: }
10970: $chgtext =~ s/\; $//;
10971: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
10972: }
10973: $resulttext .= '</ul>';
10974: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10975: if (ref($lastactref) eq 'HASH') {
10976: $lastactref->{'directorysrch'} = 1;
10977: }
10978: } else {
10979: $resulttext = &mt('No changes made to directory search settings');
10980: }
10981: } else {
10982: $resulttext = '<span class="LC_error">'.
10983: &mt('An error occurred: [_1]',$putresult).'</span>';
10984: }
10985: return $resulttext;
10986: }
10987:
10988: sub modify_contacts {
10989: my ($dom,$lastactref,%domconfig) = @_;
10990: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10991: if (ref($domconfig{'contacts'}) eq 'HASH') {
10992: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10993: $currsetting{$key} = $domconfig{'contacts'}{$key};
10994: }
10995: }
10996: my (%others,%to,%bcc,%includestr,%includeloc);
10997: my @contacts = ('supportemail','adminemail');
10998: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10999: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
11000: my @toggles = ('reporterrors','reportupdates');
11001: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
11002: foreach my $type (@mailings) {
11003: @{$newsetting{$type}} =
11004: &Apache::loncommon::get_env_multiple('form.'.$type);
11005: foreach my $item (@contacts) {
11006: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11007: $contacts_hash{contacts}{$type}{$item} = 1;
11008: } else {
11009: $contacts_hash{contacts}{$type}{$item} = 0;
11010: }
11011: }
11012: $others{$type} = $env{'form.'.$type.'_others'};
11013: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
11014: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
11015: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11016: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
11017: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11018: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11019: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11020: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11021: }
11022: }
11023: }
11024: foreach my $item (@contacts) {
11025: $to{$item} = $env{'form.'.$item};
11026: $contacts_hash{'contacts'}{$item} = $to{$item};
11027: }
11028: foreach my $item (@toggles) {
11029: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11030: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11031: }
11032: }
11033: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11034: foreach my $field (@{$fields}) {
11035: if (ref($possoptions->{$field}) eq 'ARRAY') {
11036: my $value = $env{'form.helpform_'.$field};
11037: $value =~ s/^\s+|\s+$//g;
11038: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
11039: $contacts_hash{contacts}{'helpform'}{$field} = $value;
11040: if ($field eq 'screenshot') {
11041: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11042: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
11043: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
11044: }
11045: }
11046: }
11047: }
11048: }
11049: }
11050: if (keys(%currsetting) > 0) {
11051: foreach my $item (@contacts) {
11052: if ($to{$item} ne $currsetting{$item}) {
11053: $changes{$item} = 1;
11054: }
11055: }
11056: foreach my $type (@mailings) {
11057: foreach my $item (@contacts) {
11058: if (ref($currsetting{$type}) eq 'HASH') {
11059: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11060: push(@{$changes{$type}},$item);
11061: }
11062: } else {
11063: push(@{$changes{$type}},@{$newsetting{$type}});
11064: }
11065: }
11066: if ($others{$type} ne $currsetting{$type}{'others'}) {
11067: push(@{$changes{$type}},'others');
11068: }
11069: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
11070: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11071: push(@{$changes{$type}},'bcc');
11072: }
11073: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11074: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11075: push(@{$changes{$type}},'include');
11076: }
11077: }
11078: }
11079: if (ref($fields) eq 'ARRAY') {
11080: if (ref($currsetting{'helpform'}) eq 'HASH') {
11081: foreach my $field (@{$fields}) {
11082: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11083: push(@{$changes{'helpform'}},$field);
11084: }
11085: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11086: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11087: push(@{$changes{'helpform'}},'maxsize');
11088: }
11089: }
11090: }
11091: } else {
11092: foreach my $field (@{$fields}) {
11093: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11094: push(@{$changes{'helpform'}},$field);
11095: }
11096: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11097: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11098: push(@{$changes{'helpform'}},'maxsize');
11099: }
11100: }
11101: }
11102: }
11103: }
11104: } else {
11105: my %default;
11106: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
11107: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
11108: $default{'errormail'} = 'adminemail';
11109: $default{'packagesmail'} = 'adminemail';
11110: $default{'helpdeskmail'} = 'supportemail';
11111: $default{'otherdomsmail'} = 'supportemail';
11112: $default{'lonstatusmail'} = 'adminemail';
11113: $default{'requestsmail'} = 'adminemail';
11114: $default{'updatesmail'} = 'adminemail';
11115: foreach my $item (@contacts) {
11116: if ($to{$item} ne $default{$item}) {
11117: $changes{$item} = 1;
11118: }
11119: }
11120: foreach my $type (@mailings) {
11121: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
11122: push(@{$changes{$type}},@{$newsetting{$type}});
11123: }
11124: if ($others{$type} ne '') {
11125: push(@{$changes{$type}},'others');
11126: }
11127: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
11128: if ($bcc{$type} ne '') {
11129: push(@{$changes{$type}},'bcc');
11130: }
11131: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
11132: push(@{$changes{$type}},'include');
11133: }
11134: }
11135: }
11136: if (ref($fields) eq 'ARRAY') {
11137: foreach my $field (@{$fields}) {
11138: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11139: push(@{$changes{'helpform'}},$field);
11140: }
11141: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11142: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11143: push(@{$changes{'helpform'}},'maxsize');
11144: }
11145: }
11146: }
11147: }
11148: }
11149: foreach my $item (@toggles) {
11150: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
11151: $changes{$item} = 1;
11152: } elsif ((!$env{'form.'.$item}) &&
11153: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
11154: $changes{$item} = 1;
11155: }
11156: }
11157: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
11158: $dom);
11159: if ($putresult eq 'ok') {
11160: if (keys(%changes) > 0) {
11161: &Apache::loncommon::devalidate_domconfig_cache($dom);
11162: if (ref($lastactref) eq 'HASH') {
11163: $lastactref->{'domainconfig'} = 1;
11164: }
11165: my ($titles,$short_titles) = &contact_titles();
11166: $resulttext = &mt('Changes made:').'<ul>';
11167: foreach my $item (@contacts) {
11168: if ($changes{$item}) {
11169: $resulttext .= '<li>'.$titles->{$item}.
11170: &mt(' set to: ').
11171: '<span class="LC_cusr_emph">'.
11172: $to{$item}.'</span></li>';
11173: }
11174: }
11175: foreach my $type (@mailings) {
11176: if (ref($changes{$type}) eq 'ARRAY') {
11177: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
11178: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
11179: } else {
11180: $resulttext .= '<li>'.$titles->{$type}.': ';
11181: }
11182: my @text;
11183: foreach my $item (@{$newsetting{$type}}) {
11184: push(@text,$short_titles->{$item});
11185: }
11186: if ($others{$type} ne '') {
11187: push(@text,$others{$type});
11188: }
11189: if (@text) {
11190: $resulttext .= '<span class="LC_cusr_emph">'.
11191: join(', ',@text).'</span>';
11192: }
11193: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
11194: if ($bcc{$type} ne '') {
11195: my $bcctext;
11196: if (@text) {
11197: $bcctext = ' '.&mt('with Bcc to');
11198: } else {
11199: $bcctext = '(Bcc)';
11200: }
11201: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
11202: } elsif (!@text) {
11203: $resulttext .= &mt('No one');
11204: }
11205: if ($includestr{$type} ne '') {
11206: if ($includeloc{$type} eq 'b') {
11207: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
11208: } elsif ($includeloc{$type} eq 's') {
11209: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
11210: }
11211: }
11212: } elsif (!@text) {
11213: $resulttext .= &mt('No recipients');
11214: }
11215: $resulttext .= '</li>';
11216: }
11217: }
11218: my @offon = ('off','on');
11219: if ($changes{'reporterrors'}) {
11220: $resulttext .= '<li>'.
11221: &mt('E-mail error reports to [_1] set to "'.
11222: $offon[$env{'form.reporterrors'}].'".',
11223: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11224: &mt('LON-CAPA core group - MSU'),600,500)).
11225: '</li>';
11226: }
11227: if ($changes{'reportupdates'}) {
11228: $resulttext .= '<li>'.
11229: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
11230: $offon[$env{'form.reportupdates'}].'".',
11231: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11232: &mt('LON-CAPA core group - MSU'),600,500)).
11233: '</li>';
11234: }
11235: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11236: my (@optional,@required,@unused,$maxsizechg);
11237: foreach my $field (@{$changes{'helpform'}}) {
11238: if ($field eq 'maxsize') {
11239: $maxsizechg = 1;
11240: next;
11241: }
11242: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
11243: push(@optional,$field);
11244: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11245: push(@unused,$field);
11246: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
11247: push(@required,$field);
11248: }
11249: }
11250: if (@optional) {
11251: $resulttext .= '<li>'.
11252: &mt('Help form fields changed to "Optional": [_1].',
11253: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11254: '</li>';
11255: }
11256: if (@required) {
11257: $resulttext .= '<li>'.
11258: &mt('Help form fields changed to "Required": [_1].',
11259: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11260: '</li>';
11261: }
11262: if (@unused) {
11263: $resulttext .= '<li>'.
11264: &mt('Help form fields changed to "Not shown": [_1].',
11265: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11266: '</li>';
11267: }
11268: if ($maxsizechg) {
11269: $resulttext .= '<li>'.
11270: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11271: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11272: '</li>';
11273:
11274: }
11275: }
11276: $resulttext .= '</ul>';
11277: } else {
11278: $resulttext = &mt('No changes made to contacts and form settings');
11279: }
11280: } else {
11281: $resulttext = '<span class="LC_error">'.
11282: &mt('An error occurred: [_1].',$putresult).'</span>';
11283: }
11284: return $resulttext;
11285: }
11286:
11287: sub modify_usercreation {
11288: my ($dom,%domconfig) = @_;
11289: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
11290: my $warningmsg;
11291: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11292: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11293: if ($key eq 'cancreate') {
11294: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11295: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11296: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
11297: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11298: } else {
11299: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11300: }
11301: }
11302: }
11303: } elsif ($key eq 'email_rule') {
11304: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11305: } else {
11306: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11307: }
11308: }
11309: }
11310: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
11311: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
11312: my @contexts = ('author','course','requestcrs');
11313: foreach my $item(@contexts) {
11314: $cancreate{$item} = $env{'form.can_createuser_'.$item};
11315: }
11316: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11317: foreach my $item (@contexts) {
11318: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11319: push(@{$changes{'cancreate'}},$item);
11320: }
11321: }
11322: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11323: foreach my $item (@contexts) {
11324: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
11325: if ($cancreate{$item} ne 'any') {
11326: push(@{$changes{'cancreate'}},$item);
11327: }
11328: } else {
11329: if ($cancreate{$item} ne 'none') {
11330: push(@{$changes{'cancreate'}},$item);
11331: }
11332: }
11333: }
11334: } else {
11335: foreach my $item (@contexts) {
11336: push(@{$changes{'cancreate'}},$item);
11337: }
11338: }
11339:
11340: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11341: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11342: if (!grep(/^\Q$type\E$/,@username_rule)) {
11343: push(@{$changes{'username_rule'}},$type);
11344: }
11345: }
11346: foreach my $type (@username_rule) {
11347: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11348: push(@{$changes{'username_rule'}},$type);
11349: }
11350: }
11351: } else {
11352: push(@{$changes{'username_rule'}},@username_rule);
11353: }
11354:
11355: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11356: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11357: if (!grep(/^\Q$type\E$/,@id_rule)) {
11358: push(@{$changes{'id_rule'}},$type);
11359: }
11360: }
11361: foreach my $type (@id_rule) {
11362: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11363: push(@{$changes{'id_rule'}},$type);
11364: }
11365: }
11366: } else {
11367: push(@{$changes{'id_rule'}},@id_rule);
11368: }
11369:
11370: my @authen_contexts = ('author','course','domain');
11371: my @authtypes = ('int','krb4','krb5','loc');
11372: my %authhash;
11373: foreach my $item (@authen_contexts) {
11374: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11375: foreach my $auth (@authtypes) {
11376: if (grep(/^\Q$auth\E$/,@authallowed)) {
11377: $authhash{$item}{$auth} = 1;
11378: } else {
11379: $authhash{$item}{$auth} = 0;
11380: }
11381: }
11382: }
11383: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
11384: foreach my $item (@authen_contexts) {
11385: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11386: foreach my $auth (@authtypes) {
11387: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11388: push(@{$changes{'authtypes'}},$item);
11389: last;
11390: }
11391: }
11392: }
11393: }
11394: } else {
11395: foreach my $item (@authen_contexts) {
11396: push(@{$changes{'authtypes'}},$item);
11397: }
11398: }
11399:
11400: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11401: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11402: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11403: $save_usercreate{'id_rule'} = \@id_rule;
11404: $save_usercreate{'username_rule'} = \@username_rule,
11405: $save_usercreate{'authtypes'} = \%authhash;
11406:
11407: my %usercreation_hash = (
11408: usercreation => \%save_usercreate,
11409: );
11410:
11411: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11412: $dom);
11413:
11414: if ($putresult eq 'ok') {
11415: if (keys(%changes) > 0) {
11416: $resulttext = &mt('Changes made:').'<ul>';
11417: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11418: my %lt = &usercreation_types();
11419: foreach my $type (@{$changes{'cancreate'}}) {
11420: my $chgtext = $lt{$type}.', ';
11421: if ($cancreate{$type} eq 'none') {
11422: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11423: } elsif ($cancreate{$type} eq 'any') {
11424: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11425: } elsif ($cancreate{$type} eq 'official') {
11426: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11427: } elsif ($cancreate{$type} eq 'unofficial') {
11428: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11429: }
11430: $resulttext .= '<li>'.$chgtext.'</li>';
11431: }
11432: }
11433: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11434: my ($rules,$ruleorder) =
11435: &Apache::lonnet::inst_userrules($dom,'username');
11436: my $chgtext = '<ul>';
11437: foreach my $type (@username_rule) {
11438: if (ref($rules->{$type}) eq 'HASH') {
11439: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11440: }
11441: }
11442: $chgtext .= '</ul>';
11443: if (@username_rule > 0) {
11444: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11445: } else {
11446: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11447: }
11448: }
11449: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11450: my ($idrules,$idruleorder) =
11451: &Apache::lonnet::inst_userrules($dom,'id');
11452: my $chgtext = '<ul>';
11453: foreach my $type (@id_rule) {
11454: if (ref($idrules->{$type}) eq 'HASH') {
11455: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11456: }
11457: }
11458: $chgtext .= '</ul>';
11459: if (@id_rule > 0) {
11460: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11461: } else {
11462: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11463: }
11464: }
11465: my %authname = &authtype_names();
11466: my %context_title = &context_names();
11467: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11468: my $chgtext = '<ul>';
11469: foreach my $type (@{$changes{'authtypes'}}) {
11470: my @allowed;
11471: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11472: foreach my $auth (@authtypes) {
11473: if ($authhash{$type}{$auth}) {
11474: push(@allowed,$authname{$auth});
11475: }
11476: }
11477: if (@allowed > 0) {
11478: $chgtext .= join(', ',@allowed).'</li>';
11479: } else {
11480: $chgtext .= &mt('none').'</li>';
11481: }
11482: }
11483: $chgtext .= '</ul>';
11484: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11485: $resulttext .= '</li>';
11486: }
11487: $resulttext .= '</ul>';
11488: } else {
11489: $resulttext = &mt('No changes made to user creation settings');
11490: }
11491: } else {
11492: $resulttext = '<span class="LC_error">'.
11493: &mt('An error occurred: [_1]',$putresult).'</span>';
11494: }
11495: if ($warningmsg ne '') {
11496: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11497: }
11498: return $resulttext;
11499: }
11500:
11501: sub modify_selfcreation {
11502: my ($dom,$lastactref,%domconfig) = @_;
11503: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11504: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11505: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11506: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11507: if (ref($typesref) eq 'ARRAY') {
11508: @types = @{$typesref};
11509: }
11510: if (ref($usertypesref) eq 'HASH') {
11511: %usertypes = %{$usertypesref};
11512: }
11513: $usertypes{'default'} = $othertitle;
11514: #
11515: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11516: #
11517: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11518: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11519: if ($key eq 'cancreate') {
11520: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11521: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11522: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11523: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11524: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11525: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11526: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
11527: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
11528: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11529: } else {
11530: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11531: }
11532: }
11533: }
11534: } elsif ($key eq 'email_rule') {
11535: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11536: } else {
11537: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11538: }
11539: }
11540: }
11541: #
11542: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11543: #
11544: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11545: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11546: if ($key eq 'selfcreate') {
11547: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11548: } else {
11549: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11550: }
11551: }
11552: }
11553: #
11554: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11555: #
11556: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11557: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
11558: if ($key eq 'inststatusguest') {
11559: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
11560: } else {
11561: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
11562: }
11563: }
11564: }
11565:
11566: my @contexts = ('selfcreate');
11567: @{$cancreate{'selfcreate'}} = ();
11568: %{$cancreate{'emailusername'}} = ();
11569: if (@types) {
11570: @{$cancreate{'statustocreate'}} = ();
11571: }
11572: %{$cancreate{'selfcreateprocessing'}} = ();
11573: %{$cancreate{'shibenv'}} = ();
11574: %{$cancreate{'emailverified'}} = ();
11575: %{$cancreate{'emailoptions'}} = ();
11576: %{$cancreate{'emaildomain'}} = ();
11577: my %selfcreatetypes = (
11578: sso => 'users authenticated by institutional single sign on',
11579: login => 'users authenticated by institutional log-in',
11580: email => 'users verified by e-mail',
11581: );
11582: #
11583: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11584: # is permitted.
11585: #
11586: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
11587:
11588: my (@statuses,%email_rule);
11589: foreach my $item ('login','sso','email') {
11590: if ($item eq 'email') {
11591: if ($env{'form.cancreate_email'}) {
11592: if (@types) {
11593: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
11594: foreach my $status (@poss_statuses) {
11595: if (grep(/^\Q$status\E$/,(@types,'default'))) {
11596: push(@statuses,$status);
11597: }
11598: }
11599: $save_inststatus{'inststatusguest'} = \@statuses;
11600: } else {
11601: push(@statuses,'default');
11602: }
11603: if (@statuses) {
11604: my %curr_rule;
11605: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11606: foreach my $type (@statuses) {
11607: $curr_rule{$type} = $curr_usercreation{'email_rule'};
11608: }
11609: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
11610: foreach my $type (@statuses) {
11611: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
11612: }
11613: }
11614: push(@{$cancreate{'selfcreate'}},'email');
11615: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
11616: my %curremaildom;
11617: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
11618: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
11619: }
11620: foreach my $type (@statuses) {
11621: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
11622: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11623: }
11624: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
11625: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
11626: }
11627: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
11628: #
11629: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
11630: #
11631: my $chosen = $1;
11632: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
11633: my $emaildom;
11634: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
11635: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
11636: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
11637: if (ref($curremaildom{$type}) eq 'HASH') {
11638: if (exists($curremaildom{$type}{$chosen})) {
11639: if ($curremaildom{$type}{$chosen} ne $emaildom) {
11640: push(@{$changes{'cancreate'}},'emaildomain');
11641: }
11642: } elsif ($emaildom ne '') {
11643: push(@{$changes{'cancreate'}},'emaildomain');
11644: }
11645: } elsif ($emaildom ne '') {
11646: push(@{$changes{'cancreate'}},'emaildomain');
11647: }
11648: }
11649: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11650: } elsif ($chosen eq 'custom') {
11651: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
11652: $email_rule{$type} = [];
11653: if (ref($emailrules) eq 'HASH') {
11654: foreach my $rule (@possemail_rules) {
11655: if (exists($emailrules->{$rule})) {
11656: push(@{$email_rule{$type}},$rule);
11657: }
11658: }
11659: }
11660: if (@{$email_rule{$type}}) {
11661: $cancreate{'emailoptions'}{$type} = 'custom';
11662: if (ref($curr_rule{$type}) eq 'ARRAY') {
11663: if (@{$curr_rule{$type}} > 0) {
11664: foreach my $rule (@{$curr_rule{$type}}) {
11665: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
11666: push(@{$changes{'email_rule'}},$type);
11667: }
11668: }
11669: }
11670: foreach my $type (@{$email_rule{$type}}) {
11671: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
11672: push(@{$changes{'email_rule'}},$type);
11673: }
11674: }
11675: } else {
11676: push(@{$changes{'email_rule'}},$type);
11677: }
11678: }
11679: } else {
11680: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11681: }
11682: }
11683: }
11684: if (@types) {
11685: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11686: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
11687: if (@changed) {
11688: push(@{$changes{'inststatus'}},'inststatusguest');
11689: }
11690: } else {
11691: push(@{$changes{'inststatus'}},'inststatusguest');
11692: }
11693: }
11694: } else {
11695: delete($env{'form.cancreate_email'});
11696: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11697: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11698: push(@{$changes{'inststatus'}},'inststatusguest');
11699: }
11700: }
11701: }
11702: } else {
11703: $save_inststatus{'inststatusguest'} = [];
11704: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11705: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11706: push(@{$changes{'inststatus'}},'inststatusguest');
11707: }
11708: }
11709: }
11710: } else {
11711: if ($env{'form.cancreate_'.$item}) {
11712: push(@{$cancreate{'selfcreate'}},$item);
11713: }
11714: }
11715: }
11716: my (%userinfo,%savecaptcha);
11717: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11718: #
11719: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11720: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
11721: #
11722:
11723: if ($env{'form.cancreate_email'}) {
11724: push(@contexts,'emailusername');
11725: if (@statuses) {
11726: foreach my $type (@statuses) {
11727: if (ref($infofields) eq 'ARRAY') {
11728: foreach my $field (@{$infofields}) {
11729: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11730: $cancreate{'emailusername'}{$type}{$field} = $1;
11731: }
11732: }
11733: }
11734: }
11735: }
11736: #
11737: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11738: # queued requests for self-creation of account verified by e-mail.
11739: #
11740:
11741: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11742: @approvalnotify = sort(@approvalnotify);
11743: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11744: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11745: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11746: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11747: push(@{$changes{'cancreate'}},'notify');
11748: }
11749: } else {
11750: if ($cancreate{'notify'}{'approval'}) {
11751: push(@{$changes{'cancreate'}},'notify');
11752: }
11753: }
11754: } elsif ($cancreate{'notify'}{'approval'}) {
11755: push(@{$changes{'cancreate'}},'notify');
11756: }
11757:
11758: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11759: }
11760: #
11761: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
11762: # institutional log-in.
11763: #
11764: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11765: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11766: ($domdefaults{'auth_def'} eq 'localauth'))) {
11767: $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.').' '.
11768: &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.');
11769: }
11770: }
11771: my @fields = ('lastname','firstname','middlename','generation',
11772: 'permanentemail','id');
11773: my @shibfields = (@fields,'inststatus');
11774: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11775: #
11776: # Where usernames may created for institutional log-in and/or institutional single sign on:
11777: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11778: # may self-create accounts
11779: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11780: # which the user may supply, if institutional data is unavailable.
11781: #
11782: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11783: if (@types) {
11784: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11785: push(@contexts,'statustocreate');
11786: foreach my $type (@types) {
11787: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11788: foreach my $field (@fields) {
11789: if (grep(/^\Q$field\E$/,@modifiable)) {
11790: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11791: } else {
11792: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11793: }
11794: }
11795: }
11796: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11797: foreach my $type (@types) {
11798: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11799: foreach my $field (@fields) {
11800: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11801: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11802: push(@{$changes{'selfcreate'}},$type);
11803: last;
11804: }
11805: }
11806: }
11807: }
11808: } else {
11809: foreach my $type (@types) {
11810: push(@{$changes{'selfcreate'}},$type);
11811: }
11812: }
11813: }
11814: foreach my $field (@shibfields) {
11815: if ($env{'form.shibenv_'.$field} ne '') {
11816: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11817: }
11818: }
11819: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11820: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11821: foreach my $field (@shibfields) {
11822: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11823: push(@{$changes{'cancreate'}},'shibenv');
11824: }
11825: }
11826: } else {
11827: foreach my $field (@shibfields) {
11828: if ($env{'form.shibenv_'.$field}) {
11829: push(@{$changes{'cancreate'}},'shibenv');
11830: last;
11831: }
11832: }
11833: }
11834: }
11835: }
11836: foreach my $item (@contexts) {
11837: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11838: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11839: if (ref($cancreate{$item}) eq 'ARRAY') {
11840: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11841: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11842: push(@{$changes{'cancreate'}},$item);
11843: }
11844: }
11845: }
11846: }
11847: if (ref($cancreate{$item}) eq 'ARRAY') {
11848: foreach my $type (@{$cancreate{$item}}) {
11849: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11850: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11851: push(@{$changes{'cancreate'}},$item);
11852: }
11853: }
11854: }
11855: }
11856: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11857: if (ref($cancreate{$item}) eq 'HASH') {
11858: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
11859: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11860: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
11861: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
11862: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11863: push(@{$changes{'cancreate'}},$item);
11864: }
11865: }
11866: }
11867: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11868: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
11869: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11870: push(@{$changes{'cancreate'}},$item);
11871: }
11872: }
11873: }
11874: }
11875: foreach my $type (keys(%{$cancreate{$item}})) {
11876: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11877: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11878: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11879: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
11880: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11881: push(@{$changes{'cancreate'}},$item);
11882: }
11883: }
11884: } else {
11885: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11886: push(@{$changes{'cancreate'}},$item);
11887: }
11888: }
11889: }
11890: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11891: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
11892: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11893: push(@{$changes{'cancreate'}},$item);
11894: }
11895: }
11896: }
11897: }
11898: }
11899: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11900: if (ref($cancreate{$item}) eq 'ARRAY') {
11901: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11902: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11903: push(@{$changes{'cancreate'}},$item);
11904: }
11905: }
11906: }
11907: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11908: if (ref($cancreate{$item}) eq 'HASH') {
11909: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11910: push(@{$changes{'cancreate'}},$item);
11911: }
11912: }
11913: } elsif ($item eq 'emailusername') {
11914: if (ref($cancreate{$item}) eq 'HASH') {
11915: foreach my $type (keys(%{$cancreate{$item}})) {
11916: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11917: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11918: if ($cancreate{$item}{$type}{$field}) {
11919: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11920: push(@{$changes{'cancreate'}},$item);
11921: }
11922: last;
11923: }
11924: }
11925: }
11926: }
11927: }
11928: }
11929: }
11930: #
11931: # Populate %save_usercreate hash with updates to self-creation configuration.
11932: #
11933: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11934: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
11935: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
11936: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11937: if (ref($cancreate{'notify'}) eq 'HASH') {
11938: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11939: }
11940: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11941: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11942: }
11943: if (ref($cancreate{'emailverified'}) eq 'HASH') {
11944: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
11945: }
11946: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
11947: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
11948: }
11949: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
11950: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
11951: }
11952: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11953: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11954: }
11955: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11956: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11957: }
11958: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11959: $save_usercreate{'email_rule'} = \%email_rule;
11960:
11961: my %userconfig_hash = (
11962: usercreation => \%save_usercreate,
11963: usermodification => \%save_usermodify,
11964: inststatus => \%save_inststatus,
11965: );
11966:
11967: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11968: $dom);
11969: #
11970: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
11971: #
11972: if ($putresult eq 'ok') {
11973: if (keys(%changes) > 0) {
11974: $resulttext = &mt('Changes made:').'<ul>';
11975: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11976: my %lt = &selfcreation_types();
11977: foreach my $type (@{$changes{'cancreate'}}) {
11978: my $chgtext = '';
11979: if ($type eq 'selfcreate') {
11980: if (@{$cancreate{$type}} == 0) {
11981: $chgtext .= &mt('Self creation of a new user account is not permitted.');
11982: } else {
11983: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11984: '<ul>';
11985: foreach my $case (@{$cancreate{$type}}) {
11986: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11987: }
11988: $chgtext .= '</ul>';
11989: if (ref($cancreate{$type}) eq 'ARRAY') {
11990: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11991: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11992: if (@{$cancreate{'statustocreate'}} == 0) {
11993: $chgtext .= '<span class="LC_warning">'.
11994: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
11995: '</span><br />';
11996: }
11997: }
11998: }
11999: if (grep(/^email$/,@{$cancreate{$type}})) {
12000: if (!@statuses) {
12001: $chgtext .= '<span class="LC_warning">'.
12002: &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.").
12003: '</span><br />';
12004:
12005: }
12006: }
12007: }
12008: }
12009: } elsif ($type eq 'shibenv') {
12010: if (keys(%{$cancreate{$type}}) == 0) {
12011: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
12012: } else {
12013: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
12014: '<ul>';
12015: foreach my $field (@shibfields) {
12016: next if ($cancreate{$type}{$field} eq '');
12017: if ($field eq 'inststatus') {
12018: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
12019: } else {
12020: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
12021: }
12022: }
12023: $chgtext .= '</ul>';
12024: }
12025: } elsif ($type eq 'statustocreate') {
12026: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
12027: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
12028: if (@{$cancreate{'selfcreate'}} > 0) {
12029: if (@{$cancreate{'statustocreate'}} == 0) {
12030: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
12031: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
12032: $chgtext .= '<br />'.
12033: '<span class="LC_warning">'.
12034: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
12035: '</span>';
12036: }
12037: } elsif (keys(%usertypes) > 0) {
12038: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
12039: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
12040: } else {
12041: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
12042: }
12043: $chgtext .= '<ul>';
12044: foreach my $case (@{$cancreate{$type}}) {
12045: if ($case eq 'default') {
12046: $chgtext .= '<li>'.$othertitle.'</li>';
12047: } else {
12048: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
12049: }
12050: }
12051: $chgtext .= '</ul>';
12052: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
12053: $chgtext .= '<span class="LC_warning">'.
12054: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
12055: '</span>';
12056: }
12057: }
12058: } else {
12059: if (@{$cancreate{$type}} == 0) {
12060: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
12061: } else {
12062: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
12063: }
12064: }
12065: $chgtext .= '<br />';
12066: }
12067: } elsif ($type eq 'selfcreateprocessing') {
12068: my %choices = &Apache::lonlocal::texthash (
12069: automatic => 'Automatic approval',
12070: approval => 'Queued for approval',
12071: );
12072: if (@types) {
12073: if (@statuses) {
12074: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
12075: '<ul>';
12076: foreach my $status (@statuses) {
12077: if ($status eq 'default') {
12078: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
12079: } else {
12080: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
12081: }
12082: }
12083: $chgtext .= '</ul>';
12084: }
12085: } else {
12086: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
12087: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
12088: }
12089: } elsif ($type eq 'emailverified') {
12090: my %options = &Apache::lonlocal::texthash (
12091: all => 'Same as e-mail',
12092: first => 'Omit @domain',
12093: free => 'Free to choose',
12094: );
12095: if (@types) {
12096: if (@statuses) {
12097: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
12098: '<ul>';
12099: foreach my $status (@statuses) {
12100: if ($type eq 'default') {
12101: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
12102: } else {
12103: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
12104: }
12105: }
12106: $chgtext .= '</ul>';
12107: }
12108: } else {
12109: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
12110: $options{$cancreate{'emailverified'}{'default'}});
12111: }
12112: } elsif ($type eq 'emailoptions') {
12113: my %options = &Apache::lonlocal::texthash (
12114: any => 'Any e-mail',
12115: inst => 'Institutional only',
12116: noninst => 'Non-institutional only',
12117: custom => 'Custom restrictions',
12118: );
12119: if (@types) {
12120: if (@statuses) {
12121: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
12122: '<ul>';
12123: foreach my $status (@statuses) {
12124: if ($type eq 'default') {
12125: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12126: } else {
12127: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12128: }
12129: }
12130: $chgtext .= '</ul>';
12131: }
12132: } else {
12133: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
12134: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
12135: } else {
12136: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
12137: $options{$cancreate{'emailoptions'}{'default'}});
12138: }
12139: }
12140: } elsif ($type eq 'emaildomain') {
12141: my $output;
12142: if (@statuses) {
12143: foreach my $type (@statuses) {
12144: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
12145: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
12146: if ($type eq 'default') {
12147: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12148: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12149: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12150: } else {
12151: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
12152: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12153: }
12154: } else {
12155: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12156: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12157: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12158: } else {
12159: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
12160: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12161: }
12162: }
12163: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
12164: if ($type eq 'default') {
12165: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12166: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12167: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12168: } else {
12169: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
12170: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12171: }
12172: } else {
12173: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12174: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12175: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12176: } else {
12177: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
12178: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12179: }
12180: }
12181: }
12182: }
12183: }
12184: }
12185: if ($output ne '') {
12186: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
12187: '<ul>'.$output.'</ul>';
12188: }
12189: } elsif ($type eq 'captcha') {
12190: if ($savecaptcha{$type} eq 'notused') {
12191: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
12192: } else {
12193: my %captchas = &captcha_phrases();
12194: if ($captchas{$savecaptcha{$type}}) {
12195: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
12196: } else {
12197: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
12198: }
12199: }
12200: } elsif ($type eq 'recaptchakeys') {
12201: my ($privkey,$pubkey);
12202: if (ref($savecaptcha{$type}) eq 'HASH') {
12203: $pubkey = $savecaptcha{$type}{'public'};
12204: $privkey = $savecaptcha{$type}{'private'};
12205: }
12206: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
12207: if (!$pubkey) {
12208: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
12209: } else {
12210: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12211: }
12212: if (!$privkey) {
12213: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
12214: } else {
12215: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
12216: }
12217: $chgtext .= '</ul>';
12218: } elsif ($type eq 'recaptchaversion') {
12219: if ($savecaptcha{'captcha'} eq 'recaptcha') {
12220: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
12221: }
12222: } elsif ($type eq 'emailusername') {
12223: if (ref($cancreate{'emailusername'}) eq 'HASH') {
12224: if (@statuses) {
12225: foreach my $type (@statuses) {
12226: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
12227: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
12228: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
12229: '<ul>';
12230: foreach my $field (@{$infofields}) {
12231: if ($cancreate{'emailusername'}{$type}{$field}) {
12232: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
12233: }
12234: }
12235: $chgtext .= '</ul>';
12236: } else {
12237: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
12238: }
12239: } else {
12240: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
12241: }
12242: }
12243: }
12244: }
12245: } elsif ($type eq 'notify') {
12246: my $numapprove = 0;
12247: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12248: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
12249: if ($cancreate{'notify'}{'approval'}) {
12250: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
12251: $numapprove ++;
12252: }
12253: }
12254: }
12255: unless ($numapprove) {
12256: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12257: }
12258: }
12259: if ($chgtext) {
12260: $resulttext .= '<li>'.$chgtext.'</li>';
12261: }
12262: }
12263: }
12264: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
12265: my ($emailrules,$emailruleorder) =
12266: &Apache::lonnet::inst_userrules($dom,'email');
12267: foreach my $type (@{$changes{'email_rule'}}) {
12268: if (ref($email_rule{$type}) eq 'ARRAY') {
12269: my $chgtext = '<ul>';
12270: foreach my $rule (@{$email_rule{$type}}) {
12271: if (ref($emailrules->{$rule}) eq 'HASH') {
12272: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12273: }
12274: }
12275: $chgtext .= '</ul>';
12276: if (@types) {
12277: my $typename;
12278: if ($type eq 'default') {
12279: $typename = $othertitle;
12280: } else {
12281: $typename = $usertypes{$type};
12282: }
12283: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12284: }
12285: if (@{$email_rule{$type}} > 0) {
12286: $resulttext .= '<li>'.
12287: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12288: $usertypes{$type}).
12289: $chgtext.
12290: '</li>';
12291: } else {
12292: $resulttext .= '<li>'.
12293: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.',
12294: $usertypes{$type}).
12295: '</li>'.
12296: &mt('(Affiliation: [_1])',$type);
12297: }
12298: }
12299: }
12300: }
12301: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12302: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12303: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12304: my $chgtext = '<ul>';
12305: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12306: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12307: }
12308: $chgtext .= '</ul>';
12309: $resulttext .= '<li>'.
12310: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12311: $chgtext.
12312: '</li>';
12313: } else {
12314: $resulttext .= '<li>'.
12315: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12316: '</li>';
12317: }
12318: }
12319: }
12320: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12321: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12322: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12323: foreach my $type (@{$changes{'selfcreate'}}) {
12324: my $typename = $type;
12325: if (keys(%usertypes) > 0) {
12326: if ($usertypes{$type} ne '') {
12327: $typename = $usertypes{$type};
12328: }
12329: }
12330: my @modifiable;
12331: $resulttext .= '<li>'.
12332: &mt('Self-creation of account by users with status: [_1]',
12333: '<span class="LC_cusr_emph">'.$typename.'</span>').
12334: ' - '.&mt('modifiable fields (if institutional data blank): ');
12335: foreach my $field (@fields) {
12336: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12337: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
12338: }
12339: }
12340: if (@modifiable > 0) {
12341: $resulttext .= join(', ',@modifiable);
12342: } else {
12343: $resulttext .= &mt('none');
12344: }
12345: $resulttext .= '</li>';
12346: }
12347: $resulttext .= '</ul></li>';
12348: }
12349: $resulttext .= '</ul>';
12350: my $cachetime = 24*60*60;
12351: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12352: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12353: if (ref($lastactref) eq 'HASH') {
12354: $lastactref->{'domdefaults'} = 1;
12355: }
12356: } else {
12357: $resulttext = &mt('No changes made to self-creation settings');
12358: }
12359: } else {
12360: $resulttext = '<span class="LC_error">'.
12361: &mt('An error occurred: [_1]',$putresult).'</span>';
12362: }
12363: if ($warningmsg ne '') {
12364: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12365: }
12366: return $resulttext;
12367: }
12368:
12369: sub process_captcha {
12370: my ($container,$changes,$newsettings,$current) = @_;
12371: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12372: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12373: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12374: $newsettings->{'captcha'} = 'original';
12375: }
12376: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
12377: if ($container eq 'cancreate') {
12378: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12379: push(@{$changes->{'cancreate'}},'captcha');
12380: } elsif (!defined($changes->{'cancreate'})) {
12381: $changes->{'cancreate'} = ['captcha'];
12382: }
12383: } else {
12384: $changes->{'captcha'} = 1;
12385: }
12386: }
12387: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
12388: if ($newsettings->{'captcha'} eq 'recaptcha') {
12389: $newpub = $env{'form.'.$container.'_recaptchapub'};
12390: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
12391: $newpub =~ s/[^\w\-]//g;
12392: $newpriv =~ s/[^\w\-]//g;
12393: $newsettings->{'recaptchakeys'} = {
12394: public => $newpub,
12395: private => $newpriv,
12396: };
12397: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12398: $newversion =~ s/\D//g;
12399: if ($newversion ne '2') {
12400: $newversion = 1;
12401: }
12402: $newsettings->{'recaptchaversion'} = $newversion;
12403: }
12404: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12405: $currpub = $current->{'recaptchakeys'}{'public'};
12406: $currpriv = $current->{'recaptchakeys'}{'private'};
12407: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12408: $newsettings->{'recaptchakeys'} = {
12409: public => '',
12410: private => '',
12411: }
12412: }
12413: }
12414: if ($current->{'captcha'} eq 'recaptcha') {
12415: $currversion = $current->{'recaptchaversion'};
12416: if ($currversion ne '2') {
12417: $currversion = 1;
12418: }
12419: }
12420: if ($currversion ne $newversion) {
12421: if ($container eq 'cancreate') {
12422: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12423: push(@{$changes->{'cancreate'}},'recaptchaversion');
12424: } elsif (!defined($changes->{'cancreate'})) {
12425: $changes->{'cancreate'} = ['recaptchaversion'];
12426: }
12427: } else {
12428: $changes->{'recaptchaversion'} = 1;
12429: }
12430: }
12431: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
12432: if ($container eq 'cancreate') {
12433: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12434: push(@{$changes->{'cancreate'}},'recaptchakeys');
12435: } elsif (!defined($changes->{'cancreate'})) {
12436: $changes->{'cancreate'} = ['recaptchakeys'];
12437: }
12438: } else {
12439: $changes->{'recaptchakeys'} = 1;
12440: }
12441: }
12442: return;
12443: }
12444:
12445: sub modify_usermodification {
12446: my ($dom,%domconfig) = @_;
12447: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
12448: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12449: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
12450: if ($key eq 'selfcreate') {
12451: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12452: } else {
12453: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12454: }
12455: }
12456: }
12457: my @contexts = ('author','course');
12458: my %context_title = (
12459: author => 'In author context',
12460: course => 'In course context',
12461: );
12462: my @fields = ('lastname','firstname','middlename','generation',
12463: 'permanentemail','id');
12464: my %roles = (
12465: author => ['ca','aa'],
12466: course => ['st','ep','ta','in','cr'],
12467: );
12468: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12469: foreach my $context (@contexts) {
12470: foreach my $role (@{$roles{$context}}) {
12471: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12472: foreach my $item (@fields) {
12473: if (grep(/^\Q$item\E$/,@modifiable)) {
12474: $modifyhash{$context}{$role}{$item} = 1;
12475: } else {
12476: $modifyhash{$context}{$role}{$item} = 0;
12477: }
12478: }
12479: }
12480: if (ref($curr_usermodification{$context}) eq 'HASH') {
12481: foreach my $role (@{$roles{$context}}) {
12482: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12483: foreach my $field (@fields) {
12484: if ($modifyhash{$context}{$role}{$field} ne
12485: $curr_usermodification{$context}{$role}{$field}) {
12486: push(@{$changes{$context}},$role);
12487: last;
12488: }
12489: }
12490: }
12491: }
12492: } else {
12493: foreach my $context (@contexts) {
12494: foreach my $role (@{$roles{$context}}) {
12495: push(@{$changes{$context}},$role);
12496: }
12497: }
12498: }
12499: }
12500: my %usermodification_hash = (
12501: usermodification => \%modifyhash,
12502: );
12503: my $putresult = &Apache::lonnet::put_dom('configuration',
12504: \%usermodification_hash,$dom);
12505: if ($putresult eq 'ok') {
12506: if (keys(%changes) > 0) {
12507: $resulttext = &mt('Changes made: ').'<ul>';
12508: foreach my $context (@contexts) {
12509: if (ref($changes{$context}) eq 'ARRAY') {
12510: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12511: if (ref($changes{$context}) eq 'ARRAY') {
12512: foreach my $role (@{$changes{$context}}) {
12513: my $rolename;
12514: if ($role eq 'cr') {
12515: $rolename = &mt('Custom');
12516: } else {
12517: $rolename = &Apache::lonnet::plaintext($role);
12518: }
12519: my @modifiable;
12520: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
12521: foreach my $field (@fields) {
12522: if ($modifyhash{$context}{$role}{$field}) {
12523: push(@modifiable,$fieldtitles{$field});
12524: }
12525: }
12526: if (@modifiable > 0) {
12527: $resulttext .= join(', ',@modifiable);
12528: } else {
12529: $resulttext .= &mt('none');
12530: }
12531: $resulttext .= '</li>';
12532: }
12533: $resulttext .= '</ul></li>';
12534: }
12535: }
12536: }
12537: $resulttext .= '</ul>';
12538: } else {
12539: $resulttext = &mt('No changes made to user modification settings');
12540: }
12541: } else {
12542: $resulttext = '<span class="LC_error">'.
12543: &mt('An error occurred: [_1]',$putresult).'</span>';
12544: }
12545: return $resulttext;
12546: }
12547:
12548: sub modify_defaults {
12549: my ($dom,$lastactref,%domconfig) = @_;
12550: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
12551: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12552: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
12553: 'portal_def','intauth_cost','intauth_check','intauth_switch');
12554: my @authtypes = ('internal','krb4','krb5','localauth');
12555: foreach my $item (@items) {
12556: $newvalues{$item} = $env{'form.'.$item};
12557: if ($item eq 'auth_def') {
12558: if ($newvalues{$item} ne '') {
12559: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12560: push(@errors,$item);
12561: }
12562: }
12563: } elsif ($item eq 'lang_def') {
12564: if ($newvalues{$item} ne '') {
12565: if ($newvalues{$item} =~ /^(\w+)/) {
12566: my $langcode = $1;
12567: if ($langcode ne 'x_chef') {
12568: if (code2language($langcode) eq '') {
12569: push(@errors,$item);
12570: }
12571: }
12572: } else {
12573: push(@errors,$item);
12574: }
12575: }
12576: } elsif ($item eq 'timezone_def') {
12577: if ($newvalues{$item} ne '') {
12578: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
12579: push(@errors,$item);
12580: }
12581: }
12582: } elsif ($item eq 'datelocale_def') {
12583: if ($newvalues{$item} ne '') {
12584: my @datelocale_ids = DateTime::Locale->ids();
12585: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12586: push(@errors,$item);
12587: }
12588: }
12589: } elsif ($item eq 'portal_def') {
12590: if ($newvalues{$item} ne '') {
12591: 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])\/?$/) {
12592: push(@errors,$item);
12593: }
12594: }
12595: } elsif ($item eq 'intauth_cost') {
12596: if ($newvalues{$item} ne '') {
12597: if ($newvalues{$item} =~ /\D/) {
12598: push(@errors,$item);
12599: }
12600: }
12601: } elsif ($item eq 'intauth_check') {
12602: if ($newvalues{$item} ne '') {
12603: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12604: push(@errors,$item);
12605: }
12606: }
12607: } elsif ($item eq 'intauth_switch') {
12608: if ($newvalues{$item} ne '') {
12609: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12610: push(@errors,$item);
12611: }
12612: }
12613: }
12614: if (grep(/^\Q$item\E$/,@errors)) {
12615: $newvalues{$item} = $domdefaults{$item};
12616: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12617: $changes{$item} = 1;
12618: }
12619: $domdefaults{$item} = $newvalues{$item};
12620: }
12621: my %defaults_hash = (
12622: defaults => \%newvalues,
12623: );
12624: my $title = &defaults_titles();
12625:
12626: my $currinststatus;
12627: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12628: $currinststatus = $domconfig{'inststatus'};
12629: } else {
12630: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12631: $currinststatus = {
12632: inststatustypes => $usertypes,
12633: inststatusorder => $types,
12634: inststatusguest => [],
12635: };
12636: }
12637: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12638: my @allpos;
12639: my %alltypes;
12640: my @inststatusguest;
12641: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12642: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
12643: unless (grep(/^\Q$type\E$/,@todelete)) {
12644: push(@inststatusguest,$type);
12645: }
12646: }
12647: }
12648: my ($currtitles,$currorder);
12649: if (ref($currinststatus) eq 'HASH') {
12650: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12651: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12652: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12653: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12654: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12655: }
12656: }
12657: unless (grep(/^\Q$type\E$/,@todelete)) {
12658: my $position = $env{'form.inststatus_pos_'.$type};
12659: $position =~ s/\D+//g;
12660: $allpos[$position] = $type;
12661: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12662: $alltypes{$type} =~ s/`//g;
12663: }
12664: }
12665: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12666: $currtitles =~ s/,$//;
12667: }
12668: }
12669: if ($env{'form.addinststatus'}) {
12670: my $newtype = $env{'form.addinststatus'};
12671: $newtype =~ s/\W//g;
12672: unless (exists($alltypes{$newtype})) {
12673: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12674: $alltypes{$newtype} =~ s/`//g;
12675: my $position = $env{'form.addinststatus_pos'};
12676: $position =~ s/\D+//g;
12677: if ($position ne '') {
12678: $allpos[$position] = $newtype;
12679: }
12680: }
12681: }
12682: my @orderedstatus;
12683: foreach my $type (@allpos) {
12684: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12685: push(@orderedstatus,$type);
12686: }
12687: }
12688: foreach my $type (keys(%alltypes)) {
12689: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12690: delete($alltypes{$type});
12691: }
12692: }
12693: $defaults_hash{'inststatus'} = {
12694: inststatustypes => \%alltypes,
12695: inststatusorder => \@orderedstatus,
12696: inststatusguest => \@inststatusguest,
12697: };
12698: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12699: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12700: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12701: }
12702: }
12703: if ($currorder ne join(',',@orderedstatus)) {
12704: $changes{'inststatus'}{'inststatusorder'} = 1;
12705: }
12706: my $newtitles;
12707: foreach my $item (@orderedstatus) {
12708: $newtitles .= $alltypes{$item}.',';
12709: }
12710: $newtitles =~ s/,$//;
12711: if ($currtitles ne $newtitles) {
12712: $changes{'inststatus'}{'inststatustypes'} = 1;
12713: }
12714: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12715: $dom);
12716: if ($putresult eq 'ok') {
12717: if (keys(%changes) > 0) {
12718: $resulttext = &mt('Changes made:').'<ul>';
12719: my $version = &Apache::lonnet::get_server_loncaparev($dom);
12720: 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";
12721: foreach my $item (sort(keys(%changes))) {
12722: if ($item eq 'inststatus') {
12723: if (ref($changes{'inststatus'}) eq 'HASH') {
12724: if (@orderedstatus) {
12725: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12726: foreach my $type (@orderedstatus) {
12727: $resulttext .= $alltypes{$type}.', ';
12728: }
12729: $resulttext =~ s/, $//;
12730: $resulttext .= '</li>';
12731: } else {
12732: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
12733: }
12734: }
12735: } else {
12736: my $value = $env{'form.'.$item};
12737: if ($value eq '') {
12738: $value = &mt('none');
12739: } elsif ($item eq 'auth_def') {
12740: my %authnames = &authtype_names();
12741: my %shortauth = (
12742: internal => 'int',
12743: krb4 => 'krb4',
12744: krb5 => 'krb5',
12745: localauth => 'loc',
12746: );
12747: $value = $authnames{$shortauth{$value}};
12748: } elsif ($item eq 'intauth_switch') {
12749: my %optiondesc = &Apache::lonlocal::texthash (
12750: 0 => 'No',
12751: 1 => 'Yes',
12752: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12753: );
12754: if ($value =~ /^(0|1|2)$/) {
12755: $value = $optiondesc{$value};
12756: } else {
12757: $value = &mt('none -- defaults to No');
12758: }
12759: } elsif ($item eq 'intauth_check') {
12760: my %optiondesc = &Apache::lonlocal::texthash (
12761: 0 => 'No',
12762: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12763: 2 => 'Yes, disallow login if stored cost is less than domain default',
12764: );
12765: if ($value =~ /^(0|1|2)$/) {
12766: $value = $optiondesc{$value};
12767: } else {
12768: $value = &mt('none -- defaults to No');
12769: }
12770: }
12771: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12772: $mailmsgtext .= "$title->{$item} set to $value\n";
12773: }
12774: }
12775: $resulttext .= '</ul>';
12776: $mailmsgtext .= "\n";
12777: my $cachetime = 24*60*60;
12778: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12779: if (ref($lastactref) eq 'HASH') {
12780: $lastactref->{'domdefaults'} = 1;
12781: }
12782: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
12783: my $notify = 1;
12784: if (ref($domconfig{'contacts'}) eq 'HASH') {
12785: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12786: $notify = 0;
12787: }
12788: }
12789: if ($notify) {
12790: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12791: "LON-CAPA Domain Settings Change - $dom",
12792: $mailmsgtext);
12793: }
12794: }
12795: } else {
12796: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
12797: }
12798: } else {
12799: $resulttext = '<span class="LC_error">'.
12800: &mt('An error occurred: [_1]',$putresult).'</span>';
12801: }
12802: if (@errors > 0) {
12803: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12804: foreach my $item (@errors) {
12805: $resulttext .= ' "'.$title->{$item}.'",';
12806: }
12807: $resulttext =~ s/,$//;
12808: }
12809: return $resulttext;
12810: }
12811:
12812: sub modify_scantron {
12813: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12814: my ($resulttext,%confhash,%changes,$errors);
12815: my $custom = 'custom.tab';
12816: my $default = 'default.tab';
12817: my $servadm = $r->dir_config('lonAdmEMail');
12818: my ($configuserok,$author_ok,$switchserver) =
12819: &config_check($dom,$confname,$servadm);
12820: if ($env{'form.scantronformat.filename'} ne '') {
12821: my $error;
12822: if ($configuserok eq 'ok') {
12823: if ($switchserver) {
12824: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
12825: } else {
12826: if ($author_ok eq 'ok') {
12827: my ($result,$scantronurl) =
12828: &publishlogo($r,'upload','scantronformat',$dom,
12829: $confname,'scantron','','',$custom);
12830: if ($result eq 'ok') {
12831: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
12832: $changes{'scantronformat'} = 1;
12833: } else {
12834: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12835: }
12836: } else {
12837: $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);
12838: }
12839: }
12840: } else {
12841: $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);
12842: }
12843: if ($error) {
12844: &Apache::lonnet::logthis($error);
12845: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12846: }
12847: }
12848: if (ref($domconfig{'scantron'}) eq 'HASH') {
12849: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12850: if ($env{'form.scantronformat_del'}) {
12851: $confhash{'scantron'}{'scantronformat'} = '';
12852: $changes{'scantronformat'} = 1;
12853: }
12854: }
12855: }
12856: if (keys(%confhash) > 0) {
12857: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12858: $dom);
12859: if ($putresult eq 'ok') {
12860: if (keys(%changes) > 0) {
12861: if (ref($confhash{'scantron'}) eq 'HASH') {
12862: $resulttext = &mt('Changes made:').'<ul>';
12863: if ($confhash{'scantron'}{'scantronformat'} eq '') {
12864: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
12865: } else {
12866: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
12867: }
12868: $resulttext .= '</ul>';
12869: } else {
12870: $resulttext = &mt('Changes made to bubblesheet format file.');
12871: }
12872: $resulttext .= '</ul>';
12873: &Apache::loncommon::devalidate_domconfig_cache($dom);
12874: if (ref($lastactref) eq 'HASH') {
12875: $lastactref->{'domainconfig'} = 1;
12876: }
12877: } else {
12878: $resulttext = &mt('No changes made to bubblesheet format file');
12879: }
12880: } else {
12881: $resulttext = '<span class="LC_error">'.
12882: &mt('An error occurred: [_1]',$putresult).'</span>';
12883: }
12884: } else {
12885: $resulttext = &mt('No changes made to bubblesheet format file');
12886: }
12887: if ($errors) {
12888: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12889: $errors.'</ul>';
12890: }
12891: return $resulttext;
12892: }
12893:
12894: sub modify_coursecategories {
12895: my ($dom,$lastactref,%domconfig) = @_;
12896: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12897: $cathash);
12898: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
12899: my @catitems = ('unauth','auth');
12900: my @cattypes = ('std','domonly','codesrch','none');
12901: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12902: $cathash = $domconfig{'coursecategories'}{'cats'};
12903: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12904: $changes{'togglecats'} = 1;
12905: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12906: }
12907: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12908: $changes{'categorize'} = 1;
12909: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12910: }
12911: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12912: $changes{'togglecatscomm'} = 1;
12913: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12914: }
12915: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12916: $changes{'categorizecomm'} = 1;
12917: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
12918:
12919: }
12920: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12921: $changes{'togglecatsplace'} = 1;
12922: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12923: }
12924: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12925: $changes{'categorizeplace'} = 1;
12926: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
12927: }
12928: foreach my $item (@catitems) {
12929: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12930: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12931: $changes{$item} = 1;
12932: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12933: }
12934: }
12935: }
12936: } else {
12937: $changes{'togglecats'} = 1;
12938: $changes{'categorize'} = 1;
12939: $changes{'togglecatscomm'} = 1;
12940: $changes{'categorizecomm'} = 1;
12941: $changes{'togglecatsplace'} = 1;
12942: $changes{'categorizeplace'} = 1;
12943: $domconfig{'coursecategories'} = {
12944: togglecats => $env{'form.togglecats'},
12945: categorize => $env{'form.categorize'},
12946: togglecatscomm => $env{'form.togglecatscomm'},
12947: categorizecomm => $env{'form.categorizecomm'},
12948: togglecatsplace => $env{'form.togglecatsplace'},
12949: categorizeplace => $env{'form.categorizeplace'},
12950: };
12951: foreach my $item (@catitems) {
12952: if ($env{'form.coursecat_'.$item} ne 'std') {
12953: $changes{$item} = 1;
12954: }
12955: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12956: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12957: }
12958: }
12959: }
12960: if (ref($cathash) eq 'HASH') {
12961: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
12962: push (@deletecategory,'instcode::0');
12963: }
12964: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12965: push(@deletecategory,'communities::0');
12966: }
12967: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12968: push(@deletecategory,'placement::0');
12969: }
12970: }
12971: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12972: if (ref($cathash) eq 'HASH') {
12973: if (@deletecategory > 0) {
12974: #FIXME Need to remove category from all courses using a deleted category
12975: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
12976: foreach my $item (@deletecategory) {
12977: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12978: delete($domconfig{'coursecategories'}{'cats'}{$item});
12979: $deletions{$item} = 1;
12980: &recurse_cat_deletes($item,$cathash,\%deletions);
12981: }
12982: }
12983: }
12984: foreach my $item (keys(%{$cathash})) {
12985: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12986: if ($cathash->{$item} ne $env{'form.'.$item}) {
12987: $reorderings{$item} = 1;
12988: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
12989: }
12990: if ($env{'form.addcategory_name_'.$item} ne '') {
12991: my $newcat = $env{'form.addcategory_name_'.$item};
12992: my $newdepth = $depth+1;
12993: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
12994: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
12995: $adds{$newitem} = 1;
12996: }
12997: if ($env{'form.subcat_'.$item} ne '') {
12998: my $newcat = $env{'form.subcat_'.$item};
12999: my $newdepth = $depth+1;
13000: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
13001: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
13002: $adds{$newitem} = 1;
13003: }
13004: }
13005: }
13006: if ($env{'form.instcode'} eq '1') {
13007: if (ref($cathash) eq 'HASH') {
13008: my $newitem = 'instcode::0';
13009: if ($cathash->{$newitem} eq '') {
13010: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
13011: $adds{$newitem} = 1;
13012: }
13013: } else {
13014: my $newitem = 'instcode::0';
13015: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
13016: $adds{$newitem} = 1;
13017: }
13018: }
13019: if ($env{'form.communities'} eq '1') {
13020: if (ref($cathash) eq 'HASH') {
13021: my $newitem = 'communities::0';
13022: if ($cathash->{$newitem} eq '') {
13023: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13024: $adds{$newitem} = 1;
13025: }
13026: } else {
13027: my $newitem = 'communities::0';
13028: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13029: $adds{$newitem} = 1;
13030: }
13031: }
13032: if ($env{'form.placement'} eq '1') {
13033: if (ref($cathash) eq 'HASH') {
13034: my $newitem = 'placement::0';
13035: if ($cathash->{$newitem} eq '') {
13036: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13037: $adds{$newitem} = 1;
13038: }
13039: } else {
13040: my $newitem = 'placement::0';
13041: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13042: $adds{$newitem} = 1;
13043: }
13044: }
13045: if ($env{'form.addcategory_name'} ne '') {
13046: if (($env{'form.addcategory_name'} ne 'instcode') &&
13047: ($env{'form.addcategory_name'} ne 'communities') &&
13048: ($env{'form.addcategory_name'} ne 'placement')) {
13049: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
13050: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
13051: $adds{$newitem} = 1;
13052: }
13053: }
13054: my $putresult;
13055: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13056: if (keys(%deletions) > 0) {
13057: foreach my $key (keys(%deletions)) {
13058: if ($predelallitems{$key} ne '') {
13059: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
13060: }
13061: }
13062: }
13063: my (@chkcats,@chktrails,%chkallitems);
13064: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
13065: if (ref($chkcats[0]) eq 'ARRAY') {
13066: my $depth = 0;
13067: my $chg = 0;
13068: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
13069: my $name = $chkcats[0][$i];
13070: my $item;
13071: if ($name eq '') {
13072: $chg ++;
13073: } else {
13074: $item = &escape($name).'::0';
13075: if ($chg) {
13076: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
13077: }
13078: $depth ++;
13079: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
13080: $depth --;
13081: }
13082: }
13083: }
13084: }
13085: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13086: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
13087: if ($putresult eq 'ok') {
13088: my %title = (
13089: togglecats => 'Show/Hide a course in catalog',
13090: categorize => 'Assign a category to a course',
13091: togglecatscomm => 'Show/Hide a community in catalog',
13092: categorizecomm => 'Assign a category to a community',
13093: );
13094: my %level = (
13095: dom => 'set in Domain ("Modify Course/Community")',
13096: crs => 'set in Course ("Course Configuration")',
13097: comm => 'set in Community ("Community Configuration")',
13098: none => 'No catalog',
13099: std => 'Standard catalog',
13100: domonly => 'Domain-only catalog',
13101: codesrch => 'Code search form',
13102: );
13103: $resulttext = &mt('Changes made:').'<ul>';
13104: if ($changes{'togglecats'}) {
13105: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
13106: }
13107: if ($changes{'categorize'}) {
13108: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
13109: }
13110: if ($changes{'togglecatscomm'}) {
13111: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
13112: }
13113: if ($changes{'categorizecomm'}) {
13114: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
13115: }
13116: if ($changes{'unauth'}) {
13117: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
13118: }
13119: if ($changes{'auth'}) {
13120: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
13121: }
13122: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13123: my $cathash;
13124: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
13125: $cathash = $domconfig{'coursecategories'}{'cats'};
13126: } else {
13127: $cathash = {};
13128: }
13129: my (@cats,@trails,%allitems);
13130: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
13131: if (keys(%deletions) > 0) {
13132: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
13133: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
13134: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
13135: }
13136: $resulttext .= '</ul></li>';
13137: }
13138: if (keys(%reorderings) > 0) {
13139: my %sort_by_trail;
13140: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
13141: foreach my $key (keys(%reorderings)) {
13142: if ($allitems{$key} ne '') {
13143: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13144: }
13145: }
13146: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13147: $resulttext .= '<li>'.$trails[$trail].'</li>';
13148: }
13149: $resulttext .= '</ul></li>';
13150: }
13151: if (keys(%adds) > 0) {
13152: my %sort_by_trail;
13153: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
13154: foreach my $key (keys(%adds)) {
13155: if ($allitems{$key} ne '') {
13156: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13157: }
13158: }
13159: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13160: $resulttext .= '<li>'.$trails[$trail].'</li>';
13161: }
13162: $resulttext .= '</ul></li>';
13163: }
13164: }
13165: $resulttext .= '</ul>';
13166: if ($changes{'unauth'} || $changes{'auth'}) {
13167: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13168: if ($changes{'auth'}) {
13169: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
13170: }
13171: if ($changes{'unauth'}) {
13172: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
13173: }
13174: my $cachetime = 24*60*60;
13175: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13176: if (ref($lastactref) eq 'HASH') {
13177: $lastactref->{'domdefaults'} = 1;
13178: }
13179: }
13180: } else {
13181: $resulttext = '<span class="LC_error">'.
13182: &mt('An error occurred: [_1]',$putresult).'</span>';
13183: }
13184: } else {
13185: $resulttext = &mt('No changes made to course and community categories');
13186: }
13187: return $resulttext;
13188: }
13189:
13190: sub modify_serverstatuses {
13191: my ($dom,%domconfig) = @_;
13192: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
13193: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
13194: %currserverstatus = %{$domconfig{'serverstatuses'}};
13195: }
13196: my @pages = &serverstatus_pages();
13197: foreach my $type (@pages) {
13198: $newserverstatus{$type}{'namedusers'} = '';
13199: $newserverstatus{$type}{'machines'} = '';
13200: if (defined($env{'form.'.$type.'_namedusers'})) {
13201: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
13202: my @okusers;
13203: foreach my $user (@users) {
13204: my ($uname,$udom) = split(/:/,$user);
13205: if (($udom =~ /^$match_domain$/) &&
13206: (&Apache::lonnet::domain($udom)) &&
13207: ($uname =~ /^$match_username$/)) {
13208: if (!grep(/^\Q$user\E/,@okusers)) {
13209: push(@okusers,$user);
13210: }
13211: }
13212: }
13213: if (@okusers > 0) {
13214: @okusers = sort(@okusers);
13215: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13216: }
13217: }
13218: if (defined($env{'form.'.$type.'_machines'})) {
13219: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13220: my @okmachines;
13221: foreach my $ip (@machines) {
13222: my @parts = split(/\./,$ip);
13223: next if (@parts < 4);
13224: my $badip = 0;
13225: for (my $i=0; $i<4; $i++) {
13226: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13227: $badip = 1;
13228: last;
13229: }
13230: }
13231: if (!$badip) {
13232: push(@okmachines,$ip);
13233: }
13234: }
13235: @okmachines = sort(@okmachines);
13236: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13237: }
13238: }
13239: my %serverstatushash = (
13240: serverstatuses => \%newserverstatus,
13241: );
13242: foreach my $type (@pages) {
13243: foreach my $setting ('namedusers','machines') {
13244: my (@current,@new);
13245: if (ref($currserverstatus{$type}) eq 'HASH') {
13246: if ($currserverstatus{$type}{$setting} ne '') {
13247: @current = split(/,/,$currserverstatus{$type}{$setting});
13248: }
13249: }
13250: if ($newserverstatus{$type}{$setting} ne '') {
13251: @new = split(/,/,$newserverstatus{$type}{$setting});
13252: }
13253: if (@current > 0) {
13254: if (@new > 0) {
13255: foreach my $item (@current) {
13256: if (!grep(/^\Q$item\E$/,@new)) {
13257: $changes{$type}{$setting} = 1;
13258: last;
13259: }
13260: }
13261: foreach my $item (@new) {
13262: if (!grep(/^\Q$item\E$/,@current)) {
13263: $changes{$type}{$setting} = 1;
13264: last;
13265: }
13266: }
13267: } else {
13268: $changes{$type}{$setting} = 1;
13269: }
13270: } elsif (@new > 0) {
13271: $changes{$type}{$setting} = 1;
13272: }
13273: }
13274: }
13275: if (keys(%changes) > 0) {
13276: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
13277: my $putresult = &Apache::lonnet::put_dom('configuration',
13278: \%serverstatushash,$dom);
13279: if ($putresult eq 'ok') {
13280: $resulttext .= &mt('Changes made:').'<ul>';
13281: foreach my $type (@pages) {
13282: if (ref($changes{$type}) eq 'HASH') {
13283: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
13284: if ($changes{$type}{'namedusers'}) {
13285: if ($newserverstatus{$type}{'namedusers'} eq '') {
13286: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13287: } else {
13288: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13289: }
13290: }
13291: if ($changes{$type}{'machines'}) {
13292: if ($newserverstatus{$type}{'machines'} eq '') {
13293: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13294: } else {
13295: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13296: }
13297:
13298: }
13299: $resulttext .= '</ul></li>';
13300: }
13301: }
13302: $resulttext .= '</ul>';
13303: } else {
13304: $resulttext = '<span class="LC_error">'.
13305: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13306:
13307: }
13308: } else {
13309: $resulttext = &mt('No changes made to access to server status pages');
13310: }
13311: return $resulttext;
13312: }
13313:
13314: sub modify_helpsettings {
13315: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
13316: my ($resulttext,$errors,%changes,%helphash);
13317: my %defaultchecked = ('submitbugs' => 'on');
13318: my @offon = ('off','on');
13319: my @toggles = ('submitbugs');
13320: my %current = ('submitbugs' => '',
13321: 'adhoc' => {},
13322: );
13323: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
13324: %current = %{$domconfig{'helpsettings'}};
13325: }
13326: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13327: foreach my $item (@toggles) {
13328: if ($defaultchecked{$item} eq 'on') {
13329: if ($current{$item} eq '') {
13330: if ($env{'form.'.$item} eq '0') {
13331: $changes{$item} = 1;
13332: }
13333: } elsif ($current{$item} ne $env{'form.'.$item}) {
13334: $changes{$item} = 1;
13335: }
13336: } elsif ($defaultchecked{$item} eq 'off') {
13337: if ($current{$item} eq '') {
13338: if ($env{'form.'.$item} eq '1') {
13339: $changes{$item} = 1;
13340: }
13341: } elsif ($current{$item} ne $env{'form.'.$item}) {
13342: $changes{$item} = 1;
13343: }
13344: }
13345: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13346: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13347: }
13348: }
13349: my $maxnum = $env{'form.helproles_maxnum'};
13350: my $confname = $dom.'-domainconfig';
13351: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
13352: my (@allpos,%newsettings,%changedprivs,$newrole);
13353: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13354: my @accesstypes = ('all','dh','da','none','status','inc','exc');
13355: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
13356: my %lt = &Apache::lonlocal::texthash(
13357: s => 'system',
13358: d => 'domain',
13359: order => 'Display order',
13360: access => 'Role usage',
13361: all => 'All with domain helpdesk or helpdesk assistant role',
13362: dh => 'All with domain helpdesk role',
13363: da => 'All with domain helpdesk assistant role',
13364: none => 'None',
13365: status => 'Determined based on institutional status',
13366: inc => 'Include all, but exclude specific personnel',
13367: exc => 'Exclude all, but include specific personnel',
13368: );
13369: for (my $num=0; $num<=$maxnum; $num++) {
13370: my ($prefix,$identifier,$rolename,%curr);
13371: if ($num == $maxnum) {
13372: next unless ($env{'form.newcusthelp'} == $maxnum);
13373: $identifier = 'custhelp'.$num;
13374: $prefix = 'helproles_'.$num;
13375: $rolename = $env{'form.custhelpname'.$num};
13376: $rolename=~s/[^A-Za-z0-9]//gs;
13377: next if ($rolename eq '');
13378: next if (exists($existing{'rolesdef_'.$rolename}));
13379: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13380: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13381: $newprivs{'c'},$confname,$dom);
13382: if ($result ne 'ok') {
13383: $errors .= '<li><span class="LC_error">'.
13384: &mt('An error occurred storing the new custom role: [_1]',
13385: $result).'</span></li>';
13386: next;
13387: } else {
13388: $changedprivs{$rolename} = \%newprivs;
13389: $newrole = $rolename;
13390: }
13391: } else {
13392: $prefix = 'helproles_'.$num;
13393: $rolename = $env{'form.'.$prefix};
13394: next if ($rolename eq '');
13395: next unless (exists($existing{'rolesdef_'.$rolename}));
13396: $identifier = 'custhelp'.$num;
13397: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13398: my %currprivs;
13399: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
13400: split(/\_/,$existing{'rolesdef_'.$rolename});
13401: foreach my $level ('c','d','s') {
13402: if ($newprivs{$level} ne $currprivs{$level}) {
13403: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13404: $newprivs{'c'},$confname,$dom);
13405: if ($result ne 'ok') {
13406: $errors .= '<li><span class="LC_error">'.
13407: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13408: $rolename,$result).'</span></li>';
13409: } else {
13410: $changedprivs{$rolename} = \%newprivs;
13411: }
13412: last;
13413: }
13414: }
13415: if (ref($current{'adhoc'}) eq 'HASH') {
13416: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13417: %curr = %{$current{'adhoc'}{$rolename}};
13418: }
13419: }
13420: }
13421: my $newpos = $env{'form.'.$prefix.'_pos'};
13422: $newpos =~ s/\D+//g;
13423: $allpos[$newpos] = $rolename;
13424: my $newdesc = $env{'form.'.$prefix.'_desc'};
13425: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13426: if ($curr{'desc'}) {
13427: if ($curr{'desc'} ne $newdesc) {
13428: $changes{'customrole'}{$rolename}{'desc'} = 1;
13429: $newsettings{$rolename}{'desc'} = $newdesc;
13430: }
13431: } elsif ($newdesc ne '') {
13432: $changes{'customrole'}{$rolename}{'desc'} = 1;
13433: $newsettings{$rolename}{'desc'} = $newdesc;
13434: }
13435: my $access = $env{'form.'.$prefix.'_access'};
13436: if (grep(/^\Q$access\E$/,@accesstypes)) {
13437: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13438: if ($access eq 'status') {
13439: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13440: if (scalar(@statuses) == 0) {
13441: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
13442: } else {
13443: my (@shownstatus,$numtypes);
13444: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13445: if (ref($types) eq 'ARRAY') {
13446: $numtypes = scalar(@{$types});
13447: foreach my $type (sort(@statuses)) {
13448: if ($type eq 'default') {
13449: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13450: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13451: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13452: push(@shownstatus,$usertypes->{$type});
13453: }
13454: }
13455: }
13456: if (grep(/^default$/,@statuses)) {
13457: push(@shownstatus,$othertitle);
13458: }
13459: if (scalar(@shownstatus) == 1+$numtypes) {
13460: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13461: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13462: } else {
13463: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13464: if (ref($curr{'status'}) eq 'ARRAY') {
13465: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13466: if (@diffs) {
13467: $changes{'customrole'}{$rolename}{$access} = 1;
13468: }
13469: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13470: $changes{'customrole'}{$rolename}{$access} = 1;
13471: }
13472: }
13473: }
13474: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13475: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13476: my @newspecstaff;
13477: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13478: foreach my $person (sort(@personnel)) {
13479: if ($domhelpdesk{$person}) {
13480: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13481: }
13482: }
13483: if (ref($curr{$access}) eq 'ARRAY') {
13484: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13485: if (@diffs) {
13486: $changes{'customrole'}{$rolename}{$access} = 1;
13487: }
13488: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13489: $changes{'customrole'}{$rolename}{$access} = 1;
13490: }
13491: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13492: my ($uname,$udom) = split(/:/,$person);
13493: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13494: }
13495: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
13496: }
13497: } else {
13498: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13499: }
13500: unless ($curr{'access'} eq $access) {
13501: $changes{'customrole'}{$rolename}{'access'} = 1;
13502: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
13503: }
13504: }
13505: if (@allpos > 0) {
13506: my $idx = 0;
13507: foreach my $rolename (@allpos) {
13508: if ($rolename ne '') {
13509: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13510: if (ref($current{'adhoc'}) eq 'HASH') {
13511: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13512: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13513: $changes{'customrole'}{$rolename}{'order'} = 1;
13514: $newsettings{$rolename}{'order'} = $idx+1;
13515: }
13516: }
13517: }
13518: $idx ++;
13519: }
13520: }
13521: }
13522: my $putresult;
13523: if (keys(%changes) > 0) {
13524: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
13525: if ($putresult eq 'ok') {
13526: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13527: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13528: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13529: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13530: }
13531: }
13532: my $cachetime = 24*60*60;
13533: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13534: if (ref($lastactref) eq 'HASH') {
13535: $lastactref->{'domdefaults'} = 1;
13536: }
13537: } else {
13538: $errors .= '<li><span class="LC_error">'.
13539: &mt('An error occurred storing the settings: [_1]',
13540: $putresult).'</span></li>';
13541: }
13542: }
13543: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13544: $resulttext = &mt('Changes made:').'<ul>';
13545: my (%shownprivs,@levelorder);
13546: @levelorder = ('c','d','s');
13547: if ((keys(%changes)) && ($putresult eq 'ok')) {
13548: foreach my $item (sort(keys(%changes))) {
13549: if ($item eq 'submitbugs') {
13550: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13551: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13552: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
13553: } elsif ($item eq 'customrole') {
13554: if (ref($changes{'customrole'}) eq 'HASH') {
13555: my @keyorder = ('order','desc','access','status','exc','inc');
13556: my %keytext = &Apache::lonlocal::texthash(
13557: order => 'Order',
13558: desc => 'Role description',
13559: access => 'Role usage',
13560: status => 'Allowed institutional types',
13561: exc => 'Allowed personnel',
13562: inc => 'Disallowed personnel',
13563: );
13564: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
13565: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13566: if ($role eq $newrole) {
13567: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13568: $role).'<ul>';
13569: } else {
13570: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13571: $role).'<ul>';
13572: }
13573: foreach my $key (@keyorder) {
13574: if ($changes{'customrole'}{$role}{$key}) {
13575: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13576: $keytext{$key},$newsettings{$role}{$key}).
13577: '</li>';
13578: }
13579: }
13580: if (ref($changedprivs{$role}) eq 'HASH') {
13581: $shownprivs{$role} = 1;
13582: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13583: foreach my $level (@levelorder) {
13584: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13585: next if ($item eq '');
13586: my ($priv) = split(/\&/,$item,2);
13587: if (&Apache::lonnet::plaintext($priv)) {
13588: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13589: unless ($level eq 'c') {
13590: $resulttext .= ' ('.$lt{$level}.')';
13591: }
13592: $resulttext .= '</li>';
13593: }
13594: }
13595: }
13596: $resulttext .= '</ul>';
13597: }
13598: $resulttext .= '</ul></li>';
13599: }
13600: }
13601: }
13602: }
13603: }
13604: }
13605: if (keys(%changedprivs)) {
13606: foreach my $role (sort(keys(%changedprivs))) {
13607: unless ($shownprivs{$role}) {
13608: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13609: $role).'<ul>'.
13610: '<li>'.&mt('Privileges set to :').'<ul>';
13611: foreach my $level (@levelorder) {
13612: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13613: next if ($item eq '');
13614: my ($priv) = split(/\&/,$item,2);
13615: if (&Apache::lonnet::plaintext($priv)) {
13616: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13617: unless ($level eq 'c') {
13618: $resulttext .= ' ('.$lt{$level}.')';
13619: }
13620: $resulttext .= '</li>';
13621: }
13622: }
13623: }
13624: $resulttext .= '</ul></li></ul></li>';
13625: }
13626: }
13627: }
13628: $resulttext .= '</ul>';
13629: } else {
13630: $resulttext = &mt('No changes made to help settings');
13631: }
13632: if ($errors) {
13633: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
13634: $errors.'</ul>';
13635: }
13636: return $resulttext;
13637: }
13638:
13639: sub modify_coursedefaults {
13640: my ($dom,$lastactref,%domconfig) = @_;
13641: my ($resulttext,$errors,%changes,%defaultshash);
13642: my %defaultchecked = (
13643: 'canuse_pdfforms' => 'off',
13644: 'uselcmath' => 'on',
13645: 'usejsme' => 'on'
13646: );
13647: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
13648: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
13649: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13650: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13651: 'mysqltables_textbook','mysqltables_placement');
13652: my @types = ('official','unofficial','community','textbook','placement');
13653: my %staticdefaults = (
13654: anonsurvey_threshold => 10,
13655: uploadquota => 500,
13656: postsubmit => 60,
13657: mysqltables => 172800,
13658: );
13659:
13660: $defaultshash{'coursedefaults'} = {};
13661:
13662: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13663: if ($domconfig{'coursedefaults'} eq '') {
13664: $domconfig{'coursedefaults'} = {};
13665: }
13666: }
13667:
13668: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13669: foreach my $item (@toggles) {
13670: if ($defaultchecked{$item} eq 'on') {
13671: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13672: ($env{'form.'.$item} eq '0')) {
13673: $changes{$item} = 1;
13674: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13675: $changes{$item} = 1;
13676: }
13677: } elsif ($defaultchecked{$item} eq 'off') {
13678: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13679: ($env{'form.'.$item} eq '1')) {
13680: $changes{$item} = 1;
13681: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13682: $changes{$item} = 1;
13683: }
13684: }
13685: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13686: }
13687: foreach my $item (@numbers) {
13688: my ($currdef,$newdef);
13689: $newdef = $env{'form.'.$item};
13690: if ($item eq 'anonsurvey_threshold') {
13691: $currdef = $domconfig{'coursedefaults'}{$item};
13692: $newdef =~ s/\D//g;
13693: if ($newdef eq '' || $newdef < 1) {
13694: $newdef = 1;
13695: }
13696: $defaultshash{'coursedefaults'}{$item} = $newdef;
13697: } else {
13698: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13699: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13700: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
13701: }
13702: $newdef =~ s/[^\w.\-]//g;
13703: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
13704: }
13705: if ($currdef ne $newdef) {
13706: my $staticdef;
13707: if ($item eq 'anonsurvey_threshold') {
13708: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13709: $changes{$item} = 1;
13710: }
13711: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
13712: my $setting = $1;
13713: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13714: $changes{$setting} = 1;
13715: }
13716: }
13717: }
13718: }
13719: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13720: my @currclonecode;
13721: if (ref($currclone) eq 'HASH') {
13722: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13723: @currclonecode = @{$currclone->{'instcode'}};
13724: }
13725: }
13726: my $newclone;
13727: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
13728: $newclone = $env{'form.canclone'};
13729: }
13730: if ($newclone eq 'instcode') {
13731: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13732: my (%codedefaults,@code_order,@clonecode);
13733: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13734: \@code_order);
13735: foreach my $item (@code_order) {
13736: if (grep(/^\Q$item\E$/,@newcodes)) {
13737: push(@clonecode,$item);
13738: }
13739: }
13740: if (@clonecode) {
13741: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13742: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13743: if (@diffs) {
13744: $changes{'canclone'} = 1;
13745: }
13746: } else {
13747: $newclone eq '';
13748: }
13749: } elsif ($newclone ne '') {
13750: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13751: }
13752: if ($newclone ne $currclone) {
13753: $changes{'canclone'} = 1;
13754: }
13755: my %credits;
13756: foreach my $type (@types) {
13757: unless ($type eq 'community') {
13758: $credits{$type} = $env{'form.'.$type.'_credits'};
13759: $credits{$type} =~ s/[^\d.]+//g;
13760: }
13761: }
13762: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13763: ($env{'form.coursecredits'} eq '1')) {
13764: $changes{'coursecredits'} = 1;
13765: foreach my $type (keys(%credits)) {
13766: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13767: }
13768: } else {
13769: if ($env{'form.coursecredits'} eq '1') {
13770: foreach my $type (@types) {
13771: unless ($type eq 'community') {
13772: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
13773: $changes{'coursecredits'} = 1;
13774: }
13775: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13776: }
13777: }
13778: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13779: foreach my $type (@types) {
13780: unless ($type eq 'community') {
13781: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13782: $changes{'coursecredits'} = 1;
13783: last;
13784: }
13785: }
13786: }
13787: }
13788: }
13789: if ($env{'form.postsubmit'} eq '1') {
13790: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13791: my %currtimeout;
13792: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13793: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13794: $changes{'postsubmit'} = 1;
13795: }
13796: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13797: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13798: }
13799: } else {
13800: $changes{'postsubmit'} = 1;
13801: }
13802: foreach my $type (@types) {
13803: my $timeout = $env{'form.'.$type.'_timeout'};
13804: $timeout =~ s/\D//g;
13805: if ($timeout == $staticdefaults{'postsubmit'}) {
13806: $timeout = '';
13807: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13808: $timeout = '0';
13809: }
13810: unless ($timeout eq '') {
13811: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13812: }
13813: if (exists($currtimeout{$type})) {
13814: if ($timeout ne $currtimeout{$type}) {
13815: $changes{'postsubmit'} = 1;
13816: }
13817: } elsif ($timeout ne '') {
13818: $changes{'postsubmit'} = 1;
13819: }
13820: }
13821: } else {
13822: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13823: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13824: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13825: $changes{'postsubmit'} = 1;
13826: }
13827: } else {
13828: $changes{'postsubmit'} = 1;
13829: }
13830: }
13831: }
13832: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13833: $dom);
13834: if ($putresult eq 'ok') {
13835: if (keys(%changes) > 0) {
13836: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13837: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
13838: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
13839: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
13840: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13841: if ($changes{$item}) {
13842: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13843: }
13844: }
13845: if ($changes{'coursecredits'}) {
13846: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13847: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13848: $domdefaults{$type.'credits'} =
13849: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13850: }
13851: }
13852: }
13853: if ($changes{'postsubmit'}) {
13854: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13855: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13856: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13857: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13858: $domdefaults{$type.'postsubtimeout'} =
13859: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13860: }
13861: }
13862: }
13863: }
13864: if ($changes{'uploadquota'}) {
13865: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13866: foreach my $type (@types) {
13867: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13868: }
13869: }
13870: }
13871: if ($changes{'canclone'}) {
13872: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13873: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13874: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13875: if (@clonecodes) {
13876: $domdefaults{'canclone'} = join('+',@clonecodes);
13877: }
13878: }
13879: } else {
13880: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13881: }
13882: }
13883: my $cachetime = 24*60*60;
13884: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13885: if (ref($lastactref) eq 'HASH') {
13886: $lastactref->{'domdefaults'} = 1;
13887: }
13888: }
13889: $resulttext = &mt('Changes made:').'<ul>';
13890: foreach my $item (sort(keys(%changes))) {
13891: if ($item eq 'canuse_pdfforms') {
13892: if ($env{'form.'.$item} eq '1') {
13893: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13894: } else {
13895: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13896: }
13897: } elsif ($item eq 'uselcmath') {
13898: if ($env{'form.'.$item} eq '1') {
13899: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13900: } else {
13901: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13902: }
13903: } elsif ($item eq 'usejsme') {
13904: if ($env{'form.'.$item} eq '1') {
13905: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13906: } else {
13907: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
13908: }
13909: } elsif ($item eq 'anonsurvey_threshold') {
13910: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
13911: } elsif ($item eq 'uploadquota') {
13912: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13913: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13914: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13915: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
13916: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
13917: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
13918: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13919: '</ul>'.
13920: '</li>';
13921: } else {
13922: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13923: }
13924: } elsif ($item eq 'mysqltables') {
13925: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13926: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13927: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13928: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13929: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13930: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13931: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13932: '</ul>'.
13933: '</li>';
13934: } else {
13935: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13936: }
13937: } elsif ($item eq 'postsubmit') {
13938: if ($domdefaults{'postsubmit'} eq 'off') {
13939: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13940: } else {
13941: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
13942: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13943: $resulttext .= &mt('durations:').'<ul>';
13944: foreach my $type (@types) {
13945: $resulttext .= '<li>';
13946: my $timeout;
13947: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13948: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13949: }
13950: my $display;
13951: if ($timeout eq '0') {
13952: $display = &mt('unlimited');
13953: } elsif ($timeout eq '') {
13954: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13955: } else {
13956: $display = &mt('[quant,_1,second]',$timeout);
13957: }
13958: if ($type eq 'community') {
13959: $resulttext .= &mt('Communities');
13960: } elsif ($type eq 'official') {
13961: $resulttext .= &mt('Official courses');
13962: } elsif ($type eq 'unofficial') {
13963: $resulttext .= &mt('Unofficial courses');
13964: } elsif ($type eq 'textbook') {
13965: $resulttext .= &mt('Textbook courses');
13966: } elsif ($type eq 'placement') {
13967: $resulttext .= &mt('Placement tests');
13968: }
13969: $resulttext .= ' -- '.$display.'</li>';
13970: }
13971: $resulttext .= '</ul>';
13972: }
13973: $resulttext .= '</li>';
13974: }
13975: } elsif ($item eq 'coursecredits') {
13976: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13977: if (($domdefaults{'officialcredits'} eq '') &&
13978: ($domdefaults{'unofficialcredits'} eq '') &&
13979: ($domdefaults{'textbookcredits'} eq '')) {
13980: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13981: } else {
13982: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13983: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13984: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
13985: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
13986: '</ul>'.
13987: '</li>';
13988: }
13989: } else {
13990: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13991: }
13992: } elsif ($item eq 'canclone') {
13993: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13994: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13995: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13996: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13997: }
13998: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13999: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
14000: } else {
14001: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
14002: }
14003: }
14004: }
14005: $resulttext .= '</ul>';
14006: } else {
14007: $resulttext = &mt('No changes made to course defaults');
14008: }
14009: } else {
14010: $resulttext = '<span class="LC_error">'.
14011: &mt('An error occurred: [_1]',$putresult).'</span>';
14012: }
14013: return $resulttext;
14014: }
14015:
14016: sub modify_selfenrollment {
14017: my ($dom,$lastactref,%domconfig) = @_;
14018: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
14019: my @types = ('official','unofficial','community','textbook','placement');
14020: my %titles = &tool_titles();
14021: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
14022: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
14023: $ordered{'default'} = ['types','registered','approval','limit'];
14024:
14025: my (%roles,%shown,%toplevel);
14026: $roles{'0'} = &Apache::lonnet::plaintext('dc');
14027:
14028: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
14029: if ($domconfig{'selfenrollment'} eq '') {
14030: $domconfig{'selfenrollment'} = {};
14031: }
14032: }
14033: %toplevel = (
14034: admin => 'Configuration Rights',
14035: default => 'Default settings',
14036: validation => 'Validation of self-enrollment requests',
14037: );
14038: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
14039:
14040: if (ref($ordered{'admin'}) eq 'ARRAY') {
14041: foreach my $item (@{$ordered{'admin'}}) {
14042: foreach my $type (@types) {
14043: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
14044: $selfenrollhash{'admin'}{$type}{$item} = 1;
14045: } else {
14046: $selfenrollhash{'admin'}{$type}{$item} = 0;
14047: }
14048: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
14049: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
14050: if ($selfenrollhash{'admin'}{$type}{$item} ne
14051: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
14052: push(@{$changes{'admin'}{$type}},$item);
14053: }
14054: } else {
14055: if (!$selfenrollhash{'admin'}{$type}{$item}) {
14056: push(@{$changes{'admin'}{$type}},$item);
14057: }
14058: }
14059: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
14060: push(@{$changes{'admin'}{$type}},$item);
14061: }
14062: }
14063: }
14064: }
14065:
14066: foreach my $item (@{$ordered{'default'}}) {
14067: foreach my $type (@types) {
14068: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
14069: if ($item eq 'types') {
14070: unless (($value eq 'all') || ($value eq 'dom')) {
14071: $value = '';
14072: }
14073: } elsif ($item eq 'registered') {
14074: unless ($value eq '1') {
14075: $value = 0;
14076: }
14077: } elsif ($item eq 'approval') {
14078: unless ($value =~ /^[012]$/) {
14079: $value = 0;
14080: }
14081: } else {
14082: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14083: $value = 'none';
14084: }
14085: }
14086: $selfenrollhash{'default'}{$type}{$item} = $value;
14087: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
14088: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14089: if ($selfenrollhash{'default'}{$type}{$item} ne
14090: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
14091: push(@{$changes{'default'}{$type}},$item);
14092: }
14093: } else {
14094: push(@{$changes{'default'}{$type}},$item);
14095: }
14096: } else {
14097: push(@{$changes{'default'}{$type}},$item);
14098: }
14099: if ($item eq 'limit') {
14100: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14101: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
14102: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
14103: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
14104: }
14105: } else {
14106: $selfenrollhash{'default'}{$type}{'cap'} = '';
14107: }
14108: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14109: if ($selfenrollhash{'default'}{$type}{'cap'} ne
14110: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
14111: push(@{$changes{'default'}{$type}},'cap');
14112: }
14113: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
14114: push(@{$changes{'default'}{$type}},'cap');
14115: }
14116: }
14117: }
14118: }
14119:
14120: foreach my $item (@{$itemsref}) {
14121: if ($item eq 'fields') {
14122: my @changed;
14123: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
14124: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
14125: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
14126: }
14127: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14128: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
14129: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
14130: $domconfig{'selfenrollment'}{'validation'}{$item});
14131: } else {
14132: @changed = @{$selfenrollhash{'validation'}{$item}};
14133: }
14134: } else {
14135: @changed = @{$selfenrollhash{'validation'}{$item}};
14136: }
14137: if (@changed) {
14138: if ($selfenrollhash{'validation'}{$item}) {
14139: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
14140: } else {
14141: $changes{'validation'}{$item} = &mt('None');
14142: }
14143: }
14144: } else {
14145: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
14146: if ($item eq 'markup') {
14147: if ($env{'form.selfenroll_validation_'.$item}) {
14148: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14149: }
14150: }
14151: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14152: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
14153: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
14154: }
14155: }
14156: }
14157: }
14158:
14159: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
14160: $dom);
14161: if ($putresult eq 'ok') {
14162: if (keys(%changes) > 0) {
14163: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14164: $resulttext = &mt('Changes made:').'<ul>';
14165: foreach my $key ('admin','default','validation') {
14166: if (ref($changes{$key}) eq 'HASH') {
14167: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
14168: if ($key eq 'validation') {
14169: foreach my $item (@{$itemsref}) {
14170: if (exists($changes{$key}{$item})) {
14171: if ($item eq 'markup') {
14172: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14173: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
14174: } else {
14175: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14176: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
14177: }
14178: }
14179: }
14180: } else {
14181: foreach my $type (@types) {
14182: if ($type eq 'community') {
14183: $roles{'1'} = &mt('Community personnel');
14184: } else {
14185: $roles{'1'} = &mt('Course personnel');
14186: }
14187: if (ref($changes{$key}{$type}) eq 'ARRAY') {
14188: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14189: if ($key eq 'admin') {
14190: my @mgrdc = ();
14191: if (ref($ordered{$key}) eq 'ARRAY') {
14192: foreach my $item (@{$ordered{'admin'}}) {
14193: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14194: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
14195: push(@mgrdc,$item);
14196: }
14197: }
14198: }
14199: if (@mgrdc) {
14200: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14201: } else {
14202: delete($domdefaults{$type.'selfenrolladmdc'});
14203: }
14204: }
14205: } else {
14206: if (ref($ordered{$key}) eq 'ARRAY') {
14207: foreach my $item (@{$ordered{$key}}) {
14208: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14209: $domdefaults{$type.'selfenroll'.$item} =
14210: $selfenrollhash{$key}{$type}{$item};
14211: }
14212: }
14213: }
14214: }
14215: }
14216: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14217: foreach my $item (@{$ordered{$key}}) {
14218: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14219: $resulttext .= '<li>';
14220: if ($key eq 'admin') {
14221: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14222: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14223: } else {
14224: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14225: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14226: }
14227: $resulttext .= '</li>';
14228: }
14229: }
14230: $resulttext .= '</ul></li>';
14231: }
14232: }
14233: $resulttext .= '</ul></li>';
14234: }
14235: }
14236: }
14237: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14238: my $cachetime = 24*60*60;
14239: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14240: if (ref($lastactref) eq 'HASH') {
14241: $lastactref->{'domdefaults'} = 1;
14242: }
14243: }
14244: $resulttext .= '</ul>';
14245: } else {
14246: $resulttext = &mt('No changes made to self-enrollment settings');
14247: }
14248: } else {
14249: $resulttext = '<span class="LC_error">'.
14250: &mt('An error occurred: [_1]',$putresult).'</span>';
14251: }
14252: return $resulttext;
14253: }
14254:
14255: sub modify_usersessions {
14256: my ($dom,$lastactref,%domconfig) = @_;
14257: my @hostingtypes = ('version','excludedomain','includedomain');
14258: my @offloadtypes = ('primary','default');
14259: my %types = (
14260: remote => \@hostingtypes,
14261: hosted => \@hostingtypes,
14262: spares => \@offloadtypes,
14263: );
14264: my @prefixes = ('remote','hosted','spares');
14265: my @lcversions = &Apache::lonnet::all_loncaparevs();
14266: my (%by_ip,%by_location,@intdoms,@instdoms);
14267: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14268: my @locations = sort(keys(%by_location));
14269: my (%defaultshash,%changes);
14270: foreach my $prefix (@prefixes) {
14271: $defaultshash{'usersessions'}{$prefix} = {};
14272: }
14273: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14274: my $resulttext;
14275: my %iphost = &Apache::lonnet::get_iphost();
14276: foreach my $prefix (@prefixes) {
14277: next if ($prefix eq 'spares');
14278: foreach my $type (@{$types{$prefix}}) {
14279: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14280: if ($type eq 'version') {
14281: my $value = $env{'form.'.$prefix.'_'.$type};
14282: my $okvalue;
14283: if ($value ne '') {
14284: if (grep(/^\Q$value\E$/,@lcversions)) {
14285: $okvalue = $value;
14286: }
14287: }
14288: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14289: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14290: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14291: if ($inuse == 0) {
14292: $changes{$prefix}{$type} = 1;
14293: } else {
14294: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14295: $changes{$prefix}{$type} = 1;
14296: }
14297: if ($okvalue ne '') {
14298: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14299: }
14300: }
14301: } else {
14302: if (($inuse == 1) && ($okvalue ne '')) {
14303: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14304: $changes{$prefix}{$type} = 1;
14305: }
14306: }
14307: } else {
14308: if (($inuse == 1) && ($okvalue ne '')) {
14309: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14310: $changes{$prefix}{$type} = 1;
14311: }
14312: }
14313: } else {
14314: if (($inuse == 1) && ($okvalue ne '')) {
14315: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14316: $changes{$prefix}{$type} = 1;
14317: }
14318: }
14319: } else {
14320: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14321: my @okvals;
14322: foreach my $val (@vals) {
14323: if ($val =~ /:/) {
14324: my @items = split(/:/,$val);
14325: foreach my $item (@items) {
14326: if (ref($by_location{$item}) eq 'ARRAY') {
14327: push(@okvals,$item);
14328: }
14329: }
14330: } else {
14331: if (ref($by_location{$val}) eq 'ARRAY') {
14332: push(@okvals,$val);
14333: }
14334: }
14335: }
14336: @okvals = sort(@okvals);
14337: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14338: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14339: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14340: if ($inuse == 0) {
14341: $changes{$prefix}{$type} = 1;
14342: } else {
14343: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14344: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14345: if (@changed > 0) {
14346: $changes{$prefix}{$type} = 1;
14347: }
14348: }
14349: } else {
14350: if ($inuse == 1) {
14351: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14352: $changes{$prefix}{$type} = 1;
14353: }
14354: }
14355: } else {
14356: if ($inuse == 1) {
14357: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14358: $changes{$prefix}{$type} = 1;
14359: }
14360: }
14361: } else {
14362: if ($inuse == 1) {
14363: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14364: $changes{$prefix}{$type} = 1;
14365: }
14366: }
14367: }
14368: }
14369: }
14370:
14371: my @alldoms = &Apache::lonnet::all_domains();
14372: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14373: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14374: my $savespares;
14375:
14376: foreach my $lonhost (sort(keys(%servers))) {
14377: my $serverhomeID =
14378: &Apache::lonnet::get_server_homeID($servers{$lonhost});
14379: my $serverhostname = &Apache::lonnet::hostname($lonhost);
14380: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14381: my %spareschg;
14382: foreach my $type (@{$types{'spares'}}) {
14383: my @okspares;
14384: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14385: foreach my $server (@checked) {
14386: if (&Apache::lonnet::hostname($server) ne '') {
14387: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14388: unless (grep(/^\Q$server\E$/,@okspares)) {
14389: push(@okspares,$server);
14390: }
14391: }
14392: }
14393: }
14394: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14395: my $newspare;
14396: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14397: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
14398: $newspare = $new;
14399: }
14400: }
14401: my @spares;
14402: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14403: @spares = sort(@okspares,$newspare);
14404: } else {
14405: @spares = sort(@okspares);
14406: }
14407: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
14408: if (ref($spareid{$lonhost}) eq 'HASH') {
14409: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
14410: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
14411: if (@diffs > 0) {
14412: $spareschg{$type} = 1;
14413: }
14414: }
14415: }
14416: }
14417: if (keys(%spareschg) > 0) {
14418: $changes{'spares'}{$lonhost} = \%spareschg;
14419: }
14420: }
14421: $defaultshash{'usersessions'}{'offloadnow'} = {};
14422: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14423: my @okoffload;
14424: if (@offloadnow) {
14425: foreach my $server (@offloadnow) {
14426: if (&Apache::lonnet::hostname($server) ne '') {
14427: unless (grep(/^\Q$server\E$/,@okoffload)) {
14428: push(@okoffload,$server);
14429: }
14430: }
14431: }
14432: if (@okoffload) {
14433: foreach my $lonhost (@okoffload) {
14434: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14435: }
14436: }
14437: }
14438: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14439: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14440: if (ref($changes{'spares'}) eq 'HASH') {
14441: if (keys(%{$changes{'spares'}}) > 0) {
14442: $savespares = 1;
14443: }
14444: }
14445: } else {
14446: $savespares = 1;
14447: }
14448: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14449: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14450: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14451: $changes{'offloadnow'} = 1;
14452: last;
14453: }
14454: }
14455: unless ($changes{'offloadnow'}) {
14456: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
14457: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14458: $changes{'offloadnow'} = 1;
14459: last;
14460: }
14461: }
14462: }
14463: } elsif (@okoffload) {
14464: $changes{'offloadnow'} = 1;
14465: }
14466: } elsif (@okoffload) {
14467: $changes{'offloadnow'} = 1;
14468: }
14469: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14470: if ((keys(%changes) > 0) || ($savespares)) {
14471: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14472: $dom);
14473: if ($putresult eq 'ok') {
14474: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14475: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14476: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14477: }
14478: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14479: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14480: }
14481: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14482: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14483: }
14484: }
14485: my $cachetime = 24*60*60;
14486: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14487: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
14488: if (ref($lastactref) eq 'HASH') {
14489: $lastactref->{'domdefaults'} = 1;
14490: $lastactref->{'usersessions'} = 1;
14491: }
14492: if (keys(%changes) > 0) {
14493: my %lt = &usersession_titles();
14494: $resulttext = &mt('Changes made:').'<ul>';
14495: foreach my $prefix (@prefixes) {
14496: if (ref($changes{$prefix}) eq 'HASH') {
14497: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14498: if ($prefix eq 'spares') {
14499: if (ref($changes{$prefix}) eq 'HASH') {
14500: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14501: $resulttext .= '<li><b>'.$lonhost.'</b> ';
14502: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
14503: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14504: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14505: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14506: foreach my $type (@{$types{$prefix}}) {
14507: if ($changes{$prefix}{$lonhost}{$type}) {
14508: my $offloadto = &mt('None');
14509: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14510: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14511: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14512: }
14513: }
14514: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
14515: }
14516: }
14517: }
14518: $resulttext .= '</li>';
14519: }
14520: }
14521: } else {
14522: foreach my $type (@{$types{$prefix}}) {
14523: if (defined($changes{$prefix}{$type})) {
14524: my $newvalue;
14525: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14526: if (ref($defaultshash{'usersessions'}{$prefix})) {
14527: if ($type eq 'version') {
14528: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14529: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14530: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14531: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14532: }
14533: }
14534: }
14535: }
14536: if ($newvalue eq '') {
14537: if ($type eq 'version') {
14538: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14539: } else {
14540: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14541: }
14542: } else {
14543: if ($type eq 'version') {
14544: $newvalue .= ' '.&mt('(or later)');
14545: }
14546: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14547: }
14548: }
14549: }
14550: }
14551: $resulttext .= '</ul>';
14552: }
14553: }
14554: if ($changes{'offloadnow'}) {
14555: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14556: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14557: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14558: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14559: $resulttext .= '<li>'.$lonhost.'</li>';
14560: }
14561: $resulttext .= '</ul>';
14562: } else {
14563: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14564: }
14565: } else {
14566: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14567: }
14568: }
14569: $resulttext .= '</ul>';
14570: } else {
14571: $resulttext = $nochgmsg;
14572: }
14573: } else {
14574: $resulttext = '<span class="LC_error">'.
14575: &mt('An error occurred: [_1]',$putresult).'</span>';
14576: }
14577: } else {
14578: $resulttext = $nochgmsg;
14579: }
14580: return $resulttext;
14581: }
14582:
14583: sub modify_ssl {
14584: my ($dom,$lastactref,%domconfig) = @_;
14585: my (%by_ip,%by_location,@intdoms,@instdoms);
14586: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14587: my @locations = sort(keys(%by_location));
14588: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14589: my (%defaultshash,%changes);
14590: my $action = 'ssl';
14591: my @prefixes = ('connto','connfrom','replication');
14592: foreach my $prefix (@prefixes) {
14593: $defaultshash{$action}{$prefix} = {};
14594: }
14595: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14596: my $resulttext;
14597: my %iphost = &Apache::lonnet::get_iphost();
14598: my @reptypes = ('certreq','nocertreq');
14599: my @connecttypes = ('dom','intdom','other');
14600: my %types = (
14601: connto => \@connecttypes,
14602: connfrom => \@connecttypes,
14603: replication => \@reptypes,
14604: );
14605: foreach my $prefix (sort(keys(%types))) {
14606: foreach my $type (@{$types{$prefix}}) {
14607: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
14608: my $value = 'yes';
14609: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
14610: $value = $env{'form.'.$prefix.'_'.$type};
14611: }
14612: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14613: if ($domconfig{$action}{$prefix}{$type} ne '') {
14614: if ($value ne $domconfig{$action}{$prefix}{$type}) {
14615: $changes{$prefix}{$type} = 1;
14616: }
14617: $defaultshash{$action}{$prefix}{$type} = $value;
14618: } else {
14619: $defaultshash{$action}{$prefix}{$type} = $value;
14620: $changes{$prefix}{$type} = 1;
14621: }
14622: } else {
14623: $defaultshash{$action}{$prefix}{$type} = $value;
14624: $changes{$prefix}{$type} = 1;
14625: }
14626: if (($type eq 'dom') && (keys(%servers) == 1)) {
14627: delete($changes{$prefix}{$type});
14628: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14629: delete($changes{$prefix}{$type});
14630: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14631: delete($changes{$prefix}{$type});
14632: }
14633: } elsif ($prefix eq 'replication') {
14634: if (@locations > 0) {
14635: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14636: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14637: my @okvals;
14638: foreach my $val (@vals) {
14639: if ($val =~ /:/) {
14640: my @items = split(/:/,$val);
14641: foreach my $item (@items) {
14642: if (ref($by_location{$item}) eq 'ARRAY') {
14643: push(@okvals,$item);
14644: }
14645: }
14646: } else {
14647: if (ref($by_location{$val}) eq 'ARRAY') {
14648: push(@okvals,$val);
14649: }
14650: }
14651: }
14652: @okvals = sort(@okvals);
14653: if (ref($domconfig{$action}) eq 'HASH') {
14654: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14655: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
14656: if ($inuse == 0) {
14657: $changes{$prefix}{$type} = 1;
14658: } else {
14659: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14660: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
14661: if (@changed > 0) {
14662: $changes{$prefix}{$type} = 1;
14663: }
14664: }
14665: } else {
14666: if ($inuse == 1) {
14667: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14668: $changes{$prefix}{$type} = 1;
14669: }
14670: }
14671: } else {
14672: if ($inuse == 1) {
14673: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14674: $changes{$prefix}{$type} = 1;
14675: }
14676: }
14677: } else {
14678: if ($inuse == 1) {
14679: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14680: $changes{$prefix}{$type} = 1;
14681: }
14682: }
14683: }
14684: }
14685: }
14686: }
14687: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14688: if (keys(%changes) > 0) {
14689: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14690: $dom);
14691: if ($putresult eq 'ok') {
14692: if (ref($defaultshash{$action}) eq 'HASH') {
14693: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14694: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14695: }
14696: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14697: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14698: }
14699: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14700: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
14701: }
14702: }
14703: my $cachetime = 24*60*60;
14704: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14705: if (ref($lastactref) eq 'HASH') {
14706: $lastactref->{'domdefaults'} = 1;
14707: }
14708: if (keys(%changes) > 0) {
14709: my %titles = &ssl_titles();
14710: $resulttext = &mt('Changes made:').'<ul>';
14711: foreach my $prefix (@prefixes) {
14712: if (ref($changes{$prefix}) eq 'HASH') {
14713: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14714: foreach my $type (@{$types{$prefix}}) {
14715: if (defined($changes{$prefix}{$type})) {
14716: my $newvalue;
14717: if (ref($defaultshash{$action}) eq 'HASH') {
14718: if (ref($defaultshash{$action}{$prefix})) {
14719: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
14720: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14721: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14722: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14723: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14724: }
14725: }
14726: }
14727: if ($newvalue eq '') {
14728: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14729: } else {
14730: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14731: }
14732: }
14733: }
14734: }
14735: $resulttext .= '</ul>';
14736: }
14737: }
14738: } else {
14739: $resulttext = $nochgmsg;
14740: }
14741: } else {
14742: $resulttext = '<span class="LC_error">'.
14743: &mt('An error occurred: [_1]',$putresult).'</span>';
14744: }
14745: } else {
14746: $resulttext = $nochgmsg;
14747: }
14748: return $resulttext;
14749: }
14750:
14751: sub modify_trust {
14752: my ($dom,$lastactref,%domconfig) = @_;
14753: my (%by_ip,%by_location,@intdoms,@instdoms);
14754: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14755: my @locations = sort(keys(%by_location));
14756: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14757: my @types = ('exc','inc');
14758: my (%defaultshash,%changes);
14759: foreach my $prefix (@prefixes) {
14760: $defaultshash{'trust'}{$prefix} = {};
14761: }
14762: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14763: my $resulttext;
14764: foreach my $prefix (@prefixes) {
14765: foreach my $type (@types) {
14766: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14767: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14768: my @okvals;
14769: foreach my $val (@vals) {
14770: if ($val =~ /:/) {
14771: my @items = split(/:/,$val);
14772: foreach my $item (@items) {
14773: if (ref($by_location{$item}) eq 'ARRAY') {
14774: push(@okvals,$item);
14775: }
14776: }
14777: } else {
14778: if (ref($by_location{$val}) eq 'ARRAY') {
14779: push(@okvals,$val);
14780: }
14781: }
14782: }
14783: @okvals = sort(@okvals);
14784: if (ref($domconfig{'trust'}) eq 'HASH') {
14785: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14786: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14787: if ($inuse == 0) {
14788: $changes{$prefix}{$type} = 1;
14789: } else {
14790: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14791: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14792: if (@changed > 0) {
14793: $changes{$prefix}{$type} = 1;
14794: }
14795: }
14796: } else {
14797: if ($inuse == 1) {
14798: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14799: $changes{$prefix}{$type} = 1;
14800: }
14801: }
14802: } else {
14803: if ($inuse == 1) {
14804: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14805: $changes{$prefix}{$type} = 1;
14806: }
14807: }
14808: } else {
14809: if ($inuse == 1) {
14810: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14811: $changes{$prefix}{$type} = 1;
14812: }
14813: }
14814: }
14815: }
14816: my $nochgmsg = &mt('No changes made to trust settings.');
14817: if (keys(%changes) > 0) {
14818: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14819: $dom);
14820: if ($putresult eq 'ok') {
14821: if (ref($defaultshash{'trust'}) eq 'HASH') {
14822: foreach my $prefix (@prefixes) {
14823: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14824: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14825: }
14826: }
14827: }
14828: my $cachetime = 24*60*60;
14829: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14830: if (ref($lastactref) eq 'HASH') {
14831: $lastactref->{'domdefaults'} = 1;
14832: }
14833: if (keys(%changes) > 0) {
14834: my %lt = &trust_titles();
14835: $resulttext = &mt('Changes made:').'<ul>';
14836: foreach my $prefix (@prefixes) {
14837: if (ref($changes{$prefix}) eq 'HASH') {
14838: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14839: foreach my $type (@types) {
14840: if (defined($changes{$prefix}{$type})) {
14841: my $newvalue;
14842: if (ref($defaultshash{'trust'}) eq 'HASH') {
14843: if (ref($defaultshash{'trust'}{$prefix})) {
14844: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14845: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14846: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14847: }
14848: }
14849: }
14850: }
14851: if ($newvalue eq '') {
14852: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14853: } else {
14854: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14855: }
14856: }
14857: }
14858: $resulttext .= '</ul>';
14859: }
14860: }
14861: $resulttext .= '</ul>';
14862: } else {
14863: $resulttext = $nochgmsg;
14864: }
14865: } else {
14866: $resulttext = '<span class="LC_error">'.
14867: &mt('An error occurred: [_1]',$putresult).'</span>';
14868: }
14869: } else {
14870: $resulttext = $nochgmsg;
14871: }
14872: return $resulttext;
14873: }
14874:
14875: sub modify_loadbalancing {
14876: my ($dom,%domconfig) = @_;
14877: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14878: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14879: my ($othertitle,$usertypes,$types) =
14880: &Apache::loncommon::sorted_inst_types($dom);
14881: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14882: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
14883: my @sparestypes = ('primary','default');
14884: my %typetitles = &sparestype_titles();
14885: my $resulttext;
14886: my (%currbalancer,%currtargets,%currrules,%existing);
14887: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14888: %existing = %{$domconfig{'loadbalancing'}};
14889: }
14890: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14891: \%currtargets,\%currrules);
14892: my ($saveloadbalancing,%defaultshash,%changes);
14893: my ($alltypes,$othertypes,$titles) =
14894: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14895: my %ruletitles = &offloadtype_text();
14896: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14897: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14898: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14899: if ($balancer eq '') {
14900: next;
14901: }
14902: if (!exists($servers{$balancer})) {
14903: if (exists($currbalancer{$balancer})) {
14904: push(@{$changes{'delete'}},$balancer);
14905: }
14906: next;
14907: }
14908: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14909: push(@{$changes{'delete'}},$balancer);
14910: next;
14911: }
14912: if (!exists($currbalancer{$balancer})) {
14913: push(@{$changes{'add'}},$balancer);
14914: }
14915: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14916: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14917: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14918: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14919: $saveloadbalancing = 1;
14920: }
14921: foreach my $sparetype (@sparestypes) {
14922: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14923: my @offloadto;
14924: foreach my $target (@targets) {
14925: if (($servers{$target}) && ($target ne $balancer)) {
14926: if ($sparetype eq 'default') {
14927: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14928: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
14929: }
14930: }
14931: unless(grep(/^\Q$target\E$/,@offloadto)) {
14932: push(@offloadto,$target);
14933: }
14934: }
14935: }
14936: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14937: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14938: push(@offloadto,$balancer);
14939: }
14940: }
14941: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
14942: }
14943: if (ref($currtargets{$balancer}) eq 'HASH') {
14944: foreach my $sparetype (@sparestypes) {
14945: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14946: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
14947: if (@targetdiffs > 0) {
14948: $changes{'curr'}{$balancer}{'targets'} = 1;
14949: }
14950: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14951: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14952: $changes{'curr'}{$balancer}{'targets'} = 1;
14953: }
14954: }
14955: }
14956: } else {
14957: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
14958: foreach my $sparetype (@sparestypes) {
14959: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14960: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14961: $changes{'curr'}{$balancer}{'targets'} = 1;
14962: }
14963: }
14964: }
14965: }
14966: }
14967: my $ishomedom;
14968: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14969: $ishomedom = 1;
14970: }
14971: if (ref($alltypes) eq 'ARRAY') {
14972: foreach my $type (@{$alltypes}) {
14973: my $rule;
14974: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
14975: (!$ishomedom)) {
14976: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14977: }
14978: if ($rule eq 'specific') {
14979: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
14980: if (exists($servers{$specifiedhost})) {
14981: $rule = $specifiedhost;
14982: }
14983: }
14984: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14985: if (ref($currrules{$balancer}) eq 'HASH') {
14986: if ($rule ne $currrules{$balancer}{$type}) {
14987: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
14988: }
14989: } elsif ($rule ne '') {
14990: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
14991: }
14992: }
14993: }
14994: }
14995: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14996: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14997: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14998: $defaultshash{'loadbalancing'} = {};
14999: }
15000: my $putresult = &Apache::lonnet::put_dom('configuration',
15001: \%defaultshash,$dom);
15002: if ($putresult eq 'ok') {
15003: if (keys(%changes) > 0) {
15004: my %toupdate;
15005: if (ref($changes{'delete'}) eq 'ARRAY') {
15006: foreach my $balancer (sort(@{$changes{'delete'}})) {
15007: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
15008: $toupdate{$balancer} = 1;
15009: }
15010: }
15011: if (ref($changes{'add'}) eq 'ARRAY') {
15012: foreach my $balancer (sort(@{$changes{'add'}})) {
15013: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
15014: $toupdate{$balancer} = 1;
15015: }
15016: }
15017: if (ref($changes{'curr'}) eq 'HASH') {
15018: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
15019: $toupdate{$balancer} = 1;
15020: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
15021: if ($changes{'curr'}{$balancer}{'targets'}) {
15022: my %offloadstr;
15023: foreach my $sparetype (@sparestypes) {
15024: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15025: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15026: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15027: }
15028: }
15029: }
15030: if (keys(%offloadstr) == 0) {
15031: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
15032: } else {
15033: my $showoffload;
15034: foreach my $sparetype (@sparestypes) {
15035: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
15036: if (defined($offloadstr{$sparetype})) {
15037: $showoffload .= $offloadstr{$sparetype};
15038: } else {
15039: $showoffload .= &mt('None');
15040: }
15041: $showoffload .= (' 'x3);
15042: }
15043: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
15044: }
15045: }
15046: }
15047: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
15048: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
15049: foreach my $type (@{$alltypes}) {
15050: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
15051: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15052: my $balancetext;
15053: if ($rule eq '') {
15054: $balancetext = $ruletitles{'default'};
15055: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
15056: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
15057: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
15058: foreach my $sparetype (@sparestypes) {
15059: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15060: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15061: }
15062: }
15063: foreach my $item (@{$alltypes}) {
15064: next if ($item =~ /^_LC_ipchange/);
15065: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
15066: if ($hasrule eq 'homeserver') {
15067: map { $toupdate{$_} = 1; } (keys(%libraryservers));
15068: } else {
15069: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
15070: if ($servers{$hasrule}) {
15071: $toupdate{$hasrule} = 1;
15072: }
15073: }
15074: }
15075: }
15076: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
15077: $balancetext = $ruletitles{$rule};
15078: } else {
15079: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15080: $balancetext = $ruletitles{'particular'}.' '.$receiver;
15081: if ($receiver) {
15082: $toupdate{$receiver};
15083: }
15084: }
15085: } else {
15086: $balancetext = $ruletitles{$rule};
15087: }
15088: } else {
15089: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
15090: }
15091: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
15092: }
15093: }
15094: }
15095: }
15096: if (keys(%toupdate)) {
15097: my %thismachine;
15098: my $updatedhere;
15099: my $cachetime = 60*60*24;
15100: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
15101: foreach my $lonhost (keys(%toupdate)) {
15102: if ($thismachine{$lonhost}) {
15103: unless ($updatedhere) {
15104: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
15105: $defaultshash{'loadbalancing'},
15106: $cachetime);
15107: $updatedhere = 1;
15108: }
15109: } else {
15110: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
15111: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
15112: }
15113: }
15114: }
15115: }
15116: }
15117: if ($resulttext ne '') {
15118: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
15119: } else {
15120: $resulttext = $nochgmsg;
15121: }
15122: } else {
15123: $resulttext = $nochgmsg;
15124: }
15125: } else {
15126: $resulttext = '<span class="LC_error">'.
15127: &mt('An error occurred: [_1]',$putresult).'</span>';
15128: }
15129: } else {
15130: $resulttext = $nochgmsg;
15131: }
15132: return $resulttext;
15133: }
15134:
15135: sub recurse_check {
15136: my ($chkcats,$categories,$depth,$name) = @_;
15137: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
15138: my $chg = 0;
15139: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
15140: my $category = $chkcats->[$depth]{$name}[$j];
15141: my $item;
15142: if ($category eq '') {
15143: $chg ++;
15144: } else {
15145: my $deeper = $depth + 1;
15146: $item = &escape($category).':'.&escape($name).':'.$depth;
15147: if ($chg) {
15148: $categories->{$item} -= $chg;
15149: }
15150: &recurse_check($chkcats,$categories,$deeper,$category);
15151: $deeper --;
15152: }
15153: }
15154: }
15155: return;
15156: }
15157:
15158: sub recurse_cat_deletes {
15159: my ($item,$coursecategories,$deletions) = @_;
15160: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15161: my $subdepth = $depth + 1;
15162: if (ref($coursecategories) eq 'HASH') {
15163: foreach my $subitem (keys(%{$coursecategories})) {
15164: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
15165: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
15166: delete($coursecategories->{$subitem});
15167: $deletions->{$subitem} = 1;
15168: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
15169: }
15170: }
15171: }
15172: return;
15173: }
15174:
15175: sub active_dc_picker {
15176: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
15177: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
15178: my @domcoord = keys(%domcoords);
15179: if (keys(%currhash)) {
15180: foreach my $dc (keys(%currhash)) {
15181: unless (exists($domcoords{$dc})) {
15182: push(@domcoord,$dc);
15183: }
15184: }
15185: }
15186: @domcoord = sort(@domcoord);
15187: my $numdcs = scalar(@domcoord);
15188: my $rows = 0;
15189: my $table;
15190: if ($numdcs > 1) {
15191: $table = '<table>';
15192: for (my $i=0; $i<@domcoord; $i++) {
15193: my $rem = $i%($numinrow);
15194: if ($rem == 0) {
15195: if ($i > 0) {
15196: $table .= '</tr>';
15197: }
15198: $table .= '<tr>';
15199: $rows ++;
15200: }
15201: my $check = '';
15202: if ($inputtype eq 'radio') {
15203: if (keys(%currhash) == 0) {
15204: if (!$i) {
15205: $check = ' checked="checked"';
15206: }
15207: } elsif (exists($currhash{$domcoord[$i]})) {
15208: $check = ' checked="checked"';
15209: }
15210: } else {
15211: if (exists($currhash{$domcoord[$i]})) {
15212: $check = ' checked="checked"';
15213: }
15214: }
15215: if ($i == @domcoord - 1) {
15216: my $colsleft = $numinrow - $rem;
15217: if ($colsleft > 1) {
15218: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
15219: } else {
15220: $table .= '<td class="LC_left_item">';
15221: }
15222: } else {
15223: $table .= '<td class="LC_left_item">';
15224: }
15225: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
15226: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
15227: $table .= '<span class="LC_nobreak"><label>'.
15228: '<input type="'.$inputtype.'" name="'.$name.'"'.
15229: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
15230: if ($user ne $dcname.':'.$dcdom) {
15231: $table .= ' ('.$dcname.':'.$dcdom.')';
15232: }
15233: $table .= '</label></span></td>';
15234: }
15235: $table .= '</tr></table>';
15236: } elsif ($numdcs == 1) {
15237: my ($dcname,$dcdom) = split(':',$domcoord[0]);
15238: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
15239: if ($inputtype eq 'radio') {
15240: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
15241: if ($user ne $dcname.':'.$dcdom) {
15242: $table .= ' ('.$dcname.':'.$dcdom.')';
15243: }
15244: } else {
15245: my $check;
15246: if (exists($currhash{$domcoord[0]})) {
15247: $check = ' checked="checked"';
15248: }
15249: $table = '<span class="LC_nobreak"><label>'.
15250: '<input type="checkbox" name="'.$name.'" '.
15251: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
15252: if ($user ne $dcname.':'.$dcdom) {
15253: $table .= ' ('.$dcname.':'.$dcdom.')';
15254: }
15255: $table .= '</label></span>';
15256: $rows ++;
15257: }
15258: }
15259: return ($numdcs,$table,$rows);
15260: }
15261:
15262: sub usersession_titles {
15263: return &Apache::lonlocal::texthash(
15264: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
15265: remote => 'Hosting of sessions for users in this domain on servers in other domains',
15266: spares => 'Servers offloaded to, when busy',
15267: version => 'LON-CAPA version requirement',
15268: excludedomain => 'Allow all, but exclude specific domains',
15269: includedomain => 'Deny all, but include specific domains',
15270: primary => 'Primary (checked first)',
15271: default => 'Default',
15272: );
15273: }
15274:
15275: sub id_for_thisdom {
15276: my (%servers) = @_;
15277: my %altids;
15278: foreach my $server (keys(%servers)) {
15279: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
15280: if ($serverhome ne $server) {
15281: $altids{$serverhome} = $server;
15282: }
15283: }
15284: return %altids;
15285: }
15286:
15287: sub count_servers {
15288: my ($currbalancer,%servers) = @_;
15289: my (@spares,$numspares);
15290: foreach my $lonhost (sort(keys(%servers))) {
15291: next if ($currbalancer eq $lonhost);
15292: push(@spares,$lonhost);
15293: }
15294: if ($currbalancer) {
15295: $numspares = scalar(@spares);
15296: } else {
15297: $numspares = scalar(@spares) - 1;
15298: }
15299: return ($numspares,@spares);
15300: }
15301:
15302: sub lonbalance_targets_js {
15303: my ($dom,$types,$servers,$settings) = @_;
15304: my $select = &mt('Select');
15305: my ($alltargets,$allishome,$allinsttypes,@alltypes);
15306: if (ref($servers) eq 'HASH') {
15307: $alltargets = join("','",sort(keys(%{$servers})));
15308: my @homedoms;
15309: foreach my $server (sort(keys(%{$servers}))) {
15310: if (&Apache::lonnet::host_domain($server) eq $dom) {
15311: push(@homedoms,'1');
15312: } else {
15313: push(@homedoms,'0');
15314: }
15315: }
15316: $allishome = join("','",@homedoms);
15317: }
15318: if (ref($types) eq 'ARRAY') {
15319: if (@{$types} > 0) {
15320: @alltypes = @{$types};
15321: }
15322: }
15323: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
15324: $allinsttypes = join("','",@alltypes);
15325: my (%currbalancer,%currtargets,%currrules,%existing);
15326: if (ref($settings) eq 'HASH') {
15327: %existing = %{$settings};
15328: }
15329: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
15330: \%currtargets,\%currrules);
15331: my $balancers = join("','",sort(keys(%currbalancer)));
15332: return <<"END";
15333:
15334: <script type="text/javascript">
15335: // <![CDATA[
15336:
15337: currBalancers = new Array('$balancers');
15338:
15339: function toggleTargets(balnum) {
15340: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15341: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
15342: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
15343: var prevbalancer = prevhostitem.value;
15344: var baltotal = document.getElementById('loadbalancing_total').value;
15345: prevhostitem.value = balancer;
15346: if (prevbalancer != '') {
15347: var prevIdx = currBalancers.indexOf(prevbalancer);
15348: if (prevIdx != -1) {
15349: currBalancers.splice(prevIdx,1);
15350: }
15351: }
15352: if (balancer == '') {
15353: hideSpares(balnum);
15354: } else {
15355: var currIdx = currBalancers.indexOf(balancer);
15356: if (currIdx == -1) {
15357: currBalancers.push(balancer);
15358: }
15359: var homedoms = new Array('$allishome');
15360: var ishomedom = homedoms[lonhostitem.selectedIndex];
15361: showSpares(balancer,ishomedom,balnum);
15362: }
15363: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
15364: return;
15365: }
15366:
15367: function showSpares(balancer,ishomedom,balnum) {
15368: var alltargets = new Array('$alltargets');
15369: var insttypes = new Array('$allinsttypes');
15370: var offloadtypes = new Array('primary','default');
15371:
15372: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
15373: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
15374:
15375: for (var i=0; i<offloadtypes.length; i++) {
15376: var count = 0;
15377: for (var j=0; j<alltargets.length; j++) {
15378: if (alltargets[j] != balancer) {
15379: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
15380: item.value = alltargets[j];
15381: item.style.textAlign='left';
15382: item.style.textFace='normal';
15383: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
15384: if (currBalancers.indexOf(alltargets[j]) == -1) {
15385: item.disabled = '';
15386: } else {
15387: item.disabled = 'disabled';
15388: item.checked = false;
15389: }
15390: count ++;
15391: }
15392: }
15393: }
15394: for (var k=0; k<insttypes.length; k++) {
15395: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
15396: if (ishomedom == 1) {
15397: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15398: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
15399: } else {
15400: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15401: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
15402: }
15403: } else {
15404: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15405: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
15406: }
15407: if ((insttypes[k] != '_LC_external') &&
15408: ((insttypes[k] != '_LC_internetdom') ||
15409: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
15410: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15411: item.options.length = 0;
15412: item.options[0] = new Option("","",true,true);
15413: var idx = 0;
15414: for (var m=0; m<alltargets.length; m++) {
15415: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15416: idx ++;
15417: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15418: }
15419: }
15420: }
15421: }
15422: return;
15423: }
15424:
15425: function hideSpares(balnum) {
15426: var alltargets = new Array('$alltargets');
15427: var insttypes = new Array('$allinsttypes');
15428: var offloadtypes = new Array('primary','default');
15429:
15430: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15431: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
15432:
15433: var total = alltargets.length - 1;
15434: for (var i=0; i<offloadtypes; i++) {
15435: for (var j=0; j<total; j++) {
15436: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15437: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15438: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
15439: }
15440: }
15441: for (var k=0; k<insttypes.length; k++) {
15442: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15443: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
15444: if (insttypes[k] != '_LC_external') {
15445: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15446: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
15447: }
15448: }
15449: return;
15450: }
15451:
15452: function checkOffloads(item,balnum,type) {
15453: var alltargets = new Array('$alltargets');
15454: var offloadtypes = new Array('primary','default');
15455: if (item.checked) {
15456: var total = alltargets.length - 1;
15457: var other;
15458: if (type == offloadtypes[0]) {
15459: other = offloadtypes[1];
15460: } else {
15461: other = offloadtypes[0];
15462: }
15463: for (var i=0; i<total; i++) {
15464: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
15465: if (server == item.value) {
15466: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15467: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
15468: }
15469: }
15470: }
15471: }
15472: return;
15473: }
15474:
15475: function singleServerToggle(balnum,type) {
15476: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
15477: if (offloadtoSelIdx == 0) {
15478: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15479: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
15480:
15481: } else {
15482: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15483: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15484: }
15485: return;
15486: }
15487:
15488: function balanceruleChange(formname,balnum,type) {
15489: if (type == '_LC_external') {
15490: return;
15491: }
15492: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
15493: for (var i=0; i<typesRules.length; i++) {
15494: if (formname.elements[typesRules[i]].checked) {
15495: if (formname.elements[typesRules[i]].value != 'specific') {
15496: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15497: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
15498: } else {
15499: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15500: }
15501: }
15502: }
15503: return;
15504: }
15505:
15506: function balancerDeleteChange(balnum) {
15507: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15508: var baltotal = document.getElementById('loadbalancing_total').value;
15509: var addtarget;
15510: var removetarget;
15511: var action = 'delete';
15512: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15513: var lonhost = hostitem.value;
15514: var currIdx = currBalancers.indexOf(lonhost);
15515: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15516: if (currIdx != -1) {
15517: currBalancers.splice(currIdx,1);
15518: }
15519: addtarget = lonhost;
15520: } else {
15521: if (currIdx == -1) {
15522: currBalancers.push(lonhost);
15523: }
15524: removetarget = lonhost;
15525: action = 'undelete';
15526: }
15527: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15528: }
15529: return;
15530: }
15531:
15532: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15533: if (baltotal > 1) {
15534: var offloadtypes = new Array('primary','default');
15535: var alltargets = new Array('$alltargets');
15536: var insttypes = new Array('$allinsttypes');
15537: for (var i=0; i<baltotal; i++) {
15538: if (i != balnum) {
15539: for (var j=0; j<offloadtypes.length; j++) {
15540: var total = alltargets.length - 1;
15541: for (var k=0; k<total; k++) {
15542: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15543: var server = serveritem.value;
15544: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15545: if (server == addtarget) {
15546: serveritem.disabled = '';
15547: }
15548: }
15549: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15550: if (server == removetarget) {
15551: serveritem.disabled = 'disabled';
15552: serveritem.checked = false;
15553: }
15554: }
15555: }
15556: }
15557: for (var j=0; j<insttypes.length; j++) {
15558: if (insttypes[j] != '_LC_external') {
15559: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15560: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15561: var currSel = singleserver.selectedIndex;
15562: var currVal = singleserver.options[currSel].value;
15563: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15564: var numoptions = singleserver.options.length;
15565: var needsnew = 1;
15566: for (var k=0; k<numoptions; k++) {
15567: if (singleserver.options[k] == addtarget) {
15568: needsnew = 0;
15569: break;
15570: }
15571: }
15572: if (needsnew == 1) {
15573: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15574: }
15575: }
15576: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15577: singleserver.options.length = 0;
15578: if ((currVal) && (currVal != removetarget)) {
15579: singleserver.options[0] = new Option("","",false,false);
15580: } else {
15581: singleserver.options[0] = new Option("","",true,true);
15582: }
15583: var idx = 0;
15584: for (var m=0; m<alltargets.length; m++) {
15585: if (currBalancers.indexOf(alltargets[m]) == -1) {
15586: idx ++;
15587: if (currVal == alltargets[m]) {
15588: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15589: } else {
15590: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15591: }
15592: }
15593: }
15594: }
15595: }
15596: }
15597: }
15598: }
15599: }
15600: }
15601: return;
15602: }
15603:
15604: // ]]>
15605: </script>
15606:
15607: END
15608: }
15609:
15610: sub new_spares_js {
15611: my @sparestypes = ('primary','default');
15612: my $types = join("','",@sparestypes);
15613: my $select = &mt('Select');
15614: return <<"END";
15615:
15616: <script type="text/javascript">
15617: // <![CDATA[
15618:
15619: function updateNewSpares(formname,lonhost) {
15620: var types = new Array('$types');
15621: var include = new Array();
15622: var exclude = new Array();
15623: for (var i=0; i<types.length; i++) {
15624: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15625: for (var j=0; j<spareboxes.length; j++) {
15626: if (formname.elements[spareboxes[j]].checked) {
15627: exclude.push(formname.elements[spareboxes[j]].value);
15628: } else {
15629: include.push(formname.elements[spareboxes[j]].value);
15630: }
15631: }
15632: }
15633: for (var i=0; i<types.length; i++) {
15634: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15635: var selIdx = newSpare.selectedIndex;
15636: var currnew = newSpare.options[selIdx].value;
15637: var okSpares = new Array();
15638: for (var j=0; j<newSpare.options.length; j++) {
15639: var possible = newSpare.options[j].value;
15640: if (possible != '') {
15641: if (exclude.indexOf(possible) == -1) {
15642: okSpares.push(possible);
15643: } else {
15644: if (currnew == possible) {
15645: selIdx = 0;
15646: }
15647: }
15648: }
15649: }
15650: for (var k=0; k<include.length; k++) {
15651: if (okSpares.indexOf(include[k]) == -1) {
15652: okSpares.push(include[k]);
15653: }
15654: }
15655: okSpares.sort();
15656: newSpare.options.length = 0;
15657: if (selIdx == 0) {
15658: newSpare.options[0] = new Option("$select","",true,true);
15659: } else {
15660: newSpare.options[0] = new Option("$select","",false,false);
15661: }
15662: for (var m=0; m<okSpares.length; m++) {
15663: var idx = m+1;
15664: var selThis = 0;
15665: if (selIdx != 0) {
15666: if (okSpares[m] == currnew) {
15667: selThis = 1;
15668: }
15669: }
15670: if (selThis == 1) {
15671: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15672: } else {
15673: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15674: }
15675: }
15676: }
15677: return;
15678: }
15679:
15680: function checkNewSpares(lonhost,type) {
15681: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15682: var chosen = newSpare.options[newSpare.selectedIndex].value;
15683: if (chosen != '') {
15684: var othertype;
15685: var othernewSpare;
15686: if (type == 'primary') {
15687: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15688: }
15689: if (type == 'default') {
15690: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15691: }
15692: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15693: othernewSpare.selectedIndex = 0;
15694: }
15695: }
15696: return;
15697: }
15698:
15699: // ]]>
15700: </script>
15701:
15702: END
15703:
15704: }
15705:
15706: sub common_domprefs_js {
15707: return <<"END";
15708:
15709: <script type="text/javascript">
15710: // <![CDATA[
15711:
15712: function getIndicesByName(formname,item) {
15713: var group = new Array();
15714: for (var i=0;i<formname.elements.length;i++) {
15715: if (formname.elements[i].name == item) {
15716: group.push(formname.elements[i].id);
15717: }
15718: }
15719: return group;
15720: }
15721:
15722: // ]]>
15723: </script>
15724:
15725: END
15726:
15727: }
15728:
15729: sub recaptcha_js {
15730: my %lt = &captcha_phrases();
15731: return <<"END";
15732:
15733: <script type="text/javascript">
15734: // <![CDATA[
15735:
15736: function updateCaptcha(caller,context) {
15737: var privitem;
15738: var pubitem;
15739: var privtext;
15740: var pubtext;
15741: var versionitem;
15742: var versiontext;
15743: if (document.getElementById(context+'_recaptchapub')) {
15744: pubitem = document.getElementById(context+'_recaptchapub');
15745: } else {
15746: return;
15747: }
15748: if (document.getElementById(context+'_recaptchapriv')) {
15749: privitem = document.getElementById(context+'_recaptchapriv');
15750: } else {
15751: return;
15752: }
15753: if (document.getElementById(context+'_recaptchapubtxt')) {
15754: pubtext = document.getElementById(context+'_recaptchapubtxt');
15755: } else {
15756: return;
15757: }
15758: if (document.getElementById(context+'_recaptchaprivtxt')) {
15759: privtext = document.getElementById(context+'_recaptchaprivtxt');
15760: } else {
15761: return;
15762: }
15763: if (document.getElementById(context+'_recaptchaversion')) {
15764: versionitem = document.getElementById(context+'_recaptchaversion');
15765: } else {
15766: return;
15767: }
15768: if (document.getElementById(context+'_recaptchavertxt')) {
15769: versiontext = document.getElementById(context+'_recaptchavertxt');
15770: } else {
15771: return;
15772: }
15773: if (caller.checked) {
15774: if (caller.value == 'recaptcha') {
15775: pubitem.type = 'text';
15776: privitem.type = 'text';
15777: pubitem.size = '40';
15778: privitem.size = '40';
15779: pubtext.innerHTML = "$lt{'pub'}";
15780: privtext.innerHTML = "$lt{'priv'}";
15781: versionitem.type = 'text';
15782: versionitem.size = '3';
15783: versiontext.innerHTML = "$lt{'ver'}";
15784: } else {
15785: pubitem.type = 'hidden';
15786: privitem.type = 'hidden';
15787: versionitem.type = 'hidden';
15788: pubtext.innerHTML = '';
15789: privtext.innerHTML = '';
15790: versiontext.innerHTML = '';
15791: }
15792: }
15793: return;
15794: }
15795:
15796: // ]]>
15797: </script>
15798:
15799: END
15800:
15801: }
15802:
15803: sub toggle_display_js {
15804: return <<"END";
15805:
15806: <script type="text/javascript">
15807: // <![CDATA[
15808:
15809: function toggleDisplay(domForm,caller) {
15810: if (document.getElementById(caller)) {
15811: var divitem = document.getElementById(caller);
15812: var optionsElement = domForm.coursecredits;
15813: var checkval = 1;
15814: var dispval = 'block';
15815: var selfcreateRegExp = /^cancreate_emailverified/;
15816: if (caller == 'emailoptions') {
15817: optionsElement = domForm.cancreate_email;
15818: }
15819: if (caller == 'studentsubmission') {
15820: optionsElement = domForm.postsubmit;
15821: }
15822: if (caller == 'cloneinstcode') {
15823: optionsElement = domForm.canclone;
15824: checkval = 'instcode';
15825: }
15826: if (selfcreateRegExp.test(caller)) {
15827: optionsElement = domForm.elements[caller];
15828: checkval = 'other';
15829: dispval = 'inline'
15830: }
15831: if (optionsElement.length) {
15832: var currval;
15833: for (var i=0; i<optionsElement.length; i++) {
15834: if (optionsElement[i].checked) {
15835: currval = optionsElement[i].value;
15836: }
15837: }
15838: if (currval == checkval) {
15839: divitem.style.display = dispval;
15840: } else {
15841: divitem.style.display = 'none';
15842: }
15843: }
15844: }
15845: return;
15846: }
15847:
15848: // ]]>
15849: </script>
15850:
15851: END
15852:
15853: }
15854:
15855: sub captcha_phrases {
15856: return &Apache::lonlocal::texthash (
15857: priv => 'Private key',
15858: pub => 'Public key',
15859: original => 'original (CAPTCHA)',
15860: recaptcha => 'successor (ReCAPTCHA)',
15861: notused => 'unused',
15862: ver => 'ReCAPTCHA version (1 or 2)',
15863: );
15864: }
15865:
15866: sub devalidate_remote_domconfs {
15867: my ($dom,$cachekeys) = @_;
15868: return unless (ref($cachekeys) eq 'HASH');
15869: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15870: my %thismachine;
15871: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
15872: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
15873: if (keys(%servers)) {
15874: foreach my $server (keys(%servers)) {
15875: next if ($thismachine{$server});
15876: my @cached;
15877: foreach my $name (@posscached) {
15878: if ($cachekeys->{$name}) {
15879: push(@cached,&escape($name).':'.&escape($dom));
15880: }
15881: }
15882: if (@cached) {
15883: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15884: }
15885: }
15886: }
15887: return;
15888: }
15889:
15890: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>