File:
[LON-CAPA] /
loncom /
interface /
domainprefs.pm
Revision
1.274:
download - view:
text,
annotated -
select for diffs
Sun Jul 24 14:34:59 2016 UTC (7 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 5464
Can set failsafe value in domain (or override in Auto-enollment course
configuration to avoid unwanted dropping of students when no data are
retrieved for a particular inststitutional section.
1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.274 2016/07/24 14:34:59 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: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
48: for use by individuals affiliated with the institution. Accordingly, each domain
49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
89: number of rows displayed on the page, and $action is the context (quotas,
90: requestcourses or requestauthor).
91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for Authoring Spaces.
99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
106: (official, unofficial, community, textbook, and placement).
107: In each case the radio buttons allow the selection of one of four values:
108:
109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
120: approval
121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
144: - course requests will be processed automatically up to a limit of
145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
165: use Apache::lonmsg();
166: use Apache::lonconfigsettings;
167: use Apache::lonuserutils();
168: use Apache::loncoursequeueadmin();
169: use LONCAPA qw(:DEFAULT :match);
170: use LONCAPA::Enrollment;
171: use LONCAPA::lonauthcgi();
172: use File::Copy;
173: use Locale::Language;
174: use DateTime::TimeZone;
175: use DateTime::Locale;
176: use Time::HiRes qw( sleep );
177:
178: my $registered_cleanup;
179: my $modified_urls;
180:
181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
189: my $context = 'domain';
190: my $dom = $env{'request.role.domain'};
191: my $domdesc = &Apache::lonnet::domain($dom,'description');
192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
206: ['phase','actions']);
207: my $phase = 'pickactions';
208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
212: my %domconfig =
213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
219: 'requestauthor','selfenrollment','inststatus',
220: 'ltitools'],$dom);
221: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
222: 'autoupdate','autocreate','directorysrch','contacts',
223: 'usercreation','selfcreation','usermodification','scantron',
224: 'requestcourses','requestauthor','coursecategories',
225: 'serverstatuses','helpsettings','coursedefaults',
226: 'ltitools','selfenrollment','usersessions');
227: my %existing;
228: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
229: %existing = %{$domconfig{'loadbalancing'}};
230: }
231: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
232: push(@prefs_order,'loadbalancing');
233: }
234: my %prefs = (
235: 'rolecolors' =>
236: { text => 'Default color schemes',
237: help => 'Domain_Configuration_Color_Schemes',
238: header => [{col1 => 'Student Settings',
239: col2 => '',},
240: {col1 => 'Coordinator Settings',
241: col2 => '',},
242: {col1 => 'Author Settings',
243: col2 => '',},
244: {col1 => 'Administrator Settings',
245: col2 => '',}],
246: print => \&print_rolecolors,
247: modify => \&modify_rolecolors,
248: },
249: 'login' =>
250: { text => 'Log-in page options',
251: help => 'Domain_Configuration_Login_Page',
252: header => [{col1 => 'Log-in Page Items',
253: col2 => '',},
254: {col1 => 'Log-in Help',
255: col2 => 'Value'},
256: {col1 => 'Custom HTML in document head',
257: col2 => 'Value'}],
258: print => \&print_login,
259: modify => \&modify_login,
260: },
261: 'defaults' =>
262: { text => 'Default authentication/language/timezone/portal/types',
263: help => 'Domain_Configuration_LangTZAuth',
264: header => [{col1 => 'Setting',
265: col2 => 'Value'},
266: {col1 => 'Institutional user types',
267: col2 => 'Assignable to e-mail usernames'}],
268: print => \&print_defaults,
269: modify => \&modify_defaults,
270: },
271: 'quotas' =>
272: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
273: help => 'Domain_Configuration_Quotas',
274: header => [{col1 => 'User affiliation',
275: col2 => 'Available tools',
276: col3 => 'Quotas, MB; (Authoring requires role)',}],
277: print => \&print_quotas,
278: modify => \&modify_quotas,
279: },
280: 'autoenroll' =>
281: { text => 'Auto-enrollment settings',
282: help => 'Domain_Configuration_Auto_Enrollment',
283: header => [{col1 => 'Configuration setting',
284: col2 => 'Value(s)'}],
285: print => \&print_autoenroll,
286: modify => \&modify_autoenroll,
287: },
288: 'autoupdate' =>
289: { text => 'Auto-update settings',
290: help => 'Domain_Configuration_Auto_Updates',
291: header => [{col1 => 'Setting',
292: col2 => 'Value',},
293: {col1 => 'Setting',
294: col2 => 'Affiliation'},
295: {col1 => 'User population',
296: col2 => 'Updatable user data'}],
297: print => \&print_autoupdate,
298: modify => \&modify_autoupdate,
299: },
300: 'autocreate' =>
301: { text => 'Auto-course creation settings',
302: help => 'Domain_Configuration_Auto_Creation',
303: header => [{col1 => 'Configuration Setting',
304: col2 => 'Value',}],
305: print => \&print_autocreate,
306: modify => \&modify_autocreate,
307: },
308: 'directorysrch' =>
309: { text => 'Institutional directory searches',
310: help => 'Domain_Configuration_InstDirectory_Search',
311: header => [{col1 => 'Setting',
312: col2 => 'Value',}],
313: print => \&print_directorysrch,
314: modify => \&modify_directorysrch,
315: },
316: 'contacts' =>
317: { text => 'Contact Information',
318: help => 'Domain_Configuration_Contact_Info',
319: header => [{col1 => 'Setting',
320: col2 => 'Value',}],
321: print => \&print_contacts,
322: modify => \&modify_contacts,
323: },
324: 'usercreation' =>
325: { text => 'User creation',
326: help => 'Domain_Configuration_User_Creation',
327: header => [{col1 => 'Format rule type',
328: col2 => 'Format rules in force'},
329: {col1 => 'User account creation',
330: col2 => 'Usernames which may be created',},
331: {col1 => 'Context',
332: col2 => 'Assignable authentication types'}],
333: print => \&print_usercreation,
334: modify => \&modify_usercreation,
335: },
336: 'selfcreation' =>
337: { text => 'Users self-creating accounts',
338: help => 'Domain_Configuration_Self_Creation',
339: header => [{col1 => 'Self-creation with institutional username',
340: col2 => 'Enabled?'},
341: {col1 => 'Institutional user type (login/SSO self-creation)',
342: col2 => 'Information user can enter'},
343: {col1 => 'Self-creation with e-mail as username',
344: col2 => 'Settings'}],
345: print => \&print_selfcreation,
346: modify => \&modify_selfcreation,
347: },
348: 'usermodification' =>
349: { text => 'User modification',
350: help => 'Domain_Configuration_User_Modification',
351: header => [{col1 => 'Target user has role',
352: col2 => 'User information updatable in author context'},
353: {col1 => 'Target user has role',
354: col2 => 'User information updatable in course context'}],
355: print => \&print_usermodification,
356: modify => \&modify_usermodification,
357: },
358: 'scantron' =>
359: { text => 'Bubblesheet format file',
360: help => 'Domain_Configuration_Scantron_Format',
361: header => [ {col1 => 'Item',
362: col2 => '',
363: }],
364: print => \&print_scantron,
365: modify => \&modify_scantron,
366: },
367: 'requestcourses' =>
368: {text => 'Request creation of courses',
369: help => 'Domain_Configuration_Request_Courses',
370: header => [{col1 => 'User affiliation',
371: col2 => 'Availability/Processing of requests',},
372: {col1 => 'Setting',
373: col2 => 'Value'},
374: {col1 => 'Available textbooks',
375: col2 => ''},
376: {col1 => 'Available templates',
377: col2 => ''},
378: {col1 => 'Validation (not official courses)',
379: col2 => 'Value'},],
380: print => \&print_quotas,
381: modify => \&modify_quotas,
382: },
383: 'requestauthor' =>
384: {text => 'Request Authoring Space',
385: help => 'Domain_Configuration_Request_Author',
386: header => [{col1 => 'User affiliation',
387: col2 => 'Availability/Processing of requests',},
388: {col1 => 'Setting',
389: col2 => 'Value'}],
390: print => \&print_quotas,
391: modify => \&modify_quotas,
392: },
393: 'coursecategories' =>
394: { text => 'Cataloging of courses/communities',
395: help => 'Domain_Configuration_Cataloging_Courses',
396: header => [{col1 => 'Catalog type/availability',
397: col2 => '',},
398: {col1 => 'Category settings for standard catalog',
399: col2 => '',},
400: {col1 => 'Categories',
401: col2 => '',
402: }],
403: print => \&print_coursecategories,
404: modify => \&modify_coursecategories,
405: },
406: 'serverstatuses' =>
407: {text => 'Access to server status pages',
408: help => 'Domain_Configuration_Server_Status',
409: header => [{col1 => 'Status Page',
410: col2 => 'Other named users',
411: col3 => 'Specific IPs',
412: }],
413: print => \&print_serverstatuses,
414: modify => \&modify_serverstatuses,
415: },
416: 'helpsettings' =>
417: {text => 'Help page settings',
418: help => 'Domain_Configuration_Help_Settings',
419: header => [{col1 => 'Help Settings (logged-in users)',
420: col2 => 'Value'}],
421: print => \&print_helpsettings,
422: modify => \&modify_helpsettings,
423: },
424: 'coursedefaults' =>
425: {text => 'Course/Community defaults',
426: help => 'Domain_Configuration_Course_Defaults',
427: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
428: col2 => 'Value',},
429: {col1 => 'Defaults which can be overridden for each course by a DC',
430: col2 => 'Value',},],
431: print => \&print_coursedefaults,
432: modify => \&modify_coursedefaults,
433: },
434: 'selfenrollment' =>
435: {text => 'Self-enrollment in Course/Community',
436: help => 'Domain_Configuration_Selfenrollment',
437: header => [{col1 => 'Configuration Rights',
438: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
439: {col1 => 'Defaults',
440: col2 => 'Value'},
441: {col1 => 'Self-enrollment validation (optional)',
442: col2 => 'Value'},],
443: print => \&print_selfenrollment,
444: modify => \&modify_selfenrollment,
445: },
446: 'privacy' =>
447: {text => 'User Privacy',
448: help => 'Domain_Configuration_User_Privacy',
449: header => [{col1 => 'Setting',
450: col2 => 'Value',}],
451: print => \&print_privacy,
452: modify => \&modify_privacy,
453: },
454: 'usersessions' =>
455: {text => 'User session hosting/offloading',
456: help => 'Domain_Configuration_User_Sessions',
457: header => [{col1 => 'Domain server',
458: col2 => 'Servers to offload sessions to when busy'},
459: {col1 => 'Hosting of users from other domains',
460: col2 => 'Rules'},
461: {col1 => "Hosting domain's own users elsewhere",
462: col2 => 'Rules'}],
463: print => \&print_usersessions,
464: modify => \&modify_usersessions,
465: },
466: 'loadbalancing' =>
467: {text => 'Dedicated Load Balancer(s)',
468: help => 'Domain_Configuration_Load_Balancing',
469: header => [{col1 => 'Balancers',
470: col2 => 'Default destinations',
471: col3 => 'User affiliation',
472: col4 => 'Overrides'},
473: ],
474: print => \&print_loadbalancing,
475: modify => \&modify_loadbalancing,
476: },
477: 'ltitools' =>
478: {text => 'External Tools (LTI)',
479: help => 'Domain_configuration_LTI_Tools',
480: header => [{col1 => 'Setting',
481: col2 => 'Value',}],
482: print => \&print_ltitools,
483: modify => \&modify_ltitools,
484: },
485:
486: );
487: if (keys(%servers) > 1) {
488: $prefs{'login'} = { text => 'Log-in page options',
489: help => 'Domain_Configuration_Login_Page',
490: header => [{col1 => 'Log-in Service',
491: col2 => 'Server Setting',},
492: {col1 => 'Log-in Page Items',
493: col2 => ''},
494: {col1 => 'Log-in Help',
495: col2 => 'Value'},
496: {col1 => 'Custom HTML in document head',
497: col2 => 'Value'}],
498: print => \&print_login,
499: modify => \&modify_login,
500: };
501: }
502:
503: my @roles = ('student','coordinator','author','admin');
504: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
505: &Apache::lonhtmlcommon::add_breadcrumb
506: ({href=>"javascript:changePage(document.$phase,'pickactions')",
507: text=>"Settings to display/modify"});
508: my $confname = $dom.'-domainconfig';
509:
510: if ($phase eq 'process') {
511: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
512: \%prefs,\%domconfig,$confname,\@roles);
513: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
514: $r->rflush();
515: &devalidate_remote_domconfs($dom,$result);
516: }
517: } elsif ($phase eq 'display') {
518: my $js = &recaptcha_js().
519: &toggle_display_js();
520: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
521: my ($othertitle,$usertypes,$types) =
522: &Apache::loncommon::sorted_inst_types($dom);
523: $js .= &lonbalance_targets_js($dom,$types,\%servers,
524: $domconfig{'loadbalancing'}).
525: &new_spares_js().
526: &common_domprefs_js().
527: &Apache::loncommon::javascript_array_indexof();
528: }
529: if (grep(/^requestcourses$/,@actions)) {
530: my $javascript_validations;
531: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
532: $js .= <<END;
533: <script type="text/javascript">
534: $javascript_validations
535: </script>
536: $coursebrowserjs
537: END
538: }
539: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
540: } else {
541: # check if domconfig user exists for the domain.
542: my $servadm = $r->dir_config('lonAdmEMail');
543: my ($configuserok,$author_ok,$switchserver) =
544: &config_check($dom,$confname,$servadm);
545: unless ($configuserok eq 'ok') {
546: &Apache::lonconfigsettings::print_header($r,$phase,$context);
547: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
548: $confname).
549: '<br />'
550: );
551: if ($switchserver) {
552: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
553: '<br />'.
554: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
555: '<br />'.
556: &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).
557: '<br />'.
558: &mt('To do that now, use the following link: [_1]',$switchserver)
559: );
560: } else {
561: $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.').
562: '<br />'.
563: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
564: );
565: }
566: $r->print(&Apache::loncommon::end_page());
567: return OK;
568: }
569: if (keys(%domconfig) == 0) {
570: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
571: my @ids=&Apache::lonnet::current_machine_ids();
572: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
573: my %designhash = &Apache::loncommon::get_domainconf($dom);
574: my @loginimages = ('img','logo','domlogo','login');
575: my $custom_img_count = 0;
576: foreach my $img (@loginimages) {
577: if ($designhash{$dom.'.login.'.$img} ne '') {
578: $custom_img_count ++;
579: }
580: }
581: foreach my $role (@roles) {
582: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
583: $custom_img_count ++;
584: }
585: }
586: if ($custom_img_count > 0) {
587: &Apache::lonconfigsettings::print_header($r,$phase,$context);
588: my $switch_server = &check_switchserver($dom,$confname);
589: $r->print(
590: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
591: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
592: &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 />'.
593: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
594: if ($switch_server) {
595: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
596: }
597: $r->print(&Apache::loncommon::end_page());
598: return OK;
599: }
600: }
601: }
602: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
603: }
604: return OK;
605: }
606:
607: sub process_changes {
608: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
609: my %domconfig;
610: if (ref($values) eq 'HASH') {
611: %domconfig = %{$values};
612: }
613: my $output;
614: if ($action eq 'login') {
615: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
616: } elsif ($action eq 'rolecolors') {
617: $output = &modify_rolecolors($r,$dom,$confname,$roles,
618: $lastactref,%domconfig);
619: } elsif ($action eq 'quotas') {
620: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
621: } elsif ($action eq 'autoenroll') {
622: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
623: } elsif ($action eq 'autoupdate') {
624: $output = &modify_autoupdate($dom,%domconfig);
625: } elsif ($action eq 'autocreate') {
626: $output = &modify_autocreate($dom,%domconfig);
627: } elsif ($action eq 'directorysrch') {
628: $output = &modify_directorysrch($dom,%domconfig);
629: } elsif ($action eq 'usercreation') {
630: $output = &modify_usercreation($dom,%domconfig);
631: } elsif ($action eq 'selfcreation') {
632: $output = &modify_selfcreation($dom,%domconfig);
633: } elsif ($action eq 'usermodification') {
634: $output = &modify_usermodification($dom,%domconfig);
635: } elsif ($action eq 'contacts') {
636: $output = &modify_contacts($dom,$lastactref,%domconfig);
637: } elsif ($action eq 'defaults') {
638: $output = &modify_defaults($dom,$lastactref,%domconfig);
639: } elsif ($action eq 'scantron') {
640: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
641: } elsif ($action eq 'coursecategories') {
642: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
643: } elsif ($action eq 'serverstatuses') {
644: $output = &modify_serverstatuses($dom,%domconfig);
645: } elsif ($action eq 'requestcourses') {
646: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
647: } elsif ($action eq 'requestauthor') {
648: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
649: } elsif ($action eq 'helpsettings') {
650: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
651: } elsif ($action eq 'coursedefaults') {
652: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
653: } elsif ($action eq 'selfenrollment') {
654: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
655: } elsif ($action eq 'usersessions') {
656: $output = &modify_usersessions($dom,$lastactref,%domconfig);
657: } elsif ($action eq 'loadbalancing') {
658: $output = &modify_loadbalancing($dom,%domconfig);
659: } elsif ($action eq 'ltitools') {
660: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
661: }
662: return $output;
663: }
664:
665: sub print_config_box {
666: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
667: my $rowtotal = 0;
668: my $output;
669: if ($action eq 'coursecategories') {
670: $output = &coursecategories_javascript($settings);
671: } elsif ($action eq 'defaults') {
672: $output = &defaults_javascript($settings);
673: }
674: $output .=
675: '<table class="LC_nested_outer">
676: <tr>
677: <th align="left" valign="middle"><span class="LC_nobreak">'.
678: &mt($item->{text}).' '.
679: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
680: '</tr>';
681: $rowtotal ++;
682: my $numheaders = 1;
683: if (ref($item->{'header'}) eq 'ARRAY') {
684: $numheaders = scalar(@{$item->{'header'}});
685: }
686: if ($numheaders > 1) {
687: my $colspan = '';
688: my $rightcolspan = '';
689: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
690: (($action eq 'login') && ($numheaders < 4))) {
691: $colspan = ' colspan="2"';
692: }
693: if ($action eq 'usersessions') {
694: $rightcolspan = ' colspan="3"';
695: }
696: $output .= '
697: <tr>
698: <td>
699: <table class="LC_nested">
700: <tr class="LC_info_row">
701: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
702: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
703: </tr>';
704: $rowtotal ++;
705: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
706: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
707: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
708: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
709: } elsif ($action eq 'coursecategories') {
710: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
711: } elsif ($action eq 'login') {
712: if ($numheaders == 4) {
713: $colspan = ' colspan="2"';
714: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
715: } else {
716: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
717: }
718: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
719: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
720: } elsif ($action eq 'rolecolors') {
721: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
722: }
723: $output .= '
724: </table>
725: </td>
726: </tr>
727: <tr>
728: <td>
729: <table class="LC_nested">
730: <tr class="LC_info_row">
731: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
732: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
733: </tr>';
734: $rowtotal ++;
735: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
736: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
737: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
738: if ($action eq 'coursecategories') {
739: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
740: $colspan = ' colspan="2"';
741: } else {
742: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
743: }
744: $output .= '
745: </table>
746: </td>
747: </tr>
748: <tr>
749: <td>
750: <table class="LC_nested">
751: <tr class="LC_info_row">
752: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
753: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
754: </tr>'."\n";
755: if ($action eq 'coursecategories') {
756: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
757: } else {
758: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
759: }
760: $rowtotal ++;
761: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
762: ($action eq 'defaults')) {
763: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
764: } elsif ($action eq 'login') {
765: if ($numheaders == 4) {
766: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
767: </table>
768: </td>
769: </tr>
770: <tr>
771: <td>
772: <table class="LC_nested">
773: <tr class="LC_info_row">
774: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
775: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
776: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
777: $rowtotal ++;
778: } else {
779: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
780: }
781: $output .= '
782: </table>
783: </td>
784: </tr>
785: <tr>
786: <td>
787: <table class="LC_nested">
788: <tr class="LC_info_row">';
789: if ($numheaders == 4) {
790: $output .= '
791: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
792: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
793: </tr>';
794: } else {
795: $output .= '
796: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
797: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
798: </tr>';
799: }
800: $rowtotal ++;
801: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
802: } elsif ($action eq 'requestcourses') {
803: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
804: $rowtotal ++;
805: $output .= &print_studentcode($settings,\$rowtotal).'
806: </table>
807: </td>
808: </tr>
809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">
813: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
814: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
815: &textbookcourses_javascript($settings).
816: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
817: </table>
818: </td>
819: </tr>
820: <tr>
821: <td>
822: <table class="LC_nested">
823: <tr class="LC_info_row">
824: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
825: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
826: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
827: </table>
828: </td>
829: </tr>
830: <tr>
831: <td>
832: <table class="LC_nested">
833: <tr class="LC_info_row">
834: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
835: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
836: </tr>'.
837: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
838: } elsif ($action eq 'requestauthor') {
839: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
840: $rowtotal ++;
841: } elsif ($action eq 'rolecolors') {
842: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
843: </table>
844: </td>
845: </tr>
846: <tr>
847: <td>
848: <table class="LC_nested">
849: <tr class="LC_info_row">
850: <td class="LC_left_item"'.$colspan.' valign="top">'.
851: &mt($item->{'header'}->[2]->{'col1'}).'</td>
852: <td class="LC_right_item" valign="top">'.
853: &mt($item->{'header'}->[2]->{'col2'}).'</td>
854: </tr>'.
855: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
856: </table>
857: </td>
858: </tr>
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'}->[3]->{'col1'}).'</td>
864: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
865: </tr>'.
866: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
867: $rowtotal += 2;
868: }
869: } else {
870: $output .= '
871: <tr>
872: <td>
873: <table class="LC_nested">
874: <tr class="LC_info_row">';
875: if (($action eq 'login') || ($action eq 'directorysrch')) {
876: $output .= '
877: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
878: } elsif ($action eq 'serverstatuses') {
879: $output .= '
880: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
881: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
882:
883: } else {
884: $output .= '
885: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
886: }
887: if (defined($item->{'header'}->[0]->{'col3'})) {
888: $output .= '<td class="LC_left_item" valign="top">'.
889: &mt($item->{'header'}->[0]->{'col2'});
890: if ($action eq 'serverstatuses') {
891: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
892: }
893: } else {
894: $output .= '<td class="LC_right_item" valign="top">'.
895: &mt($item->{'header'}->[0]->{'col2'});
896: }
897: $output .= '</td>';
898: if ($item->{'header'}->[0]->{'col3'}) {
899: if (defined($item->{'header'}->[0]->{'col4'})) {
900: $output .= '<td class="LC_left_item" valign="top">'.
901: &mt($item->{'header'}->[0]->{'col3'});
902: } else {
903: $output .= '<td class="LC_right_item" valign="top">'.
904: &mt($item->{'header'}->[0]->{'col3'});
905: }
906: if ($action eq 'serverstatuses') {
907: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
908: }
909: $output .= '</td>';
910: }
911: if ($item->{'header'}->[0]->{'col4'}) {
912: $output .= '<td class="LC_right_item" valign="top">'.
913: &mt($item->{'header'}->[0]->{'col4'});
914: }
915: $output .= '</tr>';
916: $rowtotal ++;
917: if ($action eq 'quotas') {
918: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
919: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
920: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
921: ($action eq 'ltitools')) {
922: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
923: } elsif ($action eq 'scantron') {
924: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
925: } elsif ($action eq 'helpsettings') {
926: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
927: }
928: }
929: $output .= '
930: </table>
931: </td>
932: </tr>
933: </table><br />';
934: return ($output,$rowtotal);
935: }
936:
937: sub print_login {
938: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
939: my ($css_class,$datatable);
940: my %choices = &login_choices();
941:
942: if ($caller eq 'service') {
943: my %servers = &Apache::lonnet::internet_dom_servers($dom);
944: my $choice = $choices{'disallowlogin'};
945: $css_class = ' class="LC_odd_row"';
946: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
947: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
948: '<th>'.$choices{'server'}.'</th>'.
949: '<th>'.$choices{'serverpath'}.'</th>'.
950: '<th>'.$choices{'custompath'}.'</th>'.
951: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
952: my %disallowed;
953: if (ref($settings) eq 'HASH') {
954: if (ref($settings->{'loginvia'}) eq 'HASH') {
955: %disallowed = %{$settings->{'loginvia'}};
956: }
957: }
958: foreach my $lonhost (sort(keys(%servers))) {
959: my $direct = 'selected="selected"';
960: if (ref($disallowed{$lonhost}) eq 'HASH') {
961: if ($disallowed{$lonhost}{'server'} ne '') {
962: $direct = '';
963: }
964: }
965: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
966: '<td><select name="'.$lonhost.'_server">'.
967: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
968: '</option>';
969: foreach my $hostid (sort(keys(%servers))) {
970: next if ($servers{$hostid} eq $servers{$lonhost});
971: my $selected = '';
972: if (ref($disallowed{$lonhost}) eq 'HASH') {
973: if ($hostid eq $disallowed{$lonhost}{'server'}) {
974: $selected = 'selected="selected"';
975: }
976: }
977: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
978: $servers{$hostid}.'</option>';
979: }
980: $datatable .= '</select></td>'.
981: '<td><select name="'.$lonhost.'_serverpath">';
982: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
983: my $pathname = $path;
984: if ($path eq 'custom') {
985: $pathname = &mt('Custom Path').' ->';
986: }
987: my $selected = '';
988: if (ref($disallowed{$lonhost}) eq 'HASH') {
989: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
990: $selected = 'selected="selected"';
991: }
992: } elsif ($path eq '') {
993: $selected = 'selected="selected"';
994: }
995: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
996: }
997: $datatable .= '</select></td>';
998: my ($custom,$exempt);
999: if (ref($disallowed{$lonhost}) eq 'HASH') {
1000: $custom = $disallowed{$lonhost}{'custompath'};
1001: $exempt = $disallowed{$lonhost}{'exempt'};
1002: }
1003: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1004: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1005: '</tr>';
1006: }
1007: $datatable .= '</table></td></tr>';
1008: return $datatable;
1009: } elsif ($caller eq 'page') {
1010: my %defaultchecked = (
1011: 'coursecatalog' => 'on',
1012: 'helpdesk' => 'on',
1013: 'adminmail' => 'off',
1014: 'newuser' => 'off',
1015: );
1016: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1017: my (%checkedon,%checkedoff);
1018: foreach my $item (@toggles) {
1019: if ($defaultchecked{$item} eq 'on') {
1020: $checkedon{$item} = ' checked="checked" ';
1021: $checkedoff{$item} = ' ';
1022: } elsif ($defaultchecked{$item} eq 'off') {
1023: $checkedoff{$item} = ' checked="checked" ';
1024: $checkedon{$item} = ' ';
1025: }
1026: }
1027: my @images = ('img','logo','domlogo','login');
1028: my @logintext = ('textcol','bgcol');
1029: my @bgs = ('pgbg','mainbg','sidebg');
1030: my @links = ('link','alink','vlink');
1031: my %designhash = &Apache::loncommon::get_domainconf($dom);
1032: my %defaultdesign = %Apache::loncommon::defaultdesign;
1033: my (%is_custom,%designs);
1034: my %defaults = (
1035: font => $defaultdesign{'login.font'},
1036: );
1037: foreach my $item (@images) {
1038: $defaults{$item} = $defaultdesign{'login.'.$item};
1039: $defaults{'showlogo'}{$item} = 1;
1040: }
1041: foreach my $item (@bgs) {
1042: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1043: }
1044: foreach my $item (@logintext) {
1045: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1046: }
1047: foreach my $item (@links) {
1048: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1049: }
1050: if (ref($settings) eq 'HASH') {
1051: foreach my $item (@toggles) {
1052: if ($settings->{$item} eq '1') {
1053: $checkedon{$item} = ' checked="checked" ';
1054: $checkedoff{$item} = ' ';
1055: } elsif ($settings->{$item} eq '0') {
1056: $checkedoff{$item} = ' checked="checked" ';
1057: $checkedon{$item} = ' ';
1058: }
1059: }
1060: foreach my $item (@images) {
1061: if (defined($settings->{$item})) {
1062: $designs{$item} = $settings->{$item};
1063: $is_custom{$item} = 1;
1064: }
1065: if (defined($settings->{'showlogo'}{$item})) {
1066: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1067: }
1068: }
1069: foreach my $item (@logintext) {
1070: if ($settings->{$item} ne '') {
1071: $designs{'logintext'}{$item} = $settings->{$item};
1072: $is_custom{$item} = 1;
1073: }
1074: }
1075: if ($settings->{'font'} ne '') {
1076: $designs{'font'} = $settings->{'font'};
1077: $is_custom{'font'} = 1;
1078: }
1079: foreach my $item (@bgs) {
1080: if ($settings->{$item} ne '') {
1081: $designs{'bgs'}{$item} = $settings->{$item};
1082: $is_custom{$item} = 1;
1083: }
1084: }
1085: foreach my $item (@links) {
1086: if ($settings->{$item} ne '') {
1087: $designs{'links'}{$item} = $settings->{$item};
1088: $is_custom{$item} = 1;
1089: }
1090: }
1091: } else {
1092: if ($designhash{$dom.'.login.font'} ne '') {
1093: $designs{'font'} = $designhash{$dom.'.login.font'};
1094: $is_custom{'font'} = 1;
1095: }
1096: foreach my $item (@images) {
1097: if ($designhash{$dom.'.login.'.$item} ne '') {
1098: $designs{$item} = $designhash{$dom.'.login.'.$item};
1099: $is_custom{$item} = 1;
1100: }
1101: }
1102: foreach my $item (@bgs) {
1103: if ($designhash{$dom.'.login.'.$item} ne '') {
1104: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1105: $is_custom{$item} = 1;
1106: }
1107: }
1108: foreach my $item (@links) {
1109: if ($designhash{$dom.'.login.'.$item} ne '') {
1110: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1111: $is_custom{$item} = 1;
1112: }
1113: }
1114: }
1115: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1116: logo => 'Institution Logo',
1117: domlogo => 'Domain Logo',
1118: login => 'Login box');
1119: my $itemcount = 1;
1120: foreach my $item (@toggles) {
1121: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1122: $datatable .=
1123: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1124: '</td><td>'.
1125: '<span class="LC_nobreak"><label><input type="radio" name="'.
1126: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1127: '</label> <label><input type="radio" name="'.$item.'"'.
1128: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1129: '</tr>';
1130: $itemcount ++;
1131: }
1132: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1133: $datatable .= '</tr></table></td></tr>';
1134: } elsif ($caller eq 'help') {
1135: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1136: my $switchserver = &check_switchserver($dom,$confname);
1137: my $itemcount = 1;
1138: $defaulturl = '/adm/loginproblems.html';
1139: $defaulttype = 'default';
1140: %lt = &Apache::lonlocal::texthash (
1141: del => 'Delete?',
1142: rep => 'Replace:',
1143: upl => 'Upload:',
1144: default => 'Default',
1145: custom => 'Custom',
1146: );
1147: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1148: my @currlangs;
1149: if (ref($settings) eq 'HASH') {
1150: if (ref($settings->{'helpurl'}) eq 'HASH') {
1151: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1152: next if ($settings->{'helpurl'}{$key} eq '');
1153: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1154: $type{$key} = 'custom';
1155: unless ($key eq 'nolang') {
1156: push(@currlangs,$key);
1157: }
1158: }
1159: } elsif ($settings->{'helpurl'} ne '') {
1160: $type{'nolang'} = 'custom';
1161: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1162: }
1163: }
1164: foreach my $lang ('nolang',sort(@currlangs)) {
1165: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1166: $datatable .= '<tr'.$css_class.'>';
1167: if ($url{$lang} eq '') {
1168: $url{$lang} = $defaulturl;
1169: }
1170: if ($type{$lang} eq '') {
1171: $type{$lang} = $defaulttype;
1172: }
1173: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1174: if ($lang eq 'nolang') {
1175: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1176: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1177: } else {
1178: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1179: $langchoices{$lang},
1180: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1181: }
1182: $datatable .= '</span></td>'."\n".
1183: '<td class="LC_left_item">';
1184: if ($type{$lang} eq 'custom') {
1185: $datatable .= '<span class="LC_nobreak"><label>'.
1186: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1187: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1188: } else {
1189: $datatable .= $lt{'upl'};
1190: }
1191: $datatable .='<br />';
1192: if ($switchserver) {
1193: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1194: } else {
1195: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1196: }
1197: $datatable .= '</td></tr>';
1198: $itemcount ++;
1199: }
1200: my @addlangs;
1201: foreach my $lang (sort(keys(%langchoices))) {
1202: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1203: push(@addlangs,$lang);
1204: }
1205: if (@addlangs > 0) {
1206: my %toadd;
1207: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1208: $toadd{''} = &mt('Select');
1209: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1210: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1211: &mt('Add log-in help page for a specific language:').' '.
1212: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1213: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1214: if ($switchserver) {
1215: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1216: } else {
1217: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1218: }
1219: $datatable .= '</td></tr>';
1220: $itemcount ++;
1221: }
1222: $datatable .= &captcha_choice('login',$settings,$itemcount);
1223: } elsif ($caller eq 'headtag') {
1224: my %domservers = &Apache::lonnet::get_servers($dom);
1225: my $choice = $choices{'headtag'};
1226: $css_class = ' class="LC_odd_row"';
1227: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1228: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1229: '<th>'.$choices{'current'}.'</th>'.
1230: '<th>'.$choices{'action'}.'</th>'.
1231: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1232: my (%currurls,%currexempt);
1233: if (ref($settings) eq 'HASH') {
1234: if (ref($settings->{'headtag'}) eq 'HASH') {
1235: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1236: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1237: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1238: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1239: }
1240: }
1241: }
1242: }
1243: my %lt = &Apache::lonlocal::texthash(
1244: del => 'Delete?',
1245: rep => 'Replace:',
1246: upl => 'Upload:',
1247: curr => 'View contents',
1248: none => 'None',
1249: );
1250: my $switchserver = &check_switchserver($dom,$confname);
1251: foreach my $lonhost (sort(keys(%domservers))) {
1252: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1253: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1254: if ($currurls{$lonhost}) {
1255: $datatable .= '<td class="LC_right_item"><a href="'.
1256: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1257: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1258: '">'.$lt{'curr'}.'</a></td>'.
1259: '<td><span class="LC_nobreak"><label>'.
1260: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1261: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1262: } else {
1263: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1264: }
1265: $datatable .='<br />';
1266: if ($switchserver) {
1267: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1268: } else {
1269: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1270: }
1271: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1272: }
1273: $datatable .= '</table></td></tr>';
1274: }
1275: return $datatable;
1276: }
1277:
1278: sub login_choices {
1279: my %choices =
1280: &Apache::lonlocal::texthash (
1281: coursecatalog => 'Display Course/Community Catalog link?',
1282: adminmail => "Display Administrator's E-mail Address?",
1283: helpdesk => 'Display "Contact Helpdesk" link',
1284: disallowlogin => "Login page requests redirected",
1285: hostid => "Server",
1286: server => "Redirect to:",
1287: serverpath => "Path",
1288: custompath => "Custom",
1289: exempt => "Exempt IP(s)",
1290: directlogin => "No redirect",
1291: newuser => "Link to create a user account",
1292: img => "Header",
1293: logo => "Main Logo",
1294: domlogo => "Domain Logo",
1295: login => "Log-in Header",
1296: textcol => "Text color",
1297: bgcol => "Box color",
1298: bgs => "Background colors",
1299: links => "Link colors",
1300: font => "Font color",
1301: pgbg => "Header",
1302: mainbg => "Page",
1303: sidebg => "Login box",
1304: link => "Link",
1305: alink => "Active link",
1306: vlink => "Visited link",
1307: headtag => "Custom markup",
1308: action => "Action",
1309: current => "Current",
1310: );
1311: return %choices;
1312: }
1313:
1314: sub print_rolecolors {
1315: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1316: my %choices = &color_font_choices();
1317: my @bgs = ('pgbg','tabbg','sidebg');
1318: my @links = ('link','alink','vlink');
1319: my @images = ('img');
1320: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1321: my %designhash = &Apache::loncommon::get_domainconf($dom);
1322: my %defaultdesign = %Apache::loncommon::defaultdesign;
1323: my (%is_custom,%designs);
1324: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1325: if (ref($settings) eq 'HASH') {
1326: if (ref($settings->{$role}) eq 'HASH') {
1327: if ($settings->{$role}->{'img'} ne '') {
1328: $designs{'img'} = $settings->{$role}->{'img'};
1329: $is_custom{'img'} = 1;
1330: }
1331: if ($settings->{$role}->{'font'} ne '') {
1332: $designs{'font'} = $settings->{$role}->{'font'};
1333: $is_custom{'font'} = 1;
1334: }
1335: if ($settings->{$role}->{'fontmenu'} ne '') {
1336: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1337: $is_custom{'fontmenu'} = 1;
1338: }
1339: foreach my $item (@bgs) {
1340: if ($settings->{$role}->{$item} ne '') {
1341: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1342: $is_custom{$item} = 1;
1343: }
1344: }
1345: foreach my $item (@links) {
1346: if ($settings->{$role}->{$item} ne '') {
1347: $designs{'links'}{$item} = $settings->{$role}->{$item};
1348: $is_custom{$item} = 1;
1349: }
1350: }
1351: }
1352: } else {
1353: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1354: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1355: $is_custom{'img'} = 1;
1356: }
1357: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1358: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1359: $is_custom{'fontmenu'} = 1;
1360: }
1361: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1362: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1363: $is_custom{'font'} = 1;
1364: }
1365: foreach my $item (@bgs) {
1366: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1367: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1368: $is_custom{$item} = 1;
1369:
1370: }
1371: }
1372: foreach my $item (@links) {
1373: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1374: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1375: $is_custom{$item} = 1;
1376: }
1377: }
1378: }
1379: my $itemcount = 1;
1380: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1381: $datatable .= '</tr></table></td></tr>';
1382: return $datatable;
1383: }
1384:
1385: sub role_defaults {
1386: my ($role,$bgs,$links,$images,$logintext) = @_;
1387: my %defaults;
1388: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1389: return %defaults;
1390: }
1391: my %defaultdesign = %Apache::loncommon::defaultdesign;
1392: if ($role eq 'login') {
1393: %defaults = (
1394: font => $defaultdesign{$role.'.font'},
1395: );
1396: if (ref($logintext) eq 'ARRAY') {
1397: foreach my $item (@{$logintext}) {
1398: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1399: }
1400: }
1401: foreach my $item (@{$images}) {
1402: $defaults{'showlogo'}{$item} = 1;
1403: }
1404: } else {
1405: %defaults = (
1406: img => $defaultdesign{$role.'.img'},
1407: font => $defaultdesign{$role.'.font'},
1408: fontmenu => $defaultdesign{$role.'.fontmenu'},
1409: );
1410: }
1411: foreach my $item (@{$bgs}) {
1412: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1413: }
1414: foreach my $item (@{$links}) {
1415: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1416: }
1417: foreach my $item (@{$images}) {
1418: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1419: }
1420: return %defaults;
1421: }
1422:
1423: sub display_color_options {
1424: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1425: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1426: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1427: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1428: my $datatable = '<tr'.$css_class.'>'.
1429: '<td>'.$choices->{'font'}.'</td>';
1430: if (!$is_custom->{'font'}) {
1431: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1432: } else {
1433: $datatable .= '<td> </td>';
1434: }
1435: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1436:
1437: $datatable .= '<td><span class="LC_nobreak">'.
1438: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1439: ' value="'.$current_color.'" /> '.
1440: ' </td></tr>';
1441: unless ($role eq 'login') {
1442: $datatable .= '<tr'.$css_class.'>'.
1443: '<td>'.$choices->{'fontmenu'}.'</td>';
1444: if (!$is_custom->{'fontmenu'}) {
1445: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1446: } else {
1447: $datatable .= '<td> </td>';
1448: }
1449: $current_color = $designs->{'fontmenu'} ?
1450: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1451: $datatable .= '<td><span class="LC_nobreak">'.
1452: '<input class="colorchooser" type="text" size="10" name="'
1453: .$role.'_fontmenu"'.
1454: ' value="'.$current_color.'" /> '.
1455: ' </td></tr>';
1456: }
1457: my $switchserver = &check_switchserver($dom,$confname);
1458: foreach my $img (@{$images}) {
1459: $itemcount ++;
1460: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1461: $datatable .= '<tr'.$css_class.'>'.
1462: '<td>'.$choices->{$img};
1463: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1464: if ($role eq 'login') {
1465: if ($img eq 'login') {
1466: $login_hdr_pick =
1467: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1468: $logincolors =
1469: &login_text_colors($img,$role,$logintext,$phase,$choices,
1470: $designs,$defaults);
1471: } elsif ($img ne 'domlogo') {
1472: $datatable.= &logo_display_options($img,$defaults,$designs);
1473: }
1474: }
1475: $datatable .= '</td>';
1476: if ($designs->{$img} ne '') {
1477: $imgfile = $designs->{$img};
1478: $img_import = ($imgfile =~ m{^/adm/});
1479: } else {
1480: $imgfile = $defaults->{$img};
1481: }
1482: if ($imgfile) {
1483: my ($showfile,$fullsize);
1484: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1485: my $urldir = $1;
1486: my $filename = $2;
1487: my @info = &Apache::lonnet::stat_file($designs->{$img});
1488: if (@info) {
1489: my $thumbfile = 'tn-'.$filename;
1490: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1491: if (@thumb) {
1492: $showfile = $urldir.'/'.$thumbfile;
1493: } else {
1494: $showfile = $imgfile;
1495: }
1496: } else {
1497: $showfile = '';
1498: }
1499: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1500: $showfile = $imgfile;
1501: my $imgdir = $1;
1502: my $filename = $2;
1503: if (-e "$londocroot/$imgdir/tn-".$filename) {
1504: $showfile = "/$imgdir/tn-".$filename;
1505: } else {
1506: my $input = $londocroot.$imgfile;
1507: my $output = "$londocroot/$imgdir/tn-".$filename;
1508: if (!-e $output) {
1509: my ($width,$height) = &thumb_dimensions();
1510: my ($fullwidth,$fullheight) = &check_dimensions($input);
1511: if ($fullwidth ne '' && $fullheight ne '') {
1512: if ($fullwidth > $width && $fullheight > $height) {
1513: my $size = $width.'x'.$height;
1514: system("convert -sample $size $input $output");
1515: $showfile = "/$imgdir/tn-".$filename;
1516: }
1517: }
1518: }
1519: }
1520: }
1521: if ($showfile) {
1522: if ($showfile =~ m{^/(adm|res)/}) {
1523: if ($showfile =~ m{^/res/}) {
1524: my $local_showfile =
1525: &Apache::lonnet::filelocation('',$showfile);
1526: &Apache::lonnet::repcopy($local_showfile);
1527: }
1528: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1529: }
1530: if ($imgfile) {
1531: if ($imgfile =~ m{^/(adm|res)/}) {
1532: if ($imgfile =~ m{^/res/}) {
1533: my $local_imgfile =
1534: &Apache::lonnet::filelocation('',$imgfile);
1535: &Apache::lonnet::repcopy($local_imgfile);
1536: }
1537: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1538: } else {
1539: $fullsize = $imgfile;
1540: }
1541: }
1542: $datatable .= '<td>';
1543: if ($img eq 'login') {
1544: $datatable .= $login_hdr_pick;
1545: }
1546: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1547: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1548: } else {
1549: $datatable .= '<td> </td><td class="LC_left_item">'.
1550: &mt('Upload:').'<br />';
1551: }
1552: } else {
1553: $datatable .= '<td> </td><td class="LC_left_item">'.
1554: &mt('Upload:').'<br />';
1555: }
1556: if ($switchserver) {
1557: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1558: } else {
1559: if ($img ne 'login') { # suppress file selection for Log-in header
1560: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1561: }
1562: }
1563: $datatable .= '</td></tr>';
1564: }
1565: $itemcount ++;
1566: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1567: $datatable .= '<tr'.$css_class.'>'.
1568: '<td>'.$choices->{'bgs'}.'</td>';
1569: my $bgs_def;
1570: foreach my $item (@{$bgs}) {
1571: if (!$is_custom->{$item}) {
1572: $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>';
1573: }
1574: }
1575: if ($bgs_def) {
1576: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1577: } else {
1578: $datatable .= '<td> </td>';
1579: }
1580: $datatable .= '<td class="LC_right_item">'.
1581: '<table border="0"><tr>';
1582:
1583: foreach my $item (@{$bgs}) {
1584: $datatable .= '<td align="center">'.$choices->{$item};
1585: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1586: if ($designs->{'bgs'}{$item}) {
1587: $datatable .= ' ';
1588: }
1589: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1590: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1591: }
1592: $datatable .= '</tr></table></td></tr>';
1593: $itemcount ++;
1594: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1595: $datatable .= '<tr'.$css_class.'>'.
1596: '<td>'.$choices->{'links'}.'</td>';
1597: my $links_def;
1598: foreach my $item (@{$links}) {
1599: if (!$is_custom->{$item}) {
1600: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1601: }
1602: }
1603: if ($links_def) {
1604: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1605: } else {
1606: $datatable .= '<td> </td>';
1607: }
1608: $datatable .= '<td class="LC_right_item">'.
1609: '<table border="0"><tr>';
1610: foreach my $item (@{$links}) {
1611: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1612: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1613: if ($designs->{'links'}{$item}) {
1614: $datatable.=' ';
1615: }
1616: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1617: '" /></td>';
1618: }
1619: $$rowtotal += $itemcount;
1620: return $datatable;
1621: }
1622:
1623: sub logo_display_options {
1624: my ($img,$defaults,$designs) = @_;
1625: my $checkedon;
1626: if (ref($defaults) eq 'HASH') {
1627: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1628: if ($defaults->{'showlogo'}{$img}) {
1629: $checkedon = 'checked="checked" ';
1630: }
1631: }
1632: }
1633: if (ref($designs) eq 'HASH') {
1634: if (ref($designs->{'showlogo'}) eq 'HASH') {
1635: if (defined($designs->{'showlogo'}{$img})) {
1636: if ($designs->{'showlogo'}{$img} == 0) {
1637: $checkedon = '';
1638: } elsif ($designs->{'showlogo'}{$img} == 1) {
1639: $checkedon = 'checked="checked" ';
1640: }
1641: }
1642: }
1643: }
1644: return '<br /><label> <input type="checkbox" name="'.
1645: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1646: &mt('show').'</label>'."\n";
1647: }
1648:
1649: sub login_header_options {
1650: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1651: my $output = '';
1652: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1653: $output .= &mt('Text default(s):').'<br />';
1654: if (!$is_custom->{'textcol'}) {
1655: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1656: ' ';
1657: }
1658: if (!$is_custom->{'bgcol'}) {
1659: $output .= $choices->{'bgcol'}.': '.
1660: '<span id="css_'.$role.'_font" style="background-color: '.
1661: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1662: }
1663: $output .= '<br />';
1664: }
1665: $output .='<br />';
1666: return $output;
1667: }
1668:
1669: sub login_text_colors {
1670: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1671: my $color_menu = '<table border="0"><tr>';
1672: foreach my $item (@{$logintext}) {
1673: $color_menu .= '<td align="center">'.$choices->{$item};
1674: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1675: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1676: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1677: }
1678: $color_menu .= '</tr></table><br />';
1679: return $color_menu;
1680: }
1681:
1682: sub image_changes {
1683: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1684: my $output;
1685: if ($img eq 'login') {
1686: # suppress image for Log-in header
1687: } elsif (!$is_custom) {
1688: if ($img ne 'domlogo') {
1689: $output .= &mt('Default image:').'<br />';
1690: } else {
1691: $output .= &mt('Default in use:').'<br />';
1692: }
1693: }
1694: if ($img eq 'login') { # suppress image for Log-in header
1695: $output .= '<td>'.$logincolors;
1696: } else {
1697: if ($img_import) {
1698: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1699: }
1700: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1701: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1702: if ($is_custom) {
1703: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1704: '<input type="checkbox" name="'.
1705: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1706: '</label> '.&mt('Replace:').'</span><br />';
1707: } else {
1708: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1709: }
1710: }
1711: return $output;
1712: }
1713:
1714: sub print_quotas {
1715: my ($dom,$settings,$rowtotal,$action) = @_;
1716: my $context;
1717: if ($action eq 'quotas') {
1718: $context = 'tools';
1719: } else {
1720: $context = $action;
1721: }
1722: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1723: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1724: my $typecount = 0;
1725: my ($css_class,%titles);
1726: if ($context eq 'requestcourses') {
1727: @usertools = ('official','unofficial','community','textbook','placement');
1728: @options =('norequest','approval','validate','autolimit');
1729: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1730: %titles = &courserequest_titles();
1731: } elsif ($context eq 'requestauthor') {
1732: @usertools = ('author');
1733: @options = ('norequest','approval','automatic');
1734: %titles = &authorrequest_titles();
1735: } else {
1736: @usertools = ('aboutme','blog','webdav','portfolio');
1737: %titles = &tool_titles();
1738: }
1739: if (ref($types) eq 'ARRAY') {
1740: foreach my $type (@{$types}) {
1741: my ($currdefquota,$currauthorquota);
1742: unless (($context eq 'requestcourses') ||
1743: ($context eq 'requestauthor')) {
1744: if (ref($settings) eq 'HASH') {
1745: if (ref($settings->{defaultquota}) eq 'HASH') {
1746: $currdefquota = $settings->{defaultquota}->{$type};
1747: } else {
1748: $currdefquota = $settings->{$type};
1749: }
1750: if (ref($settings->{authorquota}) eq 'HASH') {
1751: $currauthorquota = $settings->{authorquota}->{$type};
1752: }
1753: }
1754: }
1755: if (defined($usertypes->{$type})) {
1756: $typecount ++;
1757: $css_class = $typecount%2?' class="LC_odd_row"':'';
1758: $datatable .= '<tr'.$css_class.'>'.
1759: '<td>'.$usertypes->{$type}.'</td>'.
1760: '<td class="LC_left_item">';
1761: if ($context eq 'requestcourses') {
1762: $datatable .= '<table><tr>';
1763: }
1764: my %cell;
1765: foreach my $item (@usertools) {
1766: if ($context eq 'requestcourses') {
1767: my ($curroption,$currlimit);
1768: if (ref($settings) eq 'HASH') {
1769: if (ref($settings->{$item}) eq 'HASH') {
1770: $curroption = $settings->{$item}->{$type};
1771: if ($curroption =~ /^autolimit=(\d*)$/) {
1772: $currlimit = $1;
1773: }
1774: }
1775: }
1776: if (!$curroption) {
1777: $curroption = 'norequest';
1778: }
1779: $datatable .= '<th>'.$titles{$item}.'</th>';
1780: foreach my $option (@options) {
1781: my $val = $option;
1782: if ($option eq 'norequest') {
1783: $val = 0;
1784: }
1785: if ($option eq 'validate') {
1786: my $canvalidate = 0;
1787: if (ref($validations{$item}) eq 'HASH') {
1788: if ($validations{$item}{$type}) {
1789: $canvalidate = 1;
1790: }
1791: }
1792: next if (!$canvalidate);
1793: }
1794: my $checked = '';
1795: if ($option eq $curroption) {
1796: $checked = ' checked="checked"';
1797: } elsif ($option eq 'autolimit') {
1798: if ($curroption =~ /^autolimit/) {
1799: $checked = ' checked="checked"';
1800: }
1801: }
1802: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1803: '<input type="radio" name="crsreq_'.$item.
1804: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1805: $titles{$option}.'</label>';
1806: if ($option eq 'autolimit') {
1807: $cell{$item} .= ' <input type="text" name="crsreq_'.
1808: $item.'_limit_'.$type.'" size="1" '.
1809: 'value="'.$currlimit.'" />';
1810: }
1811: $cell{$item} .= '</span> ';
1812: if ($option eq 'autolimit') {
1813: $cell{$item} .= $titles{'unlimited'};
1814: }
1815: }
1816: } elsif ($context eq 'requestauthor') {
1817: my $curroption;
1818: if (ref($settings) eq 'HASH') {
1819: $curroption = $settings->{$type};
1820: }
1821: if (!$curroption) {
1822: $curroption = 'norequest';
1823: }
1824: foreach my $option (@options) {
1825: my $val = $option;
1826: if ($option eq 'norequest') {
1827: $val = 0;
1828: }
1829: my $checked = '';
1830: if ($option eq $curroption) {
1831: $checked = ' checked="checked"';
1832: }
1833: $datatable .= '<span class="LC_nobreak"><label>'.
1834: '<input type="radio" name="authorreq_'.$type.
1835: '" value="'.$val.'"'.$checked.' />'.
1836: $titles{$option}.'</label></span> ';
1837: }
1838: } else {
1839: my $checked = 'checked="checked" ';
1840: if (ref($settings) eq 'HASH') {
1841: if (ref($settings->{$item}) eq 'HASH') {
1842: if ($settings->{$item}->{$type} == 0) {
1843: $checked = '';
1844: } elsif ($settings->{$item}->{$type} == 1) {
1845: $checked = 'checked="checked" ';
1846: }
1847: }
1848: }
1849: $datatable .= '<span class="LC_nobreak"><label>'.
1850: '<input type="checkbox" name="'.$context.'_'.$item.
1851: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1852: '</label></span> ';
1853: }
1854: }
1855: if ($context eq 'requestcourses') {
1856: $datatable .= '</tr><tr>';
1857: foreach my $item (@usertools) {
1858: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1859: }
1860: $datatable .= '</tr></table>';
1861: }
1862: $datatable .= '</td>';
1863: unless (($context eq 'requestcourses') ||
1864: ($context eq 'requestauthor')) {
1865: $datatable .=
1866: '<td class="LC_right_item">'.
1867: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1868: '<input type="text" name="quota_'.$type.
1869: '" value="'.$currdefquota.
1870: '" size="5" /></span>'.(' ' x 2).
1871: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1872: '<input type="text" name="authorquota_'.$type.
1873: '" value="'.$currauthorquota.
1874: '" size="5" /></span></td>';
1875: }
1876: $datatable .= '</tr>';
1877: }
1878: }
1879: }
1880: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1881: $defaultquota = '20';
1882: $authorquota = '500';
1883: if (ref($settings) eq 'HASH') {
1884: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1885: $defaultquota = $settings->{'defaultquota'}->{'default'};
1886: } elsif (defined($settings->{'default'})) {
1887: $defaultquota = $settings->{'default'};
1888: }
1889: if (ref($settings->{'authorquota'}) eq 'HASH') {
1890: $authorquota = $settings->{'authorquota'}->{'default'};
1891: }
1892: }
1893: }
1894: $typecount ++;
1895: $css_class = $typecount%2?' class="LC_odd_row"':'';
1896: $datatable .= '<tr'.$css_class.'>'.
1897: '<td>'.$othertitle.'</td>'.
1898: '<td class="LC_left_item">';
1899: if ($context eq 'requestcourses') {
1900: $datatable .= '<table><tr>';
1901: }
1902: my %defcell;
1903: foreach my $item (@usertools) {
1904: if ($context eq 'requestcourses') {
1905: my ($curroption,$currlimit);
1906: if (ref($settings) eq 'HASH') {
1907: if (ref($settings->{$item}) eq 'HASH') {
1908: $curroption = $settings->{$item}->{'default'};
1909: if ($curroption =~ /^autolimit=(\d*)$/) {
1910: $currlimit = $1;
1911: }
1912: }
1913: }
1914: if (!$curroption) {
1915: $curroption = 'norequest';
1916: }
1917: $datatable .= '<th>'.$titles{$item}.'</th>';
1918: foreach my $option (@options) {
1919: my $val = $option;
1920: if ($option eq 'norequest') {
1921: $val = 0;
1922: }
1923: if ($option eq 'validate') {
1924: my $canvalidate = 0;
1925: if (ref($validations{$item}) eq 'HASH') {
1926: if ($validations{$item}{'default'}) {
1927: $canvalidate = 1;
1928: }
1929: }
1930: next if (!$canvalidate);
1931: }
1932: my $checked = '';
1933: if ($option eq $curroption) {
1934: $checked = ' checked="checked"';
1935: } elsif ($option eq 'autolimit') {
1936: if ($curroption =~ /^autolimit/) {
1937: $checked = ' checked="checked"';
1938: }
1939: }
1940: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1941: '<input type="radio" name="crsreq_'.$item.
1942: '_default" value="'.$val.'"'.$checked.' />'.
1943: $titles{$option}.'</label>';
1944: if ($option eq 'autolimit') {
1945: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1946: $item.'_limit_default" size="1" '.
1947: 'value="'.$currlimit.'" />';
1948: }
1949: $defcell{$item} .= '</span> ';
1950: if ($option eq 'autolimit') {
1951: $defcell{$item} .= $titles{'unlimited'};
1952: }
1953: }
1954: } elsif ($context eq 'requestauthor') {
1955: my $curroption;
1956: if (ref($settings) eq 'HASH') {
1957: $curroption = $settings->{'default'};
1958: }
1959: if (!$curroption) {
1960: $curroption = 'norequest';
1961: }
1962: foreach my $option (@options) {
1963: my $val = $option;
1964: if ($option eq 'norequest') {
1965: $val = 0;
1966: }
1967: my $checked = '';
1968: if ($option eq $curroption) {
1969: $checked = ' checked="checked"';
1970: }
1971: $datatable .= '<span class="LC_nobreak"><label>'.
1972: '<input type="radio" name="authorreq_default"'.
1973: ' value="'.$val.'"'.$checked.' />'.
1974: $titles{$option}.'</label></span> ';
1975: }
1976: } else {
1977: my $checked = 'checked="checked" ';
1978: if (ref($settings) eq 'HASH') {
1979: if (ref($settings->{$item}) eq 'HASH') {
1980: if ($settings->{$item}->{'default'} == 0) {
1981: $checked = '';
1982: } elsif ($settings->{$item}->{'default'} == 1) {
1983: $checked = 'checked="checked" ';
1984: }
1985: }
1986: }
1987: $datatable .= '<span class="LC_nobreak"><label>'.
1988: '<input type="checkbox" name="'.$context.'_'.$item.
1989: '" value="default" '.$checked.'/>'.$titles{$item}.
1990: '</label></span> ';
1991: }
1992: }
1993: if ($context eq 'requestcourses') {
1994: $datatable .= '</tr><tr>';
1995: foreach my $item (@usertools) {
1996: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1997: }
1998: $datatable .= '</tr></table>';
1999: }
2000: $datatable .= '</td>';
2001: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2002: $datatable .= '<td class="LC_right_item">'.
2003: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2004: '<input type="text" name="defaultquota" value="'.
2005: $defaultquota.'" size="5" /></span>'.(' ' x2).
2006: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2007: '<input type="text" name="authorquota" value="'.
2008: $authorquota.'" size="5" /></span></td>';
2009: }
2010: $datatable .= '</tr>';
2011: $typecount ++;
2012: $css_class = $typecount%2?' class="LC_odd_row"':'';
2013: $datatable .= '<tr'.$css_class.'>'.
2014: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
2015: if ($context eq 'requestcourses') {
2016: $datatable .= &mt('(overrides affiliation, if set)').
2017: '</td>'.
2018: '<td class="LC_left_item">'.
2019: '<table><tr>';
2020: } else {
2021: $datatable .= &mt('(overrides affiliation, if checked)').
2022: '</td>'.
2023: '<td class="LC_left_item" colspan="2">'.
2024: '<br />';
2025: }
2026: my %advcell;
2027: foreach my $item (@usertools) {
2028: if ($context eq 'requestcourses') {
2029: my ($curroption,$currlimit);
2030: if (ref($settings) eq 'HASH') {
2031: if (ref($settings->{$item}) eq 'HASH') {
2032: $curroption = $settings->{$item}->{'_LC_adv'};
2033: if ($curroption =~ /^autolimit=(\d*)$/) {
2034: $currlimit = $1;
2035: }
2036: }
2037: }
2038: $datatable .= '<th>'.$titles{$item}.'</th>';
2039: my $checked = '';
2040: if ($curroption eq '') {
2041: $checked = ' checked="checked"';
2042: }
2043: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2044: '<input type="radio" name="crsreq_'.$item.
2045: '__LC_adv" value=""'.$checked.' />'.
2046: &mt('No override set').'</label></span> ';
2047: foreach my $option (@options) {
2048: my $val = $option;
2049: if ($option eq 'norequest') {
2050: $val = 0;
2051: }
2052: if ($option eq 'validate') {
2053: my $canvalidate = 0;
2054: if (ref($validations{$item}) eq 'HASH') {
2055: if ($validations{$item}{'_LC_adv'}) {
2056: $canvalidate = 1;
2057: }
2058: }
2059: next if (!$canvalidate);
2060: }
2061: my $checked = '';
2062: if ($val eq $curroption) {
2063: $checked = ' checked="checked"';
2064: } elsif ($option eq 'autolimit') {
2065: if ($curroption =~ /^autolimit/) {
2066: $checked = ' checked="checked"';
2067: }
2068: }
2069: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2070: '<input type="radio" name="crsreq_'.$item.
2071: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2072: $titles{$option}.'</label>';
2073: if ($option eq 'autolimit') {
2074: $advcell{$item} .= ' <input type="text" name="crsreq_'.
2075: $item.'_limit__LC_adv" size="1" '.
2076: 'value="'.$currlimit.'" />';
2077: }
2078: $advcell{$item} .= '</span> ';
2079: if ($option eq 'autolimit') {
2080: $advcell{$item} .= $titles{'unlimited'};
2081: }
2082: }
2083: } elsif ($context eq 'requestauthor') {
2084: my $curroption;
2085: if (ref($settings) eq 'HASH') {
2086: $curroption = $settings->{'_LC_adv'};
2087: }
2088: my $checked = '';
2089: if ($curroption eq '') {
2090: $checked = ' checked="checked"';
2091: }
2092: $datatable .= '<span class="LC_nobreak"><label>'.
2093: '<input type="radio" name="authorreq__LC_adv"'.
2094: ' value=""'.$checked.' />'.
2095: &mt('No override set').'</label></span> ';
2096: foreach my $option (@options) {
2097: my $val = $option;
2098: if ($option eq 'norequest') {
2099: $val = 0;
2100: }
2101: my $checked = '';
2102: if ($val eq $curroption) {
2103: $checked = ' checked="checked"';
2104: }
2105: $datatable .= '<span class="LC_nobreak"><label>'.
2106: '<input type="radio" name="authorreq__LC_adv"'.
2107: ' value="'.$val.'"'.$checked.' />'.
2108: $titles{$option}.'</label></span> ';
2109: }
2110: } else {
2111: my $checked = 'checked="checked" ';
2112: if (ref($settings) eq 'HASH') {
2113: if (ref($settings->{$item}) eq 'HASH') {
2114: if ($settings->{$item}->{'_LC_adv'} == 0) {
2115: $checked = '';
2116: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2117: $checked = 'checked="checked" ';
2118: }
2119: }
2120: }
2121: $datatable .= '<span class="LC_nobreak"><label>'.
2122: '<input type="checkbox" name="'.$context.'_'.$item.
2123: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2124: '</label></span> ';
2125: }
2126: }
2127: if ($context eq 'requestcourses') {
2128: $datatable .= '</tr><tr>';
2129: foreach my $item (@usertools) {
2130: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2131: }
2132: $datatable .= '</tr></table>';
2133: }
2134: $datatable .= '</td></tr>';
2135: $$rowtotal += $typecount;
2136: return $datatable;
2137: }
2138:
2139: sub print_requestmail {
2140: my ($dom,$action,$settings,$rowtotal) = @_;
2141: my ($now,$datatable,%currapp);
2142: $now = time;
2143: if (ref($settings) eq 'HASH') {
2144: if (ref($settings->{'notify'}) eq 'HASH') {
2145: if ($settings->{'notify'}{'approval'} ne '') {
2146: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2147: }
2148: }
2149: }
2150: my $numinrow = 2;
2151: my $css_class;
2152: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
2153: my $text;
2154: if ($action eq 'requestcourses') {
2155: $text = &mt('Receive notification of course requests requiring approval');
2156: } elsif ($action eq 'requestauthor') {
2157: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2158: } else {
2159: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2160: }
2161: $datatable = '<tr'.$css_class.'>'.
2162: ' <td>'.$text.'</td>'.
2163: ' <td class="LC_left_item">';
2164: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2165: $action.'notifyapproval',%currapp);
2166: if ($numdc > 0) {
2167: $datatable .= $table;
2168: } else {
2169: $datatable .= &mt('There are no active Domain Coordinators');
2170: }
2171: $datatable .='</td></tr>';
2172: return $datatable;
2173: }
2174:
2175: sub print_studentcode {
2176: my ($settings,$rowtotal) = @_;
2177: my $rownum = 0;
2178: my ($output,%current);
2179: my @crstypes = ('official','unofficial','community','textbook','placement');
2180: if (ref($settings) eq 'HASH') {
2181: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2182: foreach my $type (@crstypes) {
2183: $current{$type} = $settings->{'uniquecode'}{$type};
2184: }
2185: }
2186: }
2187: $output .= '<tr>'.
2188: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2189: '<td class="LC_left_item">';
2190: foreach my $type (@crstypes) {
2191: my $check = ' ';
2192: if ($current{$type}) {
2193: $check = ' checked="checked" ';
2194: }
2195: $output .= '<span class="LC_nobreak"><label>'.
2196: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2197: &mt($type).'</label></span>'.(' 'x2).' ';
2198: }
2199: $output .= '</td></tr>';
2200: $$rowtotal ++;
2201: return $output;
2202: }
2203:
2204: sub print_textbookcourses {
2205: my ($dom,$type,$settings,$rowtotal) = @_;
2206: my $rownum = 0;
2207: my $css_class;
2208: my $itemcount = 1;
2209: my $maxnum = 0;
2210: my $bookshash;
2211: if (ref($settings) eq 'HASH') {
2212: $bookshash = $settings->{$type};
2213: }
2214: my %ordered;
2215: if (ref($bookshash) eq 'HASH') {
2216: foreach my $item (keys(%{$bookshash})) {
2217: if (ref($bookshash->{$item}) eq 'HASH') {
2218: my $num = $bookshash->{$item}{'order'};
2219: $ordered{$num} = $item;
2220: }
2221: }
2222: }
2223: my $confname = $dom.'-domainconfig';
2224: my $switchserver = &check_switchserver($dom,$confname);
2225: my $maxnum = scalar(keys(%ordered));
2226: my $datatable;
2227: if (keys(%ordered)) {
2228: my @items = sort { $a <=> $b } keys(%ordered);
2229: for (my $i=0; $i<@items; $i++) {
2230: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2231: my $key = $ordered{$items[$i]};
2232: my %coursehash=&Apache::lonnet::coursedescription($key);
2233: my $coursetitle = $coursehash{'description'};
2234: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2235: if (ref($bookshash->{$key}) eq 'HASH') {
2236: $subject = $bookshash->{$key}->{'subject'};
2237: $title = $bookshash->{$key}->{'title'};
2238: if ($type eq 'textbooks') {
2239: $publisher = $bookshash->{$key}->{'publisher'};
2240: $author = $bookshash->{$key}->{'author'};
2241: $image = $bookshash->{$key}->{'image'};
2242: if ($image ne '') {
2243: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2244: my $imagethumb = "$path/tn-".$imagefile;
2245: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2246: }
2247: }
2248: }
2249: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2250: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2251: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2252: for (my $k=0; $k<=$maxnum; $k++) {
2253: my $vpos = $k+1;
2254: my $selstr;
2255: if ($k == $i) {
2256: $selstr = ' selected="selected" ';
2257: }
2258: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2259: }
2260: $datatable .= '</select>'.(' 'x2).
2261: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2262: &mt('Delete?').'</label></span></td>'.
2263: '<td colspan="2">'.
2264: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2265: (' 'x2).
2266: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2267: if ($type eq 'textbooks') {
2268: $datatable .= (' 'x2).
2269: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2270: (' 'x2).
2271: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2272: (' 'x2).
2273: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2274: if ($image) {
2275: $datatable .= $imgsrc.
2276: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2277: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2278: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2279: }
2280: if ($switchserver) {
2281: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2282: } else {
2283: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2284: }
2285: }
2286: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2287: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2288: $coursetitle.'</span></td></tr>'."\n";
2289: $itemcount ++;
2290: }
2291: }
2292: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2293: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2294: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2295: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2296: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2297: for (my $k=0; $k<$maxnum+1; $k++) {
2298: my $vpos = $k+1;
2299: my $selstr;
2300: if ($k == $maxnum) {
2301: $selstr = ' selected="selected" ';
2302: }
2303: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2304: }
2305: $datatable .= '</select> '."\n".
2306: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
2307: '<td colspan="2">'.
2308: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2309: (' 'x2).
2310: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2311: (' 'x2);
2312: if ($type eq 'textbooks') {
2313: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2314: (' 'x2).
2315: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2316: (' 'x2).
2317: '<span class="LC_nobreak">'.&mt('Image:').' ';
2318: if ($switchserver) {
2319: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2320: } else {
2321: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2322: }
2323: }
2324: $datatable .= '</span>'."\n".
2325: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2326: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2327: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2328: &Apache::loncommon::selectcourse_link
2329: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
2330: '</span></td>'."\n".
2331: '</tr>'."\n";
2332: $itemcount ++;
2333: return $datatable;
2334: }
2335:
2336: sub textbookcourses_javascript {
2337: my ($settings) = @_;
2338: return unless(ref($settings) eq 'HASH');
2339: my (%ordered,%total,%jstext);
2340: foreach my $type ('textbooks','templates') {
2341: $total{$type} = 0;
2342: if (ref($settings->{$type}) eq 'HASH') {
2343: foreach my $item (keys(%{$settings->{$type}})) {
2344: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2345: my $num = $settings->{$type}->{$item}{'order'};
2346: $ordered{$type}{$num} = $item;
2347: }
2348: }
2349: $total{$type} = scalar(keys(%{$settings->{$type}}));
2350: }
2351: my @jsarray = ();
2352: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2353: push(@jsarray,$ordered{$type}{$item});
2354: }
2355: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2356: }
2357: return <<"ENDSCRIPT";
2358: <script type="text/javascript">
2359: // <![CDATA[
2360: function reorderBooks(form,item,caller) {
2361: var changedVal;
2362: $jstext{'textbooks'};
2363: $jstext{'templates'};
2364: var newpos;
2365: var maxh;
2366: if (caller == 'textbooks') {
2367: newpos = 'textbooks_addbook_pos';
2368: maxh = 1 + $total{'textbooks'};
2369: } else {
2370: newpos = 'templates_addbook_pos';
2371: maxh = 1 + $total{'templates'};
2372: }
2373: var current = new Array;
2374: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2375: if (item == newpos) {
2376: changedVal = newitemVal;
2377: } else {
2378: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2379: current[newitemVal] = newpos;
2380: }
2381: if (caller == 'textbooks') {
2382: for (var i=0; i<textbooks.length; i++) {
2383: var elementName = 'textbooks_'+textbooks[i];
2384: if (elementName != item) {
2385: if (form.elements[elementName]) {
2386: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2387: current[currVal] = elementName;
2388: }
2389: }
2390: }
2391: }
2392: if (caller == 'templates') {
2393: for (var i=0; i<templates.length; i++) {
2394: var elementName = 'templates_'+templates[i];
2395: if (elementName != item) {
2396: if (form.elements[elementName]) {
2397: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2398: current[currVal] = elementName;
2399: }
2400: }
2401: }
2402: }
2403: var oldVal;
2404: for (var j=0; j<maxh; j++) {
2405: if (current[j] == undefined) {
2406: oldVal = j;
2407: }
2408: }
2409: if (oldVal < changedVal) {
2410: for (var k=oldVal+1; k<=changedVal ; k++) {
2411: var elementName = current[k];
2412: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2413: }
2414: } else {
2415: for (var k=changedVal; k<oldVal; k++) {
2416: var elementName = current[k];
2417: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2418: }
2419: }
2420: return;
2421: }
2422:
2423: // ]]>
2424: </script>
2425:
2426: ENDSCRIPT
2427: }
2428:
2429: sub ltitools_javascript {
2430: my ($settings) = @_;
2431: return unless(ref($settings) eq 'HASH');
2432: my (%ordered,$total,%jstext);
2433: $total = 0;
2434: foreach my $item (keys(%{$settings})) {
2435: if (ref($settings->{$item}) eq 'HASH') {
2436: my $num = $settings->{$item}{'order'};
2437: $ordered{$num} = $item;
2438: }
2439: }
2440: $total = scalar(keys(%{$settings}));
2441: my @jsarray = ();
2442: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2443: push(@jsarray,$ordered{$item});
2444: }
2445: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2446: return <<"ENDSCRIPT";
2447: <script type="text/javascript">
2448: // <![CDATA[
2449: function reorderLTI(form,item) {
2450: var changedVal;
2451: $jstext
2452: var newpos = 'ltitools_add_pos';
2453: var maxh = 1 + $total;
2454: var current = new Array;
2455: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2456: if (item == newpos) {
2457: changedVal = newitemVal;
2458: } else {
2459: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2460: current[newitemVal] = newpos;
2461: }
2462: for (var i=0; i<ltitools.length; i++) {
2463: var elementName = 'ltitools_'+ltitools[i];
2464: if (elementName != item) {
2465: if (form.elements[elementName]) {
2466: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2467: current[currVal] = elementName;
2468: }
2469: }
2470: }
2471: var oldVal;
2472: for (var j=0; j<maxh; j++) {
2473: if (current[j] == undefined) {
2474: oldVal = j;
2475: }
2476: }
2477: if (oldVal < changedVal) {
2478: for (var k=oldVal+1; k<=changedVal ; k++) {
2479: var elementName = current[k];
2480: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2481: }
2482: } else {
2483: for (var k=changedVal; k<oldVal; k++) {
2484: var elementName = current[k];
2485: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2486: }
2487: }
2488: return;
2489: }
2490:
2491: // ]]>
2492: </script>
2493:
2494: ENDSCRIPT
2495: }
2496:
2497: sub print_autoenroll {
2498: my ($dom,$settings,$rowtotal) = @_;
2499: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2500: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
2501: if (ref($settings) eq 'HASH') {
2502: if (exists($settings->{'run'})) {
2503: if ($settings->{'run'} eq '0') {
2504: $runoff = ' checked="checked" ';
2505: $runon = ' ';
2506: } else {
2507: $runon = ' checked="checked" ';
2508: $runoff = ' ';
2509: }
2510: } else {
2511: if ($autorun) {
2512: $runon = ' checked="checked" ';
2513: $runoff = ' ';
2514: } else {
2515: $runoff = ' checked="checked" ';
2516: $runon = ' ';
2517: }
2518: }
2519: if (exists($settings->{'co-owners'})) {
2520: if ($settings->{'co-owners'} eq '0') {
2521: $coownersoff = ' checked="checked" ';
2522: $coownerson = ' ';
2523: } else {
2524: $coownerson = ' checked="checked" ';
2525: $coownersoff = ' ';
2526: }
2527: } else {
2528: $coownersoff = ' checked="checked" ';
2529: $coownerson = ' ';
2530: }
2531: if (exists($settings->{'sender_domain'})) {
2532: $defdom = $settings->{'sender_domain'};
2533: }
2534: if (exists($settings->{'autofailsafe'})) {
2535: $failsafe = $settings->{'autofailsafe'};
2536: }
2537: } else {
2538: if ($autorun) {
2539: $runon = ' checked="checked" ';
2540: $runoff = ' ';
2541: } else {
2542: $runoff = ' checked="checked" ';
2543: $runon = ' ';
2544: }
2545: }
2546: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
2547: my $notif_sender;
2548: if (ref($settings) eq 'HASH') {
2549: $notif_sender = $settings->{'sender_uname'};
2550: }
2551: my $datatable='<tr class="LC_odd_row">'.
2552: '<td>'.&mt('Auto-enrollment active?').'</td>'.
2553: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2554: '<input type="radio" name="autoenroll_run"'.
2555: $runon.' value="1" />'.&mt('Yes').'</label> '.
2556: '<label><input type="radio" name="autoenroll_run"'.
2557: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
2558: '</tr><tr>'.
2559: '<td>'.&mt('Notification messages - sender').
2560: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
2561: &mt('username').': '.
2562: '<input type="text" name="sender_uname" value="'.
2563: $notif_sender.'" size="10" /> '.&mt('domain').
2564: ': '.$domform.'</span></td></tr>'.
2565: '<tr class="LC_odd_row">'.
2566: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2567: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2568: '<input type="radio" name="autoassign_coowners"'.
2569: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2570: '<label><input type="radio" name="autoassign_coowners"'.
2571: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2572: '</tr><tr>'.
2573: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2574: '<td class="LC_right_item"><span class="LC_nobreak">'.
2575: '<input type="text" name="autoenroll_failsafe"'.
2576: ' value="'.$failsafe.'" size="4" /></td></tr>';
2577: $$rowtotal += 4;
2578: return $datatable;
2579: }
2580:
2581: sub print_autoupdate {
2582: my ($position,$dom,$settings,$rowtotal) = @_;
2583: my $datatable;
2584: if ($position eq 'top') {
2585: my $updateon = ' ';
2586: my $updateoff = ' checked="checked" ';
2587: my $classlistson = ' ';
2588: my $classlistsoff = ' checked="checked" ';
2589: if (ref($settings) eq 'HASH') {
2590: if ($settings->{'run'} eq '1') {
2591: $updateon = $updateoff;
2592: $updateoff = ' ';
2593: }
2594: if ($settings->{'classlists'} eq '1') {
2595: $classlistson = $classlistsoff;
2596: $classlistsoff = ' ';
2597: }
2598: }
2599: my %title = (
2600: run => 'Auto-update active?',
2601: classlists => 'Update information in classlists?',
2602: );
2603: $datatable = '<tr class="LC_odd_row">'.
2604: '<td>'.&mt($title{'run'}).'</td>'.
2605: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2606: '<input type="radio" name="autoupdate_run"'.
2607: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2608: '<label><input type="radio" name="autoupdate_run"'.
2609: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
2610: '</tr><tr>'.
2611: '<td>'.&mt($title{'classlists'}).'</td>'.
2612: '<td class="LC_right_item"><span class="LC_nobreak">'.
2613: '<label><input type="radio" name="classlists"'.
2614: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2615: '<label><input type="radio" name="classlists"'.
2616: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
2617: '</tr>';
2618: $$rowtotal += 2;
2619: } elsif ($position eq 'middle') {
2620: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2621: my $numinrow = 3;
2622: my $locknamesettings;
2623: $datatable .= &insttypes_row($settings,$types,$usertypes,
2624: $dom,$numinrow,$othertitle,
2625: 'lockablenames');
2626: $$rowtotal ++;
2627: } else {
2628: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2629: my @fields = ('lastname','firstname','middlename','generation',
2630: 'permanentemail','id');
2631: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2632: my $numrows = 0;
2633: if (ref($types) eq 'ARRAY') {
2634: if (@{$types} > 0) {
2635: $datatable =
2636: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2637: \@fields,$types,\$numrows);
2638: $$rowtotal += @{$types};
2639: }
2640: }
2641: $datatable .=
2642: &usertype_update_row($settings,{'default' => $othertitle},
2643: \%fieldtitles,\@fields,['default'],
2644: \$numrows);
2645: $$rowtotal ++;
2646: }
2647: return $datatable;
2648: }
2649:
2650: sub print_autocreate {
2651: my ($dom,$settings,$rowtotal) = @_;
2652: my (%createon,%createoff,%currhash);
2653: my @types = ('xml','req');
2654: if (ref($settings) eq 'HASH') {
2655: foreach my $item (@types) {
2656: $createoff{$item} = ' checked="checked" ';
2657: $createon{$item} = ' ';
2658: if (exists($settings->{$item})) {
2659: if ($settings->{$item}) {
2660: $createon{$item} = ' checked="checked" ';
2661: $createoff{$item} = ' ';
2662: }
2663: }
2664: }
2665: if ($settings->{'xmldc'} ne '') {
2666: $currhash{$settings->{'xmldc'}} = 1;
2667: }
2668: } else {
2669: foreach my $item (@types) {
2670: $createoff{$item} = ' checked="checked" ';
2671: $createon{$item} = ' ';
2672: }
2673: }
2674: $$rowtotal += 2;
2675: my $numinrow = 2;
2676: my $datatable='<tr class="LC_odd_row">'.
2677: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2678: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2679: '<input type="radio" name="autocreate_xml"'.
2680: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2681: '<label><input type="radio" name="autocreate_xml"'.
2682: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2683: '</td></tr><tr>'.
2684: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2685: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2686: '<input type="radio" name="autocreate_req"'.
2687: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2688: '<label><input type="radio" name="autocreate_req"'.
2689: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2690: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2691: 'autocreate_xmldc',%currhash);
2692: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
2693: if ($numdc > 1) {
2694: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2695: '</td><td class="LC_left_item">';
2696: } else {
2697: $datatable .= &mt('Course creation processed as:').
2698: '</td><td class="LC_right_item">';
2699: }
2700: $datatable .= $dctable.'</td></tr>';
2701: $$rowtotal += $rows;
2702: return $datatable;
2703: }
2704:
2705: sub print_directorysrch {
2706: my ($dom,$settings,$rowtotal) = @_;
2707: my $srchon = ' ';
2708: my $srchoff = ' checked="checked" ';
2709: my ($exacton,$containson,$beginson);
2710: my $localon = ' ';
2711: my $localoff = ' checked="checked" ';
2712: if (ref($settings) eq 'HASH') {
2713: if ($settings->{'available'} eq '1') {
2714: $srchon = $srchoff;
2715: $srchoff = ' ';
2716: }
2717: if ($settings->{'localonly'} eq '1') {
2718: $localon = $localoff;
2719: $localoff = ' ';
2720: }
2721: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2722: foreach my $type (@{$settings->{'searchtypes'}}) {
2723: if ($type eq 'exact') {
2724: $exacton = ' checked="checked" ';
2725: } elsif ($type eq 'contains') {
2726: $containson = ' checked="checked" ';
2727: } elsif ($type eq 'begins') {
2728: $beginson = ' checked="checked" ';
2729: }
2730: }
2731: } else {
2732: if ($settings->{'searchtypes'} eq 'exact') {
2733: $exacton = ' checked="checked" ';
2734: } elsif ($settings->{'searchtypes'} eq 'contains') {
2735: $containson = ' checked="checked" ';
2736: } elsif ($settings->{'searchtypes'} eq 'specify') {
2737: $exacton = ' checked="checked" ';
2738: $containson = ' checked="checked" ';
2739: }
2740: }
2741: }
2742: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2743: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2744:
2745: my $numinrow = 4;
2746: my $cansrchrow = 0;
2747: my $datatable='<tr class="LC_odd_row">'.
2748: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
2749: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2750: '<input type="radio" name="dirsrch_available"'.
2751: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2752: '<label><input type="radio" name="dirsrch_available"'.
2753: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2754: '</tr><tr>'.
2755: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
2756: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2757: '<input type="radio" name="dirsrch_localonly"'.
2758: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2759: '<label><input type="radio" name="dirsrch_localonly"'.
2760: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
2761: '</tr>';
2762: $$rowtotal += 2;
2763: if (ref($usertypes) eq 'HASH') {
2764: if (keys(%{$usertypes}) > 0) {
2765: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2766: $numinrow,$othertitle,'cansearch');
2767: $cansrchrow = 1;
2768: }
2769: }
2770: if ($cansrchrow) {
2771: $$rowtotal ++;
2772: $datatable .= '<tr>';
2773: } else {
2774: $datatable .= '<tr class="LC_odd_row">';
2775: }
2776: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2777: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2778: foreach my $title (@{$titleorder}) {
2779: if (defined($searchtitles->{$title})) {
2780: my $check = ' ';
2781: if (ref($settings) eq 'HASH') {
2782: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2783: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2784: $check = ' checked="checked" ';
2785: }
2786: }
2787: }
2788: $datatable .= '<td class="LC_left_item">'.
2789: '<span class="LC_nobreak"><label>'.
2790: '<input type="checkbox" name="searchby" '.
2791: 'value="'.$title.'"'.$check.'/>'.
2792: $searchtitles->{$title}.'</label></span></td>';
2793: }
2794: }
2795: $datatable .= '</tr></table></td></tr>';
2796: $$rowtotal ++;
2797: if ($cansrchrow) {
2798: $datatable .= '<tr class="LC_odd_row">';
2799: } else {
2800: $datatable .= '<tr>';
2801: }
2802: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2803: '<td class="LC_left_item" colspan="2">'.
2804: '<span class="LC_nobreak"><label>'.
2805: '<input type="checkbox" name="searchtypes" '.
2806: $exacton.' value="exact" />'.&mt('Exact match').
2807: '</label> '.
2808: '<label><input type="checkbox" name="searchtypes" '.
2809: $beginson.' value="begins" />'.&mt('Begins with').
2810: '</label> '.
2811: '<label><input type="checkbox" name="searchtypes" '.
2812: $containson.' value="contains" />'.&mt('Contains').
2813: '</label></span></td></tr>';
2814: $$rowtotal ++;
2815: return $datatable;
2816: }
2817:
2818: sub print_contacts {
2819: my ($dom,$settings,$rowtotal) = @_;
2820: my $datatable;
2821: my @contacts = ('adminemail','supportemail');
2822: my (%checked,%to,%otheremails,%bccemails);
2823: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2824: 'requestsmail','updatesmail','idconflictsmail');
2825: foreach my $type (@mailings) {
2826: $otheremails{$type} = '';
2827: }
2828: $bccemails{'helpdeskmail'} = '';
2829: if (ref($settings) eq 'HASH') {
2830: foreach my $item (@contacts) {
2831: if (exists($settings->{$item})) {
2832: $to{$item} = $settings->{$item};
2833: }
2834: }
2835: foreach my $type (@mailings) {
2836: if (exists($settings->{$type})) {
2837: if (ref($settings->{$type}) eq 'HASH') {
2838: foreach my $item (@contacts) {
2839: if ($settings->{$type}{$item}) {
2840: $checked{$type}{$item} = ' checked="checked" ';
2841: }
2842: }
2843: $otheremails{$type} = $settings->{$type}{'others'};
2844: if ($type eq 'helpdeskmail') {
2845: $bccemails{$type} = $settings->{$type}{'bcc'};
2846: }
2847: }
2848: } elsif ($type eq 'lonstatusmail') {
2849: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2850: }
2851: }
2852: } else {
2853: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2854: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2855: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2856: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2857: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2858: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2859: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2860: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2861: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2862: }
2863: my ($titles,$short_titles) = &contact_titles();
2864: my $rownum = 0;
2865: my $css_class;
2866: foreach my $item (@contacts) {
2867: $css_class = $rownum%2?' class="LC_odd_row"':'';
2868: $datatable .= '<tr'.$css_class.'>'.
2869: '<td><span class="LC_nobreak">'.$titles->{$item}.
2870: '</span></td><td class="LC_right_item">'.
2871: '<input type="text" name="'.$item.'" value="'.
2872: $to{$item}.'" /></td></tr>';
2873: $rownum ++;
2874: }
2875: foreach my $type (@mailings) {
2876: $css_class = $rownum%2?' class="LC_odd_row"':'';
2877: $datatable .= '<tr'.$css_class.'>'.
2878: '<td><span class="LC_nobreak">'.
2879: $titles->{$type}.': </span></td>'.
2880: '<td class="LC_left_item">'.
2881: '<span class="LC_nobreak">';
2882: foreach my $item (@contacts) {
2883: $datatable .= '<label>'.
2884: '<input type="checkbox" name="'.$type.'"'.
2885: $checked{$type}{$item}.
2886: ' value="'.$item.'" />'.$short_titles->{$item}.
2887: '</label> ';
2888: }
2889: $datatable .= '</span><br />'.&mt('Others').': '.
2890: '<input type="text" name="'.$type.'_others" '.
2891: 'value="'.$otheremails{$type}.'" />';
2892: if ($type eq 'helpdeskmail') {
2893: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2894: '<input type="text" name="'.$type.'_bcc" '.
2895: 'value="'.$bccemails{$type}.'" />';
2896: }
2897: $datatable .= '</td></tr>'."\n";
2898: $rownum ++;
2899: }
2900: my %choices;
2901: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2902: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2903: &mt('LON-CAPA core group - MSU'),600,500));
2904: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2905: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2906: &mt('LON-CAPA core group - MSU'),600,500));
2907: my @toggles = ('reporterrors','reportupdates');
2908: my %defaultchecked = ('reporterrors' => 'on',
2909: 'reportupdates' => 'on');
2910: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2911: \%choices,$rownum);
2912: $datatable .= $reports;
2913: $$rowtotal += $rownum;
2914: return $datatable;
2915: }
2916:
2917: sub print_helpsettings {
2918: my ($dom,$confname,$settings,$rowtotal) = @_;
2919: my ($datatable,$itemcount);
2920: $itemcount = 1;
2921: my (%choices,%defaultchecked,@toggles);
2922: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2923: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2924: &mt('LON-CAPA bug tracker'),600,500));
2925: %defaultchecked = ('submitbugs' => 'on');
2926: @toggles = ('submitbugs',);
2927:
2928: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2929: \%choices,$itemcount);
2930: return $datatable;
2931: }
2932:
2933: sub radiobutton_prefs {
2934: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2935: $additional,$align) = @_;
2936: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2937: (ref($choices) eq 'HASH'));
2938:
2939: my (%checkedon,%checkedoff,$datatable,$css_class);
2940:
2941: foreach my $item (@{$toggles}) {
2942: if ($defaultchecked->{$item} eq 'on') {
2943: $checkedon{$item} = ' checked="checked" ';
2944: $checkedoff{$item} = ' ';
2945: } elsif ($defaultchecked->{$item} eq 'off') {
2946: $checkedoff{$item} = ' checked="checked" ';
2947: $checkedon{$item} = ' ';
2948: }
2949: }
2950: if (ref($settings) eq 'HASH') {
2951: foreach my $item (@{$toggles}) {
2952: if ($settings->{$item} eq '1') {
2953: $checkedon{$item} = ' checked="checked" ';
2954: $checkedoff{$item} = ' ';
2955: } elsif ($settings->{$item} eq '0') {
2956: $checkedoff{$item} = ' checked="checked" ';
2957: $checkedon{$item} = ' ';
2958: }
2959: }
2960: }
2961: if ($onclick) {
2962: $onclick = ' onclick="'.$onclick.'"';
2963: }
2964: foreach my $item (@{$toggles}) {
2965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2966: $datatable .=
2967: '<tr'.$css_class.'><td valign="top">'.
2968: '<span class="LC_nobreak">'.$choices->{$item}.
2969: '</span></td>';
2970: if ($align eq 'left') {
2971: $datatable .= '<td class="LC_left_item">';
2972: } else {
2973: $datatable .= '<td class="LC_right_item">';
2974: }
2975: $datatable .=
2976: '<span class="LC_nobreak">'.
2977: '<label><input type="radio" name="'.
2978: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
2979: '</label> <label><input type="radio" name="'.$item.'" '.
2980: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2981: '</span>'.$additional.
2982: '</td>'.
2983: '</tr>';
2984: $itemcount ++;
2985: }
2986: return ($datatable,$itemcount);
2987: }
2988:
2989: sub print_ltitools {
2990: my ($dom,$settings,$rowtotal) = @_;
2991: my $rownum = 0;
2992: my $css_class;
2993: my $itemcount = 1;
2994: my $maxnum = 0;
2995: my %ordered;
2996: if (ref($settings) eq 'HASH') {
2997: foreach my $item (keys(%{$settings})) {
2998: if (ref($settings->{$item}) eq 'HASH') {
2999: my $num = $settings->{$item}{'order'};
3000: $ordered{$num} = $item;
3001: }
3002: }
3003: }
3004: my $confname = $dom.'-domainconfig';
3005: my $switchserver = &check_switchserver($dom,$confname);
3006: my $maxnum = scalar(keys(%ordered));
3007: my $datatable = <itools_javascript($settings);
3008: my %lt = <itools_names();
3009: my @courseroles = ('cc','in','ta','ep','st');
3010: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3011: my @fields = ('fullname','firstname','lastname','email','user','roles');
3012: if (keys(%ordered)) {
3013: my @items = sort { $a <=> $b } keys(%ordered);
3014: for (my $i=0; $i<@items; $i++) {
3015: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3016: my $item = $ordered{$items[$i]};
3017: my ($title,$key,$secret,$url,$imgsrc,$version);
3018: if (ref($settings->{$item}) eq 'HASH') {
3019: $title = $settings->{$item}->{'title'};
3020: $url = $settings->{$item}->{'url'};
3021: $key = $settings->{$item}->{'key'};
3022: $secret = $settings->{$item}->{'secret'};
3023: my $image = $settings->{$item}->{'image'};
3024: if ($image ne '') {
3025: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3026: }
3027: }
3028: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3029: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3030: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3031: for (my $k=0; $k<=$maxnum; $k++) {
3032: my $vpos = $k+1;
3033: my $selstr;
3034: if ($k == $i) {
3035: $selstr = ' selected="selected" ';
3036: }
3037: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3038: }
3039: $datatable .= '</select>'.(' 'x2).
3040: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3041: &mt('Delete?').'</label></span></td>'.
3042: '<td colspan="2">'.
3043: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3044: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3045: (' 'x2).
3046: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3047: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3048: (' 'x2).
3049: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3050: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3051: '<br /><br />'.
3052: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3053: ' value="'.$url.'" /></span>'.
3054: (' 'x2).
3055: '<span class="LC_nobreak">'.$lt{'key'}.
3056: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3057: (' 'x2).
3058: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3059: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3060: '<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>'.
3061: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3062: '</fieldset>'.
3063: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3064: '<span class="LC_nobreak">'.&mt('Display target:');
3065: my %currdisp;
3066: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3067: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3068: $currdisp{'window'} = ' checked="checked"';
3069: } else {
3070: $currdisp{'iframe'} = ' checked="checked"';
3071: }
3072: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3073: $currdisp{'width'} = $1;
3074: }
3075: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3076: $currdisp{'height'} = $1;
3077: }
3078: } else {
3079: $currdisp{'iframe'} = ' checked="checked"';
3080: }
3081: foreach my $disp ('iframe','window') {
3082: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3083: $lt{$disp}.'</label>'.(' 'x2);
3084: }
3085: $datatable .= (' 'x4);
3086: foreach my $dimen ('width','height') {
3087: $datatable .= '<label>'.$lt{$dimen}.' '.
3088: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3089: (' 'x2);
3090: }
3091: $datatable .= '<br />';
3092: foreach my $extra ('passback','roster') {
3093: my $checkedon = '';
3094: my $checkedoff = ' checked="checked"';
3095: if ($settings->{$item}->{$extra}) {
3096: $checkedon = $checkedoff;
3097: $checkedoff = '';
3098: }
3099: $datatable .= $lt{$extra}.' '.
3100: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3101: &mt('Yes').'</label>'.(' 'x2).
3102: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3103: &mt('No').'</label>'.(' 'x4);
3104: }
3105: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3106: if ($imgsrc) {
3107: $datatable .= $imgsrc.
3108: '<label><input type="checkbox" name="ltitools_image_del"'.
3109: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3110: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3111: } else {
3112: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3113: }
3114: if ($switchserver) {
3115: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3116: } else {
3117: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3118: }
3119: $datatable .= '</span></fieldset>';
3120: my (%checkedfields,%rolemaps);
3121: if (ref($settings->{$item}) eq 'HASH') {
3122: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3123: %checkedfields = %{$settings->{$item}->{'fields'}};
3124: }
3125: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3126: %rolemaps = %{$settings->{$item}->{'roles'}};
3127: $checkedfields{'roles'} = 1;
3128: }
3129: }
3130: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3131: '<span class="LC_nobreak">';
3132: foreach my $field (@fields) {
3133: my $checked;
3134: if ($checkedfields{$field}) {
3135: $checked = ' checked="checked"';
3136: }
3137: $datatable .= '<label>'.
3138: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3139: $lt{$field}.'</label>'.(' ' x2);
3140: }
3141: $datatable .= '</span></fieldset>'.
3142: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3143: foreach my $role (@courseroles) {
3144: my ($selected,$selectnone);
3145: if (!$rolemaps{$role}) {
3146: $selectnone = ' selected="selected"';
3147: }
3148: $datatable .= '<td align="center">'.
3149: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3150: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3151: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3152: foreach my $ltirole (@ltiroles) {
3153: unless ($selectnone) {
3154: if ($rolemaps{$role} eq $ltirole) {
3155: $selected = ' selected="selected"';
3156: } else {
3157: $selected = '';
3158: }
3159: }
3160: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3161: }
3162: $datatable .= '</select></td>';
3163: }
3164: $datatable .= '</tr></table></fieldset>';
3165: my %courseconfig;
3166: if (ref($settings->{$item}) eq 'HASH') {
3167: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3168: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3169: }
3170: }
3171: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3172: foreach my $item ('label','title','target') {
3173: my $checked;
3174: if ($courseconfig{$item}) {
3175: $checked = ' checked="checked"';
3176: }
3177: $datatable .= '<label>'.
3178: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3179: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3180: }
3181: $datatable .= '</span></fieldset>'.
3182: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3183: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3184: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3185: my %custom = %{$settings->{$item}->{'custom'}};
3186: if (keys(%custom) > 0) {
3187: foreach my $key (sort(keys(%custom))) {
3188: $datatable .= '<tr><td><span class="LC_nobreak">'.
3189: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3190: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3191: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3192: ' value="'.$custom{$key}.'" /></td></tr>';
3193: }
3194: }
3195: }
3196: $datatable .= '<tr><td><span class="LC_nobreak">'.
3197: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3198: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3199: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3200: $datatable .= '</table></fieldset></td></tr>'."\n";
3201: $itemcount ++;
3202: }
3203: }
3204: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3205: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3206: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3207: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3208: '<select name="ltitools_add_pos"'.$chgstr.'>';
3209: for (my $k=0; $k<$maxnum+1; $k++) {
3210: my $vpos = $k+1;
3211: my $selstr;
3212: if ($k == $maxnum) {
3213: $selstr = ' selected="selected" ';
3214: }
3215: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3216: }
3217: $datatable .= '</select> '."\n".
3218: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3219: '<td colspan="2">'.
3220: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3221: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3222: (' 'x2).
3223: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3224: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3225: (' 'x2).
3226: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3227: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3228: '<br />'.
3229: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3230: (' 'x2).
3231: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3232: (' 'x2).
3233: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3234: '<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".
3235: '</fieldset>'.
3236: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3237: '<span class="LC_nobreak">'.&mt('Display target:');
3238: my %defaultdisp;
3239: $defaultdisp{'iframe'} = ' checked="checked"';
3240: foreach my $disp ('iframe','window') {
3241: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3242: $lt{$disp}.'</label>'.(' 'x2);
3243: }
3244: $datatable .= (' 'x4);
3245: foreach my $dimen ('width','height') {
3246: $datatable .= '<label>'.$lt{$dimen}.' '.
3247: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3248: (' 'x2);
3249: }
3250: $datatable .= '<br />';
3251: foreach my $extra ('passback','roster') {
3252: $datatable .= $lt{$extra}.' '.
3253: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3254: &mt('Yes').'</label>'.(' 'x2).
3255: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3256: &mt('No').'</label>'.(' 'x4);
3257: }
3258: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3259: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3260: if ($switchserver) {
3261: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3262: } else {
3263: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3264: }
3265: $datatable .= '</span></fieldset>'.
3266: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3267: '<span class="LC_nobreak">';
3268: foreach my $field (@fields) {
3269: $datatable .= '<label>'.
3270: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3271: $lt{$field}.'</label>'.(' ' x2);
3272: }
3273: $datatable .= '</span></fieldset>'.
3274: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3275: foreach my $role (@courseroles) {
3276: my ($checked,$checkednone);
3277: $datatable .= '<td align="center">'.
3278: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3279: '<select name="ltitools_add_roles_'.$role.'">'.
3280: '<option value="" selected="selected">'.&mt('Select').'</option>';
3281: foreach my $ltirole (@ltiroles) {
3282: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3283: }
3284: $datatable .= '</select></td>';
3285: }
3286: $datatable .= '</tr></table></fieldset>'.
3287: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3288: foreach my $item ('label','title','target') {
3289: $datatable .= '<label>'.
3290: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3291: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3292: }
3293: $datatable .= '</span></fieldset>'.
3294: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3295: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3296: '<tr><td><span class="LC_nobreak">'.
3297: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3298: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3299: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3300: '</table></fieldset></td></tr>'."\n".
3301: '</td>'."\n".
3302: '</tr>'."\n";
3303: $itemcount ++;
3304: return $datatable;
3305: }
3306:
3307: sub ltitools_names {
3308: my %lt = &Apache::lonlocal::texthash(
3309: 'title' => 'Title',
3310: 'version' => 'Version',
3311: 'msgtype' => 'Message Type',
3312: 'url' => 'URL',
3313: 'key' => 'Key',
3314: 'secret' => 'Secret',
3315: 'icon' => 'Icon',
3316: 'user' => 'Username:domain',
3317: 'fullname' => 'Full Name',
3318: 'firstname' => 'First Name',
3319: 'lastname' => 'Last Name',
3320: 'email' => 'E-mail',
3321: 'roles' => 'Role',
3322: 'window' => 'Window/Tab',
3323: 'iframe' => 'iFrame',
3324: 'height' => 'Height',
3325: 'width' => 'Width',
3326: 'passback' => 'Tool can return grades:',
3327: 'roster' => 'Tool can retrieve roster:',
3328: 'crstarget' => 'Display target',
3329: 'crslabel' => 'Course label',
3330: 'crstitle' => 'Course title',
3331: );
3332: return %lt;
3333: }
3334:
3335: sub print_coursedefaults {
3336: my ($position,$dom,$settings,$rowtotal) = @_;
3337: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
3338: my $itemcount = 1;
3339: my %choices = &Apache::lonlocal::texthash (
3340: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
3341: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
3342: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3343: coursecredits => 'Credits can be specified for courses',
3344: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3345: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3346: postsubmit => 'Disable submit button/keypress following student submission',
3347: canclone => "People who may clone a course (besides course's owner and coordinators)",
3348: );
3349: my %staticdefaults = (
3350: anonsurvey_threshold => 10,
3351: uploadquota => 500,
3352: postsubmit => 60,
3353: );
3354: if ($position eq 'top') {
3355: %defaultchecked = (
3356: 'canuse_pdfforms' => 'off',
3357: 'uselcmath' => 'on',
3358: 'usejsme' => 'on',
3359: 'canclone' => 'none',
3360: );
3361: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
3362: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3363: \%choices,$itemcount);
3364: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3365: $datatable .=
3366: '<tr'.$css_class.'><td valign="top">'.
3367: '<span class="LC_nobreak">'.$choices{'canclone'}.
3368: '</span></td><td class="LC_left_item">';
3369: my $currcanclone = 'none';
3370: my $onclick;
3371: my @cloneoptions = ('none','domain');
3372: my %clonetitles = (
3373: none => 'No additional course requesters',
3374: domain => "Any course requester in course's domain",
3375: instcode => 'Course requests for official courses ...',
3376: );
3377: my (%codedefaults,@code_order,@posscodes);
3378: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3379: \@code_order) eq 'ok') {
3380: if (@code_order > 0) {
3381: push(@cloneoptions,'instcode');
3382: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3383: }
3384: }
3385: if (ref($settings) eq 'HASH') {
3386: if ($settings->{'canclone'}) {
3387: if (ref($settings->{'canclone'}) eq 'HASH') {
3388: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3389: if (@code_order > 0) {
3390: $currcanclone = 'instcode';
3391: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3392: }
3393: }
3394: } elsif ($settings->{'canclone'} eq 'domain') {
3395: $currcanclone = $settings->{'canclone'};
3396: }
3397: }
3398: }
3399: foreach my $option (@cloneoptions) {
3400: my ($checked,$additional);
3401: if ($currcanclone eq $option) {
3402: $checked = ' checked="checked"';
3403: }
3404: if ($option eq 'instcode') {
3405: if (@code_order) {
3406: my $show = 'none';
3407: if ($checked) {
3408: $show = 'block';
3409: }
3410: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3411: &mt('Institutional codes for new and cloned course have identical:').
3412: '<br />';
3413: foreach my $item (@code_order) {
3414: my $codechk;
3415: if ($checked) {
3416: if (grep(/^\Q$item\E$/,@posscodes)) {
3417: $codechk = ' checked="checked"';
3418: }
3419: }
3420: $additional .= '<label>'.
3421: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3422: $item.'</label>';
3423: }
3424: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3425: }
3426: }
3427: $datatable .=
3428: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3429: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3430: '</label> '.$additional.'</span><br />';
3431: }
3432: $datatable .= '</td>'.
3433: '</tr>';
3434: $itemcount ++;
3435: } else {
3436: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3437: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
3438: my $currusecredits = 0;
3439: my $postsubmitclient = 1;
3440: my @types = ('official','unofficial','community','textbook','placement');
3441: if (ref($settings) eq 'HASH') {
3442: $currdefresponder = $settings->{'anonsurvey_threshold'};
3443: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3444: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3445: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3446: }
3447: }
3448: if (ref($settings->{'coursecredits'}) eq 'HASH') {
3449: foreach my $type (@types) {
3450: next if ($type eq 'community');
3451: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3452: if ($defcredits{$type} ne '') {
3453: $currusecredits = 1;
3454: }
3455: }
3456: }
3457: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3458: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3459: $postsubmitclient = 0;
3460: foreach my $type (@types) {
3461: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3462: }
3463: } else {
3464: foreach my $type (@types) {
3465: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3466: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3467: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3468: } else {
3469: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3470: }
3471: } else {
3472: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3473: }
3474: }
3475: }
3476: } else {
3477: foreach my $type (@types) {
3478: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3479: }
3480: }
3481: } else {
3482: foreach my $type (@types) {
3483: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3484: }
3485: }
3486: if (!$currdefresponder) {
3487: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
3488: } elsif ($currdefresponder < 1) {
3489: $currdefresponder = 1;
3490: }
3491: foreach my $type (@types) {
3492: if ($curruploadquota{$type} eq '') {
3493: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3494: }
3495: }
3496: $datatable .=
3497: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3498: $choices{'anonsurvey_threshold'}.
3499: '</span></td>'.
3500: '<td class="LC_right_item"><span class="LC_nobreak">'.
3501: '<input type="text" name="anonsurvey_threshold"'.
3502: ' value="'.$currdefresponder.'" size="5" /></span>'.
3503: '</td></tr>'."\n";
3504: $itemcount ++;
3505: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3506: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3507: $choices{'uploadquota'}.
3508: '</span></td>'.
3509: '<td align="right" class="LC_right_item">'.
3510: '<table><tr>';
3511: foreach my $type (@types) {
3512: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3513: '<input type="text" name="uploadquota_'.$type.'"'.
3514: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3515: }
3516: $datatable .= '</tr></table></td></tr>'."\n";
3517: $itemcount ++;
3518: my $onclick = "toggleDisplay(this.form,'credits');";
3519: my $display = 'none';
3520: if ($currusecredits) {
3521: $display = 'block';
3522: }
3523: my $additional = '<div id="credits" style="display: '.$display.'">'.
3524: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3525: foreach my $type (@types) {
3526: next if ($type eq 'community');
3527: $additional .= '<td align="center">'.&mt($type).'<br />'.
3528: '<input type="text" name="'.$type.'_credits"'.
3529: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3530: }
3531: $additional .= '</tr></table></div>'."\n";
3532: %defaultchecked = ('coursecredits' => 'off');
3533: @toggles = ('coursecredits');
3534: my $current = {
3535: 'coursecredits' => $currusecredits,
3536: };
3537: (my $table,$itemcount) =
3538: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3539: \%choices,$itemcount,$onclick,$additional,'left');
3540: $datatable .= $table;
3541: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3542: my $display = 'none';
3543: if ($postsubmitclient) {
3544: $display = 'block';
3545: }
3546: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
3547: &mt('Number of seconds submit is disabled').'<br />'.
3548: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3549: '<table><tr>';
3550: foreach my $type (@types) {
3551: $additional .= '<td align="center">'.&mt($type).'<br />'.
3552: '<input type="text" name="'.$type.'_timeout" value="'.
3553: $deftimeout{$type}.'" size="5" /></td>';
3554: }
3555: $additional .= '</tr></table></div>'."\n";
3556: %defaultchecked = ('postsubmit' => 'on');
3557: @toggles = ('postsubmit');
3558: my $current = {
3559: 'postsubmit' => $postsubmitclient,
3560: };
3561: ($table,$itemcount) =
3562: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3563: \%choices,$itemcount,$onclick,$additional,'left');
3564: $datatable .= $table;
3565: }
3566: $$rowtotal += $itemcount;
3567: return $datatable;
3568: }
3569:
3570: sub print_selfenrollment {
3571: my ($position,$dom,$settings,$rowtotal) = @_;
3572: my ($css_class,$datatable);
3573: my $itemcount = 1;
3574: my @types = ('official','unofficial','community','textbook','placement');
3575: if (($position eq 'top') || ($position eq 'middle')) {
3576: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3577: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3578: my @rows;
3579: my $key;
3580: if ($position eq 'top') {
3581: $key = 'admin';
3582: if (ref($rowsref) eq 'ARRAY') {
3583: @rows = @{$rowsref};
3584: }
3585: } elsif ($position eq 'middle') {
3586: $key = 'default';
3587: @rows = ('types','registered','approval','limit');
3588: }
3589: foreach my $row (@rows) {
3590: if (defined($titlesref->{$row})) {
3591: $itemcount ++;
3592: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3593: $datatable .= '<tr'.$css_class.'>'.
3594: '<td>'.$titlesref->{$row}.'</td>'.
3595: '<td class="LC_left_item">'.
3596: '<table><tr>';
3597: my (%current,%currentcap);
3598: if (ref($settings) eq 'HASH') {
3599: if (ref($settings->{$key}) eq 'HASH') {
3600: foreach my $type (@types) {
3601: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3602: $current{$type} = $settings->{$key}->{$type}->{$row};
3603: }
3604: if (($row eq 'limit') && ($key eq 'default')) {
3605: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3606: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3607: }
3608: }
3609: }
3610: }
3611: }
3612: my %roles = (
3613: '0' => &Apache::lonnet::plaintext('dc'),
3614: );
3615:
3616: foreach my $type (@types) {
3617: unless (($row eq 'registered') && ($key eq 'default')) {
3618: $datatable .= '<th>'.&mt($type).'</th>';
3619: }
3620: }
3621: unless (($row eq 'registered') && ($key eq 'default')) {
3622: $datatable .= '</tr><tr>';
3623: }
3624: foreach my $type (@types) {
3625: if ($type eq 'community') {
3626: $roles{'1'} = &mt('Community personnel');
3627: } else {
3628: $roles{'1'} = &mt('Course personnel');
3629: }
3630: $datatable .= '<td style="vertical-align: top">';
3631: if ($position eq 'top') {
3632: my %checked;
3633: if ($current{$type} eq '0') {
3634: $checked{'0'} = ' checked="checked"';
3635: } else {
3636: $checked{'1'} = ' checked="checked"';
3637: }
3638: foreach my $role ('1','0') {
3639: $datatable .= '<span class="LC_nobreak"><label>'.
3640: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3641: 'value="'.$role.'"'.$checked{$role}.' />'.
3642: $roles{$role}.'</label></span> ';
3643: }
3644: } else {
3645: if ($row eq 'types') {
3646: my %checked;
3647: if ($current{$type} =~ /^(all|dom)$/) {
3648: $checked{$1} = ' checked="checked"';
3649: } else {
3650: $checked{''} = ' checked="checked"';
3651: }
3652: foreach my $val ('','dom','all') {
3653: $datatable .= '<span class="LC_nobreak"><label>'.
3654: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3655: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3656: }
3657: } elsif ($row eq 'registered') {
3658: my %checked;
3659: if ($current{$type} eq '1') {
3660: $checked{'1'} = ' checked="checked"';
3661: } else {
3662: $checked{'0'} = ' checked="checked"';
3663: }
3664: foreach my $val ('0','1') {
3665: $datatable .= '<span class="LC_nobreak"><label>'.
3666: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3667: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3668: }
3669: } elsif ($row eq 'approval') {
3670: my %checked;
3671: if ($current{$type} =~ /^([12])$/) {
3672: $checked{$1} = ' checked="checked"';
3673: } else {
3674: $checked{'0'} = ' checked="checked"';
3675: }
3676: for my $val (0..2) {
3677: $datatable .= '<span class="LC_nobreak"><label>'.
3678: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3679: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3680: }
3681: } elsif ($row eq 'limit') {
3682: my %checked;
3683: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3684: $checked{$1} = ' checked="checked"';
3685: } else {
3686: $checked{'none'} = ' checked="checked"';
3687: }
3688: my $cap;
3689: if ($currentcap{$type} =~ /^\d+$/) {
3690: $cap = $currentcap{$type};
3691: }
3692: foreach my $val ('none','allstudents','selfenrolled') {
3693: $datatable .= '<span class="LC_nobreak"><label>'.
3694: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3695: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3696: }
3697: $datatable .= '<br />'.
3698: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3699: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3700: '</span>';
3701: }
3702: }
3703: $datatable .= '</td>';
3704: }
3705: $datatable .= '</tr>';
3706: }
3707: $datatable .= '</table></td></tr>';
3708: }
3709: } elsif ($position eq 'bottom') {
3710: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3711: }
3712: $$rowtotal += $itemcount;
3713: return $datatable;
3714: }
3715:
3716: sub print_validation_rows {
3717: my ($caller,$dom,$settings,$rowtotal) = @_;
3718: my ($itemsref,$namesref,$fieldsref);
3719: if ($caller eq 'selfenroll') {
3720: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3721: } elsif ($caller eq 'requestcourses') {
3722: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3723: }
3724: my %currvalidation;
3725: if (ref($settings) eq 'HASH') {
3726: if (ref($settings->{'validation'}) eq 'HASH') {
3727: %currvalidation = %{$settings->{'validation'}};
3728: }
3729: }
3730: my $datatable;
3731: my $itemcount = 0;
3732: foreach my $item (@{$itemsref}) {
3733: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3734: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3735: $namesref->{$item}.
3736: '</span></td>'.
3737: '<td class="LC_left_item">';
3738: if (($item eq 'url') || ($item eq 'button')) {
3739: $datatable .= '<span class="LC_nobreak">'.
3740: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3741: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3742: } elsif ($item eq 'fields') {
3743: my @currfields;
3744: if (ref($currvalidation{$item}) eq 'ARRAY') {
3745: @currfields = @{$currvalidation{$item}};
3746: }
3747: foreach my $field (@{$fieldsref}) {
3748: my $check = '';
3749: if (grep(/^\Q$field\E$/,@currfields)) {
3750: $check = ' checked="checked"';
3751: }
3752: $datatable .= '<span class="LC_nobreak"><label>'.
3753: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3754: ' value="'.$field.'"'.$check.' />'.$field.
3755: '</label></span> ';
3756: }
3757: } elsif ($item eq 'markup') {
3758: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3759: $currvalidation{$item}.
3760: '</textarea>';
3761: }
3762: $datatable .= '</td></tr>'."\n";
3763: if (ref($rowtotal)) {
3764: $itemcount ++;
3765: }
3766: }
3767: if ($caller eq 'requestcourses') {
3768: my %currhash;
3769: if (ref($settings) eq 'HASH') {
3770: if (ref($settings->{'validation'}) eq 'HASH') {
3771: if ($settings->{'validation'}{'dc'} ne '') {
3772: $currhash{$settings->{'validation'}{'dc'}} = 1;
3773: }
3774: }
3775: }
3776: my $numinrow = 2;
3777: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3778: 'validationdc',%currhash);
3779: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3780: $datatable .= '</td></tr><tr'.$css_class.'><td>';
3781: if ($numdc > 1) {
3782: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
3783: } else {
3784: $datatable .= &mt('Course creation processed as: ');
3785: }
3786: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3787: $itemcount ++;
3788: }
3789: if (ref($rowtotal)) {
3790: $$rowtotal += $itemcount;
3791: }
3792: return $datatable;
3793: }
3794:
3795: sub print_usersessions {
3796: my ($position,$dom,$settings,$rowtotal) = @_;
3797: my ($css_class,$datatable,%checked,%choices);
3798: my (%by_ip,%by_location,@intdoms);
3799: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
3800:
3801: my @alldoms = &Apache::lonnet::all_domains();
3802: my %serverhomes = %Apache::lonnet::serverhomeIDs;
3803: my %servers = &Apache::lonnet::internet_dom_servers($dom);
3804: my %altids = &id_for_thisdom(%servers);
3805: my $itemcount = 1;
3806: if ($position eq 'top') {
3807: if (keys(%serverhomes) > 1) {
3808: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
3809: my $curroffloadnow;
3810: if (ref($settings) eq 'HASH') {
3811: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3812: $curroffloadnow = $settings->{'offloadnow'};
3813: }
3814: }
3815: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
3816: } else {
3817: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3818: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
3819: }
3820: } else {
3821: if (keys(%by_location) == 0) {
3822: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3823: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
3824: } else {
3825: my %lt = &usersession_titles();
3826: my $numinrow = 5;
3827: my $prefix;
3828: my @types;
3829: if ($position eq 'bottom') {
3830: $prefix = 'remote';
3831: @types = ('version','excludedomain','includedomain');
3832: } else {
3833: $prefix = 'hosted';
3834: @types = ('excludedomain','includedomain');
3835: }
3836: my (%current,%checkedon,%checkedoff);
3837: my @lcversions = &Apache::lonnet::all_loncaparevs();
3838: my @locations = sort(keys(%by_location));
3839: foreach my $type (@types) {
3840: $checkedon{$type} = '';
3841: $checkedoff{$type} = ' checked="checked"';
3842: }
3843: if (ref($settings) eq 'HASH') {
3844: if (ref($settings->{$prefix}) eq 'HASH') {
3845: foreach my $key (keys(%{$settings->{$prefix}})) {
3846: $current{$key} = $settings->{$prefix}{$key};
3847: if ($key eq 'version') {
3848: if ($current{$key} ne '') {
3849: $checkedon{$key} = ' checked="checked"';
3850: $checkedoff{$key} = '';
3851: }
3852: } elsif (ref($current{$key}) eq 'ARRAY') {
3853: $checkedon{$key} = ' checked="checked"';
3854: $checkedoff{$key} = '';
3855: }
3856: }
3857: }
3858: }
3859: foreach my $type (@types) {
3860: next if ($type ne 'version' && !@locations);
3861: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3862: $datatable .= '<tr'.$css_class.'>
3863: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3864: <span class="LC_nobreak">
3865: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3866: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3867: if ($type eq 'version') {
3868: my $selector = '<select name="'.$prefix.'_version">';
3869: foreach my $version (@lcversions) {
3870: my $selected = '';
3871: if ($current{'version'} eq $version) {
3872: $selected = ' selected="selected"';
3873: }
3874: $selector .= ' <option value="'.$version.'"'.
3875: $selected.'>'.$version.'</option>';
3876: }
3877: $selector .= '</select> ';
3878: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3879: } else {
3880: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3881: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3882: ' />'.(' 'x2).
3883: '<input type="button" value="'.&mt('uncheck all').'" '.
3884: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3885: "\n".
3886: '</div><div><table>';
3887: my $rem;
3888: for (my $i=0; $i<@locations; $i++) {
3889: my ($showloc,$value,$checkedtype);
3890: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3891: my $ip = $by_location{$locations[$i]}->[0];
3892: if (ref($by_ip{$ip}) eq 'ARRAY') {
3893: $value = join(':',@{$by_ip{$ip}});
3894: $showloc = join(', ',@{$by_ip{$ip}});
3895: if (ref($current{$type}) eq 'ARRAY') {
3896: foreach my $loc (@{$by_ip{$ip}}) {
3897: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3898: $checkedtype = ' checked="checked"';
3899: last;
3900: }
3901: }
3902: }
3903: }
3904: }
3905: $rem = $i%($numinrow);
3906: if ($rem == 0) {
3907: if ($i > 0) {
3908: $datatable .= '</tr>';
3909: }
3910: $datatable .= '<tr>';
3911: }
3912: $datatable .= '<td class="LC_left_item">'.
3913: '<span class="LC_nobreak"><label>'.
3914: '<input type="checkbox" name="'.$prefix.'_'.$type.
3915: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3916: '</label></span></td>';
3917: }
3918: $rem = @locations%($numinrow);
3919: my $colsleft = $numinrow - $rem;
3920: if ($colsleft > 1 ) {
3921: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3922: ' </td>';
3923: } elsif ($colsleft == 1) {
3924: $datatable .= '<td class="LC_left_item"> </td>';
3925: }
3926: $datatable .= '</tr></table>';
3927: }
3928: $datatable .= '</td></tr>';
3929: $itemcount ++;
3930: }
3931: }
3932: }
3933: $$rowtotal += $itemcount;
3934: return $datatable;
3935: }
3936:
3937: sub build_location_hashes {
3938: my ($intdoms,$by_ip,$by_location) = @_;
3939: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3940: (ref($by_location) eq 'HASH'));
3941: my %iphost = &Apache::lonnet::get_iphost();
3942: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3943: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3944: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3945: foreach my $id (@{$iphost{$primary_ip}}) {
3946: my $intdom = &Apache::lonnet::internet_dom($id);
3947: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3948: push(@{$intdoms},$intdom);
3949: }
3950: }
3951: }
3952: foreach my $ip (keys(%iphost)) {
3953: if (ref($iphost{$ip}) eq 'ARRAY') {
3954: foreach my $id (@{$iphost{$ip}}) {
3955: my $location = &Apache::lonnet::internet_dom($id);
3956: if ($location) {
3957: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3958: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3959: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3960: push(@{$by_ip->{$ip}},$location);
3961: }
3962: } else {
3963: $by_ip->{$ip} = [$location];
3964: }
3965: }
3966: }
3967: }
3968: }
3969: foreach my $ip (sort(keys(%{$by_ip}))) {
3970: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3971: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3972: my $first = $by_ip->{$ip}->[0];
3973: if (ref($by_location->{$first}) eq 'ARRAY') {
3974: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3975: push(@{$by_location->{$first}},$ip);
3976: }
3977: } else {
3978: $by_location->{$first} = [$ip];
3979: }
3980: }
3981: }
3982: return;
3983: }
3984:
3985: sub current_offloads_to {
3986: my ($dom,$settings,$servers) = @_;
3987: my (%spareid,%otherdomconfigs);
3988: if (ref($servers) eq 'HASH') {
3989: foreach my $lonhost (sort(keys(%{$servers}))) {
3990: my $gotspares;
3991: if (ref($settings) eq 'HASH') {
3992: if (ref($settings->{'spares'}) eq 'HASH') {
3993: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3994: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3995: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3996: $gotspares = 1;
3997: }
3998: }
3999: }
4000: unless ($gotspares) {
4001: my $gotspares;
4002: my $serverhomeID =
4003: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4004: my $serverhomedom =
4005: &Apache::lonnet::host_domain($serverhomeID);
4006: if ($serverhomedom ne $dom) {
4007: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4008: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4009: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4010: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4011: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4012: $gotspares = 1;
4013: }
4014: }
4015: } else {
4016: $otherdomconfigs{$serverhomedom} =
4017: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4018: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4019: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4020: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4021: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4022: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4023: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4024: $gotspares = 1;
4025: }
4026: }
4027: }
4028: }
4029: }
4030: }
4031: }
4032: unless ($gotspares) {
4033: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4034: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4035: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4036: } else {
4037: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4038: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4039: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4040: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4041: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4042: } else {
4043: my %what = (
4044: spareid => 1,
4045: );
4046: my ($result,$returnhash) =
4047: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4048: if ($result eq 'ok') {
4049: if (ref($returnhash) eq 'HASH') {
4050: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4051: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4052: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4053: }
4054: }
4055: }
4056: }
4057: }
4058: }
4059: }
4060: }
4061: return %spareid;
4062: }
4063:
4064: sub spares_row {
4065: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
4066: my $css_class;
4067: my $numinrow = 4;
4068: my $itemcount = 1;
4069: my $datatable;
4070: my %typetitles = &sparestype_titles();
4071: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
4072: foreach my $server (sort(keys(%{$servers}))) {
4073: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4074: my ($othercontrol,$serverdom);
4075: if ($serverhome ne $server) {
4076: $serverdom = &Apache::lonnet::host_domain($serverhome);
4077: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4078: } else {
4079: $serverdom = &Apache::lonnet::host_domain($server);
4080: if ($serverdom ne $dom) {
4081: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4082: }
4083: }
4084: next unless (ref($spareid->{$server}) eq 'HASH');
4085: my $checkednow;
4086: if (ref($curroffloadnow) eq 'HASH') {
4087: if ($curroffloadnow->{$server}) {
4088: $checkednow = ' checked="checked"';
4089: }
4090: }
4091: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4092: $datatable .= '<tr'.$css_class.'>
4093: <td rowspan="2">
4094: <span class="LC_nobreak">'.
4095: &mt('[_1] when busy, offloads to:'
4096: ,'<b>'.$server.'</b>').'</span><br />'.
4097: '<span class="LC_nobreak">'."\n".
4098: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4099: ' '.&mt('Switch active users on next access').'</label></span>'.
4100: "\n";
4101: my (%current,%canselect);
4102: my @choices =
4103: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4104: foreach my $type ('primary','default') {
4105: if (ref($spareid->{$server}) eq 'HASH') {
4106: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4107: my @spares = @{$spareid->{$server}{$type}};
4108: if (@spares > 0) {
4109: if ($othercontrol) {
4110: $current{$type} = join(', ',@spares);
4111: } else {
4112: $current{$type} .= '<table>';
4113: my $numspares = scalar(@spares);
4114: for (my $i=0; $i<@spares; $i++) {
4115: my $rem = $i%($numinrow);
4116: if ($rem == 0) {
4117: if ($i > 0) {
4118: $current{$type} .= '</tr>';
4119: }
4120: $current{$type} .= '<tr>';
4121: }
4122: $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'".');" /> '.
4123: $spareid->{$server}{$type}[$i].
4124: '</label></td>'."\n";
4125: }
4126: my $rem = @spares%($numinrow);
4127: my $colsleft = $numinrow - $rem;
4128: if ($colsleft > 1 ) {
4129: $current{$type} .= '<td colspan="'.$colsleft.
4130: '" class="LC_left_item">'.
4131: ' </td>';
4132: } elsif ($colsleft == 1) {
4133: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
4134: }
4135: $current{$type} .= '</tr></table>';
4136: }
4137: }
4138: }
4139: if ($current{$type} eq '') {
4140: $current{$type} = &mt('None specified');
4141: }
4142: if ($othercontrol) {
4143: if ($type eq 'primary') {
4144: $canselect{$type} = $othercontrol;
4145: }
4146: } else {
4147: $canselect{$type} =
4148: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4149: '<select name="newspare_'.$type.'_'.$server.'" '.
4150: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4151: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4152: if (@choices > 0) {
4153: foreach my $lonhost (@choices) {
4154: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4155: }
4156: }
4157: $canselect{$type} .= '</select>'."\n";
4158: }
4159: } else {
4160: $current{$type} = &mt('Could not be determined');
4161: if ($type eq 'primary') {
4162: $canselect{$type} = $othercontrol;
4163: }
4164: }
4165: if ($type eq 'default') {
4166: $datatable .= '<tr'.$css_class.'>';
4167: }
4168: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4169: '<td>'.$current{$type}.'</td>'."\n".
4170: '<td>'.$canselect{$type}.'</td></tr>'."\n";
4171: }
4172: $itemcount ++;
4173: }
4174: }
4175: $$rowtotal += $itemcount;
4176: return $datatable;
4177: }
4178:
4179: sub possible_newspares {
4180: my ($server,$currspares,$serverhomes,$altids) = @_;
4181: my $serverhostname = &Apache::lonnet::hostname($server);
4182: my %excluded;
4183: if ($serverhostname ne '') {
4184: %excluded = (
4185: $serverhostname => 1,
4186: );
4187: }
4188: if (ref($currspares) eq 'HASH') {
4189: foreach my $type (keys(%{$currspares})) {
4190: if (ref($currspares->{$type}) eq 'ARRAY') {
4191: if (@{$currspares->{$type}} > 0) {
4192: foreach my $curr (@{$currspares->{$type}}) {
4193: my $hostname = &Apache::lonnet::hostname($curr);
4194: $excluded{$hostname} = 1;
4195: }
4196: }
4197: }
4198: }
4199: }
4200: my @choices;
4201: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4202: if (keys(%{$serverhomes}) > 1) {
4203: foreach my $name (sort(keys(%{$serverhomes}))) {
4204: unless ($excluded{$name}) {
4205: if (exists($altids->{$serverhomes->{$name}})) {
4206: push(@choices,$altids->{$serverhomes->{$name}});
4207: } else {
4208: push(@choices,$serverhomes->{$name});
4209: }
4210: }
4211: }
4212: }
4213: }
4214: return sort(@choices);
4215: }
4216:
4217: sub print_loadbalancing {
4218: my ($dom,$settings,$rowtotal) = @_;
4219: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4220: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4221: my $numinrow = 1;
4222: my $datatable;
4223: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4224: my (%currbalancer,%currtargets,%currrules,%existing);
4225: if (ref($settings) eq 'HASH') {
4226: %existing = %{$settings};
4227: }
4228: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4229: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4230: \%currtargets,\%currrules);
4231: } else {
4232: return;
4233: }
4234: my ($othertitle,$usertypes,$types) =
4235: &Apache::loncommon::sorted_inst_types($dom);
4236: my $rownum = 8;
4237: if (ref($types) eq 'ARRAY') {
4238: $rownum += scalar(@{$types});
4239: }
4240: my @css_class = ('LC_odd_row','LC_even_row');
4241: my $balnum = 0;
4242: my $islast;
4243: my (@toshow,$disabledtext);
4244: if (keys(%currbalancer) > 0) {
4245: @toshow = sort(keys(%currbalancer));
4246: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4247: push(@toshow,'');
4248: }
4249: } else {
4250: @toshow = ('');
4251: $disabledtext = &mt('No existing load balancer');
4252: }
4253: foreach my $lonhost (@toshow) {
4254: if ($balnum == scalar(@toshow)-1) {
4255: $islast = 1;
4256: } else {
4257: $islast = 0;
4258: }
4259: my $cssidx = $balnum%2;
4260: my $targets_div_style = 'display: none';
4261: my $disabled_div_style = 'display: block';
4262: my $homedom_div_style = 'display: none';
4263: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4264: '<td rowspan="'.$rownum.'" valign="top">'.
4265: '<p>';
4266: if ($lonhost eq '') {
4267: $datatable .= '<span class="LC_nobreak">';
4268: if (keys(%currbalancer) > 0) {
4269: $datatable .= &mt('Add balancer:');
4270: } else {
4271: $datatable .= &mt('Enable balancer:');
4272: }
4273: $datatable .= ' '.
4274: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4275: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4276: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4277: '<option value="" selected="selected">'.&mt('None').
4278: '</option>'."\n";
4279: foreach my $server (sort(keys(%servers))) {
4280: next if ($currbalancer{$server});
4281: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4282: }
4283: $datatable .=
4284: '</select>'."\n".
4285: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4286: } else {
4287: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4288: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4289: &mt('Stop balancing').'</label>'.
4290: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4291: $targets_div_style = 'display: block';
4292: $disabled_div_style = 'display: none';
4293: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4294: $homedom_div_style = 'display: block';
4295: }
4296: }
4297: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4298: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4299: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4300: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4301: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4302: my @sparestypes = ('primary','default');
4303: my %typetitles = &sparestype_titles();
4304: foreach my $sparetype (@sparestypes) {
4305: my $targettable;
4306: for (my $i=0; $i<$numspares; $i++) {
4307: my $checked;
4308: if (ref($currtargets{$lonhost}) eq 'HASH') {
4309: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4310: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4311: $checked = ' checked="checked"';
4312: }
4313: }
4314: }
4315: my ($chkboxval,$disabled);
4316: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4317: $chkboxval = $spares[$i];
4318: }
4319: if (exists($currbalancer{$spares[$i]})) {
4320: $disabled = ' disabled="disabled"';
4321: }
4322: $targettable .=
4323: '<td><span class="LC_nobreak"><label>'.
4324: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
4325: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
4326: '</span></label></span></td>';
4327: my $rem = $i%($numinrow);
4328: if ($rem == 0) {
4329: if (($i > 0) && ($i < $numspares-1)) {
4330: $targettable .= '</tr>';
4331: }
4332: if ($i < $numspares-1) {
4333: $targettable .= '<tr>';
4334: }
4335: }
4336: }
4337: if ($targettable ne '') {
4338: my $rem = $numspares%($numinrow);
4339: my $colsleft = $numinrow - $rem;
4340: if ($colsleft > 1 ) {
4341: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4342: ' </td>';
4343: } elsif ($colsleft == 1) {
4344: $targettable .= '<td class="LC_left_item"> </td>';
4345: }
4346: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4347: '<table><tr>'.$targettable.'</tr></table><br />';
4348: }
4349: }
4350: $datatable .= '</div></td></tr>'.
4351: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4352: $othertitle,$usertypes,$types,\%servers,
4353: \%currbalancer,$lonhost,
4354: $targets_div_style,$homedom_div_style,
4355: $css_class[$cssidx],$balnum,$islast);
4356: $$rowtotal += $rownum;
4357: $balnum ++;
4358: }
4359: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4360: return $datatable;
4361: }
4362:
4363: sub get_loadbalancers_config {
4364: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4365: return unless ((ref($servers) eq 'HASH') &&
4366: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4367: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4368: if (keys(%{$existing}) > 0) {
4369: my $oldlonhost;
4370: foreach my $key (sort(keys(%{$existing}))) {
4371: if ($key eq 'lonhost') {
4372: $oldlonhost = $existing->{'lonhost'};
4373: $currbalancer->{$oldlonhost} = 1;
4374: } elsif ($key eq 'targets') {
4375: if ($oldlonhost) {
4376: $currtargets->{$oldlonhost} = $existing->{'targets'};
4377: }
4378: } elsif ($key eq 'rules') {
4379: if ($oldlonhost) {
4380: $currrules->{$oldlonhost} = $existing->{'rules'};
4381: }
4382: } elsif (ref($existing->{$key}) eq 'HASH') {
4383: $currbalancer->{$key} = 1;
4384: $currtargets->{$key} = $existing->{$key}{'targets'};
4385: $currrules->{$key} = $existing->{$key}{'rules'};
4386: }
4387: }
4388: } else {
4389: my ($balancerref,$targetsref) =
4390: &Apache::lonnet::get_lonbalancer_config($servers);
4391: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4392: foreach my $server (sort(keys(%{$balancerref}))) {
4393: $currbalancer->{$server} = 1;
4394: $currtargets->{$server} = $targetsref->{$server};
4395: }
4396: }
4397: }
4398: return;
4399: }
4400:
4401: sub loadbalancing_rules {
4402: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
4403: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4404: $css_class,$balnum,$islast) = @_;
4405: my $output;
4406: my $num = 0;
4407: my ($alltypes,$othertypes,$titles) =
4408: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4409: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4410: foreach my $type (@{$alltypes}) {
4411: $num ++;
4412: my $current;
4413: if (ref($currrules) eq 'HASH') {
4414: $current = $currrules->{$type};
4415: }
4416: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
4417: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
4418: $current = '';
4419: }
4420: }
4421: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
4422: $servers,$currbalancer,$lonhost,$dom,
4423: $targets_div_style,$homedom_div_style,
4424: $css_class,$balnum,$num,$islast);
4425: }
4426: }
4427: return $output;
4428: }
4429:
4430: sub loadbalancing_titles {
4431: my ($dom,$intdom,$usertypes,$types) = @_;
4432: my %othertypes = (
4433: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4434: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4435: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4436: '_LC_external' => &mt('Users not from [_1]',$intdom),
4437: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4438: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
4439: );
4440: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
4441: if (ref($types) eq 'ARRAY') {
4442: unshift(@alltypes,@{$types},'default');
4443: }
4444: my %titles;
4445: foreach my $type (@alltypes) {
4446: if ($type =~ /^_LC_/) {
4447: $titles{$type} = $othertypes{$type};
4448: } elsif ($type eq 'default') {
4449: $titles{$type} = &mt('All users from [_1]',$dom);
4450: if (ref($types) eq 'ARRAY') {
4451: if (@{$types} > 0) {
4452: $titles{$type} = &mt('Other users from [_1]',$dom);
4453: }
4454: }
4455: } elsif (ref($usertypes) eq 'HASH') {
4456: $titles{$type} = $usertypes->{$type};
4457: }
4458: }
4459: return (\@alltypes,\%othertypes,\%titles);
4460: }
4461:
4462: sub loadbalance_rule_row {
4463: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4464: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
4465: my @rulenames;
4466: my %ruletitles = &offloadtype_text();
4467: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
4468: @rulenames = ('balancer','offloadedto','specific');
4469: } else {
4470: @rulenames = ('default','homeserver');
4471: if ($type eq '_LC_external') {
4472: push(@rulenames,'externalbalancer');
4473: } else {
4474: push(@rulenames,'specific');
4475: }
4476: push(@rulenames,'none');
4477: }
4478: my $style = $targets_div_style;
4479: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
4480: $style = $homedom_div_style;
4481: }
4482: my $space;
4483: if ($islast && $num == 1) {
4484: $space = '<div display="inline-block"> </div>';
4485: }
4486: my $output =
4487: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4488: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4489: '<td valaign="top">'.$space.
4490: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
4491: for (my $i=0; $i<@rulenames; $i++) {
4492: my $rule = $rulenames[$i];
4493: my ($checked,$extra);
4494: if ($rulenames[$i] eq 'default') {
4495: $rule = '';
4496: }
4497: if ($rulenames[$i] eq 'specific') {
4498: if (ref($servers) eq 'HASH') {
4499: my $default;
4500: if (($current ne '') && (exists($servers->{$current}))) {
4501: $checked = ' checked="checked"';
4502: }
4503: unless ($checked) {
4504: $default = ' selected="selected"';
4505: }
4506: $extra =
4507: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4508: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4509: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4510: '<option value=""'.$default.'></option>'."\n";
4511: foreach my $server (sort(keys(%{$servers}))) {
4512: if (ref($currbalancer) eq 'HASH') {
4513: next if (exists($currbalancer->{$server}));
4514: }
4515: my $selected;
4516: if ($server eq $current) {
4517: $selected = ' selected="selected"';
4518: }
4519: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
4520: }
4521: $extra .= '</select>';
4522: }
4523: } elsif ($rule eq $current) {
4524: $checked = ' checked="checked"';
4525: }
4526: $output .= '<span class="LC_nobreak"><label>'.
4527: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4528: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4529: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
4530: ')"'.$checked.' /> ';
4531: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4532: $output .= $ruletitles{'particular'};
4533: } else {
4534: $output .= $ruletitles{$rulenames[$i]};
4535: }
4536: $output .= '</label>'.$extra.'</span><br />'."\n";
4537: }
4538: $output .= '</div></td></tr>'."\n";
4539: return $output;
4540: }
4541:
4542: sub offloadtype_text {
4543: my %ruletitles = &Apache::lonlocal::texthash (
4544: 'default' => 'Offloads to default destinations',
4545: 'homeserver' => "Offloads to user's home server",
4546: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4547: 'specific' => 'Offloads to specific server',
4548: 'none' => 'No offload',
4549: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4550: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
4551: 'particular' => 'Session hosted (after re-auth) on server:',
4552: );
4553: return %ruletitles;
4554: }
4555:
4556: sub sparestype_titles {
4557: my %typestitles = &Apache::lonlocal::texthash (
4558: 'primary' => 'primary',
4559: 'default' => 'default',
4560: );
4561: return %typestitles;
4562: }
4563:
4564: sub contact_titles {
4565: my %titles = &Apache::lonlocal::texthash (
4566: 'supportemail' => 'Support E-mail address',
4567: 'adminemail' => 'Default Server Admin E-mail address',
4568: 'errormail' => 'Error reports to be e-mailed to',
4569: 'packagesmail' => 'Package update alerts to be e-mailed to',
4570: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4571: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4572: 'requestsmail' => 'E-mail from course requests requiring approval',
4573: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
4574: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
4575: );
4576: my %short_titles = &Apache::lonlocal::texthash (
4577: adminemail => 'Admin E-mail address',
4578: supportemail => 'Support E-mail',
4579: );
4580: return (\%titles,\%short_titles);
4581: }
4582:
4583: sub tool_titles {
4584: my %titles = &Apache::lonlocal::texthash (
4585: aboutme => 'Personal web page',
4586: blog => 'Blog',
4587: webdav => 'WebDAV',
4588: portfolio => 'Portfolio',
4589: official => 'Official courses (with institutional codes)',
4590: unofficial => 'Unofficial courses',
4591: community => 'Communities',
4592: textbook => 'Textbook courses',
4593: placement => 'Placement tests',
4594: );
4595: return %titles;
4596: }
4597:
4598: sub courserequest_titles {
4599: my %titles = &Apache::lonlocal::texthash (
4600: official => 'Official',
4601: unofficial => 'Unofficial',
4602: community => 'Communities',
4603: textbook => 'Textbook',
4604: placement => 'Placement tests',
4605: norequest => 'Not allowed',
4606: approval => 'Approval by Dom. Coord.',
4607: validate => 'With validation',
4608: autolimit => 'Numerical limit',
4609: unlimited => '(blank for unlimited)',
4610: );
4611: return %titles;
4612: }
4613:
4614: sub authorrequest_titles {
4615: my %titles = &Apache::lonlocal::texthash (
4616: norequest => 'Not allowed',
4617: approval => 'Approval by Dom. Coord.',
4618: automatic => 'Automatic approval',
4619: );
4620: return %titles;
4621: }
4622:
4623: sub courserequest_conditions {
4624: my %conditions = &Apache::lonlocal::texthash (
4625: approval => '(Processing of request subject to approval by Domain Coordinator).',
4626: validate => '(Processing of request subject to institutional validation).',
4627: );
4628: return %conditions;
4629: }
4630:
4631:
4632: sub print_usercreation {
4633: my ($position,$dom,$settings,$rowtotal) = @_;
4634: my $numinrow = 4;
4635: my $datatable;
4636: if ($position eq 'top') {
4637: $$rowtotal ++;
4638: my $rowcount = 0;
4639: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
4640: if (ref($rules) eq 'HASH') {
4641: if (keys(%{$rules}) > 0) {
4642: $datatable .= &user_formats_row('username',$settings,$rules,
4643: $ruleorder,$numinrow,$rowcount);
4644: $$rowtotal ++;
4645: $rowcount ++;
4646: }
4647: }
4648: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4649: if (ref($idrules) eq 'HASH') {
4650: if (keys(%{$idrules}) > 0) {
4651: $datatable .= &user_formats_row('id',$settings,$idrules,
4652: $idruleorder,$numinrow,$rowcount);
4653: $$rowtotal ++;
4654: $rowcount ++;
4655: }
4656: }
4657: if ($rowcount == 0) {
4658: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4659: $$rowtotal ++;
4660: $rowcount ++;
4661: }
4662: } elsif ($position eq 'middle') {
4663: my @creators = ('author','course','requestcrs');
4664: my ($rules,$ruleorder) =
4665: &Apache::lonnet::inst_userrules($dom,'username');
4666: my %lt = &usercreation_types();
4667: my %checked;
4668: if (ref($settings) eq 'HASH') {
4669: if (ref($settings->{'cancreate'}) eq 'HASH') {
4670: foreach my $item (@creators) {
4671: $checked{$item} = $settings->{'cancreate'}{$item};
4672: }
4673: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4674: foreach my $item (@creators) {
4675: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4676: $checked{$item} = 'none';
4677: }
4678: }
4679: }
4680: }
4681: my $rownum = 0;
4682: foreach my $item (@creators) {
4683: $rownum ++;
4684: if ($checked{$item} eq '') {
4685: $checked{$item} = 'any';
4686: }
4687: my $css_class;
4688: if ($rownum%2) {
4689: $css_class = '';
4690: } else {
4691: $css_class = ' class="LC_odd_row" ';
4692: }
4693: $datatable .= '<tr'.$css_class.'>'.
4694: '<td><span class="LC_nobreak">'.$lt{$item}.
4695: '</span></td><td align="right">';
4696: my @options = ('any');
4697: if (ref($rules) eq 'HASH') {
4698: if (keys(%{$rules}) > 0) {
4699: push(@options,('official','unofficial'));
4700: }
4701: }
4702: push(@options,'none');
4703: foreach my $option (@options) {
4704: my $type = 'radio';
4705: my $check = ' ';
4706: if ($checked{$item} eq $option) {
4707: $check = ' checked="checked" ';
4708: }
4709: $datatable .= '<span class="LC_nobreak"><label>'.
4710: '<input type="'.$type.'" name="can_createuser_'.
4711: $item.'" value="'.$option.'"'.$check.'/> '.
4712: $lt{$option}.'</label> </span>';
4713: }
4714: $datatable .= '</td></tr>';
4715: }
4716: } else {
4717: my @contexts = ('author','course','domain');
4718: my @authtypes = ('int','krb4','krb5','loc');
4719: my %checked;
4720: if (ref($settings) eq 'HASH') {
4721: if (ref($settings->{'authtypes'}) eq 'HASH') {
4722: foreach my $item (@contexts) {
4723: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4724: foreach my $auth (@authtypes) {
4725: if ($settings->{'authtypes'}{$item}{$auth}) {
4726: $checked{$item}{$auth} = ' checked="checked" ';
4727: }
4728: }
4729: }
4730: }
4731: }
4732: } else {
4733: foreach my $item (@contexts) {
4734: foreach my $auth (@authtypes) {
4735: $checked{$item}{$auth} = ' checked="checked" ';
4736: }
4737: }
4738: }
4739: my %title = &context_names();
4740: my %authname = &authtype_names();
4741: my $rownum = 0;
4742: my $css_class;
4743: foreach my $item (@contexts) {
4744: if ($rownum%2) {
4745: $css_class = '';
4746: } else {
4747: $css_class = ' class="LC_odd_row" ';
4748: }
4749: $datatable .= '<tr'.$css_class.'>'.
4750: '<td>'.$title{$item}.
4751: '</td><td class="LC_left_item">'.
4752: '<span class="LC_nobreak">';
4753: foreach my $auth (@authtypes) {
4754: $datatable .= '<label>'.
4755: '<input type="checkbox" name="'.$item.'_auth" '.
4756: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4757: $authname{$auth}.'</label> ';
4758: }
4759: $datatable .= '</span></td></tr>';
4760: $rownum ++;
4761: }
4762: $$rowtotal += $rownum;
4763: }
4764: return $datatable;
4765: }
4766:
4767: sub print_selfcreation {
4768: my ($position,$dom,$settings,$rowtotal) = @_;
4769: my (@selfcreate,$createsettings,$processing,$datatable);
4770: if (ref($settings) eq 'HASH') {
4771: if (ref($settings->{'cancreate'}) eq 'HASH') {
4772: $createsettings = $settings->{'cancreate'};
4773: if (ref($createsettings) eq 'HASH') {
4774: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4775: @selfcreate = @{$createsettings->{'selfcreate'}};
4776: } elsif ($createsettings->{'selfcreate'} ne '') {
4777: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4778: @selfcreate = ('email','login','sso');
4779: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4780: @selfcreate = ($createsettings->{'selfcreate'});
4781: }
4782: }
4783: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4784: $processing = $createsettings->{'selfcreateprocessing'};
4785: }
4786: }
4787: }
4788: }
4789: my %radiohash;
4790: my $numinrow = 4;
4791: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4792: if ($position eq 'top') {
4793: my %choices = &Apache::lonlocal::texthash (
4794: cancreate_login => 'Institutional Login',
4795: cancreate_sso => 'Institutional Single Sign On',
4796: );
4797: my @toggles = sort(keys(%choices));
4798: my %defaultchecked = (
4799: 'cancreate_login' => 'off',
4800: 'cancreate_sso' => 'off',
4801: );
4802: my ($onclick,$itemcount);
4803: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4804: \%choices,$itemcount,$onclick);
4805: $$rowtotal += $itemcount;
4806:
4807: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4808:
4809: if (ref($usertypes) eq 'HASH') {
4810: if (keys(%{$usertypes}) > 0) {
4811: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4812: $dom,$numinrow,$othertitle,
4813: 'statustocreate',$$rowtotal);
4814: $$rowtotal ++;
4815: }
4816: }
4817: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4818: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4819: $fieldtitles{'inststatus'} = &mt('Institutional status');
4820: my $rem;
4821: my $numperrow = 2;
4822: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4823: $datatable .= '<tr'.$css_class.'>'.
4824: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
4825: '<td class="LC_left_item">'."\n".
4826: '<table><tr><td>'."\n";
4827: for (my $i=0; $i<@fields; $i++) {
4828: $rem = $i%($numperrow);
4829: if ($rem == 0) {
4830: if ($i > 0) {
4831: $datatable .= '</tr>';
4832: }
4833: $datatable .= '<tr>';
4834: }
4835: my $currval;
4836: if (ref($createsettings) eq 'HASH') {
4837: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4838: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4839: }
4840: }
4841: $datatable .= '<td class="LC_left_item">'.
4842: '<span class="LC_nobreak">'.
4843: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4844: 'value="'.$currval.'" size="10" /> '.
4845: $fieldtitles{$fields[$i]}.'</span></td>';
4846: }
4847: my $colsleft = $numperrow - $rem;
4848: if ($colsleft > 1 ) {
4849: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4850: ' </td>';
4851: } elsif ($colsleft == 1) {
4852: $datatable .= '<td class="LC_left_item"> </td>';
4853: }
4854: $datatable .= '</tr></table></td></tr>';
4855: $$rowtotal ++;
4856: } elsif ($position eq 'middle') {
4857: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4858: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4859: $usertypes->{'default'} = $othertitle;
4860: if (ref($types) eq 'ARRAY') {
4861: push(@{$types},'default');
4862: $usertypes->{'default'} = $othertitle;
4863: foreach my $status (@{$types}) {
4864: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
4865: $numinrow,$$rowtotal,$usertypes);
4866: $$rowtotal ++;
4867: }
4868: }
4869: } else {
4870: my %choices = &Apache::lonlocal::texthash (
4871: cancreate_email => 'E-mail address as username',
4872: );
4873: my @toggles = sort(keys(%choices));
4874: my %defaultchecked = (
4875: 'cancreate_email' => 'off',
4876: );
4877: my $itemcount = 0;
4878: my $display = 'none';
4879: if (grep(/^\Qemail\E$/,@selfcreate)) {
4880: $display = 'block';
4881: }
4882: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4883: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4884: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4885: my $usertypes = {};
4886: my $order = [];
4887: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4888: $usertypes = $domdefaults{'inststatustypes'};
4889: $order = $domdefaults{'inststatusguest'};
4890: }
4891: if (ref($order) eq 'ARRAY') {
4892: push(@{$order},'default');
4893: if (@{$order} > 1) {
4894: $usertypes->{'default'} = &mt('Other users');
4895: $additional .= '<table><tr>';
4896: foreach my $status (@{$order}) {
4897: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4898: }
4899: $additional .= '</tr><tr>';
4900: foreach my $status (@{$order}) {
4901: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
4902: }
4903: $additional .= '</tr></table>';
4904: } else {
4905: $usertypes->{'default'} = &mt('All users');
4906: $additional .= &email_as_username($rowtotal,$processing);
4907: }
4908: }
4909: $additional .= '</div>'."\n";
4910:
4911: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4912: \%choices,$$rowtotal,$onclick,$additional);
4913: $$rowtotal ++;
4914: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
4915: $$rowtotal ++;
4916: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4917: $numinrow = 1;
4918: if (ref($order) eq 'ARRAY') {
4919: foreach my $status (@{$order}) {
4920: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4921: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4922: $$rowtotal ++;
4923: }
4924: }
4925: my ($emailrules,$emailruleorder) =
4926: &Apache::lonnet::inst_userrules($dom,'email');
4927: if (ref($emailrules) eq 'HASH') {
4928: if (keys(%{$emailrules}) > 0) {
4929: $datatable .= &user_formats_row('email',$settings,$emailrules,
4930: $emailruleorder,$numinrow,$$rowtotal);
4931: $$rowtotal ++;
4932: }
4933: }
4934: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
4935: }
4936: return $datatable;
4937: }
4938:
4939: sub email_as_username {
4940: my ($rowtotal,$processing,$type) = @_;
4941: my %choices =
4942: &Apache::lonlocal::texthash (
4943: automatic => 'Automatic approval',
4944: approval => 'Queued for approval',
4945: );
4946: my $output;
4947: foreach my $option ('automatic','approval') {
4948: my $checked;
4949: if (ref($processing) eq 'HASH') {
4950: if ($type eq '') {
4951: if (!exists($processing->{'default'})) {
4952: if ($option eq 'automatic') {
4953: $checked = ' checked="checked"';
4954: }
4955: } else {
4956: if ($processing->{'default'} eq $option) {
4957: $checked = ' checked="checked"';
4958: }
4959: }
4960: } else {
4961: if (!exists($processing->{$type})) {
4962: if ($option eq 'automatic') {
4963: $checked = ' checked="checked"';
4964: }
4965: } else {
4966: if ($processing->{$type} eq $option) {
4967: $checked = ' checked="checked"';
4968: }
4969: }
4970: }
4971: } elsif ($option eq 'automatic') {
4972: $checked = ' checked="checked"';
4973: }
4974: my $name = 'cancreate_emailprocess';
4975: if (($type ne '') && ($type ne 'default')) {
4976: $name .= '_'.$type;
4977: }
4978: $output .= '<span class="LC_nobreak"><label>'.
4979: '<input type="radio" name="'.$name.'"'.
4980: $checked.' value="'.$option.'" />'.
4981: $choices{$option}.'</label></span>';
4982: if ($type eq '') {
4983: $output .= ' ';
4984: } else {
4985: $output .= '<br />';
4986: }
4987: }
4988: $$rowtotal ++;
4989: return $output;
4990: }
4991:
4992: sub captcha_choice {
4993: my ($context,$settings,$itemcount) = @_;
4994: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
4995: $vertext,$currver);
4996: my %lt = &captcha_phrases();
4997: $keyentry = 'hidden';
4998: if ($context eq 'cancreate') {
4999: $rowname = &mt('CAPTCHA validation');
5000: } elsif ($context eq 'login') {
5001: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5002: }
5003: if (ref($settings) eq 'HASH') {
5004: if ($settings->{'captcha'}) {
5005: $checked{$settings->{'captcha'}} = ' checked="checked"';
5006: } else {
5007: $checked{'original'} = ' checked="checked"';
5008: }
5009: if ($settings->{'captcha'} eq 'recaptcha') {
5010: $pubtext = $lt{'pub'};
5011: $privtext = $lt{'priv'};
5012: $keyentry = 'text';
5013: $vertext = $lt{'ver'};
5014: $currver = $settings->{'recaptchaversion'};
5015: if ($currver ne '2') {
5016: $currver = 1;
5017: }
5018: }
5019: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5020: $currpub = $settings->{'recaptchakeys'}{'public'};
5021: $currpriv = $settings->{'recaptchakeys'}{'private'};
5022: }
5023: } else {
5024: $checked{'original'} = ' checked="checked"';
5025: }
5026: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5027: my $output = '<tr'.$css_class.'>'.
5028: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5029: '<table><tr><td>'."\n";
5030: foreach my $option ('original','recaptcha','notused') {
5031: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5032: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5033: $lt{$option}.'</label></span>';
5034: unless ($option eq 'notused') {
5035: $output .= (' 'x2)."\n";
5036: }
5037: }
5038: #
5039: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5040: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5041: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5042: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5043: #
5044: $output .= '</td></tr>'."\n".
5045: '<tr><td>'."\n".
5046: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5047: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5048: $currpub.'" size="40" /></span><br />'."\n".
5049: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5050: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
5051: $currpriv.'" size="40" /></span><br />'.
5052: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5053: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5054: $currver.'" size="3" /></span><br />'.
5055: '</td></tr></table>'."\n".
5056: '</td></tr>';
5057: return $output;
5058: }
5059:
5060: sub user_formats_row {
5061: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5062: my $output;
5063: my %text = (
5064: 'username' => 'new usernames',
5065: 'id' => 'IDs',
5066: 'email' => 'self-created accounts (e-mail)',
5067: );
5068: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5069: $output = '<tr '.$css_class.'>'.
5070: '<td><span class="LC_nobreak">';
5071: if ($type eq 'email') {
5072: $output .= &mt("Formats disallowed for $text{$type}: ");
5073: } else {
5074: $output .= &mt("Format rules to check for $text{$type}: ");
5075: }
5076: $output .= '</span></td>'.
5077: '<td class="LC_left_item" colspan="2"><table>';
5078: my $rem;
5079: if (ref($ruleorder) eq 'ARRAY') {
5080: for (my $i=0; $i<@{$ruleorder}; $i++) {
5081: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5082: my $rem = $i%($numinrow);
5083: if ($rem == 0) {
5084: if ($i > 0) {
5085: $output .= '</tr>';
5086: }
5087: $output .= '<tr>';
5088: }
5089: my $check = ' ';
5090: if (ref($settings) eq 'HASH') {
5091: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5092: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5093: $check = ' checked="checked" ';
5094: }
5095: }
5096: }
5097: $output .= '<td class="LC_left_item">'.
5098: '<span class="LC_nobreak"><label>'.
5099: '<input type="checkbox" name="'.$type.'_rule" '.
5100: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5101: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5102: }
5103: }
5104: $rem = @{$ruleorder}%($numinrow);
5105: }
5106: my $colsleft = $numinrow - $rem;
5107: if ($colsleft > 1 ) {
5108: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5109: ' </td>';
5110: } elsif ($colsleft == 1) {
5111: $output .= '<td class="LC_left_item"> </td>';
5112: }
5113: $output .= '</tr></table></td></tr>';
5114: return $output;
5115: }
5116:
5117: sub usercreation_types {
5118: my %lt = &Apache::lonlocal::texthash (
5119: author => 'When adding a co-author',
5120: course => 'When adding a user to a course',
5121: requestcrs => 'When requesting a course',
5122: any => 'Any',
5123: official => 'Institutional only ',
5124: unofficial => 'Non-institutional only',
5125: none => 'None',
5126: );
5127: return %lt;
5128: }
5129:
5130: sub selfcreation_types {
5131: my %lt = &Apache::lonlocal::texthash (
5132: selfcreate => 'User creates own account',
5133: any => 'Any',
5134: official => 'Institutional only ',
5135: unofficial => 'Non-institutional only',
5136: email => 'E-mail address',
5137: login => 'Institutional Login',
5138: sso => 'SSO',
5139: );
5140: }
5141:
5142: sub authtype_names {
5143: my %lt = &Apache::lonlocal::texthash(
5144: int => 'Internal',
5145: krb4 => 'Kerberos 4',
5146: krb5 => 'Kerberos 5',
5147: loc => 'Local',
5148: );
5149: return %lt;
5150: }
5151:
5152: sub context_names {
5153: my %context_title = &Apache::lonlocal::texthash(
5154: author => 'Creating users when an Author',
5155: course => 'Creating users when in a course',
5156: domain => 'Creating users when a Domain Coordinator',
5157: );
5158: return %context_title;
5159: }
5160:
5161: sub print_usermodification {
5162: my ($position,$dom,$settings,$rowtotal) = @_;
5163: my $numinrow = 4;
5164: my ($context,$datatable,$rowcount);
5165: if ($position eq 'top') {
5166: $rowcount = 0;
5167: $context = 'author';
5168: foreach my $role ('ca','aa') {
5169: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5170: $numinrow,$rowcount);
5171: $$rowtotal ++;
5172: $rowcount ++;
5173: }
5174: } elsif ($position eq 'bottom') {
5175: $context = 'course';
5176: $rowcount = 0;
5177: foreach my $role ('st','ep','ta','in','cr') {
5178: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5179: $numinrow,$rowcount);
5180: $$rowtotal ++;
5181: $rowcount ++;
5182: }
5183: }
5184: return $datatable;
5185: }
5186:
5187: sub print_defaults {
5188: my ($position,$dom,$settings,$rowtotal) = @_;
5189: my $rownum = 0;
5190: my ($datatable,$css_class);
5191: if ($position eq 'top') {
5192: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5193: 'datelocale_def','portal_def');
5194: my %defaults;
5195: if (ref($settings) eq 'HASH') {
5196: %defaults = %{$settings};
5197: } else {
5198: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5199: foreach my $item (@items) {
5200: $defaults{$item} = $domdefaults{$item};
5201: }
5202: }
5203: my $titles = &defaults_titles($dom);
5204: foreach my $item (@items) {
5205: if ($rownum%2) {
5206: $css_class = '';
5207: } else {
5208: $css_class = ' class="LC_odd_row" ';
5209: }
5210: $datatable .= '<tr'.$css_class.'>'.
5211: '<td><span class="LC_nobreak">'.$titles->{$item}.
5212: '</span></td><td class="LC_right_item" colspan="3">';
5213: if ($item eq 'auth_def') {
5214: my @authtypes = ('internal','krb4','krb5','localauth');
5215: my %shortauth = (
5216: internal => 'int',
5217: krb4 => 'krb4',
5218: krb5 => 'krb5',
5219: localauth => 'loc'
5220: );
5221: my %authnames = &authtype_names();
5222: foreach my $auth (@authtypes) {
5223: my $checked = ' ';
5224: if ($defaults{$item} eq $auth) {
5225: $checked = ' checked="checked" ';
5226: }
5227: $datatable .= '<label><input type="radio" name="'.$item.
5228: '" value="'.$auth.'"'.$checked.'/>'.
5229: $authnames{$shortauth{$auth}}.'</label> ';
5230: }
5231: } elsif ($item eq 'timezone_def') {
5232: my $includeempty = 1;
5233: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5234: } elsif ($item eq 'datelocale_def') {
5235: my $includeempty = 1;
5236: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5237: } elsif ($item eq 'lang_def') {
5238: my $includeempty = 1;
5239: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
5240: } else {
5241: my $size;
5242: if ($item eq 'portal_def') {
5243: $size = ' size="25"';
5244: }
5245: $datatable .= '<input type="text" name="'.$item.'" value="'.
5246: $defaults{$item}.'"'.$size.' />';
5247: }
5248: $datatable .= '</td></tr>';
5249: $rownum ++;
5250: }
5251: } else {
5252: my (%defaults);
5253: if (ref($settings) eq 'HASH') {
5254: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5255: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5256: my $maxnum = @{$settings->{'inststatusorder'}};
5257: for (my $i=0; $i<$maxnum; $i++) {
5258: $css_class = $rownum%2?' class="LC_odd_row"':'';
5259: my $item = $settings->{'inststatusorder'}->[$i];
5260: my $title = $settings->{'inststatustypes'}->{$item};
5261: my $guestok;
5262: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5263: $guestok = 1;
5264: }
5265: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5266: $datatable .= '<tr'.$css_class.'>'.
5267: '<td><span class="LC_nobreak">'.
5268: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5269: for (my $k=0; $k<=$maxnum; $k++) {
5270: my $vpos = $k+1;
5271: my $selstr;
5272: if ($k == $i) {
5273: $selstr = ' selected="selected" ';
5274: }
5275: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5276: }
5277: my ($checkedon,$checkedoff);
5278: $checkedoff = ' checked="checked"';
5279: if ($guestok) {
5280: $checkedon = $checkedoff;
5281: $checkedoff = '';
5282: }
5283: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5284: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5285: &mt('delete').'</span></td>'.
5286: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5287: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5288: '</span></td>'.
5289: '<td class="LC_right_item"><span class="LC_nobreak">'.
5290: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5291: &mt('Yes').'</label>'.(' 'x2).
5292: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5293: &mt('No').'</label></span></td></tr>';
5294: }
5295: $css_class = $rownum%2?' class="LC_odd_row"':'';
5296: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5297: $datatable .= '<tr '.$css_class.'>'.
5298: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5299: for (my $k=0; $k<=$maxnum; $k++) {
5300: my $vpos = $k+1;
5301: my $selstr;
5302: if ($k == $maxnum) {
5303: $selstr = ' selected="selected" ';
5304: }
5305: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5306: }
5307: $datatable .= '</select> '.&mt('Internal ID:').
5308: '<input type="text" size="10" name="addinststatus" value="" />'.
5309: ' '.&mt('(new)').
5310: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5311: &mt('Name displayed:').
5312: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5313: '<td class="LC_right_item"><span class="LC_nobreak">'.
5314: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5315: &mt('Yes').'</label>'.(' 'x2).
5316: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5317: &mt('No').'</label></span></td></tr>';
5318: '</tr>'."\n";
5319: $rownum ++;
5320: }
5321: }
5322: }
5323: $$rowtotal += $rownum;
5324: return $datatable;
5325: }
5326:
5327: sub get_languages_hash {
5328: my %langchoices;
5329: foreach my $id (&Apache::loncommon::languageids()) {
5330: my $code = &Apache::loncommon::supportedlanguagecode($id);
5331: if ($code ne '') {
5332: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5333: }
5334: }
5335: return %langchoices;
5336: }
5337:
5338: sub defaults_titles {
5339: my ($dom) = @_;
5340: my %titles = &Apache::lonlocal::texthash (
5341: 'auth_def' => 'Default authentication type',
5342: 'auth_arg_def' => 'Default authentication argument',
5343: 'lang_def' => 'Default language',
5344: 'timezone_def' => 'Default timezone',
5345: 'datelocale_def' => 'Default locale for dates',
5346: 'portal_def' => 'Portal/Default URL',
5347: );
5348: if ($dom) {
5349: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5350: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5351: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5352: $protocol = 'http' if ($protocol ne 'https');
5353: if ($uint_dom) {
5354: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5355: $uint_dom);
5356: }
5357: }
5358: return (\%titles);
5359: }
5360:
5361: sub print_scantronformat {
5362: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5363: my $itemcount = 1;
5364: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5365: %confhash);
5366: my $switchserver = &check_switchserver($dom,$confname);
5367: my %lt = &Apache::lonlocal::texthash (
5368: default => 'Default bubblesheet format file error',
5369: custom => 'Custom bubblesheet format file error',
5370: );
5371: my %scantronfiles = (
5372: default => 'default.tab',
5373: custom => 'custom.tab',
5374: );
5375: foreach my $key (keys(%scantronfiles)) {
5376: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5377: .$scantronfiles{$key};
5378: }
5379: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5380: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5381: if (!$switchserver) {
5382: my $servadm = $r->dir_config('lonAdmEMail');
5383: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5384: if ($configuserok eq 'ok') {
5385: if ($author_ok eq 'ok') {
5386: my %legacyfile = (
5387: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5388: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5389: );
5390: my %md5chk;
5391: foreach my $type (keys(%legacyfile)) {
5392: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5393: chomp($md5chk{$type});
5394: }
5395: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5396: foreach my $type (keys(%legacyfile)) {
5397: ($scantronurls{$type},my $error) =
5398: &legacy_scantronformat($r,$dom,$confname,
5399: $type,$legacyfile{$type},
5400: $scantronurls{$type},
5401: $scantronfiles{$type});
5402: if ($error ne '') {
5403: $error{$type} = $error;
5404: }
5405: }
5406: if (keys(%error) == 0) {
5407: $is_custom = 1;
5408: $confhash{'scantron'}{'scantronformat'} =
5409: $scantronurls{'custom'};
5410: my $putresult =
5411: &Apache::lonnet::put_dom('configuration',
5412: \%confhash,$dom);
5413: if ($putresult ne 'ok') {
5414: $error{'custom'} =
5415: '<span class="LC_error">'.
5416: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5417: }
5418: }
5419: } else {
5420: ($scantronurls{'default'},my $error) =
5421: &legacy_scantronformat($r,$dom,$confname,
5422: 'default',$legacyfile{'default'},
5423: $scantronurls{'default'},
5424: $scantronfiles{'default'});
5425: if ($error eq '') {
5426: $confhash{'scantron'}{'scantronformat'} = '';
5427: my $putresult =
5428: &Apache::lonnet::put_dom('configuration',
5429: \%confhash,$dom);
5430: if ($putresult ne 'ok') {
5431: $error{'default'} =
5432: '<span class="LC_error">'.
5433: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5434: }
5435: } else {
5436: $error{'default'} = $error;
5437: }
5438: }
5439: }
5440: }
5441: } else {
5442: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
5443: }
5444: }
5445: if (ref($settings) eq 'HASH') {
5446: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5447: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5448: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5449: $scantronurl = '';
5450: } else {
5451: $scantronurl = $settings->{'scantronformat'};
5452: }
5453: $is_custom = 1;
5454: } else {
5455: $scantronurl = $scantronurls{'default'};
5456: }
5457: } else {
5458: if ($is_custom) {
5459: $scantronurl = $scantronurls{'custom'};
5460: } else {
5461: $scantronurl = $scantronurls{'default'};
5462: }
5463: }
5464: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5465: $datatable .= '<tr'.$css_class.'>';
5466: if (!$is_custom) {
5467: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5468: '<span class="LC_nobreak">';
5469: if ($scantronurl) {
5470: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5471: undef,undef,undef,undef,'background-color:#ffffff');
5472: } else {
5473: $datatable = &mt('File unavailable for display');
5474: }
5475: $datatable .= '</span></td>';
5476: if (keys(%error) == 0) {
5477: $datatable .= '<td valign="bottom">';
5478: if (!$switchserver) {
5479: $datatable .= &mt('Upload:').'<br />';
5480: }
5481: } else {
5482: my $errorstr;
5483: foreach my $key (sort(keys(%error))) {
5484: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5485: }
5486: $datatable .= '<td>'.$errorstr;
5487: }
5488: } else {
5489: if (keys(%error) > 0) {
5490: my $errorstr;
5491: foreach my $key (sort(keys(%error))) {
5492: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5493: }
5494: $datatable .= '<td>'.$errorstr.'</td><td> ';
5495: } elsif ($scantronurl) {
5496: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5497: undef,undef,undef,undef,'background-color:#ffffff');
5498: $datatable .= '<td><span class="LC_nobreak">'.
5499: $link.
5500: '<label><input type="checkbox" name="scantronformat_del"'.
5501: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
5502: '<td><span class="LC_nobreak"> '.
5503: &mt('Replace:').'</span><br />';
5504: }
5505: }
5506: if (keys(%error) == 0) {
5507: if ($switchserver) {
5508: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5509: } else {
5510: $datatable .='<span class="LC_nobreak"> '.
5511: '<input type="file" name="scantronformat" /></span>';
5512: }
5513: }
5514: $datatable .= '</td></tr>';
5515: $$rowtotal ++;
5516: return $datatable;
5517: }
5518:
5519: sub legacy_scantronformat {
5520: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5521: my ($url,$error);
5522: my @statinfo = &Apache::lonnet::stat_file($newurl);
5523: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5524: (my $result,$url) =
5525: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5526: '','',$newfile);
5527: if ($result ne 'ok') {
5528: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
5529: }
5530: }
5531: return ($url,$error);
5532: }
5533:
5534: sub print_coursecategories {
5535: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5536: my $datatable;
5537: if ($position eq 'top') {
5538: my (%checked);
5539: my @catitems = ('unauth','auth');
5540: my @cattypes = ('std','domonly','codesrch','none');
5541: $checked{'unauth'} = 'std';
5542: $checked{'auth'} = 'std';
5543: if (ref($settings) eq 'HASH') {
5544: foreach my $type (@cattypes) {
5545: if ($type eq $settings->{'unauth'}) {
5546: $checked{'unauth'} = $type;
5547: }
5548: if ($type eq $settings->{'auth'}) {
5549: $checked{'auth'} = $type;
5550: }
5551: }
5552: }
5553: my %lt = &Apache::lonlocal::texthash (
5554: unauth => 'Catalog type for unauthenticated users',
5555: auth => 'Catalog type for authenticated users',
5556: none => 'No catalog',
5557: std => 'Standard catalog',
5558: domonly => 'Domain-only catalog',
5559: codesrch => "Code search form",
5560: );
5561: my $itemcount = 0;
5562: foreach my $item (@catitems) {
5563: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5564: $datatable .= '<tr '.$css_class.'>'.
5565: '<td>'.$lt{$item}.'</td>'.
5566: '<td class="LC_right_item"><span class="LC_nobreak">';
5567: foreach my $type (@cattypes) {
5568: my $ischecked;
5569: if ($checked{$item} eq $type) {
5570: $ischecked=' checked="checked"';
5571: }
5572: $datatable .= '<label>'.
5573: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5574: ' />'.$lt{$type}.'</label> ';
5575: }
5576: $datatable .= '</td></tr>';
5577: $itemcount ++;
5578: }
5579: $$rowtotal += $itemcount;
5580: } elsif ($position eq 'middle') {
5581: my $toggle_cats_crs = ' ';
5582: my $toggle_cats_dom = ' checked="checked" ';
5583: my $can_cat_crs = ' ';
5584: my $can_cat_dom = ' checked="checked" ';
5585: my $toggle_catscomm_comm = ' ';
5586: my $toggle_catscomm_dom = ' checked="checked" ';
5587: my $can_catcomm_comm = ' ';
5588: my $can_catcomm_dom = ' checked="checked" ';
5589: my $toggle_catsplace_place = ' ';
5590: my $toggle_catsplace_dom = ' checked="checked" ';
5591: my $can_catplace_place = ' ';
5592: my $can_catplace_dom = ' checked="checked" ';
5593:
5594: if (ref($settings) eq 'HASH') {
5595: if ($settings->{'togglecats'} eq 'crs') {
5596: $toggle_cats_crs = $toggle_cats_dom;
5597: $toggle_cats_dom = ' ';
5598: }
5599: if ($settings->{'categorize'} eq 'crs') {
5600: $can_cat_crs = $can_cat_dom;
5601: $can_cat_dom = ' ';
5602: }
5603: if ($settings->{'togglecatscomm'} eq 'comm') {
5604: $toggle_catscomm_comm = $toggle_catscomm_dom;
5605: $toggle_catscomm_dom = ' ';
5606: }
5607: if ($settings->{'categorizecomm'} eq 'comm') {
5608: $can_catcomm_comm = $can_catcomm_dom;
5609: $can_catcomm_dom = ' ';
5610: }
5611: if ($settings->{'togglecatsplace'} eq 'place') {
5612: $toggle_catsplace_place = $toggle_catsplace_dom;
5613: $toggle_catsplace_dom = ' ';
5614: }
5615: if ($settings->{'categorizeplace'} eq 'place') {
5616: $can_catplace_place = $can_catplace_dom;
5617: $can_catplace_dom = ' ';
5618: }
5619: }
5620: my %title = &Apache::lonlocal::texthash (
5621: togglecats => 'Show/Hide a course in catalog',
5622: togglecatscomm => 'Show/Hide a community in catalog',
5623: togglecatsplace => 'Show/Hide a placement test in catalog',
5624: categorize => 'Assign a category to a course',
5625: categorizecomm => 'Assign a category to a community',
5626: categorizeplace => 'Assign a category to a placement test',
5627: );
5628: my %level = &Apache::lonlocal::texthash (
5629: dom => 'Set in Domain',
5630: crs => 'Set in Course',
5631: comm => 'Set in Community',
5632: place => 'Set in Placement Test',
5633: );
5634: $datatable = '<tr class="LC_odd_row">'.
5635: '<td>'.$title{'togglecats'}.'</td>'.
5636: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5637: '<input type="radio" name="togglecats"'.
5638: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5639: '<label><input type="radio" name="togglecats"'.
5640: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5641: '</tr><tr>'.
5642: '<td>'.$title{'categorize'}.'</td>'.
5643: '<td class="LC_right_item"><span class="LC_nobreak">'.
5644: '<label><input type="radio" name="categorize"'.
5645: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5646: '<label><input type="radio" name="categorize"'.
5647: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
5648: '</tr><tr class="LC_odd_row">'.
5649: '<td>'.$title{'togglecatscomm'}.'</td>'.
5650: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5651: '<input type="radio" name="togglecatscomm"'.
5652: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5653: '<label><input type="radio" name="togglecatscomm"'.
5654: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5655: '</tr><tr>'.
5656: '<td>'.$title{'categorizecomm'}.'</td>'.
5657: '<td class="LC_right_item"><span class="LC_nobreak">'.
5658: '<label><input type="radio" name="categorizecomm"'.
5659: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5660: '<label><input type="radio" name="categorizecomm"'.
5661: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
5662: '</tr><tr>'.
5663: '<td>'.$title{'togglecatsplace'}.'</td>'.
5664: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5665: '<input type="radio" name="togglecatsplace"'.
5666: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5667: '<label><input type="radio" name="togglecatscomm"'.
5668: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
5669: '</tr><tr>'.
5670: '<td>'.$title{'categorizeplace'}.'</td>'.
5671: '<td class="LC_right_item"><span class="LC_nobreak">'.
5672: '<label><input type="radio" name="categorizeplace"'.
5673: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5674: '<label><input type="radio" name="categorizeplace"'.
5675: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
5676: '</tr>';
5677: $$rowtotal += 6;
5678: } else {
5679: my $css_class;
5680: my $itemcount = 1;
5681: my $cathash;
5682: if (ref($settings) eq 'HASH') {
5683: $cathash = $settings->{'cats'};
5684: }
5685: if (ref($cathash) eq 'HASH') {
5686: my (@cats,@trails,%allitems,%idx,@jsarray);
5687: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5688: \%allitems,\%idx,\@jsarray);
5689: my $maxdepth = scalar(@cats);
5690: my $colattrib = '';
5691: if ($maxdepth > 2) {
5692: $colattrib = ' colspan="2" ';
5693: }
5694: my @path;
5695: if (@cats > 0) {
5696: if (ref($cats[0]) eq 'ARRAY') {
5697: my $numtop = @{$cats[0]};
5698: my $maxnum = $numtop;
5699: my %default_names = (
5700: instcode => &mt('Official courses'),
5701: communities => &mt('Communities'),
5702: placement => &mt('Placement Tests'),
5703: );
5704:
5705: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5706: ($cathash->{'instcode::0'} eq '') ||
5707: (!grep(/^communities$/,@{$cats[0]})) ||
5708: ($cathash->{'communities::0'} eq '') ||
5709: (!grep(/^placement$/,@{$cats[0]})) ||
5710: ($cathash->{'placement::0'} eq '')) {
5711: $maxnum ++;
5712: }
5713: my $lastidx;
5714: for (my $i=0; $i<$numtop; $i++) {
5715: my $parent = $cats[0][$i];
5716: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5717: my $item = &escape($parent).'::0';
5718: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5719: $lastidx = $idx{$item};
5720: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5721: .'<select name="'.$item.'"'.$chgstr.'>';
5722: for (my $k=0; $k<=$maxnum; $k++) {
5723: my $vpos = $k+1;
5724: my $selstr;
5725: if ($k == $i) {
5726: $selstr = ' selected="selected" ';
5727: }
5728: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5729: }
5730: $datatable .= '</select></span></td><td>';
5731: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
5732: $datatable .= '<span class="LC_nobreak">'
5733: .$default_names{$parent}.'</span>';
5734: if ($parent eq 'instcode') {
5735: $datatable .= '<br /><span class="LC_nobreak">('
5736: .&mt('with institutional codes')
5737: .')</span></td><td'.$colattrib.'>';
5738: } else {
5739: $datatable .= '<table><tr><td>';
5740: }
5741: $datatable .= '<span class="LC_nobreak">'
5742: .'<label><input type="radio" name="'
5743: .$parent.'" value="1" checked="checked" />'
5744: .&mt('Display').'</label>';
5745: if ($parent eq 'instcode') {
5746: $datatable .= ' ';
5747: } else {
5748: $datatable .= '</span></td></tr><tr><td>'
5749: .'<span class="LC_nobreak">';
5750: }
5751: $datatable .= '<label><input type="radio" name="'
5752: .$parent.'" value="0" />'
5753: .&mt('Do not display').'</label></span>';
5754: if (($parent eq 'communities') || ($parent eq 'placement')) {
5755: $datatable .= '</td></tr></table>';
5756: }
5757: $datatable .= '</td>';
5758: } else {
5759: $datatable .= $parent
5760: .' <span class="LC_nobreak"><label>'
5761: .'<input type="checkbox" name="deletecategory" '
5762: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5763: }
5764: my $depth = 1;
5765: push(@path,$parent);
5766: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5767: pop(@path);
5768: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5769: $itemcount ++;
5770: }
5771: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5772: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5773: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
5774: for (my $k=0; $k<=$maxnum; $k++) {
5775: my $vpos = $k+1;
5776: my $selstr;
5777: if ($k == $numtop) {
5778: $selstr = ' selected="selected" ';
5779: }
5780: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5781: }
5782: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
5783: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5784: .'</tr>'."\n";
5785: $itemcount ++;
5786: foreach my $default ('instcode','communities','placement') {
5787: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5788: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5789: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5790: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5791: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5792: for (my $k=0; $k<=$maxnum; $k++) {
5793: my $vpos = $k+1;
5794: my $selstr;
5795: if ($k == $maxnum) {
5796: $selstr = ' selected="selected" ';
5797: }
5798: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5799: }
5800: $datatable .= '</select></span></td>'.
5801: '<td><span class="LC_nobreak">'.
5802: $default_names{$default}.'</span>';
5803: if ($default eq 'instcode') {
5804: $datatable .= '<br /><span class="LC_nobreak">('
5805: .&mt('with institutional codes').')</span>';
5806: }
5807: $datatable .= '</td>'
5808: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5809: .&mt('Display').'</label> '
5810: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5811: .&mt('Do not display').'</label></span></td></tr>';
5812: }
5813: }
5814: }
5815: } else {
5816: $datatable .= &initialize_categories($itemcount);
5817: }
5818: } else {
5819: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
5820: .&initialize_categories($itemcount);
5821: }
5822: $$rowtotal += $itemcount;
5823: }
5824: return $datatable;
5825: }
5826:
5827: sub print_serverstatuses {
5828: my ($dom,$settings,$rowtotal) = @_;
5829: my $datatable;
5830: my @pages = &serverstatus_pages();
5831: my (%namedaccess,%machineaccess);
5832: foreach my $type (@pages) {
5833: $namedaccess{$type} = '';
5834: $machineaccess{$type}= '';
5835: }
5836: if (ref($settings) eq 'HASH') {
5837: foreach my $type (@pages) {
5838: if (exists($settings->{$type})) {
5839: if (ref($settings->{$type}) eq 'HASH') {
5840: foreach my $key (keys(%{$settings->{$type}})) {
5841: if ($key eq 'namedusers') {
5842: $namedaccess{$type} = $settings->{$type}->{$key};
5843: } elsif ($key eq 'machines') {
5844: $machineaccess{$type} = $settings->{$type}->{$key};
5845: }
5846: }
5847: }
5848: }
5849: }
5850: }
5851: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
5852: my $rownum = 0;
5853: my $css_class;
5854: foreach my $type (@pages) {
5855: $rownum ++;
5856: $css_class = $rownum%2?' class="LC_odd_row"':'';
5857: $datatable .= '<tr'.$css_class.'>'.
5858: '<td><span class="LC_nobreak">'.
5859: $titles->{$type}.'</span></td>'.
5860: '<td class="LC_left_item">'.
5861: '<input type="text" name="'.$type.'_namedusers" '.
5862: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5863: '<td class="LC_right_item">'.
5864: '<span class="LC_nobreak">'.
5865: '<input type="text" name="'.$type.'_machines" '.
5866: 'value="'.$machineaccess{$type}.'" size="10" />'.
5867: '</td></tr>'."\n";
5868: }
5869: $$rowtotal += $rownum;
5870: return $datatable;
5871: }
5872:
5873: sub serverstatus_pages {
5874: return ('userstatus','lonstatus','loncron','server-status','codeversions',
5875: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
5876: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
5877: 'uniquecodes','diskusage','coursecatalog');
5878: }
5879:
5880: sub defaults_javascript {
5881: my ($settings) = @_;
5882: return unless (ref($settings) eq 'HASH');
5883: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5884: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5885: if ($maxnum eq '') {
5886: $maxnum = 0;
5887: }
5888: $maxnum ++;
5889: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5890: return <<"ENDSCRIPT";
5891: <script type="text/javascript">
5892: // <![CDATA[
5893: function reorderTypes(form,caller) {
5894: var changedVal;
5895: $jstext
5896: var newpos = 'addinststatus_pos';
5897: var current = new Array;
5898: var maxh = $maxnum;
5899: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5900: var oldVal;
5901: if (caller == newpos) {
5902: changedVal = newitemVal;
5903: } else {
5904: var curritem = 'inststatus_pos_'+caller;
5905: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5906: current[newitemVal] = newpos;
5907: }
5908: for (var i=0; i<inststatuses.length; i++) {
5909: if (inststatuses[i] != caller) {
5910: var elementName = 'inststatus_pos_'+inststatuses[i];
5911: if (form.elements[elementName]) {
5912: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5913: current[currVal] = elementName;
5914: }
5915: }
5916: }
5917: for (var j=0; j<maxh; j++) {
5918: if (current[j] == undefined) {
5919: oldVal = j;
5920: }
5921: }
5922: if (oldVal < changedVal) {
5923: for (var k=oldVal+1; k<=changedVal ; k++) {
5924: var elementName = current[k];
5925: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5926: }
5927: } else {
5928: for (var k=changedVal; k<oldVal; k++) {
5929: var elementName = current[k];
5930: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5931: }
5932: }
5933: return;
5934: }
5935:
5936: // ]]>
5937: </script>
5938:
5939: ENDSCRIPT
5940: }
5941: }
5942:
5943: sub coursecategories_javascript {
5944: my ($settings) = @_;
5945: my ($output,$jstext,$cathash);
5946: if (ref($settings) eq 'HASH') {
5947: $cathash = $settings->{'cats'};
5948: }
5949: if (ref($cathash) eq 'HASH') {
5950: my (@cats,@jsarray,%idx);
5951: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
5952: if (@jsarray > 0) {
5953: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5954: for (my $i=0; $i<@jsarray; $i++) {
5955: if (ref($jsarray[$i]) eq 'ARRAY') {
5956: my $catstr = join('","',@{$jsarray[$i]});
5957: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5958: }
5959: }
5960: }
5961: } else {
5962: $jstext = ' var categories = Array(1);'."\n".
5963: ' categories[0] = Array("instcode_pos");'."\n";
5964: }
5965: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5966: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5967: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
5968: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5969: &js_escape(\$instcode_reserved);
5970: &js_escape(\$communities_reserved);
5971: &js_escape(\$placement_reserved);
5972: &js_escape(\$choose_again);
5973: $output = <<"ENDSCRIPT";
5974: <script type="text/javascript">
5975: // <![CDATA[
5976: function reorderCats(form,parent,item,idx) {
5977: var changedVal;
5978: $jstext
5979: var newpos = 'addcategory_pos';
5980: if (parent == '') {
5981: var has_instcode = 0;
5982: var maxtop = categories[idx].length;
5983: for (var j=0; j<maxtop; j++) {
5984: if (categories[idx][j] == 'instcode::0') {
5985: has_instcode == 1;
5986: }
5987: }
5988: if (has_instcode == 0) {
5989: categories[idx][maxtop] = 'instcode_pos';
5990: }
5991: } else {
5992: newpos += '_'+parent;
5993: }
5994: var maxh = 1 + categories[idx].length;
5995: var current = new Array;
5996: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5997: if (item == newpos) {
5998: changedVal = newitemVal;
5999: } else {
6000: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6001: current[newitemVal] = newpos;
6002: }
6003: for (var i=0; i<categories[idx].length; i++) {
6004: var elementName = categories[idx][i];
6005: if (elementName != item) {
6006: if (form.elements[elementName]) {
6007: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6008: current[currVal] = elementName;
6009: }
6010: }
6011: }
6012: var oldVal;
6013: for (var j=0; j<maxh; j++) {
6014: if (current[j] == undefined) {
6015: oldVal = j;
6016: }
6017: }
6018: if (oldVal < changedVal) {
6019: for (var k=oldVal+1; k<=changedVal ; k++) {
6020: var elementName = current[k];
6021: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6022: }
6023: } else {
6024: for (var k=changedVal; k<oldVal; k++) {
6025: var elementName = current[k];
6026: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6027: }
6028: }
6029: return;
6030: }
6031:
6032: function categoryCheck(form) {
6033: if (form.elements['addcategory_name'].value == 'instcode') {
6034: alert('$instcode_reserved\\n$choose_again');
6035: return false;
6036: }
6037: if (form.elements['addcategory_name'].value == 'communities') {
6038: alert('$communities_reserved\\n$choose_again');
6039: return false;
6040: }
6041: if (form.elements['addcategory_name'].value == 'placement') {
6042: alert('$placement_reserved\\n$choose_again');
6043: return false;
6044: }
6045: return true;
6046: }
6047:
6048: // ]]>
6049: </script>
6050:
6051: ENDSCRIPT
6052: return $output;
6053: }
6054:
6055: sub initialize_categories {
6056: my ($itemcount) = @_;
6057: my ($datatable,$css_class,$chgstr);
6058: my %default_names = (
6059: instcode => 'Official courses (with institutional codes)',
6060: communities => 'Communities',
6061: placement => 'Placement Tests',
6062: );
6063: my $select0 = ' selected="selected"';
6064: my $select1 = '';
6065: foreach my $default ('instcode','communities','placement') {
6066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6067: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
6068: if (($default eq 'communities') || ($default eq 'placement')) {
6069: $select1 = $select0;
6070: $select0 = '';
6071: }
6072: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6073: .'<select name="'.$default.'_pos">'
6074: .'<option value="0"'.$select0.'>1</option>'
6075: .'<option value="1"'.$select1.'>2</option>'
6076: .'<option value="2">3</option></select> '
6077: .$default_names{$default}
6078: .'</span></td><td><span class="LC_nobreak">'
6079: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6080: .&mt('Display').'</label> <label>'
6081: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
6082: .'</label></span></td></tr>';
6083: $itemcount ++;
6084: }
6085: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6086: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
6087: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6088: .'<select name="addcategory_pos"'.$chgstr.'>'
6089: .'<option value="0">1</option>'
6090: .'<option value="1">2</option>'
6091: .'<option value="2" selected="selected">3</option></select> '
6092: .&mt('Add category').'</td><td>'.&mt('Name:')
6093: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6094: return $datatable;
6095: }
6096:
6097: sub build_category_rows {
6098: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6099: my ($text,$name,$item,$chgstr);
6100: if (ref($cats) eq 'ARRAY') {
6101: my $maxdepth = scalar(@{$cats});
6102: if (ref($cats->[$depth]) eq 'HASH') {
6103: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6104: my $numchildren = @{$cats->[$depth]{$parent}};
6105: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6106: $text .= '<td><table class="LC_data_table">';
6107: my ($idxnum,$parent_name,$parent_item);
6108: my $higher = $depth - 1;
6109: if ($higher == 0) {
6110: $parent_name = &escape($parent).'::'.$higher;
6111: } else {
6112: if (ref($path) eq 'ARRAY') {
6113: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6114: }
6115: }
6116: $parent_item = 'addcategory_pos_'.$parent_name;
6117: for (my $j=0; $j<=$numchildren; $j++) {
6118: if ($j < $numchildren) {
6119: $name = $cats->[$depth]{$parent}[$j];
6120: $item = &escape($name).':'.&escape($parent).':'.$depth;
6121: $idxnum = $idx->{$item};
6122: } else {
6123: $name = $parent_name;
6124: $item = $parent_item;
6125: }
6126: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6127: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
6128: for (my $i=0; $i<=$numchildren; $i++) {
6129: my $vpos = $i+1;
6130: my $selstr;
6131: if ($j == $i) {
6132: $selstr = ' selected="selected" ';
6133: }
6134: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6135: }
6136: $text .= '</select> ';
6137: if ($j < $numchildren) {
6138: my $deeper = $depth+1;
6139: $text .= $name.' '
6140: .'<label><input type="checkbox" name="deletecategory" value="'
6141: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6142: if(ref($path) eq 'ARRAY') {
6143: push(@{$path},$name);
6144: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
6145: pop(@{$path});
6146: }
6147: } else {
6148: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
6149: if ($j == $numchildren) {
6150: $text .= $name;
6151: } else {
6152: $text .= $item;
6153: }
6154: $text .= '" value="" />';
6155: }
6156: $text .= '</td></tr>';
6157: }
6158: $text .= '</table></td>';
6159: } else {
6160: my $higher = $depth-1;
6161: if ($higher == 0) {
6162: $name = &escape($parent).'::'.$higher;
6163: } else {
6164: if (ref($path) eq 'ARRAY') {
6165: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6166: }
6167: }
6168: my $colspan;
6169: if ($parent ne 'instcode') {
6170: $colspan = $maxdepth - $depth - 1;
6171: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6172: }
6173: }
6174: }
6175: }
6176: return $text;
6177: }
6178:
6179: sub modifiable_userdata_row {
6180: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6181: my ($role,$rolename,$statustype);
6182: $role = $item;
6183: if ($context eq 'cancreate') {
6184: if ($item =~ /^emailusername_(.+)$/) {
6185: $statustype = $1;
6186: $role = 'emailusername';
6187: if (ref($usertypes) eq 'HASH') {
6188: if ($usertypes->{$statustype}) {
6189: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6190: } else {
6191: $rolename = &mt('Data provided by user');
6192: }
6193: }
6194: }
6195: } elsif ($context eq 'selfcreate') {
6196: if (ref($usertypes) eq 'HASH') {
6197: $rolename = $usertypes->{$role};
6198: } else {
6199: $rolename = $role;
6200: }
6201: } else {
6202: if ($role eq 'cr') {
6203: $rolename = &mt('Custom role');
6204: } else {
6205: $rolename = &Apache::lonnet::plaintext($role);
6206: }
6207: }
6208: my (@fields,%fieldtitles);
6209: if (ref($fieldsref) eq 'ARRAY') {
6210: @fields = @{$fieldsref};
6211: } else {
6212: @fields = ('lastname','firstname','middlename','generation',
6213: 'permanentemail','id');
6214: }
6215: if ((ref($titlesref) eq 'HASH')) {
6216: %fieldtitles = %{$titlesref};
6217: } else {
6218: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6219: }
6220: my $output;
6221: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6222: $output = '<tr '.$css_class.'>'.
6223: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6224: '<td class="LC_left_item" colspan="2"><table>';
6225: my $rem;
6226: my %checks;
6227: if (ref($settings) eq 'HASH') {
6228: if (ref($settings->{$context}) eq 'HASH') {
6229: if (ref($settings->{$context}->{$role}) eq 'HASH') {
6230: my $hashref = $settings->{$context}->{$role};
6231: if ($role eq 'emailusername') {
6232: if ($statustype) {
6233: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6234: $hashref = $settings->{$context}->{$role}->{$statustype};
6235: if (ref($hashref) eq 'HASH') {
6236: foreach my $field (@fields) {
6237: if ($hashref->{$field}) {
6238: $checks{$field} = $hashref->{$field};
6239: }
6240: }
6241: }
6242: }
6243: }
6244: } else {
6245: if (ref($hashref) eq 'HASH') {
6246: foreach my $field (@fields) {
6247: if ($hashref->{$field}) {
6248: $checks{$field} = ' checked="checked" ';
6249: }
6250: }
6251: }
6252: }
6253: }
6254: }
6255: }
6256:
6257: for (my $i=0; $i<@fields; $i++) {
6258: my $rem = $i%($numinrow);
6259: if ($rem == 0) {
6260: if ($i > 0) {
6261: $output .= '</tr>';
6262: }
6263: $output .= '<tr>';
6264: }
6265: my $check = ' ';
6266: unless ($role eq 'emailusername') {
6267: if (exists($checks{$fields[$i]})) {
6268: $check = $checks{$fields[$i]}
6269: } else {
6270: if ($role eq 'st') {
6271: if (ref($settings) ne 'HASH') {
6272: $check = ' checked="checked" ';
6273: }
6274: }
6275: }
6276: }
6277: $output .= '<td class="LC_left_item">'.
6278: '<span class="LC_nobreak">';
6279: if ($role eq 'emailusername') {
6280: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6281: $checks{$fields[$i]} = 'omit';
6282: }
6283: foreach my $option ('required','optional','omit') {
6284: my $checked='';
6285: if ($checks{$fields[$i]} eq $option) {
6286: $checked='checked="checked" ';
6287: }
6288: $output .= '<label>'.
6289: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6290: &mt($option).'</label>'.(' ' x2);
6291: }
6292: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6293: } else {
6294: $output .= '<label>'.
6295: '<input type="checkbox" name="canmodify_'.$role.'" '.
6296: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6297: '</label>';
6298: }
6299: $output .= '</span></td>';
6300: $rem = @fields%($numinrow);
6301: }
6302: my $colsleft = $numinrow - $rem;
6303: if ($colsleft > 1 ) {
6304: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6305: ' </td>';
6306: } elsif ($colsleft == 1) {
6307: $output .= '<td class="LC_left_item"> </td>';
6308: }
6309: $output .= '</tr></table></td></tr>';
6310: return $output;
6311: }
6312:
6313: sub insttypes_row {
6314: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
6315: my %lt = &Apache::lonlocal::texthash (
6316: cansearch => 'Users allowed to search',
6317: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
6318: lockablenames => 'User preference to lock name',
6319: );
6320: my $showdom;
6321: if ($context eq 'cansearch') {
6322: $showdom = ' ('.$dom.')';
6323: }
6324: my $class = 'LC_left_item';
6325: if ($context eq 'statustocreate') {
6326: $class = 'LC_right_item';
6327: }
6328: my $css_class = ' class="LC_odd_row"';
6329: if ($rownum ne '') {
6330: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6331: }
6332: my $output = '<tr'.$css_class.'>'.
6333: '<td>'.$lt{$context}.$showdom.
6334: '</td><td class="'.$class.'" colspan="2"><table>';
6335: my $rem;
6336: if (ref($types) eq 'ARRAY') {
6337: for (my $i=0; $i<@{$types}; $i++) {
6338: if (defined($usertypes->{$types->[$i]})) {
6339: my $rem = $i%($numinrow);
6340: if ($rem == 0) {
6341: if ($i > 0) {
6342: $output .= '</tr>';
6343: }
6344: $output .= '<tr>';
6345: }
6346: my $check = ' ';
6347: if (ref($settings) eq 'HASH') {
6348: if (ref($settings->{$context}) eq 'ARRAY') {
6349: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6350: $check = ' checked="checked" ';
6351: }
6352: } elsif ($context eq 'statustocreate') {
6353: $check = ' checked="checked" ';
6354: }
6355: }
6356: $output .= '<td class="LC_left_item">'.
6357: '<span class="LC_nobreak"><label>'.
6358: '<input type="checkbox" name="'.$context.'" '.
6359: 'value="'.$types->[$i].'"'.$check.'/>'.
6360: $usertypes->{$types->[$i]}.'</label></span></td>';
6361: }
6362: }
6363: $rem = @{$types}%($numinrow);
6364: }
6365: my $colsleft = $numinrow - $rem;
6366: if (($rem == 0) && (@{$types} > 0)) {
6367: $output .= '<tr>';
6368: }
6369: if ($colsleft > 1) {
6370: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6371: } else {
6372: $output .= '<td class="LC_left_item">';
6373: }
6374: my $defcheck = ' ';
6375: if (ref($settings) eq 'HASH') {
6376: if (ref($settings->{$context}) eq 'ARRAY') {
6377: if (grep(/^default$/,@{$settings->{$context}})) {
6378: $defcheck = ' checked="checked" ';
6379: }
6380: } elsif ($context eq 'statustocreate') {
6381: $defcheck = ' checked="checked" ';
6382: }
6383: }
6384: $output .= '<span class="LC_nobreak"><label>'.
6385: '<input type="checkbox" name="'.$context.'" '.
6386: 'value="default"'.$defcheck.'/>'.
6387: $othertitle.'</label></span></td>'.
6388: '</tr></table></td></tr>';
6389: return $output;
6390: }
6391:
6392: sub sorted_searchtitles {
6393: my %searchtitles = &Apache::lonlocal::texthash(
6394: 'uname' => 'username',
6395: 'lastname' => 'last name',
6396: 'lastfirst' => 'last name, first name',
6397: );
6398: my @titleorder = ('uname','lastname','lastfirst');
6399: return (\%searchtitles,\@titleorder);
6400: }
6401:
6402: sub sorted_searchtypes {
6403: my %srchtypes_desc = (
6404: exact => 'is exact match',
6405: contains => 'contains ..',
6406: begins => 'begins with ..',
6407: );
6408: my @srchtypeorder = ('exact','begins','contains');
6409: return (\%srchtypes_desc,\@srchtypeorder);
6410: }
6411:
6412: sub usertype_update_row {
6413: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6414: my $datatable;
6415: my $numinrow = 4;
6416: foreach my $type (@{$types}) {
6417: if (defined($usertypes->{$type})) {
6418: $$rownums ++;
6419: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6420: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6421: '</td><td class="LC_left_item"><table>';
6422: for (my $i=0; $i<@{$fields}; $i++) {
6423: my $rem = $i%($numinrow);
6424: if ($rem == 0) {
6425: if ($i > 0) {
6426: $datatable .= '</tr>';
6427: }
6428: $datatable .= '<tr>';
6429: }
6430: my $check = ' ';
6431: if (ref($settings) eq 'HASH') {
6432: if (ref($settings->{'fields'}) eq 'HASH') {
6433: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6434: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6435: $check = ' checked="checked" ';
6436: }
6437: }
6438: }
6439: }
6440:
6441: if ($i == @{$fields}-1) {
6442: my $colsleft = $numinrow - $rem;
6443: if ($colsleft > 1) {
6444: $datatable .= '<td colspan="'.$colsleft.'">';
6445: } else {
6446: $datatable .= '<td>';
6447: }
6448: } else {
6449: $datatable .= '<td>';
6450: }
6451: $datatable .= '<span class="LC_nobreak"><label>'.
6452: '<input type="checkbox" name="updateable_'.$type.
6453: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6454: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
6455: }
6456: $datatable .= '</tr></table></td></tr>';
6457: }
6458: }
6459: return $datatable;
6460: }
6461:
6462: sub modify_login {
6463: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
6464: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6465: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6466: %title = ( coursecatalog => 'Display course catalog',
6467: adminmail => 'Display administrator E-mail address',
6468: helpdesk => 'Display "Contact Helpdesk" link',
6469: newuser => 'Link for visitors to create a user account',
6470: loginheader => 'Log-in box header');
6471: @offon = ('off','on');
6472: if (ref($domconfig{login}) eq 'HASH') {
6473: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6474: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6475: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6476: }
6477: }
6478: }
6479: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6480: \%domconfig,\%loginhash);
6481: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
6482: foreach my $item (@toggles) {
6483: $loginhash{login}{$item} = $env{'form.'.$item};
6484: }
6485: $loginhash{login}{loginheader} = $env{'form.loginheader'};
6486: if (ref($colchanges{'login'}) eq 'HASH') {
6487: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6488: \%loginhash);
6489: }
6490:
6491: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6492: my %domservers = &Apache::lonnet::get_servers($dom);
6493: my @loginvia_attribs = ('serverpath','custompath','exempt');
6494: if (keys(%servers) > 1) {
6495: foreach my $lonhost (keys(%servers)) {
6496: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6497: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6498: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6499: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6500: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6501: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6502: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6503: $changes{'loginvia'}{$lonhost} = 1;
6504: } else {
6505: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6506: $changes{'loginvia'}{$lonhost} = 1;
6507: }
6508: } else {
6509: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6510: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6511: $changes{'loginvia'}{$lonhost} = 1;
6512: }
6513: }
6514: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6515: foreach my $item (@loginvia_attribs) {
6516: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6517: }
6518: } else {
6519: foreach my $item (@loginvia_attribs) {
6520: my $new = $env{'form.'.$lonhost.'_'.$item};
6521: if (($item eq 'serverpath') && ($new eq 'custom')) {
6522: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6523: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6524: $new = '/';
6525: }
6526: }
6527: if (($item eq 'custompath') &&
6528: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6529: $new = '';
6530: }
6531: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6532: $changes{'loginvia'}{$lonhost} = 1;
6533: }
6534: if ($item eq 'exempt') {
6535: $new = &check_exempt_addresses($new);
6536: }
6537: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6538: }
6539: }
6540: } else {
6541: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6542: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6543: $changes{'loginvia'}{$lonhost} = 1;
6544: foreach my $item (@loginvia_attribs) {
6545: my $new = $env{'form.'.$lonhost.'_'.$item};
6546: if (($item eq 'serverpath') && ($new eq 'custom')) {
6547: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6548: $new = '/';
6549: }
6550: }
6551: if (($item eq 'custompath') &&
6552: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6553: $new = '';
6554: }
6555: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6556: }
6557: }
6558: }
6559: }
6560: }
6561:
6562: my $servadm = $r->dir_config('lonAdmEMail');
6563: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6564: if (ref($domconfig{'login'}) eq 'HASH') {
6565: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6566: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6567: if ($lang eq 'nolang') {
6568: push(@currlangs,$lang);
6569: } elsif (defined($langchoices{$lang})) {
6570: push(@currlangs,$lang);
6571: } else {
6572: next;
6573: }
6574: }
6575: }
6576: }
6577: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6578: if (@currlangs > 0) {
6579: foreach my $lang (@currlangs) {
6580: if (grep(/^\Q$lang\E$/,@delurls)) {
6581: $changes{'helpurl'}{$lang} = 1;
6582: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6583: $changes{'helpurl'}{$lang} = 1;
6584: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6585: push(@newlangs,$lang);
6586: } else {
6587: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6588: }
6589: }
6590: }
6591: unless (grep(/^nolang$/,@currlangs)) {
6592: if ($env{'form.loginhelpurl_nolang.filename'}) {
6593: $changes{'helpurl'}{'nolang'} = 1;
6594: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6595: push(@newlangs,'nolang');
6596: }
6597: }
6598: if ($env{'form.loginhelpurl_add_lang'}) {
6599: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6600: ($env{'form.loginhelpurl_add_file.filename'})) {
6601: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6602: $addedfile = $env{'form.loginhelpurl_add_lang'};
6603: }
6604: }
6605: if ((@newlangs > 0) || ($addedfile)) {
6606: my $error;
6607: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6608: if ($configuserok eq 'ok') {
6609: if ($switchserver) {
6610: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6611: } elsif ($author_ok eq 'ok') {
6612: my @allnew = @newlangs;
6613: if ($addedfile ne '') {
6614: push(@allnew,$addedfile);
6615: }
6616: foreach my $lang (@allnew) {
6617: my $formelem = 'loginhelpurl_'.$lang;
6618: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6619: $formelem = 'loginhelpurl_add_file';
6620: }
6621: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6622: "help/$lang",'','',$newfile{$lang});
6623: if ($result eq 'ok') {
6624: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6625: $changes{'helpurl'}{$lang} = 1;
6626: } else {
6627: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6628: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6629: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6630: (!grep(/^\Q$lang\E$/,@delurls))) {
6631: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6632: }
6633: }
6634: }
6635: } else {
6636: $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);
6637: }
6638: } else {
6639: $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);
6640: }
6641: if ($error) {
6642: &Apache::lonnet::logthis($error);
6643: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6644: }
6645: }
6646:
6647: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6648: if (ref($domconfig{'login'}) eq 'HASH') {
6649: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6650: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6651: if ($domservers{$lonhost}) {
6652: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6653: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
6654: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
6655: }
6656: }
6657: }
6658: }
6659: }
6660: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6661: foreach my $lonhost (sort(keys(%domservers))) {
6662: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6663: $changes{'headtag'}{$lonhost} = 1;
6664: } else {
6665: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6666: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6667: }
6668: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6669: push(@newhosts,$lonhost);
6670: } elsif ($currheadtagurls{$lonhost}) {
6671: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6672: if ($currexempt{$lonhost}) {
6673: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6674: $changes{'headtag'}{$lonhost} = 1;
6675: }
6676: } elsif ($possexempt{$lonhost}) {
6677: $changes{'headtag'}{$lonhost} = 1;
6678: }
6679: if ($possexempt{$lonhost}) {
6680: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6681: }
6682: }
6683: }
6684: }
6685: if (@newhosts) {
6686: my $error;
6687: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6688: if ($configuserok eq 'ok') {
6689: if ($switchserver) {
6690: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6691: } elsif ($author_ok eq 'ok') {
6692: foreach my $lonhost (@newhosts) {
6693: my $formelem = 'loginheadtag_'.$lonhost;
6694: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6695: "login/headtag/$lonhost",'','',
6696: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6697: if ($result eq 'ok') {
6698: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6699: $changes{'headtag'}{$lonhost} = 1;
6700: if ($possexempt{$lonhost}) {
6701: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6702: }
6703: } else {
6704: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6705: $newheadtagurls{$lonhost},$result);
6706: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6707: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6708: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6709: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6710: }
6711: }
6712: }
6713: } else {
6714: $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);
6715: }
6716: } else {
6717: $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);
6718: }
6719: if ($error) {
6720: &Apache::lonnet::logthis($error);
6721: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6722: }
6723: }
6724: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6725:
6726: my $defaulthelpfile = '/adm/loginproblems.html';
6727: my $defaulttext = &mt('Default in use');
6728:
6729: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6730: $dom);
6731: if ($putresult eq 'ok') {
6732: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
6733: my %defaultchecked = (
6734: 'coursecatalog' => 'on',
6735: 'helpdesk' => 'on',
6736: 'adminmail' => 'off',
6737: 'newuser' => 'off',
6738: );
6739: if (ref($domconfig{'login'}) eq 'HASH') {
6740: foreach my $item (@toggles) {
6741: if ($defaultchecked{$item} eq 'on') {
6742: if (($domconfig{'login'}{$item} eq '0') &&
6743: ($env{'form.'.$item} eq '1')) {
6744: $changes{$item} = 1;
6745: } elsif (($domconfig{'login'}{$item} eq '' ||
6746: $domconfig{'login'}{$item} eq '1') &&
6747: ($env{'form.'.$item} eq '0')) {
6748: $changes{$item} = 1;
6749: }
6750: } elsif ($defaultchecked{$item} eq 'off') {
6751: if (($domconfig{'login'}{$item} eq '1') &&
6752: ($env{'form.'.$item} eq '0')) {
6753: $changes{$item} = 1;
6754: } elsif (($domconfig{'login'}{$item} eq '' ||
6755: $domconfig{'login'}{$item} eq '0') &&
6756: ($env{'form.'.$item} eq '1')) {
6757: $changes{$item} = 1;
6758: }
6759: }
6760: }
6761: }
6762: if (keys(%changes) > 0 || $colchgtext) {
6763: &Apache::loncommon::devalidate_domconfig_cache($dom);
6764: if (ref($lastactref) eq 'HASH') {
6765: $lastactref->{'domainconfig'} = 1;
6766: }
6767: $resulttext = &mt('Changes made:').'<ul>';
6768: foreach my $item (sort(keys(%changes))) {
6769: if ($item eq 'loginvia') {
6770: if (ref($changes{$item}) eq 'HASH') {
6771: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6772: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6773: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6774: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6775: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6776: $protocol = 'http' if ($protocol ne 'https');
6777: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6778:
6779: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6780: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6781: } else {
6782: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6783: }
6784: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6785: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6786: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6787: }
6788: $resulttext .= '</li>';
6789: } else {
6790: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6791: }
6792: } else {
6793: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
6794: }
6795: }
6796: $resulttext .= '</ul></li>';
6797: }
6798: } elsif ($item eq 'helpurl') {
6799: if (ref($changes{$item}) eq 'HASH') {
6800: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6801: if (grep(/^\Q$lang\E$/,@delurls)) {
6802: my ($chg,$link);
6803: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6804: if ($lang eq 'nolang') {
6805: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6806: } else {
6807: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6808: }
6809: $resulttext .= '<li>'.$chg.'</li>';
6810: } else {
6811: my $chg;
6812: if ($lang eq 'nolang') {
6813: $chg = &mt('custom log-in help file for no preferred language');
6814: } else {
6815: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6816: }
6817: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6818: $loginhash{'login'}{'helpurl'}{$lang}.
6819: '?inhibitmenu=yes',$chg,600,500).
6820: '</li>';
6821: }
6822: }
6823: }
6824: } elsif ($item eq 'headtag') {
6825: if (ref($changes{$item}) eq 'HASH') {
6826: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6827: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6828: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6829: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6830: $resulttext .= '<li><a href="'.
6831: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6832: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6833: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6834: if ($possexempt{$lonhost}) {
6835: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6836: } else {
6837: $resulttext .= &mt('included for any client IP');
6838: }
6839: $resulttext .= '</li>';
6840: }
6841: }
6842: }
6843: } elsif ($item eq 'captcha') {
6844: if (ref($loginhash{'login'}) eq 'HASH') {
6845: my $chgtxt;
6846: if ($loginhash{'login'}{$item} eq 'notused') {
6847: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6848: } else {
6849: my %captchas = &captcha_phrases();
6850: if ($captchas{$loginhash{'login'}{$item}}) {
6851: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6852: } else {
6853: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6854: }
6855: }
6856: $resulttext .= '<li>'.$chgtxt.'</li>';
6857: }
6858: } elsif ($item eq 'recaptchakeys') {
6859: if (ref($loginhash{'login'}) eq 'HASH') {
6860: my ($privkey,$pubkey);
6861: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6862: $pubkey = $loginhash{'login'}{$item}{'public'};
6863: $privkey = $loginhash{'login'}{$item}{'private'};
6864: }
6865: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6866: if (!$pubkey) {
6867: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6868: } else {
6869: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6870: }
6871: if (!$privkey) {
6872: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6873: } else {
6874: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
6875: }
6876: $chgtxt .= '</ul>';
6877: $resulttext .= '<li>'.$chgtxt.'</li>';
6878: }
6879: } elsif ($item eq 'recaptchaversion') {
6880: if (ref($loginhash{'login'}) eq 'HASH') {
6881: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
6882: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
6883: '</li>';
6884: }
6885: }
6886: } else {
6887: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6888: }
6889: }
6890: $resulttext .= $colchgtext.'</ul>';
6891: } else {
6892: $resulttext = &mt('No changes made to log-in page settings');
6893: }
6894: } else {
6895: $resulttext = '<span class="LC_error">'.
6896: &mt('An error occurred: [_1]',$putresult).'</span>';
6897: }
6898: if ($errors) {
6899: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
6900: $errors.'</ul>';
6901: }
6902: return $resulttext;
6903: }
6904:
6905:
6906: sub check_exempt_addresses {
6907: my ($iplist) = @_;
6908: $iplist =~ s/^\s+//;
6909: $iplist =~ s/\s+$//;
6910: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6911: my (@okips,$new);
6912: foreach my $ip (@poss_ips) {
6913: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6914: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6915: push(@okips,$ip);
6916: }
6917: }
6918: }
6919: if (@okips > 0) {
6920: $new = join(',',@okips);
6921: } else {
6922: $new = '';
6923: }
6924: return $new;
6925: }
6926:
6927: sub color_font_choices {
6928: my %choices =
6929: &Apache::lonlocal::texthash (
6930: img => "Header",
6931: bgs => "Background colors",
6932: links => "Link colors",
6933: images => "Images",
6934: font => "Font color",
6935: fontmenu => "Font menu",
6936: pgbg => "Page",
6937: tabbg => "Header",
6938: sidebg => "Border",
6939: link => "Link",
6940: alink => "Active link",
6941: vlink => "Visited link",
6942: );
6943: return %choices;
6944: }
6945:
6946: sub modify_rolecolors {
6947: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
6948: my ($resulttext,%rolehash);
6949: $rolehash{'rolecolors'} = {};
6950: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6951: if ($domconfig{'rolecolors'} eq '') {
6952: $domconfig{'rolecolors'} = {};
6953: }
6954: }
6955: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
6956: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6957: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6958: $dom);
6959: if ($putresult eq 'ok') {
6960: if (keys(%changes) > 0) {
6961: &Apache::loncommon::devalidate_domconfig_cache($dom);
6962: if (ref($lastactref) eq 'HASH') {
6963: $lastactref->{'domainconfig'} = 1;
6964: }
6965: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6966: $rolehash{'rolecolors'});
6967: } else {
6968: $resulttext = &mt('No changes made to default color schemes');
6969: }
6970: } else {
6971: $resulttext = '<span class="LC_error">'.
6972: &mt('An error occurred: [_1]',$putresult).'</span>';
6973: }
6974: if ($errors) {
6975: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6976: $errors.'</ul>';
6977: }
6978: return $resulttext;
6979: }
6980:
6981: sub modify_colors {
6982: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
6983: my (%changes,%choices);
6984: my @bgs;
6985: my @links = ('link','alink','vlink');
6986: my @logintext;
6987: my @images;
6988: my $servadm = $r->dir_config('lonAdmEMail');
6989: my $errors;
6990: my %defaults;
6991: foreach my $role (@{$roles}) {
6992: if ($role eq 'login') {
6993: %choices = &login_choices();
6994: @logintext = ('textcol','bgcol');
6995: } else {
6996: %choices = &color_font_choices();
6997: }
6998: if ($role eq 'login') {
6999: @images = ('img','logo','domlogo','login');
7000: @bgs = ('pgbg','mainbg','sidebg');
7001: } else {
7002: @images = ('img');
7003: @bgs = ('pgbg','tabbg','sidebg');
7004: }
7005: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7006: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7007: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7008: }
7009: if ($role eq 'login') {
7010: foreach my $item (@logintext) {
7011: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7012: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7013: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7014: }
7015: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
7016: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7017: }
7018: }
7019: } else {
7020: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7021: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7022: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7023: }
7024: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
7025: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7026: }
7027: }
7028: foreach my $item (@bgs) {
7029: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7030: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7031: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7032: }
7033: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
7034: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7035: }
7036: }
7037: foreach my $item (@links) {
7038: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7039: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7040: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7041: }
7042: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
7043: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7044: }
7045: }
7046: my ($configuserok,$author_ok,$switchserver) =
7047: &config_check($dom,$confname,$servadm);
7048: my ($width,$height) = &thumb_dimensions();
7049: if (ref($domconfig->{$role}) ne 'HASH') {
7050: $domconfig->{$role} = {};
7051: }
7052: foreach my $img (@images) {
7053: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7054: if (defined($env{'form.login_showlogo_'.$img})) {
7055: $confhash->{$role}{'showlogo'}{$img} = 1;
7056: } else {
7057: $confhash->{$role}{'showlogo'}{$img} = 0;
7058: }
7059: }
7060: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7061: && !defined($domconfig->{$role}{$img})
7062: && !$env{'form.'.$role.'_del_'.$img}
7063: && $env{'form.'.$role.'_import_'.$img}) {
7064: # import the old configured image from the .tab setting
7065: # if they haven't provided a new one
7066: $domconfig->{$role}{$img} =
7067: $env{'form.'.$role.'_import_'.$img};
7068: }
7069: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
7070: my $error;
7071: if ($configuserok eq 'ok') {
7072: if ($switchserver) {
7073: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
7074: } else {
7075: if ($author_ok eq 'ok') {
7076: my ($result,$logourl) =
7077: &publishlogo($r,'upload',$role.'_'.$img,
7078: $dom,$confname,$img,$width,$height);
7079: if ($result eq 'ok') {
7080: $confhash->{$role}{$img} = $logourl;
7081: $changes{$role}{'images'}{$img} = 1;
7082: } else {
7083: $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);
7084: }
7085: } else {
7086: $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);
7087: }
7088: }
7089: } else {
7090: $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);
7091: }
7092: if ($error) {
7093: &Apache::lonnet::logthis($error);
7094: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7095: }
7096: } elsif ($domconfig->{$role}{$img} ne '') {
7097: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7098: my $error;
7099: if ($configuserok eq 'ok') {
7100: # is confname an author?
7101: if ($switchserver eq '') {
7102: if ($author_ok eq 'ok') {
7103: my ($result,$logourl) =
7104: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7105: $dom,$confname,$img,$width,$height);
7106: if ($result eq 'ok') {
7107: $confhash->{$role}{$img} = $logourl;
7108: $changes{$role}{'images'}{$img} = 1;
7109: }
7110: }
7111: }
7112: }
7113: }
7114: }
7115: }
7116: if (ref($domconfig) eq 'HASH') {
7117: if (ref($domconfig->{$role}) eq 'HASH') {
7118: foreach my $img (@images) {
7119: if ($domconfig->{$role}{$img} ne '') {
7120: if ($env{'form.'.$role.'_del_'.$img}) {
7121: $confhash->{$role}{$img} = '';
7122: $changes{$role}{'images'}{$img} = 1;
7123: } else {
7124: if ($confhash->{$role}{$img} eq '') {
7125: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7126: }
7127: }
7128: } else {
7129: if ($env{'form.'.$role.'_del_'.$img}) {
7130: $confhash->{$role}{$img} = '';
7131: $changes{$role}{'images'}{$img} = 1;
7132: }
7133: }
7134: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7135: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7136: if ($confhash->{$role}{'showlogo'}{$img} ne
7137: $domconfig->{$role}{'showlogo'}{$img}) {
7138: $changes{$role}{'showlogo'}{$img} = 1;
7139: }
7140: } else {
7141: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7142: $changes{$role}{'showlogo'}{$img} = 1;
7143: }
7144: }
7145: }
7146: }
7147: if ($domconfig->{$role}{'font'} ne '') {
7148: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7149: $changes{$role}{'font'} = 1;
7150: }
7151: } else {
7152: if ($confhash->{$role}{'font'}) {
7153: $changes{$role}{'font'} = 1;
7154: }
7155: }
7156: if ($role ne 'login') {
7157: if ($domconfig->{$role}{'fontmenu'} ne '') {
7158: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7159: $changes{$role}{'fontmenu'} = 1;
7160: }
7161: } else {
7162: if ($confhash->{$role}{'fontmenu'}) {
7163: $changes{$role}{'fontmenu'} = 1;
7164: }
7165: }
7166: }
7167: foreach my $item (@bgs) {
7168: if ($domconfig->{$role}{$item} ne '') {
7169: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7170: $changes{$role}{'bgs'}{$item} = 1;
7171: }
7172: } else {
7173: if ($confhash->{$role}{$item}) {
7174: $changes{$role}{'bgs'}{$item} = 1;
7175: }
7176: }
7177: }
7178: foreach my $item (@links) {
7179: if ($domconfig->{$role}{$item} ne '') {
7180: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7181: $changes{$role}{'links'}{$item} = 1;
7182: }
7183: } else {
7184: if ($confhash->{$role}{$item}) {
7185: $changes{$role}{'links'}{$item} = 1;
7186: }
7187: }
7188: }
7189: foreach my $item (@logintext) {
7190: if ($domconfig->{$role}{$item} ne '') {
7191: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7192: $changes{$role}{'logintext'}{$item} = 1;
7193: }
7194: } else {
7195: if ($confhash->{$role}{$item}) {
7196: $changes{$role}{'logintext'}{$item} = 1;
7197: }
7198: }
7199: }
7200: } else {
7201: &default_change_checker($role,\@images,\@links,\@bgs,
7202: \@logintext,$confhash,\%changes);
7203: }
7204: } else {
7205: &default_change_checker($role,\@images,\@links,\@bgs,
7206: \@logintext,$confhash,\%changes);
7207: }
7208: }
7209: return ($errors,%changes);
7210: }
7211:
7212: sub config_check {
7213: my ($dom,$confname,$servadm) = @_;
7214: my ($configuserok,$author_ok,$switchserver,%currroles);
7215: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7216: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7217: $confname,$servadm);
7218: if ($configuserok eq 'ok') {
7219: $switchserver = &check_switchserver($dom,$confname);
7220: if ($switchserver eq '') {
7221: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7222: }
7223: }
7224: return ($configuserok,$author_ok,$switchserver);
7225: }
7226:
7227: sub default_change_checker {
7228: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
7229: foreach my $item (@{$links}) {
7230: if ($confhash->{$role}{$item}) {
7231: $changes->{$role}{'links'}{$item} = 1;
7232: }
7233: }
7234: foreach my $item (@{$bgs}) {
7235: if ($confhash->{$role}{$item}) {
7236: $changes->{$role}{'bgs'}{$item} = 1;
7237: }
7238: }
7239: foreach my $item (@{$logintext}) {
7240: if ($confhash->{$role}{$item}) {
7241: $changes->{$role}{'logintext'}{$item} = 1;
7242: }
7243: }
7244: foreach my $img (@{$images}) {
7245: if ($env{'form.'.$role.'_del_'.$img}) {
7246: $confhash->{$role}{$img} = '';
7247: $changes->{$role}{'images'}{$img} = 1;
7248: }
7249: if ($role eq 'login') {
7250: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7251: $changes->{$role}{'showlogo'}{$img} = 1;
7252: }
7253: }
7254: }
7255: if ($confhash->{$role}{'font'}) {
7256: $changes->{$role}{'font'} = 1;
7257: }
7258: }
7259:
7260: sub display_colorchgs {
7261: my ($dom,$changes,$roles,$confhash) = @_;
7262: my (%choices,$resulttext);
7263: if (!grep(/^login$/,@{$roles})) {
7264: $resulttext = &mt('Changes made:').'<br />';
7265: }
7266: foreach my $role (@{$roles}) {
7267: if ($role eq 'login') {
7268: %choices = &login_choices();
7269: } else {
7270: %choices = &color_font_choices();
7271: }
7272: if (ref($changes->{$role}) eq 'HASH') {
7273: if ($role ne 'login') {
7274: $resulttext .= '<h4>'.&mt($role).'</h4>';
7275: }
7276: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7277: if ($role ne 'login') {
7278: $resulttext .= '<ul>';
7279: }
7280: if (ref($changes->{$role}{$key}) eq 'HASH') {
7281: if ($role ne 'login') {
7282: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7283: }
7284: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
7285: if (($role eq 'login') && ($key eq 'showlogo')) {
7286: if ($confhash->{$role}{$key}{$item}) {
7287: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7288: } else {
7289: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7290: }
7291: } elsif ($confhash->{$role}{$item} eq '') {
7292: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7293: } else {
7294: my $newitem = $confhash->{$role}{$item};
7295: if ($key eq 'images') {
7296: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7297: }
7298: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
7299: }
7300: }
7301: if ($role ne 'login') {
7302: $resulttext .= '</ul></li>';
7303: }
7304: } else {
7305: if ($confhash->{$role}{$key} eq '') {
7306: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7307: } else {
7308: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7309: }
7310: }
7311: if ($role ne 'login') {
7312: $resulttext .= '</ul>';
7313: }
7314: }
7315: }
7316: }
7317: return $resulttext;
7318: }
7319:
7320: sub thumb_dimensions {
7321: return ('200','50');
7322: }
7323:
7324: sub check_dimensions {
7325: my ($inputfile) = @_;
7326: my ($fullwidth,$fullheight);
7327: if ($inputfile =~ m|^[/\w.\-]+$|) {
7328: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7329: my $imageinfo = <PIPE>;
7330: if (!close(PIPE)) {
7331: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7332: }
7333: chomp($imageinfo);
7334: my ($fullsize) =
7335: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
7336: if ($fullsize) {
7337: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7338: }
7339: }
7340: }
7341: return ($fullwidth,$fullheight);
7342: }
7343:
7344: sub check_configuser {
7345: my ($uhome,$dom,$confname,$servadm) = @_;
7346: my ($configuserok,%currroles);
7347: if ($uhome eq 'no_host') {
7348: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7349: my $configpass = &LONCAPA::Enrollment::create_password();
7350: $configuserok =
7351: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7352: $configpass,'','','','','',undef,$servadm);
7353: } else {
7354: $configuserok = 'ok';
7355: %currroles =
7356: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7357: }
7358: return ($configuserok,%currroles);
7359: }
7360:
7361: sub check_authorstatus {
7362: my ($dom,$confname,%currroles) = @_;
7363: my $author_ok;
7364: if (!$currroles{':'.$dom.':au'}) {
7365: my $start = time;
7366: my $end = 0;
7367: $author_ok =
7368: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
7369: 'au',$end,$start,'','','domconfig');
7370: } else {
7371: $author_ok = 'ok';
7372: }
7373: return $author_ok;
7374: }
7375:
7376: sub publishlogo {
7377: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
7378: my ($output,$fname,$logourl,$madethumb);
7379: if ($action eq 'upload') {
7380: $fname=$env{'form.'.$formname.'.filename'};
7381: chop($env{'form.'.$formname});
7382: } else {
7383: ($fname) = ($formname =~ /([^\/]+)$/);
7384: }
7385: if ($savefileas ne '') {
7386: $fname = $savefileas;
7387: }
7388: $fname=&Apache::lonnet::clean_filename($fname);
7389: # See if there is anything left
7390: unless ($fname) { return ('error: no uploaded file'); }
7391: $fname="$subdir/$fname";
7392: my $docroot=$r->dir_config('lonDocRoot');
7393: my $filepath="$docroot/priv";
7394: my $relpath = "$dom/$confname";
7395: my ($fnamepath,$file,$fetchthumb);
7396: $file=$fname;
7397: if ($fname=~m|/|) {
7398: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7399: }
7400: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
7401: my $count;
7402: for ($count=5;$count<=$#parts;$count++) {
7403: $filepath.="/$parts[$count]";
7404: if ((-e $filepath)!=1) {
7405: mkdir($filepath,02770);
7406: }
7407: }
7408: # Check for bad extension and disallow upload
7409: if ($file=~/\.(\w+)$/ &&
7410: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7411: $output =
7412: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
7413: } elsif ($file=~/\.(\w+)$/ &&
7414: !defined(&Apache::loncommon::fileembstyle($1))) {
7415: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7416: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
7417: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7418: } elsif (-d "$filepath/$file") {
7419: $output = &mt('Filename is a directory name - rename the file and re-upload');
7420: } else {
7421: my $source = $filepath.'/'.$file;
7422: my $logfile;
7423: if (!open($logfile,">>$source".'.log')) {
7424: return (&mt('No write permission to Authoring Space'));
7425: }
7426: print $logfile
7427: "\n================= Publish ".localtime()." ================\n".
7428: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7429: # Save the file
7430: if (!open(FH,'>'.$source)) {
7431: &Apache::lonnet::logthis('Failed to create '.$source);
7432: return (&mt('Failed to create file'));
7433: }
7434: if ($action eq 'upload') {
7435: if (!print FH ($env{'form.'.$formname})) {
7436: &Apache::lonnet::logthis('Failed to write to '.$source);
7437: return (&mt('Failed to write file'));
7438: }
7439: } else {
7440: my $original = &Apache::lonnet::filelocation('',$formname);
7441: if(!copy($original,$source)) {
7442: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7443: return (&mt('Failed to write file'));
7444: }
7445: }
7446: close(FH);
7447: chmod(0660, $source); # Permissions to rw-rw---.
7448:
7449: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7450: my $copyfile=$targetdir.'/'.$file;
7451:
7452: my @parts=split(/\//,$targetdir);
7453: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7454: for (my $count=5;$count<=$#parts;$count++) {
7455: $path.="/$parts[$count]";
7456: if (!-e $path) {
7457: print $logfile "\nCreating directory ".$path;
7458: mkdir($path,02770);
7459: }
7460: }
7461: my $versionresult;
7462: if (-e $copyfile) {
7463: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7464: } else {
7465: $versionresult = 'ok';
7466: }
7467: if ($versionresult eq 'ok') {
7468: if (copy($source,$copyfile)) {
7469: print $logfile "\nCopied original source to ".$copyfile."\n";
7470: $output = 'ok';
7471: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
7472: push(@{$modified_urls},[$copyfile,$source]);
7473: my $metaoutput =
7474: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7475: unless ($registered_cleanup) {
7476: my $handlers = $r->get_handlers('PerlCleanupHandler');
7477: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7478: $registered_cleanup=1;
7479: }
7480: } else {
7481: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7482: $output = &mt('Failed to copy file to RES space').", $!";
7483: }
7484: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7485: my $inputfile = $filepath.'/'.$file;
7486: my $outfile = $filepath.'/'.'tn-'.$file;
7487: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7488: if ($fullwidth ne '' && $fullheight ne '') {
7489: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7490: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7491: system("convert -sample $thumbsize $inputfile $outfile");
7492: chmod(0660, $filepath.'/tn-'.$file);
7493: if (-e $outfile) {
7494: my $copyfile=$targetdir.'/tn-'.$file;
7495: if (copy($outfile,$copyfile)) {
7496: print $logfile "\nCopied source to ".$copyfile."\n";
7497: my $thumb_metaoutput =
7498: &write_metadata($dom,$confname,$formname,
7499: $targetdir,'tn-'.$file,$logfile);
7500: push(@{$modified_urls},[$copyfile,$outfile]);
7501: unless ($registered_cleanup) {
7502: my $handlers = $r->get_handlers('PerlCleanupHandler');
7503: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7504: $registered_cleanup=1;
7505: }
7506: $madethumb = 1;
7507: } else {
7508: print $logfile "\nUnable to write ".$copyfile.
7509: ':'.$!."\n";
7510: }
7511: }
7512: }
7513: }
7514: }
7515: } else {
7516: $output = $versionresult;
7517: }
7518: }
7519: return ($output,$logourl,$madethumb);
7520: }
7521:
7522: sub logo_versioning {
7523: my ($targetdir,$file,$logfile) = @_;
7524: my $target = $targetdir.'/'.$file;
7525: my ($maxversion,$fn,$extn,$output);
7526: $maxversion = 0;
7527: if ($file =~ /^(.+)\.(\w+)$/) {
7528: $fn=$1;
7529: $extn=$2;
7530: }
7531: opendir(DIR,$targetdir);
7532: while (my $filename=readdir(DIR)) {
7533: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7534: $maxversion=($1>$maxversion)?$1:$maxversion;
7535: }
7536: }
7537: $maxversion++;
7538: print $logfile "\nCreating old version ".$maxversion."\n";
7539: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7540: if (copy($target,$copyfile)) {
7541: print $logfile "Copied old target to ".$copyfile."\n";
7542: $copyfile=$copyfile.'.meta';
7543: if (copy($target.'.meta',$copyfile)) {
7544: print $logfile "Copied old target metadata to ".$copyfile."\n";
7545: $output = 'ok';
7546: } else {
7547: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7548: $output = &mt('Failed to copy old meta').", $!, ";
7549: }
7550: } else {
7551: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7552: $output = &mt('Failed to copy old target').", $!, ";
7553: }
7554: return $output;
7555: }
7556:
7557: sub write_metadata {
7558: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7559: my (%metadatafields,%metadatakeys,$output);
7560: $metadatafields{'title'}=$formname;
7561: $metadatafields{'creationdate'}=time;
7562: $metadatafields{'lastrevisiondate'}=time;
7563: $metadatafields{'copyright'}='public';
7564: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7565: $env{'user.domain'};
7566: $metadatafields{'authorspace'}=$confname.':'.$dom;
7567: $metadatafields{'domain'}=$dom;
7568: {
7569: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7570: my $mfh;
7571: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
7572: foreach (sort(keys(%metadatafields))) {
7573: unless ($_=~/\./) {
7574: my $unikey=$_;
7575: $unikey=~/^([A-Za-z]+)/;
7576: my $tag=$1;
7577: $tag=~tr/A-Z/a-z/;
7578: print $mfh "\n\<$tag";
7579: foreach (split(/\,/,$metadatakeys{$unikey})) {
7580: my $value=$metadatafields{$unikey.'.'.$_};
7581: $value=~s/\"/\'\'/g;
7582: print $mfh ' '.$_.'="'.$value.'"';
7583: }
7584: print $mfh '>'.
7585: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7586: .'</'.$tag.'>';
7587: }
7588: }
7589: $output = 'ok';
7590: print $logfile "\nWrote metadata";
7591: close($mfh);
7592: } else {
7593: print $logfile "\nFailed to open metadata file";
7594: $output = &mt('Could not write metadata');
7595: }
7596: }
7597: return $output;
7598: }
7599:
7600: sub notifysubscribed {
7601: foreach my $targetsource (@{$modified_urls}){
7602: next unless (ref($targetsource) eq 'ARRAY');
7603: my ($target,$source)=@{$targetsource};
7604: if ($source ne '') {
7605: if (open(my $logfh,'>>'.$source.'.log')) {
7606: print $logfh "\nCleanup phase: Notifications\n";
7607: my @subscribed=&subscribed_hosts($target);
7608: foreach my $subhost (@subscribed) {
7609: print $logfh "\nNotifying host ".$subhost.':';
7610: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7611: print $logfh $reply;
7612: }
7613: my @subscribedmeta=&subscribed_hosts("$target.meta");
7614: foreach my $subhost (@subscribedmeta) {
7615: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7616: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7617: $subhost);
7618: print $logfh $reply;
7619: }
7620: print $logfh "\n============ Done ============\n";
7621: close($logfh);
7622: }
7623: }
7624: }
7625: return OK;
7626: }
7627:
7628: sub subscribed_hosts {
7629: my ($target) = @_;
7630: my @subscribed;
7631: if (open(my $fh,"<$target.subscription")) {
7632: while (my $subline=<$fh>) {
7633: if ($subline =~ /^($match_lonid):/) {
7634: my $host = $1;
7635: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7636: unless (grep(/^\Q$host\E$/,@subscribed)) {
7637: push(@subscribed,$host);
7638: }
7639: }
7640: }
7641: }
7642: }
7643: return @subscribed;
7644: }
7645:
7646: sub check_switchserver {
7647: my ($dom,$confname) = @_;
7648: my ($allowed,$switchserver);
7649: my $home = &Apache::lonnet::homeserver($confname,$dom);
7650: if ($home eq 'no_host') {
7651: $home = &Apache::lonnet::domain($dom,'primary');
7652: }
7653: my @ids=&Apache::lonnet::current_machine_ids();
7654: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7655: if (!$allowed) {
7656: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
7657: }
7658: return $switchserver;
7659: }
7660:
7661: sub modify_quotas {
7662: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
7663: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
7664: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
7665: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7666: $validationfieldsref);
7667: if ($action eq 'quotas') {
7668: $context = 'tools';
7669: } else {
7670: $context = $action;
7671: }
7672: if ($context eq 'requestcourses') {
7673: @usertools = ('official','unofficial','community','textbook','placement');
7674: @options =('norequest','approval','validate','autolimit');
7675: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7676: %titles = &courserequest_titles();
7677: $toolregexp = join('|',@usertools);
7678: %conditions = &courserequest_conditions();
7679: $confname = $dom.'-domainconfig';
7680: my $servadm = $r->dir_config('lonAdmEMail');
7681: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7682: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7683: &Apache::loncoursequeueadmin::requestcourses_validation_types();
7684: } elsif ($context eq 'requestauthor') {
7685: @usertools = ('author');
7686: %titles = &authorrequest_titles();
7687: } else {
7688: @usertools = ('aboutme','blog','webdav','portfolio');
7689: %titles = &tool_titles();
7690: }
7691: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7692: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7693: foreach my $key (keys(%env)) {
7694: if ($context eq 'requestcourses') {
7695: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7696: my $item = $1;
7697: my $type = $2;
7698: if ($type =~ /^limit_(.+)/) {
7699: $limithash{$item}{$1} = $env{$key};
7700: } else {
7701: $confhash{$item}{$type} = $env{$key};
7702: }
7703: }
7704: } elsif ($context eq 'requestauthor') {
7705: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7706: $confhash{$1} = $env{$key};
7707: }
7708: } else {
7709: if ($key =~ /^form\.quota_(.+)$/) {
7710: $confhash{'defaultquota'}{$1} = $env{$key};
7711: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7712: $confhash{'authorquota'}{$1} = $env{$key};
7713: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
7714: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7715: }
7716: }
7717: }
7718: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
7719: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
7720: @approvalnotify = sort(@approvalnotify);
7721: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
7722: my @crstypes = ('official','unofficial','community','textbook','placement');
7723: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7724: foreach my $type (@hasuniquecode) {
7725: if (grep(/^\Q$type\E$/,@crstypes)) {
7726: $confhash{'uniquecode'}{$type} = 1;
7727: }
7728: }
7729: my (%newbook,%allpos);
7730: if ($context eq 'requestcourses') {
7731: foreach my $type ('textbooks','templates') {
7732: @{$allpos{$type}} = ();
7733: my $invalid;
7734: if ($type eq 'textbooks') {
7735: $invalid = &mt('Invalid LON-CAPA course for textbook');
7736: } else {
7737: $invalid = &mt('Invalid LON-CAPA course for template');
7738: }
7739: if ($env{'form.'.$type.'_addbook'}) {
7740: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7741: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7742: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7743: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7744: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7745: } else {
7746: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7747: my $position = $env{'form.'.$type.'_addbook_pos'};
7748: $position =~ s/\D+//g;
7749: if ($position ne '') {
7750: $allpos{$type}[$position] = $newbook{$type};
7751: }
7752: }
7753: } else {
7754: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7755: }
7756: }
7757: }
7758: }
7759: if (ref($domconfig{$action}) eq 'HASH') {
7760: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7761: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7762: $changes{'notify'}{'approval'} = 1;
7763: }
7764: } else {
7765: if ($confhash{'notify'}{'approval'}) {
7766: $changes{'notify'}{'approval'} = 1;
7767: }
7768: }
7769: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7770: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7771: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7772: unless ($confhash{'uniquecode'}{$crstype}) {
7773: $changes{'uniquecode'} = 1;
7774: }
7775: }
7776: unless ($changes{'uniquecode'}) {
7777: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7778: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7779: $changes{'uniquecode'} = 1;
7780: }
7781: }
7782: }
7783: } else {
7784: $changes{'uniquecode'} = 1;
7785: }
7786: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7787: $changes{'uniquecode'} = 1;
7788: }
7789: if ($context eq 'requestcourses') {
7790: foreach my $type ('textbooks','templates') {
7791: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7792: my %deletions;
7793: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7794: if (@todelete) {
7795: map { $deletions{$_} = 1; } @todelete;
7796: }
7797: my %imgdeletions;
7798: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7799: if (@todeleteimages) {
7800: map { $imgdeletions{$_} = 1; } @todeleteimages;
7801: }
7802: my $maxnum = $env{'form.'.$type.'_maxnum'};
7803: for (my $i=0; $i<=$maxnum; $i++) {
7804: my $itemid = $env{'form.'.$type.'_id_'.$i};
7805: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7806: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7807: if ($deletions{$key}) {
7808: if ($domconfig{$action}{$type}{$key}{'image'}) {
7809: #FIXME need to obsolete item in RES space
7810: }
7811: next;
7812: } else {
7813: my $newpos = $env{'form.'.$itemid};
7814: $newpos =~ s/\D+//g;
7815: foreach my $item ('subject','title','publisher','author') {
7816: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7817: ($type eq 'templates'));
7818: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7819: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7820: $changes{$type}{$key} = 1;
7821: }
7822: }
7823: $allpos{$type}[$newpos] = $key;
7824: }
7825: if ($imgdeletions{$key}) {
7826: $changes{$type}{$key} = 1;
7827: #FIXME need to obsolete item in RES space
7828: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7829: my ($cdom,$cnum) = split(/_/,$key);
7830: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7831: $cdom,$cnum,$type,$configuserok,
7832: $switchserver,$author_ok);
7833: if ($imgurl) {
7834: $confhash{$type}{$key}{'image'} = $imgurl;
7835: $changes{$type}{$key} = 1;
7836: }
7837: if ($error) {
7838: &Apache::lonnet::logthis($error);
7839: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7840: }
7841: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7842: $confhash{$type}{$key}{'image'} =
7843: $domconfig{$action}{$type}{$key}{'image'};
7844: }
7845: }
7846: }
7847: }
7848: }
7849: }
7850: } else {
7851: if ($confhash{'notify'}{'approval'}) {
7852: $changes{'notify'}{'approval'} = 1;
7853: }
7854: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7855: $changes{'uniquecode'} = 1;
7856: }
7857: }
7858: if ($context eq 'requestcourses') {
7859: foreach my $type ('textbooks','templates') {
7860: if ($newbook{$type}) {
7861: $changes{$type}{$newbook{$type}} = 1;
7862: foreach my $item ('subject','title','publisher','author') {
7863: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7864: ($type eq 'template'));
7865: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7866: if ($env{'form.'.$type.'_addbook_'.$item}) {
7867: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7868: }
7869: }
7870: if ($type eq 'textbooks') {
7871: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7872: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7873: my ($imageurl,$error) =
7874: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7875: $configuserok,$switchserver,$author_ok);
7876: if ($imageurl) {
7877: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7878: }
7879: if ($error) {
7880: &Apache::lonnet::logthis($error);
7881: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7882: }
7883: }
7884: }
7885: }
7886: if (@{$allpos{$type}} > 0) {
7887: my $idx = 0;
7888: foreach my $item (@{$allpos{$type}}) {
7889: if ($item ne '') {
7890: $confhash{$type}{$item}{'order'} = $idx;
7891: if (ref($domconfig{$action}) eq 'HASH') {
7892: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7893: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7894: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7895: $changes{$type}{$item} = 1;
7896: }
7897: }
7898: }
7899: }
7900: $idx ++;
7901: }
7902: }
7903: }
7904: }
7905: if (ref($validationitemsref) eq 'ARRAY') {
7906: foreach my $item (@{$validationitemsref}) {
7907: if ($item eq 'fields') {
7908: my @changed;
7909: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7910: if (@{$confhash{'validation'}{$item}} > 0) {
7911: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7912: }
7913: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7914: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7915: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7916: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7917: $domconfig{'requestcourses'}{'validation'}{$item});
7918: } else {
7919: @changed = @{$confhash{'validation'}{$item}};
7920: }
7921: } else {
7922: @changed = @{$confhash{'validation'}{$item}};
7923: }
7924: } else {
7925: @changed = @{$confhash{'validation'}{$item}};
7926: }
7927: if (@changed) {
7928: if ($confhash{'validation'}{$item}) {
7929: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7930: } else {
7931: $changes{'validation'}{$item} = &mt('None');
7932: }
7933: }
7934: } else {
7935: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7936: if ($item eq 'markup') {
7937: if ($env{'form.requestcourses_validation_'.$item}) {
7938: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7939: }
7940: }
7941: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7942: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7943: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7944: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7945: }
7946: } else {
7947: if ($confhash{'validation'}{$item} ne '') {
7948: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7949: }
7950: }
7951: } else {
7952: if ($confhash{'validation'}{$item} ne '') {
7953: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7954: }
7955: }
7956: }
7957: }
7958: }
7959: if ($env{'form.validationdc'}) {
7960: my $newval = $env{'form.validationdc'};
7961: my %domcoords = &get_active_dcs($dom);
7962: if (exists($domcoords{$newval})) {
7963: $confhash{'validation'}{'dc'} = $newval;
7964: }
7965: }
7966: if (ref($confhash{'validation'}) eq 'HASH') {
7967: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7968: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7969: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7970: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7971: if ($confhash{'validation'}{'dc'} eq '') {
7972: $changes{'validation'}{'dc'} = &mt('None');
7973: } else {
7974: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7975: }
7976: }
7977: } elsif ($confhash{'validation'}{'dc'} ne '') {
7978: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7979: }
7980: } elsif ($confhash{'validation'}{'dc'} ne '') {
7981: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7982: }
7983: } elsif ($confhash{'validation'}{'dc'} ne '') {
7984: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7985: }
7986: } else {
7987: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7988: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7989: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7990: $changes{'validation'}{'dc'} = &mt('None');
7991: }
7992: }
7993: }
7994: }
7995: }
7996: } else {
7997: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
7998: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
7999: }
8000: foreach my $item (@usertools) {
8001: foreach my $type (@{$types},'default','_LC_adv') {
8002: my $unset;
8003: if ($context eq 'requestcourses') {
8004: $unset = '0';
8005: if ($type eq '_LC_adv') {
8006: $unset = '';
8007: }
8008: if ($confhash{$item}{$type} eq 'autolimit') {
8009: $confhash{$item}{$type} .= '=';
8010: unless ($limithash{$item}{$type} =~ /\D/) {
8011: $confhash{$item}{$type} .= $limithash{$item}{$type};
8012: }
8013: }
8014: } elsif ($context eq 'requestauthor') {
8015: $unset = '0';
8016: if ($type eq '_LC_adv') {
8017: $unset = '';
8018: }
8019: } else {
8020: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8021: $confhash{$item}{$type} = 1;
8022: } else {
8023: $confhash{$item}{$type} = 0;
8024: }
8025: }
8026: if (ref($domconfig{$action}) eq 'HASH') {
8027: if ($action eq 'requestauthor') {
8028: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8029: $changes{$type} = 1;
8030: }
8031: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
8032: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8033: $changes{$item}{$type} = 1;
8034: }
8035: } else {
8036: if ($context eq 'requestcourses') {
8037: if ($confhash{$item}{$type} ne $unset) {
8038: $changes{$item}{$type} = 1;
8039: }
8040: } else {
8041: if (!$confhash{$item}{$type}) {
8042: $changes{$item}{$type} = 1;
8043: }
8044: }
8045: }
8046: } else {
8047: if ($context eq 'requestcourses') {
8048: if ($confhash{$item}{$type} ne $unset) {
8049: $changes{$item}{$type} = 1;
8050: }
8051: } elsif ($context eq 'requestauthor') {
8052: if ($confhash{$type} ne $unset) {
8053: $changes{$type} = 1;
8054: }
8055: } else {
8056: if (!$confhash{$item}{$type}) {
8057: $changes{$item}{$type} = 1;
8058: }
8059: }
8060: }
8061: }
8062: }
8063: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
8064: if (ref($domconfig{'quotas'}) eq 'HASH') {
8065: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8066: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8067: if (exists($confhash{'defaultquota'}{$key})) {
8068: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8069: $changes{'defaultquota'}{$key} = 1;
8070: }
8071: } else {
8072: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
8073: }
8074: }
8075: } else {
8076: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8077: if (exists($confhash{'defaultquota'}{$key})) {
8078: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8079: $changes{'defaultquota'}{$key} = 1;
8080: }
8081: } else {
8082: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
8083: }
8084: }
8085: }
8086: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8087: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8088: if (exists($confhash{'authorquota'}{$key})) {
8089: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8090: $changes{'authorquota'}{$key} = 1;
8091: }
8092: } else {
8093: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8094: }
8095: }
8096: }
8097: }
8098: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8099: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8100: if (ref($domconfig{'quotas'}) eq 'HASH') {
8101: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8102: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8103: $changes{'defaultquota'}{$key} = 1;
8104: }
8105: } else {
8106: if (!exists($domconfig{'quotas'}{$key})) {
8107: $changes{'defaultquota'}{$key} = 1;
8108: }
8109: }
8110: } else {
8111: $changes{'defaultquota'}{$key} = 1;
8112: }
8113: }
8114: }
8115: if (ref($confhash{'authorquota'}) eq 'HASH') {
8116: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8117: if (ref($domconfig{'quotas'}) eq 'HASH') {
8118: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8119: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8120: $changes{'authorquota'}{$key} = 1;
8121: }
8122: } else {
8123: $changes{'authorquota'}{$key} = 1;
8124: }
8125: } else {
8126: $changes{'authorquota'}{$key} = 1;
8127: }
8128: }
8129: }
8130: }
8131:
8132: if ($context eq 'requestauthor') {
8133: $domdefaults{'requestauthor'} = \%confhash;
8134: } else {
8135: foreach my $key (keys(%confhash)) {
8136: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
8137: $domdefaults{$key} = $confhash{$key};
8138: }
8139: }
8140: }
8141:
8142: my %quotahash = (
8143: $action => { %confhash }
8144: );
8145: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8146: $dom);
8147: if ($putresult eq 'ok') {
8148: if (keys(%changes) > 0) {
8149: my $cachetime = 24*60*60;
8150: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
8151: if (ref($lastactref) eq 'HASH') {
8152: $lastactref->{'domdefaults'} = 1;
8153: }
8154: $resulttext = &mt('Changes made:').'<ul>';
8155: unless (($context eq 'requestcourses') ||
8156: ($context eq 'requestauthor')) {
8157: if (ref($changes{'defaultquota'}) eq 'HASH') {
8158: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8159: foreach my $type (@{$types},'default') {
8160: if (defined($changes{'defaultquota'}{$type})) {
8161: my $typetitle = $usertypes->{$type};
8162: if ($type eq 'default') {
8163: $typetitle = $othertitle;
8164: }
8165: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
8166: }
8167: }
8168: $resulttext .= '</ul></li>';
8169: }
8170: if (ref($changes{'authorquota'}) eq 'HASH') {
8171: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
8172: foreach my $type (@{$types},'default') {
8173: if (defined($changes{'authorquota'}{$type})) {
8174: my $typetitle = $usertypes->{$type};
8175: if ($type eq 'default') {
8176: $typetitle = $othertitle;
8177: }
8178: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
8179: }
8180: }
8181: $resulttext .= '</ul></li>';
8182: }
8183: }
8184: my %newenv;
8185: foreach my $item (@usertools) {
8186: my (%haschgs,%inconf);
8187: if ($context eq 'requestauthor') {
8188: %haschgs = %changes;
8189: %inconf = %confhash;
8190: } else {
8191: if (ref($changes{$item}) eq 'HASH') {
8192: %haschgs = %{$changes{$item}};
8193: }
8194: if (ref($confhash{$item}) eq 'HASH') {
8195: %inconf = %{$confhash{$item}};
8196: }
8197: }
8198: if (keys(%haschgs) > 0) {
8199: my $newacc =
8200: &Apache::lonnet::usertools_access($env{'user.name'},
8201: $env{'user.domain'},
8202: $item,'reload',$context);
8203: if (($context eq 'requestcourses') ||
8204: ($context eq 'requestauthor')) {
8205: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8206: $newenv{'environment.canrequest.'.$item} = $newacc;
8207: }
8208: } else {
8209: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8210: $newenv{'environment.availabletools.'.$item} = $newacc;
8211: }
8212: }
8213: unless ($context eq 'requestauthor') {
8214: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8215: }
8216: foreach my $type (@{$types},'default','_LC_adv') {
8217: if ($haschgs{$type}) {
8218: my $typetitle = $usertypes->{$type};
8219: if ($type eq 'default') {
8220: $typetitle = $othertitle;
8221: } elsif ($type eq '_LC_adv') {
8222: $typetitle = 'LON-CAPA Advanced Users';
8223: }
8224: if ($inconf{$type}) {
8225: if ($context eq 'requestcourses') {
8226: my $cond;
8227: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
8228: if ($1 eq '') {
8229: $cond = &mt('(Automatic processing of any request).');
8230: } else {
8231: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8232: }
8233: } else {
8234: $cond = $conditions{$inconf{$type}};
8235: }
8236: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
8237: } elsif ($context eq 'requestauthor') {
8238: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8239: $titles{$inconf{$type}},$typetitle);
8240:
8241: } else {
8242: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8243: }
8244: } else {
8245: if ($type eq '_LC_adv') {
8246: if ($inconf{$type} eq '0') {
8247: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8248: } else {
8249: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8250: }
8251: } else {
8252: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8253: }
8254: }
8255: }
8256: }
8257: unless ($context eq 'requestauthor') {
8258: $resulttext .= '</ul></li>';
8259: }
8260: }
8261: }
8262: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
8263: if (ref($changes{'notify'}) eq 'HASH') {
8264: if ($changes{'notify'}{'approval'}) {
8265: if (ref($confhash{'notify'}) eq 'HASH') {
8266: if ($confhash{'notify'}{'approval'}) {
8267: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8268: } else {
8269: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
8270: }
8271: }
8272: }
8273: }
8274: }
8275: if ($action eq 'requestcourses') {
8276: my @offon = ('off','on');
8277: if ($changes{'uniquecode'}) {
8278: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8279: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8280: $resulttext .= '<li>'.
8281: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8282: '</li>';
8283: } else {
8284: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8285: '</li>';
8286: }
8287: }
8288: foreach my $type ('textbooks','templates') {
8289: if (ref($changes{$type}) eq 'HASH') {
8290: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8291: foreach my $key (sort(keys(%{$changes{$type}}))) {
8292: my %coursehash = &Apache::lonnet::coursedescription($key);
8293: my $coursetitle = $coursehash{'description'};
8294: my $position = $confhash{$type}{$key}{'order'} + 1;
8295: $resulttext .= '<li>';
8296: foreach my $item ('subject','title','publisher','author') {
8297: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8298: ($type eq 'templates'));
8299: my $name = $item.':';
8300: $name =~ s/^(\w)/\U$1/;
8301: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8302: }
8303: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8304: if ($type eq 'textbooks') {
8305: if ($confhash{$type}{$key}{'image'}) {
8306: $resulttext .= ' '.&mt('Image: [_1]',
8307: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8308: ' alt="Textbook cover" />').'<br />';
8309: }
8310: }
8311: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
8312: }
8313: $resulttext .= '</ul></li>';
8314: }
8315: }
8316: if (ref($changes{'validation'}) eq 'HASH') {
8317: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8318: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8319: foreach my $item (@{$validationitemsref}) {
8320: if (exists($changes{'validation'}{$item})) {
8321: if ($item eq 'markup') {
8322: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8323: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8324: } else {
8325: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8326: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8327: }
8328: }
8329: }
8330: if (exists($changes{'validation'}{'dc'})) {
8331: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8332: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8333: }
8334: }
8335: }
8336: }
8337: $resulttext .= '</ul>';
8338: if (keys(%newenv)) {
8339: &Apache::lonnet::appenv(\%newenv);
8340: }
8341: } else {
8342: if ($context eq 'requestcourses') {
8343: $resulttext = &mt('No changes made to rights to request creation of courses.');
8344: } elsif ($context eq 'requestauthor') {
8345: $resulttext = &mt('No changes made to rights to request author space.');
8346: } else {
8347: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
8348: }
8349: }
8350: } else {
8351: $resulttext = '<span class="LC_error">'.
8352: &mt('An error occurred: [_1]',$putresult).'</span>';
8353: }
8354: if ($errors) {
8355: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8356: '<ul>'.$errors.'</ul></p>';
8357: }
8358: return $resulttext;
8359: }
8360:
8361: sub process_textbook_image {
8362: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
8363: my $filename = $env{'form.'.$caller.'.filename'};
8364: my ($error,$url);
8365: my ($width,$height) = (50,50);
8366: if ($configuserok eq 'ok') {
8367: if ($switchserver) {
8368: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8369: $switchserver);
8370: } elsif ($author_ok eq 'ok') {
8371: my ($result,$imageurl) =
8372: &publishlogo($r,'upload',$caller,$dom,$confname,
8373: "$type/$dom/$cnum/cover",$width,$height);
8374: if ($result eq 'ok') {
8375: $url = $imageurl;
8376: } else {
8377: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8378: }
8379: } else {
8380: $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);
8381: }
8382: } else {
8383: $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);
8384: }
8385: return ($url,$error);
8386: }
8387:
8388: sub modify_ltitools {
8389: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8390: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8391: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8392: my $confname = $dom.'-domainconfig';
8393: my $servadm = $r->dir_config('lonAdmEMail');
8394: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8395: my (%posslti,%possfield);
8396: my @courseroles = ('cc','in','ta','ep','st');
8397: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8398: map { $posslti{$_} = 1; } @ltiroles;
8399: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8400: map { $possfield{$_} = 1; } @allfields;
8401: my %lt = <itools_names();
8402: if ($env{'form.ltitools_add'}) {
8403: my $title = $env{'form.ltitools_add_title'};
8404: $title =~ s/(`)/'/g;
8405: ($newid,my $error) = &get_ltitools_id($dom,$title);
8406: if ($newid) {
8407: my $position = $env{'form.ltitools_add_pos'};
8408: $position =~ s/\D+//g;
8409: if ($position ne '') {
8410: $allpos[$position] = $newid;
8411: }
8412: $changes{$newid} = 1;
8413: foreach my $item ('title','url','key','secret') {
8414: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8415: if ($env{'form.ltitools_add_'.$item}) {
8416: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8417: }
8418: }
8419: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8420: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8421: }
8422: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8423: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8424: }
8425: foreach my $item ('width','height') {
8426: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8427: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8428: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8429: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8430: }
8431: }
8432: if ($env{'form.ltitools_add_target'} eq 'window') {
8433: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8434: } else {
8435: $confhash{$newid}{'display'}{'target'} = 'iframe';
8436: }
8437: foreach my $item ('passback','roster') {
8438: if ($env{'form.ltitools_add_'.$item}) {
8439: $confhash{$newid}{$item} = 1;
8440: }
8441: }
8442: if ($env{'form.ltitools_add_image.filename'} ne '') {
8443: my ($imageurl,$error) =
8444: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8445: $configuserok,$switchserver,$author_ok);
8446: if ($imageurl) {
8447: $confhash{$newid}{'image'} = $imageurl;
8448: }
8449: if ($error) {
8450: &Apache::lonnet::logthis($error);
8451: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8452: }
8453: }
8454: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8455: foreach my $field (@fields) {
8456: if ($possfield{$field}) {
8457: if ($field eq 'roles') {
8458: foreach my $role (@courseroles) {
8459: my $choice = $env{'form.ltitools_add_roles_'.$role};
8460: if (($choice ne '') && ($posslti{$choice})) {
8461: $confhash{$newid}{'roles'}{$role} = $choice;
8462: if ($role eq 'cc') {
8463: $confhash{$newid}{'roles'}{'co'} = $choice;
8464: }
8465: }
8466: }
8467: } else {
8468: $confhash{$newid}{'fields'}{$field} = 1;
8469: }
8470: }
8471: }
8472: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
8473: foreach my $item (@courseconfig) {
8474: $confhash{$newid}{'crsconf'}{$item} = 1;
8475: }
8476: if ($env{'form.ltitools_add_custom'}) {
8477: my $name = $env{'form.ltitools_add_custom_name'};
8478: my $value = $env{'form.ltitools_add_custom_value'};
8479: $value =~ s/(`)/'/g;
8480: $name =~ s/(`)/'/g;
8481: $confhash{$newid}{'custom'}{$name} = $value;
8482: }
8483: } else {
8484: my $error = &mt('Failed to acquire unique ID for new external tool');
8485: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8486: }
8487: }
8488: if (ref($domconfig{$action}) eq 'HASH') {
8489: my %deletions;
8490: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8491: if (@todelete) {
8492: map { $deletions{$_} = 1; } @todelete;
8493: }
8494: my %customadds;
8495: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8496: if (@newcustom) {
8497: map { $customadds{$_} = 1; } @newcustom;
8498: }
8499: my %imgdeletions;
8500: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8501: if (@todeleteimages) {
8502: map { $imgdeletions{$_} = 1; } @todeleteimages;
8503: }
8504: my $maxnum = $env{'form.ltitools_maxnum'};
8505: for (my $i=0; $i<=$maxnum; $i++) {
8506: my $itemid = $env{'form.ltitools_id_'.$i};
8507: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8508: if ($deletions{$itemid}) {
8509: if ($domconfig{$action}{$itemid}{'image'}) {
8510: #FIXME need to obsolete item in RES space
8511: }
8512: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8513: next;
8514: } else {
8515: my $newpos = $env{'form.ltitools_'.$itemid};
8516: $newpos =~ s/\D+//g;
8517: foreach my $item ('title','url','key','secret') {
8518: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8519: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8520: $changes{$itemid} = 1;
8521: }
8522: }
8523: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8524: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8525: }
8526: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8527: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8528: }
8529: foreach my $size ('width','height') {
8530: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8531: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8532: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8533: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8534: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8535: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8536: $changes{$itemid} = 1;
8537: }
8538: } else {
8539: $changes{$itemid} = 1;
8540: }
8541: }
8542: }
8543: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8544: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8545: } else {
8546: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8547: }
8548: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8549: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8550: $changes{$itemid} = 1;
8551: }
8552: } else {
8553: $changes{$itemid} = 1;
8554: }
8555: foreach my $extra ('passback','roster') {
8556: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8557: $confhash{$itemid}{$extra} = 1;
8558: }
8559: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8560: $changes{$itemid} = 1;
8561: }
8562: }
8563: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
8564: foreach my $item ('label','title','target') {
8565: if (grep(/^\Q$item\E$/,@courseconfig)) {
8566: $confhash{$itemid}{'crsconf'}{$item} = 1;
8567: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
8568: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
8569: $changes{$itemid} = 1;
8570: }
8571: } else {
8572: $changes{$itemid} = 1;
8573: }
8574: }
8575: }
8576: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8577: foreach my $field (@fields) {
8578: if ($possfield{$field}) {
8579: if ($field eq 'roles') {
8580: foreach my $role (@courseroles) {
8581: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8582: if (($choice ne '') && ($posslti{$choice})) {
8583: $confhash{$itemid}{'roles'}{$role} = $choice;
8584: if ($role eq 'cc') {
8585: $confhash{$itemid}{'roles'}{'co'} = $choice;
8586: }
8587: }
8588: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8589: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8590: $changes{$itemid} = 1;
8591: }
8592: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8593: $changes{$itemid} = 1;
8594: }
8595: }
8596: } else {
8597: $confhash{$itemid}{'fields'}{$field} = 1;
8598: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8599: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8600: $changes{$itemid} = 1;
8601: }
8602: } else {
8603: $changes{$itemid} = 1;
8604: }
8605: }
8606: }
8607: }
8608: $allpos[$newpos] = $itemid;
8609: }
8610: if ($imgdeletions{$itemid}) {
8611: $changes{$itemid} = 1;
8612: #FIXME need to obsolete item in RES space
8613: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8614: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8615: $itemid,$configuserok,$switchserver,
8616: $author_ok);
8617: if ($imgurl) {
8618: $confhash{$itemid}{'image'} = $imgurl;
8619: $changes{$itemid} = 1;
8620: }
8621: if ($error) {
8622: &Apache::lonnet::logthis($error);
8623: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8624: }
8625: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8626: $confhash{$itemid}{'image'} =
8627: $domconfig{$action}{$itemid}{'image'};
8628: }
8629: if ($customadds{$i}) {
8630: my $name = $env{'form.ltitools_custom_name_'.$i};
8631: $name =~ s/(`)/'/g;
8632: $name =~ s/^\s+//;
8633: $name =~ s/\s+$//;
8634: my $value = $env{'form.ltitools_custom_value_'.$i};
8635: $value =~ s/(`)/'/g;
8636: $value =~ s/^\s+//;
8637: $value =~ s/\s+$//;
8638: if ($name ne '') {
8639: $confhash{$itemid}{'custom'}{$name} = $value;
8640: $changes{$itemid} = 1;
8641: }
8642: }
8643: my %customdels;
8644: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8645: if (@customdeletions) {
8646: $changes{$itemid} = 1;
8647: }
8648: map { $customdels{$_} = 1; } @customdeletions;
8649: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8650: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8651: unless ($customdels{$key}) {
8652: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8653: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8654: }
8655: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8656: $changes{$itemid} = 1;
8657: }
8658: }
8659: }
8660: }
8661: unless ($changes{$itemid}) {
8662: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8663: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8664: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8665: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8666: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8667: $changes{$itemid} = 1;
8668: last;
8669: }
8670: }
8671: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8672: $changes{$itemid} = 1;
8673: }
8674: }
8675: last if ($changes{$itemid});
8676: }
8677: }
8678: }
8679: }
8680: }
8681: if (@allpos > 0) {
8682: my $idx = 0;
8683: foreach my $itemid (@allpos) {
8684: if ($itemid ne '') {
8685: $confhash{$itemid}{'order'} = $idx;
8686: if (ref($domconfig{$action}) eq 'HASH') {
8687: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8688: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8689: $changes{$itemid} = 1;
8690: }
8691: }
8692: }
8693: $idx ++;
8694: }
8695: }
8696: }
8697: my %ltitoolshash = (
8698: $action => { %confhash }
8699: );
8700: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8701: $dom);
8702: if ($putresult eq 'ok') {
8703: if (keys(%changes) > 0) {
8704: my $cachetime = 24*60*60;
8705: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
8706: if (ref($lastactref) eq 'HASH') {
8707: $lastactref->{'ltitools'} = 1;
8708: }
8709: $resulttext = &mt('Changes made:').'<ul>';
8710: my %bynum;
8711: foreach my $itemid (sort(keys(%changes))) {
8712: my $position = $confhash{$itemid}{'order'};
8713: $bynum{$position} = $itemid;
8714: }
8715: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
8716: my $itemid = $bynum{$pos};
8717: if (ref($confhash{$itemid}) ne 'HASH') {
8718: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
8719: } else {
8720: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
8721: if ($confhash{$itemid}{'image'}) {
8722: $resulttext .= ' '.
8723: '<img src="'.$confhash{$itemid}{'image'}.'"'.
8724: ' alt="'.&mt('Tool Provider icon').'" />';
8725: }
8726: $resulttext .= '</li><ul>';
8727: my $position = $pos + 1;
8728: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
8729: foreach my $item ('version','msgtype','url','key') {
8730: if ($confhash{$itemid}{$item} ne '') {
8731: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
8732: }
8733: }
8734: if ($confhash{$itemid}{'secret'} ne '') {
8735: $resulttext .= '<li>'.$lt{'secret'}.': ';
8736: my $num = length($confhash{$itemid}{'secret'});
8737: $resulttext .= ('*'x$num).'</li>';
8738: }
8739: $resulttext .= '<li>'.&mt('Configurable in course:');
8740: my @possconfig = ('label','title','target');
8741: my $numconfig = 0;
8742: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
8743: foreach my $item (@possconfig) {
8744: if ($confhash{$itemid}{'crsconf'}{$item}) {
8745: $numconfig ++;
8746: $resulttext .= ' '.$lt{'crs'.$item};
8747: }
8748: }
8749: }
8750: if (!$numconfig) {
8751: $resulttext .= &mt('None');
8752: }
8753: $resulttext .= '</li>';
8754: foreach my $item ('passback','roster') {
8755: $resulttext .= '<li>'.$lt{$item}.' ';
8756: if ($confhash{$itemid}{$item}) {
8757: $resulttext .= &mt('Yes');
8758: } else {
8759: $resulttext .= &mt('No');
8760: }
8761: $resulttext .= '</li>';
8762: }
8763: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
8764: my $displaylist;
8765: if ($confhash{$itemid}{'display'}{'target'}) {
8766: $displaylist = &mt('Display target').': '.
8767: $confhash{$itemid}{'display'}{'target'}.',';
8768: }
8769: foreach my $size ('width','height') {
8770: if ($confhash{$itemid}{'display'}{$size}) {
8771: $displaylist .= (' 'x2).$lt{$size}.': '.
8772: $confhash{$itemid}{'display'}{$size}.',';
8773: }
8774: }
8775: if ($displaylist) {
8776: $displaylist =~ s/,$//;
8777: $resulttext .= '<li>'.$displaylist.'</li>';
8778: }
8779: }
8780: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
8781: my $fieldlist;
8782: foreach my $field (@allfields) {
8783: if ($confhash{$itemid}{'fields'}{$field}) {
8784: $fieldlist .= (' 'x2).$lt{$field}.',';
8785: }
8786: }
8787: if ($fieldlist) {
8788: $fieldlist =~ s/,$//;
8789: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
8790: }
8791: }
8792: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
8793: my $rolemaps;
8794: foreach my $role (@courseroles) {
8795: if ($confhash{$itemid}{'roles'}{$role}) {
8796: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
8797: $confhash{$itemid}{'roles'}{$role}.',';
8798: }
8799: }
8800: if ($rolemaps) {
8801: $rolemaps =~ s/,$//;
8802: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
8803: }
8804: }
8805: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
8806: my $customlist;
8807: if (keys(%{$confhash{$itemid}{'custom'}})) {
8808: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
8809: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
8810: }
8811: }
8812: if ($customlist) {
8813: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
8814: }
8815: }
8816: $resulttext .= '</ul></li>';
8817: }
8818: }
8819: $resulttext .= '</ul>';
8820: } else {
8821: $resulttext = &mt('No changes made.');
8822: }
8823: } else {
8824: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
8825: }
8826: if ($errors) {
8827: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8828: $errors.'</ul>';
8829: }
8830: return $resulttext;
8831: }
8832:
8833: sub process_ltitools_image {
8834: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
8835: my $filename = $env{'form.'.$caller.'.filename'};
8836: my ($error,$url);
8837: my ($width,$height) = (21,21);
8838: if ($configuserok eq 'ok') {
8839: if ($switchserver) {
8840: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
8841: $switchserver);
8842: } elsif ($author_ok eq 'ok') {
8843: my ($result,$imageurl,$madethumb) =
8844: &publishlogo($r,'upload',$caller,$dom,$confname,
8845: "ltitools/$itemid/icon",$width,$height);
8846: if ($result eq 'ok') {
8847: if ($madethumb) {
8848: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
8849: my $imagethumb = "$path/tn-".$imagefile;
8850: $url = $imagethumb;
8851: } else {
8852: $url = $imageurl;
8853: }
8854: } else {
8855: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8856: }
8857: } else {
8858: $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);
8859: }
8860: } else {
8861: $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);
8862: }
8863: return ($url,$error);
8864: }
8865:
8866: sub get_ltitools_id {
8867: my ($cdom,$title) = @_;
8868: # get lock on ltitools db
8869: my $lockhash = {
8870: lock => $env{'user.name'}.
8871: ':'.$env{'user.domain'},
8872: };
8873: my $tries = 0;
8874: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
8875: my ($id,$error);
8876:
8877: while (($gotlock ne 'ok') && ($tries<10)) {
8878: $tries ++;
8879: sleep (0.1);
8880: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
8881: }
8882: if ($gotlock eq 'ok') {
8883: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
8884: if ($currids{'lock'}) {
8885: delete($currids{'lock'});
8886: if (keys(%currids)) {
8887: my @curr = sort { $a <=> $b } keys(%currids);
8888: if ($curr[-1] =~ /^\d+$/) {
8889: $id = 1 + $curr[-1];
8890: }
8891: } else {
8892: $id = 1;
8893: }
8894: if ($id) {
8895: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
8896: $error = 'nostore';
8897: }
8898: } else {
8899: $error = 'nonumber';
8900: }
8901: }
8902: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
8903: } else {
8904: $error = 'nolock';
8905: }
8906: return ($id,$error);
8907: }
8908:
8909: sub modify_autoenroll {
8910: my ($dom,$lastactref,%domconfig) = @_;
8911: my ($resulttext,%changes);
8912: my %currautoenroll;
8913: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8914: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8915: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8916: }
8917: }
8918: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8919: my %title = ( run => 'Auto-enrollment active',
8920: sender => 'Sender for notification messages',
8921: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8922: failsafe => 'Failsafe for no drops if institutional data missing for a section');
8923: my @offon = ('off','on');
8924: my $sender_uname = $env{'form.sender_uname'};
8925: my $sender_domain = $env{'form.sender_domain'};
8926: if ($sender_domain eq '') {
8927: $sender_uname = '';
8928: } elsif ($sender_uname eq '') {
8929: $sender_domain = '';
8930: }
8931: my $coowners = $env{'form.autoassign_coowners'};
8932: my $failsafe = $env{'form.autoenroll_failsafe'};
8933: $failsafe =~ s{^\s+|\s+$}{}g;
8934: if ($failsafe =~ /\D/) {
8935: undef($failsafe);
8936: }
8937: my %autoenrollhash = (
8938: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8939: 'sender_uname' => $sender_uname,
8940: 'sender_domain' => $sender_domain,
8941: 'co-owners' => $coowners,
8942: 'autofailsafe' => $failsafe,
8943: }
8944: );
8945: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8946: $dom);
8947: if ($putresult eq 'ok') {
8948: if (exists($currautoenroll{'run'})) {
8949: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8950: $changes{'run'} = 1;
8951: }
8952: } elsif ($autorun) {
8953: if ($env{'form.autoenroll_run'} ne '1') {
8954: $changes{'run'} = 1;
8955: }
8956: }
8957: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
8958: $changes{'sender'} = 1;
8959: }
8960: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
8961: $changes{'sender'} = 1;
8962: }
8963: if ($currautoenroll{'co-owners'} ne '') {
8964: if ($currautoenroll{'co-owners'} ne $coowners) {
8965: $changes{'coowners'} = 1;
8966: }
8967: } elsif ($coowners) {
8968: $changes{'coowners'} = 1;
8969: }
8970: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8971: $changes{'autofailsafe'} = 1;
8972: }
8973: if (keys(%changes) > 0) {
8974: $resulttext = &mt('Changes made:').'<ul>';
8975: if ($changes{'run'}) {
8976: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8977: }
8978: if ($changes{'sender'}) {
8979: if ($sender_uname eq '' || $sender_domain eq '') {
8980: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8981: } else {
8982: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8983: }
8984: }
8985: if ($changes{'coowners'}) {
8986: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8987: &Apache::loncommon::devalidate_domconfig_cache($dom);
8988: if (ref($lastactref) eq 'HASH') {
8989: $lastactref->{'domainconfig'} = 1;
8990: }
8991: }
8992: if ($changes{'autofailsafe'}) {
8993: if ($failsafe ne '') {
8994: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
8995: } else {
8996: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
8997: }
8998: &Apache::lonnet::get_domain_defaults($dom,1);
8999: if (ref($lastactref) eq 'HASH') {
9000: $lastactref->{'domdefaults'} = 1;
9001: }
9002: }
9003: $resulttext .= '</ul>';
9004: } else {
9005: $resulttext = &mt('No changes made to auto-enrollment settings');
9006: }
9007: } else {
9008: $resulttext = '<span class="LC_error">'.
9009: &mt('An error occurred: [_1]',$putresult).'</span>';
9010: }
9011: return $resulttext;
9012: }
9013:
9014: sub modify_autoupdate {
9015: my ($dom,%domconfig) = @_;
9016: my ($resulttext,%currautoupdate,%fields,%changes);
9017: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9018: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9019: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9020: }
9021: }
9022: my @offon = ('off','on');
9023: my %title = &Apache::lonlocal::texthash (
9024: run => 'Auto-update:',
9025: classlists => 'Updates to user information in classlists?'
9026: );
9027: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9028: my %fieldtitles = &Apache::lonlocal::texthash (
9029: id => 'Student/Employee ID',
9030: permanentemail => 'E-mail address',
9031: lastname => 'Last Name',
9032: firstname => 'First Name',
9033: middlename => 'Middle Name',
9034: generation => 'Generation',
9035: );
9036: $othertitle = &mt('All users');
9037: if (keys(%{$usertypes}) > 0) {
9038: $othertitle = &mt('Other users');
9039: }
9040: foreach my $key (keys(%env)) {
9041: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
9042: my ($usertype,$item) = ($1,$2);
9043: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9044: if ($usertype eq 'default') {
9045: push(@{$fields{$1}},$2);
9046: } elsif (ref($types) eq 'ARRAY') {
9047: if (grep(/^\Q$usertype\E$/,@{$types})) {
9048: push(@{$fields{$1}},$2);
9049: }
9050: }
9051: }
9052: }
9053: }
9054: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9055: @lockablenames = sort(@lockablenames);
9056: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9057: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9058: if (@changed) {
9059: $changes{'lockablenames'} = 1;
9060: }
9061: } else {
9062: if (@lockablenames) {
9063: $changes{'lockablenames'} = 1;
9064: }
9065: }
9066: my %updatehash = (
9067: autoupdate => { run => $env{'form.autoupdate_run'},
9068: classlists => $env{'form.classlists'},
9069: fields => {%fields},
9070: lockablenames => \@lockablenames,
9071: }
9072: );
9073: foreach my $key (keys(%currautoupdate)) {
9074: if (($key eq 'run') || ($key eq 'classlists')) {
9075: if (exists($updatehash{autoupdate}{$key})) {
9076: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9077: $changes{$key} = 1;
9078: }
9079: }
9080: } elsif ($key eq 'fields') {
9081: if (ref($currautoupdate{$key}) eq 'HASH') {
9082: foreach my $item (@{$types},'default') {
9083: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9084: my $change = 0;
9085: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9086: if (!exists($fields{$item})) {
9087: $change = 1;
9088: last;
9089: } elsif (ref($fields{$item}) eq 'ARRAY') {
9090: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
9091: $change = 1;
9092: last;
9093: }
9094: }
9095: }
9096: if ($change) {
9097: push(@{$changes{$key}},$item);
9098: }
9099: }
9100: }
9101: }
9102: } elsif ($key eq 'lockablenames') {
9103: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9104: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9105: if (@changed) {
9106: $changes{'lockablenames'} = 1;
9107: }
9108: } else {
9109: if (@lockablenames) {
9110: $changes{'lockablenames'} = 1;
9111: }
9112: }
9113: }
9114: }
9115: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9116: if (@lockablenames) {
9117: $changes{'lockablenames'} = 1;
9118: }
9119: }
9120: foreach my $item (@{$types},'default') {
9121: if (defined($fields{$item})) {
9122: if (ref($currautoupdate{'fields'}) eq 'HASH') {
9123: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9124: my $change = 0;
9125: if (ref($fields{$item}) eq 'ARRAY') {
9126: foreach my $type (@{$fields{$item}}) {
9127: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9128: $change = 1;
9129: last;
9130: }
9131: }
9132: }
9133: if ($change) {
9134: push(@{$changes{'fields'}},$item);
9135: }
9136: } else {
9137: push(@{$changes{'fields'}},$item);
9138: }
9139: } else {
9140: push(@{$changes{'fields'}},$item);
9141: }
9142: }
9143: }
9144: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9145: $dom);
9146: if ($putresult eq 'ok') {
9147: if (keys(%changes) > 0) {
9148: $resulttext = &mt('Changes made:').'<ul>';
9149: foreach my $key (sort(keys(%changes))) {
9150: if ($key eq 'lockablenames') {
9151: $resulttext .= '<li>';
9152: if (@lockablenames) {
9153: $usertypes->{'default'} = $othertitle;
9154: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9155: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9156: } else {
9157: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9158: }
9159: $resulttext .= '</li>';
9160: } elsif (ref($changes{$key}) eq 'ARRAY') {
9161: foreach my $item (@{$changes{$key}}) {
9162: my @newvalues;
9163: foreach my $type (@{$fields{$item}}) {
9164: push(@newvalues,$fieldtitles{$type});
9165: }
9166: my $newvaluestr;
9167: if (@newvalues > 0) {
9168: $newvaluestr = join(', ',@newvalues);
9169: } else {
9170: $newvaluestr = &mt('none');
9171: }
9172: if ($item eq 'default') {
9173: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
9174: } else {
9175: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
9176: }
9177: }
9178: } else {
9179: my $newvalue;
9180: if ($key eq 'run') {
9181: $newvalue = $offon[$env{'form.autoupdate_run'}];
9182: } else {
9183: $newvalue = $offon[$env{'form.'.$key}];
9184: }
9185: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9186: }
9187: }
9188: $resulttext .= '</ul>';
9189: } else {
9190: $resulttext = &mt('No changes made to autoupdates');
9191: }
9192: } else {
9193: $resulttext = '<span class="LC_error">'.
9194: &mt('An error occurred: [_1]',$putresult).'</span>';
9195: }
9196: return $resulttext;
9197: }
9198:
9199: sub modify_autocreate {
9200: my ($dom,%domconfig) = @_;
9201: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9202: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9203: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9204: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9205: }
9206: }
9207: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9208: req => 'Auto-creation of validated requests for official courses',
9209: xmldc => 'Identity of course creator of courses from XML files',
9210: );
9211: my @types = ('xml','req');
9212: foreach my $item (@types) {
9213: $newvals{$item} = $env{'form.autocreate_'.$item};
9214: $newvals{$item} =~ s/\D//g;
9215: $newvals{$item} = 0 if ($newvals{$item} eq '');
9216: }
9217: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9218: my %domcoords = &get_active_dcs($dom);
9219: unless (exists($domcoords{$newvals{'xmldc'}})) {
9220: $newvals{'xmldc'} = '';
9221: }
9222: %autocreatehash = (
9223: autocreate => { xml => $newvals{'xml'},
9224: req => $newvals{'req'},
9225: }
9226: );
9227: if ($newvals{'xmldc'} ne '') {
9228: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9229: }
9230: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9231: $dom);
9232: if ($putresult eq 'ok') {
9233: my @items = @types;
9234: if ($newvals{'xml'}) {
9235: push(@items,'xmldc');
9236: }
9237: foreach my $item (@items) {
9238: if (exists($currautocreate{$item})) {
9239: if ($currautocreate{$item} ne $newvals{$item}) {
9240: $changes{$item} = 1;
9241: }
9242: } elsif ($newvals{$item}) {
9243: $changes{$item} = 1;
9244: }
9245: }
9246: if (keys(%changes) > 0) {
9247: my @offon = ('off','on');
9248: $resulttext = &mt('Changes made:').'<ul>';
9249: foreach my $item (@types) {
9250: if ($changes{$item}) {
9251: my $newtxt = $offon[$newvals{$item}];
9252: $resulttext .= '<li>'.
9253: &mt("$title{$item} set to [_1]$newtxt [_2]",
9254: '<b>','</b>').
9255: '</li>';
9256: }
9257: }
9258: if ($changes{'xmldc'}) {
9259: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9260: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
9261: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
9262: }
9263: $resulttext .= '</ul>';
9264: } else {
9265: $resulttext = &mt('No changes made to auto-creation settings');
9266: }
9267: } else {
9268: $resulttext = '<span class="LC_error">'.
9269: &mt('An error occurred: [_1]',$putresult).'</span>';
9270: }
9271: return $resulttext;
9272: }
9273:
9274: sub modify_directorysrch {
9275: my ($dom,%domconfig) = @_;
9276: my ($resulttext,%changes);
9277: my %currdirsrch;
9278: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9279: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9280: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9281: }
9282: }
9283: my %title = ( available => 'Directory search available',
9284: localonly => 'Other domains can search',
9285: searchby => 'Search types',
9286: searchtypes => 'Search latitude');
9287: my @offon = ('off','on');
9288: my @otherdoms = ('Yes','No');
9289:
9290: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
9291: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9292: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9293:
9294: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9295: if (keys(%{$usertypes}) == 0) {
9296: @cansearch = ('default');
9297: } else {
9298: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9299: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9300: if (!grep(/^\Q$type\E$/,@cansearch)) {
9301: push(@{$changes{'cansearch'}},$type);
9302: }
9303: }
9304: foreach my $type (@cansearch) {
9305: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9306: push(@{$changes{'cansearch'}},$type);
9307: }
9308: }
9309: } else {
9310: push(@{$changes{'cansearch'}},@cansearch);
9311: }
9312: }
9313:
9314: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9315: foreach my $by (@{$currdirsrch{'searchby'}}) {
9316: if (!grep(/^\Q$by\E$/,@searchby)) {
9317: push(@{$changes{'searchby'}},$by);
9318: }
9319: }
9320: foreach my $by (@searchby) {
9321: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9322: push(@{$changes{'searchby'}},$by);
9323: }
9324: }
9325: } else {
9326: push(@{$changes{'searchby'}},@searchby);
9327: }
9328:
9329: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9330: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9331: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9332: push(@{$changes{'searchtypes'}},$type);
9333: }
9334: }
9335: foreach my $type (@searchtypes) {
9336: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9337: push(@{$changes{'searchtypes'}},$type);
9338: }
9339: }
9340: } else {
9341: if (exists($currdirsrch{'searchtypes'})) {
9342: foreach my $type (@searchtypes) {
9343: if ($type ne $currdirsrch{'searchtypes'}) {
9344: push(@{$changes{'searchtypes'}},$type);
9345: }
9346: }
9347: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9348: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9349: }
9350: } else {
9351: push(@{$changes{'searchtypes'}},@searchtypes);
9352: }
9353: }
9354:
9355: my %dirsrch_hash = (
9356: directorysrch => { available => $env{'form.dirsrch_available'},
9357: cansearch => \@cansearch,
9358: localonly => $env{'form.dirsrch_localonly'},
9359: searchby => \@searchby,
9360: searchtypes => \@searchtypes,
9361: }
9362: );
9363: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9364: $dom);
9365: if ($putresult eq 'ok') {
9366: if (exists($currdirsrch{'available'})) {
9367: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9368: $changes{'available'} = 1;
9369: }
9370: } else {
9371: if ($env{'form.dirsrch_available'} eq '1') {
9372: $changes{'available'} = 1;
9373: }
9374: }
9375: if (exists($currdirsrch{'localonly'})) {
9376: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
9377: $changes{'localonly'} = 1;
9378: }
9379: } else {
9380: if ($env{'form.dirsrch_localonly'} eq '1') {
9381: $changes{'localonly'} = 1;
9382: }
9383: }
9384: if (keys(%changes) > 0) {
9385: $resulttext = &mt('Changes made:').'<ul>';
9386: if ($changes{'available'}) {
9387: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9388: }
9389: if ($changes{'localonly'}) {
9390: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
9391: }
9392:
9393: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9394: my $chgtext;
9395: if (ref($usertypes) eq 'HASH') {
9396: if (keys(%{$usertypes}) > 0) {
9397: foreach my $type (@{$types}) {
9398: if (grep(/^\Q$type\E$/,@cansearch)) {
9399: $chgtext .= $usertypes->{$type}.'; ';
9400: }
9401: }
9402: if (grep(/^default$/,@cansearch)) {
9403: $chgtext .= $othertitle;
9404: } else {
9405: $chgtext =~ s/\; $//;
9406: }
9407: $resulttext .=
9408: '<li>'.
9409: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9410: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9411: '</li>';
9412: }
9413: }
9414: }
9415: if (ref($changes{'searchby'}) eq 'ARRAY') {
9416: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9417: my $chgtext;
9418: foreach my $type (@{$titleorder}) {
9419: if (grep(/^\Q$type\E$/,@searchby)) {
9420: if (defined($searchtitles->{$type})) {
9421: $chgtext .= $searchtitles->{$type}.'; ';
9422: }
9423: }
9424: }
9425: $chgtext =~ s/\; $//;
9426: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9427: }
9428: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9429: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9430: my $chgtext;
9431: foreach my $type (@{$srchtypeorder}) {
9432: if (grep(/^\Q$type\E$/,@searchtypes)) {
9433: if (defined($srchtypes_desc->{$type})) {
9434: $chgtext .= $srchtypes_desc->{$type}.'; ';
9435: }
9436: }
9437: }
9438: $chgtext =~ s/\; $//;
9439: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
9440: }
9441: $resulttext .= '</ul>';
9442: } else {
9443: $resulttext = &mt('No changes made to institution directory search settings');
9444: }
9445: } else {
9446: $resulttext = '<span class="LC_error">'.
9447: &mt('An error occurred: [_1]',$putresult).'</span>';
9448: }
9449: return $resulttext;
9450: }
9451:
9452: sub modify_contacts {
9453: my ($dom,$lastactref,%domconfig) = @_;
9454: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9455: if (ref($domconfig{'contacts'}) eq 'HASH') {
9456: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9457: $currsetting{$key} = $domconfig{'contacts'}{$key};
9458: }
9459: }
9460: my (%others,%to,%bcc);
9461: my @contacts = ('supportemail','adminemail');
9462: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
9463: 'requestsmail','updatesmail','idconflictsmail');
9464: my @toggles = ('reporterrors','reportupdates');
9465: foreach my $type (@mailings) {
9466: @{$newsetting{$type}} =
9467: &Apache::loncommon::get_env_multiple('form.'.$type);
9468: foreach my $item (@contacts) {
9469: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9470: $contacts_hash{contacts}{$type}{$item} = 1;
9471: } else {
9472: $contacts_hash{contacts}{$type}{$item} = 0;
9473: }
9474: }
9475: $others{$type} = $env{'form.'.$type.'_others'};
9476: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
9477: if ($type eq 'helpdeskmail') {
9478: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9479: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9480: }
9481: }
9482: foreach my $item (@contacts) {
9483: $to{$item} = $env{'form.'.$item};
9484: $contacts_hash{'contacts'}{$item} = $to{$item};
9485: }
9486: foreach my $item (@toggles) {
9487: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9488: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9489: }
9490: }
9491: if (keys(%currsetting) > 0) {
9492: foreach my $item (@contacts) {
9493: if ($to{$item} ne $currsetting{$item}) {
9494: $changes{$item} = 1;
9495: }
9496: }
9497: foreach my $type (@mailings) {
9498: foreach my $item (@contacts) {
9499: if (ref($currsetting{$type}) eq 'HASH') {
9500: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9501: push(@{$changes{$type}},$item);
9502: }
9503: } else {
9504: push(@{$changes{$type}},@{$newsetting{$type}});
9505: }
9506: }
9507: if ($others{$type} ne $currsetting{$type}{'others'}) {
9508: push(@{$changes{$type}},'others');
9509: }
9510: if ($type eq 'helpdeskmail') {
9511: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9512: push(@{$changes{$type}},'bcc');
9513: }
9514: }
9515: }
9516: } else {
9517: my %default;
9518: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9519: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9520: $default{'errormail'} = 'adminemail';
9521: $default{'packagesmail'} = 'adminemail';
9522: $default{'helpdeskmail'} = 'supportemail';
9523: $default{'lonstatusmail'} = 'adminemail';
9524: $default{'requestsmail'} = 'adminemail';
9525: $default{'updatesmail'} = 'adminemail';
9526: foreach my $item (@contacts) {
9527: if ($to{$item} ne $default{$item}) {
9528: $changes{$item} = 1;
9529: }
9530: }
9531: foreach my $type (@mailings) {
9532: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9533:
9534: push(@{$changes{$type}},@{$newsetting{$type}});
9535: }
9536: if ($others{$type} ne '') {
9537: push(@{$changes{$type}},'others');
9538: }
9539: if ($type eq 'helpdeskmail') {
9540: if ($bcc{$type} ne '') {
9541: push(@{$changes{$type}},'bcc');
9542: }
9543: }
9544: }
9545: }
9546: foreach my $item (@toggles) {
9547: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9548: $changes{$item} = 1;
9549: } elsif ((!$env{'form.'.$item}) &&
9550: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9551: $changes{$item} = 1;
9552: }
9553: }
9554: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9555: $dom);
9556: if ($putresult eq 'ok') {
9557: if (keys(%changes) > 0) {
9558: &Apache::loncommon::devalidate_domconfig_cache($dom);
9559: if (ref($lastactref) eq 'HASH') {
9560: $lastactref->{'domainconfig'} = 1;
9561: }
9562: my ($titles,$short_titles) = &contact_titles();
9563: $resulttext = &mt('Changes made:').'<ul>';
9564: foreach my $item (@contacts) {
9565: if ($changes{$item}) {
9566: $resulttext .= '<li>'.$titles->{$item}.
9567: &mt(' set to: ').
9568: '<span class="LC_cusr_emph">'.
9569: $to{$item}.'</span></li>';
9570: }
9571: }
9572: foreach my $type (@mailings) {
9573: if (ref($changes{$type}) eq 'ARRAY') {
9574: $resulttext .= '<li>'.$titles->{$type}.': ';
9575: my @text;
9576: foreach my $item (@{$newsetting{$type}}) {
9577: push(@text,$short_titles->{$item});
9578: }
9579: if ($others{$type} ne '') {
9580: push(@text,$others{$type});
9581: }
9582: $resulttext .= '<span class="LC_cusr_emph">'.
9583: join(', ',@text).'</span>';
9584: if ($type eq 'helpdeskmail') {
9585: if ($bcc{$type} ne '') {
9586: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9587: }
9588: }
9589: $resulttext .= '</li>';
9590: }
9591: }
9592: my @offon = ('off','on');
9593: if ($changes{'reporterrors'}) {
9594: $resulttext .= '<li>'.
9595: &mt('E-mail error reports to [_1] set to "'.
9596: $offon[$env{'form.reporterrors'}].'".',
9597: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9598: &mt('LON-CAPA core group - MSU'),600,500)).
9599: '</li>';
9600: }
9601: if ($changes{'reportupdates'}) {
9602: $resulttext .= '<li>'.
9603: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9604: $offon[$env{'form.reportupdates'}].'".',
9605: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9606: &mt('LON-CAPA core group - MSU'),600,500)).
9607: '</li>';
9608: }
9609: $resulttext .= '</ul>';
9610: } else {
9611: $resulttext = &mt('No changes made to contact information');
9612: }
9613: } else {
9614: $resulttext = '<span class="LC_error">'.
9615: &mt('An error occurred: [_1].',$putresult).'</span>';
9616: }
9617: return $resulttext;
9618: }
9619:
9620: sub modify_usercreation {
9621: my ($dom,%domconfig) = @_;
9622: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
9623: my $warningmsg;
9624: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9625: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9626: if ($key eq 'cancreate') {
9627: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9628: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9629: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9630: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9631: ($item eq 'recaptchaversion')) {
9632: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9633: } else {
9634: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9635: }
9636: }
9637: }
9638: } elsif ($key eq 'email_rule') {
9639: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9640: } else {
9641: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9642: }
9643: }
9644: }
9645: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9646: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9647: my @contexts = ('author','course','requestcrs');
9648: foreach my $item(@contexts) {
9649: $cancreate{$item} = $env{'form.can_createuser_'.$item};
9650: }
9651: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9652: foreach my $item (@contexts) {
9653: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9654: push(@{$changes{'cancreate'}},$item);
9655: }
9656: }
9657: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9658: foreach my $item (@contexts) {
9659: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
9660: if ($cancreate{$item} ne 'any') {
9661: push(@{$changes{'cancreate'}},$item);
9662: }
9663: } else {
9664: if ($cancreate{$item} ne 'none') {
9665: push(@{$changes{'cancreate'}},$item);
9666: }
9667: }
9668: }
9669: } else {
9670: foreach my $item (@contexts) {
9671: push(@{$changes{'cancreate'}},$item);
9672: }
9673: }
9674:
9675: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9676: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9677: if (!grep(/^\Q$type\E$/,@username_rule)) {
9678: push(@{$changes{'username_rule'}},$type);
9679: }
9680: }
9681: foreach my $type (@username_rule) {
9682: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9683: push(@{$changes{'username_rule'}},$type);
9684: }
9685: }
9686: } else {
9687: push(@{$changes{'username_rule'}},@username_rule);
9688: }
9689:
9690: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9691: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9692: if (!grep(/^\Q$type\E$/,@id_rule)) {
9693: push(@{$changes{'id_rule'}},$type);
9694: }
9695: }
9696: foreach my $type (@id_rule) {
9697: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9698: push(@{$changes{'id_rule'}},$type);
9699: }
9700: }
9701: } else {
9702: push(@{$changes{'id_rule'}},@id_rule);
9703: }
9704:
9705: my @authen_contexts = ('author','course','domain');
9706: my @authtypes = ('int','krb4','krb5','loc');
9707: my %authhash;
9708: foreach my $item (@authen_contexts) {
9709: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9710: foreach my $auth (@authtypes) {
9711: if (grep(/^\Q$auth\E$/,@authallowed)) {
9712: $authhash{$item}{$auth} = 1;
9713: } else {
9714: $authhash{$item}{$auth} = 0;
9715: }
9716: }
9717: }
9718: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
9719: foreach my $item (@authen_contexts) {
9720: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9721: foreach my $auth (@authtypes) {
9722: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9723: push(@{$changes{'authtypes'}},$item);
9724: last;
9725: }
9726: }
9727: }
9728: }
9729: } else {
9730: foreach my $item (@authen_contexts) {
9731: push(@{$changes{'authtypes'}},$item);
9732: }
9733: }
9734:
9735: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9736: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9737: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9738: $save_usercreate{'id_rule'} = \@id_rule;
9739: $save_usercreate{'username_rule'} = \@username_rule,
9740: $save_usercreate{'authtypes'} = \%authhash;
9741:
9742: my %usercreation_hash = (
9743: usercreation => \%save_usercreate,
9744: );
9745:
9746: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9747: $dom);
9748:
9749: if ($putresult eq 'ok') {
9750: if (keys(%changes) > 0) {
9751: $resulttext = &mt('Changes made:').'<ul>';
9752: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9753: my %lt = &usercreation_types();
9754: foreach my $type (@{$changes{'cancreate'}}) {
9755: my $chgtext = $lt{$type}.', ';
9756: if ($cancreate{$type} eq 'none') {
9757: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9758: } elsif ($cancreate{$type} eq 'any') {
9759: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9760: } elsif ($cancreate{$type} eq 'official') {
9761: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9762: } elsif ($cancreate{$type} eq 'unofficial') {
9763: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9764: }
9765: $resulttext .= '<li>'.$chgtext.'</li>';
9766: }
9767: }
9768: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9769: my ($rules,$ruleorder) =
9770: &Apache::lonnet::inst_userrules($dom,'username');
9771: my $chgtext = '<ul>';
9772: foreach my $type (@username_rule) {
9773: if (ref($rules->{$type}) eq 'HASH') {
9774: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9775: }
9776: }
9777: $chgtext .= '</ul>';
9778: if (@username_rule > 0) {
9779: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9780: } else {
9781: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9782: }
9783: }
9784: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9785: my ($idrules,$idruleorder) =
9786: &Apache::lonnet::inst_userrules($dom,'id');
9787: my $chgtext = '<ul>';
9788: foreach my $type (@id_rule) {
9789: if (ref($idrules->{$type}) eq 'HASH') {
9790: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9791: }
9792: }
9793: $chgtext .= '</ul>';
9794: if (@id_rule > 0) {
9795: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9796: } else {
9797: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9798: }
9799: }
9800: my %authname = &authtype_names();
9801: my %context_title = &context_names();
9802: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9803: my $chgtext = '<ul>';
9804: foreach my $type (@{$changes{'authtypes'}}) {
9805: my @allowed;
9806: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9807: foreach my $auth (@authtypes) {
9808: if ($authhash{$type}{$auth}) {
9809: push(@allowed,$authname{$auth});
9810: }
9811: }
9812: if (@allowed > 0) {
9813: $chgtext .= join(', ',@allowed).'</li>';
9814: } else {
9815: $chgtext .= &mt('none').'</li>';
9816: }
9817: }
9818: $chgtext .= '</ul>';
9819: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9820: $resulttext .= '</li>';
9821: }
9822: $resulttext .= '</ul>';
9823: } else {
9824: $resulttext = &mt('No changes made to user creation settings');
9825: }
9826: } else {
9827: $resulttext = '<span class="LC_error">'.
9828: &mt('An error occurred: [_1]',$putresult).'</span>';
9829: }
9830: if ($warningmsg ne '') {
9831: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9832: }
9833: return $resulttext;
9834: }
9835:
9836: sub modify_selfcreation {
9837: my ($dom,%domconfig) = @_;
9838: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9839: my (%save_usercreate,%save_usermodify);
9840: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9841: if (ref($types) eq 'ARRAY') {
9842: $usertypes->{'default'} = $othertitle;
9843: push(@{$types},'default');
9844: }
9845: #
9846: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9847: #
9848: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9849: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9850: if ($key eq 'cancreate') {
9851: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9852: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9853: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9854: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9855: ($item eq 'recaptchaversion') ||
9856: ($item eq 'emailusername') || ($item eq 'notify') ||
9857: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
9858: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9859: } else {
9860: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9861: }
9862: }
9863: }
9864: } elsif ($key eq 'email_rule') {
9865: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9866: } else {
9867: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9868: }
9869: }
9870: }
9871: #
9872: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9873: #
9874: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9875: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9876: if ($key eq 'selfcreate') {
9877: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9878: } else {
9879: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9880: }
9881: }
9882: }
9883:
9884: my @contexts = ('selfcreate');
9885: @{$cancreate{'selfcreate'}} = ();
9886: %{$cancreate{'emailusername'}} = ();
9887: @{$cancreate{'statustocreate'}} = ();
9888: %{$cancreate{'selfcreateprocessing'}} = ();
9889: %{$cancreate{'shibenv'}} = ();
9890: my %selfcreatetypes = (
9891: sso => 'users authenticated by institutional single sign on',
9892: login => 'users authenticated by institutional log-in',
9893: email => 'users who provide a valid e-mail address for use as username',
9894: );
9895: #
9896: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9897: # is permitted.
9898: #
9899:
9900: my @statuses;
9901: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9902: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9903: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9904: }
9905: }
9906: push(@statuses,'default');
9907:
9908: foreach my $item ('login','sso','email') {
9909: if ($item eq 'email') {
9910: if ($env{'form.cancreate_email'}) {
9911: push(@{$cancreate{'selfcreate'}},'email');
9912: push(@contexts,'selfcreateprocessing');
9913: foreach my $type (@statuses) {
9914: if ($type eq 'default') {
9915: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9916: } else {
9917: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9918: }
9919: }
9920: }
9921: } else {
9922: if ($env{'form.cancreate_'.$item}) {
9923: push(@{$cancreate{'selfcreate'}},$item);
9924: }
9925: }
9926: }
9927: my (@email_rule,%userinfo,%savecaptcha);
9928: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9929: #
9930: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9931: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
9932: #
9933:
9934: if ($env{'form.cancreate_email'}) {
9935: push(@contexts,'emailusername');
9936: if (ref($types) eq 'ARRAY') {
9937: foreach my $type (@{$types}) {
9938: if (ref($infofields) eq 'ARRAY') {
9939: foreach my $field (@{$infofields}) {
9940: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9941: $cancreate{'emailusername'}{$type}{$field} = $1;
9942: }
9943: }
9944: }
9945: }
9946: }
9947: #
9948: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9949: # queued requests for self-creation of account using e-mail address as username
9950: #
9951:
9952: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9953: @approvalnotify = sort(@approvalnotify);
9954: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9955: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9956: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9957: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9958: push(@{$changes{'cancreate'}},'notify');
9959: }
9960: } else {
9961: if ($cancreate{'notify'}{'approval'}) {
9962: push(@{$changes{'cancreate'}},'notify');
9963: }
9964: }
9965: } elsif ($cancreate{'notify'}{'approval'}) {
9966: push(@{$changes{'cancreate'}},'notify');
9967: }
9968:
9969: #
9970: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9971: #
9972: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9973: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9974: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9975: if (@{$curr_usercreation{'email_rule'}} > 0) {
9976: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9977: if (!grep(/^\Q$type\E$/,@email_rule)) {
9978: push(@{$changes{'email_rule'}},$type);
9979: }
9980: }
9981: }
9982: if (@email_rule > 0) {
9983: foreach my $type (@email_rule) {
9984: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9985: push(@{$changes{'email_rule'}},$type);
9986: }
9987: }
9988: }
9989: } elsif (@email_rule > 0) {
9990: push(@{$changes{'email_rule'}},@email_rule);
9991: }
9992: }
9993: #
9994: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
9995: # institutional log-in.
9996: #
9997: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9998: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9999: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10000: ($domdefaults{'auth_def'} eq 'localauth'))) {
10001: $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.').' '.
10002: &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.');
10003: }
10004: }
10005: my @fields = ('lastname','firstname','middlename','generation',
10006: 'permanentemail','id');
10007: my @shibfields = (@fields,'inststatus');
10008: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10009: #
10010: # Where usernames may created for institutional log-in and/or institutional single sign on:
10011: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10012: # may self-create accounts
10013: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10014: # which the user may supply, if institutional data is unavailable.
10015: #
10016: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10017: if (ref($types) eq 'ARRAY') {
10018: if (@{$types} > 1) {
10019: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10020: push(@contexts,'statustocreate');
10021: } else {
10022: undef($cancreate{'statustocreate'});
10023: }
10024: foreach my $type (@{$types}) {
10025: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10026: foreach my $field (@fields) {
10027: if (grep(/^\Q$field\E$/,@modifiable)) {
10028: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10029: } else {
10030: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10031: }
10032: }
10033: }
10034: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10035: foreach my $type (@{$types}) {
10036: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10037: foreach my $field (@fields) {
10038: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10039: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10040: push(@{$changes{'selfcreate'}},$type);
10041: last;
10042: }
10043: }
10044: }
10045: }
10046: } else {
10047: foreach my $type (@{$types}) {
10048: push(@{$changes{'selfcreate'}},$type);
10049: }
10050: }
10051: }
10052: foreach my $field (@shibfields) {
10053: if ($env{'form.shibenv_'.$field} ne '') {
10054: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10055: }
10056: }
10057: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10058: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10059: foreach my $field (@shibfields) {
10060: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10061: push(@{$changes{'cancreate'}},'shibenv');
10062: }
10063: }
10064: } else {
10065: foreach my $field (@shibfields) {
10066: if ($env{'form.shibenv_'.$field}) {
10067: push(@{$changes{'cancreate'}},'shibenv');
10068: last;
10069: }
10070: }
10071: }
10072: }
10073: }
10074: foreach my $item (@contexts) {
10075: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10076: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10077: if (ref($cancreate{$item}) eq 'ARRAY') {
10078: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10079: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10080: push(@{$changes{'cancreate'}},$item);
10081: }
10082: }
10083: }
10084: }
10085: if (ref($cancreate{$item}) eq 'ARRAY') {
10086: foreach my $type (@{$cancreate{$item}}) {
10087: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10088: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10089: push(@{$changes{'cancreate'}},$item);
10090: }
10091: }
10092: }
10093: }
10094: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10095: if (ref($cancreate{$item}) eq 'HASH') {
10096: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
10097: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10098: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10099: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10100: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10101: push(@{$changes{'cancreate'}},$item);
10102: }
10103: }
10104: }
10105: } elsif ($item eq 'selfcreateprocessing') {
10106: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10107: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10108: push(@{$changes{'cancreate'}},$item);
10109: }
10110: }
10111: } else {
10112: if (!$cancreate{$item}{$curr}) {
10113: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10114: push(@{$changes{'cancreate'}},$item);
10115: }
10116: }
10117: }
10118: }
10119: foreach my $field (keys(%{$cancreate{$item}})) {
10120: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10121: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10122: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10123: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10124: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10125: push(@{$changes{'cancreate'}},$item);
10126: }
10127: }
10128: } else {
10129: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10130: push(@{$changes{'cancreate'}},$item);
10131: }
10132: }
10133: }
10134: } elsif ($item eq 'selfcreateprocessing') {
10135: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10136: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10137: push(@{$changes{'cancreate'}},$item);
10138: }
10139: }
10140: } else {
10141: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10142: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10143: push(@{$changes{'cancreate'}},$item);
10144: }
10145: }
10146: }
10147: }
10148: }
10149: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10150: if (ref($cancreate{$item}) eq 'ARRAY') {
10151: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10152: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10153: push(@{$changes{'cancreate'}},$item);
10154: }
10155: }
10156: } elsif (ref($cancreate{$item}) eq 'HASH') {
10157: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10158: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10159: push(@{$changes{'cancreate'}},$item);
10160: }
10161: }
10162: }
10163: } elsif ($item eq 'emailusername') {
10164: if (ref($cancreate{$item}) eq 'HASH') {
10165: foreach my $type (keys(%{$cancreate{$item}})) {
10166: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10167: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10168: if ($cancreate{$item}{$type}{$field}) {
10169: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10170: push(@{$changes{'cancreate'}},$item);
10171: }
10172: last;
10173: }
10174: }
10175: }
10176: }
10177: }
10178: }
10179: }
10180: #
10181: # Populate %save_usercreate hash with updates to self-creation configuration.
10182: #
10183: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10184: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
10185: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
10186: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10187: if (ref($cancreate{'notify'}) eq 'HASH') {
10188: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10189: }
10190: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10191: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10192: }
10193: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10194: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10195: }
10196: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10197: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10198: }
10199: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10200: $save_usercreate{'emailrule'} = \@email_rule;
10201:
10202: my %userconfig_hash = (
10203: usercreation => \%save_usercreate,
10204: usermodification => \%save_usermodify,
10205: );
10206: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10207: $dom);
10208: #
10209: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10210: #
10211: if ($putresult eq 'ok') {
10212: if (keys(%changes) > 0) {
10213: $resulttext = &mt('Changes made:').'<ul>';
10214: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10215: my %lt = &selfcreation_types();
10216: foreach my $type (@{$changes{'cancreate'}}) {
10217: my $chgtext;
10218: if ($type eq 'selfcreate') {
10219: if (@{$cancreate{$type}} == 0) {
10220: $chgtext .= &mt('Self creation of a new user account is not permitted.');
10221: } else {
10222: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10223: '<ul>';
10224: foreach my $case (@{$cancreate{$type}}) {
10225: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10226: }
10227: $chgtext .= '</ul>';
10228: if (ref($cancreate{$type}) eq 'ARRAY') {
10229: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10230: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10231: if (@{$cancreate{'statustocreate'}} == 0) {
10232: $chgtext .= '<br />'.
10233: '<span class="LC_warning">'.
10234: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10235: '</span>';
10236: }
10237: }
10238: }
10239: }
10240: }
10241: } elsif ($type eq 'shibenv') {
10242: if (keys(%{$cancreate{$type}}) == 0) {
10243: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10244: } else {
10245: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10246: '<ul>';
10247: foreach my $field (@shibfields) {
10248: next if ($cancreate{$type}{$field} eq '');
10249: if ($field eq 'inststatus') {
10250: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10251: } else {
10252: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10253: }
10254: }
10255: $chgtext .= '</ul>';
10256: }
10257: } elsif ($type eq 'statustocreate') {
10258: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10259: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10260: if (@{$cancreate{'selfcreate'}} > 0) {
10261: if (@{$cancreate{'statustocreate'}} == 0) {
10262: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
10263: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
10264: $chgtext .= '<br />'.
10265: '<span class="LC_warning">'.
10266: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10267: '</span>';
10268: }
10269: } elsif (ref($usertypes) eq 'HASH') {
10270: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
10271: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10272: } else {
10273: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10274: }
10275: $chgtext .= '<ul>';
10276: foreach my $case (@{$cancreate{$type}}) {
10277: if ($case eq 'default') {
10278: $chgtext .= '<li>'.$othertitle.'</li>';
10279: } else {
10280: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
10281: }
10282: }
10283: $chgtext .= '</ul>';
10284: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
10285: $chgtext .= '<br /><span class="LC_warning">'.
10286: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10287: '</span>';
10288: }
10289: }
10290: } else {
10291: if (@{$cancreate{$type}} == 0) {
10292: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10293: } else {
10294: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
10295: }
10296: }
10297: }
10298: } elsif ($type eq 'selfcreateprocessing') {
10299: my %choices = &Apache::lonlocal::texthash (
10300: automatic => 'Automatic approval',
10301: approval => 'Queued for approval',
10302: );
10303: if (@statuses > 1) {
10304: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10305: '<ul>';
10306: foreach my $type (@statuses) {
10307: if ($type eq 'default') {
10308: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10309: } else {
10310: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10311: }
10312: }
10313: $chgtext .= '</ul>';
10314: } else {
10315: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10316: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10317: }
10318: } elsif ($type eq 'captcha') {
10319: if ($savecaptcha{$type} eq 'notused') {
10320: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10321: } else {
10322: my %captchas = &captcha_phrases();
10323: if ($captchas{$savecaptcha{$type}}) {
10324: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
10325: } else {
10326: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10327: }
10328: }
10329: } elsif ($type eq 'recaptchakeys') {
10330: my ($privkey,$pubkey);
10331: if (ref($savecaptcha{$type}) eq 'HASH') {
10332: $pubkey = $savecaptcha{$type}{'public'};
10333: $privkey = $savecaptcha{$type}{'private'};
10334: }
10335: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10336: if (!$pubkey) {
10337: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10338: } else {
10339: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10340: }
10341: if (!$privkey) {
10342: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10343: } else {
10344: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10345: }
10346: $chgtext .= '</ul>';
10347: } elsif ($type eq 'recaptchaversion') {
10348: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10349: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10350: }
10351: } elsif ($type eq 'emailusername') {
10352: if (ref($cancreate{'emailusername'}) eq 'HASH') {
10353: if (ref($types) eq 'ARRAY') {
10354: foreach my $type (@{$types}) {
10355: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10356: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
10357: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
10358: '<ul>';
10359: foreach my $field (@{$infofields}) {
10360: if ($cancreate{'emailusername'}{$type}{$field}) {
10361: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10362: }
10363: }
10364: $chgtext .= '</ul>';
10365: } else {
10366: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
10367: }
10368: } else {
10369: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
10370: }
10371: }
10372: }
10373: }
10374: } elsif ($type eq 'notify') {
10375: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10376: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10377: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10378: if ($cancreate{'notify'}{'approval'}) {
10379: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10380: }
10381: }
10382: }
10383: }
10384: if ($chgtext) {
10385: $resulttext .= '<li>'.$chgtext.'</li>';
10386: }
10387: }
10388: }
10389: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10390: my ($emailrules,$emailruleorder) =
10391: &Apache::lonnet::inst_userrules($dom,'email');
10392: my $chgtext = '<ul>';
10393: foreach my $type (@email_rule) {
10394: if (ref($emailrules->{$type}) eq 'HASH') {
10395: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10396: }
10397: }
10398: $chgtext .= '</ul>';
10399: if (@email_rule > 0) {
10400: $resulttext .= '<li>'.
10401: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10402: $chgtext.
10403: '</li>';
10404: } else {
10405: $resulttext .= '<li>'.
10406: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10407: '</li>';
10408: }
10409: }
10410: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10411: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10412: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10413: foreach my $type (@{$changes{'selfcreate'}}) {
10414: my $typename = $type;
10415: if (ref($usertypes) eq 'HASH') {
10416: if ($usertypes->{$type} ne '') {
10417: $typename = $usertypes->{$type};
10418: }
10419: }
10420: my @modifiable;
10421: $resulttext .= '<li>'.
10422: &mt('Self-creation of account by users with status: [_1]',
10423: '<span class="LC_cusr_emph">'.$typename.'</span>').
10424: ' - '.&mt('modifiable fields (if institutional data blank): ');
10425: foreach my $field (@fields) {
10426: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10427: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10428: }
10429: }
10430: if (@modifiable > 0) {
10431: $resulttext .= join(', ',@modifiable);
10432: } else {
10433: $resulttext .= &mt('none');
10434: }
10435: $resulttext .= '</li>';
10436: }
10437: $resulttext .= '</ul></li>';
10438: }
10439: $resulttext .= '</ul>';
10440: } else {
10441: $resulttext = &mt('No changes made to self-creation settings');
10442: }
10443: } else {
10444: $resulttext = '<span class="LC_error">'.
10445: &mt('An error occurred: [_1]',$putresult).'</span>';
10446: }
10447: if ($warningmsg ne '') {
10448: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10449: }
10450: return $resulttext;
10451: }
10452:
10453: sub process_captcha {
10454: my ($container,$changes,$newsettings,$current) = @_;
10455: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10456: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10457: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10458: $newsettings->{'captcha'} = 'original';
10459: }
10460: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10461: if ($container eq 'cancreate') {
10462: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10463: push(@{$changes->{'cancreate'}},'captcha');
10464: } elsif (!defined($changes->{'cancreate'})) {
10465: $changes->{'cancreate'} = ['captcha'];
10466: }
10467: } else {
10468: $changes->{'captcha'} = 1;
10469: }
10470: }
10471: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
10472: if ($newsettings->{'captcha'} eq 'recaptcha') {
10473: $newpub = $env{'form.'.$container.'_recaptchapub'};
10474: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
10475: $newpub =~ s/[^\w\-]//g;
10476: $newpriv =~ s/[^\w\-]//g;
10477: $newsettings->{'recaptchakeys'} = {
10478: public => $newpub,
10479: private => $newpriv,
10480: };
10481: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10482: $newversion =~ s/\D//g;
10483: if ($newversion ne '2') {
10484: $newversion = 1;
10485: }
10486: $newsettings->{'recaptchaversion'} = $newversion;
10487: }
10488: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10489: $currpub = $current->{'recaptchakeys'}{'public'};
10490: $currpriv = $current->{'recaptchakeys'}{'private'};
10491: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10492: $newsettings->{'recaptchakeys'} = {
10493: public => '',
10494: private => '',
10495: }
10496: }
10497: }
10498: if ($current->{'captcha'} eq 'recaptcha') {
10499: $currversion = $current->{'recaptchaversion'};
10500: if ($currversion ne '2') {
10501: $currversion = 1;
10502: }
10503: }
10504: if ($currversion ne $newversion) {
10505: if ($container eq 'cancreate') {
10506: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10507: push(@{$changes->{'cancreate'}},'recaptchaversion');
10508: } elsif (!defined($changes->{'cancreate'})) {
10509: $changes->{'cancreate'} = ['recaptchaversion'];
10510: }
10511: } else {
10512: $changes->{'recaptchaversion'} = 1;
10513: }
10514: }
10515: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
10516: if ($container eq 'cancreate') {
10517: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10518: push(@{$changes->{'cancreate'}},'recaptchakeys');
10519: } elsif (!defined($changes->{'cancreate'})) {
10520: $changes->{'cancreate'} = ['recaptchakeys'];
10521: }
10522: } else {
10523: $changes->{'recaptchakeys'} = 1;
10524: }
10525: }
10526: return;
10527: }
10528:
10529: sub modify_usermodification {
10530: my ($dom,%domconfig) = @_;
10531: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
10532: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10533: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10534: if ($key eq 'selfcreate') {
10535: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10536: } else {
10537: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10538: }
10539: }
10540: }
10541: my @contexts = ('author','course');
10542: my %context_title = (
10543: author => 'In author context',
10544: course => 'In course context',
10545: );
10546: my @fields = ('lastname','firstname','middlename','generation',
10547: 'permanentemail','id');
10548: my %roles = (
10549: author => ['ca','aa'],
10550: course => ['st','ep','ta','in','cr'],
10551: );
10552: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10553: foreach my $context (@contexts) {
10554: foreach my $role (@{$roles{$context}}) {
10555: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10556: foreach my $item (@fields) {
10557: if (grep(/^\Q$item\E$/,@modifiable)) {
10558: $modifyhash{$context}{$role}{$item} = 1;
10559: } else {
10560: $modifyhash{$context}{$role}{$item} = 0;
10561: }
10562: }
10563: }
10564: if (ref($curr_usermodification{$context}) eq 'HASH') {
10565: foreach my $role (@{$roles{$context}}) {
10566: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10567: foreach my $field (@fields) {
10568: if ($modifyhash{$context}{$role}{$field} ne
10569: $curr_usermodification{$context}{$role}{$field}) {
10570: push(@{$changes{$context}},$role);
10571: last;
10572: }
10573: }
10574: }
10575: }
10576: } else {
10577: foreach my $context (@contexts) {
10578: foreach my $role (@{$roles{$context}}) {
10579: push(@{$changes{$context}},$role);
10580: }
10581: }
10582: }
10583: }
10584: my %usermodification_hash = (
10585: usermodification => \%modifyhash,
10586: );
10587: my $putresult = &Apache::lonnet::put_dom('configuration',
10588: \%usermodification_hash,$dom);
10589: if ($putresult eq 'ok') {
10590: if (keys(%changes) > 0) {
10591: $resulttext = &mt('Changes made: ').'<ul>';
10592: foreach my $context (@contexts) {
10593: if (ref($changes{$context}) eq 'ARRAY') {
10594: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10595: if (ref($changes{$context}) eq 'ARRAY') {
10596: foreach my $role (@{$changes{$context}}) {
10597: my $rolename;
10598: if ($role eq 'cr') {
10599: $rolename = &mt('Custom');
10600: } else {
10601: $rolename = &Apache::lonnet::plaintext($role);
10602: }
10603: my @modifiable;
10604: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
10605: foreach my $field (@fields) {
10606: if ($modifyhash{$context}{$role}{$field}) {
10607: push(@modifiable,$fieldtitles{$field});
10608: }
10609: }
10610: if (@modifiable > 0) {
10611: $resulttext .= join(', ',@modifiable);
10612: } else {
10613: $resulttext .= &mt('none');
10614: }
10615: $resulttext .= '</li>';
10616: }
10617: $resulttext .= '</ul></li>';
10618: }
10619: }
10620: }
10621: $resulttext .= '</ul>';
10622: } else {
10623: $resulttext = &mt('No changes made to user modification settings');
10624: }
10625: } else {
10626: $resulttext = '<span class="LC_error">'.
10627: &mt('An error occurred: [_1]',$putresult).'</span>';
10628: }
10629: return $resulttext;
10630: }
10631:
10632: sub modify_defaults {
10633: my ($dom,$lastactref,%domconfig) = @_;
10634: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
10635: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10636: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
10637: my @authtypes = ('internal','krb4','krb5','localauth');
10638: foreach my $item (@items) {
10639: $newvalues{$item} = $env{'form.'.$item};
10640: if ($item eq 'auth_def') {
10641: if ($newvalues{$item} ne '') {
10642: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10643: push(@errors,$item);
10644: }
10645: }
10646: } elsif ($item eq 'lang_def') {
10647: if ($newvalues{$item} ne '') {
10648: if ($newvalues{$item} =~ /^(\w+)/) {
10649: my $langcode = $1;
10650: if ($langcode ne 'x_chef') {
10651: if (code2language($langcode) eq '') {
10652: push(@errors,$item);
10653: }
10654: }
10655: } else {
10656: push(@errors,$item);
10657: }
10658: }
10659: } elsif ($item eq 'timezone_def') {
10660: if ($newvalues{$item} ne '') {
10661: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
10662: push(@errors,$item);
10663: }
10664: }
10665: } elsif ($item eq 'datelocale_def') {
10666: if ($newvalues{$item} ne '') {
10667: my @datelocale_ids = DateTime::Locale->ids();
10668: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10669: push(@errors,$item);
10670: }
10671: }
10672: } elsif ($item eq 'portal_def') {
10673: if ($newvalues{$item} ne '') {
10674: 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])\/?$/) {
10675: push(@errors,$item);
10676: }
10677: }
10678: }
10679: if (grep(/^\Q$item\E$/,@errors)) {
10680: $newvalues{$item} = $domdefaults{$item};
10681: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10682: $changes{$item} = 1;
10683: }
10684: $domdefaults{$item} = $newvalues{$item};
10685: }
10686: my %defaults_hash = (
10687: defaults => \%newvalues,
10688: );
10689: my $title = &defaults_titles();
10690:
10691: my $currinststatus;
10692: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10693: $currinststatus = $domconfig{'inststatus'};
10694: } else {
10695: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10696: $currinststatus = {
10697: inststatustypes => $usertypes,
10698: inststatusorder => $types,
10699: inststatusguest => [],
10700: };
10701: }
10702: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10703: my @allpos;
10704: my %guests;
10705: my %alltypes;
10706: my ($currtitles,$currguests,$currorder);
10707: if (ref($currinststatus) eq 'HASH') {
10708: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10709: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10710: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10711: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10712: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10713: }
10714: }
10715: unless (grep(/^\Q$type\E$/,@todelete)) {
10716: my $position = $env{'form.inststatus_pos_'.$type};
10717: $position =~ s/\D+//g;
10718: $allpos[$position] = $type;
10719: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10720: $alltypes{$type} =~ s/`//g;
10721: if ($env{'form.inststatus_guest_'.$type}) {
10722: $guests{$type} = 1;
10723: }
10724: }
10725: }
10726: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10727: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10728: }
10729: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10730: $currtitles =~ s/,$//;
10731: }
10732: }
10733: if ($env{'form.addinststatus'}) {
10734: my $newtype = $env{'form.addinststatus'};
10735: $newtype =~ s/\W//g;
10736: unless (exists($alltypes{$newtype})) {
10737: if ($env{'form.addinststatus_guest'}) {
10738: $guests{$newtype} = 1;
10739: }
10740: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10741: $alltypes{$newtype} =~ s/`//g;
10742: my $position = $env{'form.addinststatus_pos'};
10743: $position =~ s/\D+//g;
10744: if ($position ne '') {
10745: $allpos[$position] = $newtype;
10746: }
10747: }
10748: }
10749: my (@orderedstatus,@orderedguests);
10750: foreach my $type (@allpos) {
10751: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10752: push(@orderedstatus,$type);
10753: if ($guests{$type}) {
10754: push(@orderedguests,$type);
10755: }
10756: }
10757: }
10758: foreach my $type (keys(%alltypes)) {
10759: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10760: delete($alltypes{$type});
10761: }
10762: }
10763: $defaults_hash{'inststatus'} = {
10764: inststatustypes => \%alltypes,
10765: inststatusorder => \@orderedstatus,
10766: inststatusguest => \@orderedguests,
10767: };
10768: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10769: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10770: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10771: }
10772: }
10773: if ($currorder ne join(',',@orderedstatus)) {
10774: $changes{'inststatus'}{'inststatusorder'} = 1;
10775: }
10776: if ($currguests ne join(',',@orderedguests)) {
10777: $changes{'inststatus'}{'inststatusguest'} = 1;
10778: }
10779: my $newtitles;
10780: foreach my $item (@orderedstatus) {
10781: $newtitles .= $alltypes{$item}.',';
10782: }
10783: $newtitles =~ s/,$//;
10784: if ($currtitles ne $newtitles) {
10785: $changes{'inststatus'}{'inststatustypes'} = 1;
10786: }
10787: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10788: $dom);
10789: if ($putresult eq 'ok') {
10790: if (keys(%changes) > 0) {
10791: $resulttext = &mt('Changes made:').'<ul>';
10792: my $version = &Apache::lonnet::get_server_loncaparev($dom);
10793: 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";
10794: foreach my $item (sort(keys(%changes))) {
10795: if ($item eq 'inststatus') {
10796: if (ref($changes{'inststatus'}) eq 'HASH') {
10797: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10798: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10799: foreach my $type (@orderedstatus) {
10800: $resulttext .= $alltypes{$type}.', ';
10801: }
10802: $resulttext =~ s/, $//;
10803: $resulttext .= '</li>';
10804: }
10805: if ($changes{'inststatus'}{'inststatusguest'}) {
10806: $resulttext .= '<li>';
10807: if (@orderedguests) {
10808: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10809: foreach my $type (@orderedguests) {
10810: $resulttext .= $alltypes{$type}.', ';
10811: }
10812: $resulttext =~ s/, $//;
10813: } else {
10814: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10815: }
10816: $resulttext .= '</li>';
10817: }
10818: }
10819: } else {
10820: my $value = $env{'form.'.$item};
10821: if ($value eq '') {
10822: $value = &mt('none');
10823: } elsif ($item eq 'auth_def') {
10824: my %authnames = &authtype_names();
10825: my %shortauth = (
10826: internal => 'int',
10827: krb4 => 'krb4',
10828: krb5 => 'krb5',
10829: localauth => 'loc',
10830: );
10831: $value = $authnames{$shortauth{$value}};
10832: }
10833: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10834: $mailmsgtext .= "$title->{$item} set to $value\n";
10835: }
10836: }
10837: $resulttext .= '</ul>';
10838: $mailmsgtext .= "\n";
10839: my $cachetime = 24*60*60;
10840: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10841: if (ref($lastactref) eq 'HASH') {
10842: $lastactref->{'domdefaults'} = 1;
10843: }
10844: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
10845: my $notify = 1;
10846: if (ref($domconfig{'contacts'}) eq 'HASH') {
10847: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10848: $notify = 0;
10849: }
10850: }
10851: if ($notify) {
10852: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10853: "LON-CAPA Domain Settings Change - $dom",
10854: $mailmsgtext);
10855: }
10856: }
10857: } else {
10858: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
10859: }
10860: } else {
10861: $resulttext = '<span class="LC_error">'.
10862: &mt('An error occurred: [_1]',$putresult).'</span>';
10863: }
10864: if (@errors > 0) {
10865: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10866: foreach my $item (@errors) {
10867: $resulttext .= ' "'.$title->{$item}.'",';
10868: }
10869: $resulttext =~ s/,$//;
10870: }
10871: return $resulttext;
10872: }
10873:
10874: sub modify_scantron {
10875: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
10876: my ($resulttext,%confhash,%changes,$errors);
10877: my $custom = 'custom.tab';
10878: my $default = 'default.tab';
10879: my $servadm = $r->dir_config('lonAdmEMail');
10880: my ($configuserok,$author_ok,$switchserver) =
10881: &config_check($dom,$confname,$servadm);
10882: if ($env{'form.scantronformat.filename'} ne '') {
10883: my $error;
10884: if ($configuserok eq 'ok') {
10885: if ($switchserver) {
10886: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
10887: } else {
10888: if ($author_ok eq 'ok') {
10889: my ($result,$scantronurl) =
10890: &publishlogo($r,'upload','scantronformat',$dom,
10891: $confname,'scantron','','',$custom);
10892: if ($result eq 'ok') {
10893: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
10894: $changes{'scantronformat'} = 1;
10895: } else {
10896: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10897: }
10898: } else {
10899: $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);
10900: }
10901: }
10902: } else {
10903: $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);
10904: }
10905: if ($error) {
10906: &Apache::lonnet::logthis($error);
10907: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10908: }
10909: }
10910: if (ref($domconfig{'scantron'}) eq 'HASH') {
10911: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10912: if ($env{'form.scantronformat_del'}) {
10913: $confhash{'scantron'}{'scantronformat'} = '';
10914: $changes{'scantronformat'} = 1;
10915: }
10916: }
10917: }
10918: if (keys(%confhash) > 0) {
10919: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10920: $dom);
10921: if ($putresult eq 'ok') {
10922: if (keys(%changes) > 0) {
10923: if (ref($confhash{'scantron'}) eq 'HASH') {
10924: $resulttext = &mt('Changes made:').'<ul>';
10925: if ($confhash{'scantron'}{'scantronformat'} eq '') {
10926: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
10927: } else {
10928: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
10929: }
10930: $resulttext .= '</ul>';
10931: } else {
10932: $resulttext = &mt('Changes made to bubblesheet format file.');
10933: }
10934: $resulttext .= '</ul>';
10935: &Apache::loncommon::devalidate_domconfig_cache($dom);
10936: if (ref($lastactref) eq 'HASH') {
10937: $lastactref->{'domainconfig'} = 1;
10938: }
10939: } else {
10940: $resulttext = &mt('No changes made to bubblesheet format file');
10941: }
10942: } else {
10943: $resulttext = '<span class="LC_error">'.
10944: &mt('An error occurred: [_1]',$putresult).'</span>';
10945: }
10946: } else {
10947: $resulttext = &mt('No changes made to bubblesheet format file');
10948: }
10949: if ($errors) {
10950: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10951: $errors.'</ul>';
10952: }
10953: return $resulttext;
10954: }
10955:
10956: sub modify_coursecategories {
10957: my ($dom,$lastactref,%domconfig) = @_;
10958: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10959: $cathash);
10960: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
10961: my @catitems = ('unauth','auth');
10962: my @cattypes = ('std','domonly','codesrch','none');
10963: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10964: $cathash = $domconfig{'coursecategories'}{'cats'};
10965: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10966: $changes{'togglecats'} = 1;
10967: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10968: }
10969: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10970: $changes{'categorize'} = 1;
10971: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10972: }
10973: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10974: $changes{'togglecatscomm'} = 1;
10975: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10976: }
10977: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10978: $changes{'categorizecomm'} = 1;
10979: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10980:
10981: }
10982: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
10983: $changes{'togglecatsplace'} = 1;
10984: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
10985: }
10986: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
10987: $changes{'categorizeplace'} = 1;
10988: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
10989: }
10990: foreach my $item (@catitems) {
10991: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10992: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10993: $changes{$item} = 1;
10994: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10995: }
10996: }
10997: }
10998: } else {
10999: $changes{'togglecats'} = 1;
11000: $changes{'categorize'} = 1;
11001: $changes{'togglecatscomm'} = 1;
11002: $changes{'categorizecomm'} = 1;
11003: $changes{'togglecatsplace'} = 1;
11004: $changes{'categorizeplace'} = 1;
11005: $domconfig{'coursecategories'} = {
11006: togglecats => $env{'form.togglecats'},
11007: categorize => $env{'form.categorize'},
11008: togglecatscomm => $env{'form.togglecatscomm'},
11009: categorizecomm => $env{'form.categorizecomm'},
11010: togglecatsplace => $env{'form.togglecatsplace'},
11011: categorizeplace => $env{'form.categorizeplace'},
11012: };
11013: foreach my $item (@catitems) {
11014: if ($env{'form.coursecat_'.$item} ne 'std') {
11015: $changes{$item} = 1;
11016: }
11017: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11018: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11019: }
11020: }
11021: }
11022: if (ref($cathash) eq 'HASH') {
11023: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
11024: push (@deletecategory,'instcode::0');
11025: }
11026: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11027: push(@deletecategory,'communities::0');
11028: }
11029: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
11030: push(@deletecategory,'placement::0');
11031: }
11032: }
11033: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11034: if (ref($cathash) eq 'HASH') {
11035: if (@deletecategory > 0) {
11036: #FIXME Need to remove category from all courses using a deleted category
11037: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
11038: foreach my $item (@deletecategory) {
11039: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11040: delete($domconfig{'coursecategories'}{'cats'}{$item});
11041: $deletions{$item} = 1;
11042: &recurse_cat_deletes($item,$cathash,\%deletions);
11043: }
11044: }
11045: }
11046: foreach my $item (keys(%{$cathash})) {
11047: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11048: if ($cathash->{$item} ne $env{'form.'.$item}) {
11049: $reorderings{$item} = 1;
11050: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
11051: }
11052: if ($env{'form.addcategory_name_'.$item} ne '') {
11053: my $newcat = $env{'form.addcategory_name_'.$item};
11054: my $newdepth = $depth+1;
11055: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
11056: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
11057: $adds{$newitem} = 1;
11058: }
11059: if ($env{'form.subcat_'.$item} ne '') {
11060: my $newcat = $env{'form.subcat_'.$item};
11061: my $newdepth = $depth+1;
11062: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
11063: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
11064: $adds{$newitem} = 1;
11065: }
11066: }
11067: }
11068: if ($env{'form.instcode'} eq '1') {
11069: if (ref($cathash) eq 'HASH') {
11070: my $newitem = 'instcode::0';
11071: if ($cathash->{$newitem} eq '') {
11072: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
11073: $adds{$newitem} = 1;
11074: }
11075: } else {
11076: my $newitem = 'instcode::0';
11077: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
11078: $adds{$newitem} = 1;
11079: }
11080: }
11081: if ($env{'form.communities'} eq '1') {
11082: if (ref($cathash) eq 'HASH') {
11083: my $newitem = 'communities::0';
11084: if ($cathash->{$newitem} eq '') {
11085: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11086: $adds{$newitem} = 1;
11087: }
11088: } else {
11089: my $newitem = 'communities::0';
11090: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11091: $adds{$newitem} = 1;
11092: }
11093: }
11094: if ($env{'form.placement'} eq '1') {
11095: if (ref($cathash) eq 'HASH') {
11096: my $newitem = 'placement::0';
11097: if ($cathash->{$newitem} eq '') {
11098: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11099: $adds{$newitem} = 1;
11100: }
11101: } else {
11102: my $newitem = 'placement::0';
11103: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11104: $adds{$newitem} = 1;
11105: }
11106: }
11107: if ($env{'form.addcategory_name'} ne '') {
11108: if (($env{'form.addcategory_name'} ne 'instcode') &&
11109: ($env{'form.addcategory_name'} ne 'communities') &&
11110: ($env{'form.addcategory_name'} ne 'placement')) {
11111: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11112: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11113: $adds{$newitem} = 1;
11114: }
11115: }
11116: my $putresult;
11117: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11118: if (keys(%deletions) > 0) {
11119: foreach my $key (keys(%deletions)) {
11120: if ($predelallitems{$key} ne '') {
11121: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11122: }
11123: }
11124: }
11125: my (@chkcats,@chktrails,%chkallitems);
11126: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
11127: if (ref($chkcats[0]) eq 'ARRAY') {
11128: my $depth = 0;
11129: my $chg = 0;
11130: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11131: my $name = $chkcats[0][$i];
11132: my $item;
11133: if ($name eq '') {
11134: $chg ++;
11135: } else {
11136: $item = &escape($name).'::0';
11137: if ($chg) {
11138: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
11139: }
11140: $depth ++;
11141: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
11142: $depth --;
11143: }
11144: }
11145: }
11146: }
11147: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11148: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
11149: if ($putresult eq 'ok') {
11150: my %title = (
11151: togglecats => 'Show/Hide a course in catalog',
11152: categorize => 'Assign a category to a course',
11153: togglecatscomm => 'Show/Hide a community in catalog',
11154: categorizecomm => 'Assign a category to a community',
11155: );
11156: my %level = (
11157: dom => 'set in Domain ("Modify Course/Community")',
11158: crs => 'set in Course ("Course Configuration")',
11159: comm => 'set in Community ("Community Configuration")',
11160: none => 'No catalog',
11161: std => 'Standard catalog',
11162: domonly => 'Domain-only catalog',
11163: codesrch => 'Code search form',
11164: );
11165: $resulttext = &mt('Changes made:').'<ul>';
11166: if ($changes{'togglecats'}) {
11167: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11168: }
11169: if ($changes{'categorize'}) {
11170: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
11171: }
11172: if ($changes{'togglecatscomm'}) {
11173: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11174: }
11175: if ($changes{'categorizecomm'}) {
11176: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11177: }
11178: if ($changes{'unauth'}) {
11179: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11180: }
11181: if ($changes{'auth'}) {
11182: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11183: }
11184: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11185: my $cathash;
11186: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11187: $cathash = $domconfig{'coursecategories'}{'cats'};
11188: } else {
11189: $cathash = {};
11190: }
11191: my (@cats,@trails,%allitems);
11192: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11193: if (keys(%deletions) > 0) {
11194: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11195: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11196: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11197: }
11198: $resulttext .= '</ul></li>';
11199: }
11200: if (keys(%reorderings) > 0) {
11201: my %sort_by_trail;
11202: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11203: foreach my $key (keys(%reorderings)) {
11204: if ($allitems{$key} ne '') {
11205: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11206: }
11207: }
11208: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11209: $resulttext .= '<li>'.$trails[$trail].'</li>';
11210: }
11211: $resulttext .= '</ul></li>';
11212: }
11213: if (keys(%adds) > 0) {
11214: my %sort_by_trail;
11215: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11216: foreach my $key (keys(%adds)) {
11217: if ($allitems{$key} ne '') {
11218: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11219: }
11220: }
11221: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11222: $resulttext .= '<li>'.$trails[$trail].'</li>';
11223: }
11224: $resulttext .= '</ul></li>';
11225: }
11226: }
11227: $resulttext .= '</ul>';
11228: if ($changes{'unauth'} || $changes{'auth'}) {
11229: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11230: if ($changes{'auth'}) {
11231: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11232: }
11233: if ($changes{'unauth'}) {
11234: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11235: }
11236: my $cachetime = 24*60*60;
11237: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11238: if (ref($lastactref) eq 'HASH') {
11239: $lastactref->{'domdefaults'} = 1;
11240: }
11241: }
11242: } else {
11243: $resulttext = '<span class="LC_error">'.
11244: &mt('An error occurred: [_1]',$putresult).'</span>';
11245: }
11246: } else {
11247: $resulttext = &mt('No changes made to course and community categories');
11248: }
11249: return $resulttext;
11250: }
11251:
11252: sub modify_serverstatuses {
11253: my ($dom,%domconfig) = @_;
11254: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11255: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11256: %currserverstatus = %{$domconfig{'serverstatuses'}};
11257: }
11258: my @pages = &serverstatus_pages();
11259: foreach my $type (@pages) {
11260: $newserverstatus{$type}{'namedusers'} = '';
11261: $newserverstatus{$type}{'machines'} = '';
11262: if (defined($env{'form.'.$type.'_namedusers'})) {
11263: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11264: my @okusers;
11265: foreach my $user (@users) {
11266: my ($uname,$udom) = split(/:/,$user);
11267: if (($udom =~ /^$match_domain$/) &&
11268: (&Apache::lonnet::domain($udom)) &&
11269: ($uname =~ /^$match_username$/)) {
11270: if (!grep(/^\Q$user\E/,@okusers)) {
11271: push(@okusers,$user);
11272: }
11273: }
11274: }
11275: if (@okusers > 0) {
11276: @okusers = sort(@okusers);
11277: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11278: }
11279: }
11280: if (defined($env{'form.'.$type.'_machines'})) {
11281: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11282: my @okmachines;
11283: foreach my $ip (@machines) {
11284: my @parts = split(/\./,$ip);
11285: next if (@parts < 4);
11286: my $badip = 0;
11287: for (my $i=0; $i<4; $i++) {
11288: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11289: $badip = 1;
11290: last;
11291: }
11292: }
11293: if (!$badip) {
11294: push(@okmachines,$ip);
11295: }
11296: }
11297: @okmachines = sort(@okmachines);
11298: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11299: }
11300: }
11301: my %serverstatushash = (
11302: serverstatuses => \%newserverstatus,
11303: );
11304: foreach my $type (@pages) {
11305: foreach my $setting ('namedusers','machines') {
11306: my (@current,@new);
11307: if (ref($currserverstatus{$type}) eq 'HASH') {
11308: if ($currserverstatus{$type}{$setting} ne '') {
11309: @current = split(/,/,$currserverstatus{$type}{$setting});
11310: }
11311: }
11312: if ($newserverstatus{$type}{$setting} ne '') {
11313: @new = split(/,/,$newserverstatus{$type}{$setting});
11314: }
11315: if (@current > 0) {
11316: if (@new > 0) {
11317: foreach my $item (@current) {
11318: if (!grep(/^\Q$item\E$/,@new)) {
11319: $changes{$type}{$setting} = 1;
11320: last;
11321: }
11322: }
11323: foreach my $item (@new) {
11324: if (!grep(/^\Q$item\E$/,@current)) {
11325: $changes{$type}{$setting} = 1;
11326: last;
11327: }
11328: }
11329: } else {
11330: $changes{$type}{$setting} = 1;
11331: }
11332: } elsif (@new > 0) {
11333: $changes{$type}{$setting} = 1;
11334: }
11335: }
11336: }
11337: if (keys(%changes) > 0) {
11338: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
11339: my $putresult = &Apache::lonnet::put_dom('configuration',
11340: \%serverstatushash,$dom);
11341: if ($putresult eq 'ok') {
11342: $resulttext .= &mt('Changes made:').'<ul>';
11343: foreach my $type (@pages) {
11344: if (ref($changes{$type}) eq 'HASH') {
11345: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
11346: if ($changes{$type}{'namedusers'}) {
11347: if ($newserverstatus{$type}{'namedusers'} eq '') {
11348: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11349: } else {
11350: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11351: }
11352: }
11353: if ($changes{$type}{'machines'}) {
11354: if ($newserverstatus{$type}{'machines'} eq '') {
11355: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11356: } else {
11357: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11358: }
11359:
11360: }
11361: $resulttext .= '</ul></li>';
11362: }
11363: }
11364: $resulttext .= '</ul>';
11365: } else {
11366: $resulttext = '<span class="LC_error">'.
11367: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11368:
11369: }
11370: } else {
11371: $resulttext = &mt('No changes made to access to server status pages');
11372: }
11373: return $resulttext;
11374: }
11375:
11376: sub modify_helpsettings {
11377: my ($r,$dom,$confname,%domconfig) = @_;
11378: my ($resulttext,$errors,%changes,%helphash);
11379: my %defaultchecked = ('submitbugs' => 'on');
11380: my @offon = ('off','on');
11381: my @toggles = ('submitbugs');
11382: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11383: foreach my $item (@toggles) {
11384: if ($defaultchecked{$item} eq 'on') {
11385: if ($domconfig{'helpsettings'}{$item} eq '') {
11386: if ($env{'form.'.$item} eq '0') {
11387: $changes{$item} = 1;
11388: }
11389: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11390: $changes{$item} = 1;
11391: }
11392: } elsif ($defaultchecked{$item} eq 'off') {
11393: if ($domconfig{'helpsettings'}{$item} eq '') {
11394: if ($env{'form.'.$item} eq '1') {
11395: $changes{$item} = 1;
11396: }
11397: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11398: $changes{$item} = 1;
11399: }
11400: }
11401: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11402: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11403: }
11404: }
11405: }
11406: my $putresult;
11407: if (keys(%changes) > 0) {
11408: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
11409: if ($putresult eq 'ok') {
11410: $resulttext = &mt('Changes made:').'<ul>';
11411: foreach my $item (sort(keys(%changes))) {
11412: if ($item eq 'submitbugs') {
11413: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11414: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11415: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11416: }
11417: }
11418: $resulttext .= '</ul>';
11419: } else {
11420: $resulttext = &mt('No changes made to help settings');
11421: $errors .= '<li><span class="LC_error">'.
11422: &mt('An error occurred storing the settings: [_1]',
11423: $putresult).'</span></li>';
11424: }
11425: }
11426: if ($errors) {
11427: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
11428: $errors.'</ul>';
11429: }
11430: return $resulttext;
11431: }
11432:
11433: sub modify_coursedefaults {
11434: my ($dom,$lastactref,%domconfig) = @_;
11435: my ($resulttext,$errors,%changes,%defaultshash);
11436: my %defaultchecked = (
11437: 'canuse_pdfforms' => 'off',
11438: 'uselcmath' => 'on',
11439: 'usejsme' => 'on'
11440: );
11441: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
11442: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
11443: 'uploadquota_community','uploadquota_textbook','uploadquota_placement');
11444: my @types = ('official','unofficial','community','textbook','placement');
11445: my %staticdefaults = (
11446: anonsurvey_threshold => 10,
11447: uploadquota => 500,
11448: postsubmit => 60,
11449: );
11450:
11451: $defaultshash{'coursedefaults'} = {};
11452:
11453: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11454: if ($domconfig{'coursedefaults'} eq '') {
11455: $domconfig{'coursedefaults'} = {};
11456: }
11457: }
11458:
11459: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11460: foreach my $item (@toggles) {
11461: if ($defaultchecked{$item} eq 'on') {
11462: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11463: ($env{'form.'.$item} eq '0')) {
11464: $changes{$item} = 1;
11465: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11466: $changes{$item} = 1;
11467: }
11468: } elsif ($defaultchecked{$item} eq 'off') {
11469: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11470: ($env{'form.'.$item} eq '1')) {
11471: $changes{$item} = 1;
11472: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11473: $changes{$item} = 1;
11474: }
11475: }
11476: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11477: }
11478: foreach my $item (@numbers) {
11479: my ($currdef,$newdef);
11480: $newdef = $env{'form.'.$item};
11481: if ($item eq 'anonsurvey_threshold') {
11482: $currdef = $domconfig{'coursedefaults'}{$item};
11483: $newdef =~ s/\D//g;
11484: if ($newdef eq '' || $newdef < 1) {
11485: $newdef = 1;
11486: }
11487: $defaultshash{'coursedefaults'}{$item} = $newdef;
11488: } else {
11489: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
11490: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11491: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
11492: }
11493: $newdef =~ s/[^\w.\-]//g;
11494: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
11495: }
11496: if ($currdef ne $newdef) {
11497: my $staticdef;
11498: if ($item eq 'anonsurvey_threshold') {
11499: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11500: $changes{$item} = 1;
11501: }
11502: } else {
11503: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
11504: $changes{'uploadquota'} = 1;
11505: }
11506: }
11507: }
11508: }
11509: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11510: my @currclonecode;
11511: if (ref($currclone) eq 'HASH') {
11512: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11513: @currclonecode = @{$currclone->{'instcode'}};
11514: }
11515: }
11516: my $newclone;
11517: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11518: $newclone = $env{'form.canclone'};
11519: }
11520: if ($newclone eq 'instcode') {
11521: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11522: my (%codedefaults,@code_order,@clonecode);
11523: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11524: \@code_order);
11525: foreach my $item (@code_order) {
11526: if (grep(/^\Q$item\E$/,@newcodes)) {
11527: push(@clonecode,$item);
11528: }
11529: }
11530: if (@clonecode) {
11531: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11532: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11533: if (@diffs) {
11534: $changes{'canclone'} = 1;
11535: }
11536: } else {
11537: $newclone eq '';
11538: }
11539: } elsif ($newclone ne '') {
11540: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11541: }
11542: if ($newclone ne $currclone) {
11543: $changes{'canclone'} = 1;
11544: }
11545: my %credits;
11546: foreach my $type (@types) {
11547: unless ($type eq 'community') {
11548: $credits{$type} = $env{'form.'.$type.'_credits'};
11549: $credits{$type} =~ s/[^\d.]+//g;
11550: }
11551: }
11552: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11553: ($env{'form.coursecredits'} eq '1')) {
11554: $changes{'coursecredits'} = 1;
11555: foreach my $type (keys(%credits)) {
11556: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11557: }
11558: } else {
11559: if ($env{'form.coursecredits'} eq '1') {
11560: foreach my $type (@types) {
11561: unless ($type eq 'community') {
11562: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11563: $changes{'coursecredits'} = 1;
11564: }
11565: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11566: }
11567: }
11568: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11569: foreach my $type (@types) {
11570: unless ($type eq 'community') {
11571: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11572: $changes{'coursecredits'} = 1;
11573: last;
11574: }
11575: }
11576: }
11577: }
11578: }
11579: if ($env{'form.postsubmit'} eq '1') {
11580: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11581: my %currtimeout;
11582: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11583: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11584: $changes{'postsubmit'} = 1;
11585: }
11586: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11587: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11588: }
11589: } else {
11590: $changes{'postsubmit'} = 1;
11591: }
11592: foreach my $type (@types) {
11593: my $timeout = $env{'form.'.$type.'_timeout'};
11594: $timeout =~ s/\D//g;
11595: if ($timeout == $staticdefaults{'postsubmit'}) {
11596: $timeout = '';
11597: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11598: $timeout = '0';
11599: }
11600: unless ($timeout eq '') {
11601: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11602: }
11603: if (exists($currtimeout{$type})) {
11604: if ($timeout ne $currtimeout{$type}) {
11605: $changes{'postsubmit'} = 1;
11606: }
11607: } elsif ($timeout ne '') {
11608: $changes{'postsubmit'} = 1;
11609: }
11610: }
11611: } else {
11612: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11613: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11614: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11615: $changes{'postsubmit'} = 1;
11616: }
11617: } else {
11618: $changes{'postsubmit'} = 1;
11619: }
11620: }
11621: }
11622: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11623: $dom);
11624: if ($putresult eq 'ok') {
11625: if (keys(%changes) > 0) {
11626: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11627: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
11628: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
11629: ($changes{'canclone'})) {
11630: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11631: if ($changes{$item}) {
11632: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11633: }
11634: }
11635: if ($changes{'coursecredits'}) {
11636: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11637: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11638: $domdefaults{$type.'credits'} =
11639: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11640: }
11641: }
11642: }
11643: if ($changes{'postsubmit'}) {
11644: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11645: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11646: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11647: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11648: $domdefaults{$type.'postsubtimeout'} =
11649: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11650: }
11651: }
11652: }
11653: }
11654: if ($changes{'uploadquota'}) {
11655: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11656: foreach my $type (@types) {
11657: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11658: }
11659: }
11660: }
11661: if ($changes{'canclone'}) {
11662: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11663: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11664: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11665: if (@clonecodes) {
11666: $domdefaults{'canclone'} = join('+',@clonecodes);
11667: }
11668: }
11669: } else {
11670: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11671: }
11672: }
11673: my $cachetime = 24*60*60;
11674: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11675: if (ref($lastactref) eq 'HASH') {
11676: $lastactref->{'domdefaults'} = 1;
11677: }
11678: }
11679: $resulttext = &mt('Changes made:').'<ul>';
11680: foreach my $item (sort(keys(%changes))) {
11681: if ($item eq 'canuse_pdfforms') {
11682: if ($env{'form.'.$item} eq '1') {
11683: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
11684: } else {
11685: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
11686: }
11687: } elsif ($item eq 'uselcmath') {
11688: if ($env{'form.'.$item} eq '1') {
11689: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
11690: } else {
11691: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11692: }
11693: } elsif ($item eq 'usejsme') {
11694: if ($env{'form.'.$item} eq '1') {
11695: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11696: } else {
11697: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
11698: }
11699: } elsif ($item eq 'anonsurvey_threshold') {
11700: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
11701: } elsif ($item eq 'uploadquota') {
11702: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11703: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11704: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11705: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
11706: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11707: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
11708: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11709: '</ul>'.
11710: '</li>';
11711: } else {
11712: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11713: }
11714: } elsif ($item eq 'postsubmit') {
11715: if ($domdefaults{'postsubmit'} eq 'off') {
11716: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11717: } else {
11718: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11719: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11720: $resulttext .= &mt('durations:').'<ul>';
11721: foreach my $type (@types) {
11722: $resulttext .= '<li>';
11723: my $timeout;
11724: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11725: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11726: }
11727: my $display;
11728: if ($timeout eq '0') {
11729: $display = &mt('unlimited');
11730: } elsif ($timeout eq '') {
11731: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11732: } else {
11733: $display = &mt('[quant,_1,second]',$timeout);
11734: }
11735: if ($type eq 'community') {
11736: $resulttext .= &mt('Communities');
11737: } elsif ($type eq 'official') {
11738: $resulttext .= &mt('Official courses');
11739: } elsif ($type eq 'unofficial') {
11740: $resulttext .= &mt('Unofficial courses');
11741: } elsif ($type eq 'textbook') {
11742: $resulttext .= &mt('Textbook courses');
11743: } elsif ($type eq 'placement') {
11744: $resulttext .= &mt('Placement tests');
11745: }
11746: $resulttext .= ' -- '.$display.'</li>';
11747: }
11748: $resulttext .= '</ul>';
11749: }
11750: $resulttext .= '</li>';
11751: }
11752: } elsif ($item eq 'coursecredits') {
11753: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11754: if (($domdefaults{'officialcredits'} eq '') &&
11755: ($domdefaults{'unofficialcredits'} eq '') &&
11756: ($domdefaults{'textbookcredits'} eq '')) {
11757: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11758: } else {
11759: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11760: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11761: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
11762: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
11763: '</ul>'.
11764: '</li>';
11765: }
11766: } else {
11767: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11768: }
11769: } elsif ($item eq 'canclone') {
11770: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11771: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11772: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11773: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11774: }
11775: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11776: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11777: } else {
11778: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
11779: }
11780: }
11781: }
11782: $resulttext .= '</ul>';
11783: } else {
11784: $resulttext = &mt('No changes made to course defaults');
11785: }
11786: } else {
11787: $resulttext = '<span class="LC_error">'.
11788: &mt('An error occurred: [_1]',$putresult).'</span>';
11789: }
11790: return $resulttext;
11791: }
11792:
11793: sub modify_selfenrollment {
11794: my ($dom,$lastactref,%domconfig) = @_;
11795: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
11796: my @types = ('official','unofficial','community','textbook','placement');
11797: my %titles = &tool_titles();
11798: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
11799: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
11800: $ordered{'default'} = ['types','registered','approval','limit'];
11801:
11802: my (%roles,%shown,%toplevel);
11803: $roles{'0'} = &Apache::lonnet::plaintext('dc');
11804:
11805: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
11806: if ($domconfig{'selfenrollment'} eq '') {
11807: $domconfig{'selfenrollment'} = {};
11808: }
11809: }
11810: %toplevel = (
11811: admin => 'Configuration Rights',
11812: default => 'Default settings',
11813: validation => 'Validation of self-enrollment requests',
11814: );
11815: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
11816:
11817: if (ref($ordered{'admin'}) eq 'ARRAY') {
11818: foreach my $item (@{$ordered{'admin'}}) {
11819: foreach my $type (@types) {
11820: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
11821: $selfenrollhash{'admin'}{$type}{$item} = 1;
11822: } else {
11823: $selfenrollhash{'admin'}{$type}{$item} = 0;
11824: }
11825: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
11826: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
11827: if ($selfenrollhash{'admin'}{$type}{$item} ne
11828: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
11829: push(@{$changes{'admin'}{$type}},$item);
11830: }
11831: } else {
11832: if (!$selfenrollhash{'admin'}{$type}{$item}) {
11833: push(@{$changes{'admin'}{$type}},$item);
11834: }
11835: }
11836: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
11837: push(@{$changes{'admin'}{$type}},$item);
11838: }
11839: }
11840: }
11841: }
11842:
11843: foreach my $item (@{$ordered{'default'}}) {
11844: foreach my $type (@types) {
11845: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
11846: if ($item eq 'types') {
11847: unless (($value eq 'all') || ($value eq 'dom')) {
11848: $value = '';
11849: }
11850: } elsif ($item eq 'registered') {
11851: unless ($value eq '1') {
11852: $value = 0;
11853: }
11854: } elsif ($item eq 'approval') {
11855: unless ($value =~ /^[012]$/) {
11856: $value = 0;
11857: }
11858: } else {
11859: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11860: $value = 'none';
11861: }
11862: }
11863: $selfenrollhash{'default'}{$type}{$item} = $value;
11864: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
11865: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11866: if ($selfenrollhash{'default'}{$type}{$item} ne
11867: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
11868: push(@{$changes{'default'}{$type}},$item);
11869: }
11870: } else {
11871: push(@{$changes{'default'}{$type}},$item);
11872: }
11873: } else {
11874: push(@{$changes{'default'}{$type}},$item);
11875: }
11876: if ($item eq 'limit') {
11877: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11878: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
11879: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
11880: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
11881: }
11882: } else {
11883: $selfenrollhash{'default'}{$type}{'cap'} = '';
11884: }
11885: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11886: if ($selfenrollhash{'default'}{$type}{'cap'} ne
11887: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
11888: push(@{$changes{'default'}{$type}},'cap');
11889: }
11890: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
11891: push(@{$changes{'default'}{$type}},'cap');
11892: }
11893: }
11894: }
11895: }
11896:
11897: foreach my $item (@{$itemsref}) {
11898: if ($item eq 'fields') {
11899: my @changed;
11900: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
11901: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
11902: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
11903: }
11904: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11905: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
11906: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
11907: $domconfig{'selfenrollment'}{'validation'}{$item});
11908: } else {
11909: @changed = @{$selfenrollhash{'validation'}{$item}};
11910: }
11911: } else {
11912: @changed = @{$selfenrollhash{'validation'}{$item}};
11913: }
11914: if (@changed) {
11915: if ($selfenrollhash{'validation'}{$item}) {
11916: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
11917: } else {
11918: $changes{'validation'}{$item} = &mt('None');
11919: }
11920: }
11921: } else {
11922: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
11923: if ($item eq 'markup') {
11924: if ($env{'form.selfenroll_validation_'.$item}) {
11925: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11926: }
11927: }
11928: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11929: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
11930: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
11931: }
11932: }
11933: }
11934: }
11935:
11936: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
11937: $dom);
11938: if ($putresult eq 'ok') {
11939: if (keys(%changes) > 0) {
11940: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11941: $resulttext = &mt('Changes made:').'<ul>';
11942: foreach my $key ('admin','default','validation') {
11943: if (ref($changes{$key}) eq 'HASH') {
11944: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
11945: if ($key eq 'validation') {
11946: foreach my $item (@{$itemsref}) {
11947: if (exists($changes{$key}{$item})) {
11948: if ($item eq 'markup') {
11949: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11950: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
11951: } else {
11952: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11953: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
11954: }
11955: }
11956: }
11957: } else {
11958: foreach my $type (@types) {
11959: if ($type eq 'community') {
11960: $roles{'1'} = &mt('Community personnel');
11961: } else {
11962: $roles{'1'} = &mt('Course personnel');
11963: }
11964: if (ref($changes{$key}{$type}) eq 'ARRAY') {
11965: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11966: if ($key eq 'admin') {
11967: my @mgrdc = ();
11968: if (ref($ordered{$key}) eq 'ARRAY') {
11969: foreach my $item (@{$ordered{'admin'}}) {
11970: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11971: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
11972: push(@mgrdc,$item);
11973: }
11974: }
11975: }
11976: if (@mgrdc) {
11977: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
11978: } else {
11979: delete($domdefaults{$type.'selfenrolladmdc'});
11980: }
11981: }
11982: } else {
11983: if (ref($ordered{$key}) eq 'ARRAY') {
11984: foreach my $item (@{$ordered{$key}}) {
11985: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11986: $domdefaults{$type.'selfenroll'.$item} =
11987: $selfenrollhash{$key}{$type}{$item};
11988: }
11989: }
11990: }
11991: }
11992: }
11993: $resulttext .= '<li>'.$titles{$type}.'<ul>';
11994: foreach my $item (@{$ordered{$key}}) {
11995: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11996: $resulttext .= '<li>';
11997: if ($key eq 'admin') {
11998: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
11999: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12000: } else {
12001: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12002: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12003: }
12004: $resulttext .= '</li>';
12005: }
12006: }
12007: $resulttext .= '</ul></li>';
12008: }
12009: }
12010: $resulttext .= '</ul></li>';
12011: }
12012: }
12013: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12014: my $cachetime = 24*60*60;
12015: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12016: if (ref($lastactref) eq 'HASH') {
12017: $lastactref->{'domdefaults'} = 1;
12018: }
12019: }
12020: }
12021: $resulttext .= '</ul>';
12022: } else {
12023: $resulttext = &mt('No changes made to self-enrollment settings');
12024: }
12025: } else {
12026: $resulttext = '<span class="LC_error">'.
12027: &mt('An error occurred: [_1]',$putresult).'</span>';
12028: }
12029: return $resulttext;
12030: }
12031:
12032: sub modify_usersessions {
12033: my ($dom,$lastactref,%domconfig) = @_;
12034: my @hostingtypes = ('version','excludedomain','includedomain');
12035: my @offloadtypes = ('primary','default');
12036: my %types = (
12037: remote => \@hostingtypes,
12038: hosted => \@hostingtypes,
12039: spares => \@offloadtypes,
12040: );
12041: my @prefixes = ('remote','hosted','spares');
12042: my @lcversions = &Apache::lonnet::all_loncaparevs();
12043: my (%by_ip,%by_location,@intdoms);
12044: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12045: my @locations = sort(keys(%by_location));
12046: my (%defaultshash,%changes);
12047: foreach my $prefix (@prefixes) {
12048: $defaultshash{'usersessions'}{$prefix} = {};
12049: }
12050: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12051: my $resulttext;
12052: my %iphost = &Apache::lonnet::get_iphost();
12053: foreach my $prefix (@prefixes) {
12054: next if ($prefix eq 'spares');
12055: foreach my $type (@{$types{$prefix}}) {
12056: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12057: if ($type eq 'version') {
12058: my $value = $env{'form.'.$prefix.'_'.$type};
12059: my $okvalue;
12060: if ($value ne '') {
12061: if (grep(/^\Q$value\E$/,@lcversions)) {
12062: $okvalue = $value;
12063: }
12064: }
12065: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12066: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12067: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12068: if ($inuse == 0) {
12069: $changes{$prefix}{$type} = 1;
12070: } else {
12071: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12072: $changes{$prefix}{$type} = 1;
12073: }
12074: if ($okvalue ne '') {
12075: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12076: }
12077: }
12078: } else {
12079: if (($inuse == 1) && ($okvalue ne '')) {
12080: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12081: $changes{$prefix}{$type} = 1;
12082: }
12083: }
12084: } else {
12085: if (($inuse == 1) && ($okvalue ne '')) {
12086: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12087: $changes{$prefix}{$type} = 1;
12088: }
12089: }
12090: } else {
12091: if (($inuse == 1) && ($okvalue ne '')) {
12092: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12093: $changes{$prefix}{$type} = 1;
12094: }
12095: }
12096: } else {
12097: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12098: my @okvals;
12099: foreach my $val (@vals) {
12100: if ($val =~ /:/) {
12101: my @items = split(/:/,$val);
12102: foreach my $item (@items) {
12103: if (ref($by_location{$item}) eq 'ARRAY') {
12104: push(@okvals,$item);
12105: }
12106: }
12107: } else {
12108: if (ref($by_location{$val}) eq 'ARRAY') {
12109: push(@okvals,$val);
12110: }
12111: }
12112: }
12113: @okvals = sort(@okvals);
12114: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12115: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12116: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12117: if ($inuse == 0) {
12118: $changes{$prefix}{$type} = 1;
12119: } else {
12120: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12121: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12122: if (@changed > 0) {
12123: $changes{$prefix}{$type} = 1;
12124: }
12125: }
12126: } else {
12127: if ($inuse == 1) {
12128: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12129: $changes{$prefix}{$type} = 1;
12130: }
12131: }
12132: } else {
12133: if ($inuse == 1) {
12134: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12135: $changes{$prefix}{$type} = 1;
12136: }
12137: }
12138: } else {
12139: if ($inuse == 1) {
12140: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12141: $changes{$prefix}{$type} = 1;
12142: }
12143: }
12144: }
12145: }
12146: }
12147:
12148: my @alldoms = &Apache::lonnet::all_domains();
12149: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12150: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12151: my $savespares;
12152:
12153: foreach my $lonhost (sort(keys(%servers))) {
12154: my $serverhomeID =
12155: &Apache::lonnet::get_server_homeID($servers{$lonhost});
12156: my $serverhostname = &Apache::lonnet::hostname($lonhost);
12157: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12158: my %spareschg;
12159: foreach my $type (@{$types{'spares'}}) {
12160: my @okspares;
12161: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12162: foreach my $server (@checked) {
12163: if (&Apache::lonnet::hostname($server) ne '') {
12164: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12165: unless (grep(/^\Q$server\E$/,@okspares)) {
12166: push(@okspares,$server);
12167: }
12168: }
12169: }
12170: }
12171: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12172: my $newspare;
12173: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12174: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
12175: $newspare = $new;
12176: }
12177: }
12178: my @spares;
12179: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12180: @spares = sort(@okspares,$newspare);
12181: } else {
12182: @spares = sort(@okspares);
12183: }
12184: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
12185: if (ref($spareid{$lonhost}) eq 'HASH') {
12186: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
12187: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
12188: if (@diffs > 0) {
12189: $spareschg{$type} = 1;
12190: }
12191: }
12192: }
12193: }
12194: if (keys(%spareschg) > 0) {
12195: $changes{'spares'}{$lonhost} = \%spareschg;
12196: }
12197: }
12198: $defaultshash{'usersessions'}{'offloadnow'} = {};
12199: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12200: my @okoffload;
12201: if (@offloadnow) {
12202: foreach my $server (@offloadnow) {
12203: if (&Apache::lonnet::hostname($server) ne '') {
12204: unless (grep(/^\Q$server\E$/,@okoffload)) {
12205: push(@okoffload,$server);
12206: }
12207: }
12208: }
12209: if (@okoffload) {
12210: foreach my $lonhost (@okoffload) {
12211: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12212: }
12213: }
12214: }
12215: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12216: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12217: if (ref($changes{'spares'}) eq 'HASH') {
12218: if (keys(%{$changes{'spares'}}) > 0) {
12219: $savespares = 1;
12220: }
12221: }
12222: } else {
12223: $savespares = 1;
12224: }
12225: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12226: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12227: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12228: $changes{'offloadnow'} = 1;
12229: last;
12230: }
12231: }
12232: unless ($changes{'offloadnow'}) {
12233: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12234: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12235: $changes{'offloadnow'} = 1;
12236: last;
12237: }
12238: }
12239: }
12240: } elsif (@okoffload) {
12241: $changes{'offloadnow'} = 1;
12242: }
12243: } elsif (@okoffload) {
12244: $changes{'offloadnow'} = 1;
12245: }
12246: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12247: if ((keys(%changes) > 0) || ($savespares)) {
12248: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12249: $dom);
12250: if ($putresult eq 'ok') {
12251: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12252: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12253: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12254: }
12255: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12256: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12257: }
12258: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12259: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12260: }
12261: }
12262: my $cachetime = 24*60*60;
12263: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12264: if (ref($lastactref) eq 'HASH') {
12265: $lastactref->{'domdefaults'} = 1;
12266: }
12267: if (keys(%changes) > 0) {
12268: my %lt = &usersession_titles();
12269: $resulttext = &mt('Changes made:').'<ul>';
12270: foreach my $prefix (@prefixes) {
12271: if (ref($changes{$prefix}) eq 'HASH') {
12272: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12273: if ($prefix eq 'spares') {
12274: if (ref($changes{$prefix}) eq 'HASH') {
12275: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12276: $resulttext .= '<li><b>'.$lonhost.'</b> ';
12277: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
12278: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12279: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12280: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12281: foreach my $type (@{$types{$prefix}}) {
12282: if ($changes{$prefix}{$lonhost}{$type}) {
12283: my $offloadto = &mt('None');
12284: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12285: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12286: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12287: }
12288: }
12289: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
12290: }
12291: }
12292: }
12293: $resulttext .= '</li>';
12294: }
12295: }
12296: } else {
12297: foreach my $type (@{$types{$prefix}}) {
12298: if (defined($changes{$prefix}{$type})) {
12299: my $newvalue;
12300: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12301: if (ref($defaultshash{'usersessions'}{$prefix})) {
12302: if ($type eq 'version') {
12303: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12304: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12305: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12306: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12307: }
12308: }
12309: }
12310: }
12311: if ($newvalue eq '') {
12312: if ($type eq 'version') {
12313: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12314: } else {
12315: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12316: }
12317: } else {
12318: if ($type eq 'version') {
12319: $newvalue .= ' '.&mt('(or later)');
12320: }
12321: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
12322: }
12323: }
12324: }
12325: }
12326: $resulttext .= '</ul>';
12327: }
12328: }
12329: if ($changes{'offloadnow'}) {
12330: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12331: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12332: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12333: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12334: $resulttext .= '<li>'.$lonhost.'</li>';
12335: }
12336: $resulttext .= '</ul>';
12337: } else {
12338: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12339: }
12340: } else {
12341: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12342: }
12343: }
12344: $resulttext .= '</ul>';
12345: } else {
12346: $resulttext = $nochgmsg;
12347: }
12348: } else {
12349: $resulttext = '<span class="LC_error">'.
12350: &mt('An error occurred: [_1]',$putresult).'</span>';
12351: }
12352: } else {
12353: $resulttext = $nochgmsg;
12354: }
12355: return $resulttext;
12356: }
12357:
12358: sub modify_loadbalancing {
12359: my ($dom,%domconfig) = @_;
12360: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12361: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12362: my ($othertitle,$usertypes,$types) =
12363: &Apache::loncommon::sorted_inst_types($dom);
12364: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12365: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
12366: my @sparestypes = ('primary','default');
12367: my %typetitles = &sparestype_titles();
12368: my $resulttext;
12369: my (%currbalancer,%currtargets,%currrules,%existing);
12370: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12371: %existing = %{$domconfig{'loadbalancing'}};
12372: }
12373: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12374: \%currtargets,\%currrules);
12375: my ($saveloadbalancing,%defaultshash,%changes);
12376: my ($alltypes,$othertypes,$titles) =
12377: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12378: my %ruletitles = &offloadtype_text();
12379: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12380: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12381: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12382: if ($balancer eq '') {
12383: next;
12384: }
12385: if (!exists($servers{$balancer})) {
12386: if (exists($currbalancer{$balancer})) {
12387: push(@{$changes{'delete'}},$balancer);
12388: }
12389: next;
12390: }
12391: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12392: push(@{$changes{'delete'}},$balancer);
12393: next;
12394: }
12395: if (!exists($currbalancer{$balancer})) {
12396: push(@{$changes{'add'}},$balancer);
12397: }
12398: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12399: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12400: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12401: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12402: $saveloadbalancing = 1;
12403: }
12404: foreach my $sparetype (@sparestypes) {
12405: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12406: my @offloadto;
12407: foreach my $target (@targets) {
12408: if (($servers{$target}) && ($target ne $balancer)) {
12409: if ($sparetype eq 'default') {
12410: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12411: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
12412: }
12413: }
12414: unless(grep(/^\Q$target\E$/,@offloadto)) {
12415: push(@offloadto,$target);
12416: }
12417: }
12418: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
12419: }
12420: }
12421: if (ref($currtargets{$balancer}) eq 'HASH') {
12422: foreach my $sparetype (@sparestypes) {
12423: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12424: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
12425: if (@targetdiffs > 0) {
12426: $changes{'curr'}{$balancer}{'targets'} = 1;
12427: }
12428: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12429: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12430: $changes{'curr'}{$balancer}{'targets'} = 1;
12431: }
12432: }
12433: }
12434: } else {
12435: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
12436: foreach my $sparetype (@sparestypes) {
12437: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12438: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12439: $changes{'curr'}{$balancer}{'targets'} = 1;
12440: }
12441: }
12442: }
12443: }
12444: }
12445: my $ishomedom;
12446: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12447: $ishomedom = 1;
12448: }
12449: if (ref($alltypes) eq 'ARRAY') {
12450: foreach my $type (@{$alltypes}) {
12451: my $rule;
12452: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
12453: (!$ishomedom)) {
12454: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12455: }
12456: if ($rule eq 'specific') {
12457: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12458: if (exists($servers{$specifiedhost})) {
12459: $rule = $specifiedhost;
12460: }
12461: }
12462: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12463: if (ref($currrules{$balancer}) eq 'HASH') {
12464: if ($rule ne $currrules{$balancer}{$type}) {
12465: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
12466: }
12467: } elsif ($rule ne '') {
12468: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
12469: }
12470: }
12471: }
12472: }
12473: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12474: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12475: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12476: $defaultshash{'loadbalancing'} = {};
12477: }
12478: my $putresult = &Apache::lonnet::put_dom('configuration',
12479: \%defaultshash,$dom);
12480: if ($putresult eq 'ok') {
12481: if (keys(%changes) > 0) {
12482: my %toupdate;
12483: if (ref($changes{'delete'}) eq 'ARRAY') {
12484: foreach my $balancer (sort(@{$changes{'delete'}})) {
12485: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
12486: $toupdate{$balancer} = 1;
12487: }
12488: }
12489: if (ref($changes{'add'}) eq 'ARRAY') {
12490: foreach my $balancer (sort(@{$changes{'add'}})) {
12491: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
12492: $toupdate{$balancer} = 1;
12493: }
12494: }
12495: if (ref($changes{'curr'}) eq 'HASH') {
12496: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
12497: $toupdate{$balancer} = 1;
12498: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12499: if ($changes{'curr'}{$balancer}{'targets'}) {
12500: my %offloadstr;
12501: foreach my $sparetype (@sparestypes) {
12502: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12503: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12504: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12505: }
12506: }
12507: }
12508: if (keys(%offloadstr) == 0) {
12509: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
12510: } else {
12511: my $showoffload;
12512: foreach my $sparetype (@sparestypes) {
12513: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12514: if (defined($offloadstr{$sparetype})) {
12515: $showoffload .= $offloadstr{$sparetype};
12516: } else {
12517: $showoffload .= &mt('None');
12518: }
12519: $showoffload .= (' 'x3);
12520: }
12521: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
12522: }
12523: }
12524: }
12525: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12526: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12527: foreach my $type (@{$alltypes}) {
12528: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12529: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12530: my $balancetext;
12531: if ($rule eq '') {
12532: $balancetext = $ruletitles{'default'};
12533: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
12534: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12535: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12536: foreach my $sparetype (@sparestypes) {
12537: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12538: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12539: }
12540: }
12541: foreach my $item (@{$alltypes}) {
12542: next if ($item =~ /^_LC_ipchange/);
12543: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12544: if ($hasrule eq 'homeserver') {
12545: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12546: } else {
12547: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12548: if ($servers{$hasrule}) {
12549: $toupdate{$hasrule} = 1;
12550: }
12551: }
12552: }
12553: }
12554: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12555: $balancetext = $ruletitles{$rule};
12556: } else {
12557: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12558: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12559: if ($receiver) {
12560: $toupdate{$receiver};
12561: }
12562: }
12563: } else {
12564: $balancetext = $ruletitles{$rule};
12565: }
12566: } else {
12567: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12568: }
12569: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
12570: }
12571: }
12572: }
12573: }
12574: if (keys(%toupdate)) {
12575: my %thismachine;
12576: my $updatedhere;
12577: my $cachetime = 60*60*24;
12578: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12579: foreach my $lonhost (keys(%toupdate)) {
12580: if ($thismachine{$lonhost}) {
12581: unless ($updatedhere) {
12582: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12583: $defaultshash{'loadbalancing'},
12584: $cachetime);
12585: $updatedhere = 1;
12586: }
12587: } else {
12588: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12589: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12590: }
12591: }
12592: }
12593: }
12594: }
12595: if ($resulttext ne '') {
12596: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
12597: } else {
12598: $resulttext = $nochgmsg;
12599: }
12600: } else {
12601: $resulttext = $nochgmsg;
12602: }
12603: } else {
12604: $resulttext = '<span class="LC_error">'.
12605: &mt('An error occurred: [_1]',$putresult).'</span>';
12606: }
12607: } else {
12608: $resulttext = $nochgmsg;
12609: }
12610: return $resulttext;
12611: }
12612:
12613: sub recurse_check {
12614: my ($chkcats,$categories,$depth,$name) = @_;
12615: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12616: my $chg = 0;
12617: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12618: my $category = $chkcats->[$depth]{$name}[$j];
12619: my $item;
12620: if ($category eq '') {
12621: $chg ++;
12622: } else {
12623: my $deeper = $depth + 1;
12624: $item = &escape($category).':'.&escape($name).':'.$depth;
12625: if ($chg) {
12626: $categories->{$item} -= $chg;
12627: }
12628: &recurse_check($chkcats,$categories,$deeper,$category);
12629: $deeper --;
12630: }
12631: }
12632: }
12633: return;
12634: }
12635:
12636: sub recurse_cat_deletes {
12637: my ($item,$coursecategories,$deletions) = @_;
12638: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12639: my $subdepth = $depth + 1;
12640: if (ref($coursecategories) eq 'HASH') {
12641: foreach my $subitem (keys(%{$coursecategories})) {
12642: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12643: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12644: delete($coursecategories->{$subitem});
12645: $deletions->{$subitem} = 1;
12646: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
12647: }
12648: }
12649: }
12650: return;
12651: }
12652:
12653: sub get_active_dcs {
12654: my ($dom) = @_;
12655: my $now = time;
12656: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
12657: my %domcoords;
12658: my $numdcs = 0;
12659: foreach my $server (keys(%dompersonnel)) {
12660: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
12661: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
12662: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
12663: }
12664: }
12665: return %domcoords;
12666: }
12667:
12668: sub active_dc_picker {
12669: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
12670: my %domcoords = &get_active_dcs($dom);
12671: my @domcoord = keys(%domcoords);
12672: if (keys(%currhash)) {
12673: foreach my $dc (keys(%currhash)) {
12674: unless (exists($domcoords{$dc})) {
12675: push(@domcoord,$dc);
12676: }
12677: }
12678: }
12679: @domcoord = sort(@domcoord);
12680: my $numdcs = scalar(@domcoord);
12681: my $rows = 0;
12682: my $table;
12683: if ($numdcs > 1) {
12684: $table = '<table>';
12685: for (my $i=0; $i<@domcoord; $i++) {
12686: my $rem = $i%($numinrow);
12687: if ($rem == 0) {
12688: if ($i > 0) {
12689: $table .= '</tr>';
12690: }
12691: $table .= '<tr>';
12692: $rows ++;
12693: }
12694: my $check = '';
12695: if ($inputtype eq 'radio') {
12696: if (keys(%currhash) == 0) {
12697: if (!$i) {
12698: $check = ' checked="checked"';
12699: }
12700: } elsif (exists($currhash{$domcoord[$i]})) {
12701: $check = ' checked="checked"';
12702: }
12703: } else {
12704: if (exists($currhash{$domcoord[$i]})) {
12705: $check = ' checked="checked"';
12706: }
12707: }
12708: if ($i == @domcoord - 1) {
12709: my $colsleft = $numinrow - $rem;
12710: if ($colsleft > 1) {
12711: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
12712: } else {
12713: $table .= '<td class="LC_left_item">';
12714: }
12715: } else {
12716: $table .= '<td class="LC_left_item">';
12717: }
12718: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12719: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12720: $table .= '<span class="LC_nobreak"><label>'.
12721: '<input type="'.$inputtype.'" name="'.$name.'"'.
12722: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12723: if ($user ne $dcname.':'.$dcdom) {
12724: $table .= ' ('.$dcname.':'.$dcdom.')';
12725: }
12726: $table .= '</label></span></td>';
12727: }
12728: $table .= '</tr></table>';
12729: } elsif ($numdcs == 1) {
12730: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12731: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12732: if ($inputtype eq 'radio') {
12733: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
12734: if ($user ne $dcname.':'.$dcdom) {
12735: $table .= ' ('.$dcname.':'.$dcdom.')';
12736: }
12737: } else {
12738: my $check;
12739: if (exists($currhash{$domcoord[0]})) {
12740: $check = ' checked="checked"';
12741: }
12742: $table = '<span class="LC_nobreak"><label>'.
12743: '<input type="checkbox" name="'.$name.'" '.
12744: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
12745: if ($user ne $dcname.':'.$dcdom) {
12746: $table .= ' ('.$dcname.':'.$dcdom.')';
12747: }
12748: $table .= '</label></span>';
12749: $rows ++;
12750: }
12751: }
12752: return ($numdcs,$table,$rows);
12753: }
12754:
12755: sub usersession_titles {
12756: return &Apache::lonlocal::texthash(
12757: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12758: remote => 'Hosting of sessions for users in this domain on servers in other domains',
12759: spares => 'Servers offloaded to, when busy',
12760: version => 'LON-CAPA version requirement',
12761: excludedomain => 'Allow all, but exclude specific domains',
12762: includedomain => 'Deny all, but include specific domains',
12763: primary => 'Primary (checked first)',
12764: default => 'Default',
12765: );
12766: }
12767:
12768: sub id_for_thisdom {
12769: my (%servers) = @_;
12770: my %altids;
12771: foreach my $server (keys(%servers)) {
12772: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12773: if ($serverhome ne $server) {
12774: $altids{$serverhome} = $server;
12775: }
12776: }
12777: return %altids;
12778: }
12779:
12780: sub count_servers {
12781: my ($currbalancer,%servers) = @_;
12782: my (@spares,$numspares);
12783: foreach my $lonhost (sort(keys(%servers))) {
12784: next if ($currbalancer eq $lonhost);
12785: push(@spares,$lonhost);
12786: }
12787: if ($currbalancer) {
12788: $numspares = scalar(@spares);
12789: } else {
12790: $numspares = scalar(@spares) - 1;
12791: }
12792: return ($numspares,@spares);
12793: }
12794:
12795: sub lonbalance_targets_js {
12796: my ($dom,$types,$servers,$settings) = @_;
12797: my $select = &mt('Select');
12798: my ($alltargets,$allishome,$allinsttypes,@alltypes);
12799: if (ref($servers) eq 'HASH') {
12800: $alltargets = join("','",sort(keys(%{$servers})));
12801: my @homedoms;
12802: foreach my $server (sort(keys(%{$servers}))) {
12803: if (&Apache::lonnet::host_domain($server) eq $dom) {
12804: push(@homedoms,'1');
12805: } else {
12806: push(@homedoms,'0');
12807: }
12808: }
12809: $allishome = join("','",@homedoms);
12810: }
12811: if (ref($types) eq 'ARRAY') {
12812: if (@{$types} > 0) {
12813: @alltypes = @{$types};
12814: }
12815: }
12816: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
12817: $allinsttypes = join("','",@alltypes);
12818: my (%currbalancer,%currtargets,%currrules,%existing);
12819: if (ref($settings) eq 'HASH') {
12820: %existing = %{$settings};
12821: }
12822: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
12823: \%currtargets,\%currrules);
12824: my $balancers = join("','",sort(keys(%currbalancer)));
12825: return <<"END";
12826:
12827: <script type="text/javascript">
12828: // <![CDATA[
12829:
12830: currBalancers = new Array('$balancers');
12831:
12832: function toggleTargets(balnum) {
12833: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12834: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
12835: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
12836: var prevbalancer = prevhostitem.value;
12837: var baltotal = document.getElementById('loadbalancing_total').value;
12838: prevhostitem.value = balancer;
12839: if (prevbalancer != '') {
12840: var prevIdx = currBalancers.indexOf(prevbalancer);
12841: if (prevIdx != -1) {
12842: currBalancers.splice(prevIdx,1);
12843: }
12844: }
12845: if (balancer == '') {
12846: hideSpares(balnum);
12847: } else {
12848: var currIdx = currBalancers.indexOf(balancer);
12849: if (currIdx == -1) {
12850: currBalancers.push(balancer);
12851: }
12852: var homedoms = new Array('$allishome');
12853: var ishomedom = homedoms[lonhostitem.selectedIndex];
12854: showSpares(balancer,ishomedom,balnum);
12855: }
12856: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
12857: return;
12858: }
12859:
12860: function showSpares(balancer,ishomedom,balnum) {
12861: var alltargets = new Array('$alltargets');
12862: var insttypes = new Array('$allinsttypes');
12863: var offloadtypes = new Array('primary','default');
12864:
12865: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
12866: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
12867:
12868: for (var i=0; i<offloadtypes.length; i++) {
12869: var count = 0;
12870: for (var j=0; j<alltargets.length; j++) {
12871: if (alltargets[j] != balancer) {
12872: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
12873: item.value = alltargets[j];
12874: item.style.textAlign='left';
12875: item.style.textFace='normal';
12876: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
12877: if (currBalancers.indexOf(alltargets[j]) == -1) {
12878: item.disabled = '';
12879: } else {
12880: item.disabled = 'disabled';
12881: item.checked = false;
12882: }
12883: count ++;
12884: }
12885: }
12886: }
12887: for (var k=0; k<insttypes.length; k++) {
12888: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
12889: if (ishomedom == 1) {
12890: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12891: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
12892: } else {
12893: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12894: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
12895: }
12896: } else {
12897: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12898: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
12899: }
12900: if ((insttypes[k] != '_LC_external') &&
12901: ((insttypes[k] != '_LC_internetdom') ||
12902: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
12903: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
12904: item.options.length = 0;
12905: item.options[0] = new Option("","",true,true);
12906: var idx = 0;
12907: for (var m=0; m<alltargets.length; m++) {
12908: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
12909: idx ++;
12910: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
12911: }
12912: }
12913: }
12914: }
12915: return;
12916: }
12917:
12918: function hideSpares(balnum) {
12919: var alltargets = new Array('$alltargets');
12920: var insttypes = new Array('$allinsttypes');
12921: var offloadtypes = new Array('primary','default');
12922:
12923: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
12924: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
12925:
12926: var total = alltargets.length - 1;
12927: for (var i=0; i<offloadtypes; i++) {
12928: for (var j=0; j<total; j++) {
12929: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
12930: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
12931: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
12932: }
12933: }
12934: for (var k=0; k<insttypes.length; k++) {
12935: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12936: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
12937: if (insttypes[k] != '_LC_external') {
12938: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
12939: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
12940: }
12941: }
12942: return;
12943: }
12944:
12945: function checkOffloads(item,balnum,type) {
12946: var alltargets = new Array('$alltargets');
12947: var offloadtypes = new Array('primary','default');
12948: if (item.checked) {
12949: var total = alltargets.length - 1;
12950: var other;
12951: if (type == offloadtypes[0]) {
12952: other = offloadtypes[1];
12953: } else {
12954: other = offloadtypes[0];
12955: }
12956: for (var i=0; i<total; i++) {
12957: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
12958: if (server == item.value) {
12959: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
12960: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
12961: }
12962: }
12963: }
12964: }
12965: return;
12966: }
12967:
12968: function singleServerToggle(balnum,type) {
12969: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
12970: if (offloadtoSelIdx == 0) {
12971: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
12972: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
12973:
12974: } else {
12975: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
12976: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
12977: }
12978: return;
12979: }
12980:
12981: function balanceruleChange(formname,balnum,type) {
12982: if (type == '_LC_external') {
12983: return;
12984: }
12985: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
12986: for (var i=0; i<typesRules.length; i++) {
12987: if (formname.elements[typesRules[i]].checked) {
12988: if (formname.elements[typesRules[i]].value != 'specific') {
12989: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
12990: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
12991: } else {
12992: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
12993: }
12994: }
12995: }
12996: return;
12997: }
12998:
12999: function balancerDeleteChange(balnum) {
13000: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13001: var baltotal = document.getElementById('loadbalancing_total').value;
13002: var addtarget;
13003: var removetarget;
13004: var action = 'delete';
13005: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13006: var lonhost = hostitem.value;
13007: var currIdx = currBalancers.indexOf(lonhost);
13008: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13009: if (currIdx != -1) {
13010: currBalancers.splice(currIdx,1);
13011: }
13012: addtarget = lonhost;
13013: } else {
13014: if (currIdx == -1) {
13015: currBalancers.push(lonhost);
13016: }
13017: removetarget = lonhost;
13018: action = 'undelete';
13019: }
13020: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13021: }
13022: return;
13023: }
13024:
13025: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13026: if (baltotal > 1) {
13027: var offloadtypes = new Array('primary','default');
13028: var alltargets = new Array('$alltargets');
13029: var insttypes = new Array('$allinsttypes');
13030: for (var i=0; i<baltotal; i++) {
13031: if (i != balnum) {
13032: for (var j=0; j<offloadtypes.length; j++) {
13033: var total = alltargets.length - 1;
13034: for (var k=0; k<total; k++) {
13035: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13036: var server = serveritem.value;
13037: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13038: if (server == addtarget) {
13039: serveritem.disabled = '';
13040: }
13041: }
13042: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13043: if (server == removetarget) {
13044: serveritem.disabled = 'disabled';
13045: serveritem.checked = false;
13046: }
13047: }
13048: }
13049: }
13050: for (var j=0; j<insttypes.length; j++) {
13051: if (insttypes[j] != '_LC_external') {
13052: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13053: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13054: var currSel = singleserver.selectedIndex;
13055: var currVal = singleserver.options[currSel].value;
13056: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13057: var numoptions = singleserver.options.length;
13058: var needsnew = 1;
13059: for (var k=0; k<numoptions; k++) {
13060: if (singleserver.options[k] == addtarget) {
13061: needsnew = 0;
13062: break;
13063: }
13064: }
13065: if (needsnew == 1) {
13066: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13067: }
13068: }
13069: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13070: singleserver.options.length = 0;
13071: if ((currVal) && (currVal != removetarget)) {
13072: singleserver.options[0] = new Option("","",false,false);
13073: } else {
13074: singleserver.options[0] = new Option("","",true,true);
13075: }
13076: var idx = 0;
13077: for (var m=0; m<alltargets.length; m++) {
13078: if (currBalancers.indexOf(alltargets[m]) == -1) {
13079: idx ++;
13080: if (currVal == alltargets[m]) {
13081: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13082: } else {
13083: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13084: }
13085: }
13086: }
13087: }
13088: }
13089: }
13090: }
13091: }
13092: }
13093: }
13094: return;
13095: }
13096:
13097: // ]]>
13098: </script>
13099:
13100: END
13101: }
13102:
13103: sub new_spares_js {
13104: my @sparestypes = ('primary','default');
13105: my $types = join("','",@sparestypes);
13106: my $select = &mt('Select');
13107: return <<"END";
13108:
13109: <script type="text/javascript">
13110: // <![CDATA[
13111:
13112: function updateNewSpares(formname,lonhost) {
13113: var types = new Array('$types');
13114: var include = new Array();
13115: var exclude = new Array();
13116: for (var i=0; i<types.length; i++) {
13117: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13118: for (var j=0; j<spareboxes.length; j++) {
13119: if (formname.elements[spareboxes[j]].checked) {
13120: exclude.push(formname.elements[spareboxes[j]].value);
13121: } else {
13122: include.push(formname.elements[spareboxes[j]].value);
13123: }
13124: }
13125: }
13126: for (var i=0; i<types.length; i++) {
13127: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13128: var selIdx = newSpare.selectedIndex;
13129: var currnew = newSpare.options[selIdx].value;
13130: var okSpares = new Array();
13131: for (var j=0; j<newSpare.options.length; j++) {
13132: var possible = newSpare.options[j].value;
13133: if (possible != '') {
13134: if (exclude.indexOf(possible) == -1) {
13135: okSpares.push(possible);
13136: } else {
13137: if (currnew == possible) {
13138: selIdx = 0;
13139: }
13140: }
13141: }
13142: }
13143: for (var k=0; k<include.length; k++) {
13144: if (okSpares.indexOf(include[k]) == -1) {
13145: okSpares.push(include[k]);
13146: }
13147: }
13148: okSpares.sort();
13149: newSpare.options.length = 0;
13150: if (selIdx == 0) {
13151: newSpare.options[0] = new Option("$select","",true,true);
13152: } else {
13153: newSpare.options[0] = new Option("$select","",false,false);
13154: }
13155: for (var m=0; m<okSpares.length; m++) {
13156: var idx = m+1;
13157: var selThis = 0;
13158: if (selIdx != 0) {
13159: if (okSpares[m] == currnew) {
13160: selThis = 1;
13161: }
13162: }
13163: if (selThis == 1) {
13164: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13165: } else {
13166: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13167: }
13168: }
13169: }
13170: return;
13171: }
13172:
13173: function checkNewSpares(lonhost,type) {
13174: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13175: var chosen = newSpare.options[newSpare.selectedIndex].value;
13176: if (chosen != '') {
13177: var othertype;
13178: var othernewSpare;
13179: if (type == 'primary') {
13180: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13181: }
13182: if (type == 'default') {
13183: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13184: }
13185: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13186: othernewSpare.selectedIndex = 0;
13187: }
13188: }
13189: return;
13190: }
13191:
13192: // ]]>
13193: </script>
13194:
13195: END
13196:
13197: }
13198:
13199: sub common_domprefs_js {
13200: return <<"END";
13201:
13202: <script type="text/javascript">
13203: // <![CDATA[
13204:
13205: function getIndicesByName(formname,item) {
13206: var group = new Array();
13207: for (var i=0;i<formname.elements.length;i++) {
13208: if (formname.elements[i].name == item) {
13209: group.push(formname.elements[i].id);
13210: }
13211: }
13212: return group;
13213: }
13214:
13215: // ]]>
13216: </script>
13217:
13218: END
13219:
13220: }
13221:
13222: sub recaptcha_js {
13223: my %lt = &captcha_phrases();
13224: return <<"END";
13225:
13226: <script type="text/javascript">
13227: // <![CDATA[
13228:
13229: function updateCaptcha(caller,context) {
13230: var privitem;
13231: var pubitem;
13232: var privtext;
13233: var pubtext;
13234: var versionitem;
13235: var versiontext;
13236: if (document.getElementById(context+'_recaptchapub')) {
13237: pubitem = document.getElementById(context+'_recaptchapub');
13238: } else {
13239: return;
13240: }
13241: if (document.getElementById(context+'_recaptchapriv')) {
13242: privitem = document.getElementById(context+'_recaptchapriv');
13243: } else {
13244: return;
13245: }
13246: if (document.getElementById(context+'_recaptchapubtxt')) {
13247: pubtext = document.getElementById(context+'_recaptchapubtxt');
13248: } else {
13249: return;
13250: }
13251: if (document.getElementById(context+'_recaptchaprivtxt')) {
13252: privtext = document.getElementById(context+'_recaptchaprivtxt');
13253: } else {
13254: return;
13255: }
13256: if (document.getElementById(context+'_recaptchaversion')) {
13257: versionitem = document.getElementById(context+'_recaptchaversion');
13258: } else {
13259: return;
13260: }
13261: if (document.getElementById(context+'_recaptchavertxt')) {
13262: versiontext = document.getElementById(context+'_recaptchavertxt');
13263: } else {
13264: return;
13265: }
13266: if (caller.checked) {
13267: if (caller.value == 'recaptcha') {
13268: pubitem.type = 'text';
13269: privitem.type = 'text';
13270: pubitem.size = '40';
13271: privitem.size = '40';
13272: pubtext.innerHTML = "$lt{'pub'}";
13273: privtext.innerHTML = "$lt{'priv'}";
13274: versionitem.type = 'text';
13275: versionitem.size = '3';
13276: versiontext.innerHTML = "$lt{'ver'}";
13277: } else {
13278: pubitem.type = 'hidden';
13279: privitem.type = 'hidden';
13280: versionitem.type = 'hidden';
13281: pubtext.innerHTML = '';
13282: privtext.innerHTML = '';
13283: versiontext.innerHTML = '';
13284: }
13285: }
13286: return;
13287: }
13288:
13289: // ]]>
13290: </script>
13291:
13292: END
13293:
13294: }
13295:
13296: sub toggle_display_js {
13297: return <<"END";
13298:
13299: <script type="text/javascript">
13300: // <![CDATA[
13301:
13302: function toggleDisplay(domForm,caller) {
13303: if (document.getElementById(caller)) {
13304: var divitem = document.getElementById(caller);
13305: var optionsElement = domForm.coursecredits;
13306: var checkval = 1;
13307: var dispval = 'block';
13308: if (caller == 'emailoptions') {
13309: optionsElement = domForm.cancreate_email;
13310: }
13311: if (caller == 'studentsubmission') {
13312: optionsElement = domForm.postsubmit;
13313: }
13314: if (caller == 'cloneinstcode') {
13315: optionsElement = domForm.canclone;
13316: checkval = 'instcode';
13317: }
13318: if (optionsElement.length) {
13319: var currval;
13320: for (var i=0; i<optionsElement.length; i++) {
13321: if (optionsElement[i].checked) {
13322: currval = optionsElement[i].value;
13323: }
13324: }
13325: if (currval == checkval) {
13326: divitem.style.display = dispval;
13327: } else {
13328: divitem.style.display = 'none';
13329: }
13330: }
13331: }
13332: return;
13333: }
13334:
13335: // ]]>
13336: </script>
13337:
13338: END
13339:
13340: }
13341:
13342: sub captcha_phrases {
13343: return &Apache::lonlocal::texthash (
13344: priv => 'Private key',
13345: pub => 'Public key',
13346: original => 'original (CAPTCHA)',
13347: recaptcha => 'successor (ReCAPTCHA)',
13348: notused => 'unused',
13349: ver => 'ReCAPTCHA version (1 or 2)',
13350: );
13351: }
13352:
13353: sub devalidate_remote_domconfs {
13354: my ($dom,$cachekeys) = @_;
13355: return unless (ref($cachekeys) eq 'HASH');
13356: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13357: my %thismachine;
13358: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13359: my @posscached = ('domainconfig','domdefaults','ltitools');
13360: if (keys(%servers)) {
13361: foreach my $server (keys(%servers)) {
13362: next if ($thismachine{$server});
13363: my @cached;
13364: foreach my $name (@posscached) {
13365: if ($cachekeys->{$name}) {
13366: push(@cached,&escape($name).':'.&escape($dom));
13367: }
13368: }
13369: if (@cached) {
13370: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13371: }
13372: }
13373: }
13374: return;
13375: }
13376:
13377: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>